public void AddNoActivitySettlement(int? RejectedFormID, int UserID, int? ProxyUserID, int? ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, int CustomerID, int BrandID, int ExpenseSubCategoryID, int CurrencyID, string AttachedFileName, string RealAttachedFileName, string Remark, string FormApplyIds, string FormApplyNos, int CostCenterID, int PaymentTypeID) { SqlTransaction transaction = null; try { //事务开始 transaction = TableAdapterHelper.BeginTransaction(this.TAForm); TableAdapterHelper.SetTransaction(this.TAFormSaleSettlement, transaction); TableAdapterHelper.SetTransaction(this.TAFormSettlementExpenseDetail, transaction); //处理Form的内容 FormDS.FormRow formRow = this.FormDataSet.Form.NewFormRow(); if (RejectedFormID != null) { formRow.RejectedFormID = RejectedFormID.GetValueOrDefault(); } formRow.UserID = UserID; UtilityBLL utility = new UtilityBLL(); if (StatusID == SystemEnums.FormStatus.Awaiting) { string formTypeString = utility.GetFormTypeString((int)FormTypeID); formRow.FormNo = utility.GetFormNo(formTypeString); } else { formRow.SetFormNoNull(); } if (ProxyUserID != null) { formRow.ProxyUserID = ProxyUserID.GetValueOrDefault(); } if (ProxyPositionID != null) { formRow.ProxyPositionID = ProxyPositionID.GetValueOrDefault(); } formRow.OrganizationUnitID = OrganizationUnitID; formRow.PositionID = PositionID; formRow.FormTypeID = (int)FormTypeID; formRow.StatusID = (int)StatusID; formRow.SubmitDate = DateTime.Now; formRow.LastModified = DateTime.Now; formRow.InTurnUserIds = "P";//待改动 formRow.InTurnPositionIds = "P";//待改动 formRow.PageType = (int)SystemEnums.PageType.NoActivitySettlementApply; formRow.CostCenterID = CostCenterID; this.FormDataSet.Form.AddFormRow(formRow); this.TAForm.Update(formRow); //处理settlement的内容 FormDS.FormSaleSettlementRow formSettleRow = this.FormDataSet.FormSaleSettlement.NewFormSaleSettlementRow(); formSettleRow.FormSaleSettlementID = formRow.FormID; formSettleRow.CustomerID = CustomerID; formSettleRow.BrandID = BrandID; formSettleRow.ExpenseSubCategoryID = ExpenseSubCategoryID; formSettleRow.CurrencyID = CurrencyID; if (AttachedFileName != null && AttachedFileName != string.Empty) { formSettleRow.AttachedFileName = AttachedFileName; } if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) { formSettleRow.RealAttachedFileName = RealAttachedFileName; } if (Remark != null && Remark != string.Empty) { formSettleRow.Remark = Remark; } formSettleRow.AmountRMB = 0; formSettleRow.FormApplyIds = FormApplyIds; formSettleRow.FormApplyNos = FormApplyNos; formSettleRow.IsClose = false; formSettleRow.PaymentTypeID = PaymentTypeID; this.FormDataSet.FormSaleSettlement.AddFormSaleSettlementRow(formSettleRow); this.TAFormSaleSettlement.Update(formSettleRow); //费用项 decimal totalAmountRMB = 0; decimal totalApplyAmountRMB = 0; FormDS.FormSettlementExpenseDetailDataTable newExpenseDetailTable = new FormDS.FormSettlementExpenseDetailDataTable(); foreach (FormDS.FormSettlementExpenseDetailRow expenseRow in this.FormDataSet.FormSettlementExpenseDetail) { if (expenseRow.RowState != DataRowState.Deleted) { FormDS.FormSettlementExpenseDetailRow newExpenseRow = newExpenseDetailTable.NewFormSettlementExpenseDetailRow(); newExpenseRow.FormSaleSettlementID = formSettleRow.FormSaleSettlementID; newExpenseRow.FormSaleExpenseDetailID = expenseRow.FormSaleExpenseDetailID; newExpenseRow.FormSaleApplyID = expenseRow.FormSaleApplyID; newExpenseRow.ApplyFormNo = expenseRow.ApplyFormNo; newExpenseRow.ApplyPeriod = expenseRow.ApplyPeriod; newExpenseRow.ApplyProjectName = expenseRow.ApplyProjectName; newExpenseRow.ExpenseItemID = expenseRow.ExpenseItemID; if (!expenseRow.IsShopNameNull()) { newExpenseRow.ShopName = expenseRow.ShopName; } if (!expenseRow.IsSKUIDNull()) { newExpenseRow.SKUID = expenseRow.SKUID; } newExpenseRow.ApplyAmount = expenseRow.ApplyAmount; newExpenseRow.ApplyAmountRMB = expenseRow.ApplyAmountRMB; if (!expenseRow.IsApplyRemarkNull()) { newExpenseRow.ApplyRemark = expenseRow.ApplyRemark; } if (!expenseRow.IsAdvancedAmountNull()) { newExpenseRow.AdvancedAmount = expenseRow.AdvancedAmount; } newExpenseRow.AmountRMB = expenseRow.AmountRMB; if (!expenseRow.IsRemarkNull()) { newExpenseRow.Remark = expenseRow.Remark; } newExpenseDetailTable.AddFormSettlementExpenseDetailRow(newExpenseRow); totalAmountRMB = totalAmountRMB + newExpenseRow.AmountRMB; totalApplyAmountRMB = totalApplyAmountRMB + newExpenseRow.ApplyAmountRMB; } } this.TAFormSettlementExpenseDetail.Update(newExpenseDetailTable); formSettleRow.ApplyAmountRMB = totalApplyAmountRMB; formSettleRow.AmountRMB = totalAmountRMB; this.TAFormSaleSettlement.Update(formSettleRow); //作废之前的单据 if (RejectedFormID != null) { FormDS.FormRow oldRow = this.TAForm.GetDataByID(RejectedFormID.GetValueOrDefault())[0]; if (oldRow.StatusID == (int)SystemEnums.FormStatus.Rejected) { oldRow.StatusID = (int)SystemEnums.FormStatus.Scrap; this.TAForm.Update(oldRow); } } // 正式提交 if (StatusID == SystemEnums.FormStatus.Awaiting) { Dictionary<string, object> dic = new Dictionary<string, object>(); dic["TotalAmount"] = totalAmountRMB; MasterData.CustomerRow customer = new MasterDataBLL().GetCustomerById(CustomerID)[0]; dic["CustomerChannel"] = new MasterDataBLL().GetCustomerChannelById(customer.CustomerChannelID)[0].CustomerChannelCode; dic["KAType"] = customer.IsKaTypeNull() ? "" : customer.KaType; dic["PaymentTypeID"] = PaymentTypeID; APResult result = new APFlowBLL().CreateProcess(new APParameter(formRow.FormID, formRow.FormNo, formRow.OrganizationUnitID, formRow.UserID, (int)StatusID, formRow.FormTypeID, formRow.PositionID, dic)); if (result != null) { formRow.InTurnPositionIds = result.InTurnPositionIds; formRow.InTurnUserIds = result.InTurnUserIds; formRow.SubmitDate = result.ApprovedDate.GetValueOrDefault(); formRow.StatusID = result.StatusID; formRow.ProcID = result.ProcID; this.TAForm.Update(formRow); } } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new ApplicationException("Save Fail!" + ex.ToString()); } finally { transaction.Dispose(); } }
public void AddPaymentCash(int? RejectedFormID, int UserID, int? ProxyUserID, int? ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, SystemEnums.PageType PageType, int FormSaleSettlementID, int InvoiceStatusID, int PaymentTypeID, string Remark, string AttachedFileName, string RealAttachedFileName, int CostCenterID, int? VendorID, int FormPOID, int? VatTypeID) { SqlTransaction transaction = null; try { //事务开始 transaction = TableAdapterHelper.BeginTransaction(this.TAForm); TableAdapterHelper.SetTransaction(this.TAFormSalePayment, transaction); TableAdapterHelper.SetTransaction(this.TAFormSalePaymentDetail, transaction); TableAdapterHelper.SetTransaction(this.TAFormInvoice, transaction); //处理Form的内容 FormDS.FormRow formRow = this.FormDataSet.Form.NewFormRow(); if (RejectedFormID != null) { formRow.RejectedFormID = RejectedFormID.GetValueOrDefault(); } formRow.UserID = UserID; UtilityBLL utility = new UtilityBLL(); if (StatusID == SystemEnums.FormStatus.Awaiting) { string formTypeString = utility.GetFormTypeString((int)FormTypeID); formRow.FormNo = utility.GetFormNo(formTypeString); } else { formRow.SetFormNoNull(); } if (ProxyUserID != null) { formRow.ProxyUserID = ProxyUserID.GetValueOrDefault(); } if (ProxyPositionID != null) { formRow.ProxyPositionID = ProxyPositionID.GetValueOrDefault(); } formRow.OrganizationUnitID = OrganizationUnitID; formRow.PositionID = PositionID; formRow.FormTypeID = (int)FormTypeID; formRow.StatusID = (int)StatusID; formRow.SubmitDate = DateTime.Now; formRow.LastModified = DateTime.Now; formRow.InTurnUserIds = "P";//待改动 formRow.InTurnPositionIds = "P";//待改动 formRow.PageType = (int)PageType; formRow.CostCenterID = CostCenterID; formRow.IsCreateVoucher = false; formRow.IsExportLock = false; formRow.IsCompletePayment = false; formRow.IsInvoiceReturned = false; this.FormDataSet.Form.AddFormRow(formRow); this.TAForm.Update(formRow); //处理Payment的内容 FormDS.FormSalePaymentRow formPaymentRow = this.FormDataSet.FormSalePayment.NewFormSalePaymentRow(); formPaymentRow.FormSalePaymentID = formRow.FormID; formPaymentRow.FormSaleSettlementID = FormSaleSettlementID; formPaymentRow.InvoiceStatusID = InvoiceStatusID; formPaymentRow.PaymentTypeID = PaymentTypeID; if (Remark != null && Remark != string.Empty) { formPaymentRow.Remark = Remark; } if (AttachedFileName != null && AttachedFileName != string.Empty) { formPaymentRow.AttachedFileName = AttachedFileName; } if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) { formPaymentRow.RealAttachedFileName = RealAttachedFileName; } formPaymentRow.AmountRMB = 0; formPaymentRow.IsAdvanced = false; if (VendorID != null) { formPaymentRow.VendorID = VendorID.GetValueOrDefault(); } if (FormPOID > 0) { formPaymentRow.FormPOID = FormPOID; } if (VatTypeID != null) { formPaymentRow.VatTypeID = VatTypeID.GetValueOrDefault(); } this.FormDataSet.FormSalePayment.AddFormSalePaymentRow(formPaymentRow); this.TAFormSalePayment.Update(formPaymentRow); //发票 if (RejectedFormID != null) { FormDS.FormInvoiceDataTable newInvoiceTable = new FormDS.FormInvoiceDataTable(); foreach (FormDS.FormInvoiceRow invoiceRow in this.FormDataSet.FormInvoice) { if (invoiceRow.RowState != DataRowState.Deleted) { FormDS.FormInvoiceRow newInvoiceRow = newInvoiceTable.NewFormInvoiceRow(); newInvoiceRow.FormID = formPaymentRow.FormSalePaymentID; newInvoiceRow.InvoiceNo = invoiceRow.InvoiceNo; newInvoiceRow.InvoiceDate = invoiceRow.InvoiceDate; newInvoiceRow.InvoiceAmount = invoiceRow.InvoiceAmount; newInvoiceRow.Remark = invoiceRow.IsRemarkNull() ? "" : invoiceRow.Remark; newInvoiceRow.SystemInfo = invoiceRow.IsSystemInfoNull() ? "" : invoiceRow.SystemInfo; newInvoiceTable.AddFormInvoiceRow(newInvoiceRow); } this.TAFormInvoice.Update(newInvoiceTable); } } else { foreach (FormDS.FormInvoiceRow invoiceRow in this.FormDataSet.FormInvoice) { // 与父表绑定 if (invoiceRow.RowState != DataRowState.Deleted) { invoiceRow.FormID = formPaymentRow.FormSalePaymentID; } } } this.TAFormInvoice.Update(this.FormDataSet.FormInvoice); //处理明细 decimal totalAmountBeforeTax = 0; decimal totalTaxAmount = 0; decimal totalAmountRMB = 0; FormDS.FormSalePaymentDetailDataTable newDetailTable = new FormDS.FormSalePaymentDetailDataTable(); foreach (FormDS.FormSalePaymentDetailRow detailRow in this.FormDataSet.FormSalePaymentDetail) { // 与父表绑定 if (detailRow.RowState != DataRowState.Deleted) { totalAmountBeforeTax += detailRow.AmountBeforeTax; totalTaxAmount += detailRow.TaxAmount; totalAmountRMB += detailRow.AmountRMB; FormDS.FormSalePaymentDetailRow newDetailRow = newDetailTable.NewFormSalePaymentDetailRow(); newDetailRow.FormSalePaymentID = formPaymentRow.FormSalePaymentID; newDetailRow.FormSaleApplyID = detailRow.FormSaleApplyID; newDetailRow.FormSaleExpenseDetailID = detailRow.FormSaleExpenseDetailID; newDetailRow.ApplyFormNo = detailRow.ApplyFormNo; newDetailRow.ApplyPeriod = detailRow.ApplyPeriod; if (!detailRow.IsApplyProjectNameNull()) { newDetailRow.ApplyProjectName = detailRow.ApplyProjectName; } newDetailRow.ExpenseItemID = detailRow.ExpenseItemID; if (!detailRow.IsShopNameNull()) { newDetailRow.ShopName = detailRow.ShopName; } if (!detailRow.IsSKUIDNull()) { newDetailRow.SKUID = detailRow.SKUID; } newDetailRow.ApplyAmount = detailRow.ApplyAmount; newDetailRow.ApplyAmountRMB = detailRow.ApplyAmountRMB; if (!detailRow.IsSettlementAmountNull()) { newDetailRow.SettlementAmount = detailRow.SettlementAmount; } if (!detailRow.IsPayedAmountNull()) { newDetailRow.PayedAmount = detailRow.PayedAmount; } if (!detailRow.IsRemainAmountNull()) { newDetailRow.RemainAmount = detailRow.RemainAmount; } newDetailRow.AmountBeforeTax = detailRow.AmountBeforeTax; newDetailRow.TaxAmount = detailRow.TaxAmount; newDetailRow.AmountRMB = detailRow.AmountRMB; newDetailTable.AddFormSalePaymentDetailRow(newDetailRow); } } this.TAFormSalePaymentDetail.Update(newDetailTable); formPaymentRow.AmountBeforeTax = totalAmountBeforeTax; formPaymentRow.TaxAmount = totalTaxAmount; formPaymentRow.AmountRMB = totalAmountRMB; this.TAFormSalePayment.Update(formPaymentRow); //作废之前的单据 if (RejectedFormID != null) { FormDS.FormRow oldRow = this.TAForm.GetDataByID(RejectedFormID.GetValueOrDefault())[0]; if (oldRow.StatusID == (int)SystemEnums.FormStatus.Rejected) { oldRow.StatusID = (int)SystemEnums.FormStatus.Scrap; this.TAForm.Update(oldRow); } } // 正式提交 if (StatusID == SystemEnums.FormStatus.Awaiting) { Dictionary<string, object> dic = new Dictionary<string, object>(); dic["TotalAmount"] = totalAmountRMB; MasterData.CustomerRow customer = new MasterDataBLL().GetCustomerById(this.TAFormSaleSettlement.GetDataByID(FormSaleSettlementID)[0].CustomerID)[0]; dic["CustomerChannel"] = new MasterDataBLL().GetCustomerChannelById(customer.CustomerChannelID)[0].CustomerChannelCode; dic["KAType"] = customer.IsKaTypeNull() ? "" : customer.KaType; dic["InvoiceStatus"] = formPaymentRow.InvoiceStatusID; dic["PaymentTypeID"] = PaymentTypeID; APResult result = new APFlowBLL().CreateProcess(new APParameter(formRow.FormID, formRow.FormNo, formRow.OrganizationUnitID, formRow.UserID, (int)StatusID, formRow.FormTypeID, formRow.PositionID, dic)); if (result != null) { formRow.InTurnPositionIds = result.InTurnPositionIds; formRow.InTurnUserIds = result.InTurnUserIds; formRow.SubmitDate = result.ApprovedDate.GetValueOrDefault(); formRow.StatusID = result.StatusID; formRow.ProcID = result.ProcID; formRow.FinanceRemark = formPaymentRow.Remark; this.TAForm.Update(formRow); } } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new ApplicationException("Save Fail!" + ex.ToString()); } finally { transaction.Dispose(); } }
public void UpdateSaleNoActivityApply(int FormID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, decimal ExchangeRate, string ShopName, int? ShopCount, string ProjectName, string ProjectDesc, string ApplyFileName, string ApplyRealFileName, DateTime? ActivityBeginDate, DateTime? ActivityEndDate, int? CostCenterID, int? DiscountTypeID, decimal TotalBudget, decimal ApprovedAmount, decimal ApprovingAmount, decimal CompletedAmount, decimal ReimbursedAmount, decimal RemainBudget) { SqlTransaction transaction = null; try { //事务开始 transaction = TableAdapterHelper.BeginTransaction(this.TAForm); TableAdapterHelper.SetTransaction(this.TAFormSaleApply, transaction); TableAdapterHelper.SetTransaction(this.TAFormSaleExpenseDetail, transaction); FormDS.FormRow formRow = this.TAForm.GetDataByID(FormID)[0]; FormDS.FormSaleApplyRow formApplyRow = this.TAFormSaleApply.GetDataByID(FormID)[0]; //处理单据的内容 UtilityBLL utility = new UtilityBLL(); if (StatusID == SystemEnums.FormStatus.Awaiting) { string formTypeString = utility.GetFormTypeString((int)FormTypeID); formRow.FormNo = utility.GetFormNo(formTypeString); formRow.InTurnUserIds = "P";//待改动 formRow.InTurnPositionIds = "P";//待改动 } else { formRow.SetFormNoNull(); } formRow.StatusID = (int)StatusID; formRow.SubmitDate = DateTime.Now; formRow.LastModified = DateTime.Now; if (CostCenterID != null) { formRow.CostCenterID = CostCenterID.GetValueOrDefault(); } this.TAForm.Update(formRow); //处理申请表的内容 formApplyRow.ExchangeRate = ExchangeRate; if (ShopName != null) formApplyRow.ShopName = ShopName; if (ShopCount != null) formApplyRow.ShopCount = ShopCount.GetValueOrDefault(); if (ProjectName != null) formApplyRow.ProjectName = ProjectName; if (ProjectDesc != null) formApplyRow.ProjectDesc = ProjectDesc; if (ApplyFileName != null && ApplyFileName != string.Empty) { formApplyRow.ApplyFileName = ApplyFileName; } else { formApplyRow.SetApplyFileNameNull(); } if (ApplyRealFileName != null && ApplyRealFileName != string.Empty) { formApplyRow.ApplyRealFileName = ApplyRealFileName; } else { formApplyRow.SetApplyRealFileNameNull(); } if (ActivityBeginDate != null) formApplyRow.ActivityBeginDate = ActivityBeginDate.GetValueOrDefault(); if (ActivityEndDate != null) formApplyRow.ActivityEndDate = ActivityEndDate.GetValueOrDefault(); if (DiscountTypeID != null) { formApplyRow.DiscountTypeID = DiscountTypeID.GetValueOrDefault(); } formApplyRow.TotalBudget = TotalBudget; formApplyRow.ApprovedAmount = ApprovedAmount; formApplyRow.ApprovingAmount = ApprovingAmount; formApplyRow.CompletedAmount = CompletedAmount; formApplyRow.ReimbursedAmount = ReimbursedAmount; formApplyRow.RemainBudget = RemainBudget; this.TAFormSaleApply.Update(formApplyRow); //处理明细 decimal totalAmountRMB = 0; foreach (FormDS.FormSaleExpenseDetailRow detailRow in this.FormDataSet.FormSaleExpenseDetail) { if (detailRow.RowState != DataRowState.Deleted) { detailRow.FormSaleApplyID = formApplyRow.FormSaleApplyID; detailRow.AmountRMB = decimal.Round(detailRow.Amount * ExchangeRate, 2); totalAmountRMB = totalAmountRMB + detailRow.AmountRMB; } } this.TAFormSaleExpenseDetail.Update(this.FormDataSet.FormSaleExpenseDetail); formApplyRow.AmountRMB = totalAmountRMB; TAFormSaleApply.Update(formApplyRow); // 正式提交 if (StatusID == SystemEnums.FormStatus.Awaiting) { Dictionary<string, object> dic = new Dictionary<string, object>(); dic["TotalAmount"] = totalAmountRMB; MasterData.CustomerRow customer = new MasterDataBLL().GetCustomerById(formApplyRow.CustomerID)[0]; dic["CustomerChannel"] = new MasterDataBLL().GetCustomerChannelById(customer.CustomerChannelID)[0].CustomerChannelCode; dic["KAType"] = customer.IsKaTypeNull() ? "" : customer.KaType; dic["MaxDiscount"] = 0; dic["DiscountType"] = DiscountTypeID; APResult result = new APFlowBLL().CreateProcess(new APParameter(formRow.FormID, formRow.FormNo, formRow.OrganizationUnitID, formRow.UserID, (int)StatusID, formRow.FormTypeID, formRow.PositionID, dic)); if (result != null) { formRow.InTurnPositionIds = result.InTurnPositionIds; formRow.InTurnUserIds = result.InTurnUserIds; formRow.SubmitDate = result.ApprovedDate.GetValueOrDefault(); formRow.StatusID = result.StatusID; formRow.ProcID = result.ProcID; this.TAForm.Update(formRow); } } transaction.Commit(); } catch (ApplicationException ex) { transaction.Rollback(); throw ex; } catch (Exception ex) { transaction.Rollback(); throw new ApplicationException("Save Fail!" + ex.ToString()); } finally { transaction.Dispose(); } }
public void UpdateSaleActivityApply(int FormID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, decimal ExchangeRate, string ShopName, int? ShopCount, string ProjectName, string ProjectDesc, string ApplyFileName, string ApplyRealFileName, int? DisplayTypeID, decimal? DisplayArea, bool IsDM, int? DiscountTypeID, DateTime? ActivityBeginDate, DateTime? ActivityEndDate, DateTime? DeliveryBeginDate, DateTime? DeliveryEndDate, int? CostCenterID, decimal TotalBudget, decimal ApprovedAmount, decimal ApprovingAmount, decimal CompletedAmount, decimal ReimbursedAmount, decimal RemainBudget) { SqlTransaction transaction = null; try { //事务开始 transaction = TableAdapterHelper.BeginTransaction(this.TAForm); TableAdapterHelper.SetTransaction(this.TAFormSaleApply, transaction); TableAdapterHelper.SetTransaction(this.TAFormSaleSKUDetail, transaction); TableAdapterHelper.SetTransaction(this.TAFormSaleExpenseDetail, transaction); FormDS.FormRow formRow = this.TAForm.GetDataByID(FormID)[0]; FormDS.FormSaleApplyRow formApplyRow = this.TAFormSaleApply.GetDataByID(FormID)[0]; //处理单据的内容 UtilityBLL utility = new UtilityBLL(); if (StatusID == SystemEnums.FormStatus.Awaiting) { string formTypeString = utility.GetFormTypeString((int)FormTypeID); formRow.FormNo = utility.GetFormNo(formTypeString); formRow.InTurnUserIds = "P";//待改动 formRow.InTurnPositionIds = "P";//待改动 } else { formRow.SetFormNoNull(); } formRow.StatusID = (int)StatusID; formRow.SubmitDate = DateTime.Now; formRow.LastModified = DateTime.Now; if (CostCenterID != null) { formRow.CostCenterID = CostCenterID.GetValueOrDefault(); } this.TAForm.Update(formRow); //处理申请表的内容 formApplyRow.ExchangeRate = ExchangeRate; if (ShopName != null) formApplyRow.ShopName = ShopName; if (ShopCount != null) formApplyRow.ShopCount = ShopCount.GetValueOrDefault(); if (ProjectName != null) formApplyRow.ProjectName = ProjectName; if (ProjectDesc != null) formApplyRow.ProjectDesc = ProjectDesc; if (ApplyFileName != null && ApplyFileName != string.Empty) { formApplyRow.ApplyFileName = ApplyFileName; } else { formApplyRow.SetApplyFileNameNull(); } if (ApplyRealFileName != null && ApplyRealFileName != string.Empty) { formApplyRow.ApplyRealFileName = ApplyRealFileName; } else { formApplyRow.SetApplyRealFileNameNull(); } if (DisplayTypeID != null) formApplyRow.DisplayTypeID = DisplayTypeID.GetValueOrDefault(); if (DisplayArea != null) formApplyRow.DisplayArea = DisplayArea.GetValueOrDefault(); formApplyRow.IsDM = IsDM; if (DiscountTypeID != null) formApplyRow.DiscountTypeID = DiscountTypeID.GetValueOrDefault(); if (ActivityBeginDate != null) formApplyRow.ActivityBeginDate = ActivityBeginDate.GetValueOrDefault(); if (ActivityEndDate != null) formApplyRow.ActivityEndDate = ActivityEndDate.GetValueOrDefault(); if (DeliveryBeginDate != null) formApplyRow.DeliveryBeginDate = DeliveryBeginDate.GetValueOrDefault(); if (DeliveryEndDate != null) formApplyRow.DeliveryEndDate = DeliveryEndDate.GetValueOrDefault(); formApplyRow.TotalBudget = TotalBudget; formApplyRow.ApprovedAmount = ApprovedAmount; formApplyRow.ApprovingAmount = ApprovingAmount; formApplyRow.CompletedAmount = CompletedAmount; formApplyRow.ReimbursedAmount = ReimbursedAmount; formApplyRow.RemainBudget = RemainBudget; this.TAFormSaleApply.Update(formApplyRow); //处理明细,先产品表 decimal totalPriceDiscountAmountRMB = 0;// decimal totalForecastOrderAmount = 0; decimal maxDiscount = 0; foreach (FormDS.FormSaleSKUDetailRow skuRow in this.FormDataSet.FormSaleSKUDetail) { if (skuRow.RowState != DataRowState.Deleted) { skuRow.FormSaleApplyID = formApplyRow.FormSaleApplyID; skuRow.PriceDiscountAmountRMB = decimal.Round(skuRow.PriceDiscountAmount * ExchangeRate, 2); totalPriceDiscountAmountRMB = totalPriceDiscountAmountRMB + skuRow.PriceDiscountAmountRMB; totalForecastOrderAmount = totalForecastOrderAmount + skuRow.ForecastOrderAmount; if (skuRow.Discount > maxDiscount) { maxDiscount = skuRow.Discount; } //如果有折扣的话,要生成费用项 if (!skuRow.IsPriceDiscountAmountRMBNull()) { if (StatusID == SystemEnums.FormStatus.Awaiting && new ExpenseItemTableAdapter().GetPriceDiscountExpenseItem().Count != 0) { FormDS.FormSaleExpenseDetailRow newExpenseDetail = this.FormDataSet.FormSaleExpenseDetail.NewFormSaleExpenseDetailRow(); newExpenseDetail.FormSaleApplyID = formApplyRow.FormSaleApplyID; newExpenseDetail.ExpenseItemID = new ExpenseItemTableAdapter().GetPriceDiscountExpenseItem()[0].ExpenseItemID; newExpenseDetail.SKUID = skuRow.SKUID; newExpenseDetail.Amount = skuRow.PriceDiscountAmount; newExpenseDetail.AmountRMB = decimal.Round(skuRow.PriceDiscountAmount * ExchangeRate, 2); if (!skuRow.IsRemarkNull()) { newExpenseDetail.Remark = skuRow.Remark; } this.FormDataSet.FormSaleExpenseDetail.AddFormSaleExpenseDetailRow(newExpenseDetail); } } } } this.TAFormSaleSKUDetail.Update(this.FormDataSet.FormSaleSKUDetail); //费用项 decimal totalAmountRMB = 0; foreach (FormDS.FormSaleExpenseDetailRow expenseRow in this.FormDataSet.FormSaleExpenseDetail) { if (expenseRow.RowState != DataRowState.Deleted) { expenseRow.FormSaleApplyID = formApplyRow.FormSaleApplyID; expenseRow.AmountRMB = decimal.Round(expenseRow.Amount * ExchangeRate, 2); totalAmountRMB = totalAmountRMB + expenseRow.AmountRMB; } } this.TAFormSaleExpenseDetail.Update(this.FormDataSet.FormSaleExpenseDetail); formApplyRow.PriceDiscountAmountRMB = totalPriceDiscountAmountRMB; formApplyRow.AmountRMB = totalAmountRMB; formApplyRow.OtherAmountRMB = totalAmountRMB - totalPriceDiscountAmountRMB; formApplyRow.ForecastOrderAmount = totalForecastOrderAmount; if (totalForecastOrderAmount != 0) { formApplyRow.CostBenefitRate = totalAmountRMB / totalForecastOrderAmount * 100; } else { formApplyRow.CostBenefitRate = 0; } TAFormSaleApply.Update(formApplyRow); // 正式提交 if (StatusID == SystemEnums.FormStatus.Awaiting) { Dictionary<string, object> dic = new Dictionary<string, object>(); dic["TotalAmount"] = totalAmountRMB; MasterData.CustomerRow customer = new MasterDataBLL().GetCustomerById(formApplyRow.CustomerID)[0]; dic["CustomerChannel"] = new MasterDataBLL().GetCustomerChannelById(customer.CustomerChannelID)[0].CustomerChannelCode; dic["KAType"] = customer.IsKaTypeNull() ? "" : customer.KaType; dic["MaxDiscount"] = maxDiscount; dic["DiscountType"] = DiscountTypeID; APResult result = new APFlowBLL().CreateProcess(new APParameter(formRow.FormID, formRow.FormNo, formRow.OrganizationUnitID, formRow.UserID, (int)StatusID, formRow.FormTypeID, formRow.PositionID, dic)); if (result != null) { formRow.InTurnPositionIds = result.InTurnPositionIds; formRow.InTurnUserIds = result.InTurnUserIds; formRow.SubmitDate = result.ApprovedDate.GetValueOrDefault(); formRow.StatusID = result.StatusID; formRow.ProcID = result.ProcID; this.TAForm.Update(formRow); } } transaction.Commit(); } catch (ApplicationException ex) { transaction.Rollback(); throw ex; } catch (Exception ex) { transaction.Rollback(); throw new ApplicationException("Save Fail!" + ex.ToString()); } finally { transaction.Dispose(); } }
public void UpdatePaymentFreeGoods(int FormID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, int InvoiceStatusID, int PaymentTypeID, string Remark, string AttachedFileName, string RealAttachedFileName, int? VendorID) { SqlTransaction transaction = null; try { //事务开始 transaction = TableAdapterHelper.BeginTransaction(this.TAForm); TableAdapterHelper.SetTransaction(this.TAFormSalePayment, transaction); TableAdapterHelper.SetTransaction(this.TAFormSalePaymentDetail, transaction); TableAdapterHelper.SetTransaction(this.TAFormSalePaymentFreeGoods, transaction); FormDS.FormRow formRow = this.TAForm.GetDataByID(FormID)[0]; FormDS.FormSalePaymentRow formPaymentRow = this.TAFormSalePayment.GetDataByID(FormID)[0]; //处理单据的内容 UtilityBLL utility = new UtilityBLL(); if (StatusID == SystemEnums.FormStatus.Awaiting) { string formTypeString = utility.GetFormTypeString((int)FormTypeID); formRow.FormNo = utility.GetFormNo(formTypeString); formRow.InTurnUserIds = "P";//待改动 formRow.InTurnPositionIds = "P";//待改动 } else { formRow.SetFormNoNull(); } formRow.StatusID = (int)StatusID; formRow.SubmitDate = DateTime.Now; formRow.LastModified = DateTime.Now; this.TAForm.Update(formRow); //处理Payment的内容 if (AttachedFileName != null && AttachedFileName != string.Empty) { formPaymentRow.AttachedFileName = AttachedFileName; } else { formPaymentRow.SetAttachedFileNameNull(); } if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) { formPaymentRow.RealAttachedFileName = RealAttachedFileName; } else { formPaymentRow.SetRealAttachedFileNameNull(); } if (Remark != null && Remark != string.Empty) { formPaymentRow.Remark = Remark; } formPaymentRow.InvoiceStatusID = InvoiceStatusID; formPaymentRow.PaymentTypeID = PaymentTypeID; if (VendorID != null) { formPaymentRow.VendorID = VendorID.GetValueOrDefault(); } this.TAFormSalePayment.Update(formPaymentRow); //处理明细 decimal totalAmountRMB = 0; foreach (FormDS.FormSalePaymentDetailRow detailRow in this.FormDataSet.FormSalePaymentDetail) { if (detailRow.RowState != DataRowState.Deleted) { totalAmountRMB += detailRow.AmountRMB; detailRow.FormSalePaymentID = formPaymentRow.FormSalePaymentID; } } this.TAFormSalePaymentDetail.Update(this.FormDataSet.FormSalePaymentDetail); formPaymentRow.AmountRMB = totalAmountRMB; this.TAFormSalePayment.Update(formPaymentRow); foreach (FormDS.FormSalePaymentFreeGoodsRow detailFGRow in this.FormDataSet.FormSalePaymentFreeGoods) { // 与父表绑定 if (detailFGRow.RowState != DataRowState.Deleted) { detailFGRow.FormSalePaymentID = formPaymentRow.FormSalePaymentID; } } this.TAFormSalePaymentFreeGoods.Update(this.FormDataSet.FormSalePaymentFreeGoods); // 正式提交 if (StatusID == SystemEnums.FormStatus.Awaiting) { Dictionary<string, object> dic = new Dictionary<string, object>(); dic["TotalAmount"] = totalAmountRMB; MasterData.CustomerRow customer = new MasterDataBLL().GetCustomerById(this.TAFormSaleSettlement.GetDataByID(formPaymentRow.FormSaleSettlementID)[0].CustomerID)[0]; dic["CustomerChannel"] = new MasterDataBLL().GetCustomerChannelById(customer.CustomerChannelID)[0].CustomerChannelCode; dic["KAType"] = customer.IsKaTypeNull() ? "" : customer.KaType; dic["PaymentTypeID"] = PaymentTypeID; APResult result = new APFlowBLL().CreateProcess(new APParameter(formRow.FormID, formRow.FormNo, formRow.OrganizationUnitID, formRow.UserID, (int)StatusID, formRow.FormTypeID, formRow.PositionID, dic)); if (result != null) { formRow.InTurnPositionIds = result.InTurnPositionIds; formRow.InTurnUserIds = result.InTurnUserIds; formRow.SubmitDate = result.ApprovedDate.GetValueOrDefault(); formRow.StatusID = result.StatusID; formRow.ProcID = result.ProcID; formRow.FinanceRemark = formPaymentRow.Remark; this.TAForm.Update(formRow); } } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new ApplicationException("Save Fail!" + ex.ToString()); } finally { transaction.Dispose(); } }
public void UpdateActivitySettlement(int FormID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, string AttachedFileName, string RealAttachedFileName, string Remark, int PaymentTypeID) { SqlTransaction transaction = null; try { //事务开始 transaction = TableAdapterHelper.BeginTransaction(this.TAForm); TableAdapterHelper.SetTransaction(this.TAFormSaleSettlement, transaction); TableAdapterHelper.SetTransaction(this.TAFormSettlementExpenseDetail, transaction); TableAdapterHelper.SetTransaction(this.TAFormSettlementSKUDetail, transaction); FormDS.FormRow formRow = this.TAForm.GetDataByID(FormID)[0]; FormDS.FormSaleSettlementRow formSettleRow = this.TAFormSaleSettlement.GetDataByID(FormID)[0]; //处理单据的内容 UtilityBLL utility = new UtilityBLL(); if (StatusID == SystemEnums.FormStatus.Awaiting) { string formTypeString = utility.GetFormTypeString((int)FormTypeID); formRow.FormNo = utility.GetFormNo(formTypeString); formRow.InTurnUserIds = "P";//待改动 formRow.InTurnPositionIds = "P";//待改动 } else { formRow.SetFormNoNull(); } formRow.StatusID = (int)StatusID; formRow.SubmitDate = DateTime.Now; formRow.LastModified = DateTime.Now; this.TAForm.Update(formRow); //处理settlement的内容 if (AttachedFileName != null && AttachedFileName != string.Empty) { formSettleRow.AttachedFileName = AttachedFileName; } else { formSettleRow.SetAttachedFileNameNull(); } if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) { formSettleRow.RealAttachedFileName = RealAttachedFileName; } else { formSettleRow.SetRealAttachedFileNameNull(); } if (Remark != null && Remark != string.Empty) { formSettleRow.Remark = Remark; } formSettleRow.PaymentTypeID = PaymentTypeID; this.TAFormSaleSettlement.Update(formSettleRow); //处理明细,先产品表 decimal totalForecastOrderAmount = 0; decimal totalActualOrderAmount = 0; foreach (FormDS.FormSettlementSKUDetailRow skuRow in this.FormDataSet.FormSettlementSKUDetail) { if (skuRow.RowState != DataRowState.Deleted) { skuRow.FormSaleSettlementID = formSettleRow.FormSaleSettlementID; totalForecastOrderAmount = totalForecastOrderAmount + skuRow.ForecastOrderAmount; totalActualOrderAmount = totalActualOrderAmount + skuRow.ActualOrderAmount; } } this.TAFormSettlementSKUDetail.Update(this.FormDataSet.FormSettlementSKUDetail); //费用项 decimal totalAmountRMB = 0; decimal totalApplyAmountRMB = 0; foreach (FormDS.FormSettlementExpenseDetailRow expenseRow in this.FormDataSet.FormSettlementExpenseDetail) { if (expenseRow.RowState != DataRowState.Deleted) { expenseRow.FormSaleSettlementID = formSettleRow.FormSaleSettlementID; totalAmountRMB = totalAmountRMB + expenseRow.AmountRMB; totalApplyAmountRMB = totalApplyAmountRMB + expenseRow.ApplyAmountRMB; } } this.TAFormSettlementExpenseDetail.Update(this.FormDataSet.FormSettlementExpenseDetail); formSettleRow.ForecastOrderAmount = totalForecastOrderAmount; formSettleRow.ApplyAmountRMB = totalApplyAmountRMB; if (totalForecastOrderAmount != 0) { formSettleRow.CostBenefitRate = totalApplyAmountRMB / totalForecastOrderAmount * 100; } else { formSettleRow.CostBenefitRate = 0; } formSettleRow.ActualOrderAmount = totalActualOrderAmount; formSettleRow.AmountRMB = totalAmountRMB; if (totalActualOrderAmount != 0) { formSettleRow.ActualCostBenefitRate = totalAmountRMB / totalActualOrderAmount * 100; } else { formSettleRow.ActualCostBenefitRate = 0; } this.TAFormSaleSettlement.Update(formSettleRow); // 正式提交 if (StatusID == SystemEnums.FormStatus.Awaiting) { Dictionary<string, object> dic = new Dictionary<string, object>(); dic["TotalAmount"] = totalAmountRMB; MasterData.CustomerRow customer = new MasterDataBLL().GetCustomerById(formSettleRow.CustomerID)[0]; dic["CustomerChannel"] = new MasterDataBLL().GetCustomerChannelById(customer.CustomerChannelID)[0].CustomerChannelCode; dic["KAType"] = customer.IsKaTypeNull() ? "" : customer.KaType; dic["PaymentTypeID"] = PaymentTypeID; APResult result = new APFlowBLL().CreateProcess(new APParameter(formRow.FormID, formRow.FormNo, formRow.OrganizationUnitID, formRow.UserID, (int)StatusID, formRow.FormTypeID, formRow.PositionID, dic)); if (result != null) { formRow.InTurnPositionIds = result.InTurnPositionIds; formRow.InTurnUserIds = result.InTurnUserIds; formRow.SubmitDate = result.ApprovedDate.GetValueOrDefault(); formRow.StatusID = result.StatusID; formRow.ProcID = result.ProcID; this.TAForm.Update(formRow); } } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new ApplicationException("Save Fail!" + ex.ToString()); } finally { transaction.Dispose(); } }
public void AddSaleNoActivityApply(int? RejectedFormID, int UserID, int? ProxyUserID, int? ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, DateTime FPeriod, int CustomerID, int BrandID, int ExpenseSubCategoryID, int CurrencyID, decimal ExchangeRate, string ShopName, int? ShopCount, string ProjectName, string ProjectDesc, string ApplyFileName, string ApplyRealFileName, DateTime? ActivityBeginDate, DateTime? ActivityEndDate, int? CostCenterID, int? DiscountTypeID, decimal TotalBudget, decimal ApprovedAmount, decimal ApprovingAmount, decimal CompletedAmount, decimal ReimbursedAmount, decimal RemainBudget) { SqlTransaction transaction = null; try { //事务开始 transaction = TableAdapterHelper.BeginTransaction(this.TAForm); TableAdapterHelper.SetTransaction(this.TAFormSaleApply, transaction); TableAdapterHelper.SetTransaction(this.TAFormSaleExpenseDetail, transaction); //处理单据的内容 FormDS.FormRow formRow = this.FormDataSet.Form.NewFormRow(); if (RejectedFormID != null) { formRow.RejectedFormID = RejectedFormID.GetValueOrDefault(); } formRow.UserID = UserID; UtilityBLL utility = new UtilityBLL(); if (StatusID == SystemEnums.FormStatus.Awaiting) { string formTypeString = utility.GetFormTypeString((int)FormTypeID); formRow.FormNo = utility.GetFormNo(formTypeString); } else { formRow.SetFormNoNull(); } if (ProxyUserID != null) { formRow.ProxyUserID = ProxyUserID.GetValueOrDefault(); } if (ProxyPositionID != null) { formRow.ProxyPositionID = ProxyPositionID.GetValueOrDefault(); } formRow.OrganizationUnitID = OrganizationUnitID; formRow.PositionID = PositionID; formRow.FormTypeID = (int)FormTypeID; formRow.StatusID = (int)StatusID; formRow.SubmitDate = DateTime.Now; formRow.LastModified = DateTime.Now; formRow.InTurnUserIds = "P";//待改动 formRow.InTurnPositionIds = "P";//待改动 formRow.PageType = (int)SystemEnums.PageType.NoActivityApply; if (CostCenterID != null) { formRow.CostCenterID = CostCenterID.GetValueOrDefault(); } this.FormDataSet.Form.AddFormRow(formRow); this.TAForm.Update(formRow); //处理申请表的内容 FormDS.FormSaleApplyRow formApplyRow = this.FormDataSet.FormSaleApply.NewFormSaleApplyRow(); formApplyRow.FormSaleApplyID = formRow.FormID; formApplyRow.FPeriod = DateTime.Parse(FPeriod.Year.ToString() + "-" + FPeriod.Month.ToString() + "-01"); formApplyRow.CustomerID = CustomerID; formApplyRow.BrandID = BrandID; formApplyRow.ExpenseSubCategoryID = ExpenseSubCategoryID; formApplyRow.CurrencyID = CurrencyID; formApplyRow.ExchangeRate = ExchangeRate; if (ShopName != null) formApplyRow.ShopName = ShopName; if (ShopCount != null) formApplyRow.ShopCount = ShopCount.GetValueOrDefault(); if (ProjectName != null) formApplyRow.ProjectName = ProjectName; if (ProjectDesc != null) formApplyRow.ProjectDesc = ProjectDesc; if (ApplyFileName != null && ApplyFileName != string.Empty) { formApplyRow.ApplyFileName = ApplyFileName; } if (ApplyRealFileName != null && ApplyRealFileName != string.Empty) { formApplyRow.ApplyRealFileName = ApplyRealFileName; } if (ActivityBeginDate != null) formApplyRow.ActivityBeginDate = ActivityBeginDate.GetValueOrDefault(); if (ActivityEndDate != null) formApplyRow.ActivityEndDate = ActivityEndDate.GetValueOrDefault(); if (DiscountTypeID != null) { formApplyRow.DiscountTypeID = DiscountTypeID.GetValueOrDefault(); } formApplyRow.TotalBudget = TotalBudget; formApplyRow.ApprovedAmount = ApprovedAmount; formApplyRow.ApprovingAmount = ApprovingAmount; formApplyRow.CompletedAmount = CompletedAmount; formApplyRow.ReimbursedAmount = ReimbursedAmount; formApplyRow.RemainBudget = RemainBudget; formApplyRow.AmountRMB = 0;//暂时 formApplyRow.IsClose = false; formApplyRow.IsCompleted = false; this.FormDataSet.FormSaleApply.AddFormSaleApplyRow(formApplyRow); this.TAFormSaleApply.Update(formApplyRow); //处理明细 decimal totalAmountRMB = 0; if (RejectedFormID != null) { FormDS.FormSaleExpenseDetailDataTable newDetailTable = new FormDS.FormSaleExpenseDetailDataTable(); foreach (FormDS.FormSaleExpenseDetailRow detailRow in this.FormDataSet.FormSaleExpenseDetail) { if (detailRow.RowState != DataRowState.Deleted) { FormDS.FormSaleExpenseDetailRow newDetailRow = newDetailTable.NewFormSaleExpenseDetailRow(); newDetailRow.FormSaleApplyID = formApplyRow.FormSaleApplyID; newDetailRow.ExpenseItemID = detailRow.ExpenseItemID; newDetailRow.SKUID = detailRow.SKUID; newDetailRow.Amount = detailRow.Amount; newDetailRow.AmountRMB = decimal.Round(detailRow.Amount * ExchangeRate, 2); if (!detailRow.IsRemarkNull()) { newDetailRow.Remark = detailRow.Remark; } newDetailTable.AddFormSaleExpenseDetailRow(newDetailRow); totalAmountRMB = totalAmountRMB + newDetailRow.AmountRMB; } this.TAFormSaleExpenseDetail.Update(newDetailTable); } } else { foreach (FormDS.FormSaleExpenseDetailRow detailRow in this.FormDataSet.FormSaleExpenseDetail) { if (detailRow.RowState != DataRowState.Deleted) { detailRow.FormSaleApplyID = formApplyRow.FormSaleApplyID; detailRow.AmountRMB = decimal.Round(detailRow.Amount * ExchangeRate, 2); totalAmountRMB = totalAmountRMB + detailRow.AmountRMB; } } this.TAFormSaleExpenseDetail.Update(this.FormDataSet.FormSaleExpenseDetail); } formApplyRow.AmountRMB = totalAmountRMB; TAFormSaleApply.Update(formApplyRow); //作废之前的单据 if (RejectedFormID != null) { FormDS.FormRow oldRow = this.TAForm.GetDataByID(RejectedFormID.GetValueOrDefault())[0]; if (oldRow.StatusID == (int)SystemEnums.FormStatus.Rejected) { oldRow.StatusID = (int)SystemEnums.FormStatus.Scrap; this.TAForm.Update(oldRow); } } // 正式提交 if (StatusID == SystemEnums.FormStatus.Awaiting) { Dictionary<string, object> dic = new Dictionary<string, object>(); dic["TotalAmount"] = totalAmountRMB; MasterData.CustomerRow customer = new MasterDataBLL().GetCustomerById(CustomerID)[0]; dic["CustomerChannel"] = new MasterDataBLL().GetCustomerChannelById(customer.CustomerChannelID)[0].CustomerChannelCode; dic["KAType"] = customer.IsKaTypeNull() ? "" : customer.KaType; dic["MaxDiscount"] = 0; ; dic["DiscountType"] = DiscountTypeID; APResult result = new APFlowBLL().CreateProcess(new APParameter(formRow.FormID, formRow.FormNo, formRow.OrganizationUnitID, formRow.UserID, (int)StatusID, formRow.FormTypeID, formRow.PositionID, dic)); if (result != null) { formRow.InTurnPositionIds = result.InTurnPositionIds; formRow.InTurnUserIds = result.InTurnUserIds; formRow.SubmitDate = result.ApprovedDate.GetValueOrDefault(); formRow.StatusID = result.StatusID; formRow.ProcID = result.ProcID; this.TAForm.Update(formRow); } } transaction.Commit(); } catch (ApplicationException ex) { transaction.Rollback(); throw ex; } catch (Exception ex) { transaction.Rollback(); throw new ApplicationException("Save Fail!" + ex.ToString()); } finally { transaction.Dispose(); } }