示例#1
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();
                }
            }
        }