private void ProcessDetail() { IList <OrderInvoiceDetail> oidEnts = OrderInvoiceDetail.FindAllByProperty("OrderInvoiceId", ent.Id); foreach (OrderInvoiceDetail oidEnt in oidEnts) { oidEnt.DoDelete(); } oidEnts = entStrList.Select(tent => JsonHelper.GetObject <OrderInvoiceDetail>(tent) as OrderInvoiceDetail).ToList(); foreach (OrderInvoiceDetail oidEnt in oidEnts) { oidEnt.OrderInvoiceId = ent.Id; oidEnt.DoCreate(); OrdersPart opEnt = OrdersPart.Find(oidEnt.OrderDetailId); opEnt.BillingCount = (opEnt.BillingCount.HasValue ? opEnt.BillingCount : 0) + oidEnt.InvoiceCount;//顺便更新订单明细的开票数量 opEnt.DoUpdate(); } string[] orderIdArray = orderids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (string str in orderIdArray)//更新涉及订单的开票状态 { sql = @"select count(Id) from SHHG_AimExamine..OrdersPart where OId='" + str + "' and Count-isnull(ReturnCount,0)<>isnull(BillingCount,0)"; SaleOrder soEnt = SaleOrder.Find(str); if (DataHelper.QueryValue <int>(sql) == 0) { soEnt.InvoiceState = "已全部开发票"; } else { soEnt.InvoiceState = "已部分开发票"; } soEnt.DoUpdate(); } }
protected void Page_Load(object sender, EventArgs e) { Index = RequestData.Get <string>("Index"); CC = RequestData.Get <string>("CC"); string ids = RequestData.Get <string>("ids"); switch (RequestActionString) { case "delete": if (!string.IsNullOrEmpty(ids)) { string[] idArray = ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < idArray.Length; i++) { oiEnt = OrderInvoice.Find(idArray[i]); IList <OrderInvoiceDetail> oidEnts = OrderInvoiceDetail.FindAllByProperty("OrderInvoiceId", oiEnt.Id); foreach (OrderInvoiceDetail oidEnt in oidEnts) { OrdersPart opEnt = OrdersPart.Find(oidEnt.OrderDetailId); opEnt.BillingCount = opEnt.BillingCount - oidEnt.InvoiceCount; opEnt.DoUpdate(); oidEnt.DoDelete(); } //删除发票的时候 回滚销售订单的发票状态 soEnt.InvoiceState = ""; string[] oidArray = oiEnt.OId.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (string oid in oidArray) { SaleOrder soEnt = SaleOrder.Find(oid); sql = "select count(Id) from SHHG_AimExamine..OrdersPart where BillingCount>0 and OId='" + oid + "'"; if (DataHelper.QueryValue <int>(sql) == 0) { soEnt.InvoiceState = ""; } else { soEnt.InvoiceState = "已部分开发票"; } soEnt.DoUpdate(); } oiEnt.DoDelete(); } } break; case "RollBack": if (!string.IsNullOrEmpty(ids)) { string[] idArray = ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < idArray.Length; i++) { oiEnt = OrderInvoice.Find(idArray[i]); oiEnt.PayState = null; oiEnt.PayAmount = null; oiEnt.DoUpdate(); } } break; case "updateorderinvoicedetail": IList <OrderInvoice> oiEnts = OrderInvoice.FindAll(); foreach (OrderInvoice oiEnt in oiEnts) { IList <OrderInvoiceDetail> oidEnts = OrderInvoiceDetail.FindAllByProperty(OrderInvoiceDetail.Prop_OrderInvoiceId, oiEnt.Id); if (oidEnts.Count == 0) { JArray ja = JsonHelper.GetObject <JArray>(oiEnt.Child); foreach (JObject jo in ja) { OrderInvoiceDetail oidEnt = new OrderInvoiceDetail(); oidEnt.OrderDetailId = jo.Value <string>("Id"); oidEnt.OrderInvoiceId = oiEnt.Id; oidEnt.SaleOrderId = jo.Value <string>("OId"); oidEnt.ProductId = jo.Value <string>("ProductId"); oidEnt.ProductCode = jo.Value <string>("ProductCode"); oidEnt.ProductName = jo.Value <string>("ProductName"); oidEnt.SalePrice = jo.Value <decimal>("SalePrice"); oidEnt.Unit = jo.Value <string>("Unit"); oidEnt.Amount = jo.Value <decimal>("Amount"); oidEnt.Count = jo.Value <Int32>("Count"); oidEnt.InvoiceCount = jo.Value <Int32>("Count"); oidEnt.DoCreate(); } } } break; default: DoSelect(); break; } }