public List <MoneyRecord> GetMoneyRecordsBy(string where) { List <MoneyRecord> elements = new List <MoneyRecord>(); string w = ""; if (!string.IsNullOrEmpty(where)) { w = where.Trim().ToLower(); if (!w.StartsWith("where ")) { w = "where " + w; } } string sql = "select * from TF_MoneyRecord " + w + " order by 发生时间 desc"; DataTable dt = sqlHelper.Query(sql); if (dt != null && dt.Rows.Count > 0) { MemberMoneyLogic mml = MemberMoneyLogic.GetInstance(); for (int i = 0; i < dt.Rows.Count; i++) { MoneyRecord element = new MoneyRecord(); element.ID = Convert.ToInt32(dt.Rows[i]["ID"]); element.会员账户 = mml.GetMemberMoney(Convert.ToInt32(dt.Rows[i]["MID"])); element.发生金额 = Convert.ToDecimal(dt.Rows[i]["发生金额"]); element.是否充值 = Convert.ToBoolean(dt.Rows[i]["是否充值"]); element.操作人 = dt.Rows[i]["操作人"].ToString(); element.发生时间 = Convert.ToDateTime(dt.Rows[i]["发生时间"]); elements.Add(element); } } return(elements); }
private void button2_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { if (selectMemberControl1.SelectedMembers.Count == 0) { MessageBox.Show("请先指定一个会员!"); selectMemberControl1.Focus(); return; } MoneyRecord mr = (MoneyRecord)comboBox1.SelectedItem; mr.会员账户 = MemberMoneyLogic.GetInstance().GetMemberMoney(selectMemberControl1.SelectedMembers[0]); mr.发生金额 = numericUpDown1.Value; mr.是否充值 = true; mr.操作人 = textBox3.Text; MoneyRecordLogic rl = MoneyRecordLogic.GetInstance(); if (rl.UpdateMoneyRecord(mr)) { LoadMoneyRecords(); MessageBox.Show("修改成功!"); } } else { MessageBox.Show("先选定要修改的进出账!"); } }
public static MemberMoneyLogic GetInstance() { if (instance == null) { instance = new MemberMoneyLogic(); } return(instance); }
private void button1_Click(object sender, EventArgs e) { if (selectMemberControl1.SelectedMembers.Count == 0) { MessageBox.Show("请先指定一个会员!"); selectMemberControl1.Focus(); return; } Member member = selectMemberControl1.SelectedMembers[0]; MemberMoneyLogic mml = MemberMoneyLogic.GetInstance(); string name = member.姓名; string mobile = member.电话; MemberMoney mm = null; if (!mml.ExistsName(name, mobile)) { mm = new MemberMoney(); mm.会员姓名 = name; mm.会员电话 = mobile; mm.备注 = "账户创建于" + DateTime.Now.ToString(); int id = mml.AddMemberMoney(mm); if (id > 0) { mm.ID = id; } } else { mm = mml.GetMemberMoney(name, mobile); } if (mm != null) { MoneyRecord mr = new MoneyRecord(); mr.会员账户 = mm; mr.发生金额 = numericUpDown1.Value; mr.是否充值 = true; mr.操作人 = textBox3.Text; if (MoneyRecordLogic.GetInstance().AddMoneyRecord(mr) > 0) { LoadMoneyRecords(); MessageBox.Show("保存会员消费记录以及扣款成功!"); } else { MessageBox.Show("保存会员消费记录失败或者扣款失败!"); } } else { MessageBox.Show("无法创建会员账户!"); } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { MoneyRecord record = comboBox1.SelectedItem as MoneyRecord; if (record != null) { textBox3.Text = record.操作人; selectMemberControl1.SelectedMembers = new List <Member>() { MemberMoneyLogic.GetInstance().GetMember(record.会员账户) }; } } }
public MoneyRecord GetMoneyRecord(int id) { string sql = "select * from TF_MoneyRecord where ID=" + id; DataTable dt = sqlHelper.Query(sql); if (dt != null && dt.Rows.Count > 0) { MoneyRecord element = new MoneyRecord(); element.ID = id; element.会员账户 = MemberMoneyLogic.GetInstance().GetMemberMoney(Convert.ToInt32(dt.Rows[0]["MID"])); element.发生金额 = Convert.ToDecimal(dt.Rows[0]["发生金额"]); element.是否充值 = Convert.ToBoolean(dt.Rows[0]["是否充值"]); element.操作人 = dt.Rows[0]["操作人"].ToString(); element.发生时间 = Convert.ToDateTime(dt.Rows[0]["发生时间"]); return(element); } return(null); }
public List <MoneyRecord> GetMoneyRecordsByMemberMobile(string mobile) { List <MoneyRecord> elements = new List <MoneyRecord>(); string sql = "select TF_MoneyRecord.* from TF_MoneyRecord,TF_MemberMoney where TF_MoneyRecord.MID=TF_MemberMoney.ID and TF_MemberMoney.会员电话='" + mobile + "' order by TF_MoneyRecord.发生时间 desc"; DataTable dt = sqlHelper.Query(sql); if (dt != null && dt.Rows.Count > 0) { MemberMoneyLogic mml = MemberMoneyLogic.GetInstance(); for (int i = 0; i < dt.Rows.Count; i++) { MoneyRecord element = new MoneyRecord(); element.ID = Convert.ToInt32(dt.Rows[i]["ID"]); element.会员账户 = mml.GetMemberMoney(Convert.ToInt32(dt.Rows[i]["MID"])); element.发生金额 = Convert.ToDecimal(dt.Rows[i]["发生金额"]); element.是否充值 = Convert.ToBoolean(dt.Rows[i]["是否充值"]); element.操作人 = dt.Rows[i]["操作人"].ToString(); element.发生时间 = Convert.ToDateTime(dt.Rows[i]["发生时间"]); elements.Add(element); } } return(elements); }
public int AddMoneyRecord(MoneyRecord element) { if (element.会员账户 == null) { return(0); } string sql = "insert into TF_MoneyRecord (MID, 发生金额, 是否充值, 操作人) values (" + element.会员账户.ID + ", " + element.发生金额 + ", " + (element.是否充值 ? "1" : "0") + ", '" + element.操作人 + "'); select SCOPE_IDENTITY()"; object obj = sqlHelper.ExecuteSqlReturn(sql); int R; if (obj != null && obj != DBNull.Value && int.TryParse(obj.ToString(), out R)) { decimal rest = element.会员账户.账户余额; if (element.是否充值) { rest += element.发生金额; } else { rest -= element.发生金额; } element.会员账户.账户余额 = rest; if (MemberMoneyLogic.GetInstance().UpdateMemberMoney(element.会员账户)) { return(R); } else { return(0); } } else { return(0); } }
private DataTable Search(string name, string mobile, decimal lessThan) { return(MemberMoneyLogic.GetInstance().GetMemberMoneysBy(name, mobile, lessThan)); }
private void LoadAllMemberMoneys() { DataTable dt = MemberMoneyLogic.GetInstance().GetMemberMoneysBy(string.Empty); dataGridView1.DataSource = dt; }
private void button1_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex == -1) { MessageBox.Show("请先选择要出库的产品!"); comboBox1.Focus(); return; } int num = 0; int R; if (int.TryParse(textBox1.Text.Trim(), out R)) { num = R; } else { MessageBox.Show("数量必须为整数!"); textBox1.Focus(); textBox1.SelectAll(); return; } decimal price = 0; decimal r; if (decimal.TryParse(textBox2.Text.Trim(), out r)) { price = r; } else { MessageBox.Show("实价必须为整数!"); textBox2.Focus(); textBox2.SelectAll(); return; } if (checkBox1.Checked) { if (selectMemberControl1.SelectedMembers.Count == 0) { MessageBox.Show("请选择当前消费的会员!"); selectMemberControl1.Focus(); return; } } Income element = new Income(); element.PID = ((Product)comboBox1.SelectedItem).ID; element.IsProduct = true; element.IsIncome = false; element.数量 = num; element.实价 = price; element.经手人 = textBox3.Text.Trim(); element.备注 = textBox4.Text.Trim(); if (IncomeLogic.GetInstance().AddIncome(element) > 0) { MessageBox.Show("登记成功!"); if (checkBox1.Checked) { Member member = selectMemberControl1.SelectedMembers[0]; decimal sum = num * price; if (sum > 0) { MemberMoneyLogic mml = MemberMoneyLogic.GetInstance(); string name = member.姓名; string mobile = member.电话; MemberMoney mm = null; if (!mml.ExistsName(name, mobile)) { mm = new MemberMoney(); mm.会员姓名 = name; mm.会员电话 = mobile; mm.备注 = "账户创建于" + DateTime.Now.ToString(); mml.AddMemberMoney(mm); } else { mm = mml.GetMemberMoney(name, mobile); } if (mm != null) { MoneyRecord mr = new MoneyRecord(); mr.会员账户 = mm; mr.发生金额 = sum; mr.是否充值 = false; mr.操作人 = element.经手人; if (MoneyRecordLogic.GetInstance().AddMoneyRecord(mr) > 0) { MessageBox.Show("保存会员消费记录以及扣款成功!"); } else { MessageBox.Show("保存会员消费记录失败或者扣款失败!"); } } else { MessageBox.Show("无法创建会员账户!"); } } else { MessageBox.Show("消费额不能为负!"); } } } else { MessageBox.Show("登记失败!"); } }