Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            op           = RequestData.Get <string>("op");
            orderids     = RequestData.Get <string>("orderids");
            id           = RequestData.Get <string>("id");
            CustomerId   = RequestData.Get <string>("CustomerId");
            CustomerName = Server.HtmlDecode(RequestData.Get <string>("CustomerName"));
            entStrList   = RequestData.GetList <string>("data");
            if (!string.IsNullOrEmpty(id))
            {
                ent = OrderInvoice.Find(id);
            }
            switch (RequestActionString)
            {
            case "update":
                ent = GetMergedData <OrderInvoice>();
                ent.DoUpdate();
                ProcessDetail();
                break;

            case "JudgeRepeat":
                sql = "select count(1) from SHHG_AimExamine..OrderInvoice where Number like '%" + RequestData.Get <string>("InvoiceNo") + "%' ";
                if (DataHelper.QueryValue <int>(sql) > 0)
                {
                    PageState.Add("IsRepeat", "T");
                }
                else
                {
                    PageState.Add("IsRepeat", "F");
                }
                break;

            case "create":
                ent     = GetPostedData <OrderInvoice>();
                ent.OId = orderids;
                ent.DoCreate();
                ProcessDetail();
                break;

            default:
                DoSelect();
                break;
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }