1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
|
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using MODEL;
namespace DAL { public class dal { string count = "server=.;DATABASE=MyAtm;Integrated Security=true;";//连接数据库字符串
/*登陆*/ public model select(string ID, string PWD) { model mm = null; try { SqlConnection con=new SqlConnection(count); con.Open(); //string sql = "select * from data where id='"+ID+"'"; SqlCommand cmd = new SqlCommand("select * from userr WHERE ID='"+ID+"'",con); SqlDataReader dr=cmd.ExecuteReader(); if (dr.Read()) { if (mm == null) //这个必须写 { mm = new model(); } mm.id = dr["ID"].ToString().Trim(); mm.pwd = dr["pwd"].ToString().Trim(); } con.Close(); } catch (Exception ex){ } return mm; }
/*修改密码*/ public model update(string ID, string SFZ,string PWD) { model mm = null; try { SqlConnection con = new SqlConnection(count); con.Open(); string sql = "select * from data where id='" + ID + "'"; SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { if (mm == null) { mm = new model(); } mm.id = dr["id"].ToString().Trim(); mm.sfz = dr["sfz"].ToString().Trim(); dr.Close(); string sql0 = "update userr set pwd='" + PWD + "'where id='" + ID + "'"; SqlCommand cmd1 = new SqlCommand(sql0, con); int n = cmd1.ExecuteNonQuery(); mm.pwd = PWD; con.Close(); } } catch (Exception ex){ } return mm; } /*查询余额*/ public model money_select(string ID)//money { model mm = new model(); SqlConnection con = new SqlConnection(count); string sql = "select * from data where id='"+ID+"'"; con.Open(); SqlCommand cmd = new SqlCommand(sql,con); SqlDataReader dr=cmd.ExecuteReader(); if (dr.Read()) { if (mm==null) { mm = new model(); } mm.money=dr["money"].ToString().Trim(); } con.Close(); return mm; }
/*取款*/ public int i=0; public string DT=""; /*用来储存当前操作的时间,与金额*/ public model draw(string ID,string DRAW) { model mm = null; string DT_sql = "select * from DATA where id='"+ID+"'"; SqlConnection DT_con = new SqlConnection(count); DT_con.Open(); SqlCommand DT_cmd = new SqlCommand(DT_sql, DT_con); SqlDataReader DT_dr = DT_cmd.ExecuteReader(); model i_mm=new model(); if (DT_dr.HasRows) { DT_dr.Read(); /*-----------先读取之前转账的信息------------*/ DT += DT_dr["RECORD"].ToString().Trim(); i_mm.money = DT_dr["MONEY"].ToString().Trim();
} DT_dr.Close(); DT_con.Close(); if (DRAW == "" || Convert.ToInt32(DRAW) > Convert.ToInt32(i_mm.money)) { //model i_mm = null; mm = i_mm; return mm; } else { DT += "\n" + DateTime.Now.ToString("yyy-M-d H:m:s"); SqlConnection con = new SqlConnection(count); con.Open(); string sql = "select * from data where id='" + ID + "'";//这个查询账号的信息,再进行读取余额 SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read()) { i = Convert.ToInt32(dr["money"].ToString().Trim());//自己的本钱/ } con.Close(); int k = i - Convert.ToInt32(DRAW);//自己的本钱减去要取出来的钱,然后把k更新到数据可以里 //2018-12-6 14:3:53已取出100 2018-12-6 14:6:24 已取出10元 DT += " 已取出" + DRAW + "元"; string sqlup = "update data set money='" + k + "',RECORD='" + DT + "'where id='" + ID + "'";//执行sql语句 //string sql02 = "update DATA set mory='" + k + "',RECORD='" + NOW + "'where ID='" + textBox1.Text.Trim() + "'"; con.Open(); SqlCommand cmdup = new SqlCommand(sqlup, con); int n = cmdup.ExecuteNonQuery(); con.Close(); mm = null; mm = new model(); mm.money = Convert.ToString(i); //要把已经计算好的金额更新到数据库中 return mm; } }
/*储存*/ public model Storage(string ID, string Money) { string DT_sql = "select * from DATA"; SqlConnection DT_con = new SqlConnection(count); DT_con.Open(); SqlCommand DT_cmd = new SqlCommand(DT_sql, DT_con); SqlDataReader DT_dr = DT_cmd.ExecuteReader(); int m = 0; if (DT_dr.HasRows) { DT_dr.Read(); /*-----------先读取之前转账的信息------------*/ DT += DT_dr["RECORD"].ToString().Trim(); m = Convert.ToInt32(DT_dr["MONEY"].ToString().Trim());
} DT_dr.Close(); DT_con.Close();
DT += "\n" + DateTime.Now.ToString("yyy-M-d H:m:s"); if (Money == "") { model i_mm = null; return i_mm; } else { //model mm = new model(); model mm = null; SqlConnection con = new SqlConnection(count); con.Open(); string sql = "select * from data where id='" + ID + "'";//这个查询账号的信息,再进行读取余额 SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read()) { i = Convert.ToInt32(dr["money"].ToString().Trim());//自己的本钱/ } con.Close(); int k = i + Convert.ToInt32(Money);//自己的本钱减去要取出来的钱,然后把k更新到数据可以里 DT += " 已存入" + Money + "元"; string sqlup = "update data set money='" + k + "',RECORD='"+DT+"'where id='" + ID + "'";//执行sql语句 con.Open(); SqlCommand cmdup = new SqlCommand(sqlup, con); int n = cmdup.ExecuteNonQuery(); con.Close(); mm = null; mm = new model(); mm.money = Convert.ToString(k); //要把已经计算好的金额更新到数据库中 return mm; } }
/*转账*//*没有卡号能减少自己的本金,没有金额会报错*/ int n; public model T_accounts(string ID, string YouID, string Ta) { /*有这账号,没有金额报错,会报错*///ok /*,没有账号,会提示没有这个账号,但是有金额可以转账成功*/ string Ta_sql = "select * from DATA"; SqlConnection Ta_con = new SqlConnection(count); Ta_con.Open(); SqlCommand Ta_cmd = new SqlCommand(Ta_sql, Ta_con); SqlDataReader Ta_dr = Ta_cmd.ExecuteReader(); int m = 0; if (Ta_dr.HasRows) { Ta_dr.Read(); /*-----------先读取之前转账的信息------------*/ DT += Ta_dr["RECORD"].ToString().Trim(); m = Convert.ToInt32(Ta_dr["MONEY"].ToString().Trim()); } Ta_dr.Close(); Ta_con.Close();
DT += "\n" + DateTime.Now.ToString("yyy-M-d H:m:s"); if (Ta == ""||YouID=="" ||Convert.ToInt32(Ta) > Convert.ToInt32(m)) { model mm = null; return mm; } else { model mm = new model(); mm.id = YouID; SqlConnection con = new SqlConnection(count); con.Open(); string sql = "select * from data where id='" + ID + "'"; SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { mm.money = dr["money"].ToString().Trim();//获取自己的余额 dr.Close(); } /*n相当于自己的余额减去转账的金额--然后把这个n更新到数据库里面*/ DT += " 已转入" + YouID + ":"+Ta+"元"; n = Convert.ToInt32(mm.money) - Convert.ToInt32(Ta); string n_sql = "update data set money='" + n + "',RECORD='"+DT+"'where id='" + ID + "'"; SqlCommand n_cmd = new SqlCommand(n_sql, con); int i = n_cmd.ExecuteNonQuery();
string m_sql = "select * from data where id='" + YouID + "'"; SqlCommand m_cmd = new SqlCommand(m_sql, con); SqlDataReader m_dr = m_cmd.ExecuteReader(); if (m_dr.Read()) { mm.money = ""; mm.money = m_dr["money"].ToString().Trim();//获取自己的余额 } m_dr.Close(); int k_1 = Convert.ToInt32(mm.money); int k_2= Convert.ToInt32(Ta); k_1 += k_2; string q_sql = "update data set money='" + k_1 + "'where id='" + YouID + "'"; SqlCommand q_cmd = new SqlCommand(q_sql, con); int j = q_cmd.ExecuteNonQuery(); con.Close(); return mm; } }
/*记录*/ public model record(string ID) { model mm = new model(); SqlConnection con = new SqlConnection(count); string sql = "select * from data where id='" + ID + "'"; con.Open(); SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { if (mm == null) { mm = new model(); } mm.record = dr["RECORD"].ToString().Trim(); } con.Close(); return mm; }
} }
|