Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            user = (User)Session["user"];
            permission();
            //获取组织
            dsRegion = regionBll.select();
            //获取操作员
            dsUser = saleheadbll.selectCzy();
            string op = Request["op"];

            saleTaskid = Session["saleId"].ToString();
            SaleTaskBll saleBll = new SaleTaskBll();

            finishTime = saleBll.getSaleTaskFinishTime(saleTaskid);
            //getData();
            if (op == "paging")
            {
                getData();
            }
            string saleheadId = Request["ID"];

            type = Session["type"].ToString();
            //添加销售单体
            if (op == "addDetail")
            {
                if (finishTime != null && finishTime != "")
                {
                    Response.Write("该销售计划已完成");
                    Response.End();
                }
                else
                {
                    SaleMonomerBll salemonbll = new SaleMonomerBll();
                    int            state      = salemonbll.saleheadstate(saleTaskid, saleheadId);
                    if (state == 2)
                    {
                        Response.Write("失败");
                        Response.End();
                    }
                    else
                    {
                        Session["saleheadId"] = saleheadId;
                        Session["saleType"]   = "addsale";
                        Response.Write("成功");
                        Response.End();
                    }
                }
            }
            //if (op == "saleback")
            //{
            //    saleback();
            //}
            if (op == "Settlement")
            {
                string salehead = Request["ID"];
                string taskId   = Request["taskId"];
                Settlement(taskId, salehead, 0);
            }
            if (op == "SettlementAll")
            {
                SettlementAll();
            }
            if (op == "logout")
            {
                //删除身份凭证
                FormsAuthentication.SignOut();
                //设置Cookie的值为空
                Response.Cookies[FormsAuthentication.FormsCookieName].Value = null;
                //设置Cookie的过期时间为上个月今天
                Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddMonths(-1);
            }
            //查看
            if (op == "look")
            {
                string type = Request["type"];
                Session["type"]       = type;
                Session["saleheadId"] = saleheadId;
                Session["saleType"]   = "look";
                Response.Write("成功");
                Response.End();
            }
            //完成此销售任务
            if (op == "finish")
            {
                //判断该销售任务下是否还有未完成单据0新建单据 1未完成,2完成,3未结算
                SaleTaskBll salebll         = new SaleTaskBll();
                DataSet     saleHeadStateds = salebll.SelectHeadStateBySaleId(saleTaskid);
                int         count           = saleHeadStateds.Tables[0].Rows.Count;
                int         state           = 4;
                for (int i = 0; i < count; i++)
                {
                    state = Convert.ToInt32(saleHeadStateds.Tables[0].Rows[i]["state"]);
                    if (state == 0 || state == 1)
                    {
                        break;
                    }
                }
                if (state == 0)
                {
                    Response.Write("失败,有新建的单据");
                    Response.End();
                }
                if (state == 1)
                {
                    Response.Write("失败,有采集中的单据");
                    Response.End();
                }
                else
                {
                    DateTime finishTime = DateTime.Now.ToLocalTime();
                    int      row        = salebll.updatefinishTime(finishTime, saleTaskid);
                    if (row > 0)
                    {
                        Response.Write("成功");
                        Response.End();
                    }
                    else
                    {
                        Response.Write("失败");
                        Response.End();
                    }
                }
                //if (state < 2)
                //{
                //    Response.Write("未完成失败");
                //    Response.End();
                //}
                //else if (state == 2)
                //{
                //    DateTime finishTime = DateTime.Now.ToLocalTime();
                //    int row = salebll.updatefinishTime(finishTime, saleTaskid);
                //    if (row > 0)
                //    {
                //        Response.Write("成功");
                //        Response.End();
                //    }
                //    else
                //    {
                //        Response.Write("失败");
                //        Response.End();
                //    }
                //}
            }
            //添加
            if (op == "add")
            {
                //获取销售任务的状态
                SaleHeadBll saleheadbll = new SaleHeadBll();
                SaleHead    salehead    = new SaleHead();
                string      remarks     = Request["remarks"];
                if (remarks == "" || remarks == null)
                {
                    remarks = "";
                }
                string saleId = Session["saleId"].ToString();
                string SaleHeadId;
                int    count = saleheadbll.getCount();
                if (count > 0)
                {
                    string time       = saleheadbll.getSaleHeadTime();
                    string nowTime    = DateTime.Now.ToLocalTime().ToString();
                    string equalsTime = DateTime.Now.ToLocalTime().ToString("yyyyMMdd");
                    if (time.Equals(equalsTime))
                    {
                        nowTime = DateTime.Now.ToString("yyyy-MM-dd");
                        string getheadId = saleheadbll.getSaleHeadIdByTime(nowTime);
                        if (getheadId == "" || getheadId == null)
                        {
                            count      = 1;
                            SaleHeadId = "XS" + DateTime.Now.ToString("yyyyMMdd") + count.ToString().PadLeft(6, '0');
                        }
                        else
                        {
                            string js = getheadId.Remove(0, getheadId.Length - 6);
                            count      = Convert.ToInt32(js) + 1;
                            SaleHeadId = "XS" + DateTime.Now.ToString("yyyyMMdd") + count.ToString().PadLeft(6, '0');
                        }
                    }
                    else
                    {
                        count      = 1;
                        SaleHeadId = "XS" + DateTime.Now.ToString("yyyyMMdd") + count.ToString().PadLeft(6, '0');
                    }
                }
                else
                {
                    count      = 1;
                    SaleHeadId = "XS" + DateTime.Now.ToString("yyyyMMdd") + count.ToString().PadLeft(6, '0');
                }
                salehead.SaleHeadId    = SaleHeadId;
                salehead.SaleTaskId    = saleId;
                salehead.KindsNum      = 0;
                salehead.Number        = 0;
                salehead.AllTotalPrice = 0;
                salehead.AllRealPrice  = 0;
                User user = (User)Session["user"];
                salehead.UserId   = user.UserId;
                salehead.RegionId = user.ReginId.RegionId;
                salehead.DateTime = DateTime.Now.ToLocalTime();
                salehead.State    = 0;
                salehead.Remarks  = remarks;
                Result result = saleheadbll.Insert(salehead);
                if (result == Result.添加成功)
                {
                    Response.Write("添加成功");
                    Response.End();
                }
                else
                {
                    Response.Write("添加失败");
                    Response.End();
                }
            }
            //删除
            if (op == "del")
            {
                string         salehead   = Request["ID"];
                string         headstate  = Request["state"];
                SaleMonomerBll salemonbll = new SaleMonomerBll();
                int            state;
                if (headstate == "预采")
                {
                    state = salemonbll.perSaleheadstate(saleTaskid, salehead);
                }
                else
                {
                    state = salemonbll.saleheadstate(saleTaskid, salehead);
                }

                if (state == 0)
                {
                    Result result = salemonbll.realDelete(saleTaskid, salehead);
                    if (result == Result.除成功)
                    {
                        Response.Write("删除成功");
                        Response.End();
                    }
                    else
                    {
                        Response.Write("删除失败");
                        Response.End();
                    }
                }
                else if (state == 1)
                {
                    Response.Write("单据采集中");
                    Response.End();
                }
                else if (state == 2)
                {
                    Response.Write("单据完成");
                    Response.End();
                }
                else if (state == 3)
                {
                    int count = salemonbll.WeChatSelectcountbyHeadID(salehead, saleTaskid);
                    if (count > 0)
                    {
                        Response.Write("该预采单已有数据,不能删除");
                        Response.End();
                    }
                    else
                    {
                        Result result = salemonbll.DeleteHead(saleTaskid, salehead, "copy");
                        if (result == Result.除成功)
                        {
                            Response.Write("删除成功");
                            Response.End();
                        }
                        else
                        {
                            Response.Write("删除失败");
                            Response.End();
                        }
                    }
                    //Result result = salemonbll.realDeleteHeadAndMon(saleTaskid, salehead);
                    //if (result == Result.删除成功)
                    //{
                    //    Response.Write("删除成功");
                    //    Response.End();
                    //}
                    //else
                    //{
                    //    Response.Write("删除失败");
                    //    Response.End();
                    //}
                }
                else
                {
                    Response.Write("删除失败");
                    Response.End();
                }
            }
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            permission();
            //getData();
            string op = Request["op"];

            if (op == "paging")
            {
                getData();
            }
            //退出系统
            if (op == "logout")
            {
                //删除身份凭证
                FormsAuthentication.SignOut();
                //设置Cookie的值为空
                Response.Cookies[FormsAuthentication.FormsCookieName].Value = null;
                //设置Cookie的过期时间为上个月今天
                Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddMonths(-1);
            }
            //添加销售任务
            if (op == "add")
            {
                User   user      = (User)Session["user"];
                int    custmerID = Convert.ToInt32(Request["Custmer"]);
                int    regionId  = user.ReginId.RegionId;
                string state     = saleBll.getcustomermsg(custmerID, regionId);
                if (state == "1")
                {
                    Response.Write("该客户还有未完成的销售任务,不能添加");
                    Response.End();
                }
                else
                {
                    int count = saleBll.getCount();
                    if (count > 0)
                    {
                        string time       = saleBll.getSaleTaskTime();
                        string nowTime    = DateTime.Now.ToLocalTime().ToString();
                        string equalsTime = DateTime.Now.ToLocalTime().ToString("yyyyMMdd");
                        if (time.Equals(equalsTime))
                        {
                            nowTime = DateTime.Now.ToString("yyyy-MM-dd");
                            string getsaleId = saleBll.getSaleTaskIdByTimedesc(nowTime);
                            if (getsaleId == "" || getsaleId == null)
                            {
                                count      = 1;
                                saleTaskId = "XSRW" + DateTime.Now.ToString("yyyyMMdd") + count.ToString().PadLeft(6, '0');
                            }
                            else
                            {
                                string js = getsaleId.Remove(0, getsaleId.Length - 5);
                                count      = Convert.ToInt32(js) + 1;
                                saleTaskId = "XSRW" + DateTime.Now.ToString("yyyyMMdd") + count.ToString().PadLeft(6, '0');
                            }
                        }
                        else
                        {
                            count      = 1;
                            saleTaskId = "XSRW" + DateTime.Now.ToString("yyyyMMdd") + count.ToString().PadLeft(6, '0');
                        }
                    }
                    else
                    {
                        count      = 1;
                        saleTaskId = "XSRW" + DateTime.Now.ToString("yyyyMMdd") + count.ToString().PadLeft(6, '0');
                    }
                    Customer customer = new Customer();
                    customer.CustomerId = custmerID;
                    int numberLimit = Convert.ToInt32(Request["numberLimit"]);

                    string strPriceLimit = Request["priceLimit"].ToString() + ".00";
                    double priceLimit    = Convert.ToDouble(strPriceLimit);

                    string   strTotalPriceLimit = Request["totalPriceLimit"].ToString() + ".00";
                    double   totalPriceLimit    = Convert.ToDouble(strTotalPriceLimit);
                    double   defaultDiscount    = double.Parse(Request["defaultDiscount"]);
                    string   defaultCopy        = Request["defaultCopy"].ToString();
                    string   userId             = user.UserId;
                    DateTime StartTime          = DateTime.Now.ToLocalTime();
                    SaleTask saleTask           = new SaleTask()
                    {
                        SaleTaskId      = saleTaskId,
                        UserId          = userId,
                        Customer        = customer,
                        DefaultDiscount = defaultDiscount,
                        DefaultCopy     = defaultCopy,
                        NumberLimit     = numberLimit,
                        PriceLimit      = priceLimit,
                        TotalPiceLimit  = totalPriceLimit,
                        StartTime       = StartTime,
                    };
                    Result result = saleBll.insert(saleTask);
                    if (result == Result.添加成功)
                    {
                        Response.Write("添加成功");
                        Response.End();
                    }
                    else
                    {
                        Response.Write("添加失败");
                        Response.End();
                    }
                }
            }
            //删除
            if (op == "del")
            {
                string saleID   = Request["ID"];
                Result isDelete = saleBll.IsDelete("T_SellOffHead", "saleTaskId", saleID);
                if (isDelete == Result.记录不存在)
                {
                    isDelete = saleBll.IsDelete("T_ReplenishmentHead", "saleTaskId", saleID);
                    if (isDelete == Result.记录不存在)
                    {
                        isDelete = saleBll.IsDelete("T_SaleHead", "saleTaskId", saleID);
                    }
                }
                if (isDelete == Result.关联引用)
                {
                    Response.Write("该客户已被关联到其他表,不能删除!");
                }
                else
                {
                    Result result = saleBll.Delete(saleID);
                    if (result == Result.除成功)
                    {
                        Response.Write("删除成功");
                        Response.End();
                    }
                    else
                    {
                        Response.Write("删除失败");
                        Response.End();
                    }
                }
            }
            //查看
            if (op == "look")
            {
                string saleId = Request["ID"];
                Session["saleId"] = saleId;
                Session["type"]   = "look";
                Response.Write("成功");
                Response.End();
            }
            //销售
            if (op == "sale")
            {
                string saleId = Request["ID"];
                Session["saleId"] = saleId;
                Session["type"]   = "add";
                string finishState = saleBll.getSaleTaskFinishTime(saleId);
                if (finishState == null || finishState == "")
                {
                    Response.Write("可以");
                    Response.End();
                }
                else
                {
                    Response.Write("不可以");
                    Response.End();
                }
            }
            //添加销退
            if (op == "saleback")
            {
                string saleTaskId = Request["ID"];
                Session["saleId"] = saleTaskId;
                string finishState = saleBll.getSaleTaskFinishTime(saleTaskId);
                if (finishState == null || finishState == "")
                {
                    Response.Write("不可以");
                    Response.End();
                }
                else
                {
                    Response.Write("可以");
                    Response.End();
                }
            }
            if (op == "isEdit")
            {
                string saleID = Request["saleId"];
                string state  = saleBll.getSaleTaskFinishTime(saleID);
                if (state == "" || state == null)
                {
                    Response.Write("可以编辑");
                    Response.End();
                }
                else
                {
                    Response.Write("不可以编辑");
                    Response.End();
                }
            }
            //编辑
            if (op == "edit")
            {
                string saleId          = Request["saleId"];
                double allprice        = double.Parse(Request["allpricemlimited"]);
                int    number          = int.Parse(Request["numberlimited"]);
                double price           = double.Parse(Request["pricelimited"]);
                double defaultDiscount = double.Parse(Request["defaultDiscounted"]);
                string defaultCopyed   = Request["defaultCopyed"].ToString();
                int    row             = saleBll.update(number, price, allprice, defaultDiscount, defaultCopyed, saleId);
                if (row > 0)
                {
                    Response.Write("保存成功");
                    Response.End();
                }
                else
                {
                    Response.Write("保存失败");
                    Response.End();
                }
            }
        }