//导出excel
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            StringBuilder OutFileContent = new StringBuilder();//容器

            //写头文件
            OutFileContent = Exportexcel.AddHeadFile(OutFileContent);
            //写内容
            StringBuilder sbMsg = new StringBuilder();//容器


            //查询需要导出的数据
            string _strWhere = "status!=1 and status!=99";

            _strWhere += CombSqlTxt(this.outlet_id, this.city_id, this.keywords);

            this.datetime = Vincent._DTcms.DTRequest.GetQueryString("datetime");
            //if (datetime != null)
            //{
            //    _strWhere += " and datediff(dd,add_time,'" + datetime + "')=0";
            //}

            BLL.orders bll = new BLL.orders();
            BuysingooShop.Model.manager manModel = Session[Vincent._DTcms.DTKeys.SESSION_ADMIN_INFO] as Model.manager;
            if (manModel.brand_id != 0)
            {
                _strWhere += " and store_id=" + manModel.brand_id;
            }
            DataSet ds = bll.GetOrderAmount(0, _strWhere, " id");



            OutFileContent.Append(Exportexcel.AddContentFile(sbMsg, ds));
            //写尾文件
            OutFileContent = Exportexcel.AddEndFile(OutFileContent);
            //保存到xls
            string strRandomFileName = "简单生活订单报表";
            //strRandomFileName = strRandomFileName + DateTime.Now.ToString("yyyy-MM-dd");
            //strRandomFileName=strRandomFileName+"-"+DateTime.Now.Minute.ToString();
            //strRandomFileName = strRandomFileName+"-" + DateTime.Now.Second.ToString();

            string strPath      = Server.MapPath(Context.Request.ApplicationPath);
            string strExcelFile = strPath + strRandomFileName + ".xls";


            try
            {
                //生成excel
                FileStream OutFile = new FileStream(strExcelFile, FileMode.Create, FileAccess.Write);
                byte[]     btArray = new byte[OutFileContent.Length];
                btArray = Encoding.UTF8.GetBytes(OutFileContent.ToString());
                OutFile.Write(btArray, 0, btArray.Length);
                OutFile.Flush();
                OutFile.Close();


                //下载文件
                FileStream fs    = new FileStream(strExcelFile, FileMode.Open);
                byte[]     bytes = new byte[(int)fs.Length];
                fs.Read(bytes, 0, bytes.Length);
                fs.Close();
                Response.ContentType = "application/ms-word";
                //通知浏览器下载文件而不是打开
                Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strExcelFile, System.Text.Encoding.UTF8));
                Response.BinaryWrite(bytes);
                Response.Flush();
                Response.End();
            }
            catch (Exception ex)
            {
                JscriptMsg("请稍后再试!" + ex.Message, Vincent._DTcms.Utils.CombUrlTxt("areareport.aspx", "keywords={0}", this.keywords), "Success");
            }



            JscriptMsg("导出成功!", Vincent._DTcms.Utils.CombUrlTxt("areareport.aspx", "keywords={0}", this.keywords), "Success");
        }
        /// <summary>
        /// 获取订单总金额
        /// </summary>
        /// <param name="total_amount"></param>
        protected void getTotalAmount()
        {
            total_amount  = 0M;
            coupon_amount = 0M;
            refund_amount = 0M;
            if (datetime == null)
            {
                BLL.orders bll = new BLL.orders();
                DataTable  dt;
                if (this.outlet_id > 0)
                {
                    dt = bll.GetOrderAmount(0, " status!=1 and status!=99 and store_id=" + this.outlet_id, " add_time desc,id desc").Tables[0];
                }
                else if (this.city_id > 0)
                {
                    BLL.openarea   open    = new BLL.openarea();
                    Model.openarea openm   = open.GetModel(this.city_id);
                    StringBuilder  strTemp = new StringBuilder();
                    if (openm != null)
                    {
                        BLL.outlet outlet = new BLL.outlet();
                        DataTable  dts    = outlet.GetList(0, " city='" + openm.city + "'", " id").Tables[0];
                        if (dts.Rows.Count > 0)
                        {
                            StringBuilder st = new StringBuilder();
                            string        ss = string.Empty;
                            st.Append("(");
                            foreach (DataRow item in dts.Rows)
                            {
                                st.Append(item["id"] + ",");
                            }
                            if (st.ToString().Trim() != "(")
                            {
                                ss = DelLastComma(st.ToString().Trim());
                                st.Append(")");
                            }
                            strTemp.Append(" and store_id in" + ss + ")");
                        }
                        else
                        {
                            strTemp.Append(" and store_id in(null)");
                        }
                    }
                    dt = bll.GetOrderAmount(0, " status!=1 and status!=99" + strTemp, " add_time desc,id desc").Tables[0];
                }
                else
                {
                    dt = bll.GetOrderAmount(0, " status!=1 and status!=99", " add_time desc,id desc").Tables[0];
                }
                foreach (DataRow row in dt.Rows)
                {
                    total_amount += decimal.Parse(row["order_amount"].ToString());
                    if (row["refund_status"].ToString() != "" && int.Parse(row["refund_status"].ToString()) == 3) //统计退款
                    {
                        refund_amount += decimal.Parse(row["order_amount"].ToString());
                    }
                    BLL.user_coupon_log couponbll = new BLL.user_coupon_log();//统计优惠券
                    if (row["str_code"].ToString() != "")
                    {
                        Model.user_coupon_log couponmodel = couponbll.GetModel(row["str_code"].ToString());
                        if (couponmodel != null && couponmodel.status == 2)
                        {
                            BLL.user_coupon   copbl = new BLL.user_coupon();
                            Model.user_coupon copmo = copbl.GetModel(couponmodel.coupon_id);
                            if (copmo != null)
                            {
                                if (copmo.amount > decimal.Parse(row["order_amount"].ToString()))
                                {
                                    coupon_amount += decimal.Parse(row["order_amount"].ToString());
                                }
                                else
                                {
                                    coupon_amount += copmo.amount;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                BLL.orders bll = new BLL.orders();

                DataTable dt;
                if (this.outlet_id > 0)
                {
                    dt = bll.GetOrderAmount(0, " status!=1 and status!=99 and store_id=" + this.outlet_id, " add_time desc,id desc").Tables[0];
                }
                else
                {
                    dt = bll.GetOrderAmount(0, " status!=1 and status!=99", " add_time desc,id desc").Tables[0];
                }

                //DataTable dt = bll.GetOrderAmount(0, " status!=1 and status!=99 and datediff(dd,add_time,'" + datetime + "')=0", " add_time desc,id desc").Tables[0];
                foreach (DataRow row in dt.Rows)
                {
                    total_amount += decimal.Parse(row["order_amount"].ToString());
                    if (row["refund_status"].ToString() != "" && int.Parse(row["refund_status"].ToString()) == 3)
                    {
                        refund_amount += decimal.Parse(row["order_amount"].ToString());
                    }
                    BLL.user_coupon_log couponbll = new BLL.user_coupon_log();//统计优惠券
                    if (row["str_code"].ToString() != "")
                    {
                        Model.user_coupon_log couponmodel = couponbll.GetModel(row["str_code"].ToString());
                        if (couponmodel != null && couponmodel.status == 2)
                        {
                            BLL.user_coupon   copbl = new BLL.user_coupon();
                            Model.user_coupon copmo = copbl.GetModel(couponmodel.coupon_id);
                            if (copmo != null)
                            {
                                if (copmo.amount > decimal.Parse(row["order_amount"].ToString()))
                                {
                                    coupon_amount += decimal.Parse(row["order_amount"].ToString());
                                }
                                else
                                {
                                    coupon_amount += copmo.amount;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// 获取订单总金额
 /// </summary>
 /// <param name="total_amount"></param>
 protected void getTotalAmount()
 {
     total_amount  = 0M;
     coupon_amount = 0M;
     refund_amount = 0M;
     if (date == null || date == "")
     {
         BLL.orders bll = new BLL.orders();
         DataTable  dt  = bll.GetOrderAmount(0, " status!=1 and status!=99", " add_time desc,id desc").Tables[0];
         foreach (DataRow row in dt.Rows)
         {
             total_amount += decimal.Parse(row["order_amount"].ToString());
             if (row["refund_status"].ToString() != "" && int.Parse(row["refund_status"].ToString()) == 3) //统计退款
             {
                 refund_amount += decimal.Parse(row["order_amount"].ToString());
             }
             BLL.user_coupon_log couponbll = new BLL.user_coupon_log();//统计优惠券
             if (row["str_code"].ToString() != "")
             {
                 Model.user_coupon_log couponmodel = couponbll.GetModel(row["str_code"].ToString());
                 if (couponmodel != null && couponmodel.status == 2)
                 {
                     BLL.user_coupon   copbl = new BLL.user_coupon();
                     Model.user_coupon copmo = copbl.GetModel(couponmodel.coupon_id);
                     if (copmo != null)
                     {
                         if (copmo.amount > decimal.Parse(row["order_amount"].ToString()))
                         {
                             coupon_amount += decimal.Parse(row["order_amount"].ToString());
                         }
                         else
                         {
                             coupon_amount += copmo.amount;
                         }
                     }
                 }
             }
         }
     }
     else
     {
         BLL.orders bll = new BLL.orders();
         DataTable  dt  = bll.GetOrderAmount(0, " status!=1 and status!=99 and datediff(dd,add_time,'" + date + "')=0", " add_time desc,id desc").Tables[0];
         foreach (DataRow row in dt.Rows)
         {
             total_amount += decimal.Parse(row["order_amount"].ToString());
             if (row["refund_status"].ToString() != "" && int.Parse(row["refund_status"].ToString()) == 3)
             {
                 refund_amount += decimal.Parse(row["order_amount"].ToString());
             }
             BLL.user_coupon_log couponbll = new BLL.user_coupon_log();//统计优惠券
             if (row["str_code"].ToString() != "")
             {
                 Model.user_coupon_log couponmodel = couponbll.GetModel(row["str_code"].ToString());
                 if (couponmodel != null && couponmodel.status == 2)
                 {
                     BLL.user_coupon   copbl = new BLL.user_coupon();
                     Model.user_coupon copmo = copbl.GetModel(couponmodel.coupon_id);
                     if (copmo != null)
                     {
                         if (copmo.amount > decimal.Parse(row["order_amount"].ToString()))
                         {
                             coupon_amount += decimal.Parse(row["order_amount"].ToString());
                         }
                         else
                         {
                             coupon_amount += copmo.amount;
                         }
                     }
                 }
             }
         }
     }
 }