string type = String.Empty; // 对象类型 #endregion #region ASP.NET 事件 protected void Page_Load(object sender, EventArgs e) { string db = ConfigurationManager.AppSettings["ExamineDB"]; op = RequestData.Get <string>("op"); id = RequestData.Get <string>("id"); paids = RequestData.Get <string>("paids"); type = RequestData.Get <string>("type"); DeliveryOrder ent = null; IList <string> strList = RequestData.GetList <string>("data"); PageState.Add("Id", ""); switch (this.RequestAction) { case RequestActionEnum.Insert: case RequestActionEnum.Create: ent = this.GetPostedData <DeliveryOrder>(); ent.PId = paids; //自动生成流水号 ent.Number = DataHelper.QueryValue("select " + db + ".dbo.fun_getDeliveryNumber()") + ""; ent.DoCreate(); //更新销售单状态(放到保存的地方) if (!string.IsNullOrEmpty(paids)) { GetDeliveryState(strList, paids); } //添加出库商品信息 InsertPart(strList, ent.Id); PageState["Id"] = ent.Id; this.SetMessage("新建成功!"); break; default: break; } if (RequestActionString == "getSalesman") { string cid = RequestData.Get <string>("CId"); Customer customer = Customer.Find(cid); if (customer != null) { PageState.Add("result", customer.MagUser); PageState.Add("MagId", customer.MagId); PageState.Add("Address", customer.Address); // PageState.Add("Tel", customer.Tel); PageState.Add("Code", customer.Code); } } else if (RequestActionString == "checkdata") { string productIds = RequestData.Get <string>("productIds"); string WarehouseId = RequestData.Get <string>("WarehouseId"); if (!string.IsNullOrEmpty(productIds)) { int count = DataHelper.QueryValue <int>("select count(1) from " + db + "..StockInfo where WarehouseId='" + WarehouseId + "' and ProductId in ('" + productIds.Replace(",", "','") + "')"); if (count != productIds.Split(',').Length) { PageState.Add("error", "所选商品在指定仓库里没有找到,请重新选择"); } } } //销售订单生成销售出库单 else if (op == "c" && !string.IsNullOrEmpty(paids)) { string[] oids = paids.Split(','); SaleOrder[] ents = SaleOrder.FindAllByPrimaryKeys(oids); if (ents.Length > 0) { ents[0].Id = ""; ents[0].Number = "自动生成"; //ents[0].Remark = ""; ents[0].State = ""; ents[0].Child = "[]"; this.SetFormData(ents[0]); } } else if (op != "c" && op != "cs") { if (!String.IsNullOrEmpty(id)) { ent = DeliveryOrder.Find(id); } this.SetFormData(ent); this.PageState.Add("State", ent.State); } PageState.Add("DeliveryMode", SysEnumeration.GetEnumDict("DeliveryMode")); }
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); } }