/// <summary> /// 单据作废 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbInvalid_Click(object sender, EventArgs e) { if (lbl_vouchNoValue.Text != "") { try { using (var db = new ScrapSettleContext()) { WeighingSettlementModel w = db.WeighingSettlement.Where(s => s.vocherNO == lbl_vouchNoValue.Text).FirstOrDefault(); if (true) { } w.auditFlag = (int)EnumModle.voucherStatus.作废; db.SaveChanges(); MessageBox.Show("单据作废成功", "作废提示"); lbl_voucherStateValue.Text = EnumModle.voucherStatus.作废.ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.InnerException, "错误提示"); } } else { MessageBox.Show("当前无可作废单据!"); } }
/// <summary> /// 删除选择定行 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsb_delete_Click(object sender, EventArgs e) { if (dataGridView1.Rows.Count > 0) { Int32 selected = (Int32)this.dataGridView1.SelectedRows[0].Cells[0].Value; if (DialogResult.Yes == MessageBox.Show("是否确定删除", "删除提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { ScrapSettleContext db = new ScrapSettleContext(); List <Customer> delCustomer = (from del in db.Customers where del.CusCode == selected select del).ToList <Customer>(); //移除数据库的数据 db.Customers.Remove(delCustomer[0]); db.SaveChanges(); clearDate(); //如果是在新增界面状态使用删除功能,则同时删除内存中的集合数据 //数据库中的条件实体delCustomer不能成为内存中的待删除实体 //即:customerList.Remove(delCustomer[0])返回false,故无法实现 //内存当中的数据集记录删除; if (saveOrModifQueryFlag == saveOrChangeOrQueryMolde.save.ToString()) { List <Customer> customer = customerList.Where(c => c.CusCode == System.Convert.ToInt32(selected)).ToList <Customer>(); customerList.Remove(customer[0]); } bind_gv_dateSource(); } } return; }
/// <summary> /// 删除选择定行 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsb_delete_Click(object sender, EventArgs e) { if (dataGridView1.Rows.Count > 0) { string selected = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); if (DialogResult.Yes == MessageBox.Show("是否确定删除", "删除提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { ScrapSettleContext db = new ScrapSettleContext(); List <Coefficient> del = (from d in db.Coefficients where d.VoucherNO == selected select d).ToList <Coefficient>(); //移除数据库的数据 db.Coefficients.Remove(del[0]); db.SaveChanges(); clearDate(); //如果是在新增界面状态使用删除功能,则同时删除内存中的集合数据 //数据库中的条件实体delCustomer不能成为内存中的待删除实体 //即:customerList.Remove(delCustomer[0])返回false,故无法实现 //内存当中的数据集记录删除; if (saveOrModifQueryFlag == saveOrChangeOrQueryMolde.save.ToString()) { List <Coefficient> coefficients = archivesList.Where(c => c.VoucherNO == selected).ToList <Coefficient>(); archivesList.Remove(coefficients[0]); } bind_gv_dateSource(); } } return; }
/// <summary> /// 保存收款单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsb_save_Click(object sender, EventArgs e) { if (new ValidateClear().inputVlidate(tableLayoutPanel1)) { using (var db = new ScrapSettleContext()) { Income income = new Income(); income.CustormerID = Convert.ToInt32(cmb_custName.SelectedValue); income.MakeDte = dtp_make.Value; income.Money = Convert.ToDouble(txt_money.Text); income.VoucherNo = lbl_vouchNoValue.Text; income.IncomeDate = dtp_income.Value.Date; try { db.Incomes.Add(income); db.SaveChanges(); tsb_save.Enabled = false; new ValidateClear().clearDate(tableLayoutPanel1); } catch (Exception ex) { MessageBox.Show("数据保存错误:" + ex.Message + ex.InnerException, "数据保存提示"); return; } } } }
private void tsb_delete_Click(object sender, EventArgs e) { if (dgv_content.Rows.Count > 0) { var selected = dgv_content.SelectedRows[0].Cells[2].Value; ScrapSettleContext db = new ScrapSettleContext(); List <WeighingSettlementModel> del = (from d in db.WeighingSettlement where d.vocherNO == selected.ToString() select d).ToList <WeighingSettlementModel>(); foreach (var item in del) { if (item.auditFlag != 2) { if (DialogResult.Yes == MessageBox.Show("是否确定删除", "删除提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { //移除数据库的数据 db.WeighingSettlement.Remove(del[0]); db.SaveChanges(); tsb_query.PerformClick(); } } else { MessageBox.Show("单据已经审核,不能删除", "删除提示"); } } } return; }
/// <summary> /// 单据批审 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsb_batchAudit_Click(object sender, EventArgs e) { if (JudgeDataGridViewCheckBoxState().Count > 0) { try { using (var db = new ScrapSettleContext()) { foreach (var item in JudgeDataGridViewCheckBoxState()) { WeighingSettlementModel w = db.WeighingSettlement.Where(s => s.vocherNO == item).FirstOrDefault(); w.auditFlag = (int)EnumModle.voucherStatus.审核; } db.SaveChanges(); MessageBox.Show("单据审核成功", "审核提示"); tsb_query.PerformClick(); } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.InnerException, "审核错误提示"); } } else { MessageBox.Show("请选择需要审核的单据", "批审提醒"); } }
/// <summary> /// 数据保存与修改 /// </summary> private void saveOrChang() { if (inputVlidate()) { //新增后保存 if (saveOrModifQueryFlag == saveOrChangeOrQueryMolde.save.ToString()) { using (var db = new ScrapSettleContext()) { Customer customer = new Customer(); customer.CusCode = Convert.ToInt32(txt_cusCode.Text); customer.CusName = this.txt_cusName.Text; customer.EffectDate = Convert.ToDateTime(this.tbd_effect.Text); if (this.tbd_failure.Text != null & tbd_failure.Text != "") { customer.FailuerDate = Convert.ToDateTime(this.tbd_failure.Text); } db.Customers.Add(customer); try { db.SaveChanges(); } catch (Exception e) { MessageBox.Show("数据保存错误:" + e.Message + e.InnerException, "数据保存提示"); return; } customerList.Add(customer); //this.dataGridView1.DataSource = null; //this.dataGridView1.DataSource = customerList; //MessageBox.Show("数据保存成功", "保存提示"); this.bind_gv_dateSource(); //清空填制记录 //this.txt_cusCode.Text = null; //this.txt_cusName.Text = null; clearDate(); //再次调用新增事件 this.tsb_add.PerformClick(); } } if (saveOrModifQueryFlag == saveOrChangeOrQueryMolde.query.ToString()) { updateDate(); } } ; }
/// <summary> /// 单据删除方法 /// </summary> /// <param name="sender"></param> /// <param name="authorizationEventArgs"></param> private void deleteVoucher(Object sender, AuthorizationEventArgs authorizationEventArgs) { if (lbl_vouchNoValue.Text != "" & lbl_vouchNoValue.Text != null & lbl_voucherStateValue.Text != EnumModle.voucherStatus.审核.ToString()) { if (DialogResult.Yes == MessageBox.Show("是否确定删除", "删除提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { try { using (var db = new ScrapSettleContext()) { var del = (from d in db.WeighingSettlement where (d.vocherNO == lbl_vouchNoValue.Text) select d).ToList();; //移除数据库的数据 db.WeighingSettlement.Remove(del[0]); db.SaveChanges(); clearDate(); lbl_vouchNoValue.Text = ""; dtp_makeDate.Text = ""; rtxt_voucherNO.Text = ""; //修改单据功能状态 tsb_delete.Enabled = false; tsb_modify.Enabled = false; tsb_previewPrint.Enabled = false; tsb_print.Enabled = false; lbl_voucherStateValue.Text = ""; } } catch (Exception ex) { MessageBox.Show("数据删除出错" + ex.Message + ex.InnerException, "数据删除提示"); } } } else { MessageBox.Show("你所删除的单据不存在或单据已经审核", "删除提示"); } }
/// <summary> /// 恢复作废单据 /// </summary> /// <param name="sender"></param> /// <param name="authorizationEventArgs"></param> private void restoreVoucher(Object sender, AuthorizationEventArgs authorizationEventArgs) { if (lbl_vouchNoValue.Text != "") { try { using (var db = new ScrapSettleContext()) { WeighingSettlementModel w = db.WeighingSettlement.Where(s => s.vocherNO == lbl_vouchNoValue.Text).FirstOrDefault(); w.auditFlag = (int)EnumModle.voucherStatus.开立; db.SaveChanges(); MessageBox.Show("单据恢复成功", "恢复提示"); lbl_voucherStateValue.Text = EnumModle.voucherStatus.开立.ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.InnerException, "单据恢复错误提示"); } } }
private void tsb_delete_Click(object sender, EventArgs e) { if (dataGridView1.Rows.Count > 0) { var selected = dataGridView1.SelectedRows[0].Cells[1].Value; if (DialogResult.Yes == MessageBox.Show("是否确定删除", "删除提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { ScrapSettleContext db = new ScrapSettleContext(); List <Income> del = (from d in db.Incomes where d.VoucherNo == selected.ToString() select d).ToList <Income>(); //移除数据库的数据 db.Incomes.Remove(del[0]); db.SaveChanges(); tsb_query.PerformClick(); } } return; }
/// <summary> /// 密码修改方法 /// </summary> /// <param name="sender"></param> /// <param name="authorizationEventArgs"></param> private void modifyPwdResult(Object sender, ModifyPwdEventArgs auth) { if (txt_cusCode.Text != "") { try { using (var db = new ScrapSettleContext()) { int code = Convert.ToInt32(txt_cusCode.Text); Person w = db.Peple.Where(s => s.Code == code).FirstOrDefault(); w.pwd = Encrypt.Encode(auth.pwd); db.SaveChanges(); MessageBox.Show("密码修改成功", "密码修改提示"); txt_pwd.Text = Encrypt.Encode(auth.pwd); } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.InnerException, "修改密码错误提示"); } } }
private void updateDate() { //查询之后修改并保存 using (var db = new ScrapSettleContext()) { Customer customer = db.Customers.Where(c => c.CusCode.ToString() == txt_cusCode.Text).FirstOrDefault(); customer.CusCode = System.Convert.ToInt32(txt_cusCode.Text); customer.CusName = this.txt_cusName.Text; customer.EffectDate = Convert.ToDateTime(this.tbd_effect.Text); //if (this.tbd_failure.Text != null & this.tbd_failure.Text != "") //{ // customer.FailuerDate = Convert.ToDateTime(this.tbd_failure.Text); //} if (this.stop) { customer.disable = true; customer.FailuerDate = DateTime.Now; } if (stop == false) { customer.disable = false; customer.FailuerDate = null; } db.SaveChanges(); MessageBox.Show("数据修改成功!"); this.bind_gv_dateSource(); //清空修改记录 clearDate(); } }
/// <summary> /// 数据保存与修改 /// </summary> private void saveOrChang() { if (inputVlidate()) { //新增后保存 if (saveOrModifQueryFlag == saveOrChangeOrQueryMolde.save.ToString()) { using (var db = new ScrapSettleContext()) { Coefficient coefficient = new Coefficient(); coefficient.VoucherNO = lbl_vouchNoValue.Text; //注意组合框中的取值不是text属性,而是selectedValue coefficient.CustomerID = Convert.ToInt32(cmb_cusName.SelectedValue); coefficient.ScrapID = Convert.ToInt32(cmb_scrapName.SelectedValue); coefficient.Data = Convert.ToDouble(txt_data.Text); coefficient.EffectDate = Convert.ToDateTime(this.tbd_effect.Text); if (this.tbd_failure.Text != null & tbd_failure.Text != "") { coefficient.FailureDate = Convert.ToDateTime(this.tbd_failure.Text); } try { db.Coefficients.Add(coefficient); db.SaveChanges(); //内存数据源 archivesList.Add(coefficient); var query = from q in archivesList join c in db.Customers on q.CustomerID equals c.CusCode join s in db.Scraps on q.ScrapID equals s.ScrapCode select new { q.VoucherNO, c.CusName, s.ScrapName, q.Data, q.EffectDate, q.FailureDate }; dataGridView1.DataSource = query.ToList(); } catch (Exception e) { MessageBox.Show("数据保存错误:" + e.Message + e.InnerException, "数据保存提示"); return; } clearDate(); //再次调用新增事件 this.tsb_add.PerformClick(); } } //查询之后修改并保存 if (saveOrModifQueryFlag == saveOrChangeOrQueryMolde.query.ToString()) { using (var db = new ScrapSettleContext()) { Coefficient coefficient = db.Coefficients.Where(c => c.VoucherNO.ToString() == lbl_vouchNoValue.Text).FirstOrDefault(); coefficient.CustomerID = Convert.ToInt32(cmb_cusName.SelectedValue); coefficient.ScrapID = Convert.ToInt32(cmb_scrapName.SelectedValue); coefficient.Data = Convert.ToDouble(txt_data.Text); coefficient.EffectDate = Convert.ToDateTime(this.tbd_effect.Text); if (this.tbd_failure.Text != null & tbd_failure.Text != "") { coefficient.FailureDate = Convert.ToDateTime(this.tbd_failure.Text); } try { db.SaveChanges(); this.bind_gv_dateSource(); } catch (Exception e) { MessageBox.Show("数据保存错误:" + e.Message + e.InnerException, "数据保存提示"); return; } //清空修改记录 clearDate(); } } } ; }
/// <summary> /// 数据保存与修改 /// </summary> private void saveOrChang() { if (inputVlidate()) { //新增后保存 if (saveOrModifQueryFlag == saveOrChangeOrQueryMolde.save.ToString()) { using (var db = new ScrapSettleContext()) { VehicleBrand v = new VehicleBrand(); //注意组合框中的取值不是text属性,而是selectedValue v.CustomerID = Convert.ToInt32(cmb_cusName.SelectedValue); v.VehicleBrandValue = txt_vehicleBrandValue.Text; v.EffectDate = Convert.ToDateTime(this.tbd_effect.Text); if (this.tbd_failure.Text != null & tbd_failure.Text != "") { v.FailuerDate = Convert.ToDateTime(this.tbd_failure.Text); } try { db.VehicleBrands.Add(v); db.SaveChanges(); //内存数据源 archivesList.Add(v); var query = from q in archivesList join c in db.Customers on q.CustomerID equals c.CusCode select new { c.CusName, q.VehicleBrandValue, q.EffectDate, q.FailuerDate }; dataGridView1.DataSource = query.ToList(); } catch (Exception e) { MessageBox.Show("数据保存错误:" + e.Message + e.InnerException, "数据保存提示"); return; } clearDate(); //再次调用新增事件 this.tsb_add.PerformClick(); } } //查询之后修改并保存 if (saveOrModifQueryFlag == saveOrChangeOrQueryMolde.query.ToString()) { using (var db = new ScrapSettleContext()) { VehicleBrand v = db.VehicleBrands.Where(c => c.VehicleBrandValue == txt_vehicleBrandValue.Text).FirstOrDefault(); v.CustomerID = Convert.ToInt32(cmb_cusName.SelectedValue); v.VehicleBrandValue = txt_vehicleBrandValue.Text; v.EffectDate = Convert.ToDateTime(this.tbd_effect.Text); if (this.tbd_failure.Text != null & tbd_failure.Text != "") { v.FailuerDate = Convert.ToDateTime(this.tbd_failure.Text); } try { db.SaveChanges(); this.bind_gv_dateSource(); } catch (Exception e) { MessageBox.Show("数据保存错误:" + e.Message + e.InnerException, "数据保存提示"); return; } //清空修改记录 clearDate(); } } } ; }
/// <summary> /// 数据保存算法 /// </summary> /// <param name="db"></param> /// <param name="w"></param> private void saveData(ScrapSettleContext db, WeighingSettlementModel w) { //查询时的过滤条件是日期,所以存储值若含时间信息则条件值与存储值比较产生的 //结果非目标数据,如查询当时的数据,因为按日期存储时其默认的时间信息是0时0分0秒 //而查询条年是>=当日与<=当时,其查询结果则会为无匹配数据 //故只按日期存储 //修改数据保存准备 if (addOrChangeFlag == addOrChangeMolde.change.ToString()) { w.webUnitPrice = String.IsNullOrEmpty(txt_webUnitPrice.Text) is true ? 0 : Convert.ToDouble(txt_webUnitPrice.Text); w.settleUnitPrice = String.IsNullOrEmpty(txt_settleUnitPrice.Text) is true ? 0 : Convert.ToDouble(txt_settleUnitPrice.Text); w.settleAmount = String.IsNullOrEmpty(txt_money.Text) is true ? 0 : Convert.ToDouble(txt_money.Text); w.note = txtNote.Text; } //新增数据保存准备 if (addOrChangeFlag == addOrChangeMolde.add.ToString()) { w.MakeDate = DateTime.Now; w.WeighingDate = dtp_makeDate.Value.Date; w.WeightingTime = dtp_makeDate.Value.ToLongTimeString(); w.CustmerCode = cmb_custName.SelectedValue.ToString(); w.GrossWeght = Convert.ToDouble(txt_grossWeight.Text); w.Tare = Convert.ToDouble(txt_tare.Text); w.netWeight = txt_netWeight.Text == "" ? w.GrossWeght - w.Tare : Convert.ToDouble(txt_netWeight.Text); w.VehicleBrand = cmb_vehicleBrand.Text; w.personCode = cmb_person.SelectedValue.ToString(); w.proportion = Convert.ToDouble(txt_coefficient.Text); w.scrapCode = cmb_scrapName.SelectedValue.ToString(); w.vocherNO = lbl_vouchNoValue.Text; w.auditFlag = (int)EnumModle.voucherStatus.开立; w.note = txtNote.Text; //考虑到价格信息由业务经办人填写,而非由过磅人填写,故可为空 //w.webUnitPrice = Convert.ToDouble(txt_webUnitPrice.Text); //w.settleUnitPrice = Convert.ToDouble(txt_settleUnitPrice.Text); //w.settleAmount = Convert.ToDouble(txt_money.Text); w.webUnitPrice = txt_webUnitPrice.Text == "" ? 0 : Convert.ToDouble(txt_webUnitPrice.Text); w.settleUnitPrice = txt_settleUnitPrice.Text == "" ? 0 : Convert.ToDouble(txt_settleUnitPrice.Text); w.settleAmount = txt_money.Text == "" ? 0 : Convert.ToDouble(txt_money.Text); db.WeighingSettlement.Add(w); } //数据保存 try { db.SaveChanges(); tsb_save.Enabled = false; tsb_print.Enabled = true; tsb_previewPrint.Enabled = true; tableLayoutPanel1.Enabled = false; if (addOrChangeFlag == addOrChangeMolde.change.ToString()) { tsb_new.Enabled = true; tsb_audit.Enabled = true; } if (addOrChangeFlag == addOrChangeMolde.add.ToString()) { tsb_modify.Enabled = true; tsb_delete.Enabled = true; tsb_audit.Enabled = true; } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.InnerException, "保存错误提示"); } }
/// <summary> /// 数据保存与修改 /// </summary> private void saveOrChang() { if (inputVlidate()) { //新增后保存 if (saveOrModifQueryFlag == saveOrChangeOrQueryMolde.save.ToString()) { using (var db = new ScrapSettleContext()) { Person person = new Person(); person.Code = Convert.ToInt32(txt_cusCode.Text); person.Name = this.txt_cusName.Text; person.pwd = Encrypt.Encode(txt_pwd.Text); person.EffectDate = Convert.ToDateTime(this.tbd_effect.Text); if (this.tbd_failure.Text != null & tbd_failure.Text != "") { person.FailuerDate = Convert.ToDateTime(this.tbd_failure.Text); } db.Peple.Add(person); try { db.SaveChanges(); } catch (Exception e) { MessageBox.Show("数据保存错误:" + e.Message + e.InnerException, "数据保存提示"); return; } archivesList.Add(person); this.bind_gv_dateSource(); //清空填制记录 clearDate(); //再次调用新增事件 this.tsb_add.PerformClick(); } } //查询之后修改并保存 if (saveOrModifQueryFlag == saveOrChangeOrQueryMolde.query.ToString()) { using (var db = new ScrapSettleContext()) { Person person = db.Peple.Where(c => c.Code.ToString() == txt_cusCode.Text).FirstOrDefault(); person.Code = System.Convert.ToInt32(txt_cusCode.Text); person.Name = this.txt_cusName.Text; person.pwd = Encrypt.Encode(txt_pwd.Text); person.EffectDate = Convert.ToDateTime(this.tbd_effect.Text); if (this.tbd_failure.Text != null & this.tbd_failure.Text != "") { person.FailuerDate = Convert.ToDateTime(this.tbd_failure.Text); } db.SaveChanges(); this.bind_gv_dateSource(); //清空修改记录 clearDate(); } } } ; }
/// <summary> /// 数据保存与修改 /// </summary> private void saveOrChang() { if (inputVlidate()) { //新增后保存 if (saveOrModifQueryFlag == saveOrChangeOrQueryMolde.save.ToString()) { using (var db = new ScrapSettleContext()) { Scrap scrap = new Scrap(); scrap.ScrapCode = Convert.ToInt32(txt_cusCode.Text); scrap.ScrapName = this.txt_cusName.Text; scrap.EffectDate = Convert.ToDateTime(this.tbd_effect.Text); if (this.tbd_failure.Text != null & tbd_failure.Text != "") { scrap.FailuerDate = Convert.ToDateTime(this.tbd_failure.Text); } db.Scraps.Add(scrap); try { db.SaveChanges(); } catch (Exception e) { MessageBox.Show("数据保存错误:" + e.Message + e.InnerException, "数据保存提示"); return; } scrapList.Add(scrap); //this.dataGridView1.DataSource = null; //this.dataGridView1.DataSource = customerList; //MessageBox.Show("数据保存成功", "保存提示"); this.bind_gv_dateSource(); //清空填制记录 //this.txt_cusCode.Text = null; //this.txt_cusName.Text = null; clearDate(); //再次调用新增事件 this.tsb_add.PerformClick(); } } //查询之后修改并保存 if (saveOrModifQueryFlag == saveOrChangeOrQueryMolde.query.ToString()) { using (var db = new ScrapSettleContext()) { Scrap scrap = db.Scraps.Where(c => c.ScrapCode.ToString() == txt_cusCode.Text).FirstOrDefault(); scrap.ScrapCode = System.Convert.ToInt32(txt_cusCode.Text); scrap.ScrapName = this.txt_cusName.Text; scrap.EffectDate = Convert.ToDateTime(this.tbd_effect.Text); if (this.tbd_failure.Text != null & this.tbd_failure.Text != "") { scrap.FailuerDate = Convert.ToDateTime(this.tbd_failure.Text); } db.SaveChanges(); this.bind_gv_dateSource(); //清空修改记录 clearDate(); } } } ; }