protected void Page_Load(object sender, EventArgs e) { user = (User)Session["user"]; type = Session["saleType"].ToString(); saleId = Session["saleId"].ToString(); //getData(); getlimt(); SaleTask task = saletaskbll.selectById(saleId); defaultdiscount = task.DefaultDiscount.ToString(); SaleHeadId = Session["saleheadId"].ToString(); //更新单头 updateSalehead(); string op = Request["op"]; //isbn回车 if (op == "search") { string ISBN = Request["ISBN"]; bookds = bookbll.SelectByIsbn(ISBN); if (bookds != null) { //如果有两条及两条以上显示表格 if (bookds.Tables[0].Rows.Count > 1) { getbook(); } //只有一条数据 else { backbook(); } } else { Response.Write("无数据"); Response.End(); } } //一书多号选择后执行 if (op == "add") { showBook(); } //添加销售 if (op == "addsale") { SaleHeadBll saleheadbll = new SaleHeadBll(); string saletaskId = saleheadbll.SelectTaskByheadId(SaleHeadId); string customerId = saletaskbll.getCustomerId(saletaskId); int AlreadyBought = user.ReginId.RegionId; //判断馆藏 LibraryCollectionBll library = new LibraryCollectionBll(); bookISBN = Request["bookISBN"]; Result libresult = library.Selectbook(customerId, bookISBN); if (libresult == Result.记录不存在) { bookISBN = Request["bookISBN"]; disCount = double.Parse(Request["discount"]); number = Convert.ToInt32(Request["number"]); bookNum = Request["bookNum"].ToString(); if (number < 0) { number = Math.Abs(number); DataSet bookNumds = salemonbll.getsalemonDetail(SaleHeadId, saleId, bookNum); if (bookNumds != null) { int booknumber = int.Parse(bookNumds.Tables[0].Rows[0]["number"].ToString()); if (number > booknumber) { msg.Messege = "输入的负数不能大于已购数量,已购数为:" + booknumber; Response.Write(ObjectToJson(msg)); Response.End(); } else { number = number * -1; addsalemon(); } } else { msg.Messege = "该书籍没有购买过,数量不能为负数"; Response.Write(ObjectToJson(msg)); Response.End(); } } else { addsalemon(); } } else { msg.Messege = "客户馆藏已存在"; Response.Write(ObjectToJson(msg)); Response.End(); } } //客户馆藏已存在,继续录入 if (op == "addRsMon") { bookISBN = Request["bookISBN"]; disCount = double.Parse(Request["discount"]); number = Convert.ToInt32(Request["number"]); bookNum = Request["bookNum"].ToString(); if (number < 0) { number = Math.Abs(number); DataSet bookNumds = salemonbll.getsalemonDetail(SaleHeadId, saleId, bookNum); if (bookNumds != null) { int booknumber = int.Parse(bookNumds.Tables[0].Rows[0]["number"].ToString()); if (number > booknumber) { msg.Messege = "输入的负数不能大于已购数量,已购数为:" + booknumber; Response.Write(ObjectToJson(msg)); Response.End(); } else { number = number * -1; addsalemon(); } } else { msg.Messege = "该书籍没有购买过,数量不能为负数"; Response.Write(ObjectToJson(msg)); Response.End(); } } else { addsalemon(); } } //完成单据 if (op == "success") { //判断是否有单体 int row = salemonbll.SelectBySaleHeadId(SaleHeadId); if (row > 0) { //修改单头状态为2 Result result = salemonbll.updateHeadstate(saleId, SaleHeadId, 2); if (result == Result.更新成功) { Response.Write("状态修改成功"); Response.End(); } else { Response.Write("状态修改失败"); Response.End(); } } else { Response.Write("没有数据"); Response.End(); } } //返回按钮 if (op == "back") { updateSalehead(); int row = salemonbll.SelectBySaleHeadId(SaleHeadId); if (row > 0) { string state = salemonbll.getsaleHeadState(SaleHeadId, saleId); if (state == "0") { Result res = salemonbll.updateHeadstate(saleId, SaleHeadId, 1); if (res == Result.更新成功) { Response.Write("更新成功"); Response.End(); } else { Response.Write("更新失败"); Response.End(); } } else { Response.Write("无数据"); Response.End(); } } else { Response.Write("无数据"); Response.End(); } } }
private void getBook(HttpContext context) { string ISBN = context.Request["ISBN"]; string type = context.Request["type"]; DataSet bookds = bookbll.SelectByIsbn(ISBN); if (bookds != null) { string saleId = context.Request["saletaskID"]; string customerId = saletaskbll.getCustomerId(saleId); LibraryCollectionBll library = new LibraryCollectionBll(); Result libresult = library.Selectbook(customerId, ISBN); if (libresult == Result.记录不存在 || type == "continue") { SaleTaskBll saletaskbll = new SaleTaskBll(); DataSet limtds = saletaskbll.SelectBysaleTaskId(saleId); string copy = limtds.Tables[0].Rows[0]["defaultCopy"].ToString(); //如果有两条及两条以上 if (bookds.Tables[0].Rows.Count > 1) { DataTable dt = new DataTable(); dt.Columns.Add("bookNum", typeof(string)); dt.Columns.Add("rownum", typeof(int)); dt.Columns.Add("bookName", typeof(string)); dt.Columns.Add("unitPrice", typeof(double)); dt.Columns.Add("count", typeof(int)); dt.Columns.Add("color", typeof(string)); for (int i = 0; i < bookds.Tables[0].Rows.Count; i++) { int regionid = saletaskbll.GetregionidBysaleid(saleId); int count = stobll.selectStockNum(bookds.Tables[0].Rows[i]["bookNum"].ToString(), regionid); if (count == 0) { continue; } dt.Rows.Add(bookds.Tables[0].Rows[i]["bookNum"].ToString(), Convert.ToInt32((i + 1)), bookds.Tables[0].Rows[i]["bookName"].ToString(), Convert.ToDouble(bookds.Tables[0].Rows[i]["price"].ToString()), count, ""); } if (dt.Rows.Count == 1) { book book = new book(); //bookNum,ISBN,price,author,bookName,supplier int regionid = saletaskbll.GetregionidBysaleid(saleId); int count = stobll.selectStockNum(dt.Rows[0]["bookNum"].ToString(), regionid); if (count != 0) { book.BookNum = bookds.Tables[0].Rows[0]["bookNum"].ToString(); book.BookName = bookds.Tables[0].Rows[0]["bookName"].ToString(); book.Price = double.Parse(bookds.Tables[0].Rows[0]["price"].ToString()); book.count = count; if (copy == "" || copy == null) { book.number = "0"; } else { book.number = copy; } string json = JsonHelper.JsonSerializerBySingleData(book); context.Response.Write(json); context.Response.End(); } else { context.Response.Write("无库存"); context.Response.End(); } } else if (dt.Rows.Count != 0) { Page page = new Page(); if (copy == "" || copy == null) { page.number = "0"; } else { page.number = copy; } page.data = JsonHelper.ToJson(dt, "book"); page.type = "books"; string json = JsonHelper.JsonSerializerBySingleData(page); context.Response.Write(json); context.Response.End(); } else { context.Response.Write("无库存"); context.Response.End(); } } //只有一条数据 else { book book = new book(); //bookNum,ISBN,price,author,bookName,supplier int regionid = saletaskbll.GetregionidBysaleid(saleId); int count = stobll.selectStockNum(bookds.Tables[0].Rows[0]["bookNum"].ToString(), regionid); if (count != 0) { book.BookNum = bookds.Tables[0].Rows[0]["bookNum"].ToString(); book.BookName = bookds.Tables[0].Rows[0]["bookName"].ToString(); book.Price = double.Parse(bookds.Tables[0].Rows[0]["price"].ToString()); book.count = count; if (copy == "" || copy == null) { book.number = "0"; } else { book.number = copy; } string json = JsonHelper.JsonSerializerBySingleData(book); context.Response.Write(json); context.Response.End(); } else { context.Response.Write("无库存"); context.Response.End(); } } } else { context.Response.Write("馆藏存在"); context.Response.End(); } } else { context.Response.Write("无数据"); context.Response.End(); } }