Exemple #1
0
        public void addsalemon(HttpContext context)
        {
            string        SaleHeadId  = context.Request["saleheadID"];
            string        saleId      = context.Request["saletaskID"];
            int           number      = Convert.ToInt32(context.Request["number"]);
            string        bookNum     = context.Request["bookNum"];
            SaleTaskBll   saletaskbll = new SaleTaskBll();
            BookBasicData book        = new BookBasicData();
            BookBasicBll  bookbll     = new BookBasicBll();

            if (teamtype == "team")
            {
                int     regionid    = saletaskbll.GetregionidBysaleid(saleId);
                DataSet stockbook   = stobll.SelectByBookNum(bookNum, regionid);
                int     allstockNum = 0;
                for (int h = 0; h < stockbook.Tables[0].Rows.Count; h++)
                {
                    allstockNum += Convert.ToInt32(stockbook.Tables[0].Rows[h]["stockNum"]);
                }
                if (number > allstockNum)
                {
                    context.Response.Write("库存数量不足,当前最大库存为:" + allstockNum);
                    context.Response.End();
                }
                else
                {
                    BookBasicBll Bookbll = new BookBasicBll();
                    book = Bookbll.SelectById(bookNum);
                    string   remarks = book.Remarks;
                    string   defaultdiscount;
                    string   bookISBN   = book.Isbn;
                    string   saleHeadId = SaleHeadId;
                    SaleTask task       = saletaskbll.selectById(saleId);
                    defaultdiscount = task.DefaultDiscount.ToString();
                    if (defaultdiscount == "-1")
                    {
                        if (double.Parse(remarks) < 1)
                        {
                            remarks = (double.Parse(remarks) * 100).ToString();
                        }
                    }
                    double disCount = double.Parse(remarks);
                    int    count    = salemonbll.SelectBySaleHeadId(saleHeadId);
                    int    saleIdmonomerId;
                    if (count == 0)
                    {
                        saleIdmonomerId = 1;
                        salemonbll.updateHeadstate(saleId, SaleHeadId, 1);
                    }
                    else
                    {
                        saleIdmonomerId = count + 1;
                    }
                    double      price      = Convert.ToInt32(book.Price);
                    double      totalPrice = price * number;
                    double      realPrice  = totalPrice * (disCount / 100);
                    DateTime    Time       = DateTime.Now.ToLocalTime();
                    SaleMonomer newSalemon = new SaleMonomer()
                    {
                        AlreadyBought   = 0,
                        SaleIdMonomerId = saleIdmonomerId,
                        BookNum         = bookNum,
                        ISBN1           = bookISBN,
                        SaleHeadId      = saleHeadId,
                        Number          = number,
                        UnitPrice       = price,
                        TotalPrice      = totalPrice,
                        RealPrice       = realPrice,
                        RealDiscount    = disCount,
                        Datetime        = Time,
                        SaleTaskId      = saleId
                    };

                    //for (int j = 0; j < stockbook.Tables[0].Rows.Count; j++)
                    //{
                    //    int stockNum = Convert.ToInt32(stockbook.Tables[0].Rows[j]["stockNum"]);
                    //    string goodsId = stockbook.Tables[0].Rows[j]["goodsShelvesId"].ToString();
                    //    if (number <= stockNum)
                    //    {
                    //        int stockcount = stockNum - number;
                    //        stobll.update(stockcount, goodsId, bookNum);

                    //    }
                    //    else
                    //    {
                    //        number = number - stockNum;
                    //        stobll.update(0, goodsId, bookNum);
                    //        if (number == 0)
                    //        {
                    //            break;
                    //        }
                    //    }
                    //}
                    Result insertres = salemonbll.addsale(regionid, newSalemon);
                    string op        = context.Request["op"];
                    if (insertres == Result.添加成功)
                    {
                        //更新单头
                        updateSalehead(context);

                        if (op == "change")
                        {
                            context.Response.Write("修改成功");
                            context.Response.End();
                        }
                        else
                        {
                            context.Response.Write("添加成功");
                            context.Response.End();
                        }
                    }
                    else
                    {
                        if (op == "change")
                        {
                            context.Response.Write("修改失败");
                            context.Response.End();
                        }
                        else
                        {
                            context.Response.Write("添加失败");
                            context.Response.End();
                        }
                    }
                }
            }
            else
            {
                BookBasicData bookData = bookbll.SelectById(bookNum);
                string        remarks  = bookData.Remarks;
                string        defaultdiscount;
                string        bookISBN = bookData.Isbn;
                SaleTask      task     = saletaskbll.selectById(saleId);
                defaultdiscount = task.DefaultDiscount.ToString();
                if (defaultdiscount == "-1")
                {
                    if (double.Parse(remarks) < 1)
                    {
                        remarks = (double.Parse(remarks) * 100).ToString();
                    }
                }
                //if (remarks == "" || remarks == null)
                //{
                //    remarks = defaultdiscount;
                //}
                else
                {
                    remarks = defaultdiscount;
                }
                double disCount = double.Parse(remarks);
                book = bookbll.SelectById(bookNum);
                string saleHeadId = SaleHeadId;
                int    saleIdmonomerId;
                int    count = salemonbll.SelectByPerSaleHeadId(saleHeadId);
                if (count == 0)
                {
                    saleIdmonomerId = 1;
                    salemonbll.updatePerHeadstate(saleId, SaleHeadId, 1);
                }
                else
                {
                    saleIdmonomerId = count + 1;
                }
                double      price      = Convert.ToDouble(book.Price);
                double      totalPrice = price * number;
                double      realPrice  = totalPrice * (disCount / 100);
                DateTime    Time       = DateTime.Now.ToLocalTime();
                SaleMonomer newSalemon = new SaleMonomer()
                {
                    AlreadyBought   = 0,
                    SaleIdMonomerId = saleIdmonomerId,
                    BookNum         = bookNum,
                    ISBN1           = bookISBN,
                    SaleHeadId      = saleHeadId,
                    Number          = number,
                    UnitPrice       = price,
                    TotalPrice      = totalPrice,
                    RealPrice       = realPrice,
                    RealDiscount    = disCount,
                    Datetime        = Time,
                    SaleTaskId      = saleId
                };
                Result res = salemonbll.perInsert(newSalemon);


                string op = context.Request["op"];
                if (res == Result.添加成功)
                {
                    //更新单头
                    updateSalehead(context);

                    if (op == "change")
                    {
                        context.Response.Write("修改成功");
                        context.Response.End();
                    }
                    else
                    {
                        context.Response.Write("添加成功");
                        context.Response.End();
                    }
                }
                else
                {
                    if (op == "change")
                    {
                        context.Response.Write("修改失败");
                        context.Response.End();
                    }
                    else
                    {
                        context.Response.Write("添加失败");
                        context.Response.End();
                    }
                }
            }
        }
Exemple #2
0
        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();
            }
        }