Beispiel #1
0
        private void exportDetail()
        {
            User   user        = (User)Session["user"];
            int    regionId    = user.ReginId.RegionId;
            string roleName    = user.RoleId.RoleName;
            string strWhere    = "";
            string groupbyType = Request["groupbyType"];
            string supplier    = Request["supplier"];
            string regionName  = Request["regionName"];

            if (groupbyType == "state" || groupbyType == null)
            {
                groupbyType = "supplier";
            }
            if (supplier != "" && supplier != null)
            {
                strWhere = "supplier='" + supplier + "'";
            }
            if (regionName != "" && regionName != null)
            {
                strWhere = "regionName='" + regionName + "'";
            }

            if (roleName != "超级管理员")
            {
                if (strWhere == "" || strWhere == null)
                {
                    strWhere = "regionId=" + regionId;
                }
                else
                {
                    strWhere += "and regionId=" + regionId;
                }
            }
            string str = "";

            if (strWhere == "" || strWhere == null)
            {
                str = groupbyType + " like'%'";
            }
            else
            {
                str = strWhere;
            }
            string    file  = "书籍库存明细导出" + DateTime.Now.ToString("yyyyMMddHHmmss");
            DataTable dt    = StockBll.bookStockDe(str, groupbyType);
            int       count = dt.Rows.Count;

            if (count > 0)
            {
                ExcelHelp.dtToExcelForXlsxByNpoi(dt, file);
            }
            else
            {
                Response.Write("<script language='javascript'>alert('查询不到数据,不能执行导出操作!')</script>");
            }
        }
Beispiel #2
0
        /// <summary>
        /// 导出
        /// </summary>
        public void excelBook()
        {
            string bookName  = Request["bookName"];
            string bookNum   = Request["bookNum"];
            string bookISBN  = Request["bookISBN"];
            string discount  = Request["discount"];
            string discount2 = Request["discount2"];
            string bookGys   = Request["bookGys"];
            string fileName  = "";
            string strExcel  = "";

            if (bookName != "" && bookName != null)
            {
                if (strExcel == "" || strExcel == null)
                {
                    strExcel = "bookName like '%" + bookName + "%'";
                }
                else
                {
                    strExcel += " and bookName like '%" + bookName + "%'";
                }
            }
            if (bookNum != "" && bookNum != null)
            {
                if (strExcel == "" || strExcel == null)
                {
                    strExcel = "bookNum like '%" + bookNum + "%'";
                }
                else
                {
                    strExcel += " and bookNum like '%" + bookNum + "%'";
                }
            }
            if (bookISBN != "" && bookISBN != null)
            {
                if (strExcel == "" || strExcel == null)
                {
                    strExcel = "isbn like '%" + bookISBN + "%'";
                }
                else
                {
                    strExcel += " and isbn like '%" + bookISBN + "%'";
                }
            }
            if (discount != "" && discount != null)
            {
                string[] sArray = discount.Split('于');
                string   type   = sArray[0];
                string   number = sArray[1];
                try
                {
                    if (strExcel == "" || strExcel == null)
                    {
                        if (type == "小")
                        {
                            strExcel = "remarks < '" + number + "'";
                        }
                        else if (type == "等")
                        {
                            strExcel = "remarks = '" + number + "'";
                        }
                        else
                        {
                            strExcel = "remarks > '" + number + "'";
                        }
                    }
                    else
                    {
                        if (type == "小")
                        {
                            strExcel += " and remarks < '" + number + "'";
                        }
                        else if (type == "等")
                        {
                            strExcel += " and remarks = '" + number + "'";
                        }
                        else
                        {
                            strExcel += " and remarks > '" + number + "'";
                        }
                    }
                }
                catch
                {
                    Response.Write("数据库存在不符合格式的数据");
                    Response.End();
                }
            }
            if (discount2 != "" && discount2 != null)
            {
                string[] sArray = discount2.Split('于');
                string   type   = sArray[0];
                string   number = sArray[1];
                try
                {
                    if (strExcel == "" || strExcel == null)
                    {
                        if (type == "小")
                        {
                            strExcel = "author < '" + number + "'";
                        }
                        else if (type == "等")
                        {
                            strExcel = "author = '" + number + "'";
                        }
                        else
                        {
                            strExcel = "author > '" + number + "'";
                        }
                    }
                    else
                    {
                        if (type == "小")
                        {
                            strExcel += " and author < '" + number + "'";
                        }
                        else if (type == "等")
                        {
                            strExcel += " and author = '" + number + "'";
                        }
                        else
                        {
                            strExcel += " and author > '" + number + "'";
                        }
                    }
                }
                catch
                {
                    Response.Write("数据库存在不符合格式的数据");
                    Response.End();
                }
            }
            if (bookGys != "" && bookGys != null)
            {
                if (strExcel == "" || strExcel == null)
                {
                    strExcel += "supplier like '%" + bookGys + "%'";
                }
                else
                {
                    strExcel += " and supplier like '%" + bookGys + "%'";
                }
            }
            string    Name = fileName + "-书籍基础数据-" + DateTime.Now.ToString("yyyyMMdd") + new Random(DateTime.Now.Second).Next(10000);
            DataTable dt   = bookbll.excelBook(strExcel);

            if (dt != null && dt.Rows.Count > 0)
            {
                ExcelHelp.dtToExcelForXlsxByNpoi(dt, Name);
            }
            else
            {
                Response.Write("<script>alert('没有数据,不能执行导出操作!');</script>");
                Response.End();
            }
        }