private void Show_Load(object sender, EventArgs e) { BLL.cardinfo bll = new BLL.cardinfo(); Model.cardinfo model = bll.GetModel(CardID); label1.Text = "账号:" + model.cardID + "\r\n货币类型:" + model.curType + "\r\n存款类型:" + model.savingType; label2.Text = "开户日期:" + model.openDate + "\r\n账户状态:" + (model.IsReportLoss?"已挂失":"正常") + "\r\n账户余额:" + model.balance; }
private void button2_Click(object sender, EventArgs e) { label9.Text = ""; string acctype = comboBox1.Text; decimal opennnum = numericUpDown1.Value; string pwd = textBox5.Text; Model.cardinfo model = new Model.cardinfo(); model.cardID = ""; model.curType = "RMB"; model.customerID = CustomerID; model.IsReportLoss = false; model.savingType = acctype; model.openDate = DateTime.Now; model.openMoney = opennnum; model.balance = opennnum; model.pass = pwd; bool openOK; if (CustomerID != 0)//身份证已注册 { BLL.cardinfo bll = new BLL.cardinfo(); openOK = bll.Add(model, out CardID); } else { string name = textBox2.Text; string pid = textBox1.Text; string tel = textBox3.Text; string add = textBox4.Text; Model.userInfo modelU = new Model.userInfo(); modelU.customerID = 0; modelU.customerName = name; modelU.pID = pid; modelU.telephone = tel; modelU.address = add; BLL.userInfo bllU = new BLL.userInfo(); CustomerID = bllU.Add(modelU); model.customerID = CustomerID; BLL.cardinfo bll = new BLL.cardinfo(); openOK = bll.Add(model, out CardID); } if (openOK) { label9.Text = "注册成功,卡号是:" + CardID + ",请前去登录!"; Clipboard.SetText(CardID);//剪贴板 } else { label9.Text = "注册失败,下次再来!"; } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.cardinfo DataRowToModel(DataRow row) { Model.cardinfo model = new Model.cardinfo(); if (row != null) { if (row["cardID"] != null) { model.cardID = row["cardID"].ToString(); } if (row["curType"] != null) { model.curType = row["curType"].ToString(); } if (row["savingType"] != null) { model.savingType = row["savingType"].ToString(); } if (row["openDate"] != null && row["openDate"].ToString() != "") { model.openDate = DateTime.Parse(row["openDate"].ToString()); } if (row["openMoney"] != null && row["openMoney"].ToString() != "") { model.openMoney = decimal.Parse(row["openMoney"].ToString()); } if (row["balance"] != null && row["balance"].ToString() != "") { model.balance = decimal.Parse(row["balance"].ToString()); } if (row["pass"] != null) { model.pass = row["pass"].ToString(); } if (row["IsReportLoss"] != null && row["IsReportLoss"].ToString() != "") { if ((row["IsReportLoss"].ToString() == "1") || (row["IsReportLoss"].ToString().ToLower() == "true")) { model.IsReportLoss = true; } else { model.IsReportLoss = false; } } if (row["customerID"] != null && row["customerID"].ToString() != "") { model.customerID = int.Parse(row["customerID"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.cardinfo GetModel(string cardID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 "); strSql.Append(" cardID,curType,savingType,openDate,openMoney,balance,pass,IsReportLoss,customerID "); strSql.Append(" from cardinfo "); strSql.Append(" where cardID='" + cardID + "' "); Model.cardinfo model = new Model.cardinfo(); DataSet ds = DbHelperSQL.Query(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
public bool UpdateBalance(string CardID, decimal MoneyNum, string remark) { //增加交易记录 Model.transInfo t = new Model.transInfo(); t.cardID = CardID; t.transDate = DateTime.Now; t.transMoney = Math.Abs(MoneyNum); t.transType = "存入"; t.remark = remark; string sql = "update cardinfo set balance=balance+" + MoneyNum + " where cardID='" + CardID + "' and IsReportLoss=0"; if (MoneyNum < 0) { //先判断余额是否足 Model.cardinfo c = GetModel(CardID); if (c != null) { if (c.balance < Math.Abs(MoneyNum))//余额不足 { return(false); } } else { return(false); } t.transType = "支取"; } if (DbHelperSQL.ExecuteSql(sql) >= 1)//存取款成功 则增加交易记录 { DAL.transInfo dalt = new DAL.transInfo(); dalt.Add(t); return(true); } return(false); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.cardinfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update cardinfo set "); if (model.curType != null) { strSql.Append("curType='" + model.curType + "',"); } else { strSql.Append("curType= null ,"); } if (model.savingType != null) { strSql.Append("savingType='" + model.savingType + "',"); } if (model.openDate != null) { strSql.Append("openDate='" + model.openDate + "',"); } else { strSql.Append("openDate= null ,"); } if (model.openMoney != null) { strSql.Append("openMoney=" + model.openMoney + ","); } if (model.balance != null) { strSql.Append("balance=" + model.balance + ","); } if (model.pass != null) { strSql.Append("pass='******',"); } else { strSql.Append("pass= null ,"); } if (model.IsReportLoss != null) { strSql.Append("IsReportLoss=" + (model.IsReportLoss? 1 : 0) + ","); } else { strSql.Append("IsReportLoss= null ,"); } if (model.customerID != null) { strSql.Append("customerID=" + model.customerID + ","); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where cardID='" + model.cardID + "' "); int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString()); if (rowsAffected > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Model.cardinfo model, out string cardID) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); cardID = ""; //62212611 。1-6表示银行 7-8省份。9-15位才是自己的账户号,最后一位仍然是校验码 。中间7位 //获取最新的银行卡号。新卡的账号。是卡号9-15位的数字+1.。最后一位是随机数 string ss = getMaxCardID(); if (ss == "") { cardID = "622126110000001"; } //第一个开卡的人 else { int xx = int.Parse(ss.Substring(8, 7)) + 1; if (xx == 10000000) { return(false); } //超额了 cardID = ss.Substring(0, 8) + xx.ToString("D7"); } Random r = new Random(); cardID = cardID + r.Next(0, 10); model.cardID = cardID; if (model.cardID != null) { strSql1.Append("cardID,"); strSql2.Append("'" + model.cardID + "',"); } if (model.curType != null) { strSql1.Append("curType,"); strSql2.Append("'" + model.curType + "',"); } if (model.savingType != null) { strSql1.Append("savingType,"); strSql2.Append("'" + model.savingType + "',"); } if (model.openDate != null) { strSql1.Append("openDate,"); strSql2.Append("'" + model.openDate + "',"); } if (model.openMoney != null) { strSql1.Append("openMoney,"); strSql2.Append("" + model.openMoney + ","); } if (model.balance != null) { strSql1.Append("balance,"); strSql2.Append("" + model.balance + ","); } if (model.pass != null) { strSql1.Append("pass,"); strSql2.Append("'" + model.pass + "',"); } if (model.IsReportLoss != null) { strSql1.Append("IsReportLoss,"); strSql2.Append("" + (model.IsReportLoss? 1 : 0) + ","); } if (model.customerID != null) { strSql1.Append("customerID,"); strSql2.Append("" + model.customerID + ","); } strSql.Append("insert into cardinfo("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); int rows = DbHelperSQL.ExecuteSql(strSql.ToString()); if (rows > 0) { //增加交易记录 Model.transInfo t = new Model.transInfo(); t.cardID = model.cardID; t.transDate = model.openDate; t.transMoney = model.openMoney; t.transType = "存入"; t.remark = "开户存入"; DAL.transInfo dalt = new DAL.transInfo(); dalt.Add(t); return(true); } else { return(false); } }