protected void Page_Load(object sender, EventArgs e) { op = RequestData.Get <string>("op"); ids = RequestData.Get <string>("ids"); id = RequestData.Get <string>("id"); type = RequestData.Get <string>("type"); OrderInvoice ent = null; switch (this.RequestAction) { case RequestActionEnum.Update: ent = this.GetMergedData <OrderInvoice>(); ent.DoUpdate(); this.SetMessage("修改成功!"); break; case RequestActionEnum.Insert: case RequestActionEnum.Create: ent = this.GetPostedData <OrderInvoice>(); ent.OId = ids; ent.DoCreate(); IList <string> strList = RequestData.GetList <string>("data"); string[] oids = ids.Split(','); SaleOrder[] ents = SaleOrder.FindAllByPrimaryKeys(oids); if (ents.Length > 0) { foreach (SaleOrder soent in ents) { //更新订单开票状态及发票号码 soent.InvoiceState = getInvoiceState(strList, soent.Id, soent.Number); soent.InvoiceNumber += ent.Number + ","; soent.DoSave(); } } this.SetMessage("新建成功!"); break; case RequestActionEnum.Delete: ent = this.GetTargetData <OrderInvoice>(); ent.DoDelete(); this.SetMessage("删除成功!"); return; default: if (RequestActionString == "") { } break; } //加载要开发票的数据 if (op == "c" && !string.IsNullOrEmpty(ids)) { string[] oids = ids.Split(','); SaleOrder[] ents = SaleOrder.FindAllByPrimaryKeys(oids); if (ents.Length > 0) { DataTable dtall = null; DataTable dtMain = null; DataTable dtReturn = null; DataTable dtChange = null; string columns = "Id,OId,PId as ProductId,PCode as ProductCode,PName as ProductName,Isbn,[Count],Unit,SalePrice,Amount,Remark,BillingCount,'销售' as Type"; string columns2 = "Id,OId,ProductId,ProductCode,ProductName,Isbn,[Count],Unit,ReturnPrice as SalePrice,Amount,Remark,BillingCount"; foreach (SaleOrder soent in ents) { //partList.AddRange(OrdersPart.FindAllByProperty("OId", soent.Id)); //查询数据 dtMain = DataHelper.QueryDataTable("select " + columns + " from " + db + "..OrdersPart where OId='" + soent.Id + "'"); dtReturn = DataHelper.QueryDataTable("select " + columns2 + ",'退货' as Type from " + db + "..ReturnOrderPart where OId='" + soent.Id + "'"); dtChange = DataHelper.QueryDataTable("select " + columns2 + ",'换货' as Type from " + db + "..ChangeOrderPart where OId='" + soent.Id + "'"); //处理换货商品 DataTable dttemp = dtMain; if (dtChange.Rows.Count > 0) { bool isfind = false; foreach (DataRow charow in dtChange.Rows) { isfind = false; foreach (DataRow mainrow in dtMain.Rows) { if (charow["ProductId"] + "" == mainrow["ProductId"] + "") { isfind = true; //加上换货的商品数量 //dttemp.Rows.Remove(mainrow); mainrow["Count"] = Convert.ToInt32(mainrow["Count"]) + Convert.ToInt32(charow["Count"]); mainrow["Amount"] = Convert.ToInt32(mainrow["Amount"]) + Convert.ToInt32(charow["Amount"]); //dttemp.Rows.Add(mainrow); break; } } //不在原商品列表里,添加新的 if (!isfind) { dttemp.Rows.Add(charow.ItemArray); } } dtMain = dttemp; } //处理退货商品 if (dtReturn.Rows.Count > 0) { foreach (DataRow rtnrow in dtReturn.Rows) { foreach (DataRow mainrow in dtMain.Rows) { if (rtnrow["ProductId"] + "" == mainrow["ProductId"] + "") { //完全退货移除 if (rtnrow["Count"] + "" == mainrow["Count"] + "") { dttemp.Rows.Remove(mainrow); } else { //dttemp.Rows.Remove(mainrow); mainrow["Count"] = Convert.ToInt32(mainrow["Count"]) - Convert.ToInt32(rtnrow["Count"]); mainrow["Amount"] = Convert.ToInt32(mainrow["Amount"]) - Convert.ToInt32(rtnrow["Amount"]); //dttemp.Rows.Add(mainrow); } break; } } } dtMain = dttemp; } if (dtall == null) { dtall = dtMain; } else { dtall.Merge(dtMain); } } #region old // string sql = @"select OId,ProductId,ProductCode,ProductName,Isbn,sum([count]) as [Count],max(SalePrice) as SalePrice,sum(Amount) as Amount,Unit,sum(BillingCount) as BillingCount from( // select Id,OId,PId as ProductId,PCode as ProductCode,PName as ProductName,Isbn,[Count],Unit,SalePrice,Amount,BillingCount from {0}..OrdersPart // union all // select Id,OId,ProductId,ProductCode,ProductName,Isbn,[Count],Unit,0,Amount,BillingCount from {1}..ChangeOrderPart // union all // select Id,OId,ProductId,ProductCode,ProductName,Isbn,([Count]*-1) as [Count],Unit,0,(Amount*-1) as Amount,BillingCount from {2}..ReturnOrderPart // )t where OId in ('" + ids.Replace(",", "','") + "') group by ProductId,ProductCode,ProductName,Unit,Isbn,OId having sum([Count])>0"; // DataTable dt = DataHelper.QueryDataTable(string.Format(sql, db, db, db)); // PageState.Add("DetailList", DataHelper.DataTableToDictList(dt)); #endregion PageState.Add("DetailList", DataHelper.DataTableToDictList(dtall)); ents[0].Child = ""; ents[0].Number = ""; this.SetFormData(ents[0]); } } else if (op != "c" && op != "cs") { if (!String.IsNullOrEmpty(id)) { ent = OrderInvoice.Find(id); } this.SetFormData(ent); } }
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; } }