FrmRefundRecord.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. namespace LYFZ.Software.MainBusiness.Dresses.DressManagement.Rental
  11. {
  12. public partial class FrmRefundRecord : LYFZ.Software.UI.Dresses.DressManagement.Rental.FrmRefundRecord
  13. {
  14. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  15. LYFZ.BLL.BLL_ErpSystemLogs syslogbll = new BLL.BLL_ErpSystemLogs();
  16. LYFZ.BLL.BLL_ErpDressRefundRecord drrbll = new BLL.BLL_ErpDressRefundRecord();
  17. LYFZ.BLL.BLL_ErpOtherIncomeAndExpenses oiebll = new BLL.BLL_ErpOtherIncomeAndExpenses();
  18. public FrmRefundRecord()
  19. {
  20. this.Shown += FrmRefundRecord_Shown;
  21. this.txtRefundAmount.KeyPress += txtRefundAmount_KeyPress;
  22. this.btnSave.Click += btnSave_Click;
  23. this.btnClose.Click += btnClose_Click;
  24. this.btnPrint.Click += btnPrint_Click;
  25. this.btnDelete.Click += btnDelete_Click;
  26. }
  27. /// <summary>
  28. /// 是否保存
  29. /// </summary>
  30. public bool IsSaveed = false;
  31. /// <summary>
  32. /// 订单号
  33. /// </summary>
  34. public string StrOrderNumber;
  35. /// <summary>
  36. /// 窗体加载事件
  37. /// </summary>
  38. /// <param name="sender"></param>
  39. /// <param name="e"></param>
  40. void FrmRefundRecord_Shown(object sender, EventArgs e)
  41. {
  42. this.dgvData.DataColumns("ID,退款类型,金额,退款人,录入人,录入时间,退款备注", strHideField: "ID");
  43. this.btnDelete.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.DressManagement, CustomAttributes.OperatingAuthority.Delete);
  44. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_DepartmentAndEmployee(this.cmbtreevRefundName, IsFirstNodeNull: true);
  45. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboxTreeView(this.cmbtreevRefundType, "退押金,报损", IsFirstNodeNull: true);
  46. if (!string.IsNullOrEmpty(this.StrOrderNumber))
  47. {
  48. DataTable dt = orbll.GetView_Custom("BView_DressOrderReport", StrWhere: "订单号 = '" + this.StrOrderNumber + "'", ShowColumnName: "订单号,客户姓名,客户电话,欠款金额,应收押金,已收押金,未退押金,是否还衣,订单备注").Tables[0];
  49. if (dt.Rows.Count > 0)
  50. {
  51. this.txtOrderNumber.Text = dt.Rows[0]["订单号"].ToString().Trim();
  52. this.txtClientName.Text = dt.Rows[0]["客户姓名"].ToString().Trim();
  53. this.txtClientPhone.Text = dt.Rows[0]["客户电话"].ToString().Trim();
  54. this.txtArrears.Text = dt.Rows[0]["欠款金额"].ToString().Trim();
  55. this.txtBackStatus.Text = dt.Rows[0]["是否还衣"].ToString().Trim();
  56. this.txtReceivableDeposit.Text = dt.Rows[0]["应收押金"].ToString().Trim();
  57. this.txtReceivedDeposit.Text = dt.Rows[0]["已收押金"].ToString().Trim();
  58. this.txtNotReturnedDeposit.Text = dt.Rows[0]["未退押金"].ToString().Trim();
  59. this.txtRemark.Text = dt.Rows[0]["订单备注"].ToString().Trim();
  60. this.txtRefundAmount.Text = dt.Rows[0]["未退押金"].ToString().Trim();
  61. }
  62. this.PublicFunctionRows();
  63. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_PaymentMethod(this.cbx_PaymentType,StrWhere: " Sc_ClassCode != 'BEBACCAFEGECFBJFD' ");
  64. //DataTable dt = orbll.GetView_Custom("tb_ErpDressDepositReceivables", StrWhere: "DDR_Number = '" + this.StrOrderNumber + "'", ShowColumnName: "sum(DDR_Money) AS SumAmount").Tables[0];
  65. //if (string.IsNullOrEmpty(dt.Rows[0]["SumAmount"].ToString().Trim()))
  66. //{ this.txtRefundAmount.Text = "0"; }
  67. //else
  68. //{ this.txtRefundAmount.Text = dt.Rows[0]["SumAmount"].ToString().Trim(); }
  69. //this.PublicFunctionRows();
  70. }
  71. }
  72. /// <summary>
  73. /// 绑定退款记录
  74. /// </summary>
  75. void PublicFunctionRows()
  76. {
  77. this.dgvData.Rows.Clear();
  78. 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";
  79. 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];
  80. this.dgvData.DataSource(dt, strHideField: "ID");
  81. this.dgvData.Columns["录入时间"].Width = 110;
  82. this.dgvData.FillLastColumn();
  83. }
  84. /// <summary>
  85. /// 输入框设置
  86. /// </summary>
  87. /// <param name="sender"></param>
  88. /// <param name="e"></param>
  89. void txtRefundAmount_KeyPress(object sender, KeyPressEventArgs e)
  90. {
  91. if (!Char.IsNumber(e.KeyChar) && !Char.IsPunctuation(e.KeyChar) && !Char.IsControl(e.KeyChar))
  92. { e.Handled = true; }
  93. else if (Char.IsPunctuation(e.KeyChar))
  94. {
  95. if (e.KeyChar == '.')
  96. {
  97. if (((System.Windows.Forms.TextBox)sender).Text.LastIndexOf('.') != -1)
  98. { e.Handled = true; }
  99. }
  100. else
  101. { e.Handled = true; }
  102. }
  103. }
  104. /// <summary>
  105. /// 保存
  106. /// </summary>
  107. /// <param name="sender"></param>
  108. /// <param name="e"></param>
  109. void btnSave_Click(object sender, EventArgs e)
  110. {
  111. if (string.IsNullOrEmpty(this.cmbtreevRefundType.Text.Trim()))
  112. { MessageBoxCustom.Show("退款类型不能为空!"); return; }
  113. if (string.IsNullOrEmpty(this.txtRefundAmount.Text.Trim()))
  114. { MessageBoxCustom.Show("金额不能为空!"); return; }
  115. if (Convert.ToDecimal(this.txtRefundAmount.Text.Trim()) <= 0)
  116. { MessageBoxCustom.Show("退款金额必须大于0!"); return; }
  117. if (string.IsNullOrEmpty(this.cmbtreevRefundName.Text.Trim()))
  118. { MessageBoxCustom.Show("退款人不能为空!"); return; }
  119. if (string.IsNullOrEmpty(this.cbx_PaymentType.Text.Trim()))
  120. { MessageBoxCustom.Show("退款方式不能为空!"); return; }
  121. List<LYFZ.Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  122. LYFZ.Model.Model_ErpDressRefundRecord model = new Model.Model_ErpDressRefundRecord();
  123. model.DRR_RefundNumber = "D3RN" + LYFZ.BLL.BLL_ErpCustomer.GetClientNumber();
  124. model.DRR_Number = this.StrOrderNumber;
  125. model.DRR_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
  126. if (this.cmbtreevRefundType.Text.Trim() == "退押金")
  127. {
  128. model.DRR_Type = 0;
  129. DataTable dt = orbll.GetView_Custom("tb_ErpDressSaleRentalOrder", StrWhere: "Dsro_Number = '" + this.StrOrderNumber + "'", ShowColumnName: "Dsro_MortgageAmount").Tables[0];
  130. if (dt.Rows.Count > 0)
  131. {
  132. if (Convert.ToDecimal(dt.Rows[0]["Dsro_MortgageAmount"]) <= 0)
  133. { MessageBoxCustom.Show("此订单的订单押金为零,不需要退押金!"); return; }
  134. DataTable tb = orbll.GetView_Custom("tb_ErpDressDepositReceivables", StrWhere: "DDR_Number = '" + this.StrOrderNumber + "'", ShowColumnName: "sum(DDR_Money) AS SumAmount").Tables[0];
  135. if (tb.Rows.Count <= 0 || string.IsNullOrEmpty(tb.Rows[0]["SumAmount"].ToString().Trim()))
  136. { MessageBoxCustom.Show("此订单未收押金,不能处理退押金!"); return; }
  137. decimal ReceivedDeposit = Convert.ToDecimal(tb.Rows[0]["SumAmount"]);
  138. DataTable tbl = orbll.GetView_Custom("tb_ErpDressRefundRecord", StrWhere: "DRR_Number='" + this.StrOrderNumber + "'", ShowColumnName: "sum(DRR_Money) AS SumAmount").Tables[0];
  139. if (tbl.Rows.Count > 0)
  140. {
  141. decimal decA = 0;
  142. if (!string.IsNullOrEmpty(tbl.Rows[0]["SumAmount"].ToString()))
  143. { decA = Convert.ToDecimal(tbl.Rows[0]["SumAmount"]); }
  144. if ((decA + Convert.ToDecimal(txtRefundAmount.Text)) > ReceivedDeposit)
  145. { MessageBoxCustom.Show("退押金金额不能超过收到的押金金额(收到押金金额为:" + ReceivedDeposit + " 已退:" + decA + ")!"); return; }
  146. }
  147. }
  148. DataTable dts = orbll.GetView_Custom("BView_DressOrderReport", StrWhere: "订单号 = '" + StrOrderNumber + "'", ShowColumnName: "欠款金额").Tables[0];
  149. if (dts.Rows.Count > 0)
  150. {
  151. if (Convert.ToDecimal(dts.Rows[0]["欠款金额"]) > 0)
  152. { MessageBoxCustom.Show("订单有欠款,不能退押金!"); return; }
  153. }
  154. }
  155. else
  156. { model.DRR_Type = 1; }
  157. model.DRR_Money = Convert.ToDecimal(this.txtRefundAmount.Text);
  158. model.DRR_RefundAmountAudit = "";
  159. model.DRR_RefundAmountAuditName = "";
  160. model.DRR_RefundAmountAuditRemark = "";
  161. model.DRR_Remark = this.txtRefundRemark.Text.Trim();
  162. model.DRR_CreateName = this.cmbtreevRefundName.Tag.ToString();
  163. model.DRR_HandledName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  164. model.DRR_CreateDatetime = SDateTime.Now;
  165. model.DRR_PaymentType = this.cbx_PaymentType.Tag.ToString_s();
  166. clist.Add(drrbll.GetAddCommandInfo(model));
  167. if (model.DRR_Type == 1)
  168. {
  169. string StrPaymentMethod = "";
  170. DataTable dt = orbll.GetView_Custom("tb_ErpDressDepositReceivables", StrWhere: "DDR_Number = '" + model.DRR_Number + "'", ShowColumnName: "DDR_PaymentMethod").Tables[0];
  171. if (dt.Rows.Count > 0)
  172. { StrPaymentMethod = dt.Rows[0]["DDR_PaymentMethod"].ToString().Trim(); }
  173. LYFZ.Model.Model_ErpOtherIncomeAndExpenses modelIE = new Model.Model_ErpOtherIncomeAndExpenses();
  174. modelIE.Oiae_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
  175. modelIE.Oiae_Type = "收入";
  176. modelIE.Oiae_ProjectName = "礼服报损";
  177. modelIE.Oiae_Money = model.DRR_Money;
  178. modelIE.Oiae_IEDatetime = model.DRR_CreateDatetime;
  179. modelIE.Oiae_PersonHandling = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  180. modelIE.Oiae_ThePayer = this.txtClientName.Text.Trim();
  181. modelIE.Oiae_Invoice = "";
  182. modelIE.Oiae_SourceType = 1;
  183. modelIE.Oiae_OrderNumber = model.DRR_Number;
  184. modelIE.Oiae_RelatedNumber = model.DRR_RefundNumber;
  185. modelIE.Oiae_Remark = "礼服报损,礼服单号:" + this.StrOrderNumber;
  186. modelIE.Oiae_CreateDateTime = model.DRR_CreateDatetime;
  187. modelIE.Oiae_PaymentMethod = StrPaymentMethod;
  188. modelIE.Oiae_FinancialAuditState = "未审核";
  189. modelIE.Oiae_ManagerAuditState = "未审核";
  190. modelIE.Oiae_CEOAuditState = "未审核";
  191. clist.Add(oiebll.GetAddCommandInfo(modelIE));
  192. }
  193. if (clist.Count > 0)
  194. {
  195. if (MessageBoxCustom.Show("你确定要" + this.cmbtreevRefundType.Text.Trim() + "吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.No)
  196. { return; }
  197. if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0)
  198. {
  199. this.IsSaveed = true;
  200. MessageBoxCustom.Show("保存成功!");
  201. this.FrmRefundRecord_Shown(this, null);
  202. }
  203. else
  204. { MessageBoxCustom.Show("保存失败!"); }
  205. }
  206. }
  207. /// <summary>
  208. /// 关闭
  209. /// </summary>
  210. /// <param name="sender"></param>
  211. /// <param name="e"></param>
  212. void btnClose_Click(object sender, EventArgs e)
  213. {
  214. this.Close();
  215. }
  216. /// <summary>
  217. /// 打印收据
  218. /// </summary>
  219. /// <param name="sender"></param>
  220. /// <param name="e"></param>
  221. void btnPrint_Click(object sender, EventArgs e)
  222. {
  223. if (this.dgvData.SelectedRows.Count == 0)
  224. { MessageBoxCustom.Show("请选择你要打印的数据!"); return; }
  225. LYFZ.BLL.BLL_ErpDressSaleRentalOrder DressSaleRentalOrderbll = new BLL.BLL_ErpDressSaleRentalOrder();
  226. DataTable dt = DressSaleRentalOrderbll.GetList("Dsro_Number='" + StrOrderNumber + "'").Tables[0];
  227. if (dt.Rows.Count > 0)
  228. {
  229. decimal OkRefundAmount = 0;
  230. for (int i = 0; i < this.dgvData.Rows.Count; i++)
  231. {
  232. OkRefundAmount += Convert.ToDecimal(this.dgvData.Rows[i].Cells["金额"].Value);
  233. }
  234. Hashtable htData = new Hashtable();
  235. htData["dgvData"] = this.dgvData;
  236. htData["DressOrderNumber"] = StrOrderNumber.Trim();
  237. htData["CustomerNumber"] = dt.Rows[0]["Dsro_CustomerNumber"].ToString();
  238. htData["DepositAmount"] = dt.Rows[0]["Dsro_MortgageAmount"].ToString();
  239. htData["NotRefundAmount"] = Convert.ToDecimal(dt.Rows[0]["Dsro_MortgageAmount"]) - OkRefundAmount;
  240. LYFZ.Software.MainBusiness.ReportPrint.ReportFixedFormat.PrintFixedFormat(LYFZ.EnumPublic.PrintTypeEnum.礼服出租退押金, htData);
  241. }
  242. }
  243. /// <summary>
  244. /// 删除
  245. /// </summary>
  246. /// <param name="sender"></param>
  247. /// <param name="e"></param>
  248. void btnDelete_Click(object sender, EventArgs e)
  249. {
  250. if (this.dgvData.SelectedRows.Count == 0)
  251. { MessageBoxCustom.Show("请选中你要删除的数据!"); return; }
  252. int id = Convert.ToInt32(this.dgvData.CurrentRow.Cells["ID"].Value);
  253. DataTable dt = drrbll.GetList("Id=" + id + "").Tables[0];
  254. if (dt.Rows.Count > 0)
  255. {
  256. if (dt.Rows[0]["DRR_RefundAmountAudit"].ToString().Trim() == "已审核")
  257. { MessageBoxCustom.Show("退款已审核成功,不能删除!"); return; }
  258. }
  259. if (this.dgvData.CurrentRow.Cells["退款类型"].Value.ToString().Trim() == "退押金")
  260. {
  261. if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.No)
  262. { return; }
  263. if (drrbll.Delete(id) == true)
  264. {
  265. // 写入操作日志
  266. string logsContent = "删除退押金:礼服单号:" + StrOrderNumber + ";退押金金额" + dt.Rows[0]["DRR_Money"].ToString().Trim(); ;
  267. LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(LYFZ.EnumPublic.SystemLogsType.删除订单, logsContent, LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
  268. MessageBoxCustom.Show("删除成功!");
  269. this.PublicFunctionRows();
  270. }
  271. }
  272. else if (this.dgvData.CurrentRow.Cells["退款类型"].Value.ToString().Trim() == "报损")
  273. {
  274. List<LYFZ.Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  275. DataTable dt2 = orbll.GetView_Custom("tb_ErpOtherIncomeAndExpenses", StrWhere: "Oiae_RelatedNumber = '" + dt.Rows[0]["DRR_RefundNumber"].ToString().Trim() + "'", ShowColumnName: "ID,Oiae_CEOAuditState").Tables[0];
  276. if (dt2.Rows.Count > 0)
  277. {
  278. if (dt2.Rows[0]["Oiae_CEOAuditState"].ToString().Trim() == "已审核")
  279. { MessageBoxCustom.Show("报损已审核成功,不能删除!"); return; }
  280. clist.Add(oiebll.GetDeleteCommandInfo("ID", "=", dt2.Rows[0]["ID"]));
  281. }
  282. clist.Add(drrbll.GetDeleteCommandInfo("ID", "=", id));
  283. string logsContent = "删除报损:礼服单号:" + StrOrderNumber + ";报损编号:" + dt.Rows[0]["DRR_RefundNumber"].ToString().Trim() + ";报损金额" + dt.Rows[0]["DRR_Money"].ToString().Trim();
  284. 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());
  285. syslogbll.GetAddCommandInfo(modelLog);
  286. if (clist.Count > 0)
  287. {
  288. if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.No)
  289. { return; }
  290. if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0)
  291. {
  292. MessageBoxCustom.Show("删除成功!");
  293. this.FrmRefundRecord_Shown(this, null);
  294. }
  295. else
  296. { MessageBoxCustom.Show("删除失败!"); }
  297. }
  298. }
  299. }
  300. }
  301. }