public List<OrderExpectDeliverQuery> GetModel(OrderExpectDeliverQuery store)
 {
     try
     {
         return _orderExpectDeliverDao.GetModel(store);
     }
     catch (Exception ex)
     {
         throw new Exception("OrderExpectDeliverMgr.GetModel-->" + ex.Message, ex);
     }
 }
 public int OrderExpectModify(OrderExpectDeliverQuery store)
 {
     try
     {
         return _orderExpectDeliverDao.OrderExpectModify(store);
     }
     catch (Exception ex)
     {
         throw new Exception("OrderExpectDeliverMgr.OrderExpectModify-->" + ex.Message, ex);
     }
 }
 public List<OrderExpectDeliverQuery> GetOrderExpectList(OrderExpectDeliverQuery query, out int totalCount)
 {
     try
     {
         return _orderExpectDeliverDao.GetOrderExpectList(query, out totalCount);
     }
     catch (Exception ex)
     {
         throw new Exception("OrderExpectDeliverMgr.GetOrderExpectList-->" + ex.Message, ex);
     }
 }
 public int OrderExpectModify(OrderExpectDeliverQuery store)
 {
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.AppendFormat(" UPDATE order_expect_deliver SET `status`='{0}',store='{1}',code='{2}',time='{3}',updatedate='{4}',note='{5}' WHERE expect_id='{6}';", store.status, store.store, store.code, store.time, store.updatedate, store.note, store.expect_id);
         return _accessMySql.execCommand(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("OrderExpectDeliverDao.OrderExpectModify-->" + ex.Message + sql.ToString(), ex);
     }
 }
        public List<OrderExpectDeliverQuery> GetOrderExpectList(OrderExpectDeliverQuery query, out int totalCount)
        {
            StringBuilder sql = new StringBuilder();
            StringBuilder sqlCondi = new StringBuilder();
            try
            {
                sql.Append(@" SELECT oed.expect_id,oed.order_id,oed.slave_id,oed.detail_id,oed.`status`,oed.store,oed.`code`,FROM_UNIXTIME(oed.time) as stime,oed.note,FROM_UNIXTIME(oed.createdate) as date_one,FROM_UNIXTIME(oed.updatedate) as date_two,om.note_order,od.product_name,od.detail_status,c.remark as d_status_name ");
                sqlCondi.Append(" FROM order_expect_deliver oed ,order_master om,order_detail od left join (select parametercode,parametername,remark from t_parametersrc where parametertype='order_status') c on od.detail_status=c.parametercode ");
                sqlCondi.Append(" WHERE  oed.order_id=om.order_id AND oed.detail_id =od.detail_id ");

                if (query.date_one != DateTime.MinValue)
                {
                    sqlCondi.AppendFormat(" and oed.createdate >='{0}'", CommonFunction.GetPHPTime(query.date_one.ToString("yyyy-MM-dd HH:mm:ss")));

                }
                if (query.date_two != DateTime.MinValue)
                {
                    sqlCondi.AppendFormat(" and oed.createdate <='{0}'", CommonFunction.GetPHPTime(query.date_two.ToString("yyyy-MM-dd HH:mm:ss")));
                }

                if (query.query_status != -1)//-1表所有狀態,0表示未出貨
                {
                    sqlCondi.AppendFormat(" and oed.`status`='{0}'", query.query_status);
                }
                totalCount = 0;
                if (query.IsPage)
                {
                    System.Data.DataTable _dt = _accessMySql.getDataTable("select count(*) as totalCount " + sqlCondi.ToString());
                    if (_dt != null && _dt.Rows.Count > 0)
                    {
                        totalCount = Convert.ToInt32(_dt.Rows[0]["totalCount"]);
                    }
                    sqlCondi.AppendFormat(" limit {0},{1}", query.Start, query.Limit);

                }
                sql.Append(sqlCondi.ToString());
                return _accessMySql.getDataTableForObj<OrderExpectDeliverQuery>(sql.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("OrderExpectDeliverDao.GetOrderExpectList-->" + ex.Message + sql.ToString(), ex);
            }

        }
        public void ExportToExcel()
        {
            string json = string.Empty;

            OrderExpectDeliverQuery query = new OrderExpectDeliverQuery();
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["seledate"]))
                {
                    if (int.Parse(Request.Params["seledate"]) == 1)
                    {
                        if (!string.IsNullOrEmpty(Request.Params["dateOne"]))
                        {
                            query.date_one = Convert.ToDateTime(Request.Params["dateOne"].ToString());
                        }
                        if (!string.IsNullOrEmpty(Request.Params["dateTwo"]))
                        {
                            query.date_two = Convert.ToDateTime(Request.Params["dateTwo"].ToString());
                        }

                    }
                }
                if (!string.IsNullOrEmpty(Request.Params["status"]))
                {
                    query.query_status = Convert.ToInt32(Request.Params["status"].ToString());
                }
                List<OrderExpectDeliverQuery> stores = new List<OrderExpectDeliverQuery>();
                DataTable dtHZ = new DataTable();
                string newExcelName = string.Empty;
                dtHZ.Columns.Add("商品編號", typeof(String));
                dtHZ.Columns.Add("商品名稱", typeof(String));
                dtHZ.Columns.Add("訂購人", typeof(String));
                dtHZ.Columns.Add("收貨人", typeof(String));
                dtHZ.Columns.Add("收貨人手機", typeof(String));
                dtHZ.Columns.Add("收貨人住址", typeof(String));
                dtHZ.Columns.Add("數量", typeof(String));
                dtHZ.Columns.Add("金額", typeof(String));
                dtHZ.Columns.Add("購物金", typeof(String));
                dtHZ.Columns.Add("小計", typeof(String));
                dtHZ.Columns.Add("預購單狀態", typeof(String));
                _orderExpectDeliverMgr = new OrderExpectDeliverMgr(mySqlConnectionString);
                stores = _orderExpectDeliverMgr.GetModel(query);
                foreach (var item in stores)
                {
                    DataRow dr = dtHZ.NewRow();
                    dr[0] = item.item_id;
                    dr[1] = item.product_name;
                    dr[2] = item.order_name;
                    dr[3] = item.delivery_name;
                    dr[4] = item.delivery_mobile;
                    dr[5] = item.zip;
                    dr[6] = item.buy_num;
                    dr[7] = item.single_money;
                    dr[8] = item.deduct_bonus;
                    dr[9] = item.sum;
                    switch (item.status.ToString())
                    {
                        case "0": dr[10] = "未出貨";
                            break;
                        case "1": dr[10] = "已出貨";
                            break;
                        case "2": dr[10] = "異常";
                            break;
                    }
                    dtHZ.Rows.Add(dr);
                }
                if (dtHZ.Rows.Count > 0)
                {
                    string fileName = "預購單_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
                    MemoryStream ms = ExcelHelperXhf.ExportDT(dtHZ, "");
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                    Response.BinaryWrite(ms.ToArray());
                }
                else
                {
                    Response.Write("匯出數據不存在");
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,data:[]}";
            }
        }
        public HttpResponseBase OrderExpectModify()
        {
            string json = "{success:false}";
            try
            {
                _orderExpectDeliverMgr = new OrderExpectDeliverMgr(mySqlConnectionString);
                OrderExpectDeliverQuery query = new OrderExpectDeliverQuery();
                uint isTryUint = 0;
                query.expect_id = Convert.ToUInt32(Request.Params["expect_id"]);


                if (uint.TryParse(Request.Params["e_status"].ToString(), out isTryUint))
                {
                    query.status = Convert.ToUInt32(Request.Params["e_status"]);
                }
                else
                {
                    query.status = 0;
                }
                if (uint.TryParse(Request.Params["deliver_id"].ToString(), out isTryUint))
                {
                    query.store = uint.Parse(Request.Params["deliver_id"]);
                }
                else
                {
                    query.store = 99;
                }
                if (!string.IsNullOrEmpty(Request.Params["code"]))
                {
                    query.code = Request.Params["code"].ToString();
                }
                else
                {
                    query.code = "";
                }
                if (!string.IsNullOrEmpty(Request.Params["stime"]))
                {
                    query.time = Convert.ToUInt32(CommonFunction.GetPHPTime(DateTime.Parse(Request.Params["stime"]).ToString("yyyy-MM-dd 00:00:00")));
                }
                else
                {
                    query.time = Convert.ToUInt32(CommonFunction.GetPHPTime(DateTime.MinValue.ToString()));
                }
                if (!string.IsNullOrEmpty(Request.Params["note"]))
                {
                    query.note = Request.Params["note"];
                }
                else
                {
                    query.note = "";
                }
                query.updatedate = uint.Parse(CommonFunction.GetPHPTime(DateTime.Now.ToString()).ToString());
                if (_orderExpectDeliverMgr.OrderExpectModify(query) > 0)
                {
                    json = "{success:true}";//返回json數據
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;

        }
 public HttpResponseBase GetOrderExpectList()
 {
     List<OrderExpectDeliverQuery> stores = new List<OrderExpectDeliverQuery>();
     string json = string.Empty;
     try
     {
         OrderExpectDeliverQuery query = new OrderExpectDeliverQuery();
         query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量
         query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");//用於分頁的變量
         #region 日期條件
         if (!string.IsNullOrEmpty(Request.Params["seledate"]))
         {
             if (int.Parse(Request.Params["seledate"]) == 1)
             {
                 if (!string.IsNullOrEmpty(Request.Params["dateOne"]))
                 {
                     query.date_one = Convert.ToDateTime(Request.Params["dateOne"].ToString());
                 }
                 if (!string.IsNullOrEmpty(Request.Params["dateTwo"]))
                 {
                     query.date_two = Convert.ToDateTime(Request.Params["dateTwo"].ToString());
                 }
             }
         }
         #endregion
         #region 訂單狀態
         if (!string.IsNullOrEmpty(Request.Params["status"]))
         {
             query.query_status = Convert.ToInt32(Request.Params["status"].ToString());
         }
         #endregion
         _orderExpectDeliverMgr = new OrderExpectDeliverMgr(mySqlConnectionString);
         int totalCount = 0;
         stores = _orderExpectDeliverMgr.GetOrderExpectList(query, out totalCount);
         IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
         //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
         timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
         //listUser是准备转换的对象
         json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(stores, Formatting.Indented, timeConverter) + "}";//返回json數據
     }
     catch (Exception ex)
     {
         Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
         logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
         logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
         log.Error(logMessage);
         json = "{success:true,totalCount:0,data:[]}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }
        public List<OrderExpectDeliverQuery> GetModel(OrderExpectDeliverQuery store)
        {
            StringBuilder sql = new StringBuilder();
            StringBuilder sqlCondi = new StringBuilder();
            try
            {

                if (store.date_one != DateTime.MinValue)
                {
                    sqlCondi.AppendFormat(" and oed.createdate >='{0}'", CommonFunction.GetPHPTime(store.date_one.ToString("yyyy-MM-dd HH:mm:ss")));

                }
                if (store.date_two != DateTime.MinValue)
                {
                    sqlCondi.AppendFormat(" and oed.createdate <='{0}'", CommonFunction.GetPHPTime(store.date_two.ToString("yyyy-MM-dd HH:mm:ss")));
                }

                if (store.query_status != -1)//-1表所有狀態,0表示未出貨
                {
                    sqlCondi.AppendFormat(" and oed.`status`='{0}'", store.query_status);
                }
                sql.Append(@" SELECT oed.expect_id,CONCAT_WS(' ',om.delivery_zip,tzc.middle,tzc.small,om.delivery_address) as zip,om.order_address,oed.order_id,oed.slave_id,oed.detail_id, ");
                sql.Append(" oed.`status`,oed.`code`,oed.time,oed.note,oed.store, ");
                sql.Append(" oed.createdate,oed.updatedate,od.detail_status,om.note_order,od.product_name, ");
                sql.Append(" od.item_id,om.order_name,om.delivery_name,om.delivery_mobile,om.delivery_zip,");
                sql.Append(" om.delivery_address,od.buy_num,od.single_money,od.deduct_bonus,(od.single_money*od.buy_num-od.deduct_bonus) as sum ");
                sql.AppendFormat(" FROM order_expect_deliver oed ,order_master om,order_detail od, t_zip_code tzc ");
                sql.AppendFormat(" WHERE 1=1 AND oed.order_id=om.order_id AND oed.detail_id =od.detail_id and tzc.zipcode= om.delivery_zip ");
                return _accessMySql.getDataTableForObj<OrderExpectDeliverQuery>(sql.ToString() + sqlCondi.ToString());
            }
            catch(Exception ex)
            {
             throw new Exception("OrderExpectDeliverDao-->GetModel"+ex.Message+sql.ToString(),ex);
            }
        }