using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace LYFZ.Software.MainBusiness.Dresses.DressManagement.Rental { public partial class FrmRefundRecord : LYFZ.Software.UI.Dresses.DressManagement.Rental.FrmRefundRecord { LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder(); LYFZ.BLL.BLL_ErpSystemLogs syslogbll = new BLL.BLL_ErpSystemLogs(); LYFZ.BLL.BLL_ErpDressRefundRecord drrbll = new BLL.BLL_ErpDressRefundRecord(); LYFZ.BLL.BLL_ErpOtherIncomeAndExpenses oiebll = new BLL.BLL_ErpOtherIncomeAndExpenses(); public FrmRefundRecord() { this.Shown += FrmRefundRecord_Shown; this.txtRefundAmount.KeyPress += txtRefundAmount_KeyPress; this.btnSave.Click += btnSave_Click; this.btnClose.Click += btnClose_Click; this.btnPrint.Click += btnPrint_Click; this.btnDelete.Click += btnDelete_Click; } /// /// 是否保存 /// public bool IsSaveed = false; /// /// 订单号 /// public string StrOrderNumber; /// /// 窗体加载事件 /// /// /// void FrmRefundRecord_Shown(object sender, EventArgs e) { this.dgvData.DataColumns("ID,退款类型,金额,退款人,录入人,录入时间,退款备注", strHideField: "ID"); this.btnDelete.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.DressManagement, CustomAttributes.OperatingAuthority.Delete); LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_DepartmentAndEmployee(this.cmbtreevRefundName, IsFirstNodeNull: true); LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboxTreeView(this.cmbtreevRefundType, "退押金,报损", IsFirstNodeNull: true); if (!string.IsNullOrEmpty(this.StrOrderNumber)) { DataTable dt = orbll.GetView_Custom("BView_DressOrderReport", StrWhere: "订单号 = '" + this.StrOrderNumber + "'", ShowColumnName: "订单号,客户姓名,客户电话,欠款金额,应收押金,已收押金,未退押金,是否还衣,订单备注").Tables[0]; if (dt.Rows.Count > 0) { this.txtOrderNumber.Text = dt.Rows[0]["订单号"].ToString().Trim(); this.txtClientName.Text = dt.Rows[0]["客户姓名"].ToString().Trim(); this.txtClientPhone.Text = dt.Rows[0]["客户电话"].ToString().Trim(); this.txtArrears.Text = dt.Rows[0]["欠款金额"].ToString().Trim(); this.txtBackStatus.Text = dt.Rows[0]["是否还衣"].ToString().Trim(); this.txtReceivableDeposit.Text = dt.Rows[0]["应收押金"].ToString().Trim(); this.txtReceivedDeposit.Text = dt.Rows[0]["已收押金"].ToString().Trim(); this.txtNotReturnedDeposit.Text = dt.Rows[0]["未退押金"].ToString().Trim(); this.txtRemark.Text = dt.Rows[0]["订单备注"].ToString().Trim(); this.txtRefundAmount.Text = dt.Rows[0]["未退押金"].ToString().Trim(); } this.PublicFunctionRows(); LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_PaymentMethod(this.cbx_PaymentType,StrWhere: " Sc_ClassCode != 'BEBACCAFEGECFBJFD' "); //DataTable dt = orbll.GetView_Custom("tb_ErpDressDepositReceivables", StrWhere: "DDR_Number = '" + this.StrOrderNumber + "'", ShowColumnName: "sum(DDR_Money) AS SumAmount").Tables[0]; //if (string.IsNullOrEmpty(dt.Rows[0]["SumAmount"].ToString().Trim())) //{ this.txtRefundAmount.Text = "0"; } //else //{ this.txtRefundAmount.Text = dt.Rows[0]["SumAmount"].ToString().Trim(); } //this.PublicFunctionRows(); } } /// /// 绑定退款记录 /// void PublicFunctionRows() { this.dgvData.Rows.Clear(); string StrTableName = "tb_ErpDressRefundRecord Left Join tb_ErpUser As tb_RefundName on tb_RefundName.User_EmployeeID = DRR_CreateName Left Join tb_ErpUser As tb_HandledName on tb_HandledName.User_EmployeeID = DRR_HandledName left join tb_ErpSystemCategory on Sc_ClassCode = tb_ErpDressRefundRecord.DRR_PaymentType"; DataTable dt = orbll.GetView_Custom(StrTableName, StrWhere: "DRR_Number = '" + this.StrOrderNumber + "'", ShowColumnName: "tb_ErpDressRefundRecord.ID,(case when DRR_Type = '0' then '退押金' else '报损' end) AS 退款类型,Sc_ClassName as 退款方式, DRR_Money AS 金额,tb_RefundName.User_Name AS 退款人,tb_HandledName.User_Name AS 录入人,dbo.fn_CheckDateTime(DRR_CreateDatetime) AS 录入时间,DRR_Remark AS 退款备注").Tables[0]; this.dgvData.DataSource(dt, strHideField: "ID"); this.dgvData.Columns["录入时间"].Width = 110; this.dgvData.FillLastColumn(); } /// /// 输入框设置 /// /// /// void txtRefundAmount_KeyPress(object sender, KeyPressEventArgs e) { if (!Char.IsNumber(e.KeyChar) && !Char.IsPunctuation(e.KeyChar) && !Char.IsControl(e.KeyChar)) { e.Handled = true; } else if (Char.IsPunctuation(e.KeyChar)) { if (e.KeyChar == '.') { if (((System.Windows.Forms.TextBox)sender).Text.LastIndexOf('.') != -1) { e.Handled = true; } } else { e.Handled = true; } } } /// /// 保存 /// /// /// void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.cmbtreevRefundType.Text.Trim())) { MessageBoxCustom.Show("退款类型不能为空!"); return; } if (string.IsNullOrEmpty(this.txtRefundAmount.Text.Trim())) { MessageBoxCustom.Show("金额不能为空!"); return; } if (Convert.ToDecimal(this.txtRefundAmount.Text.Trim()) <= 0) { MessageBoxCustom.Show("退款金额必须大于0!"); return; } if (string.IsNullOrEmpty(this.cmbtreevRefundName.Text.Trim())) { MessageBoxCustom.Show("退款人不能为空!"); return; } if (string.IsNullOrEmpty(this.cbx_PaymentType.Text.Trim())) { MessageBoxCustom.Show("退款方式不能为空!"); return; } List clist = new List(); LYFZ.Model.Model_ErpDressRefundRecord model = new Model.Model_ErpDressRefundRecord(); model.DRR_RefundNumber = "D3RN" + LYFZ.BLL.BLL_ErpCustomer.GetClientNumber(); model.DRR_Number = this.StrOrderNumber; model.DRR_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID(); if (this.cmbtreevRefundType.Text.Trim() == "退押金") { model.DRR_Type = 0; DataTable dt = orbll.GetView_Custom("tb_ErpDressSaleRentalOrder", StrWhere: "Dsro_Number = '" + this.StrOrderNumber + "'", ShowColumnName: "Dsro_MortgageAmount").Tables[0]; if (dt.Rows.Count > 0) { if (Convert.ToDecimal(dt.Rows[0]["Dsro_MortgageAmount"]) <= 0) { MessageBoxCustom.Show("此订单的订单押金为零,不需要退押金!"); return; } DataTable tb = orbll.GetView_Custom("tb_ErpDressDepositReceivables", StrWhere: "DDR_Number = '" + this.StrOrderNumber + "'", ShowColumnName: "sum(DDR_Money) AS SumAmount").Tables[0]; if (tb.Rows.Count <= 0 || string.IsNullOrEmpty(tb.Rows[0]["SumAmount"].ToString().Trim())) { MessageBoxCustom.Show("此订单未收押金,不能处理退押金!"); return; } decimal ReceivedDeposit = Convert.ToDecimal(tb.Rows[0]["SumAmount"]); DataTable tbl = orbll.GetView_Custom("tb_ErpDressRefundRecord", StrWhere: "DRR_Number='" + this.StrOrderNumber + "'", ShowColumnName: "sum(DRR_Money) AS SumAmount").Tables[0]; if (tbl.Rows.Count > 0) { decimal decA = 0; if (!string.IsNullOrEmpty(tbl.Rows[0]["SumAmount"].ToString())) { decA = Convert.ToDecimal(tbl.Rows[0]["SumAmount"]); } if ((decA + Convert.ToDecimal(txtRefundAmount.Text)) > ReceivedDeposit) { MessageBoxCustom.Show("退押金金额不能超过收到的押金金额(收到押金金额为:" + ReceivedDeposit + " 已退:" + decA + ")!"); return; } } } DataTable dts = orbll.GetView_Custom("BView_DressOrderReport", StrWhere: "订单号 = '" + StrOrderNumber + "'", ShowColumnName: "欠款金额").Tables[0]; if (dts.Rows.Count > 0) { if (Convert.ToDecimal(dts.Rows[0]["欠款金额"]) > 0) { MessageBoxCustom.Show("订单有欠款,不能退押金!"); return; } } } else { model.DRR_Type = 1; } model.DRR_Money = Convert.ToDecimal(this.txtRefundAmount.Text); model.DRR_RefundAmountAudit = ""; model.DRR_RefundAmountAuditName = ""; model.DRR_RefundAmountAuditRemark = ""; model.DRR_Remark = this.txtRefundRemark.Text.Trim(); model.DRR_CreateName = this.cmbtreevRefundName.Tag.ToString(); model.DRR_HandledName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID; model.DRR_CreateDatetime = SDateTime.Now; model.DRR_PaymentType = this.cbx_PaymentType.Tag.ToString_s(); clist.Add(drrbll.GetAddCommandInfo(model)); if (model.DRR_Type == 1) { string StrPaymentMethod = ""; DataTable dt = orbll.GetView_Custom("tb_ErpDressDepositReceivables", StrWhere: "DDR_Number = '" + model.DRR_Number + "'", ShowColumnName: "DDR_PaymentMethod").Tables[0]; if (dt.Rows.Count > 0) { StrPaymentMethod = dt.Rows[0]["DDR_PaymentMethod"].ToString().Trim(); } LYFZ.Model.Model_ErpOtherIncomeAndExpenses modelIE = new Model.Model_ErpOtherIncomeAndExpenses(); modelIE.Oiae_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID(); modelIE.Oiae_Type = "收入"; modelIE.Oiae_ProjectName = "礼服报损"; modelIE.Oiae_Money = model.DRR_Money; modelIE.Oiae_IEDatetime = model.DRR_CreateDatetime; modelIE.Oiae_PersonHandling = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID; modelIE.Oiae_ThePayer = this.txtClientName.Text.Trim(); modelIE.Oiae_Invoice = ""; modelIE.Oiae_SourceType = 1; modelIE.Oiae_OrderNumber = model.DRR_Number; modelIE.Oiae_RelatedNumber = model.DRR_RefundNumber; modelIE.Oiae_Remark = "礼服报损,礼服单号:" + this.StrOrderNumber; modelIE.Oiae_CreateDateTime = model.DRR_CreateDatetime; modelIE.Oiae_PaymentMethod = StrPaymentMethod; modelIE.Oiae_FinancialAuditState = "未审核"; modelIE.Oiae_ManagerAuditState = "未审核"; modelIE.Oiae_CEOAuditState = "未审核"; clist.Add(oiebll.GetAddCommandInfo(modelIE)); } if (clist.Count > 0) { if (MessageBoxCustom.Show("你确定要" + this.cmbtreevRefundType.Text.Trim() + "吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.No) { return; } if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0) { this.IsSaveed = true; MessageBoxCustom.Show("保存成功!"); this.FrmRefundRecord_Shown(this, null); } else { MessageBoxCustom.Show("保存失败!"); } } } /// /// 关闭 /// /// /// void btnClose_Click(object sender, EventArgs e) { this.Close(); } /// /// 打印收据 /// /// /// void btnPrint_Click(object sender, EventArgs e) { if (this.dgvData.SelectedRows.Count == 0) { MessageBoxCustom.Show("请选择你要打印的数据!"); return; } LYFZ.BLL.BLL_ErpDressSaleRentalOrder DressSaleRentalOrderbll = new BLL.BLL_ErpDressSaleRentalOrder(); DataTable dt = DressSaleRentalOrderbll.GetList("Dsro_Number='" + StrOrderNumber + "'").Tables[0]; if (dt.Rows.Count > 0) { decimal OkRefundAmount = 0; for (int i = 0; i < this.dgvData.Rows.Count; i++) { OkRefundAmount += Convert.ToDecimal(this.dgvData.Rows[i].Cells["金额"].Value); } Hashtable htData = new Hashtable(); htData["dgvData"] = this.dgvData; htData["DressOrderNumber"] = StrOrderNumber.Trim(); htData["CustomerNumber"] = dt.Rows[0]["Dsro_CustomerNumber"].ToString(); htData["DepositAmount"] = dt.Rows[0]["Dsro_MortgageAmount"].ToString(); htData["NotRefundAmount"] = Convert.ToDecimal(dt.Rows[0]["Dsro_MortgageAmount"]) - OkRefundAmount; LYFZ.Software.MainBusiness.ReportPrint.ReportFixedFormat.PrintFixedFormat(LYFZ.EnumPublic.PrintTypeEnum.礼服出租退押金, htData); } } /// /// 删除 /// /// /// void btnDelete_Click(object sender, EventArgs e) { if (this.dgvData.SelectedRows.Count == 0) { MessageBoxCustom.Show("请选中你要删除的数据!"); return; } int id = Convert.ToInt32(this.dgvData.CurrentRow.Cells["ID"].Value); DataTable dt = drrbll.GetList("Id=" + id + "").Tables[0]; if (dt.Rows.Count > 0) { if (dt.Rows[0]["DRR_RefundAmountAudit"].ToString().Trim() == "已审核") { MessageBoxCustom.Show("退款已审核成功,不能删除!"); return; } } if (this.dgvData.CurrentRow.Cells["退款类型"].Value.ToString().Trim() == "退押金") { if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.No) { return; } if (drrbll.Delete(id) == true) { // 写入操作日志 string logsContent = "删除退押金:礼服单号:" + StrOrderNumber + ";退押金金额" + dt.Rows[0]["DRR_Money"].ToString().Trim(); ; LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(LYFZ.EnumPublic.SystemLogsType.删除订单, logsContent, LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name); MessageBoxCustom.Show("删除成功!"); this.PublicFunctionRows(); } } else if (this.dgvData.CurrentRow.Cells["退款类型"].Value.ToString().Trim() == "报损") { List clist = new List(); DataTable dt2 = orbll.GetView_Custom("tb_ErpOtherIncomeAndExpenses", StrWhere: "Oiae_RelatedNumber = '" + dt.Rows[0]["DRR_RefundNumber"].ToString().Trim() + "'", ShowColumnName: "ID,Oiae_CEOAuditState").Tables[0]; if (dt2.Rows.Count > 0) { if (dt2.Rows[0]["Oiae_CEOAuditState"].ToString().Trim() == "已审核") { MessageBoxCustom.Show("报损已审核成功,不能删除!"); return; } clist.Add(oiebll.GetDeleteCommandInfo("ID", "=", dt2.Rows[0]["ID"])); } clist.Add(drrbll.GetDeleteCommandInfo("ID", "=", id)); string logsContent = "删除报损:礼服单号:" + StrOrderNumber + ";报损编号:" + dt.Rows[0]["DRR_RefundNumber"].ToString().Trim() + ";报损金额" + dt.Rows[0]["DRR_Money"].ToString().Trim(); LYFZ.Model.Model_ErpSystemLogs modelLog = LYFZ.BLL.BLL_ErpSystemLogs.GetWriteLogModel(LYFZ.EnumPublic.SystemLogsType.删除订单, logsContent, LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name, LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID()); syslogbll.GetAddCommandInfo(modelLog); if (clist.Count > 0) { if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.No) { return; } if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0) { MessageBoxCustom.Show("删除成功!"); this.FrmRefundRecord_Shown(this, null); } else { MessageBoxCustom.Show("删除失败!"); } } } } } }