private void DoSelect() { if (op != "c" && op != "cs") { if (!String.IsNullOrEmpty(id)) { ent = PaymentInvoice.Find(id); } } else { ent = new PaymentInvoice(); } SetFormData(ent); PageState.Add("PayType", SysEnumeration.GetEnumDict("PayType")); }
string type = String.Empty; // 对象类型 #endregion #region ASP.NET 事件 protected void Page_Load(object sender, EventArgs e) { op = RequestData.Get <string>("op"); id = RequestData.Get <string>("id"); type = RequestData.Get <string>("type"); PaymentInvoice ent = null; switch (this.RequestAction) { case RequestActionEnum.Update: ent = this.GetMergedData <PaymentInvoice>(); ent.DoUpdate(); this.SetMessage("修改成功!"); break; case RequestActionEnum.Insert: case RequestActionEnum.Create: ent = this.GetPostedData <PaymentInvoice>(); ent.CId = RequestData.Get <string>("CId"); ent.DoCreate(); this.SetMessage("新建成功!"); break; case RequestActionEnum.Delete: ent = this.GetTargetData <PaymentInvoice>(); ent.DoDelete(); this.SetMessage("删除成功!"); return; } if (op != "c" && op != "cs") { if (!String.IsNullOrEmpty(id)) { ent = PaymentInvoice.Find(id); } this.SetFormData(ent); } PageState.Add("PayType", SysEnumeration.GetEnumDict("PayType")); }
protected void Page_Load(object sender, EventArgs e) { CC = RequestData.Get <string>("CC"); string ids = RequestData.Get <string>("ids"); string[] idArray = null; if (!string.IsNullOrEmpty(ids)) { idArray = ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); } switch (RequestActionString) { case "CancelCorrespond": foreach (string str in idArray) //可以同时对多个付款进行撤销对应 { piEnt = PaymentInvoice.Find(str); string[] invoiceArray = piEnt.CorrespondInvoice.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < invoiceArray.Length; i++) { int index = invoiceArray[i].IndexOf("_"); string number = invoiceArray[i].Substring(0, index); //找到对应的发票号和销账金额 对发票进行回滚 decimal amount = Convert.ToDecimal(invoiceArray[i].Substring(index + 1)); OrderInvoice oiEnt = OrderInvoice.FindAllByProperty(OrderInvoice.Prop_Number, number).FirstOrDefault <OrderInvoice>(); oiEnt.PayAmount = oiEnt.PayAmount - amount; oiEnt.PayState = oiEnt.PayAmount > 0 ? "部分付款" : ""; oiEnt.DoUpdate(); } piEnt.CorrespondAmount = 0; piEnt.CorrespondInvoice = ""; piEnt.CorrespondState = ""; piEnt.Name = "暂不销账"; piEnt.DoUpdate(); } break; case "AutoCorrespond": foreach (string id in idArray) { piEnt = PaymentInvoice.Find(id); sql = @"select sum(Amount-isnull(PayAmount,0)) from SHHG_AimExamine..OrderInvoice where (PayState is null or PayState<>'已全部付款') and CId='" + piEnt.CId + "'"; decimal shouldpayAmount = DataHelper.QueryValue <decimal>(sql); //合计应付金额 if (shouldpayAmount > 0) { decimal validAmount = piEnt.Money.Value - (piEnt.CorrespondAmount.HasValue ? piEnt.CorrespondAmount.Value : 0); //有效金额 if (shouldpayAmount >= validAmount) //如果 付款金额小于等于应付款总额 { sql = @"select * from SHHG_AimExamine..OrderInvoice where (PayState is null or PayState<>'已全部付款') and CId='" + piEnt.CId + "' order by InvoiceDate asc"; IList <EasyDictionary> dics = DataHelper.QueryDictList(sql); //decimal payamount = piEnt.Money.Value; foreach (EasyDictionary dic in dics) { if (validAmount > 0) { OrderInvoice oiEnt = OrderInvoice.Find(dic.Get <string>("Id")); if (validAmount >= (oiEnt.Amount.Value - (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0))) //大于等于该发票的未付金额 { validAmount = validAmount - (oiEnt.Amount.Value - (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0)); oiEnt.PayState = "已全部付款"; piEnt.CorrespondInvoice += (string.IsNullOrEmpty(piEnt.CorrespondInvoice) ? "" : ",") + oiEnt.Number + "_" + (oiEnt.Amount - (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0)); oiEnt.PayAmount = oiEnt.Amount; } else { oiEnt.PayAmount = (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0) + validAmount; oiEnt.PayState = "部分付款"; piEnt.CorrespondInvoice += (string.IsNullOrEmpty(piEnt.CorrespondInvoice) ? "" : ",") + oiEnt.Number + "_" + validAmount; validAmount = 0; } oiEnt.DoUpdate(); } } piEnt.CorrespondAmount = piEnt.Money; piEnt.CorrespondState = "已对应"; piEnt.Name = "自动销账"; piEnt.DoUpdate(); } else //如果付款金额大于应付款总金额 { sql = @"select * from SHHG_AimExamine..OrderInvoice where (PayState is null or PayState<>'已全部付款') and CId='" + piEnt.CId + "' order by InvoiceDate asc"; IList <EasyDictionary> dics = DataHelper.QueryDictList(sql); foreach (EasyDictionary dic in dics) { OrderInvoice oiEnt = OrderInvoice.Find(dic.Get <string>("Id")); piEnt.CorrespondInvoice += (string.IsNullOrEmpty(piEnt.CorrespondInvoice) ? "" : ",") + oiEnt.Number + "_" + (oiEnt.Amount - (oiEnt.PayAmount.HasValue ? oiEnt.PayAmount.Value : 0)); piEnt.CorrespondState = "部分对应"; piEnt.CorrespondAmount = (piEnt.CorrespondAmount.HasValue ? piEnt.CorrespondAmount.Value : 0) + shouldpayAmount; piEnt.DoUpdate(); oiEnt.PayState = "已全部付款"; oiEnt.PayAmount = oiEnt.Amount; oiEnt.DoUpdate(); } } } } break; case "delete": foreach (string str in idArray) { piEnt = PaymentInvoice.Find(str); piEnt.DoDelete(); } break; default: DoSelect(); break; } }
protected void Page_Load(object sender, EventArgs e) { string ids = RequestData.Get <string>("ids"); string[] idArray = null; if (!string.IsNullOrEmpty(ids)) { idArray = ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); } id = RequestData.Get <string>("id"); if (!string.IsNullOrEmpty(id)) { piEnt = PaymentInvoice.Find(id); } switch (RequestActionString) { case "CancelCorrespond": foreach (string str in idArray) //可以同时对多个付款进行撤销对应 { piEnt = PaymentInvoice.Find(str); string[] invoiceArray = piEnt.CorrespondInvoice.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < invoiceArray.Length; i++) { int index = invoiceArray[i].IndexOf("_"); string number = invoiceArray[i].Substring(0, index); //找到对应的发票号和销账金额 对发票进行回滚 decimal amount = Convert.ToDecimal(invoiceArray[i].Substring(index + 1)); SaleOrder oiEnt = SaleOrder.FindAllByProperty(SaleOrder.Prop_Number, number).FirstOrDefault <SaleOrder>(); oiEnt.ReceiptAmount = (oiEnt.ReceiptAmount.HasValue ? oiEnt.ReceiptAmount.Value : 0) - amount; oiEnt.PayState = oiEnt.ReceiptAmount > 0 ? "部分付款" : null; oiEnt.DoUpdate(); } piEnt.CorrespondInvoice = ""; piEnt.CorrespondState = ""; piEnt.Name = "暂不销账"; piEnt.DoUpdate(); } break; case "AutoCorrespond": sql = @"select sum(TotalMoney-isnull(DiscountAmount,0)-isnull(ReturnAmount,0)-isnull(ReceiptAmount,0)) from SHHG_AimExamine..SaleOrders where CId='" + piEnt.CId + "' and State is null and InvoiceType='收据' and (PayState is null or PayState='部分付款')"; decimal TotalArrearage = DataHelper.QueryValue <decimal>(sql); if (TotalArrearage >= piEnt.Money) { sql = @"select * from SHHG_AimExamine..SaleOrders where InvoiceType='收据' and CId='" + piEnt.CId + "' and State is null and (PayState is null or PayState='部分付款') order by CreateTime asc"; IList <EasyDictionary> dics = DataHelper.QueryDictList(sql); decimal payamount = piEnt.Money.Value; piEnt.CorrespondInvoice = ""; foreach (EasyDictionary dic in dics) { if (payamount > 0) { SaleOrder oiEnt = SaleOrder.Find(dic.Get <string>("Id")); decimal unpayAmount = oiEnt.TotalMoney.Value - (oiEnt.ReceiptAmount.HasValue ? oiEnt.ReceiptAmount.Value : 0) - (oiEnt.DiscountAmount.HasValue ? oiEnt.DiscountAmount.Value : 0) - (oiEnt.ReturnAmount.HasValue ? oiEnt.ReturnAmount.Value : 0); if (payamount >= unpayAmount) { payamount = payamount - unpayAmount; oiEnt.ReceiptAmount = (oiEnt.ReceiptAmount.HasValue ? oiEnt.ReceiptAmount.Value : 0) + unpayAmount; oiEnt.PayState = "已全部付款"; piEnt.CorrespondInvoice += oiEnt.Number + "_" + unpayAmount + ","; } else { oiEnt.ReceiptAmount = (oiEnt.ReceiptAmount.HasValue ? oiEnt.ReceiptAmount.Value : 0) + payamount; piEnt.CorrespondInvoice += oiEnt.Number + "_" + payamount + ","; payamount = 0; } oiEnt.DoUpdate(); } } piEnt.CorrespondState = "已对应"; piEnt.Name = "自动销账"; piEnt.DoUpdate(); PageState.Add("Result", "T"); } else { PageState.Add("Result", "F"); } break; case "delete": foreach (string str in idArray) { piEnt = PaymentInvoice.Find(str); piEnt.DoDelete(); } break; default: DoSelect(); break; } }