Beispiel #1
0
        /// <summary>
        /// 根据书号查找isbn,单价,折扣
        /// </summary>
        /// <param name="bookNum">书号</param>
        /// <returns></returns>
        public BookBasicData SelectById(string bookNum)
        {
            MySqlHelp db      = new MySqlHelp();
            string    comText = "select ISBN,price,bookName,supplier,remarks,author from T_BookBasicData where bookNum=@bookNum";

            string[] param  = { "@bookNum" };
            object[] values = { bookNum };
            DataSet  ds     = db.FillDataSet(comText, param, values);

            if (ds != null || ds.Tables[0].Rows.Count > 0)
            {
                string        isbn      = ds.Tables[0].Rows[0]["isbn"].ToString();
                string        price     = ds.Tables[0].Rows[0]["price"].ToString();
                string        remarks   = ds.Tables[0].Rows[0]["remarks"].ToString();
                string        bookName  = ds.Tables[0].Rows[0]["bookName"].ToString();
                string        supplier  = ds.Tables[0].Rows[0]["supplier"].ToString();
                string        author    = ds.Tables[0].Rows[0]["author"].ToString();
                BookBasicData bookBasic = new BookBasicData();
                bookBasic.Isbn      = isbn;
                bookBasic.Price     = Convert.ToDouble(price);
                bookBasic.Remarks   = remarks;
                bookBasic.BookName  = bookName;
                bookBasic.Publisher = supplier;
                bookBasic.Author    = author;
                return(bookBasic);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        private void excelNo()
        {
            DataTable         dataTable = addBookId();
            int               counts    = 0;
            DataRowCollection count     = dataTable.Rows;

            foreach (DataRow row in count)//遍历excel数据集
            {
                try
                {
                    string        isbn      = row[2].ToString().Trim();
                    string        bookName  = ToSBC(row[3].ToString().Trim());
                    double        price     = Convert.ToDouble(row[6]);
                    BookBasicData basicData = new BookBasicData();
                    basicData.BookNum   = row[0].ToString();
                    basicData.Isbn      = isbn;
                    basicData.BookName  = bookName;
                    basicData.Publisher = row[4].ToString();
                    basicData.Time      = row[5].ToString();
                    //basicData.PublishTime = Convert.ToDateTime(row[5]);
                    basicData.Price         = Convert.ToDouble(row[6]);
                    basicData.Catalog       = row[7].ToString();
                    basicData.Author        = row[8].ToString();
                    basicData.Remarks       = row[9].ToString();
                    basicData.Dentification = row[10].ToString();
                    basicData.Remarks1      = row[11].ToString();
                    basicData.Remarks2      = row[12].ToString();
                    basicData.Remarks3      = row[13].ToString();
                    Result result = bookbll.Insert(basicData);
                    if (result == Result.添加失败)
                    {
                        Response.Write("导入失败,可能重复导入");
                        Response.End();
                    }
                    else
                    {
                        Result reg = bookbll.updateBookNum(row[0].ToString());     //更新书号
                        counts++;
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex);
                    Response.End();
                }
            }
            int cf = row - counts;

            if (counts == 0)
            {
                Response.Write("导入失败,共导入数据" + counts + "条数据,共有重复数据" + cf + "条");
                Response.End();
            }
            else
            {
                Response.Write("导入成功,共导入数据" + counts + "条数据,共有重复数据" + cf + "条");
                Response.End();
            }
        }
Beispiel #3
0
        /// <summary>
        /// 添加基础数据
        /// </summary>
        /// <param name="basic">基础数据实体对象</param>
        /// <returns></returns>
        public int Insert(BookBasicData basic)
        {
            string cmdText = "insert into T_BookBasicData(bookNum,ISBN,bookName,supplier,publishTime,price,catalog,author,remarks,dentification,remarksOne,remarksTwo,remarksThree) values(@bookNum,@ISBN,@bookName,@supplier,@publishTime,@price,@catalog,@author,@remarks,@dentification,@remarksOne,@remarksTwo,@remarksThree)";

            String[] param  = { "@bookNum", "@ISBN", "@bookName", "@supplier", "@publishTime", "@price", "@catalog", "@author", "@remarks", "@dentification", "@remarksOne", "@remarksTwo", "@remarksThree" };
            object[] values = { basic.BookNum, basic.Isbn, basic.BookName, basic.Publisher, basic.PublishTime, basic.Price, basic.Catalog, basic.Author, basic.Remarks, basic.Dentification, basic.Remarks1, basic.Remarks2, basic.Remarks3 };
            return(db.ExecuteNoneQuery(cmdText, param, values));
        }
Beispiel #4
0
        /// <summary>
        /// 一号多书时选择其中一本后触发
        /// </summary>
        public void showBook()
        {
            int count = salemonbll.SelectBySaleHeadId(SaleHeadId);

            if (count == 0)
            {
                count = 1;
            }
            else
            {
                count += 1;
            }
            string booknum       = Request["bookNum"];
            int    alreadyBought = salemonbll.getBookNumberSumByBookNum(booknum, saleId);

            BookBasicBll  bookbll = new BookBasicBll();
            BookBasicData book    = bookbll.SelectById(booknum);
            string        remarks = book.Remarks;

            if (defaultdiscount == "-1")
            {
                if (double.Parse(remarks) < 1)
                {
                    remarks = (double.Parse(remarks) * 100).ToString();
                }
            }
            //if (remarks == "" || remarks == null)
            //{
            //    remarks = defaultdiscount;
            //}
            else
            {
                remarks = defaultdiscount;
            }
            string        ISBN     = Request["isbn"];
            string        bookname = Request["bookname"];
            string        price    = Request["price"];
            StringBuilder sb       = new StringBuilder();

            sb.Append("<tbody>");
            sb.Append("<tr class='first'><td>" + count + "</td>");
            sb.Append("<td>" + "<input type='text' class='isbn textareaISBN' value='" + ISBN + "' onkeyup='this.value=this.value.replace(/[^\r\n0-9]/g,'');' /></td>");
            sb.Append("<td>" + booknum + "</td>");
            sb.Append("<td>" + bookname + "</td>");
            sb.Append("<td>" + price + "</td>");
            sb.Append("<td><input class='count textareaCount' type='number' value='" + defaultCopy.ToString() + "'/></td>");
            sb.Append("<td><input class='discount textareaDiscount' value='" + remarks + "' onkeyup='this.value=this.value.replace(/[^\r\n0-9]/g,'');' /></td>");
            sb.Append("<td>" + "" + "</td>");
            sb.Append("<td>" + alreadyBought + "</td></tr>");
            sb.Append("</tbody>");
            Response.Write(sb.ToString());
            Response.End();
        }
Beispiel #5
0
        /// <summary>
        /// 取得最新书号
        /// </summary>
        /// <returns></returns>
        public BookBasicData getBookNum()
        {
            string          sql       = "select bookNum from T_NewBook";
            BookBasicData   bookBasic = new BookBasicData();
            MySqlDataReader reader    = db.ExecuteReader(sql, null, null);

            while (reader.Read())
            {
                bookBasic.NewBookNum = reader.GetString(0);
            }
            reader.Close();
            return(bookBasic);;
        }
Beispiel #6
0
        /// <summary>
        /// 添加基础数据
        /// </summary>
        /// <param name="basic">基础数据实体对象</param>
        /// <returns></returns>
        public Result Insert(BookBasicData basic)
        {
            int row = basicDao.Insert(basic);

            if (row > 0)
            {
                return(Result.添加成功);
            }
            else
            {
                return(Result.添加失败);
            }
        }
Beispiel #7
0
        /// <summary>
        /// 带输入框的tr列表
        /// </summary>
        /// <returns></returns>
        public String WriteBook()
        {
            string bookNum   = "";
            string ISBN      = "";
            double unitPrice = 0;
            string isbn      = Request["ISBN"];

            bookNum = Request["bookNO"];
            string bookName = Request["bookName"];

            if (isbn != "" || isbn != null)
            {
                ISBN = isbn;
            }
            if (bookNum == "" || bookNum == null)
            {
                if (bookds != null)
                {
                    bookNum = bookds.Tables[0].Rows[0]["bookNum"].ToString();//书号
                    BookBasicData book = new BookBasicData();
                    book      = bookBll.SelectById(bookNum);
                    bookName  = book.BookName;
                    unitPrice = book.Price;//定价
                }
            }
            else
            {
                unitPrice = double.Parse(Request["price"]);
            }
            StringBuilder sb = new StringBuilder();

            sb.Append("<tr calss='first'>");
            sb.Append("<td>" + "</td>");
            sb.Append("<td>" + "<input type='text' id='inputISBN' class='textareaISBN' autofocus='autofocus' value='" + ISBN + "' />" + "</td>");
            sb.Append("<td>" + bookNum + "</td>");
            sb.Append("<td>" + bookName + "</td>");
            sb.Append("<td>" + unitPrice + "</td>");
            sb.Append("<td>" + "<input type='text' id='inputCount' class='textareaCount' />" + "</td>");
            sb.Append("<td>" + "</td>");
            sb.Append("<td>" + "</td>");
            sb.Append("<td>" + "</td>");
            sb.Append("</tr>");
            //Response.Write(sb.ToString());
            //Response.End();
            return(sb.ToString());
        }
Beispiel #8
0
        /// <summary>
        /// 根据书号查找isbn,单价,折扣
        /// </summary>
        /// <param name="bookNum">书号</param>
        /// <returns></returns>
        public BookBasicData SelectByBookNum(long bookNum, string retailHeadId)
        {
            MySqlHelp db       = new MySqlHelp();
            string    comTexts = "select count(id) from T_RetailMonomer where bookNum=@bookNum and retailHeadId=@retailHeadId";

            string[] parames = { "@bookNum", "@retailHeadId" };
            object[] value   = { bookNum, retailHeadId };
            int      row     = Convert.ToInt32(db.ExecuteScalar(comTexts, parames, value));

            if (row == 0)
            {
                return(null);
            }
            else
            {
                string   comText = "select ISBN,price,bookName,supplier,remarks from T_BookBasicData where bookNum=@bookNum";
                string[] param   = { "@bookNum" };
                object[] values  = { bookNum };
                DataSet  ds      = db.FillDataSet(comText, param, values);
                if (ds != null || ds.Tables[0].Rows.Count > 0)
                {
                    string        isbn      = ds.Tables[0].Rows[0]["isbn"].ToString();
                    string        price     = ds.Tables[0].Rows[0]["price"].ToString();
                    string        remarks   = ds.Tables[0].Rows[0]["remarks"].ToString();
                    string        bookName  = ds.Tables[0].Rows[0]["bookName"].ToString();
                    string        supplier  = ds.Tables[0].Rows[0]["supplier"].ToString();
                    BookBasicData bookBasic = new BookBasicData();
                    bookBasic.Isbn      = isbn;
                    bookBasic.Price     = Convert.ToDouble(price);
                    bookBasic.Remarks   = remarks;
                    bookBasic.BookName  = bookName;
                    bookBasic.Publisher = supplier;
                    return(bookBasic);
                }
                else
                {
                    return(null);
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// 单个销售单结算
        /// </summary>
        public void Settlement(string saleTaskid, string saleHead, int scaler)
        {
            int           RegionId = user.ReginId.RegionId;
            DataTable     dt = saleheadbll.getSaleAllbyHeadIdAndStaskId(saleTaskid, saleHead);
            int           number = 0;
            string        bookNum, bookName, saleHeadId, saleTaskId, Isbn, Author, Supplier;
            int           saleIdMonomerId, rsMonomerId;
            int           allstockNum = 0;//总库存
            int           bhnum       = 0;
            BookBasicData book        = new BookBasicData();

            saleHeadId = dt.Rows[0]["saleHeadId"].ToString();
            saleTaskId = dt.Rows[0]["saleTaskId"].ToString();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                bookNum = dt.Rows[i]["bookNum"].ToString();
                DataSet stockbook = stockbll.SelectByBookNum(bookNum, RegionId);
                allstockNum = 0;
                for (int h = 0; h < stockbook.Tables[0].Rows.Count; h++)
                {
                    allstockNum += Convert.ToInt32(stockbook.Tables[0].Rows[h]["stockNum"]);
                }
                number = int.Parse(dt.Rows[i]["number"].ToString());
                //库存小于数量时生成补货单
                if (allstockNum < number)
                {
                    book            = bookbll.SelectById(bookNum);
                    Isbn            = book.Isbn;
                    Supplier        = book.Publisher;
                    Author          = book.Author;
                    bookName        = dt.Rows[i]["bookName"].ToString();
                    saleIdMonomerId = int.Parse(dt.Rows[i]["saleIdMonomerId"].ToString());
                    bhnum           = number - allstockNum;

                    string rsHead = replenBll.getRsHeadID(saleTaskId);
                    //判断该销售任务是否已有补货记录,如果没有则新增
                    if (rsHead == "none")
                    {
                        Result res = addrsHead(saleTaskId);
                        if (res == Result.添加成功)
                        {
                            int count = replenBll.countMon(saleTaskId);
                            if (count > 0)
                            {
                                rsMonomerId = count + 1;
                            }
                            else
                            {
                                rsMonomerId = 1;
                            }
                            respMon.BookNum         = bookNum;
                            respMon.Count           = bhnum;
                            respMon.Supplier        = Supplier;
                            respMon.DateTime        = DateTime.Now.ToLocalTime();
                            respMon.Isbn            = Isbn;
                            respMon.SaleIdMonomerId = saleIdMonomerId;
                            respMon.SaleTaskId      = saleTaskId;
                            respMon.Author          = Author;
                            respMon.SaleHeadId      = saleHeadId;
                            respMon.RsMonomerID     = rsMonomerId;
                            Result addmonRes = replenBll.Insert(respMon);
                            if (addmonRes == Result.添加成功)
                            {
                                //更新补货单头
                                int rskinds  = replenBll.getkinds(saleTaskId);
                                int rsnumber = replenBll.getsBookNumberSum(saleTaskId);
                                replenishMentHead upRsHead = new replenishMentHead()
                                {
                                    SaleTaskId = saleTaskId,
                                    KindsNum   = rskinds,
                                    Number     = rsnumber,
                                };
                                replenBll.updateRsHead(upRsHead);
                                for (int t = 0; t < stockbook.Tables[0].Rows.Count; t++)
                                {
                                    string goodsID = stockbook.Tables[0].Rows[t]["goodsShelvesId"].ToString();
                                    stockbll.update(0, goodsID, bookNum);
                                }
                            }
                            else
                            {
                                Response.Write("添加失败");
                                Response.End();
                            }
                        }
                        else
                        {
                            Response.Write("添加单头失败");
                            Response.End();
                        }
                    }
                    else
                    {
                        int count = replenBll.countMon(saleTaskId);
                        if (count > 0)
                        {
                            rsMonomerId = count + 1;
                        }
                        else
                        {
                            rsMonomerId = 1;
                        }
                        respMon.BookNum         = bookNum;
                        respMon.Count           = bhnum;
                        respMon.Supplier        = Supplier;
                        respMon.DateTime        = DateTime.Now.ToLocalTime();
                        respMon.Isbn            = Isbn;
                        respMon.SaleIdMonomerId = saleIdMonomerId;
                        respMon.SaleTaskId      = saleTaskId;
                        respMon.Author          = Author;
                        respMon.SaleHeadId      = saleHeadId;
                        respMon.RsMonomerID     = rsMonomerId;
                        Result addmonRes = replenBll.Insert(respMon);
                        if (addmonRes == Result.添加成功)
                        {
                            //更新补货单头
                            int rskinds  = replenBll.getkinds(saleTaskId);
                            int rsnumber = replenBll.getsBookNumberSum(saleTaskId);
                            replenishMentHead upRsHead = new replenishMentHead()
                            {
                                SaleTaskId = saleTaskId,
                                KindsNum   = rskinds,
                                Number     = rsnumber,
                            };
                            replenBll.updateRsHead(upRsHead);
                            for (int t = 0; t < stockbook.Tables[0].Rows.Count; t++)
                            {
                                string goodsID = stockbook.Tables[0].Rows[t]["goodsShelvesId"].ToString();
                                stockbll.update(0, goodsID, bookNum);
                            }
                        }
                        else
                        {
                            Response.Write("添加补货单失败");
                            Response.End();
                        }
                    }
                }
                //库存足则直接减库存
                else
                {
                    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;
                            stockbll.update(stockcount, goodsId, bookNum);
                            number = 0;
                        }
                        else
                        {
                            number = number - stockNum;
                            stockbll.update(0, goodsId, bookNum);
                        }
                    }
                }
            }
            if (scaler == 0)
            {
                //循环完后更新销售单的状态
                Result upHeadstate = salemonbll.updateHeadstate(saleTaskId, saleHeadId, 2);
                if (upHeadstate == Result.更新成功)
                {
                    Response.Write("添加成功");
                    Response.End();
                }
                else
                {
                    Response.Write("更新销售单头失败");
                    Response.End();
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// 只有一条数据时
        /// </summary>
        public void backbook()
        {
            int count = salemonbll.SelectBySaleHeadId(SaleHeadId);

            if (count == 0)
            {
                count = 1;
            }
            else
            {
                count += 1;
            }

            BookBasicBll bookbll = new BookBasicBll();
            string       booknum = bookds.Tables[0].Rows[0]["bookNum"].ToString();

            //判断库存
            DataSet stockbook = stockbll.SelectByBookNum(booknum, user.ReginId.RegionId);

            if (stockbook == null)
            {
                Response.Write("无库存");
                Response.End();
            }
            BookBasicData book    = bookbll.SelectById(booknum);
            string        remarks = book.Remarks;

            if (defaultdiscount == "-1")
            {
                if (double.Parse(remarks) < 1)
                {
                    remarks = (double.Parse(remarks) * 100).ToString();
                }
            }
            else
            {
                remarks = defaultdiscount;
            }
            //if (remarks == "" || remarks == null)
            //{
            //    remarks = defaultdiscount;
            //}
            //else
            //{
            //    if (double.Parse(remarks) < 1)
            //    {
            //        remarks = (double.Parse(remarks) * 100).ToString();
            //    }
            //}
            StringBuilder sb = new StringBuilder();

            sb.Append("<tbody>");
            int    alreadyBought;
            string addbooknum;

            for (int i = 0; i < bookds.Tables[0].Rows.Count; i++)
            {
                addbooknum    = bookds.Tables[0].Rows[i]["bookNum"].ToString();
                alreadyBought = salemonbll.getBookNumberSumByBookNum(addbooknum, saleId);
                sb.Append("<tr class='first'><td>" + count + "</td>");
                sb.Append("<td>" + "<input type='text' class='isbn textareaISBN' value='" + bookds.Tables[0].Rows[i]["ISBN"].ToString() + "' onkeyup='this.value=this.value.replace(/[^\r\n0-9]/g,'');' /></td>");
                sb.Append("<td>" + bookds.Tables[0].Rows[i]["bookNum"].ToString() + "</td>");
                sb.Append("<td>" + bookds.Tables[0].Rows[i]["bookName"].ToString() + "</td>");
                sb.Append("<td>" + bookds.Tables[0].Rows[i]["price"].ToString() + "</td>");
                sb.Append("<td><input class='count textareaCount' type='number' value='" + defaultCopy.ToString() + "'/></td>");
                sb.Append("<td><input class='discount textareaDiscount' value='" + remarks + "' onkeyup='this.value=this.value.replace(/[^\r\n0-9]/g,'');' /></td>");
                sb.Append("<td>" + "" + "</td>");
                sb.Append("<td>" + alreadyBought + "</td></tr>");
            }
            sb.Append("</tbody>");
            Response.Write(sb.ToString());
            Response.End();
        }
Beispiel #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            permission();
            dsSupplier = bookbll.selectSupplier();
            //获取书号
            BookBasicData bookId = bookbll.getBookNum();

            if (!IsPostBack)
            {
                if (bookId.NewBookNum == "0" || bookId.NewBookNum == null || bookId.NewBookNum.Length < 8)
                {
                    num = "0";
                }
                else
                {
                    num = bookId.NewBookNum;
                }
                ViewState["i"] = num;
            }
            //getData();
            string op = Request["op"];

            if (op == "paging")
            {
                getData();
            }
            if (op == "del")
            {
                string bookNum = Request["bookNum"].ToString();
                Result row     = isDelete();
                if (row == Result.记录不存在)
                {
                    Result result = bookbll.Delete(bookNum);
                    if (result == Result.除成功)
                    {
                        Response.Write("删除成功");
                        Response.End();
                    }
                    else

                    {
                        Response.Write("删除失败");
                        Response.End();
                    }
                }
                else
                {
                    Response.Write("此资料已有关联订单,无法删除!");
                    Response.End();
                }
            }
            if (op == "check")
            {
                test();
            }
            if (op == "export")
            {
                excelBook();
            }
            string action = Request["action"];

            if (action == "import")
            {
                differentDt();
                //DataTable dtInsert = new DataTable();
                //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                //watch.Start();
                //differentDt();
                //except.Columns.Remove("id"); //移除匹配列
                //dtInsert = except; //赋给新table
                //TimeSpan ts = watch.Elapsed;
                //dtInsert.TableName = "T_BookBasicData"; //导入的表名
                //int a = userBll.BulkInsert(dtInsert);
                //watch.Stop();
                //double minute = ts.TotalMinutes; //计时
                //string m = minute.ToString("0.00");
                //if (a > 0)
                //{
                //    int cf = row - a;
                //    BookBasicData bookNum = bookbll.getBookNum();
                //    Result result = bookbll.updateBookNum(last); //更新书号
                //    //Response.Write("导入成功,总数据有" + row + "条,共导入" + a + "条数据" + ",共用时:" + m + "分钟");
                //    Response.Write("导入成功,共导入数据"+a+"条数据,共有重复数据"+cf+"条");
                //    Response.End();
                //}
                //else
                //{
                //    Response.Write("导入失败,可能重复导入");
                //    Response.End();
                //}
            }
            if (op == "logout")
            {
                //删除身份凭证
                FormsAuthentication.SignOut();
                //设置Cookie的值为空
                Response.Cookies[FormsAuthentication.FormsCookieName].Value = null;
                //设置Cookie的过期时间为上个月今天
                Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddMonths(-1);
            }
        }
Beispiel #12
0
        //private void excelNo()
        //{
        //    BookBasicBll bookBasicBll = new BookBasicBll();
        //        except.Columns.Add("书号", typeof(string));
        //        except.Columns.Add("id", typeof(string));
        //        except.Columns.Add("ISBN", typeof(string));
        //        except.Columns.Add("书名", typeof(string));
        //        except.Columns.Add("供应商", typeof(string));
        //        except.Columns.Add("出版日期", typeof(string));
        //        except.Columns.Add("单价", typeof(double));
        //        except.Columns.Add("预收数量", typeof(string));
        //        except.Columns.Add("进货折扣", typeof(string));
        //        except.Columns.Add("销售折扣", typeof(string));
        //        except.Columns.Add("备注", typeof(string));

        //        DataRowCollection count = addBookId().Rows;
        //        int counts = 0;
        //        foreach (DataRow row in count)//遍历excel数据集
        //        {
        //            try
        //            {
        //                string isbn = row[2].ToString().Trim();
        //                string bookName = ToSBC(row[3].ToString().Trim());
        //                double price = Convert.ToDouble(row[6]);
        //                DataRow[] rows = excelToDt().Select(string.Format("ISBN='{0}' and 书名='{1}' and 单价={2}", isbn, bookName, price));
        //                if (rows.Length == 1)//判断如果DataRow.Length为0,即该行excel数据不存在于表A中,就插入到dt3
        //                {
        //                    //except.Rows.Add(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10]);
        //                    BookBasicData basicData = new BookBasicData();
        //                    basicData.BookNum = row[0].ToString();
        //                    basicData.Isbn = isbn;
        //                    basicData.BookName = bookName;
        //                    basicData.Publisher = row[4].ToString();
        //                    basicData.Time = row[5].ToString();
        //                    //basicData.PublishTime = Convert.ToDateTime(row[5]);
        //                    basicData.Price = Convert.ToDouble(row[6]);
        //                    basicData.Catalog = row[7].ToString();
        //                    basicData.Author = row[8].ToString();
        //                    basicData.Remarks = row[9].ToString();
        //                    basicData.Dentification = row[10].ToString();
        //                    Result result = bookBasicBll.Insert(basicData);
        //                    if (result == Result.添加失败)
        //                    {
        //                        Response.Write("导入失败,可能重复导入");
        //                        Response.End();
        //                    }
        //                    else
        //                    {
        //                        counts++;
        //                    }
        //                }
        //            else
        //            {
        //                excelToDt().Rows.RemoveAt();
        //            }
        //            }
        //            catch (Exception ex)
        //            {
        //                Response.Write(ex);
        //                Response.End();
        //            }
        //        }
        //        int cf = row - counts;
        //        Response.Write("导入成功,共导入数据" + counts + "条数据,共有重复数据" + cf + "条");
        //        Response.End();

        //}

        private void differentDt()
        {
            BookBasicBll bookBasicBll = new BookBasicBll();
            int          j            = bookBasicBll.SelectCount();

            //数据库无数据时直接导入excel
            if (j <= 0)
            {
                //except = addBookId();
                //except= GetDistinctSelf(addBookId(), "ISBN", "书名", "单价");
                excelNo();
            }
            else
            {
                //except.Columns.Add("书号", typeof(string));
                //except.Columns.Add("id", typeof(string));
                //except.Columns.Add("ISBN", typeof(string));
                //except.Columns.Add("书名", typeof(string));
                //except.Columns.Add("供应商", typeof(string));
                //except.Columns.Add("出版日期", typeof(string));
                //except.Columns.Add("单价", typeof(double));
                //except.Columns.Add("预收数量", typeof(string));
                //except.Columns.Add("进货折扣", typeof(string));
                //except.Columns.Add("销售折扣", typeof(string));
                //except.Columns.Add("备注", typeof(string));
                BookBasicData     bookId = bookbll.getBookNum();
                DataRowCollection count  = addBookId().Rows;
                int       counts         = 0;
                DataTable dataTable      = bookBasicBll.Select();
                bool      isNull         = false;
                int       rowls          = 0;
                int       kz             = 0;
                foreach (DataRow row in count)//遍历excel数据集
                {
                    try
                    {
                        string isbn     = row[2].ToString().Trim();
                        string bookName = ToSBC(row[3].ToString().Trim());
                        string supplier = row[4].ToString().Trim();
                        string accept   = row[8].ToString().Trim();
                        string sale     = row[9].ToString().Trim();
                        string price    = row[6].ToString().Trim();

                        if (price == "" || isbn == "" || bookName == "")
                        {
                            price  = "0";
                            isNull = true;
                            kz++;
                            continue;
                        }
                        DataRow[] rows = dataTable.Select(string.Format("ISBN='{0}' and bookName='{1}'  and supplier='{2}' and price='{3}' and author='{4}' and remarks='{5}'", isbn, bookName, supplier, price, accept, sale));
                        //DataRow[] rows = dataTable.Select(string.Format("ISBN='{0}' and bookName='{1}' and price={2}", isbn, bookName, Convert.ToDouble(price)));
                        if (rows.Length == 0)//判断如果DataRow.Length为0,即该行excel数据不存在于表A中,就插入到dt3
                        {
                            //except.Rows.Add(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10]);
                            BookBasicData basicData = new BookBasicData();
                            basicData.BookNum   = row[0].ToString();
                            basicData.Isbn      = isbn;
                            basicData.BookName  = bookName;
                            basicData.Publisher = row[4].ToString();
                            basicData.Time      = row[5].ToString();
                            //basicData.PublishTime = Convert.ToDateTime(row[5]);
                            basicData.Price         = Convert.ToDouble(price);
                            basicData.Catalog       = row[7].ToString();
                            basicData.Author        = row[8].ToString();
                            basicData.Remarks       = row[9].ToString();
                            basicData.Dentification = row[10].ToString();
                            basicData.Remarks1      = row[11].ToString();
                            basicData.Remarks2      = row[12].ToString();
                            basicData.Remarks3      = row[13].ToString();
                            Result result = bookBasicBll.Insert(basicData);
                            if (result == Result.添加失败)
                            {
                                Response.Write("远程服务器未响应");
                                Response.End();
                            }
                            else
                            {
                                counts++;
                            }
                        }
                        rowls++;
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex);
                        Response.End();
                    }
                }
                string s   = last;
                Result reg = bookbll.updateBookNum(s); //更新书号
                //bookId.NewBookNum = bookId.NewBookNum.Substring(bookId.NewBookNum.Length - 8);
                //last = last.ToString().Substring(last.ToString().Length - 8);
                //if (Convert.ToInt64(bookId.NewBookNum) < Convert.ToInt64(last))
                //{
                //    Result reg = bookbll.updateBookNum(s); //更新书号
                //}
                Session["path"] = null; //清除路径session
                int cf = row - counts;
                if (counts == 0)
                {
                    if (isNull)
                    {
                        Response.Write("导入成功,共导入数据" + counts + "条数据,共有重复数据" + cf + "条,共有错误数据" + kz.ToString());
                        Response.End();
                    }
                    else
                    {
                        Response.Write("导入失败,共导入数据" + counts + "条数据,共有重复数据" + cf + "条");
                        Response.End();
                    }
                }
                else
                {
                    Response.Write("导入成功,共导入数据" + counts + "条数据,共有重复数据" + cf + "条");
                    Response.End();
                }
            }
        }
Beispiel #13
0
        protected void selectIsbn()
        {
            //货架
            GoodsShelvesBll goodsShelvesBll = new GoodsShelvesBll();
            User            user            = (User)Session["user"];
            int             regionId        = user.ReginId.RegionId;

            dsGoods = goodsShelvesBll.Select(regionId);

            string    action   = Request["action"];
            string    isbn     = Request["isbn"];
            DataTable monTable = new DataTable();
            DataRow   dr       = monTable.NewRow();

            if (action == "isbn")
            {
                long    monId  = Convert.ToInt64(Request["sid"]);
                DataSet dsBook = basicBll.SelectByIsbn(isbn);
                if (dsBook == null || dsBook.Tables[0].Rows.Count <= 0)
                {
                    Response.Write("ISBN不存在");
                    Response.End();
                }
                else
                {
                    int billCount = Convert.ToInt32(Request["billCount"]);

                    string bookName = dsBook.Tables[0].Rows[0]["bookName"].ToString();
                    string bookNum  = dsBook.Tables[0].Rows[0]["bookNum"].ToString();
                    string supplier = dsBook.Tables[0].Rows[0]["supplier"].ToString();
                    double uPrice   = Convert.ToDouble(dsBook.Tables[0].Rows[0]["price"]);
                    if (dsBook.Tables[0].Rows[0]["author"].ToString() == null || dsBook.Tables[0].Rows[0]["author"].ToString() == "")
                    {
                        discount = 100;
                    }
                    else
                    {
                        discount = Convert.ToDouble(dsBook.Tables[0].Rows[0]["author"]);
                        if (discount < 1)
                        {
                            discount = discount * 100;
                        }
                    }
                    double totalPrice = Convert.ToDouble((billCount * uPrice).ToString("0.00"));
                    double realPrice  = Convert.ToDouble((totalPrice * discount * 0.01).ToString("0.00"));

                    monTable.Columns.Add("ISBN", typeof(string));
                    monTable.Columns.Add("uPrice", typeof(double));
                    monTable.Columns.Add("bookName", typeof(string));
                    monTable.Columns.Add("bookNum", typeof(string));
                    monTable.Columns.Add("discount", typeof(double));
                    monTable.Columns.Add("monId", typeof(long));
                    monTable.Columns.Add("number", typeof(string));
                    monTable.Columns.Add("totalPrice", typeof(double));
                    monTable.Columns.Add("realPrice", typeof(double));
                    monTable.Columns.Add("singleHeadId", typeof(string));
                    monTable.Columns.Add("supplier", typeof(string));

                    dr["ISBN"]         = isbn;
                    dr["uPrice"]       = uPrice;
                    dr["bookName"]     = bookName;
                    dr["bookNum"]      = bookNum;
                    dr["discount"]     = discount;
                    dr["monId"]        = monId;
                    dr["number"]       = billCount;
                    dr["totalPrice"]   = totalPrice;
                    dr["realPrice"]    = realPrice;
                    dr["singleHeadId"] = singleHeadId;
                    dr["supplier"]     = supplier;
                    monTable.Rows.Add(dr);
                    int           count = dsBook.Tables[0].Rows.Count;
                    StringBuilder sb    = new StringBuilder();
                    if (count == 1)
                    {
                        for (int i = 0; i < monTable.Rows.Count; i++)
                        {
                            bookNumList = (List <string>)Session["List"];
                            foreach (string bookNums in bookNumList)
                            {
                                if (bookNums == monTable.Rows[i]["bookNum"].ToString())
                                {
                                    Response.Write("已添加过此图书");
                                    Response.End();
                                }
                            }
                            bookNumList.Add(monTable.Rows[i]["bookNum"].ToString());
                            Session["List"] = bookNumList;
                            sb.Append("<tr><td>" + monTable.Rows[i]["monId"] + "</td>");
                            sb.Append("<td><textarea class='isbn textareaISBN' row='1' maxlength='13'>" + monTable.Rows[i]["ISBN"] + "</textarea></td>");
                            sb.Append("<td style='display:none'>" + monTable.Rows[i]["bookNum"] + "</td>");
                            sb.Append("<td>" + monTable.Rows[i]["bookName"] + "</td>");
                            sb.Append("<td>" + monTable.Rows[i]["supplier"] + "</td>");
                            sb.Append("<td><textarea class='count textareaCount' row='1'>" + 0 + "</textarea></td>");
                            sb.Append("<td>" + monTable.Rows[i]["uPrice"] + "</td>");
                            sb.Append("<td><textarea class='discount textareaDiscount' row='1'>" + monTable.Rows[i]["discount"] + "</textarea></td>");
                            sb.Append("<td>" + monTable.Rows[i]["totalPrice"] + "</td>");
                            sb.Append("<td>" + monTable.Rows[i]["realPrice"] + "</td>");
                            sb.Append("<td><button class='btn btn-danger btn-sm'><i class='fa fa-trash'></i></button></td></tr>");
                        }
                        Response.Write(sb.ToString());
                        Response.End();
                    }
                    else
                    {
                        sb.Append("<tbody>");
                        for (int i = 0; i < dsBook.Tables[0].Rows.Count; i++)
                        {
                            sb.Append("<tr><td><div class='pretty inline much'><input type = 'radio' name='radio' value='" + dsBook.Tables[0].Rows[i]["bookNum"].ToString() + "'><label><i class='mdi mdi-check'></i></label></div></td>");
                            sb.Append("<td>" + dsBook.Tables[0].Rows[i]["bookNum"].ToString() + "</td>");
                            sb.Append("<td>" + dsBook.Tables[0].Rows[i]["ISBN"].ToString() + "</td>");
                            sb.Append("<td>" + dsBook.Tables[0].Rows[i]["bookName"].ToString() + "</td>");
                            sb.Append("<td>" + dsBook.Tables[0].Rows[i]["price"].ToString() + "</td>");
                            sb.Append("<td>" + dsBook.Tables[0].Rows[i]["supplier"].ToString() + "</td></tr>");
                        }
                        sb.Append("</tbody>");
                        Response.Write(sb.ToString());
                        Response.End();
                        //Response.Write("一号多书");
                        //Response.End();
                    }
                }
            }
            else if (action == "add")
            {
                long monId = Convert.ToInt64(Request["sid"]);
                monTable.Columns.Add("ISBN", typeof(string));
                monTable.Columns.Add("uPrice", typeof(double));
                monTable.Columns.Add("bookName", typeof(string));
                monTable.Columns.Add("bookNum", typeof(string));
                monTable.Columns.Add("discount", typeof(double));
                monTable.Columns.Add("monId", typeof(long));
                monTable.Columns.Add("number", typeof(string));
                monTable.Columns.Add("totalPrice", typeof(double));
                monTable.Columns.Add("realPrice", typeof(double));
                monTable.Columns.Add("singleHeadId", typeof(string));
                monTable.Columns.Add("supplier", typeof(string));

                string        bookNum       = Request["bookNum"].ToString();
                BookBasicData bookBasicData = basicBll.SelectById(bookNum);
                string        supplier      = bookBasicData.Publisher;
                string        bookName      = bookBasicData.BookName;
                string        publisher     = bookBasicData.Publisher;
                double        price         = bookBasicData.Price;
                string        _isbn         = bookBasicData.Isbn;
                string        discount      = bookBasicData.Author;
                if (discount == "" || discount == null)
                {
                    discount = "100";
                }

                bookNumList = (List <string>)Session["List"];
                foreach (string bookNums in bookNumList)
                {
                    if (bookNums == bookNum)
                    {
                        Response.Write("已添加过此图书");
                        Response.End();
                    }
                }

                dr["ISBN"]         = _isbn;
                dr["uPrice"]       = price;
                dr["bookName"]     = bookName;
                dr["bookNum"]      = bookNum;
                dr["discount"]     = discount;
                dr["monId"]        = monId;
                dr["number"]       = 0;
                dr["totalPrice"]   = 0;
                dr["realPrice"]    = 0;
                dr["singleHeadId"] = singleHeadId;
                dr["supplier"]     = supplier;
                monTable.Rows.Add(dr);
                for (int k = 0; k < monTable.Rows.Count; k++)
                {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < monTable.Rows.Count; i++)
                    {
                        sb.Append("<tr><td>" + monTable.Rows[i]["monId"] + "</td>");
                        sb.Append("<td><textarea class='isbn textareaISBN' row='1' maxlength='13'>" + monTable.Rows[i]["ISBN"] + "</textarea></td>");
                        sb.Append("<td style='display:none'>" + monTable.Rows[i]["bookNum"] + "</td>");
                        sb.Append("<td>" + monTable.Rows[i]["bookName"] + "</td>");
                        sb.Append("<td>" + monTable.Rows[i]["supplier"] + "</td>");
                        sb.Append("<td><textarea class='count textareaCount' row='1'>" + monTable.Rows[i]["number"] + "</textarea></td>");
                        sb.Append("<td>" + monTable.Rows[i]["uPrice"] + "</td>");
                        sb.Append("<td><textarea class='discount textareaDiscount' row='1'>" + monTable.Rows[i]["discount"] + "</textarea></td>");
                        sb.Append("<td>" + monTable.Rows[i]["totalPrice"] + "</td>");
                        sb.Append("<td>" + monTable.Rows[i]["realPrice"] + "</td>");
                        sb.Append("<td><button class='btn btn-danger btn-sm'><i class='fa fa-trash'></i></button></td></tr>");
                        bookNumList.Add(bookNum);
                        Session["List"] = bookNumList;
                    }
                    Response.Write(sb.ToString());
                    Response.End();
                }
            }
            else if (action == "save")
            {
                string        json = Request["json"];
                DataTable     dataTable = jsonToDt(json);
                int           Count = dataTable.Rows.Count;
                Monomers      monomers = new Monomers();
                BookBasicData book = new BookBasicData();
                int           count = 0, counts = 0;
                double        total, allTotal = 0, real, allReal = 0;
                for (int i = 0; i < Count; i++)
                {
                    DataRow drow = dataTable.Rows[i];


                    string bookNum = drow["书号"].ToString();
                    count = Convert.ToInt32(drow["数量"]);
                    int     billCount = Convert.ToInt32(drow["数量"]);
                    string  goodsId   = "0";                                                      //货架ID
                    DataSet dsGoods   = stockBll.SelectByBookNum(bookNum, user.ReginId.RegionId); //出库组织库存量
                    int     rgId      = int.Parse(Session["jsRegionId"].ToString());              //接收组织ID
                    DataSet jsGoods   = stockBll.SelectByBookNum(bookNum, rgId);                  //接收组织库存量
                    for (int j = 0; j < dsGoods.Tables[0].Rows.Count; j++)
                    {
                        billCount = count;
                        int stockNum = Convert.ToInt32(dsGoods.Tables[0].Rows[j]["stockNum"]); //原库存量

                        goodsId = dsGoods.Tables[0].Rows[j]["goodsShelvesId"].ToString();      //获取货架ID
                        if (billCount <= stockNum)
                        {
                            int    a      = stockNum - billCount;
                            Result result = stockBll.update(a, goodsId, bookNum);
                            if (result == Result.更新失败)
                            {
                                Response.Write("添加失败");
                                Response.End();
                            }
                            //if (jsGoods.Tables[0].Rows.Count > 0)//判断库存中是否有数据
                            //{
                            //    int jsstockNum = Convert.ToInt32(jsGoods.Tables[0].Rows[0]["stockNum"]);//接收组织原库存量
                            //    int jsgoodsId = Convert.ToInt32(jsGoods.Tables[0].Rows[0]["goodsShelvesId"]);//接收组织库存Id
                            //    int jsNewStock = jsstockNum + billCount;//获取接收组织新的库存
                            //    result = stockBll.update(jsNewStock, jsgoodsId, bookNum);//更新入库库存
                            //    if (result == Result.更新失败)
                            //    {
                            //        Response.Write("更新失败");
                            //        Response.End();
                            //    }
                            //}
                            //else//没有数据时,直接添加
                            //{
                            //    //int jsgoodsId = Convert.ToInt32(jsGoods.Tables[0].Rows[0]["goodsShelvesId"]);//接收组织库存Id
                            //    int jsstockNum = billCount;//库存量
                            //    Region reg = new Region();
                            //    reg.RegionId = rgId;
                            //    DataSet gds = goodsShelvesBll.Select(rgId);
                            //    int gid = int.Parse(gds.Tables[0].Rows[0]["goodsShelvesId"].ToString());
                            //    GoodsShelves goods = new GoodsShelves();
                            //    goods.GoodsShelvesId = gid;
                            //    BookBasicData jsbook = new BookBasicData();
                            //    jsbook.BookNum = bookNum;
                            //    jsbook.Isbn = drow["ISBN号"].ToString();
                            //    Stock stock = new Stock();//库存实体
                            //    stock.BookNum = jsbook;
                            //    stock.ISBN = jsbook;
                            //    stock.RegionId = reg;
                            //    stock.StockNum = billCount;
                            //    stock.GoodsShelvesId = goods;
                            //    result = stockBll.insert(stock);//写入库存
                            //    if (result == Result.添加失败)
                            //    {
                            //        Response.Write("添加失败");
                            //        Response.End();
                            //    }
                            //}
                            Session["List"] = null;
                            break;
                        }
                        else
                        {
                            if (stockNum != 0)
                            {
                                Result result;
                                count = billCount - stockNum;
                                if (count > 0)
                                {
                                    result = stockBll.update(0, goodsId, bookNum);//记录存在且库存不为0
                                    if (result == Result.更新失败)
                                    {
                                        Response.Write("添加失败");
                                        Response.End();
                                    }
                                    count = billCount - stockNum;
                                    continue;
                                }
                                if (count == 0)
                                {
                                    Session["List"] = null;
                                    break;
                                }
                            }
                            //Response.Write("库存不足");
                            //Response.End();
                        }
                    }
                    //添加出库单体
                    book.Isbn           = drow["ISBN号"].ToString();
                    book.Price          = Convert.ToDouble(drow["单价"]);
                    book.BookNum        = drow["书号"].ToString();
                    monomers.Isbn       = book;
                    monomers.UPrice     = book;
                    monomers.BookNum    = book;
                    monomers.Discount   = Convert.ToDouble(drow["折扣"]);
                    monomers.MonomersId = Convert.ToInt32(drow["单据编号"]);
                    monomers.Number     = Convert.ToInt32(drow["数量"]);
                    monomers.TotalPrice = Convert.ToDouble(drow["码洋"]);
                    monomers.RealPrice  = Convert.ToDouble(drow["实洋"]);
                    monomers.ShelvesId  = goodsId;//货架ID
                    SingleHead single = new SingleHead();
                    single.SingleHeadId   = Session["singleHeadId"].ToString();
                    monomers.SingleHeadId = single;
                    count    = Convert.ToInt32(drow["数量"]);
                    counts   = counts + count;
                    total    = Convert.ToDouble(drow["码洋"]);
                    allTotal = allTotal + total;
                    real     = Convert.ToDouble(drow["实洋"]);
                    allReal  = allReal + real;
                    Result row = warehousingBll.insertMono(monomers);
                    if (row == Result.添加失败)
                    {
                        Response.Write("添加失败");
                        Response.End();
                    }



                    //book.Isbn = drow["ISBN号"].ToString();
                    //book.Price = Convert.ToDouble(drow["单价"]);
                    //book.BookNum = drow["书号"].ToString();
                    //monomers.Isbn = book;
                    //monomers.UPrice = book;
                    //monomers.BookNum = book;
                    //monomers.Discount = Convert.ToDouble(drow["折扣"]);
                    //monomers.MonomersId = Convert.ToInt32(drow["单据编号"]);
                    //monomers.Number = Convert.ToInt32(drow["商品数量"]);
                    //monomers.TotalPrice = Convert.ToDouble(drow["码洋"]);
                    //monomers.RealPrice = Convert.ToDouble(drow["实洋"]);
                    //SingleHead single = new SingleHead();
                    //single.SingleHeadId = Session["singleHeadId"].ToString();
                    //monomers.SingleHeadId = single;
                    //count = Convert.ToInt32(drow["商品数量"]);
                    //counts = counts + count;
                    //total = Convert.ToDouble(drow["码洋"]);
                    //allTotal = allTotal + total;
                    //real = Convert.ToDouble(drow["实洋"]);
                    //allReal = allReal + real;
                    //Result row = warehousingBll.insertMono(monomers);
                    //if (row == Result.添加失败)
                    //{
                    //    Response.Write("添加失败");
                    //    Response.End();
                    //}
                    //else if (row == Result.添加成功)
                    //{
                    //    string bookNum = drow["书号"].ToString();
                    //    int billCount = Convert.ToInt32(drow["商品数量"]);
                    //    DataSet dsGoods = stockBll.SelectByBookNum(bookNum, user.ReginId.RegionId);
                    //    for (int j = 0; j < dsGoods.Tables[0].Rows.Count; j++)
                    //    {
                    //        billCount = count;
                    //        int stockNum = Convert.ToInt32(dsGoods.Tables[0].Rows[j]["stockNum"]);
                    //        int goodsId = Convert.ToInt32(dsGoods.Tables[0].Rows[j]["goodsShelvesId"]);
                    //        if (billCount <= stockNum)
                    //        {
                    //            int a = stockNum - billCount;
                    //            Result result = stockBll.update(a, goodsId, bookNum);
                    //            if (result == Result.更新失败)
                    //            {
                    //                Response.Write("添加失败");
                    //                Response.End();
                    //            }
                    //        }
                    //        else
                    //        {
                    //            count = billCount - stockNum;
                    //            Result result = stockBll.update(0, goodsId, bookNum);
                    //            if (count == 0)
                    //            {
                    //                Session["List"] = null;
                    //                Response.Write("添加成功");
                    //                Response.End();
                    //            }
                    //            if (result == Result.更新失败)
                    //            {
                    //                Response.Write("添加失败");
                    //                Response.End();
                    //            }
                    //        }
                    //    }
                    //}
                }
                SingleHead singleHead = new SingleHead();
                singleHead.SingleHeadId  = Session["singleHeadId"].ToString();
                singleHead.AllBillCount  = counts;
                singleHead.AllRealPrice  = allReal;
                singleHead.AllTotalPrice = allTotal;
                Result head = warehousingBll.updateHead(singleHead);
                if (head == Result.更新成功)
                {
                    Response.Write("添加成功");
                    Response.End();
                }
                else
                {
                    Response.Write("添加失败");
                    Response.End();
                }
            }
            else if (action == "changeDiscount")
            {
                double discount = Convert.ToDouble(Request["discount"]);
                Result result   = warehousingBll.updateDiscount(discount);
                if (result == Result.更新成功)
                {
                    Response.Write("更新成功");
                    Response.End();
                }
                else
                {
                    Response.Write("更新失败");
                    Response.End();
                }
            }
            else if (action == "checkNum")
            {
                int     regId     = user.ReginId.RegionId;
                string  bookNum   = Request["bookNum"].ToString();
                int     billCount = Convert.ToInt32(Request["count"]);
                DataSet dsGoods   = stockBll.SelectByBookNum(bookNum, regId);
                int     j         = dsGoods.Tables[0].Rows.Count;
                if (dsGoods != null && dsGoods.Tables[0].Rows.Count > 0)
                {
                    int count = billCount;
                    int allCount = 0, allCounts = 0;
                    for (int i = 0; i < dsGoods.Tables[0].Rows.Count; i++)
                    {
                        allCount  = Convert.ToInt32(dsGoods.Tables[0].Rows[i]["stockNum"]);
                        allCounts = allCounts + allCount;
                    }
                    if (billCount > allCounts)
                    {
                        Response.Write("库存不足");
                        Response.End();
                    }
                }
                else
                {
                    Response.Write("库存不足");
                    Response.End();
                }
            }
        }
Beispiel #14
0
        //某字段table去重方法
        private DataTable GetDistinctSelf(DataTable SourceDt, string field1, string field2, string field3)
        {
            int j      = SourceDt.Rows.Count;
            int counts = 0;

            if (j > 1)
            {
                int k = j - 1;
                int i = 0;
                while (i <= k)
                {
                    DataRow   dr       = SourceDt.Rows[i];
                    string    isbn     = dr[field1].ToString();
                    string    bookName = dr[field2].ToString();
                    double    price    = Convert.ToDouble(dr[field3]);
                    DataRow[] rows     = SourceDt.Select(string.Format("{0}='{3}' and {1}='{4}' and {2}={5}", field1, field2, field3, isbn, ToSBC(bookName), price));
                    //if (rows.Length > 1)
                    //{
                    //    SourceDt.Rows.RemoveAt(i);
                    //    k = k - 1;
                    //}
                    //else
                    //{
                    //    i++;
                    //}
                    if (rows.Length == 1)
                    {
                        BookBasicData basicData = new BookBasicData();
                        basicData.BookNum  = dr[0].ToString();
                        basicData.Isbn     = isbn;
                        basicData.BookName = bookName;

                        basicData.Publisher = dr[4].ToString();
                        basicData.Time      = dr[5].ToString();
                        //basicData.PublishTime = Convert.ToDateTime(rows[5]);
                        basicData.Price         = Convert.ToDouble(dr[6]);
                        basicData.Catalog       = dr[7].ToString();
                        basicData.Author        = dr[8].ToString();
                        basicData.Remarks       = dr[9].ToString();
                        basicData.Dentification = dr[10].ToString();
                        Result result = bookbll.Insert(basicData);
                        if (result == Result.添加失败)
                        {
                            Response.Write("导入失败,可能重复导入");
                            Response.End();
                        }
                        else
                        {
                            counts++;
                        }
                        i++;
                    }
                    else
                    {
                        SourceDt.Rows.RemoveAt(i);
                        k = k - 1;
                    }
                }
                int cf = row - counts;
                Response.Write("导入成功,共导入数据" + counts + "条数据,共有重复数据" + cf + "条");
                Response.End();
            }
            return(SourceDt);
        }
Beispiel #15
0
        public void add(string bookNum, string addType)
        {
            bookNumList = (List <string>)Session["List"];
            foreach (string bookNums in bookNumList)
            {
                if (bookNums == bookNum)
                {
                    if (addType == "other")
                    {
                        Response.Write("已添加过此图书|:");
                        Response.End();
                    }
                    else
                    {
                        Response.Write("已添加过此图书");
                        Response.End();
                    }
                }
            }
            BookBasicData bookBasicData = basicBll.SelectById(bookNum);
            string        isbn          = bookBasicData.Isbn;
            string        bookName      = bookBasicData.BookName;
            double        discount      = 100;

            if (bookBasicData.Remarks == "")
            {
                discount = 100;
            }
            else
            {
                discount = Convert.ToInt32(bookBasicData.Remarks);
                if (discount <= 1)
                {
                    discount = discount * 100;
                }
            }
            int         row      = monTable.Rows.Count;
            double      uPrice   = bookBasicData.Price;
            SaleMonomer monomers = new SaleMonomer();

            monTable.Columns.Add("ISBN", typeof(string));
            monTable.Columns.Add("unitPrice", typeof(double));
            monTable.Columns.Add("bookNum", typeof(long));
            monTable.Columns.Add("bookName", typeof(string));
            monTable.Columns.Add("realDiscount", typeof(double));
            monTable.Columns.Add("number", typeof(int));
            monTable.Columns.Add("totalPrice", typeof(double));
            monTable.Columns.Add("realPrice", typeof(double));
            DataRow monRow = monTable.NewRow();

            monRow["ISBN"]         = isbn;
            monRow["unitPrice"]    = uPrice;
            monRow["bookNum"]      = bookNum;
            monRow["bookName"]     = bookName;
            monRow["realDiscount"] = discount;
            monRow["number"]       = 1;
            monRow["totalPrice"]   = uPrice;
            monRow["realPrice"]    = uPrice * discount * 0.01;
            monTable.Rows.Add(monRow);
            StringBuilder sb     = new StringBuilder();
            int           counts = monTable.Rows.Count;

            for (int i = 0; i < counts; i++)
            {
                bookNumList.Add(bookNum);
                Session["List"] = bookNumList;
                DataRow dr = monTable.Rows[i];
                sb.Append("<tr><td>" + dr["ISBN"].ToString() + "</td>");
                sb.Append("<td>" + dr["bookName"].ToString() + "</td>");
                sb.Append("<td>" + dr["unitPrice"].ToString() + "</td>");
                sb.Append("<td style='display:none'>" + dr["number"].ToString() + "</td>");
                sb.Append("<td><div class='gw_num' style='width:100%'><em class='jian' style='height:100%;width:40%;'>-</em>");
                sb.Append("<input type = 'text' min='1' value='" + dr["number"].ToString() + "' class='num' readonly='readonly' style='width:20%;height:100%'/>");
                sb.Append("<em class='add' style='height:100%;width:40%;'>+</em></div></td>");
                sb.Append("<td>" + dr["realDiscount"].ToString() + "</td>");
                sb.Append("<td>" + dr["totalPrice"].ToString() + "</td>");
                sb.Append("<td style='display:none'>" + dr["realPrice"].ToString() + "</td>");
                sb.Append("<td style='display:none'>" + dr["bookNum"].ToString() + "</td>");
                sb.Append("<td><button class='btn btn-danger btn-sm btn-delete'><i class='fa fa-trash'></i></button></td></tr>");
            }
            if (addType == "other")
            {
                Response.Write(addType + "|:" + sb.ToString());
                Response.End();
            }
            else
            {
                Response.Write(sb.ToString());
                Response.End();
            }
        }
Beispiel #16
0
        /// <summary>
        /// 收银添加图书
        /// </summary>
        /// <param name="bookNum"></param>
        public void add(string bookNum, string headId, string addType)
        {
            Result record = retailBll.selectByBookNum(bookNum, headId);

            if (record == Result.记录不存在)
            {
                BookBasicData bookBasicData = basicBll.SelectById(bookNum);
                string        isbn          = bookBasicData.Isbn;
                string        bookName      = bookBasicData.BookName;
                double        discount      = 100;
                if (bookBasicData.Remarks != "")
                {
                    discount = Convert.ToDouble(bookBasicData.Remarks);
                }
                discount = discount * 0.01;
                int billCount = Convert.ToInt32(Request["billCount"]);
                if (billCount <= 0)
                {
                    billCount = 1;
                }
                int         row        = monTable.Rows.Count;
                double      uPrice     = bookBasicData.Price;
                SaleMonomer monomers   = new SaleMonomer();
                double      totalPrice = Convert.ToDouble((billCount * uPrice).ToString("0.00"));
                double      realPrice  = Convert.ToDouble((totalPrice * discount).ToString("0.00"));
                DataSet     ds         = retailBll.GetRetail(headId);
                int         monId      = 0;
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    int k = ds.Tables[0].Rows.Count - 1;
                    monId = Convert.ToInt32(ds.Tables[0].Rows[k]["retailMonomerId"]);
                }
                monomers.ISBN1           = isbn;
                monomers.UnitPrice       = uPrice;
                monomers.BookNum         = bookNum;
                monomers.SaleIdMonomerId = monId + 1;
                monomers.RealDiscount    = discount * 100;
                monomers.Number          = 1;
                monomers.TotalPrice      = uPrice;
                monomers.RealPrice       = uPrice * discount;
                monomers.SaleHeadId      = headId;
                monomers.Datetime        = Convert.ToDateTime(com.getDate());
                Result mon = retailBll.InsertRetail(monomers);
                if (mon == Result.添加成功)
                {
                    SaleHead sale    = retailBll.GetHead(headId);
                    SaleHead newSale = new SaleHead();
                    newSale.SaleHeadId    = headId;
                    newSale.KindsNum      = sale.KindsNum + 1;
                    newSale.Number        = sale.Number + 1;
                    newSale.AllTotalPrice = sale.AllTotalPrice + monomers.TotalPrice;
                    newSale.AllRealPrice  = sale.AllRealPrice + monomers.RealPrice;
                    Result update = retailBll.UpdateHeadNumber(newSale);
                    if (update == Result.更新成功)
                    {
                        StringBuilder sb    = new StringBuilder();
                        DataSet       dsNew = retailBll.GetRetail(headId);
                        if (dsNew != null && dsNew.Tables[0].Rows.Count > 0)
                        {
                            int counts = dsNew.Tables[0].Rows.Count;
                            for (int i = 0; i < counts; i++)
                            {
                                DataRow dr = dsNew.Tables[0].Rows[i];
                                sb.Append("<tr><td>" + dr["retailMonomerId"].ToString() + "</td>");
                                sb.Append("<td>" + dr["ISBN"].ToString() + "</td>");
                                sb.Append("<td>" + dr["bookName"].ToString() + "</td>");
                                sb.Append("<td>" + dr["unitPrice"].ToString() + "</td>");
                                sb.Append("<td style='display:none'>" + dr["number"].ToString() + "</td>");
                                //sb.Append("<td><input class='numberEnd' type='number' style='width:50px;border:none;' name='points',min='1' value='" + dr["number"].ToString() + "'/></td>");
                                sb.Append("<td><div class='gw_num' style='width:100%'><em class='jian' style='height:100%;width:40%;'>-</em>");
                                sb.Append("<input type = 'text' min='1' value='" + dr["number"].ToString() + "' class='num' readonly='readonly' style='width:20%;height:100%'/>");
                                sb.Append("<em class='add' style='height:100%;width:40%;'>+</em></div></td>");
                                sb.Append("<td>" + dr["realDiscount"].ToString() + "</td>");
                                sb.Append("<td>" + dr["totalPrice"].ToString() + "</td>");
                                sb.Append("<td>" + dr["realPrice"].ToString() + "</td>");
                                sb.Append("<td style='display:none'>" + dr["bookNum"].ToString() + "</td>");
                                sb.Append("<td><button class='btn btn-danger btn-sm delete'><i class='fa fa-trash'></i></button></td></tr>");
                            }
                            if (addType == "other")
                            {
                                Response.Write(addType + "|:" + sb.ToString() + "|:" + newSale.KindsNum + "," + newSale.Number + "," + newSale.AllTotalPrice + "," + newSale.AllRealPrice + "|:" + headId);
                                Response.End();
                            }
                            else
                            {
                                Response.Write(sb.ToString() + "|:" + newSale.KindsNum + "," + newSale.Number + "," + newSale.AllTotalPrice + "," + newSale.AllRealPrice + "|:" + headId);
                                Response.End();
                            }
                        }
                    }
                    else
                    {
                        Response.Write("添加失败|:");
                        Response.End();
                    }
                }
                else
                {
                    Response.Write("添加失败|:");
                    Response.End();
                }
            }
            else
            {
                Response.Write("已添加过此图书|:");
                Response.End();
            }
        }
Beispiel #17
0
        /// <summary>
        /// 添加销售
        /// </summary>
        public void addsalemon()
        {
            string headState = salemonbll.getsaleHeadState(SaleHeadId, saleId);

            if (headState == "2")
            {
                msg.Messege = "该单据已完成,不能再添加数据!";
                Response.Write(ObjectToJson(msg));
                Response.End();
            }
            else
            {
                int     RegionId  = user.ReginId.RegionId;
                DataSet stockbook = stockbll.SelectByBookNum(bookNum, RegionId);
                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)
                {
                    msg.Messege = "库存不足,当前最大库存为:" + allstockNum;
                    Response.Write(ObjectToJson(msg));
                    Response.End();
                }
                else
                {
                    BookBasicBll  Bookbll = new BookBasicBll();
                    BookBasicData book    = new BookBasicData();
                    book = Bookbll.SelectById(bookNum);
                    string saleHeadId = SaleHeadId;
                    int    count      = salemonbll.SelectBySaleHeadId(saleHeadId);
                    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;
                    //        stockbll.update(stockcount, goodsId, bookNum);

                    //    }
                    //    else
                    //    {
                    //        number = number - stockNum;
                    //        stockbll.update(0, goodsId, bookNum);
                    //        if (number == 0)
                    //        {
                    //            break;
                    //        }
                    //    }
                    //}

                    Result res = salemonbll.addsale(RegionId, newSalemon);
                    if (res == Result.添加成功)
                    {
                        updateSalehead();
                        msg.DataTable     = getData();
                        msg.DataTable1    = "<tr class='first'> <td></td><td><input type='text' id='ISBN' class='isbn textareaISBN' /> </td><td></td><td></td><td></td><td><input class='count textareaCount' type='number'/></td><td><input class='discount textareaDiscount' onkeyup='this.value=this.value.replace(/[^\r\n0-9]/g,'');' /></td><td></td><td></td></tr>";
                        msg.AllKinds      = allkinds.ToString();
                        msg.Number        = allnumber.ToString();
                        msg.AlltotalPrice = alltotalprice.ToString();
                        msg.AllrealPrice  = allreadprice.ToString();
                        msg.Messege       = "添加成功";
                        Response.Write(ObjectToJson(msg));
                        Response.End();
                    }
                    else
                    {
                        msg.Messege = "添加失败";
                        Response.Write(ObjectToJson(msg));
                        Response.End();
                    }
                }
            }
        }
Beispiel #18
0
        /// <summary>
        /// 添加销退单体
        /// </summary>
        public void addSalemon()
        {
            string sellId = Session["sellId"].ToString();
            string isbn   = Request["ISBN"];//ISBN

            if (isbn == "" || isbn == null)
            {
                Response.Write("请先输入ISBN号");
                Response.End();
            }
            else
            {
                string bookNo = Request["bookNum"];
                if (bookNo == null || bookNo == "")
                {
                    bookNo = bookds.Tables[0].Rows[0]["bookNum"].ToString();//书号
                }
                int bookCount = smBll.getBookCount(bookNo);
                if (bookCount > 0)
                {
                    BookBasicData book = new BookBasicData();
                    book = bookBll.SelectById(bookNo);
                    double unitPrice = book.Price; //定价
                                                   //double discount = double.Parse(Request["discount"]);//实际折扣

                    //获取默认折扣
                    DataSet stds = smBll.getSaleTask(sellId);
                    string  stId = Session["saleId"].ToString();
                    DataSet seds = smBll.getDisCount(stId, bookNo);
                    string  dc   = null;
                    if (seds.Tables[0].Rows.Count > 0)
                    {
                        dc = seds.Tables[0].Rows[0]["realDiscount"].ToString();
                    }
                    double discount = 0;//默认折扣
                    if (dc != null)
                    {
                        discount = double.Parse(dc);
                    }

                    int    count      = int.Parse(Request["count"]);  //数量
                    double totalPrice = unitPrice * count;            //码洋
                    double d          = totalPrice * (discount / 100);
                    double realPrice  = Math.Round(d, 2);             //实洋
                    string headId     = Session["sellId"].ToString(); //单头Id
                    int    moNum      = smBll.GetCount(headId);
                    int    smId;
                    smId = moNum + 1;//单体Id
                    DateTime time = DateTime.Now;

                    //获取默认折扣
                    //DataSet stds = smBll.getSaleTask(sellId);
                    //string stId = stds.Tables[0].Rows[0]["saleTaskId"].ToString();//销售任务Id
                    DataSet        countds = smBll.selctByBookNum(bookNo, stId);
                    int            num     = 0;
                    SellOffMonomer sm      = new SellOffMonomer();
                    sm.SellOffMonomerId = smId.ToString();
                    sm.SellOffHeadId    = headId;
                    sm.BookNum          = long.Parse(bookNo);
                    sm.ISBN1            = isbn;
                    sm.Count            = count;
                    sm.TotalPrice       = totalPrice;
                    sm.RealPrice        = realPrice;
                    sm.Price            = unitPrice;
                    sm.Time             = time;
                    sm.Discount         = discount;
                    //DataSet smcountds = smBll.selecctSm(bookNo, sellId);
                    int allcount = smBll.selecctSm(bookNo, sellId);
                    //string state = null;
                    if (countds != null)//获取销售中的相应的数量
                    {
                        for (int i = 0; i < countds.Tables[0].Rows.Count; i++)
                        {
                            num = num + int.Parse(countds.Tables[0].Rows[i]["number"].ToString());
                        }
                    }
                    //if (smcountds != null)//获取销退单体中已有的数量
                    //{
                    //    for (int i = 0; i < smcountds.Tables[0].Rows.Count; i++)
                    //    {
                    //        allcount = allcount + int.Parse(smcountds.Tables[0].Rows[i]["count"].ToString());
                    //    }
                    //}
                    if ((count + allcount) > num)//判断销退数量是否大于销售数量
                    {
                        Response.Write("销退数量大于销售数量");
                        Response.End();
                    }
                    else
                    {
                        Result row = smBll.Insert(sm);
                        if (row == Result.添加成功)//先添加销退体
                        {
                            string update = updateSellHead();
                            if (update == "更新成功")//后更新销退单头信息
                            {
                                string stock = insertStock();
                                if (stock == "更新成功")//最后写入库存
                                {
                                    Response.Write("添加成功");
                                    Response.End();
                                }
                                else
                                {
                                    Response.Write(stock);
                                    Response.End();
                                }
                            }
                            else
                            {
                                Response.Write("更新单头信息失败");
                                Response.End();
                            }
                        }
                        else
                        {
                            Response.Write("添加失败");
                            Response.End();
                        }
                    }
                }
                else
                {
                    Response.Write("销售单中暂无此数据");
                    Response.End();
                }
            }
        }
Beispiel #19
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();
                    }
                }
            }
        }