public HttpResponseBase PromoShareList()
 {
     PromoShareMasterQuery query = new PromoShareMasterQuery();
     DataTable _dt = new DataTable();
     string json = string.Empty;
     int  totalCount = 0;
     try
     {
         query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");
         query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");
         if (!string.IsNullOrEmpty(Request.Params["ddlstatus"]))
         {
         query.promo_active = Convert.ToInt32(Request.Params["ddlstatus"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["promo_name_list"]))
         { 
          query.promo_name=Request.Params["promo_name_list"];
         }
         PshareMgr = new PromoShareMasterMgr(mySqlConnectionString);
         _dt = PshareMgr.GetList(query, out totalCount);
         IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
         timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
         json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(_dt, Formatting.Indented, timeConverter) + "}";
     }
     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 JsonResult DeletePromoShareMessage()
 {
     try
     {
         string str = Request.Params["rid"];//獲取類型
         str = str.Substring(0, str.LastIndexOf(","));
         PshareMgr = new PromoShareMasterMgr(mySqlConnectionString);
         if (PshareMgr.DeletePromoShareMessage(str) > 0)
         {
             return Json(new { success = "true" });
         }
         else
         {
             return Json(new { success = "false" });
         }
     }
     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);
         return Json(new { success = "false" });
     }
 }
        //public HttpResponseBase EditPromoShareMaster()
        //{
        //    PromoShareMaster query = new PromoShareMaster();
        //    string json = string.Empty;
        //    try
        //    {
        //        if (!string.IsNullOrEmpty(Request.Params["Epromo_id"]))
        //        {
        //            query.promo_id = Convert.ToInt32(Request.Params["Epromo_id"]);
        //        }
        //        if (!string.IsNullOrEmpty(Request.Params["Epromo_name"]))
        //        {
        //            query.promo_name = Request.Params["Epromo_name"];
        //        }
        //        if (!string.IsNullOrEmpty(Request.Params["Epromo_desc"]))
        //        {
        //            query.promo_desc = Request.Params["Epromo_desc"];
        //        }
        //        if (!string.IsNullOrEmpty(Request.Params["Epromo_start"]))
        //        {
        //            query.promo_start = Convert.ToDateTime(Request.Params["Epromo_start"]);
        //        }
        //        if (!string.IsNullOrEmpty(Request.Params["Epromo_end"]))
        //        {
        //            query.promo_end = Convert.ToDateTime(Request.Params["Epromo_end"]);
        //        }
        //        PshareMgr = new PromoShareMasterMgr(mySqlConnectionString);
        //        if (PshareMgr.Update(query) > 0)
        //        {
        //            json = "{success:true}";
        //        }
        //        else
        //        {
        //            json = "{success:false}";
        //        }
        //    }
        //    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;
        //}
        #endregion

        #region 編輯
        public HttpResponseBase updatePromoShareCon()
        {
            PromoShareMaster psmQuery = new PromoShareMaster();
              PromoShareCondition pscQuery = new PromoShareCondition();
            PshareMgr = new PromoShareMasterMgr(mySqlConnectionString);
            PshareConMgr = new PromoShareConditionMgr(mySqlConnectionString);
            string json = string.Empty;
            try
            {
            if (!string.IsNullOrEmpty(Request.Params["promo_name"]))
            {
                psmQuery.promo_name = Request.Params["promo_name"];
            }
            if (!string.IsNullOrEmpty(Request.Params["promo_desc"]))
            {
                psmQuery.promo_desc = Request.Params["promo_desc"];
            }
            if (!string.IsNullOrEmpty(Request.Params["promo_start"]))
            {
                psmQuery.promo_start = Convert.ToDateTime(Request.Params["promo_start"]);
            }
            if (!string.IsNullOrEmpty(Request.Params["promo_end"]))
            {
                psmQuery.promo_end = Convert.ToDateTime(Request.Params["promo_end"]);
            }
            if (!string.IsNullOrEmpty(Request.Params["promo_id"]))
            {
                psmQuery.promo_id = Convert.ToInt32(Request.Params["promo_id"]);
            }

            //判斷如果condition表內無此編號的數據則insert,如果有此編號的數據則update
            if (PshareMgr.PromoCon(psmQuery) == 0)
            {//執行新增
                InsertIntoPromoShareCon(pscQuery);//插入promo_share_condition;新增入第二個面板
            }
            else
            {//執行編輯
                //編輯第一個面板
                PshareMgr.Update(psmQuery);
                //1編輯第二個面板 promo_share_condition, 
                //2將promo_share_condition表中對應promo_id數據刪除 
                //3然後再次insert
                PshareConMgr.Delete(psmQuery.promo_id);
                InsertIntoPromoShareCon(pscQuery);
                //PshareConMgr.Update(pscQuery);
            }
            json = "{success:true}";
        }
               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 JsonResult UpdateActivePromoShareMaster()
        {
            try
            {
                int row_id = 0;
                if (!string.IsNullOrEmpty(Request.Params["row_id"].ToString()))
                {
                    row_id = Convert.ToInt32(Request.Params["row_id"].ToString());
                }
                int activeValue = Convert.ToInt32(Request.Params["active"] ?? "0");
                PshareMgr = new PromoShareMasterMgr(mySqlConnectionString);
                PromoShareMaster model = new PromoShareMaster();
                model.promo_id = row_id;
                model.promo_active = activeValue;
                if (PshareMgr.UpdateActivePromoShareMaster(model) > 0)
                {
                    return Json(new { success = "true" });
                }
                else
                {
                    return Json(new { success = "false" });
                }
            }
            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);
                return Json(new { success = "false" });
            }

        }
 public HttpResponseBase InsertIntoPromoShareMaster()
 {
     PromoShareMasterQuery query = new PromoShareMasterQuery();
     string json = string.Empty;
     try
     {
         if (!string.IsNullOrEmpty(Request.Params["promo_name"]))
         {
             query.promo_name = Request.Params["promo_name"];
         }
         if (!string.IsNullOrEmpty(Request.Params["promo_desc"]))
         {
             query.promo_desc = Request.Params["promo_desc"];
         }
         if (!string.IsNullOrEmpty(Request.Params["promo_start"]))
         {
             query.promo_start = Convert.ToDateTime(Request.Params["promo_start"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["promo_end"]))
         {
             query.promo_end = Convert.ToDateTime(Request.Params["promo_end"]);
         }
         PshareMgr = new PromoShareMasterMgr(mySqlConnectionString);
         int PromoId = PshareMgr.Add(query);
         string strPromoId ="SH";
         if (PromoId > 0)
         {
             if (PromoId.ToString().Length < 6)
             {
                 for (int i = 0; i < 6 - PromoId.ToString().Length; i++)
                 {
                     strPromoId += "0";
                 }
             }
             strPromoId += PromoId.ToString();
             query = new PromoShareMasterQuery();
             query.promo_event_id = strPromoId;
             query.promo_id = PromoId;
             query.eventId = true;
             if (PshareMgr.Update(query) > 0)
             {
                 json = "{success:'true',strPromoId:'" + strPromoId + "',PromoId:'" + PromoId + "'}";
             }
             else
             {
                 json = "{success:false}";
             }
         }
         else
         {
             json = "{success:false}";
         }
     }
     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;
 }