/// <summary>
 /// 新增
 /// </summary>
 /// <param name="model">PromoShareCondition對象</param>
 /// <returns>新增數據的Sql語句</returns>
 public string AddSql(PromoShareCondition model)
 {
     StringBuilder sbSql = new StringBuilder();
     sbSql.Append("INSERT INTO promo_share_condition(condition_name,condition_value,promo_id) ");
     sbSql.AppendFormat(" VALUES('{0}','{1}','{2}');", model.condition_name, model.condition_value, model.promo_id);
     return sbSql.ToString();
 }
 /// <summary>
 /// 修改
 /// </summary>
 /// <param name="model">PromoShareCondition對象</param>
 /// <returns>更新結果</returns>
 public int Update(PromoShareCondition model)
 {
     try
     {
         return _pscDao.Update(model);
     }
     catch (Exception ex)
     {
         throw new Exception("PromoShareConditionMgr-->Update-->" + ex.Message, ex);
     }
 }
 /// <summary>
 /// 新增
 /// </summary>
 /// <param name="model">PromoShareCondition對象</param>
 /// <returns>新增后的標識</returns>
 public int Add(PromoShareCondition model)
 {
     try
     {
        return _pscDao.Add(model);
     }
     catch (Exception ex)
     {
         throw new Exception("PromoShareConditionMgr-->Add-->" + ex.Message, ex);
     }
 }
 /// <summary>
 /// 修改
 /// </summary>
 /// <param name="model">PromoShareCondition對象</param>
 /// <returns>更新結果</returns>
 public int Update(PromoShareCondition model)
 {
     int result = 0;
     StringBuilder sbSql = new StringBuilder();
     sbSql.Append("set sql_safe_updates=0;");
     sbSql.AppendFormat("UPDATE promo_share_condition set condition_type_id='{0}',condition_name='{1}',condition_value='{2}',promo_id='{3}' WHERE condition_id='{4}';", model.condition_type_id, model.condition_name,model.condition_value, model.promo_id,model.condition_id);
     sbSql.Append("set sql_safe_updates=1;");
     try
     {
         result = _access.execCommand(sbSql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("PromoShareConditionDao-->Update-->" + ex.Message + sbSql.ToString(), ex);
     }
     return result;
 } 
 /// <summary>
 /// 新增
 /// </summary>
 /// <param name="model">PromoShareCondition對象</param>
 /// <returns>新增后的標識</returns>
 public int Add(PromoShareCondition model)
 {
     StringBuilder sbSql = new StringBuilder();
     sbSql.Append("INSERT INTO promo_share_condition(condition_name,condition_value,promo_id) ");
     sbSql.AppendFormat(" VALUES('{0}','{1}','{2}');", model.condition_name, model.condition_value, model.promo_id);
     try
     {
         DataTable _dt = _access.getDataTable(sbSql.ToString());
         if (_dt.Rows.Count > 0)
         {
             return Convert.ToInt32(_dt.Rows[0][0]);
         }
         else
         {
             return 0;
         }
     }
     catch (Exception ex)
     {
         throw new Exception("PromoShareConditionDao-->Add-->" + ex.Message + sbSql.ToString(), ex);
     }
 }
 public int GetPromoShareConditionCount(PromoShareCondition query)
 {
     try
     {
         return _pscDao.GetPromoShareConditionCount(query);
     }
     catch (Exception ex)
     {
         throw new Exception("PromoShareConditionMgr-->GetPromoShareConditionCount-->" + ex.Message, ex);
     }
 }
 public DataTable Get(string[] condition, PromoShareCondition query)
 {
     try
     {
         return _pscDao.Get(condition, query);
     }
     catch (Exception ex)
     {
         throw new Exception("PromoShareConditionMgr-->Get-->" + ex.Message, ex);
     }
 }
 public HttpResponseBase GetEditData()
 {
    // List<PromoShareCondition> store = new List<PromoShareCondition>();
     PromoShareCondition query = new PromoShareCondition();
     string json = string.Empty;
     try
     {
         if (!string.IsNullOrEmpty(Request.Params["PromoId"]))
         {
             query.promo_id = Convert.ToInt32(Request.Params["PromoId"]);
         }
         PshareConMgr = new PromoShareConditionMgr(mySqlConnectionString);
         DataTable _dt=PshareConMgr.Get(condition, query);
     //    _dt.Columns.Add("promo_event_id",typeof (string));
      //   string strPromoId = "SH";
         //if (_dt.Rows[0]["promo_id"].ToString().Length < 6)
         //{
         //    for (int i = 0; i <6-_dt.Rows[0]["promo_id"].ToString().Length; i++)
         //    {
         //        strPromoId += "0";
         //    }
         //}
         //strPromoId += _dt.Rows[0]["promo_id"].ToString();
         //_dt.Rows[0]["promo_event_id"] = strPromoId;
         json = "{success:true,data:" + JsonConvert.SerializeObject(_dt, Formatting.Indented) + "}";
     }
     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);
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }
        public HttpResponseBase GetPromoShareConditionCount()
        {
            PromoShareCondition query = new PromoShareCondition();
            string json = string.Empty;
            int count = 0;
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["promo_id"]))
                {
                    query.promo_id = Convert.ToInt32(Request.Params["promo_id"]);
                }
                PshareConMgr = new PromoShareConditionMgr(mySqlConnectionString);
                count = PshareConMgr.GetPromoShareConditionCount(query);
               
                json = "{success:true,Count:" + count + "}";
            }

            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,Count:0}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
示例#10
0
        //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;
        }
示例#11
0
        public void InsertIntoPromoShareCon(PromoShareCondition query)
        {
            List<PromoShareCondition> list = new List<PromoShareCondition>();
            PshareConMgr = new PromoShareConditionMgr(mySqlConnectionString);
            string json = string.Empty;
             DataTable _dt=new DataTable();
            try
            {
                for (int i = 0; i < condition.Length; i++)
                {
                    if (!string.IsNullOrEmpty(Request.Params[condition[i]]))
                    {
                        query = new PromoShareConditionQuery();
                        query.promo_id = Convert.ToInt32(Request.Params["promo_id"]);
                        query.condition_name = condition[i];
                        query.condition_value = Request.Params[ condition[i]];
                        if (query.condition_name == "picture")
                        {
                            #region 上傳圖片
                            string ErrorMsg = string.Empty;
                            string path = Server.MapPath(xmlPath);
                            SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
                            SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format");
                            SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_Min_Element");
                            SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue");
                            SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME");
                            SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD");
                            //擴展名、最小值、最大值
                            string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value;
                            string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value;
                            string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value;
                            string localPromoPath = imgLocalPath + promoPath;//圖片存儲地址
                            FileManagement fileLoad = new FileManagement();
                            if (Request.Files.Count > 0)
                            {
                                HttpPostedFileBase file = Request.Files[0];
                                string fileName = string.Empty;//當前文件名
                                string fileExtention = string.Empty;//當前文件的擴展名
                                fileName = fileLoad.NewFileName(file.FileName);
                                if (fileName != "")
                                {
                                    fileName = fileName.Substring(0, fileName.LastIndexOf("."));
                                    fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString();
                                    string NewFileName = string.Empty;
                                    HashEncrypt hash = new HashEncrypt();
                                    NewFileName = hash.Md5Encrypt(fileName, "32");
                                    string ServerPath = string.Empty;
                                    FTP f_cf = new FTP();
                                    f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'), ftpuser, ftppwd);
                                    fileName = NewFileName + fileExtention;
                                    NewFileName = localPromoPath + NewFileName + fileExtention;//絕對路徑
                                    ServerPath = Server.MapPath(imgLocalServerPath + promoPath);

                                    //上傳之前刪除已有的圖片
                                    if (query.promo_id != 0)
                                    {
                                        _dt = PshareConMgr.Get(condition, query);
                                        if (_dt.Rows[0]["picture"].ToString() != "")
                                        {
                                            string oldFileName = _dt.Rows[0]["picture"].ToString();
                                            CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                                            FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd);
                                            List<string> tem = ftp.GetFileList();
                                            if (tem.Contains(oldFileName))
                                            {
                                                FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd);
                                                ftps.DeleteFile(localPromoPath + oldFileName);
                                            }
                                        }
                                    }
                                    try
                                    {
                                        Resource.CoreMessage = new CoreResource("Product");
                                        bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                        if (result)
                                        {
                                            query.condition_value = fileName;
                                        }

                                    }
                                    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);
                                    }
                                    if (!string.IsNullOrEmpty(ErrorMsg))
                                    {
                                        string jsonStr = string.Empty;
                                        json = "{success:true,msg:\"" + ErrorMsg + "\"}";
                                        this.Response.Clear();
                                        this.Response.Write(json);
                                        this.Response.End();
                                    }

                                }
                            }
                            else
                            {
                                query.condition_value = _dt.Rows[0]["picture"].ToString();
                            }
                            #endregion
                        }
                        list.Add(query);
                    }
                }
             
                PshareConMgr.AddSql(list);
            }
            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}";
            }
        }
 /// <summary>
 /// 通過id獲取PromoShareCondition對象
 /// </summary>
 /// <param name="condition_id">編號</param>
 /// <returns>PromoShareCondition對象</returns>
 public PromoShareCondition Get(int condition_id)
 {
     PromoShareCondition model = new PromoShareCondition();
     string sql = "SELECT condition_id,condition_type_id,condition_name,condition_value,promo_id FROM promo_share_condition WHERE condition_id=" + condition_id;
     try
     {
         model = _access.getSinggleObj<PromoShareCondition>(sql);
     }
     catch (Exception ex)
     {
         throw new Exception("PromoShareCondition-->Get-->" + ex.Message + sql, ex);
     }
     return model;
 }
 public int GetPromoShareConditionCount(PromoShareCondition query)
 {
     string sql = "SELECT promo_id FROM promo_share_condition WHERE promo_id=" + query.promo_id;
     try
     {
         return _access.getDataTable(sql).Rows.Count;
     }
     catch (Exception ex)
     {
         throw new Exception("PromoShareCondition-->GetPromoShareConditionCount-->" + ex.Message + sql, ex);
     }
 }
 public DataTable Get(string[] condition,PromoShareCondition query)
 {
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.Append(" select promo_id ");
         for (int i = 0; i < condition.Length; i++)
         {
             sql.AppendFormat(",max(case psc.condition_name when '{0}' then psc.condition_value end)  '{1}'", condition[i], condition[i]);
         }
         sql.AppendFormat("from   promo_share_condition psc where promo_id='{0}';", query.promo_id);
         return _access.getDataTable(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("PromoShareConditionDao-->Get-->"+sql.ToString()+ex.Message,ex);
     }
 }