/// <summary> /// Linq动态查询参数 /// </summary> /// <param name="m"></param> /// <param name="cusCode"></param> /// <param name="voucherState"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns></returns> private bool GetCondition(WeighingSettlementModel m, string cusCode, int voucherState, DateTime startDate, DateTime endDate) { bool boolResult = true; if (!String.IsNullOrEmpty(cusCode)) { boolResult &= m.CustmerCode == cusCode; } //如果为空则默认包含所有单据状态,因为文本为空时,selectValue是有值的 if (!String.IsNullOrEmpty(voucherState.ToString()) && !String.IsNullOrEmpty(cmbVoucherState.Text)) { boolResult &= m.auditFlag == voucherState; } //过磅单日期 if (!String.IsNullOrEmpty(startDate.ToString())) { boolResult &= m.WeighingDate >= startDate; } if (!String.IsNullOrEmpty(endDate.ToString())) { boolResult &= m.WeighingDate <= endDate; } return(boolResult); }
/// <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> /// <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_save_Click(object sender, EventArgs e) { if (addOrChangeFlag == addOrChangeMolde.add.ToString()) { using (var db = new ScrapSettleContext()) { WeighingSettlementModel w = new WeighingSettlementModel(); saveData(db, w); } } if (addOrChangeFlag == addOrChangeMolde.change.ToString()) { using (var db = new ScrapSettleContext()) { WeighingSettlementModel w = db.WeighingSettlement.Where(s => s.vocherNO == lbl_vouchNoValue.Text).FirstOrDefault(); saveData(db, w); } } }
/// <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, "单据恢复错误提示"); } } }
/// <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, "保存错误提示"); } }