protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { switch (keyData) { case Keys.Escape: this.Close(); return(true); case Keys.Enter: if (tbVipCode.Text.Trim() != "") { Dong.BLL.MemberInfo bMember = new Dong.BLL.MemberInfo(); Dong.Model.MemberInfo mMember = new Dong.Model.MemberInfo(); mMember = bMember.GetModel(tbVipCode.Text); if (mMember == null) { MessageBox.Show("对不起,无此会员!"); } else { tbVipName.Text = mMember.Name; Dong.Model.GlobalsInfo.vipZK = mMember.Discount; Dong.Model.GlobalsInfo.vipCode = tbVipCode.Text; frmCash frmP = (frmCash)this.Owner; frmP.sumCash(); } } return(true); default: return(base.ProcessCmdKey(ref msg, keyData)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Dong.Model.MemberInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update MemberInfo set "); strSql.Append("IdCode=@IdCode,"); strSql.Append("UserName=@UserName,"); strSql.Append("Stime=@Stime,"); strSql.Append("Etime=@Etime,"); strSql.Append("Email=@Email,"); strSql.Append("Addr=@Addr,"); strSql.Append("Birthday=@Birthday,"); strSql.Append("Discount=@Discount,"); strSql.Append("iMoney=@iMoney,"); strSql.Append("Oper=@Oper,"); strSql.Append("OperDate=@OperDate"); strSql.Append(" where Id=@Id"); OleDbParameter[] parameters = { new OleDbParameter("@IdCode", OleDbType.VarChar, 50), new OleDbParameter("@UserName", OleDbType.VarChar, 50), new OleDbParameter("@Stime", OleDbType.Date), new OleDbParameter("@Etime", OleDbType.Date), new OleDbParameter("@Email", OleDbType.VarChar, 50), new OleDbParameter("@Addr", OleDbType.VarChar, 200), new OleDbParameter("@Birthday", OleDbType.Date), new OleDbParameter("@Discount", OleDbType.Double), new OleDbParameter("@iMoney", OleDbType.Double), new OleDbParameter("@Oper", OleDbType.VarChar, 50), new OleDbParameter("@OperDate", OleDbType.Date), new OleDbParameter("@Id", OleDbType.Integer, 4) }; parameters[0].Value = model.IdCode; parameters[1].Value = model.Name; parameters[2].Value = model.Stime; parameters[3].Value = model.Etime; parameters[4].Value = model.Email; parameters[5].Value = model.Addr; parameters[6].Value = model.Birthday; parameters[7].Value = model.Discount; parameters[8].Value = model.Money; parameters[9].Value = model.Oper; parameters[10].Value = model.OperDate; parameters[11].Value = model.Id; int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Dong.Model.MemberInfo DataRowToModel(DataRow row) { Dong.Model.MemberInfo model = new Dong.Model.MemberInfo(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["IdCode"] != null) { model.IdCode = row["IdCode"].ToString(); } if (row["UserName"] != null) { model.Name = row["UserName"].ToString(); } if (row["Stime"] != null && row["Stime"].ToString() != "") { model.Stime = DateTime.Parse(row["Stime"].ToString()); } if (row["Etime"] != null && row["Etime"].ToString() != "") { model.Etime = DateTime.Parse(row["Etime"].ToString()); } if (row["Email"] != null) { model.Email = row["Email"].ToString(); } if (row["Addr"] != null) { model.Addr = row["Addr"].ToString(); } if (row["Birthday"] != null && row["Birthday"].ToString() != "") { model.Birthday = DateTime.Parse(row["Birthday"].ToString()); } if (row["Discount"] != null && row["Discount"].ToString() != "") { model.Discount = double.Parse(row["Discount"].ToString()); } //model.Discount=row["Discount"].ToString(); //model.Money=row["Money"].ToString(); if (row["Oper"] != null) { model.Oper = row["Oper"].ToString(); } if (row["OperDate"] != null && row["OperDate"].ToString() != "") { model.OperDate = DateTime.Parse(row["OperDate"].ToString()); } } return(model); }
private void frmAddVip_Load(object sender, EventArgs e) { Dong.BLL.MemberInfo bMember = new Dong.BLL.MemberInfo(); Dong.Model.MemberInfo mMember = new Dong.Model.MemberInfo(); mMember = bMember.GetModel(int.Parse(this.Tag.ToString())); if (mMember != null) { tbCode.Text = mMember.IdCode; tbAddr.Text = mMember.Addr; tbBirthday.Text = mMember.Birthday.ToString(); tbDiscount.Text = mMember.Discount.ToString(); tbEmail.Text = mMember.Email; tbName.Text = mMember.Name; cbStime.Text = mMember.Stime.ToString(); cbEtime.Text = mMember.Etime.ToString(); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Dong.Model.MemberInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into MemberInfo("); strSql.Append("IdCode,UserName,Stime,Etime,Email,Addr,Birthday,Discount,iMoney,Oper,OperDate)"); strSql.Append(" values ("); strSql.Append("@IdCode,@UserName,@Stime,@Etime,@Email,@Addr,@Birthday,@Discount,@Money,@Oper,@OperDate)"); OleDbParameter[] parameters = { new OleDbParameter("@IdCode", OleDbType.VarChar, 50), new OleDbParameter("@UserName", OleDbType.VarChar, 50), new OleDbParameter("@Stime", OleDbType.Date), new OleDbParameter("@Etime", OleDbType.Date), new OleDbParameter("@Email", OleDbType.VarChar, 50), new OleDbParameter("@Addr", OleDbType.VarChar, 200), new OleDbParameter("@Birthday", OleDbType.Date), new OleDbParameter("@Discount", OleDbType.Double), new OleDbParameter("@iMoney", OleDbType.Double), new OleDbParameter("@Oper", OleDbType.VarChar, 50), new OleDbParameter("@OperDate", OleDbType.Date) }; parameters[0].Value = model.IdCode; parameters[1].Value = model.Name; parameters[2].Value = model.Stime; parameters[3].Value = model.Etime; parameters[4].Value = model.Email; parameters[5].Value = model.Addr; parameters[6].Value = model.Birthday; parameters[7].Value = model.Discount; parameters[8].Value = model.Money; parameters[9].Value = model.Oper; parameters[10].Value = model.OperDate; int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
public Dong.Model.MemberInfo GetModel(string Code) { StringBuilder strSql = new StringBuilder(); strSql.Append("select Id,IdCode,UserName,Stime,Etime,Email,Addr,Birthday,Discount,iMoney,Oper,OperDate from MemberInfo "); strSql.Append(" where IdCode=@IdCode"); OleDbParameter[] parameters = { new OleDbParameter("@IdCode", OleDbType.VarChar, 50) }; parameters[0].Value = Code; Dong.Model.MemberInfo model = new Dong.Model.MemberInfo(); DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void btnSave_Click(object sender, EventArgs e) { //验证用户姓名 if (tbName.Text.Trim() == "") { MessageBoxEx.Show("请输入会员姓名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); tbName.Focus(); return; } if (cbStime.Text.Trim() == "") { MessageBoxEx.Show("请输入会员的开始时间!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); cbStime.Focus(); return; } if (cbEtime.Text.Trim() == "") { MessageBoxEx.Show("请输入会员的结束时间!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); cbEtime.Focus(); return; } if (tbDiscount.Text.Trim() == "") { MessageBoxEx.Show("请输入会员享受的折扣!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); tbDiscount.Focus(); return; } Dong.BLL.MemberInfo bMember = new Dong.BLL.MemberInfo(); Dong.Model.MemberInfo mMember = new Dong.Model.MemberInfo(); mMember = bMember.GetModel(int.Parse(this.Tag.ToString())); mMember.Id = int.Parse(this.Tag.ToString()); mMember.IdCode = tbCode.Text; mMember.Name = tbName.Text; mMember.Stime = DateTime.Parse(cbStime.Text); mMember.Etime = DateTime.Parse(cbEtime.Text); if (tbEmail.Text != "") { mMember.Email = tbEmail.Text; } else { mMember.Email = "无"; } if (tbAddr.Text != "") { mMember.Addr = tbAddr.Text; } else { mMember.Addr = "无"; } if (tbBirthday.Text != "") { mMember.Birthday = DateTime.Parse(tbBirthday.Text); } else { mMember.Birthday = DateTime.Parse("1900-1-1"); } mMember.Discount = double.Parse(tbDiscount.Text); mMember.Oper = Dong.Model.GlobalsInfo.UserName; mMember.OperDate = DateTime.Now; mMember.Money = mMember.Money; if (bMember.Update(mMember)) { MessageBoxEx.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); frmVip fvip = (frmVip)this.Owner; fvip.refreshData(); this.Close(); } else { MessageBoxEx.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }