コード例 #1
0
ファイル: FrmOrdersEdit.aspx.cs プロジェクト: radtek/SHHG_ERP
        protected void Page_Load(object sender, EventArgs e)
        {
            string db = ConfigurationManager.AppSettings["ExamineDB"];

            op      = RequestData.Get <string>("op");
            id      = RequestData.Get <string>("id");
            paid    = RequestData.Get <string>("paid");
            PAState = RequestData.Get <string>("PAState");
            type    = RequestData.Get <string>("type");

            SaleOrder      ent     = null;
            IList <string> strList = RequestData.GetList <string>("data");

            switch (this.RequestAction)
            {
            case RequestActionEnum.Update:
                ent = this.GetMergedData <SaleOrder>();
                if (PAState == "Yes")
                {
                    ent.PAState  = "待审核";
                    ent.PANumber = DataHelper.QueryValue("select " + db + ".dbo.fun_getPriceAppNumber()") + "";
                }
                else
                {
                    ent.PAState  = "";
                    ent.PANumber = "";
                }

                ent.DoUpdate();

                //处理OrdersPart表
                //删除
                OrdersPart.DeleteAll("OId='" + ent.Id + "'");
                //添加
                InsertProPart(ent, strList);

                //创建价格申请单
                if (PAState == "Yes")
                {
                    CreatePriceApply(ent);
                }

                #region  除出库单表并更新销售单状态

                if (RequestData.Get <string>("del") == "yes")
                {
                    DeliveryOrder[] dorders = DeliveryOrder.FindAllByProperty("PId", ent.Id);
                    foreach (DeliveryOrder dorder in dorders)
                    {
                        DelieryOrderPart.DeleteAll("DId='" + dorder.Id + "'");
                        DeliveryOrder.DeleteAll("Id='" + dorder.Id + "'");
                    }

                    //更新出库单状态
                    OrdersPart[] ops = OrdersPart.FindAllByProperty("OId", ent.Id);
                    foreach (OrdersPart opt in ops)
                    {
                        if (opt != null)
                        {
                            opt.OutCount = 0;
                            opt.DoSave();
                        }
                    }

                    //更新order的json
                    string jsons = "";
                    ops = OrdersPart.FindAllByProperty("OId", ent.Id);
                    foreach (OrdersPart opt in ops)
                    {
                        jsons += "{";
                        jsons += "Id:'" + opt.PId + "',";
                        jsons += "Isbn:'" + opt.Isbn + "',";
                        jsons += "Code:'" + opt.PCode + "',";
                        jsons += "Name:'" + opt.PName + "',";
                        jsons += "Unit:'" + opt.Unit + "',";
                        jsons += "MinSalePrice:'" + opt.MinSalePrice + "',";
                        jsons += "Price:'" + opt.SalePrice + "',";
                        jsons += "Amount:'" + opt.Amount + "',";
                        jsons += "Count:'" + opt.Count + "',";
                        jsons += "OutCount:'" + opt.OutCount + "',";
                        jsons += "Remark:'" + opt.Remark + "'";
                        jsons += "},";
                    }

                    string count = DataHelper.QueryValue("select count(1) from " + db + "..OrdersPart where OId='" + ent.Id + "' and OutCount=[Count]") + "";
                    if (count == "0")
                    {
                        ent.DeliveryState = "";
                    }
                    else
                    {
                        ent.DeliveryState = "部分生成出库单";
                    }

                    ent.Child = "[" + jsons.Substring(0, jsons.Length - 1) + "]";
                    ent.DoUpdate();
                }
                #endregion

                this.SetMessage("修改成功!");
                break;

            case RequestActionEnum.Insert:
            case RequestActionEnum.Create:
                ent = this.GetPostedData <SaleOrder>();
                if (PAState == "Yes")
                {
                    ent.PAState  = "待审核";
                    ent.PANumber = DataHelper.QueryValue("select " + db + ".dbo.fun_getPriceAppNumber()") + "";
                }
                ent.PId = paid;

                //自动生成流水号
                ent.Number = DataHelper.QueryValue("select " + db + ".dbo.fun_getOrderNumber()") + "";

                ent.DoCreate();

                //处理OrdersPart表
                //添加

                InsertProPart(ent, strList);

                //创建价格申请单
                if (PAState == "Yes")
                {
                    CreatePriceApply(ent);
                }

                this.SetMessage("新建成功!");
                break;

            case RequestActionEnum.Delete:
                ent = this.GetTargetData <SaleOrder>();
                ent.DoDelete();
                this.SetMessage("删除成功!");
                return;

            default:
                if (RequestActionString == "submitfinish")
                {
                    SaleOrder pc = SaleOrder.Find(this.RequestData.Get <string>("id"));
                    pc.State         = "End";
                    pc.DeliveryState = "已生成出库单";
                    pc.ApprovalState = this.RequestData.Get <string>("ApprovalState");
                    pc.Save();

                    //自动生成发货单
                    if (pc.ApprovalState == "同意")
                    {
                        DeliveryOrder dor = new DeliveryOrder
                        {
                            Child         = pc.Child,
                            CId           = pc.Id,
                            WarehouseId   = pc.WarehouseId,
                            WarehouseName = pc.WarehouseName,
                            CName         = pc.CName,
                            CreateId      = UserInfo.UserID,
                            CreateName    = UserInfo.Name,
                            CreateTime    = DateTime.Now,
                            ExpectedTime  = pc.ExpectedTime,
                            Number        = DateTime.Now.ToString("yyyyMMddHHmmss")
                        };
                        dor.DoCreate();
                    }
                }
                else if (RequestActionString == "inputexcel")
                {
                    string path  = @"D:\RW\Files\AppFiles\Portal\Default\" + RequestData.Get <string>("path");
                    string strcn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';";    //连接字符串

                    #region 遍历整个excel
                    //DataSet ds = GetDataFromExcel(path);

                    ////遍历DataSet取数据

                    ////清除无效行
                    //ds.Tables[0].Rows.RemoveAt(0);
                    //ds.Tables[0].Rows.RemoveAt(0);
                    //ds.Tables[0].Rows.RemoveAt(0);
                    //PageState.Add("error", "Tables:" + ds.Tables.Count + " Table[0]:" + ds.Tables[0].Select("F4 <> ''").Length + "数量" + ds.Tables[0].Rows[0][3]);

                    //return;
                    #endregion

                    #region old
                    try
                    {
                        string           sql  = "select * from [Sheet1$]";
                        OleDbDataAdapter oldr = new OleDbDataAdapter(sql, strcn);    //读取数据,并填充到DATASET里
                        DataTable        dt   = new DataTable();
                        oldr.Fill(dt);

                        if (dt.Rows.Count > 0)
                        {
                            string strjson = RequestData.Get <string>("json").Replace("[]", "");
                            if (strjson.Length > 0)
                            {
                                strjson = strjson.Substring(1, strjson.Length - 2) + ",";
                            }
                            DataRow row = null;
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                row = dt.Rows[i];

                                strjson += "{";
                                strjson += "Id:'" + row["Id"] + "',";
                                strjson += "Isbn:'" + row["Isbn"] + "',";
                                strjson += "Code:'" + row["Code"] + "',";
                                strjson += "Name:'" + row["Name"] + "',";
                                strjson += "Unit:'" + row["Unit"] + "',";
                                strjson += "MinSalePrice:'" + row["MinSalePrice"] + "',";
                                strjson += "Price:'" + row["MinSalePrice"] + "',";
                                strjson += "Amount:'" + row["Amount"] + "',";
                                strjson += "Count:'" + row["Count"] + "',";
                                strjson += "Remark:'" + row["Remark"] + "'";
                                strjson += "},";
                            }
                            if (strjson != "")
                            {
                                strjson = "[" + strjson.Substring(0, strjson.Length - 1) + "]";
                                PageState.Add("result", strjson);
                            }
                        }
                        return;
                    }
                    catch (Exception ex)
                    {
                        PageState.Add("error", ex.Message);
                        return;
                    }
                    #endregion
                }
                else if (RequestActionString == "updateAmount")
                {
                    SaleOrder o          = SaleOrder.TryFind(id);
                    string    TotalMoney = RequestData.Get <string>("TotalMoney");
                    o.DiscountAmount = RequestData.Get <decimal>("DiscountAmount");
                    o.TotalMoney     = Convert.ToDecimal(TotalMoney);
                    o.DoUpdate();
                }
                break;
            }

            if (RequestActionString == "getSalesman")
            {
                string   cid      = RequestData.Get <string>("CId");
                Customer customer = Customer.Find(cid);
                if (customer != null)
                {
                    PageState.Add("Code", customer.Code);
                    PageState.Add("SaleUser", customer.MagUser);
                    PageState.Add("SaleUserId", customer.MagId);
                }
            }
            else if (op == "c" && !string.IsNullOrEmpty(paid))
            {
                if (!string.IsNullOrEmpty(paid))
                {
                    PriceApply paent = PriceApply.TryFind(paid);
                    if (paent != null)
                    {
                        paent.Reason        = "";
                        paent.ApprovalState = "";
                        paent.ExpectedTime  = null;
                        paent.Id            = "";
                        paent.Number        = "";
                        paent.Remark        = "";
                        paent.State         = "";
                        this.SetFormData(paent);
                    }
                }
            }
            else if (op != "c" && op != "cs")
            {
                if (!String.IsNullOrEmpty(id))
                {
                    ent = SaleOrder.Find(id);
                }

                this.SetFormData(ent);
                this.PageState.Add("State", ent.State);

                //查询子商品
                string sql = "select Id, PId, PCode as Code, PName as Name, Isbn, Count, Unit, MinSalePrice, SalePrice as Price, Amount,CustomerOrderNo, Remark, OutCount,BillingCount from " + db + "..OrdersPart where OId='" + id + "'";
                PageState.Add("DetailList", DataHelper.QueryDictList(sql));
            }

            this.PageState.Add("FlowEnum", SysEnumeration.GetEnumDictList("WorkFlow.Simple"));

            PageState.Add("InvoiceType", SysEnumeration.GetEnumDict("InvoiceType"));
            PageState.Add("DeliveryMode", SysEnumeration.GetEnumDict("DeliveryMode"));
            PageState.Add("PayType", SysEnumeration.GetEnumDict("PayType"));
            PageState.Add("CalculateManner", SysEnumeration.GetEnumDict("CalculateManner"));
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string db = ConfigurationManager.AppSettings["ExamineDB"];

            op      = RequestData.Get <string>("op");
            id      = RequestData.Get <string>("id");
            paid    = RequestData.Get <string>("paid");
            PAState = RequestData.Get <string>("PAState");
            type    = RequestData.Get <string>("type");

            SaleOrder ent = null;

            switch (this.RequestAction)
            {
            case RequestActionEnum.Update:
                ent = this.GetMergedData <SaleOrder>();
                if (PAState == "Yes")
                {
                    ent.PAState  = "待审核";
                    ent.PANumber = "HGPA" + DateTime.Now.ToString("yyyyMMddHHmmss");
                }

                ent.DoUpdate();

                //处理OrdersPart表
                //删除
                OrdersPart.DeleteAll("OId='" + ent.Id + "'");
                //添加
                strjosn = ent.Child.Substring(1, ent.Child.Length - 2);
                objarr  = strjosn.Replace("},{", "#").Split('#');
                InsertProPart(ent);

                //创建价格申请单
                if (PAState == "Yes")
                {
                    CreatePriceApply(ent);
                }

                this.SetMessage("修改成功!");
                break;

            case RequestActionEnum.Insert:
            case RequestActionEnum.Create:
                ent = this.GetPostedData <SaleOrder>();
                if (PAState == "Yes")
                {
                    ent.PAState  = "待审核";
                    ent.PANumber = DataHelper.QueryValue("select " + db + ".dbo.fun_getPriceAppNumber()") + "";
                }
                ent.PId = paid;

                //自动生成流水号
                ent.Number = DataHelper.QueryValue("select " + db + ".dbo.fun_getOrderNumber()") + "";

                ent.DoCreate();

                //处理OrdersPart表
                //添加
                strjosn = ent.Child.Substring(1, ent.Child.Length - 2);
                objarr  = strjosn.Replace("},{", "#").Split('#');
                InsertProPart(ent);

                //创建价格申请单
                if (PAState == "Yes")
                {
                    CreatePriceApply(ent);
                }

                this.SetMessage("新建成功!");
                break;

            case RequestActionEnum.Delete:
                ent = this.GetTargetData <SaleOrder>();
                ent.DoDelete();
                this.SetMessage("删除成功!");
                return;

            default:
                if (RequestActionString == "submitfinish")
                {
                    SaleOrder pc = SaleOrder.Find(this.RequestData.Get <string>("id"));
                    pc.State         = "End";
                    pc.DeliveryState = "已生成出库单";
                    pc.ApprovalState = this.RequestData.Get <string>("ApprovalState");
                    pc.Save();

                    //自动生成发货单
                    if (pc.ApprovalState == "同意")
                    {
                        DeliveryOrder dor = new DeliveryOrder
                        {
                            Child         = pc.Child,
                            CId           = pc.Id,
                            WarehouseId   = pc.WarehouseId,
                            WarehouseName = pc.WarehouseName,
                            CName         = pc.CName,
                            CreateId      = UserInfo.UserID,
                            CreateName    = UserInfo.Name,
                            CreateTime    = DateTime.Now,
                            ExpectedTime  = pc.ExpectedTime,
                            Number        = DateTime.Now.ToString("yyyyMMddHHmmss")
                        };
                        dor.DoCreate();
                    }
                }
                else if (RequestActionString == "inputexcel")
                {
                    string path  = @"D:\RW\Files\AppFiles\Portal\Default\" + RequestData.Get <string>("path");
                    string strcn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';";    //连接字符串

                    #region 遍历整个excel
                    //DataSet ds = GetDataFromExcel(path);

                    ////遍历DataSet取数据

                    ////清除无效行
                    //ds.Tables[0].Rows.RemoveAt(0);
                    //ds.Tables[0].Rows.RemoveAt(0);
                    //ds.Tables[0].Rows.RemoveAt(0);
                    //PageState.Add("error", "Tables:" + ds.Tables.Count + " Table[0]:" + ds.Tables[0].Select("F4 <> ''").Length + "数量" + ds.Tables[0].Rows[0][3]);

                    //return;
                    #endregion

                    #region old
                    try
                    {
                        string           sql  = "select * from [Sheet1$]";
                        OleDbDataAdapter oldr = new OleDbDataAdapter(sql, strcn);    //读取数据,并填充到DATASET里
                        DataTable        dt   = new DataTable();
                        oldr.Fill(dt);

                        if (dt.Rows.Count > 0)
                        {
                            string strjson = RequestData.Get <string>("json").Replace("[]", "");
                            if (strjson.Length > 0)
                            {
                                strjson = strjson.Substring(1, strjson.Length - 2) + ",";
                            }
                            DataRow row = null;
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                row = dt.Rows[i];

                                strjson += "{";
                                strjson += "Id:'" + row["Id"] + "',";
                                strjson += "Isbn:'" + row["Isbn"] + "',";
                                strjson += "Code:'" + row["Code"] + "',";
                                strjson += "Name:'" + row["Name"] + "',";
                                strjson += "Unit:'" + row["Unit"] + "',";
                                strjson += "MinSalePrice:'" + row["MinSalePrice"] + "',";
                                strjson += "Price:'" + row["MinSalePrice"] + "',";
                                strjson += "Amount:'" + row["Amount"] + "',";
                                strjson += "Count:'" + row["Count"] + "',";
                                strjson += "Remark:'" + row["Remark"] + "'";
                                strjson += "},";
                            }
                            if (strjson != "")
                            {
                                strjson = "[" + strjson.Substring(0, strjson.Length - 1) + "]";
                                PageState.Add("result", strjson);
                            }
                        }
                        return;
                    }
                    catch (Exception ex)
                    {
                        PageState.Add("error", ex.Message);
                        return;
                    }
                    #endregion
                }
                break;
            }

            if (RequestActionString == "getSalesman")
            {
                string   cid      = RequestData.Get <string>("CId");
                Customer customer = Customer.Find(cid);
                if (customer != null)
                {
                    PageState.Add("Code", customer.Code);
                }
            }
            else if (op == "c" && !string.IsNullOrEmpty(paid))
            {
                if (!string.IsNullOrEmpty(paid))
                {
                    PriceApply paent = PriceApply.TryFind(paid);
                    if (paent != null)
                    {
                        paent.Reason        = "";
                        paent.ApprovalState = "";
                        paent.ExpectedTime  = null;
                        paent.Id            = "";
                        paent.Number        = "";
                        paent.Remark        = "";
                        paent.State         = "";
                        this.SetFormData(paent);
                    }
                }
            }
            else if (op != "c" && op != "cs")
            {
                if (!String.IsNullOrEmpty(id))
                {
                    ent = SaleOrder.Find(id);
                }

                this.SetFormData(ent);
                this.PageState.Add("State", ent.State);
            }

            this.PageState.Add("FlowEnum", SysEnumeration.GetEnumDictList("WorkFlow.Simple"));

            PageState.Add("InvoiceType", SysEnumeration.GetEnumDict("InvoiceType"));
            PageState.Add("DeliveryMode", SysEnumeration.GetEnumDict("DeliveryMode"));
            PageState.Add("PayType", SysEnumeration.GetEnumDict("PayType"));
            PageState.Add("CalculateManner", SysEnumeration.GetEnumDict("CalculateManner"));
        }