private void btnOk_Click(object sender, EventArgs e) { if (CheckEmpty()) { MemmberInfo mem = new MemmberInfo(); mem.MemBirthdaty = Convert.ToDateTime(txtBirs.Text); mem.MemDiscount = Convert.ToDecimal(txtMemDiscount.Text); mem.MemEndServerTime = Convert.ToDateTime(dtEndServerTime.Value); mem.MemGender = CheckGender(); mem.MemIntegral = Convert.ToInt32(txtMemIntegral.Text); mem.MemMobilePhone = txtMemPhone.Text; mem.MemMoney = Convert.ToDecimal(txtmemMoney.Text); mem.MemName = txtMemName.Text; mem.MemNum = txtMemNum.Text; mem.MemType = Convert.ToInt32(cmbMemType.SelectedValue); if (this.TP == 1) { mem.SubTime = System.DateTime.Now; mem.DelFlag = 0; } else if (this.TP == 2) { mem.MemmberId = Convert.ToInt32(labId.Text); } MemmberInfoBll bll = new MemmberInfoBll(); string msg = bll.SaveMemmberInfo(mem, this.TP) ? "操作成功" : "操作失败"; MessageBox.Show(msg); this.Close(); } }
/// <summary> /// 新增 /// </summary> /// <param name="mem"></param> /// <returns></returns> public int AddMemmberInfo(MemmberInfo mem) { string sql = "insert into MemmberInfo (MemName,MemMobilePhone,MemAddress,MemType,MemNum,MemGender,MemDiscount,MemMoney,DelFlag,SubTime,MemIntegral,MemEndServerTime,MemBirthdaty) values(@MemName,@MemMobilePhone,@MemAddress,@MemType,@MemNum,@MemGender,@MemDiscount,@MemMoney,@DelFlag,@SubTime,@MemIntegral,@MemEndServerTime,@MemBirthdaty)"; return(AddAndUpdateMemmberInfo(1, sql, mem)); }
//新增和修改的公共方法 private int AddAndUpdate(MemmberInfo memmber, string sql, int temp) { SQLiteParameter[] param = { new SQLiteParameter("@MemName", memmber.MemName), new SQLiteParameter("@MemMobilePhone", memmber.MemMobilePhone), new SQLiteParameter("@MemAddress", memmber.MemAddress), new SQLiteParameter("@MemType", memmber.MemType), new SQLiteParameter("@MemNum", memmber.MemNum), new SQLiteParameter("@MemGender", memmber.MemGender), new SQLiteParameter("@MemDiscount", memmber.MemDiscount), new SQLiteParameter("@MemMoney", memmber.MemMoney), new SQLiteParameter("@MemIntegral", memmber.MemIntegral), new SQLiteParameter("@MemEndServerTime", memmber.MemEndServerTime), new SQLiteParameter("@MemBirthdaty", memmber.MemBirthdaty) }; List <SQLiteParameter> list = new List <SQLiteParameter>(); list.AddRange(param); if (temp == 1) { list.Add(new SQLiteParameter("@SubTime", memmber.SubTime)); list.Add(new SQLiteParameter("@DelFlag", memmber.DelFlag)); } else if (temp == 2) { list.Add(new SQLiteParameter("@MemmberId", memmber.MemmberId)); } return(SqliteHelper.ExecuteNonQuery(sql, list.ToArray())); }
/// <summary> /// 根据会员的Id查询该会员的信息 /// </summary> /// <param name="memmberId">会员Id</param> /// <returns>会员对象</returns> public MemmberInfo GetMemmberInfoByMemmberId(int memmberId) { string sql = "select * from MemmberInfo where MemmberId=@MemmberId "; DataTable dt = SqliteHelper.ExecuteTable(sql, new SQLiteParameter("@MemmberId", memmberId)); MemmberInfo mem = null; if (dt.Rows.Count > 0) { mem = RowToMemmberInfo(dt.Rows[0]); } return(mem); }
/// <summary> /// 根据用户编号查询具体信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public MemmberInfo GetMemmberInfoByMemmberId(int id) { string sql = "select * from MemmberInfo where DelFlag=0 and MemmberId=" + id; DataTable dt = Sqlitehelper.ExecuteTable(sql); MemmberInfo mem = null; if (dt.Rows.Count > 0) { mem = RowToMemmberInfo(dt.Rows[0]); } return(mem); }
//确定按钮,新增和修改 private void btnOk_Click(object sender, EventArgs e) { MemmberInfo mem = new MemmberInfo(); if (IsCheck()) { mem.MemAddress = txtAddress.Text; mem.MemBirthdaty = Convert.ToDateTime(txtBirs.Text); mem.MemDiscount = Convert.ToDecimal(txtMemDiscount.Text); mem.MemEndServerTime = dtEndServerTime.Value; mem.MemGender = CheckGender(); mem.MemIntegral = Convert.ToInt32(txtMemIntegral.Text); mem.MemMobilePhone = txtMemPhone.Text; mem.MemMoney = Convert.ToDecimal(txtmemMoney.Text); mem.MemName = txtMemName.Text; mem.MemNum = txtMemNum.Text; mem.MemType = Convert.ToInt32(cmbMemType.SelectedIndex); } MemmberInfoBLL bll = new MemmberInfoBLL(); //新增还是修改 if (this.Tp == 1)//新增 { mem.DelFlag = 0; mem.SubTime = System.DateTime.Now; //if (bll.SaveMemmber(mem,this.Tp)) //{ // MessageBox.Show("新增成功"); // this.Close(); //} //else //{ // MessageBox.Show("新增失败"); //} } else if (this.Tp == 2) //修改 { mem.MemmberId = Convert.ToInt32(labId.Text); //if (bll.SaveMemmber(mem, this.Tp)) //{ // MessageBox.Show("修改成功"); // this.Close(); //} //else //{ // MessageBox.Show("修改失败"); //} } string st = bll.SaveMemmber(mem, this.Tp) ? "操作成功" : "操作失败"; MessageBox.Show(st); this.Close(); }
/// <summary> /// 根据用户性别查询用户信息 /// </summary> /// <param name="name"></param> /// <returns></returns> public MemmberInfo GetMemmberInfoByMemmberName(string name) { string sql = "select * from MemmberInfo where DelFlag=0 and MemName=@MemName"; DataTable dt = Sqlitehelper.ExecuteTable(sql, new SQLiteParameter("@MemName", name)); MemmberInfo mem = null; if (dt.Rows.Count > 0) { mem = RowToMemmberInfo(dt.Rows[0]); } return(mem); }
/// <summary> /// 添加和修改会员 /// </summary> /// <param name="mem">会员对象</param> /// <param name="temp">标识</param> /// <returns></returns> public bool SaveMemmberInfo(MemmberInfo mem, int temp) { int r = -1; if (temp == 1) { r = dal.AddMemmbeer(mem); } else if (temp == 2) { r = dal.UpdateMemmber(mem); } return(r > 0 ? true : false); }
//修改 private void btnUpdateMember_Click(object sender, EventArgs e) { if (dgvMemmber.SelectedRows.Count > 0) { int id = Convert.ToInt32(dgvMemmber.SelectedRows[0].Cells[0].Value); MemmberInfoBLL bll = new MemmberInfoBLL(); MemmberInfo mem = bll.GetMemmberByMemmberid(id); mem.MemmberId = id; fea.Obj = mem; ShowChangeMemmber(2);//2表示修改 //根据选中行的id去数据库查询是否有这条数据,并以对象的方式返回来 //传对象 } }
/// <summary> /// 查询所有没删除的会员 /// </summary> /// <param name="delFlag">删除表示</param> /// <returns>会员对象集合</returns> public List <MemmberInfo> GetAllMemmberInfoByDelFlag(int delFlag) { string sql = "select * from MemmberInfo where DelFlag=@DelFlag"; DataTable dt = SqliteHelper.ExecuteTable(sql, new SQLiteParameter("@DelFlag", delFlag)); List <MemmberInfo> list = new List <MemmberInfo>(); if (dt.Rows.Count > 0) { foreach (DataRow item in dt.Rows) { MemmberInfo mem = RowToMemmberInfo(item); list.Add(mem); } } return(list); }
private void btnAccounts_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtMoney.Text)) { MessageBox.Show("想吃霸王餐做你的美梦去吧"); return; } if (Convert.ToDecimal(txtMoney.Text) < Convert.ToDecimal(lblMoney.Text)) { MessageBox.Show("这点钱只能买个茶叶蛋"); return; } //餐桌状态改变 DeskInfoBll dbll = new DeskInfoBll(); bool dkFlag = dbll.UpdateDeskStateByDeskId(this.dkId, 0); OrderInfo order = new OrderInfo(); if (cmbMemmber.SelectedIndex != 0) { MemmberInfo mem = cmbMemmber.SelectedItem as MemmberInfo; order.OrderMemId = mem.MemmberId; //会员的id order.DisCount = mem.MemDiscount; //折扣 //会员的余额. decimal money = Convert.ToDecimal(mem.MemMoney) - Convert.ToDecimal(lblMoney.Text); //判断给你们了 //更新会员卡内的钱 MemmberInfoBll memBll = new MemmberInfoBll(); bool memFlag = memBll.UpdateMoneyByMemId(mem.MemmberId, money); } //订单的状态改变,钱,会员的id,折扣 order.EndTime = System.DateTime.Now;//结束时间 order.OrderId = Convert.ToInt32(labOrderId.Text); order.OrderMoney = Convert.ToDecimal(lblMoney.Text); OrderInfoBll obll = new OrderInfoBll(); bool oFlag = obll.UpdateOrderInfoMoney(order); if (dkFlag && oFlag) { MessageBox.Show("结账成功"); } else { MessageBox.Show("失败"); } }
//根据delflag会员是否删除0未删除1已经删除 /// <summary> /// 把表给全部导出来 /// </summary> /// <param name="delFlag"></param> /// <returns></returns> public List <MemmberInfo> GetAllMemmberInfoByDelflag(int delFlag) { string sql = "select MemmberId,MemName,MemMobilePhone,MemAddress,MemType,MemNum,MemGender,MemDiscount,MemMoney,SubTime,MemIntegral,MemEndServerTime,MemBirthdaty from MemmberInfo where DelFlag=@DelFlag"; DataTable dt = Sqlitehelper.ExecuteTable(sql, new SQLiteParameter("@DelFlag", delFlag)); List <MemmberInfo> list = new List <MemmberInfo>(); if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { MemmberInfo mem = RowToMemmberInfo(dr); list.Add(mem); } } return(list); }
//修改会员 2表示是修改 private void btnUpdateMember_Click(object sender, EventArgs e) { //FrmChangeMemmber fcm = new FrmChangeMemmber(); //fcm.ShowDialog(); if (dgvMemmber.SelectedRows.Count > 0) { int id = Convert.ToInt32(dgvMemmber.SelectedRows[0].Cells[0].Value); //根据id去数据库查询这条数据是否存在 MemmberInfoBLL bll = new MemmberInfoBLL(); MemmberInfo mem = bll.GetMemmberInfoByMemmberId(id); fea.obj = mem; ShowFrmChangeMemmber(2); } else { MessageBox.Show("请选择要修改的数据"); } }
/// <summary> /// 根据会员id获取会员的级别还有金额还有折扣 /// </summary> /// <param name="memId">会员id</param> /// <returns></returns> public MemmberInfo GetMemMoneyAndDisCountAndTypeNameByMemId(int memId) { string sql = "select MemTpName,MemDiscount,MemMoney from MemmberInfo inner join MemmberType on MemmberType.MemType=MemmberInfo.MemType where MemmberInfo.DelFlag=0 and MemmberId=@MemmberId"; SQLiteDataReader reader = SqliteHelper.ExecuteReader(sql, new SQLiteParameter("@MemmberId", memId)); MemmberInfo mem = null; if (reader.HasRows) { while (reader.Read()) { mem = new MemmberInfo(); mem.MemTpName = reader["MemTpName"].ToString(); mem.MemMoney = Convert.ToDecimal(reader["MemMoney"]); mem.MemDiscount = Convert.ToDecimal(reader["MemDiscount"]); } } return(mem); }
//关系转对象 private MemmberInfo RowToMemmberInfo(DataRow dr) { MemmberInfo mem = new MemmberInfo(); mem.MemAddress = dr["MemAddress"].ToString(); mem.MemBirthdaty = Convert.ToDateTime(dr["MemBirthdaty"]); mem.MemDiscount = Convert.ToDecimal(dr["MemDiscount"]); mem.MemEndServerTime = Convert.ToDateTime(dr["MemEndServerTime"]); mem.MemGender = dr["MemGender"].ToString(); mem.MemIntegral = Convert.ToInt32(dr["MemIntegral"]); mem.MemmberId = Convert.ToInt32(dr["MemmberId"]); mem.MemMobilePhone = dr["MemMobilePhone"].ToString(); mem.MemMoney = Convert.ToDecimal(dr["MemMoney"]); mem.MemName = dr["MemName"].ToString(); mem.MemNum = dr["MemNum"].ToString(); mem.MemType = Convert.ToInt32(dr["MemType"]); mem.SubTime = Convert.ToDateTime(dr["SubTime"]); return(mem); }
private void cmbMemmber_SelectedIndexChanged(object sender, EventArgs e) { if (cmbMemmber.SelectedIndex != 0) { MemmberInfoBll bll = new MemmberInfoBll(); MemmberInfo mem = cmbMemmber.SelectedItem as MemmberInfo; labTp.Text = bll.GetMemmberTpNameByMemmberId(mem.MemmberId); //会员的级别 labyeMoney.Text = mem.MemMoney.ToString(); //余额 lblDis.Text = mem.MemDiscount.ToString(); //折扣 lblMoney.Text = (Convert.ToDecimal(labMoney.Text) * mem.MemDiscount / 10).ToString(); } else { labTp.Text = ""; labyeMoney.Text = ""; lblDis.Text = ""; lblMoney.Text = labMoney.Text; } }
private void btnOk_Click(object sender, EventArgs e) { //获取会员信息 //不为空 MemmberInfo mem = new MemmberInfo(); if (IsCheck()) { mem.MemAddress = txtAddress.Text; mem.MemBirthdaty = Convert.ToDateTime(txtBirs.Text); //生日最好用控件 mem.MemDiscount = Convert.ToDecimal(txtMemDiscount.Text); //折扣 mem.MemEndServerTime = dtEndServerTime.Value; mem.MemGender = IsGender(); mem.MemIntegral = Convert.ToInt32(txtMemIntegral.Text); mem.MemMobilePhone = txtMemPhone.Text; mem.MemMoney = Convert.ToDecimal(txtmemMoney.Text); mem.MemName = txtMemName.Text; mem.MemNum = txtMemNum.Text; mem.MemType = Convert.ToInt32(cmbMemType.SelectedValue); } else { //MessageBox.Show("不能为空"); return; //没的话,直接确定会生成空值,报错 } MemmberInfoBLL bll = new MemmberInfoBLL(); //新增还是修改 if (this.Tp == 1) { mem.DelFlag = 0; mem.SubTime = System.DateTime.Now; } else if (this.Tp == 2) { mem.MemmberId = Convert.ToInt32(labId.Text); } string st = bll.SaveMemmber(mem, this.Tp) ? "操作成功" : "操作失败"; MessageBox.Show(st); this.Close(); }
//会员是否选中计算花费多少钱 private void cmbMemmber_SelectedIndexChanged(object sender, EventArgs e) { if (cmbMemmber.SelectedIndex != 0) { int memId = Convert.ToInt32(cmbMemmber.SelectedValue); MemmberInfoBLL bll = new MemmberInfoBLL(); MemmberInfo mem = bll.GetMemMoneyAndDisCountAndTypeNameByMemId(memId); labyeMoney.Text = mem.MemMoney.ToString(); //会员的余额 lblDis.Text = mem.MemDiscount.ToString(); //折扣 labTp.Text = mem.MemTpName; lblMoney.Text = (Convert.ToDecimal(labMoney.Text) * mem.MemDiscount / 10).ToString(); } else { labyeMoney.Text = ""; lblDis.Text = ""; labTp.Text = ""; lblMoney.Text = labMoney.Text; } }
//设置文本框的内容 public void SetTxt(object sender, EventArgs e) { LoadMemmberType(0); //清空所有文本框 foreach (Control item in this.Controls) { if (item is TextBox) { TextBox tb = item as TextBox; tb.Text = ""; } } FrmEventArgs fea = e as FrmEventArgs; //设置标识 this.Tp = fea.Temp; //判断是修改还是增加 if (this.Tp == 2) { MemmberInfo mem = fea.Obj as MemmberInfo; //设置所有文本框的内容 txtBirs.Text = mem.MemBirthdaty.ToString(); //生日 txtMemDiscount.Text = mem.MemDiscount.ToString(); //折扣 txtMemIntegral.Text = mem.MemIntegral.ToString(); //积分 txtmemMoney.Text = mem.MemMoney.ToString(); //余额 txtMemName.Text = mem.MemName; //会员名字 txtMemNum.Text = mem.MemNum; //会员编号 txtMemPhone.Text = mem.MemMobilePhone; //手机 dtEndServerTime.Value = Convert.ToDateTime(mem.MemEndServerTime); //有效时间 rdoMan.Checked = mem.MemGender == "男" ? true : false; rdoWomen.Checked = mem.MemGender == "女" ? true : false; labId.Text = mem.MemmberId.ToString(); cmbMemType.SelectedValue = mem.MemType; } else if (this.Tp == 1) { txtMemIntegral.Text = "0"; } }
} //存标识 //传值用 public void SetText(object sender, EventArgs e) { LoadMemmberType(); FrmEventArgs fea = e as FrmEventArgs; this.Tp = fea.Temp; //if (fea.Temp==1) //{ foreach (Control item in this.Controls) { if (item is TextBox) { TextBox tb = item as TextBox; //把控件转成文本框 tb.Text = ""; } } //}else if(fea.Temp==2)//修改 if (fea.Temp == 2) { MemmberInfo mem = fea.obj as MemmberInfo; txtBirs.Text = mem.MemBirthdaty.ToString(); txtMemDiscount.Text = mem.MemDiscount.ToString(); txtMemIntegral.Text = mem.MemIntegral.ToString(); txtmemMoney.Text = mem.MemMoney.ToString(); txtMemName.Text = mem.MemName; txtMemNum.Text = mem.MemNum; txtAddress.Text = mem.MemAddress; txtMemPhone.Text = mem.MemMobilePhone; cmbMemType.SelectedIndex = mem.MemType; rdoMan.Checked = mem.MemGender == "男" ? true : false; rdoWomen.Checked = mem.MemGender == "女" ? true : false; labId.Text = mem.MemmberId.ToString(); } else if (fea.Temp == 1) { txtMemIntegral.Text = "0"; } }
//增加或者是修改 private void btnOk_Click(object sender, EventArgs e) { //判断文本框不能为空 if (IsCheck()) { //判断是新增还是修改 MemmberInfo mem = new MemmberInfo(); //地址没写 mem.MemBirthdaty = Convert.ToDateTime(txtBirs.Text); //生日最好用控件 mem.MemDiscount = Convert.ToDecimal(txtMemDiscount.Text); //折扣 mem.MemEndServerTime = dtEndServerTime.Value; mem.MemGender = IsGender(); mem.MemIntegral = Convert.ToInt32(txtMemIntegral.Text); mem.MemMobilePhone = txtMemPhone.Text; mem.MemMoney = Convert.ToDecimal(txtmemMoney.Text); mem.MemName = txtMemName.Text; mem.MemNum = txtMemNum.Text; mem.MemType = Convert.ToInt32(cmbMemType.SelectedValue); if (this.Tp == 1)//新增 { mem.DelFlag = 0; mem.SubTime = DateTime.Now; } else if (this.Tp == 2)//修改id { mem.MemmberId = Convert.ToInt32(labId.Text); } //调用方法 是新增还是修改 MemmberInfoBLL bll = new MemmberInfoBLL(); string msg = bll.SaveMemmberInfo(mem, this.Tp)?"操作成功":"操作失败"; MessageBox.Show(msg); this.Close(); } }
public void SetText(object sender, EventArgs e) { LoadMemmberTypeByDelFlag(0); MyEventArgs mea = e as MyEventArgs; this.TP = mea.Temp; if (this.TP == 1) { foreach (Control item in this.Controls) { if (item is TextBox) { TextBox tb = item as TextBox; tb.Text = ""; } } txtMemIntegral.Text = "0"; rdoMan.Checked = true; } else if (this.TP == 2) { MemmberInfo mem = mea.Obj as MemmberInfo; txtBirs.Text = mem.MemBirthdaty.ToString(); txtMemDiscount.Text = mem.MemDiscount.ToString(); txtMemIntegral.Text = mem.MemIntegral.ToString(); txtmemMoney.Text = mem.MemMoney.ToString(); txtMemName.Text = mem.MemName; txtMemNum.Text = mem.MemNum; txtMemPhone.Text = mem.MemMobilePhone; rdoMan.Checked = mem.MemGender == "男" ? true : false; rdoWomen.Checked = mem.MemGender == "女" ? true : false; dtEndServerTime.Value = Convert.ToDateTime(mem.MemEndServerTime); labId.Text = mem.MemmberId.ToString(); cmbMemType.SelectedValue = mem.MemType; } }
//修改会员 public int UpdateMemmberInfo(MemmberInfo memmber) { string sql = "update MemmberInfo set MemName=@MemName,MemMobilePhone=@MemMobilePhone,MemAddress=@MemAddress,MemType=@MemType,MemNum=@MemNum,MemGender=@MemGender,MemDiscount=@MemDiscount,MemMoney=@MemMoney,MemIntegral=@MemIntegral,MemEndServerTime=@MemEndServerTime,MemBirthdaty=@MemBirthdaty where MemmberId=@MemmberId"; return(AddAndUpdate(memmber, sql, 2)); }