/// <summary> /// 提交编辑 /// </summary> private bool SubmintEdit() { if (FkOrderChecked != null) { FkOrderChecked.FCode = txtFCode.Text; FkOrderChecked.FName = tbxFCustomer.Text; FkOrderChecked.FMemo = txtFMemo.Text.Trim(); return(FkOrderCheckedService.SaveChanges() >= 0); } return(false); }
/// <summary> /// 提交添加 /// </summary> private bool SubmintAdd() { var order = FkOrderCheckedService.Where(p => p.KeyId == txtKeyId.Text.Trim() && p.FCompanyId == CurrentUser.AccountComId).FirstOrDefault(); if (order != null) { //核销主单据 //-------------------------------------------------- order.FCode = txtFCode.Text; order.FName = tbxFCustomer.Text; //-------------------------------------------------- order.FDeleteFlag = 0; order.FMemo = txtFMemo.Text.Trim(); order.CreateBy = CurrentUser.AccountName; order.FDate = txtFDate.SelectedDate; //本次实际核销的金额 decimal checkedAmt = 0.00M; //收款单 decimal sksum = 0.00M; int[] sks = Grid1.SelectedRowIndexArray; for (int i = 0; i < sks.Length; i++) { sksum += Convert.ToDecimal(Grid1.DataKeys[Grid1.SelectedRowIndexArray[i]][2].ToString()); } if (sksum <= 0) { Alert.Show("要核销的收款单已核销完,暂无需核销单据。", MessageBoxIcon.Information); return(false); } //销售金额 decimal salesum = 0.00M; int[] sales = Grid2.SelectedRowIndexArray; for (int i = 0; i < sales.Length; i++) { salesum += Convert.ToDecimal(Grid2.DataKeys[Grid2.SelectedRowIndexArray[i]][1].ToString()); } if (sksum <= 0) { Alert.Show("要核销的发货单已核销完,暂无需核销单据。", MessageBoxIcon.Information); return(false); } if (sksum == salesum) { //实际核销款 checkedAmt = sksum; for (int i = 0; i < sks.Length; i++) { int id = Convert.ToInt32(Grid1.DataKeys[sks[i]][1].ToString()); string keyid = Grid1.DataKeys[Grid1.SelectedRowIndexArray[i]][0].ToString(); var banks = new LHFKOrderCheckedBanks(); banks.KeyId = txtKeyId.Text; banks.CBankId = id; banks.FAmt = Convert.ToDecimal(Grid1.DataKeys[sks[i]][2]); banks.FCompanyId = CurrentUser.AccountComId; var bank = FkOrderCheckedBanksService.Where(p => p.KeyId == txtKeyId.Text && p.CBankId == id && p.FCompanyId == CurrentUser.AccountComId).FirstOrDefault(); if (bank != null) { FkOrderCheckedBanksService.SaveChanges(); } else { FkOrderCheckedBanksService.Add(banks); } } for (int i = 0; i < sales.Length; i++) { string keyid = Grid2.DataKeys[Grid2.SelectedRowIndexArray[i]][0].ToString(); var details = new LHFKOrderCheckedDetails(); details.KeyId = txtKeyId.Text; details.FSaleKeyId = keyid; details.FAmount = Convert.ToDecimal(Grid2.DataKeys[sks[i]][1]); details.FCompanyId = CurrentUser.AccountComId; var detail = FkOrderCheckedDetailsService.Where(p => p.KeyId == txtKeyId.Text && p.FSaleKeyId == keyid && p.FCompanyId == CurrentUser.AccountComId) .FirstOrDefault(); if (detail != null) { FkOrderCheckedDetailsService.SaveChanges(); } else { FkOrderCheckedDetailsService.Add(details); } } } else if (sksum > salesum) { //实际核销款 checkedAmt = salesum; //分析 decimal kfpje = salesum; for (int i = 0; i < sks.Length; i++) { int id = Convert.ToInt32(Grid1.DataKeys[Grid1.SelectedRowIndexArray[i]][1].ToString()); //string keyid = Grid1.DataKeys[sks[i]][0].ToString(); ///////////////////////////////////////////////// var sk = Convert.ToDecimal(Grid1.DataKeys[Grid1.SelectedRowIndexArray[i]][2]); decimal hxje = 0.00M; decimal yszj = sk; if (kfpje == 0) { hxje = 0; } else { decimal kyje = kfpje - yszj; if (kyje > 0) { hxje = yszj; kfpje = kyje; } else if (kyje == 0) { hxje = kfpje; kfpje = kyje; //continue; } else { hxje = kfpje; kfpje = 0; //continue; } } ///////////////////////////////////////////////// var banks = new LHFKOrderCheckedBanks(); banks.KeyId = txtKeyId.Text; banks.CBankId = id; banks.FCompanyId = CurrentUser.AccountComId; //本次核销款 banks.FAmt = hxje; var bank = FkOrderCheckedBanksService.Where(p => p.KeyId == txtKeyId.Text && p.CBankId == id && p.FCompanyId == CurrentUser.AccountComId) .FirstOrDefault(); if (bank != null) { FkOrderCheckedBanksService.SaveChanges(); } else { FkOrderCheckedBanksService.Add(banks); } } ///////////////////////////////////////////////// decimal kfpje2 = salesum; for (int i = 0; i < sales.Length; i++) { string keyid = Grid2.DataKeys[Grid2.SelectedRowIndexArray[i]][0].ToString(); ////////////////////////////////////////////////////////// var sale = Convert.ToDecimal(Grid2.DataKeys[Grid2.SelectedRowIndexArray[i]][1]); decimal hxje = 0.00M; decimal yszj = sale; if (kfpje2 == 0) { hxje = 0; } else { decimal kyje = kfpje2 - yszj; if (kyje > 0) { hxje = yszj; kfpje2 = kyje; } else if (kyje == 0) { hxje = kfpje2; kfpje2 = kyje; //continue; } else { hxje = kfpje2; kfpje = 0; //continue; } } ///////////////////////////////////////////////////////// var details = new LHFKOrderCheckedDetails(); details.KeyId = txtKeyId.Text; details.FSaleKeyId = keyid; details.FAmount = hxje; details.FCompanyId = CurrentUser.AccountComId; var detail = FkOrderCheckedDetailsService.Where(p => p.KeyId == txtKeyId.Text && p.FSaleKeyId == keyid && p.FCompanyId == CurrentUser.AccountComId) .FirstOrDefault(); if (detail != null) { FkOrderCheckedDetailsService.SaveChanges(); } else { FkOrderCheckedDetailsService.Add(details); } } } else { //实际核销款 checkedAmt = sksum; //分析 decimal kfpje = sksum; for (int i = 0; i < sks.Length; i++) { int id = Convert.ToInt32(Grid1.DataKeys[Grid1.SelectedRowIndexArray[i]][1].ToString()); //string keyid = Grid1.DataKeys[sks[i]][0].ToString(); ///////////////////////////////////////////////// var sk = Convert.ToDecimal(Grid1.DataKeys[Grid1.SelectedRowIndexArray[i]][2]); decimal hxje = 0.00M; decimal yszj = sk; if (kfpje == 0) { hxje = 0; } else { decimal kyje = kfpje - yszj; if (kyje > 0) { hxje = yszj; kfpje = kyje; } else if (kyje == 0) { hxje = kfpje; kfpje = kyje; //continue; } else { hxje = kfpje; kfpje = 0; //continue; } } ///////////////////////////////////////////////// var banks = new LHFKOrderCheckedBanks(); banks.KeyId = txtKeyId.Text; banks.CBankId = id; banks.FCompanyId = CurrentUser.AccountComId; //本次核销款 banks.FAmt = hxje; var bank = FkOrderCheckedBanksService.Where(p => p.KeyId == txtKeyId.Text && p.CBankId == id && p.FCompanyId == CurrentUser.AccountComId).FirstOrDefault(); if (bank != null) { FkOrderCheckedBanksService.SaveChanges(); } else { FkOrderCheckedBanksService.Add(banks); } } decimal kfpje2 = sksum; for (int i = 0; i < sales.Length; i++) { string keyid = Grid2.DataKeys[Grid2.SelectedRowIndexArray[i]][0].ToString(); ////////////////////////////////////////////////////////// var sale = Convert.ToDecimal(Grid2.DataKeys[Grid2.SelectedRowIndexArray[i]][1]); decimal hxje = 0.00M; decimal yszj = sale; if (kfpje2 == 0) { hxje = 0; } else { decimal kyje = kfpje2 - yszj; if (kyje > 0) { hxje = yszj; kfpje2 = kyje; } else if (kyje == 0) { hxje = kfpje2; kfpje2 = kyje; //continue; } else { hxje = kfpje2; kfpje = 0; //continue; } } var details = new LHFKOrderCheckedDetails(); details.KeyId = txtKeyId.Text; details.FSaleKeyId = keyid; details.FAmount = hxje; details.FCompanyId = CurrentUser.AccountComId; var detail = FkOrderCheckedDetailsService.Where(p => p.KeyId == txtKeyId.Text && p.FSaleKeyId == keyid && p.FCompanyId == CurrentUser.AccountComId) .FirstOrDefault(); if (detail != null) { FkOrderCheckedDetailsService.SaveChanges(); } else { FkOrderCheckedDetailsService.Add(details); } } } //----------------------------------------------------- //实际核销款 order.FAmount = checkedAmt; FkOrderCheckedService.SaveChanges(); //----------------------------------------------------- if (txtKeyId.Text.Contains("TM")) { //单据号问题 string newKeyId = SequenceService.CreateSequence(Convert.ToDateTime(txtFDate.SelectedDate), "HF", CurrentUser.AccountComId); var orderParms = new Dictionary <string, object>(); orderParms.Clear(); orderParms.Add("@oldKeyId", txtKeyId.Text); orderParms.Add("@newKeyId", newKeyId); orderParms.Add("@Bill", "18"); orderParms.Add("@companyId", CurrentUser.AccountComId); SqlService.ExecuteProcedureCommand("proc_num", orderParms); txtKeyId.Text = newKeyId; //新增日志 var billStatus = new LHBillStatus { KeyId = newKeyId, FCompanyId = CurrentUser.AccountComId, FActionName = "新增", FDate = DateTime.Now, FDeptId = CurrentUser.AccountOrgId, FOperator = CurrentUser.AccountName, FMemo = String.Format("单据号{0},{1}新增核销收款单据。", newKeyId, CurrentUser.AccountName) }; GasHelper.AddBillStatus(billStatus); } return(true); } return(false); }