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(); } } }