Esempio n. 1
0
        public ActionResult Login()
        {
            object notice = new object();
            if (string.IsNullOrEmpty(Request.Params["txtEmail"]))
            {
                notice = "{result:'Notice',msg:'" + Resources.Login.NOTICE_NO_EMAIL + "'}";
                ViewBag.notice = notice;
                return View("Index");
            }

            string IsRemember = Request.Params["chkRememberEmail"] != null ? Request.Params["chkRememberEmail"] : "false";
            string email = Request.Params["txtEmail"].Trim();
            string passwd = Request.Params["hid_password"].Trim();
            string challenge_id = Request.Params["challenge_id"];
            int CookieExpireTime = 10;
            ViewBag.LoginEmail = null;
            ICallerImplMgr callerMgr = new CallerMgr(connectionString);
            Caller caller = null;
            UserLoginAttemptsMgr ulaMgr = new UserLoginAttemptsMgr(connectionString);

            //記錄/清空cookie

            BLL.gigade.Common.CommonFunction.Cookie_Set("UserInfo", "email", email, IsRemember, CookieExpireTime);


            if (!Regex.IsMatch(email, @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"))
            {
                notice = "{result:'Notice',msg:'" + Resources.Login.NOTICE_EMAIL_FORMAT_ERROR + "'}";
                ViewBag.notice = notice;
                if (IsRemember == "true")
                {
                    ViewBag.LoginEmail = email;
                }

                return View("Index");
            }

            if (passwd == "")
            {
                notice = "{result:'Notice',msg:'" + Resources.Login.NOTICE_NO_PASSWD + "'}";
                ViewBag.notice = notice;
                if (IsRemember == "true")
                {
                    ViewBag.LoginEmail = email;
                }
                return View("Index");
            }

            try
            {
                caller = callerMgr.Login(email);
            }
            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 (caller == null)
            {
                notice = "{result:'Error',msg:'" + Resources.Login.ERROR_EMAIL_PASSWD_ERROR + "'}";
                ViewBag.notice = notice;
                if (IsRemember == "true")
                {
                    ViewBag.LoginEmail = email;
                }
                UserLoginAttempts ula = new UserLoginAttempts();
                ula.login_mail = email;
                ula.login_ipfrom = CommonFunction.GetIP4Address(Request.UserHostAddress.ToString());
                ula.login_type = 3;
                ulaMgr.Insert(ula);
                return View("Index");
            }
            else
            {
                if (caller.user_status == 2)
                {
                    notice = "{result:'Error',msg:'" + Resources.Login.NOTICE_EMAIL_STOP + "'}";

                    if (IsRemember == "true")
                    {
                        ViewBag.LoginEmail = email;
                    }
                    UserLoginAttempts ula = new UserLoginAttempts();
                    ula.login_mail = email;
                    ula.login_ipfrom = CommonFunction.GetIP4Address(Request.UserHostAddress.ToString());
                    ula.login_type = 3;
                    ulaMgr.Insert(ula);
                    ViewBag.notice = notice;
                    return View("Index");
                }

                if (caller.user_status == 3)
                {
                    notice = "{result:'Error',msg:'" + Resources.Login.NOTICE_EMAIL_DELETE + "'}";

                    if (IsRemember == "true")
                    {
                        ViewBag.LoginEmail = email;
                    }

                    UserLoginAttempts ula = new UserLoginAttempts();
                    ula.login_mail = caller.user_email;
                    ula.login_ipfrom = CommonFunction.GetIP4Address(Request.UserHostAddress.ToString());
                    ula.login_type = 3;
                    ulaMgr.Insert(ula);
                    ViewBag.notice = notice;
                    return View("Index");
                }

                string challenge_key = "";

                try
                {
                    challenge_key = callerMgr.Get_Challenge_Key(challenge_id);
                    callerMgr.Kill_Challenge_Id(challenge_id);
                }
                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);
                }

                BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                string newpasswd = hash.SHA256Encrypt(caller.user_password + challenge_key);


                if (passwd != newpasswd)
                {
                    try
                    {
                        callerMgr.Add_Login_Attempts(caller.user_id);

                    }
                    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);
                    }

                    caller.user_login_attempts++;
                    string tempStr = string.Format(Resources.Login.ERROR_PASSWD_ERROR_TIMES, caller.user_login_attempts, 5);//後台登入改為5次 edit by shuangshuang0420j 201504101555 from hill

                    notice = "{result:'Error',msg:'" + tempStr + "'}";
                    ViewBag.notice = notice;

                    ViewBag.challenge_id = callerMgr.Add_Challenge();
                    ViewBag.challenge_key = callerMgr.Get_Challenge_Key(ViewBag.challenge_id);
                    //後台登入改為5次并計入UserLoginAttempts表 edit by shuangshuang0420j 201504101555 from hill
                    UserLoginAttempts ula = new UserLoginAttempts();
                    ula.login_mail = caller.user_email;
                    ula.login_ipfrom = CommonFunction.GetIP4Address(Request.UserHostAddress.ToString());
                    ula.login_type = 3;
                    ulaMgr.Insert(ula);
                    if (caller.user_login_attempts >= 5)//後台登入改為5次 edit by shuangshuang0420j 201504101555 from hill
                    {
                        try
                        {
                            callerMgr.Modify_User_Status(caller.user_id, 2);
                        }
                        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 (IsRemember == "true")
                    {
                        ViewBag.LoginEmail = email;
                    }

                    return View("Index");
                }

                if (caller.user_status == 0)
                {
                    notice = "{result:'Notice',msg:'" + Resources.Login.NOTICE_FIRST_LOGIN + "'}";
                    ViewBag.notice = notice;
                    ViewBag.isFirst = 1;
                    ViewBag.uid = caller.user_id;
                    ViewBag.email = caller.user_email;
                    return View("ChangePasswd");
                }

                try
                {
                    //添加登錄記錄
                    callerMgr.Add_Manage_Login(caller.user_id);

                    //修改登入數據
                    callerMgr.Modify_User_Login_Data(caller.user_id);
                }
                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);
                }

                caller.user_password = "";

                try
                {
                    string xmlPath = ConfigurationManager.AppSettings["SiteConfig"];//XML的設置
                    string path = Server.MapPath(xmlPath);
                    SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
                    string APIServer = _siteConfigMgr.GetConfigByName("APIServer").Value;


                    GigadeApiRequest request = new GigadeApiRequest(APIServer);

                    var result = request.Request<SuppliersLoginViewModel, SuppliersLoginResult>("api/admin/account/login",
                         new SuppliersLoginViewModel() { user_email = email, user_password = newpasswd, user_halfToken = challenge_key, login_ipfrom = CommonFunction.GetIP4Address(Request.UserHostAddress.ToString()) });
                    var back = result.result;
                    Session["AccessToken"] = back.userToken.user_token;
                }
                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);
                }
                

                Session["caller"] = caller;
                return Redirect("../home");

            }

        }
Esempio n. 2
0
        public HttpResponseBase GetUploadArchives()
        {
            string json = string.Empty;

            try
            {
                #region 上傳

                string ErrorMsg = string.Empty;
                string path = Server.MapPath(xmlPath);
                SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
                SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format");
                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 fileName = string.Empty;//當前文件名

                _ITicketDetail = new TicketDetailMgr(mySqlConnectionString);
                FileManagement fileLoad = new FileManagement();
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase file = Request.Files[0];

                    string fileExtention = string.Empty;//當前文件的擴展名
                    string oldFileName = file.FileName.Substring(0, file.FileName.LastIndexOf('.'));
                    fileName = fileLoad.NewFileName(file.FileName);

                    if (fileName != "")
                    {
                        string filepathday = fileName.Substring(0, fileName.LastIndexOf("."));//每天建立一個文件夾保存村的文件;

                        fileName = oldFileName + "_" + filepathday;//上傳文檔為以前的名字+年月日時分秒.後綴名
                        filepathday = filepathday.Substring(0, 8);
                        fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString();
                        // string NewFileName = string.Empty;

                        BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                        // NewFileName = hash.Md5Encrypt(fileName, "32");
                        string ServerPath = string.Empty;
                        FTP f_cf = new FTP();
                        archives = archives + filepathday + "/";//創建多層路徑
                        string localPromoPath = imgLocalPath + archives;//圖片存儲地址
                        f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - archives.Length + 1), archives.Substring(1, archives.Length - 2).Split('/'), ftpuser, ftppwd);
                        // fileName = NewFileName + fileExtention;
                        fileName = localPromoPath + fileName + fileExtention;//絕對路徑
                        ServerPath = Server.MapPath(imgLocalServerPath + archives);

                        Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件
                        bool result = _ITicketDetail.UpLoadFile(file, ServerPath, fileName, extention, (int.MaxValue / 1024) - 1, 0, ref ErrorMsg, ftpuser, ftppwd);
                        if (result)
                        {
                            json = "{\"success\":\"true\"}";
                        }
                        else
                        {
                            json = "{\"success\":\"false\",\"msg\":\"上傳失败\"}";

                        }

                    }

                }
                #endregion

            }
            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\",\"msg\":\"參數出錯\"}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase SavePromotionsAmountDiscountTwo()
        {
            try
            {
                string jsonStr = string.Empty;
                PromotionsAmountDiscount model = new PromotionsAmountDiscount();
                ProductCategory pmodel = new ProductCategory();
                int isTryInt = 0;
                #region 獲取新增時promotionamountdiscount和productcategory model值
                if (!string.IsNullOrEmpty(Request.Params["pid"].ToString()))
                {
                    model.id = Convert.ToInt32(Request.Params["pid"].ToString());
                }

                PromotionsAmountDiscountCustom oldermodel = _promoAmountDiscountMgr.GetModelById(model.id);
                model.category_id = oldermodel.category_id;
                pmodel.category_id = Convert.ToUInt32(oldermodel.category_id);

                ProductCategory olderpcmodel = _produCateMgr.GetModelById(pmodel.category_id);

                PromotionsAmountDiscountCustom pacdModel = new PromotionsAmountDiscountCustom();
                pacdModel.id = model.id;
                pacdModel.category_id = model.category_id;

                if (!string.IsNullOrEmpty(Request.Params["name"].ToString()))
                {
                    pacdModel.name = Request.Params["name"].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["desc"].ToString()))
                {
                    pacdModel.event_desc = Request.Params["desc"].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["e_type"].ToString()))
                {
                    pacdModel.event_type = Request.Params["e_type"].ToString();
                }
                pacdModel.event_id = CommonFunction.GetEventId(pacdModel.event_type.ToString(), pacdModel.id.ToString());
                if (!string.IsNullOrEmpty(Request.Params["url_by"].ToString()))
                {
                    pacdModel.url_by = Convert.ToInt32(Request.Params["url_by"].ToString());
                }
                else
                {
                    pacdModel.url_by = oldermodel.url_by;
                }
                if (pacdModel.url_by == 1)
                {

                    #region 上傳圖片

                    try
                    {
                        if (Request.Files.Count != 0)
                        {
                            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_MinValue");
                            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;//圖片存儲地址
                            //生成隨機數,用於圖片的重命名
                            Random rand = new Random();
                            int newRand = rand.Next(1000, 9999);



                            //獲取上傳的圖片
                            HttpPostedFileBase file = Request.Files[0];
                            string fileName = string.Empty;//當前文件名
                            string fileExtention = string.Empty;//當前文件的擴展名

                            fileName = Path.GetFileName(file.FileName);
                            if (!string.IsNullOrEmpty(fileName))
                            {
                                bool result = false;
                                string NewFileName = string.Empty;

                                fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                                NewFileName = pacdModel.event_id + newRand + fileExtention;//圖片重命名為event_id+4位隨機數+擴展名

                                string ServerPath = string.Empty;
                                //判斷目錄是否存在,不存在則創建
                                CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'));

                                //  returnName += promoPath + NewFileName;
                                fileName = NewFileName;
                                NewFileName = localPromoPath + NewFileName;//絕對路徑
                                ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                                string ErrorMsg = string.Empty;

                                //上傳之前刪除已有的圖片
                                string oldFileName = olderpcmodel.banner_image;
                                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);//刪除ftp:71.159上的舊圖片
                                    //DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                                }
                                try
                                {
                                    //上傳
                                    FileManagement fileLoad = new FileManagement();
                                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                    if (result)//上傳成功
                                    {
                                        pacdModel.banner_image = fileName;
                                    }

                                }
                                catch (Exception ex)
                                {
                                    Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                                    logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name + "->fileLoad.UpLoadFile()", ex.Source, ex.Message);
                                    logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                                    log.Error(logMessage);
                                    jsonStr = "{success:false,msg:'圖片上傳失敗'}";

                                    pacdModel.banner_image = olderpcmodel.banner_image;
                                }
                            }
                            else
                            {
                                pacdModel.banner_image = olderpcmodel.banner_image;
                            }
                        }

                    }
                    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);
                        jsonStr = "{success:false,msg:'圖片上傳失敗'}";

                        pacdModel.banner_image = olderpcmodel.banner_image;
                    }


                    #endregion

                    if (!string.IsNullOrEmpty(Request.Params["banner_url"].ToString()))//存連接地址
                    {
                        pacdModel.category_link_url = Request.Params["banner_url"].ToString();
                    }
                    else
                    {
                        pacdModel.category_link_url = olderpcmodel.category_link_url;
                    }

                    if (!string.IsNullOrEmpty(Request.Params["sbrand_id"].ToString()))
                    {
                        int brandTranId = 0;
                        if (int.TryParse(Request.Params["sbrand_id"].ToString(), out brandTranId))
                        {
                            pacdModel.brand_id = Convert.ToInt32(Request.Params["sbrand_id"].ToString());
                        }
                        else
                        {
                            pacdModel.brand_id = oldermodel.brand_id;
                        }
                    }
                    else
                    {
                        pacdModel.brand_id = 0;
                    }


                    if (!string.IsNullOrEmpty(Request.Params["sclass_id"].ToString()))
                    {
                        int classTranId = 0;
                        if (int.TryParse(Request.Params["sclass_id"].ToString(), out classTranId))
                        {
                            pacdModel.class_id = Convert.ToInt32(Request.Params["sclass_id"].ToString());

                        }
                        else
                        {
                            pacdModel.class_id = oldermodel.class_id;
                        }
                    }
                    else
                    {
                        pacdModel.class_id = 0;
                    }
                    if (Request.Params["allClass"].ToString() == "1")//是否全館
                    {
                        string allClass = Request.Params["allClass"];
                        pacdModel.brand_id = 0;
                        pacdModel.class_id = 0;
                        pacdModel.product_id = 999999;


                    }
                }
                else
                {
                    //刪除上傳的圖片
                    //string oldFileName = olderpcmodel.banner_image;
                    //FTP ftp = new FTP(imgLocalPath + promoPath, ftpuser, ftppwd);
                    //List<string> tem = ftp.GetFileList();
                    //if (tem.Contains(oldFileName))
                    //{
                    //FTP ftps = new FTP(imgLocalPath + promoPath + oldFileName, ftpuser, ftppwd);
                    //ftps.DeleteFile(imgLocalPath + promoPath + oldFileName);//刪除ftp:71.159上的舊圖片
                    // DeletePicFile(Server.MapPath(imgLocalServerPath + promoPath) + oldFileName);//刪除本地圖片
                    // }

                    pacdModel.banner_image = "";
                    pacdModel.category_link_url = "";
                    if (!string.IsNullOrEmpty(Request.Params["noclass_id"]) && int.TryParse(Request.Params["noclass_id"].ToString(), out isTryInt))
                    {
                        pacdModel.class_id = Convert.ToInt32(Request.Params["noclass_id"]);
                    }
                    else
                    {
                        pacdModel.class_id = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["nobrand_id"]) && int.TryParse(Request.Params["nobrand_id"].ToString(), out isTryInt))
                    {
                        pacdModel.brand_id = Convert.ToInt32(Request.Params["nobrand_id"]);
                    }
                    else
                    {
                        pacdModel.brand_id =0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["product_id"]))
                    {
                        pacdModel.product_id = Convert.ToInt32(Request.Params["product_id"]);
                    }
                    else
                    {
                        pacdModel.product_id = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["no_allClass"]))
                    {
                        if (Request.Params["no_allClass"].ToString() == "1")//是否全館
                        {
                            string allClass = Request.Params["no_allClass"];
                            pacdModel.brand_id = 0;
                            pacdModel.class_id = 0;
                            pacdModel.product_id = 999999;


                        }
                    }
                    if (!string.IsNullOrEmpty(Request.Params["no_amount"]))
                    {
                        pacdModel.amount = Convert.ToInt32(Request.Params["no_amount"]);
                    }
                    else
                    {
                        pacdModel.amount = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["no_discount"]))
                    {
                        pacdModel.discount = Convert.ToInt32(Request.Params["no_discount"]);
                    }
                    else
                    {
                        pacdModel.discount = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["no_quantity"]))
                    {
                        pacdModel.quantity = Convert.ToInt32(Request.Params["no_quantity"]);
                    }
                    else
                    {
                        pacdModel.quantity = 0;
                    }
                }
                if (Request.Params["group_id"].ToString() != "")
                {
                    int groupTryId = 0;
                    if (!string.IsNullOrEmpty(Request.Params["group_id"].ToString()) && int.TryParse(Request.Params["group_id"].ToString(), out groupTryId))
                    {
                        pacdModel.group_id = Convert.ToInt32(Request.Params["group_id"].ToString());

                    }
                    else
                    {
                        pacdModel.group_id = oldermodel.group_id;
                    }
                    if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0")
                    {
                        UserCondition uc = new UserCondition();
                        uc.condition_id = Convert.ToInt32(Request.Params["condition_id"]);
                        if (_ucMgr.Delete(uc) > 0)
                        {

                            jsonStr = "{success:true}";
                        }
                        else
                        {
                            jsonStr = "{success:false,msg:'user_condition delete failure!'}";
                            this.Response.Clear();
                            this.Response.Write(jsonStr.ToString());
                            this.Response.End();
                            return this.Response;
                        }
                    }
                    pacdModel.condition_id = 0;
                }
                else
                {
                    if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0")
                    {
                        if (!string.IsNullOrEmpty(Request.Params["condition_id"].ToString()))//condition_id
                        {
                            pacdModel.condition_id = Convert.ToInt32(Request.Params["condition_id"].ToString());
                        }
                        else
                        {
                            pacdModel.condition_id = oldermodel.condition_id;
                        }
                        pacdModel.group_id = 0;
                    }
                }


                if (!string.IsNullOrEmpty(Request.Params["devicename"].ToString()))//device
                {
                    pacdModel.device = Convert.ToInt32(Request.Params["devicename"].ToString());
                }
                else
                {
                    pacdModel.device = oldermodel.device;
                }
                if (!string.IsNullOrEmpty(Request.Params["start_date"].ToString()))//start
                {
                    pacdModel.start = Convert.ToDateTime(Request.Params["start_date"].ToString());
                }
                else
                {
                    pacdModel.start = oldermodel.date_state;
                }
                if (!string.IsNullOrEmpty(Request.Params["end_date"].ToString()))//end
                {
                    pacdModel.end = Convert.ToDateTime(Request.Params["end_date"].ToString());
                }
                else
                {
                    pacdModel.end = oldermodel.date_end;
                }

                if (!string.IsNullOrEmpty(Request.Params["site"].ToString()))//修改時傳的值為siteName
                {
                    string site = Request.Params["site"].ToString();
                    Regex reg = new Regex("^([0-9]+,)*[0-9]+$");
                    if (reg.IsMatch(site))
                    {
                        pacdModel.site = site;// 將站台改為多選 edit by shuangshuang0420j 20140925 10:08
                    }
                    else
                    {
                        if (site.LastIndexOf(',') == site.Length - 1)//最後一個字符為,時
                        {
                            pacdModel.site = site.Substring(0, site.Length - 1);

                        }

                    }
                }

                if (!string.IsNullOrEmpty(Request.Params["vendor_coverage"].ToString()))//vendor_coverage
                {
                    pacdModel.vendor_coverage = Convert.ToInt32(Request.Params["vendor_coverage"].ToString());
                }
                else
                {
                    pacdModel.vendor_coverage = oldermodel.vendor_coverage;
                }
                //獲取pacdModel.category_father_id
                List<Parametersrc> fatherIdResult = _parasrcMgr.QueryUsed(new Parametersrc { ParameterType = "event_type", Used = 1, ParameterCode = pacdModel.event_type });
                if (fatherIdResult.Count > 0)
                {
                    pacdModel.category_father_id = Convert.ToUInt32(fatherIdResult[0].ParameterProperty);
                }
                pacdModel.active = false;
                pacdModel.category_updatedate = (uint)BLL.gigade.Common.CommonFunction.GetPHPTime();
                pacdModel.status = 1;
                pacdModel.category_ipfrom = Request.UserHostAddress;
                #endregion
                if (Request.Params["type"].ToString() == "Add")
                {
                    pacdModel.kuser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                    pacdModel.created = DateTime.Now;
                    pacdModel.muser = pacdModel.kuser;
                    pacdModel.modified = pacdModel.created;
                    return AddPromotionsAmountDiscount(pacdModel);
                }
                else
                {

                    pacdModel.kuser = oldermodel.kuser;
                    pacdModel.created = oldermodel.created;
                    pacdModel.muser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                    pacdModel.modified = DateTime.Now;
                    return UpdatePromotionsAmountDiscount(pacdModel, CommonFunction.GetEventId(oldermodel.event_type.ToString(), oldermodel.id.ToString()));
                }
            }
            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("{success:false,msg:0}");
                this.Response.End();
                return this.Response;
            }

        }
        public HttpResponseBase ProductCommentSave()
        {
            string json = string.Empty;
            int send_mail = 1;
            int isSave = 0;//保存未成功
            ProductCommentQuery query = new ProductCommentQuery();
            try
            {
                string path = Server.MapPath(xmlPath);
                SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
                SiteConfig Mail_From = _siteConfigMgr.GetConfigByName("Mail_From");
                SiteConfig Mail_Host = _siteConfigMgr.GetConfigByName("Mail_Host");
                SiteConfig Mail_Port = _siteConfigMgr.GetConfigByName("Mail_Port");
                SiteConfig Mail_UserName = _siteConfigMgr.GetConfigByName("Mail_UserName");
                SiteConfig Mail_UserPasswd = _siteConfigMgr.GetConfigByName("Mail_UserPasswd");
                string EmailFrom = Mail_From.Value;//發件人郵箱
                string SmtpHost = Mail_Host.Value;//smtp服务器
                string SmtpPort = Mail_Port.Value;//smtp服务器端口
                string EmailUserName = Mail_UserName.Value;//郵箱登陸名
                string EmailPassWord = Mail_UserPasswd.Value;//郵箱登陸密碼

                ProductCommentQuery store = new ProductCommentQuery();
                _proCommentImpl = new ProductCommentMgr(mySqlConnectionString);
                if (!string.IsNullOrEmpty(Request.Params["comment_id"]))
                {
                    query.comment_id = Convert.ToInt32(Request.Params["comment_id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["comment_answer"]))
                {
                    query.comment_answer = Request.Params["comment_answer"];
                    query.comment_answer = query.comment_answer.Replace("\\", "\\\\");
                }
                if (!string.IsNullOrEmpty(Request.Params["comment_answer"]))
                {
                    query.old_comment_answer = Request.Params["old_comment_answer"];
                    query.old_comment_answer = query.old_comment_answer.Replace("\\", "\\\\");
                }
                if (!string.IsNullOrEmpty(Request.Params["answer_is_show"]))
                {
                    query.answer_is_show = Convert.ToInt32(Request.Params["answer_is_show"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["old_answer_is_show"]))
                {
                    query.old_answer_is_show = Request.Params["old_answer_is_show"].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["isReplay"]))
                {
                    if (Convert.ToInt32(Request.Params["isReplay"]) == 1)
                    {
                        query.old_answer_is_show = string.Empty;
                    }
                }

                if (!string.IsNullOrEmpty(Request.Params["comment_detail_id"]))
                {
                    query.comment_detail_id = Convert.ToInt32(Request.Params["comment_detail_id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["send_mail"]))
                {
                    send_mail = Convert.ToInt32(Request.Params["send_mail"]);//0 發送  1 不發送
                    query.send_mail = Convert.ToInt32(Request.Params["send_mail"]);//0 發送  1 不發送 2 發送失敗
                }
                query.reply_user = (Session["caller"] as Caller).user_id;
                store = _proCommentImpl.GetUsetInfo(query);
                string user_email = store.user_email;
                string user_name = store.user_name;
                string product_name = store.product_name;
                string comment_info = store.comment_info;
                if (_proCommentImpl.ProductCommentSave(query) > 0)
                {

                    json = "{success:'true',msg:'0'}";//保存成功,但不發送郵件
                    isSave = 1;//指示保存成功
                    if (send_mail == 0)
                    {
                        FileStream fs = new FileStream(Server.MapPath("../ImportUserIOExcel/CommentReplay.html"), FileMode.OpenOrCreate, FileAccess.Read);
                        StreamReader sr = new StreamReader(fs, Encoding.UTF8);
                        string strTemp = sr.ReadToEnd();
                        sr.Close();
                        fs.Close();
                        //[email protected]
                        strTemp = strTemp.Replace("{{$username$}}", user_name);
                        strTemp = strTemp.Replace("{{$productName$}}", product_name);
                        strTemp = strTemp.Replace("{{$commentAnwser$}}", Request.Params["comment_answer"]);
                        strTemp = strTemp.Replace("{{$commentInfo$}}", comment_info);
                        if (sendmail(EmailFrom, FromName, user_email, user_name, EmailTile, strTemp, "", SmtpHost, Convert.ToInt32(SmtpPort), EmailUserName, EmailPassWord))
                        {
                            json = "{success:'true',msg:'1'}";//保存成功,郵件發送成功! 
                        }
                        else
                        {
                            json = "{success:'true',msg:'2'}";//保存成功,郵件發送失敗!
                            query.send_mail = 2;
                            _proCommentImpl.ProductCommentSave(query);
                        }
                    }
                }
                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);
                if (isSave == 1)//保存成功,可能郵件發送失敗!
                {
                    json = "{success:'true',msg:'2'}";//保存成功,郵件發送失敗!
                    query.send_mail = 2;
                    _proCommentImpl.ProductCommentSave(query);

                }
                else//保存失敗
                {
                    json = "{success:'false'}";
                }

            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Esempio n. 5
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}";
            }
        }
Esempio n. 6
0
        public HttpResponseBase update()
        {
            string path = Server.MapPath(xmlPath);
            SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
            SiteConfig Mail_From = _siteConfigMgr.GetConfigByName("Mail_From");
            SiteConfig Mail_Host = _siteConfigMgr.GetConfigByName("Mail_Host");
            SiteConfig Mail_Port = _siteConfigMgr.GetConfigByName("Mail_Port");
            SiteConfig Mail_UserName = _siteConfigMgr.GetConfigByName("Mail_UserName");
            SiteConfig Mail_UserPasswd = _siteConfigMgr.GetConfigByName("Mail_UserPasswd");
            string EmailFrom = Mail_From.Value;//發件人郵箱
            string SmtpHost = Mail_Host.Value;//smtp服务器
            string SmtpPort = Mail_Port.Value;//smtp服务器端口
            string EmailUserName = Mail_UserName.Value;//郵箱登陸名
            string EmailPassWord = Mail_UserPasswd.Value;//郵箱登陸密碼
            string jsonStr = String.Empty;
            int result = 0;
            ContactUsQuestion cusTion = new ContactUsQuestion();
            ContactUsResponse cusponse = new ContactUsResponse();
            SmsQuery smsquery = new SmsQuery();
            try
            {
                _ctactMgr = new ContactUsQuestionMgr(mySqlConnectionString);
                _ctactrsponseMgr = new ContactUsResponseMgr(mySqlConnectionString);
                if (!string.IsNullOrEmpty(Request.Params["question_id"]))
                {
                    cusTion.question_id = Convert.ToUInt32(Request.Params["question_id"]);
                    smsquery.serial_id = Convert.ToInt32(cusTion.question_id);
                }
                if (Convert.ToBoolean(Request.Params["state1"]) == true)
                {
                    cusTion.question_status = 1;//1表示已經回覆
                }
                else if (Convert.ToBoolean(Request.Params["state2"]) == true)
                {
                    cusTion.question_status = 1;//1表示已經回覆
                }
                else if (Convert.ToBoolean(Request.Params["state3"]) == true)
                {
                    cusTion.question_status = 2;//2表示已經回覆
                }
                string updatesql = _ctactMgr.UpdateSql(cusTion);
                string questiontime = string.Empty;
                if (!string.IsNullOrEmpty(Request.Params["question_createdate"]))
                {
                    questiontime = Request.Params["question_createdate"];//提問問題時間 
                }
                if (!string.IsNullOrEmpty(Request.Params["question_phone"]))
                {
                    smsquery.mobile = Request.Params["question_phone"];//提問者電話
                }
                if (!string.IsNullOrEmpty(Request.Params["question_content"]))
                {
                    cusTion.question_content = Request.Params["question_content"];//咨詢問題內容
                }
                if (!string.IsNullOrEmpty(Request.Params["question_username"]))
                {
                    cusTion.question_username = Request.Params["question_username"];//提問問題用戶名
                }
                cusponse.response_id = Convert.ToUInt32(_ctactrsponseMgr.GetMaxResponseId());
                if (!string.IsNullOrEmpty(Request.Params["question_id"]))
                {
                    cusponse.question_id = Convert.ToUInt32(Request.Params["question_id"]);//咨詢問題id
                }
                cusponse.user_id = Convert.ToUInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id);
                if (!string.IsNullOrEmpty(Request.Params["content_reply"]))
                {
                    cusponse.response_content = Request.Params["content_reply"].Replace("\\", "\\\\");
                    smsquery.content = Request.Params["content_reply"].ToString().Replace("\\", "\\\\");//保存sms表的數據

                }
                bool reply1 = false;
                bool reply2 = false;
                bool reply3 = false;
                if (!string.IsNullOrEmpty(Request.Params["reply1"]))
                {
                    reply1 = Convert.ToBoolean(Request.Params["reply1"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["reply2"]))
                {
                    reply2 = Convert.ToBoolean(Request.Params["reply2"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["reply3"]))
                {
                    reply3 = Convert.ToBoolean(Request.Params["reply3"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["question_email"]))
                {
                    cusTion.question_email = Request.Params["question_email"].ToString().Trim();
                }
                cusponse.response_createdate = Convert.ToInt32(CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                cusponse.response_ipfrom = CommonFunction.GetIP4Address(Request.UserHostAddress.ToString());
                if (cusTion.question_status != 2)
                {
                    //mh.SendToUser(Convert.ToInt32(cusponse.user_id),"郵箱標題","郵箱內容");//發送郵件
                    if (reply1 || !reply3 && !reply2 && !reply1)
                    {//當email被勾選
                        cusponse.response_type = 1;
                        _ctactrsponseMgr.Insert(updatesql, cusponse);
                        FileStream fs = new FileStream(Server.MapPath("../ImportUserIOExcel/ContactUsQuestionResponse.html"), FileMode.OpenOrCreate, FileAccess.Read);
                        StreamReader sr = new StreamReader(fs, Encoding.UTF8);
                        string strTemp = sr.ReadToEnd();
                        sr.Close();
                        fs.Close();
                        strTemp = strTemp.Replace("{{$s_datetime$}}", questiontime);
                        strTemp = strTemp.Replace("{{$s_username$}}", cusTion.question_username);
                        strTemp = strTemp.Replace("{{$consultInfo$}}", cusTion.question_content);
                        strTemp = strTemp.Replace("{{$consultAnwser$}}", cusponse.response_content.Replace("\\\\", "\\"));
                        sendmail(EmailFrom, FromName, cusTion.question_email, cusTion.question_username, EmailTile, strTemp, "", SmtpHost, Convert.ToInt32(SmtpPort), EmailUserName, EmailPassWord);
                    }
                    else if (reply2)
                    {//當簡訊被勾選
                        cusponse.response_id = Convert.ToUInt32(_ctactrsponseMgr.GetMaxResponseId());
                        smsquery.type = 10;//10表示聯絡客服列表保存過去的
                        smsquery.send = 0;
                        smsquery.trust_send = "8";
                        smsquery.created = DateTime.Now;
                        smsquery.modified = DateTime.Now;
                        cusponse.response_type = 2;
                        _ctactrsponseMgr.Insert(updatesql, cusponse);
                        _ISmsMgr = new SmsMgr(mySqlConnectionString);
                        _ISmsMgr.InsertSms(smsquery);
                    }
                    else if (reply3)
                    {//當電話被勾選
                        cusponse.response_id = Convert.ToUInt32(_ctactrsponseMgr.GetMaxResponseId());
                        cusponse.response_type = 3;
                        _ctactrsponseMgr.Insert(updatesql, cusponse);
                    }
                    //if (!reply3 && !reply2 && !reply1)
                    //{
                    //    cusponse.response_id = Convert.ToUInt32(_ctactrsponseMgr.GetMaxResponseId());
                    //    cusponse.response_type = 4;
                    //    _ctactrsponseMgr.Insert(updatesql, cusponse);
                    //}
                    jsonStr = "{success:true}";
                }
                else//等於2時,已處理,不操作其它
                {
                    cusponse.response_id = 4;
                    result = _ctactrsponseMgr.Insert(updatesql, cusponse);
                    if (result > 0)
                    {
                        jsonStr = "{success:true}";
                    }
                    else
                    {
                        jsonStr = "{success:false}";
                    }
                    DateTime today = DateTime.Now;
                    DateTime a = DateTime.Now.AddDays(-5);


                }

            }
            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);
                jsonStr = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(jsonStr.ToString());
            this.Response.End();
            return this.Response;
        }
        /// <summary>
        /// 會員活動新增編輯
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase SaveMemberEvent()
        {
            string json = string.Empty;
            try
            {
                MemberEventQuery query = new MemberEventQuery();
                _memberEvent = new MemberEventMgr(mySqlConnectionString);
                if (!string.IsNullOrEmpty(Request.Params["rowID"]))
                {
                    query.rowID = int.Parse(Request.Params["rowID"]);
                }
                query.me_name = Request.Params["me_name"];
                query.me_desc = Request.Params["me_desc"];
                query.event_id = Request.Params["event_id"];

                if (!string.IsNullOrEmpty(Request.Params["me_startdate"]))
                {
                    query.me_startdate = DateTime.Parse(Request.Params["me_startdate"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["me_enddate"]))
                {
                    query.me_enddate = DateTime.Parse(Request.Params["me_enddate"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["me_birthday"]))
                {
                    //query.me_birthday = int.Parse(Request.Params["me_birthday"]);
                    if (Request.Params["me_birthday"] == "1")
                    {
                        query.me_birthday = 1;
                    }
                    else
                    {
                        query.me_birthday = 0;
                    }
                }
                if (!string.IsNullOrEmpty(Request.Params["me_bonus_onetime"]))
                {
                    if (Request.Params["me_bonus_onetime"] == "1")
                    {
                        query.me_bonus_onetime = 1;
                    }
                    else
                    {
                        query.me_bonus_onetime = 0;
                    }
                }
                if (!string.IsNullOrEmpty(Request.Params["me_banner_link"]))
                {
                    query.me_banner_link = Request.Params["me_banner_link"];
                }
                if (!string.IsNullOrEmpty(Request.Params["code"]))
                {
                    query.ml_code = Request.Params["code"].TrimEnd(',');
                }
                else
                {
                    query.ml_code = "0";
                }
                if (!string.IsNullOrEmpty(Request.Params["et_id"]))
                {
                    query.et_id = int.Parse(Request.Params["et_id"]);
                }
                //query.et_name = Request.Params["et_name"];
                switch (Request.Params["et_name"])
                {
                    case "1":
                        query.et_name = "DD";
                        query.et_date_parameter = "";
                        break;
                    case "2":
                        query.et_name = "WW";
                        if (!string.IsNullOrEmpty(Request.Params["week"]))
                        {
                            query.et_date_parameter = Request.Params["week"].TrimEnd(',');
                        }
                        break;
                    case "3":
                        query.et_name = "MM";
                        if (!string.IsNullOrEmpty(Request.Params["month"]))
                        {
                            query.et_date_parameter = Request.Params["month"].TrimEnd(',');
                        }
                        break;
                }

                #region 處理每天的開始結束時間
                query.et_starttime = Request.Params["et_starttime"];
                query.et_endtime = Request.Params["et_endtime"];

                #endregion
                query.k_user = (Session["caller"] as Caller).user_id;
                query.m_user = (Session["caller"] as Caller).user_id;
                query.k_date = DateTime.Now;
                query.m_date = query.k_date;
                string event_json=_memberEvent.IsGetEventID(query.event_id);
                if (event_json.IndexOf("true") > 0)
                {
                    #region 判斷數據不能重複
                    if (_memberEvent.IsRepeat(query))//不重複
                    {

                        #region 上傳圖片


                        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 localMemberEventPath = imgLocalPath + MemberEventPath;//圖片存儲地址
                        FileManagement fileLoad = new FileManagement();
                        int totalCount = 0;
                        MemberEventQuery oldQuery = _memberEvent.Query(new MemberEventQuery { rowID = query.rowID }, out totalCount).FirstOrDefault();
                        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;
                                BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                                NewFileName = hash.Md5Encrypt(fileName, "32");
                                string[] dirPath = new string[2];
                                //dirPath[0] = NewFileName.Substring(0, 2)+"/";
                                //dirPath[1] = NewFileName.Substring(2, 2)+"/";
                                string ServerPath = string.Empty;
                                FTP f_cf = new FTP();
                                CreateFolder(localMemberEventPath, dirPath);
                                fileName = NewFileName + fileExtention;
                                NewFileName = localMemberEventPath + NewFileName + fileExtention;//絕對路徑
                                ServerPath = Server.MapPath(imgLocalServerPath + MemberEventPath);
                                string ErrorMsg = string.Empty;
                                //上傳之前刪除已有的圖片
                                if (query.rowID != 0)
                                {

                                    if (oldQuery.me_big_banner != "")
                                    {
                                        string oldFileName = oldQuery.me_big_banner;
                                        CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                                        FTP ftp = new FTP(localMemberEventPath, ftpuser, ftppwd);
                                        List<string> tem = ftp.GetFileList();
                                        if (tem.Contains(oldFileName))
                                        {
                                            FTP ftps = new FTP(localMemberEventPath + oldFileName, ftpuser, ftppwd);
                                            ftps.DeleteFile(localMemberEventPath + oldFileName);
                                        }
                                    }
                                }
                                try
                                {
                                    Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件
                                    bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                    if (result)
                                    {
                                        query.me_big_banner = 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();
                                    return this.Response;
                                }
                            }
                            else
                            {
                                query.me_big_banner = oldQuery.me_big_banner;
                            }
                        }
                        #endregion
                        if (_memberEvent.MemberEventSave(query) > 0)
                        {
                            //json = "{success:true}";
                            if (!string.IsNullOrEmpty(Request.Params["rowID"]))
                            {
                                json = "{success:true,msg:'修改成功!'}";
                            }
                            else
                            {
                                json = "{success:true,msg:'新增成功!'}";
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(Request.Params["rowID"]))
                            {
                                json = "{success:false,msg:'修改失敗!'}";
                            }
                            else
                            {
                                json = "{success:false,msg:'新增失敗!'}";
                            }
                        }

                    }
                    else
                    {
                        json = "{success:false,msg:'數據重複!'}";
                    }
                    #endregion
                }
                else
                {
                    json = "{success:false,msg:'促銷編號錯誤或促銷活動未啟用'}";
                }
                




            }
            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,msg:'異常!'}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Esempio n. 8
0
        public HttpResponseBase SaveManageUser()
        {
            string json = string.Empty;
            DataTable dt = new DataTable();
            bool isupdate = false;
            string password;
            try
            {
                #region 發送email設置
                string path = Server.MapPath(xmlPath);
                SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
                SiteConfig Mail_From = _siteConfigMgr.GetConfigByName("Mail_From");
                SiteConfig Mail_Host = _siteConfigMgr.GetConfigByName("Mail_Host");
                SiteConfig Mail_Port = _siteConfigMgr.GetConfigByName("Mail_Port");
                SiteConfig Mail_UserName = _siteConfigMgr.GetConfigByName("Mail_UserName");
                SiteConfig Mail_UserPasswd = _siteConfigMgr.GetConfigByName("Mail_UserPasswd");
                string EmailFrom = Mail_From.Value;//發件人郵箱
                string SmtpHost = Mail_Host.Value;//smtp服务器
                string SmtpPort = Mail_Port.Value;//smtp服务器端口
                string EmailUserName = Mail_UserName.Value;//郵箱登陸名
                string EmailPassWord = Mail_UserPasswd.Value;//郵箱登陸密碼
                #endregion
                _manageuserMgr = new ManageUserMgr(mySqlConnectionString);
                ManageUserQuery store = new ManageUserQuery();
                ManageUserQuery query = new ManageUserQuery();
                if (!string.IsNullOrEmpty(Request.Params["user_id"]))
                {//如果是編輯獲取該id數據
                    int totalCount = 0;
                    query.IsPage = false;
                    query.user_id = uint.Parse(Request.Params["user_id"]);
                    query.userid = Request.Params["user_id"];
                    query.search_status = "-1";
                    store = _manageuserMgr.GetManageUserList(query, out totalCount).FirstOrDefault();
                    isupdate = true;
                }
                if (!string.IsNullOrEmpty(Request.Params["user_username"]))
                {
                    query.user_username = Request.Params["user_username"];
                }
                if (!string.IsNullOrEmpty(Request.Params["user_email"]))
                {
                    query.user_email = Request.Params["user_email"];
                    if (store != null)
                    {
                        if (store.user_email == query.user_email)
                        {//如果編輯沒有變email就空值
                            query.user_email = string.Empty;
                        }
                    }
                }
                if (!string.IsNullOrEmpty(Request.Params["erp_id"]))
                {
                    query.erp_id = Request.Params["erp_id"];
                }
                if (!string.IsNullOrEmpty(Request.Params["user_status"]))
                {
                    query.user_status = uint.Parse(Request.Params["user_status"]);
                }
                else
                {
                    query.user_status = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["manage"]))
                {
                    query.manage = uint.Parse(Request.Params["manage"]);
                }
                else
                {
                    query.manage = 0;
                }
                Random rd = new Random();
                password = CommonFunction.Getserials(8, rd);
                query.user_password = hmd5.SHA256Encrypt(password);
                query.user_lastvisit = uint.Parse(CommonFunction.GetPHPTime(DateTime.Now.ToString()).ToString());
                query.user_last_login = query.user_lastvisit;
                query.user_createdate = query.user_lastvisit;
                query.user_updatedate = query.user_lastvisit;
                if (_manageuserMgr.CheckEmail(query) > 0 && !string.IsNullOrEmpty(query.user_email))
                {//判斷新增編輯過得email數據庫是否有重複
                    json = "{success:true,msg:2}";
                }
                else
                {
                    if (isupdate)
                    {
                        #region 編輯
                        if (query.user_status == 3)
                        {
                            query.user_delete_email = query.user_email;
                            Random re = new Random();
                            query.user_email = DateTime.Now.ToString("yyyyMMddhhmmss") + hmd5.SHA256Encrypt(CommonFunction.Getdeleteemail(32, re));
                            if (_manageuserMgr.ManageUserUpd(query) > 0)
                            {
                                json = "{success:true,msg:1}";
                            }
                            else
                            {
                                json = "{success:false,msg:4}";
                            }
                        }
                        else
                        {
                            if (_manageuserMgr.ManageUserUpd(query) > 0)
                            {
                                json = "{success:true,msg:1}";
                            }
                            else
                            {
                                json = "{success:false,msg:4}";
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        #region 新增
                        if (_manageuserMgr.ManageUserAdd(query) > 0)
                        {
                            FileStream fs = new FileStream(Server.MapPath("../ImportUserIOExcel/901.html"), FileMode.OpenOrCreate, FileAccess.Read);
                            StreamReader sr = new StreamReader(fs, Encoding.UTF8);
                            string strTemp = sr.ReadToEnd();
                            sr.Close();
                            fs.Close();
                            _paraMgr = new ParameterMgr(mySqlConnectionString);
                            string linkurl = string.Empty;
                            Parametersrc paModel = _paraMgr.QueryUsed(new Parametersrc { ParameterType = "admin_link_url" }).FirstOrDefault();
                            if (paModel != null)
                            {
                                linkurl = paModel.ParameterCode;
                            }


                            strTemp = strTemp.Replace("{{$s_user_username$}}", query.user_username);
                            strTemp = strTemp.Replace("{{$u_admin_url$}}", linkurl);
                            strTemp = strTemp.Replace("{{$s_email$}}", query.user_email);
                            strTemp = strTemp.Replace("{{$s_password$}}", password);
                            if (CommonFunction.sendmail(EmailFrom, FromName, query.user_email, query.user_name, EmailTile, strTemp, "", SmtpHost, Convert.ToInt32(SmtpPort), EmailUserName, EmailPassWord))
                            {
                                json = "{success:true,msg:1}";
                            }
                            else
                            {
                                json = "{success:true,msg:3}";
                            }
                        }
                        else
                        {
                            json = "{success:false,msg:4}";
                        }
                        #endregion
                    }
                }
            }
            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,msg:'操作失敗!'}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
  public HttpResponseBase isCanModifyExpectArriveDate(string deliverId)
  {
      int deliver_id = Convert.ToInt32(Request.Params["deliver_id"]);
      string json = string.Empty;
 
      try
      {
          string xmlPath = ConfigurationManager.AppSettings["SiteConfig"];//XML的設置
          string path = Server.MapPath(xmlPath);
          SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
          _DeliverChangeLogMgr = new DeliverChangeLogMgr(mySqlConnectionString);
          string APIServer = _siteConfigMgr.GetConfigByName("APIServer").Value;
          bool isCanModify = _DeliverChangeLogMgr.isCanModifyExpertArriveDate(APIServer, deliver_id);
          if (isCanModify)//可以修改
          {
              json = "{success:true,msg:'1'}";
          }
          else 
          {
              json = "{success:true,msg:'0'}";
          }
      }
      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,msg:'請求失敗'}";
      }
      this.Response.Clear();
      this.Response.Write(json);
      this.Response.End();
      return this.Response;      
  }
Esempio n. 10
0
        public HttpResponseBase sendemail()
        {
            string path = Server.MapPath(xmlPath);
            SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
            SiteConfig Mail_From = _siteConfigMgr.GetConfigByName("Mail_From");
            SiteConfig Mail_Host = _siteConfigMgr.GetConfigByName("Mail_Host");
            SiteConfig Mail_Port = _siteConfigMgr.GetConfigByName("Mail_Port");
            SiteConfig Mail_UserName = _siteConfigMgr.GetConfigByName("Mail_UserName");
            SiteConfig Mail_UserPasswd = _siteConfigMgr.GetConfigByName("Mail_UserPasswd");
            string EmailFrom = Mail_From.Value;//發件人郵箱
            string SmtpHost = Mail_Host.Value;//smtp服务器
            string SmtpPort = Mail_Port.Value;//smtp服务器端口
            string EmailUserName = Mail_UserName.Value;//郵箱登陸名
            string EmailPassWord = Mail_UserPasswd.Value;//郵箱登陸密碼
            string json = string.Empty;//返回json數據
            int id = Convert.ToInt32(Request.Params["id"]);
            _uslmpgr = new UsersListMgr(mySqlConnectionString);

            BLL.gigade.Model.Custom.Users stores = new BLL.gigade.Model.Custom.Users();
            try
            {
                BLL.gigade.Model.Custom.Users query = new BLL.gigade.Model.Custom.Users();
                query.user_id = Convert.ToUInt32(id);
                stores = _uslmpgr.getModel(id);
                if (stores.user_actkey == "")
                {
                    stores.user_actkey = CommonFunction.Generate_Rand_String(8);
                }
                else
                {
                    stores.user_actkey = stores.user_actkey;
                }
                _uslmpgr.UpdateUser(stores); //更新user數據庫

                BLL.gigade.Model.Custom.Users urs = new BLL.gigade.Model.Custom.Users();
                urs = _uslmpgr.getModel(id);
                //發送郵件
                DateTime dt = DateTime.Now;//寄送時間
                // stores.user_id;會員編號
                //store.user_name;會員姓名
                //store.user_email;寄送地址
                //store.actkey 認證編號

                // bool state = sendemail("*****@*****.**", "12345", "Gigade郵件", "www.gigade100.com/member_join_ok.php?uid=" + stores.user_id + "&act_key=" + stores.user_actkey, urs.user_email);
                FileStream fs = new FileStream(Server.MapPath("../ImportUserIOExcel/MemberValidate.html"), FileMode.OpenOrCreate, FileAccess.Read);
                StreamReader sr = new StreamReader(fs, Encoding.UTF8);
                string strTemp = sr.ReadToEnd();
                sr.Close();
                fs.Close();
                strTemp = strTemp.Replace("{{$content$}}", "<a " + "href=" + "\"" + "www.gigade100.com/member_join_ok.php?uid=" + stores.user_id + "&act_key=" + stores.user_actkey + "\"" + ">" + "www.gigade100.com/member_join_ok.php?uid=" + stores.user_id + "&act_key=" + stores.user_actkey + "</a>");
                bool state = sendmail(EmailFrom, FromName, urs.user_email, urs.user_name, EmailTile, strTemp, "", SmtpHost, Convert.ToInt32(SmtpPort), EmailUserName, EmailPassWord);
                string time = CommonFunction.DateTimeToString(DateTime.Now);
                if (state == true)
                {
                    json = "{success:true,sendtime:'" + time + "',userid:'" + stores.user_id + "',username:'******',sendto:'" + stores.user_email + "',authenid:'" + stores.user_actkey + "'}";
                }
                else
                {
                    json = "{success:false,sendtime:'" + time + "',userid:'" + stores.user_id + "',username:'******',sendto:'" + stores.user_email + "',authenid:'" + stores.user_actkey + "'}";
                }
            }
            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.ToString());
            this.Response.End();
            return this.Response;
        }
Esempio n. 11
0
        public HttpResponseBase SaveElementDetaiil()
        {
            string resultJson = "{success:false}";
            ElementDetail model = new ElementDetail();
            ElementDetail oldModel = new ElementDetail();
            _detailMgr = new ElementDetailMgr(mySqlConnectionString);
            #region 獲取圖片信息
            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 localBannerPath = imgLocalPath + ElementPath;//圖片存儲地址

            #endregion
            if (!String.IsNullOrEmpty(Request.Params["element_id"]))//如果不存在該id說明是添加頁面
            {
                model.element_id = Convert.ToInt32(Request.Params["element_id"].ToString());
                oldModel = _detailMgr.GetModel(model);
            }
            #region 獲取數據
            int isTranInt = 0;
            //if (Int32.TryParse(Request.Params["element_area_id"].ToString(), out isTranInt))
            //{
            //    model.element_area_id = Convert.ToInt32(Request.Params["element_area_id"].ToString());
            //}
            //else
            //{
            //    model.element_area_id = oldModel.element_area_id;
            //}
            if (!string.IsNullOrEmpty(Request.Params["element_name"].ToString()))
            {
                model.element_name = Request.Params["element_name"].ToString();
            }
            else
            {
                model.element_name = oldModel.element_name;
            }
            if (!string.IsNullOrEmpty(Request.Params["packet_id"]))
            {
                model.packet_id = Convert.ToInt32(Request.Params["packet_id"]);
            }
            if (Int32.TryParse(Request.Params["element_type"].ToString(), out isTranInt))
            {
                model.element_type = Convert.ToInt32(Request.Params["element_type"]);
            }
            if (model.element_type == 1)
            {
                #region 上傳圖片
                try
                {
                    FileManagement fileLoad = new FileManagement();

                    //if (Request.Files.Count > 0)//單個圖片上傳
                    for (int iFile = 0; iFile < Request.Files.Count; iFile++)//多個上傳圖片
                    {
                        HttpPostedFileBase file = Request.Files[iFile];//單個Request.Files[0]
                        string fileName = string.Empty;//當前文件名
                        string fileExtention = string.Empty;//當前文件的擴展名
                        //獲取圖片名稱
                        fileName = fileLoad.NewFileName(file.FileName);
                        if (iFile == 0 && fileName == oldModel.element_content)
                        {
                            fileName = "";
                        }
                        if(iFile == 1 && string.IsNullOrEmpty(Request.Params["element_img_big"].ToString()) )
                        {
                            fileName = Request.Params["element_img_big"].ToString();
                        }
                        if (!String.IsNullOrEmpty(fileName))
                        {
                            fileName = fileName.Substring(0, fileName.LastIndexOf("."));
                            fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString();
                            string NewFileName = string.Empty;
                            BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                            NewFileName = hash.Md5Encrypt(fileName, "32");
                            string ServerPath = string.Empty;
                            //判斷目錄是否存在,不存在則創建
                            FTP f_cf = new FTP();
                            f_cf.MakeMultiDirectory(localBannerPath.Substring(0, localBannerPath.Length - ElementPath.Length + 1), ElementPath.Substring(1, ElementPath.Length - 2).Split('/'), ftpuser, ftppwd);

                            fileName = NewFileName + fileExtention;
                            NewFileName = localBannerPath + NewFileName + fileExtention;//絕對路徑
                            ServerPath = Server.MapPath(imgLocalServerPath + ElementPath);
                            string ErrorMsg = string.Empty;

                            //上傳之前刪除已有的圖片
                            if (model.element_id != 0)
                            {
                                string oldFileName = oldModel.element_content;
                                if (iFile == 1)
                                {
                                    oldFileName = oldModel.element_img_big;
                                }
                                CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                                FTP ftp = new FTP(localBannerPath, ftpuser, ftppwd);
                                List<string> tem = ftp.GetFileList();
                                if (tem.Contains(oldFileName))
                                {
                                    FTP ftps = new FTP(localBannerPath + oldFileName, ftpuser, ftppwd);
                                    ftps.DeleteFile(localBannerPath + oldFileName);//刪除ftp:71.159上的舊圖片
                                }
                            }
                            try
                            {
                                //上傳
                                Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件
                                bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                if (result)//上傳成功
                                {
                                    if (iFile == 0)
                                    {
                                        model.element_content = fileName;
                                    }
                                    else 
                                    {
                                        model.element_img_big = 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);
                                model.element_content = oldModel.element_content;
                            }
                            if (!string.IsNullOrEmpty(ErrorMsg))
                            {
                                if (iFile == 0)
                                {
                                    ErrorMsg = "元素圖 " + ErrorMsg;
                                }
                                else {
                                    ErrorMsg = "元素圖(大) " + ErrorMsg;
                                }
                                string json = string.Empty;
                                json = "{success:true,msg:\""+ ErrorMsg + "\"}";
                                this.Response.Clear();
                                this.Response.Write(json);
                                this.Response.End();
                                return this.Response;
                            }
                        }
                        else
                        {
                            if (iFile == 0)
                            {
                                model.element_content = oldModel.element_content;
                            }
                            else 
                            {
                                if (Request.Params["element_img_big"].ToString() == "")
                                {//編輯時如果傳過來空值則直接刪除
                                    model.element_img_big = "";
                                }
                                else
                                {
                                    model.element_img_big = oldModel.element_img_big;
                                }
                                //model.element_img_big = oldModel.element_img_big;
                            }
                        }
                    }
                }
                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);
                    model.element_content = oldModel.element_content;
                }
                #endregion
            }
            else if (model.element_type == 2)
            {
                if (!string.IsNullOrEmpty(Request.Params["element_content"].ToString()))
                {
                    model.element_content = Request.Params["element_content"].ToString();
                }
                else
                {
                    model.element_content = oldModel.element_content;
                }
            }
            else if (model.element_type == 3)
            {
                if (int.TryParse(Request.Params["element_product_id"].ToString(), out isTranInt))
                {
                    model.element_content = Request.Params["element_product_id"].ToString();
                }
                else
                {
                    model.element_content = oldModel.element_content;
                }
                #region 上傳圖片
                try
                {
                    FileManagement fileLoad = new FileManagement();
                    //if (Request.Files.Count > 0)//單個圖片上傳
                    for (int iFile = 1; iFile < Request.Files.Count; iFile++)//多個上傳圖片
                    {
                        HttpPostedFileBase file = Request.Files[iFile];//單個Request.Files[0]
                        string fileName = string.Empty;//當前文件名
                        string fileExtention = string.Empty;//當前文件的擴展名
                        //獲取圖片名稱
                        fileName = fileLoad.NewFileName(file.FileName);
                        if (!String.IsNullOrEmpty(fileName) && !String.IsNullOrEmpty(Request.Params["element_img_big"].ToString()))
                        {//可獲取文件,名稱不為空則變更圖片
                            fileName = fileName.Substring(0, fileName.LastIndexOf("."));
                            fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString();
                            string NewFileName = string.Empty;
                            BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                            NewFileName = hash.Md5Encrypt(fileName, "32");
                            string ServerPath = string.Empty;
                            //判斷目錄是否存在,不存在則創建
                            FTP f_cf = new FTP();
                            f_cf.MakeMultiDirectory(localBannerPath.Substring(0, localBannerPath.Length - ElementPath.Length + 1), ElementPath.Substring(1, ElementPath.Length - 2).Split('/'), ftpuser, ftppwd);

                            fileName = NewFileName + fileExtention;
                            NewFileName = localBannerPath + NewFileName + fileExtention;//絕對路徑
                            ServerPath = Server.MapPath(imgLocalServerPath + ElementPath);
                            string ErrorMsg = string.Empty;

                            //上傳之前刪除已有的圖片
                            if (model.element_id != 0)
                            {
                                string oldFileName = oldModel.element_img_big;
                                CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                                FTP ftp = new FTP(localBannerPath, ftpuser, ftppwd);
                                List<string> tem = ftp.GetFileList();
                                if (tem.Contains(oldFileName))
                                {
                                    FTP ftps = new FTP(localBannerPath + oldFileName, ftpuser, ftppwd);
                                    ftps.DeleteFile(localBannerPath + oldFileName);//刪除ftp:71.159上的舊圖片
                                }
                            }
                            try
                            {
                                //上傳
                                Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件
                                bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);                                
                                if (result)//上傳成功
                                {
                                    model.element_img_big = 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);
                                model.element_img_big = oldModel.element_img_big;
                            }
                            if (!string.IsNullOrEmpty(ErrorMsg))
                            {
                                ErrorMsg = "元素圖(大)" + ErrorMsg;
                                string json = string.Empty;
                                json = "{success:true,msg:\"" + ErrorMsg + "\"}";
                                this.Response.Clear();
                                this.Response.Write(json);
                                this.Response.End();
                                return this.Response;
                            }
                        }
                        else
                        {
                            if (Request.Params["element_img_big"].ToString() == "")
                            {//編輯時如果傳過來空值則直接刪除
                                model.element_img_big = "";
                            }
                            else
                            {
                                model.element_img_big = oldModel.element_img_big;
                            }
                        }
                    }
                }
                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);
                    model.element_img_big = oldModel.element_img_big;
                }
                #endregion
            }
            if (int.TryParse(Request.Params["category_id_s"].ToString(), out isTranInt))
            {
                model.category_id = uint.Parse(Request.Params["category_id_s"].ToString());
            }
            else
            {
                model.category_id = 0;
            }

            model.category_name = Server.HtmlDecode(Request.Params["category_name_s"].ToString());


            if (!string.IsNullOrEmpty(Request.Params["element_link_url"].ToString()))
            {
                model.element_link_url = Request.Params["element_link_url"].ToString();
            }
            //else
            //{
            //    model.element_link_url = oldModel.element_link_url;
            //}
            if (int.TryParse(Request.Params["element_link_mode"].ToString(), out isTranInt))
            {
                model.element_link_mode = Convert.ToInt32(Request.Params["element_link_mode"]);
            }
            else
            {
                model.element_link_mode = oldModel.element_link_mode;
            }
            if (!string.IsNullOrEmpty(Request.Params["element_sort"].ToString()))
            {
                model.element_sort = Convert.ToInt32(Request.Params["element_sort"].ToString());
            }
            //else
            //{
            //    model.element_sort = oldModel.element_sort;
            //}

            if (!string.IsNullOrEmpty(Request.Params["element_start"].ToString()))
            {
                model.element_start = Convert.ToDateTime(Request.Params["element_start"].ToString());
            }
            else
            {
                model.element_start = oldModel.element_start;
            }
            if (!string.IsNullOrEmpty(Request.Params["element_end"].ToString()))
            {
                model.element_end = Convert.ToDateTime(Request.Params["element_end"].ToString());
            }
            else
            {
                model.element_end = oldModel.element_end;
            }

            model.element_remark = (Request.Params["element_remark"].ToString());

            model.element_status = 0;//默認為不啟用
            #endregion

            try
            {
                //判斷是否能夠獲取到rowid
                if (String.IsNullOrEmpty(Request.Params["element_id"]))//如果不存在該id說明是添加頁面
                {
                    model.element_createdate = DateTime.Now;
                    model.element_updatedate = model.element_createdate;
                    model.create_userid = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                    model.update_userid = model.create_userid;
                    //這裡加上各種參數

                    if (_detailMgr.Save(model) > 0)
                    {
                        resultJson = "{success:true}";//返回json數據
                    }
                }
                else
                {
                    //model.element_createdate = oldModel.element_createdate;
                    model.element_updatedate = DateTime.Now;
                    model.update_userid = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                    //    model.create_userid = oldModel.create_userid;
                    //這裡加上各種參數
                    if (_detailMgr.Update(model) > 0)//如果可以獲取到rowid則進行修改
                    {
                        resultJson = "{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);
                resultJson = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(resultJson);
            this.Response.End();
            return this.Response;
        }
Esempio n. 12
0
        //  [HttpPost]
        public HttpResponseBase SaveVipUserGroup()
        {
            NameValueCollection param = Request.Params;
            VipUserGroup userGroup = new VipUserGroup();
            string json = string.Empty;
            bool size = true;
            Serial serial = new Serial();
            _userGroupMgr = new VipUserGroupMgr(mySqlConnectionString);
            _ISerImplMgr = new SerialMgr(mySqlConnectionString);
            serial = _ISerImplMgr.GetSerialById(72);
            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_MinValue");
            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;//圖片存儲地址
            Random rand = new Random();
            int newRand = rand.Next(1000, 9999);

            string NewName = string.Empty;//當前文件名
            string fileExtention = string.Empty;//當前文件的擴展名
            string NewFileName = string.Empty;
            FileManagement fileLoad = new FileManagement();
            try
            {
                #region 新增
                if (String.IsNullOrEmpty(param["group_id"]))
                {
                    if (!string.IsNullOrEmpty(Request.Form["group_name"]))
                    {
                        userGroup.group_name = Request.Form["group_name"].ToString();
                    }
                    if (!string.IsNullOrEmpty(Request.Form["tax_id"]))
                    {
                        userGroup.tax_id = Request.Form["tax_id"].ToString();
                    }
                    if (!string.IsNullOrEmpty(Request.Form["eng_name"]))
                    {
                        userGroup.eng_name = Request.Form["eng_name"].ToString();
                    }
                    if (!string.IsNullOrEmpty(Request.Form["gift_bonus"]))
                    {
                        userGroup.gift_bonus = Convert.ToUInt32(Request.Form["gift_bonus"]);
                    }
                    if (!string.IsNullOrEmpty(Request.Form["group_category"]))
                    {
                        userGroup.group_category = Convert.ToUInt32(Request.Form["group_category"]);
                    }

                    siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath));
                    try
                    {
                        if (Request.Files["image_name"] != null && Request.Files["image_name"].ContentLength > 0)
                        {
                            HttpPostedFileBase file = Request.Files["image_name"];
                            if (file.ContentLength > int.Parse(minValue) * 1024 && file.ContentLength < int.Parse(maxValue) * 1024)
                            {
                                NewName = Path.GetFileName(file.FileName);
                                bool result = false;
                                //獲得文件的後綴名
                                fileExtention = NewName.Substring(NewName.LastIndexOf(".")).ToLower();
                                //新的文件名是隨機數字
                                BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                                NewFileName = hash.Md5Encrypt(newRand.ToString(), "32") + fileExtention;
                                NewName = NewFileName;
                                string ServerPath = string.Empty;
                                //判斷目錄是否存在,不存在則創建
                                string[] mapPath = new string[1];
                                mapPath[0] = promoPath.Substring(1, promoPath.Length - 2);
                                string jian = localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1);
                                CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), mapPath);
                                NewFileName = localPromoPath + NewFileName;//絕對路徑
                                ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                                string ErrorMsg = string.Empty;
                                //上傳
                                result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                if (result)
                                {
                                    userGroup.image_name = NewName;
                                }

                            }
                            else
                            {
                                size = false;
                            }
                        }

                    }

                    catch (Exception)
                    {
                        userGroup.image_name = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["check_iden"]))
                    {
                        userGroup.check_iden = int.Parse(Request.Params["check_iden"]);
                    }
                    userGroup.createdate = (uint)CommonFunction.GetPHPTime(DateTime.Now.ToString());
                    userGroup.group_id = uint.Parse((serial.Serial_Value + 1).ToString());
                    if (_userGroupMgr.Insert(userGroup) > 0)
                    {
                        serial.Serial_Value = serial.Serial_Value + 1;/*所在操作表的列增加*/
                        _ISerImplMgr.Update(serial);/*修改所在的表的列對應的值*/
                        if (size)
                        {
                            json = "{success:true,msg:\"" + "" + "\"}";
                        }
                        else
                        {
                            json = "{success:true,msg:\"" + " 文件大小應大於1KB小於100KB!" + "\"}";
                        }
                    }
                    else
                    {
                        json = "{success:false,msg:\"" + "新增失敗!" + "\"}";
                    }

                }
                #endregion
                #region 編輯
                else
                {
                    _userGroupMgr = new VipUserGroupMgr(mySqlConnectionString);
                    userGroup.group_id = Convert.ToUInt32(param["group_id"]);
                    VipUserGroup oldUserGroup = _userGroupMgr.GetModelById(userGroup.group_id);
                    if (!string.IsNullOrEmpty(Request.Form["group_name"]))
                    {
                        userGroup.group_name = Request.Form["group_name"].ToString();
                    }
                    if (!string.IsNullOrEmpty(Request.Form["tax_id"]))
                    {
                        userGroup.tax_id = Request.Form["tax_id"].ToString();
                    }

                    if (!string.IsNullOrEmpty(Request.Form["eng_name"]))
                    {
                        userGroup.eng_name = Request.Form["eng_name"].ToString();
                    }
                    if (!string.IsNullOrEmpty(Request.Form["gift_bonus"]))
                    {
                        userGroup.gift_bonus = Convert.ToUInt32(Request.Form["gift_bonus"]);
                    }
                    if (!string.IsNullOrEmpty(Request.Form["group_category"]))
                    {
                        userGroup.group_category = Convert.ToUInt32(Request.Form["group_category"]);
                    }
                    try
                    {
                        //如果圖片沒有改變
                        if (Request.Form["image_name"] == oldUserGroup.image_name)
                        {
                            userGroup.image_name = Request.Form["image_name"];
                        }
                        else
                        {
                            //圖片改變了
                            if (Request.Files["image_name"] != null && Request.Files["image_name"].ContentLength > 0)
                            {
                                HttpPostedFileBase file = Request.Files["image_name"];
                                if (file.ContentLength > int.Parse(minValue) * 1024 && file.ContentLength < int.Parse(maxValue) * 1024)
                                {
                                    NewName = Path.GetFileName(file.FileName);
                                    bool result = false;

                                    //獲得文件的後綴名
                                    fileExtention = NewName.Substring(NewName.LastIndexOf(".")).ToLower();
                                    //新的文件名是隨機數字
                                    BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                                    NewFileName = hash.Md5Encrypt(newRand.ToString(), "32") + fileExtention;
                                    NewName = NewFileName;
                                    string ServerPath = string.Empty;
                                    //判斷目錄是否存在,不存在則創建
                                    string[] mapPath = new string[1];
                                    mapPath[0] = promoPath.Substring(1, promoPath.Length - 2);
                                    string jian = localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1);
                                    CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), mapPath);
                                    //  returnName += promoPath + NewFileName;
                                    NewFileName = localPromoPath + NewFileName;//絕對路徑
                                    ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                                    string ErrorMsg = string.Empty;
                                    //上傳之前刪除已有的圖片
                                    string oldFileName = oldUserGroup.image_name;
                                    //FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd);
                                    //List<string> tem = ftp.GetFileList();
                                    //上傳
                                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                    if (result)
                                    {
                                        userGroup.image_name = NewName;

                                        if (System.IO.File.Exists(ServerPath + oldFileName))
                                        {
                                            FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd);
                                            if (System.IO.File.Exists(localPromoPath + oldFileName))
                                            {
                                                ftps.DeleteFile(localPromoPath + oldFileName);//刪除ftp:71.159上的舊圖片
                                            }
                                            DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                                        }
                                    }
                                    else
                                    {
                                        userGroup.image_name = oldUserGroup.image_name;
                                    }
                                }
                                else
                                {
                                    size = false;
                                    userGroup.image_name = oldUserGroup.image_name;
                                }
                            }
                        }
                    }

                    catch (Exception)
                    {
                        userGroup.image_name = oldUserGroup.image_name;
                    }
                    try
                    {
                        userGroup.check_iden = int.Parse(Request.Params["check_iden"]);
                    }
                    catch (Exception)
                    {
                        userGroup.check_iden = 0;
                    }
                    if (_userGroupMgr.Update(userGroup) > 0)
                    {
                        if (size)
                        {
                            json = "{success:true,msg:\"" + "" + "\"}";
                        }
                        else
                        {
                            json = "{success:true,msg:\"" + " 文件大小應大於1KB小於100KB!" + "\"}";
                        }
                    }
                    else
                    {
                        json = "{success:false,msg:\"" + "修改失敗!" + "\"}";
                    }

                }
                #endregion
            }
            catch (Exception ex)
            {
                json = "{success:false,msg:\"" + "異常" + "\"}";
                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;

        }
Esempio n. 13
0
        public HttpResponseBase PaperEdit()
        {
            string json = string.Empty;
            Paper p = new Paper();
            _paperMgr = new PaperMgr(mySqlConnectionString);

            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 localBannerPath = imgLocalPath + PaperPath;//圖片存儲地址

            FileManagement fileLoad = new FileManagement();

            try
            {
                List<Paper> store = new List<Paper>();
                if (!string.IsNullOrEmpty(Request.Params["paper_id"]))
                {
                    int totalCount = 0;
                    p.IsPage = false;
                    p.paperID = int.Parse(Request.Params["paper_id"]);
                    store = _paperMgr.GetPaperList(p, out totalCount);
                }
                string oldImg = string.Empty;
                foreach (var item in store)
                {
                    oldImg = item.paperBanner;
                }

                p = new Paper();
                p.paperName = Request.Params["paper_name"];
                p.paperMemo = Request.Params["paper_memo"];
                p.bannerUrl = Request.Params["banner_url"];
                if (!string.IsNullOrEmpty(Request.Params["paper_start"]))
                {
                    p.paperStart = DateTime.Parse(DateTime.Parse(Request.Params["paper_start"]).ToString("yyyy-MM-dd HH:mm:ss"));
                }
                if (!string.IsNullOrEmpty(Request.Params["paper_end"]))
                {
                    p.paperEnd = DateTime.Parse(DateTime.Parse(Request.Params["paper_end"]).ToString("yyyy-MM-dd HH:mm:ss"));
                }
                p.event_ID = Request.Params["eventid"];
                if (!string.IsNullOrEmpty(Request.Params["isRepeatGift"]))
                {
                    p.isRepeatGift = int.Parse(Request.Params["isRepeatGift"]);
                }
                //if (!string.IsNullOrEmpty(Request.Params["isPromotion"]))
                //{
                //    p.isPromotion = int.Parse(Request.Params["isPromotion"]);
                //    if (p.isPromotion == 1)
                //    {
                //        p.promotionUrl = Request.Params["promotion_url"];
                //    }
                //}
                //if (!string.IsNullOrEmpty(Request.Params["isPromotion"]))
                //{
                //    p.isPromotion = int.Parse(Request.Params["isPromotion"]);
                //    if (p.isPromotion == 1)
                //    {
                //        p.promotionUrl = Request.Params["promotion_url"];
                //    }
                //}

                //if (!string.IsNullOrEmpty(Request.Params["isGiveBonus"]))
                //{
                //    p.isGiveBonus = int.Parse(Request.Params["isGiveBonus"]);
                //    if (p.isGiveBonus == 1)
                //    {
                //        if (!string.IsNullOrEmpty(Request.Params["bonus_num"]))
                //        {
                //            p.bonusNum = int.Parse(Request.Params["bonus_num"]);
                //        }
                //    }
                //}

                //if (!string.IsNullOrEmpty(Request.Params["isGiveProduct"]))
                //{
                //    p.isGiveProduct = int.Parse(Request.Params["isGiveProduct"]);
                //    if (p.isGiveProduct == 1)
                //    {
                //        if (!string.IsNullOrEmpty(Request.Params["product_id"]))
                //        {
                //            p.productID = int.Parse(Request.Params["product_id"]);
                //        }
                //    }
                //}

                if (!string.IsNullOrEmpty(Request.Params["isRepeatWrite"]))
                {
                    p.isRepeatWrite = int.Parse(Request.Params["isRepeatWrite"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["isNewMember"]))
                {
                    p.isNewMember = int.Parse(Request.Params["isNewMember"]);
                }
                p.creator = int.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString());
                System.Net.IPAddress[] addlist = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList;
                if (addlist.Length > 0)
                {
                    p.ipfrom = addlist[0].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["paper_id"]) && Request.Params["paper_banner"] == oldImg)
                {
                    p.paperBanner = oldImg;
                }
                else
                {
                    string ServerPath = string.Empty;
                    ServerPath = Server.MapPath(imgLocalServerPath + PaperPath);
                    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;

                            BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                            NewFileName = hash.Md5Encrypt(fileName, "32");
                            //判斷目錄是否存在,不存在則創建
                            FTP f_cf = new FTP();
                            f_cf.MakeMultiDirectory(localBannerPath.Substring(0, localBannerPath.Length - PaperPath.Length + 1), PaperPath.Substring(1, PaperPath.Length - 2).Split('/'), ftpuser, ftppwd);

                            fileName = NewFileName + fileExtention;
                            NewFileName = localBannerPath + NewFileName + fileExtention;//絕對路徑

                            string ErrorMsg = string.Empty;

                            bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                            if (result)//上傳成功
                            {
                                p.paperBanner = fileName;
                                //上傳新圖片成功后,再刪除舊的圖片
                                CommonFunction.DeletePicFile(ServerPath + oldImg);//刪除本地圖片
                                FTP ftp = new FTP(localBannerPath, ftpuser, ftppwd);
                                List<string> tem = ftp.GetFileList();
                                if (tem.Contains(oldImg))
                                {
                                    FTP ftps = new FTP(localBannerPath + oldImg, ftpuser, ftppwd);
                                    ftps.DeleteFile(localBannerPath + oldImg);//刪除ftp:71.159上的舊圖片
                                }
                            }
                            else
                            {
                                p.paperBanner = oldImg;
                            }
                        }
                        else
                        {
                            //上傳之前刪除已有的圖片
                            CommonFunction.DeletePicFile(ServerPath + oldImg);//刪除本地圖片
                            FTP ftp = new FTP(localBannerPath, ftpuser, ftppwd);
                            List<string> tem = ftp.GetFileList();
                            if (tem.Contains(oldImg))
                            {
                                FTP ftps = new FTP(localBannerPath + oldImg, ftpuser, ftppwd);
                                ftps.DeleteFile(localBannerPath + oldImg);//刪除ftp:71.159上的舊圖片
                            }
                            p.paperBanner = "";
                        }

                    }
                }

                #region 新增
                if (String.IsNullOrEmpty(Request.Params["paper_id"]))
                {
                    if (_paperMgr.Add(p) > 0)
                    {
                        json = "{success:true,msg:\"" + "新增成功!" + "\"}";
                    }

                }
                #endregion
                #region 編輯
                else
                {
                    p.paperID = int.Parse(Request.Params["paper_id"]);
                    p.modifier = int.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString());
                    if (_paperMgr.Update(p) > 0)
                    {
                        json = "{success:true,msg:\"" + "修改成功!" + "\"}";
                    }

                }
                #endregion
            }
            catch (Exception ex)
            {
                json = "{success:false,msg:\"" + "異常" + "\"}";
                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;

        }
Esempio n. 14
0
        public string ArriveTime(int itemId, string created)
        {
            created= CommonFunction.DateTimeToString(Convert.ToDateTime(created.ToString()));
            string path = System.Web.HttpContext.Current.Server.MapPath(xmlPath);
            SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
            SiteConfig NETDoMain_Name = _siteConfigMgr.GetConfigByName("NETDoMain_Name");

            string Url = "http://" + NETDoMain_Name.Value + "/Open/ArriveTime?itemId=" + itemId+"&dateTime="+created;
            try
            {
                HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(Url);
                httpRequest.Timeout = 2000;
                httpRequest.Method = "GET";
                HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
                StreamReader sr = new StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
                string result = sr.ReadToEnd();
                //JsonConvert.DeserializeObject(result);
                JObject o = JObject.Parse(result);
                result = o["data"].ToString();
                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("DeliverMasterMgr-->ArriveTime-->" + ex.Message, ex);
            }
        }
Esempio n. 15
0
 /// <summary>
 /// 獲取圖片配置
 /// </summary>  
 private void ImagePathConfig()
 {
     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_MinValue");
     SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue");
     SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME");
     SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD");
     //擴展名、最小值、最大值
     extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value;
     minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value;
     maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value;
     localHealthPath = imgLocalPath + vendorPath;//圖片存儲地址
 }
Esempio n. 16
0
        public HttpResponseBase SaveDeliverExportArrivalInfo()
        {
            string json = string.Empty;
            //DeliverChangeLog dCL = new DeliverChangeLog();
            //DeliverMasterQuery dmQuery = new DeliverMasterQuery();
            _DeliverChangeLogMgr = new DeliverChangeLogMgr(mySqlConnectionString);
            //_DeliverMsterMgr = new DeliverMasterMgr(mySqlConnectionString);
            try
            {
                                             
                //dCL.deliver_id = Convert.ToInt32(Request.Params["deliver_id"]);                            
                //dCL.dcl_create_datetime = DateTime.Now;
                //dCL.dcl_ipfrom = CommonFunction.GetIP4Address(Request.UserHostAddress.ToString());
                //dCL.dcl_create_muser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                //dCL.dcl_create_user = 0;
                //dCL.dcl_create_type = 2;
                //dmQuery.deliver_id = Convert.ToUInt32(Request.Params["deliver_id"]); 
    
                //if (!string.IsNullOrEmpty(Request.Params["dcl_note"]))
                //{
                //    dCL.dcl_note = Request.Params["dcl_note"]; 
                //}
                //if (!string.IsNullOrEmpty(Request.Params["expect_arrive_date"]))
                //{
                //    dCL.expect_arrive_date = Convert.ToDateTime(Request.Params["expect_arrive_date"]);
                //    dmQuery.expect_arrive_date = Convert.ToDateTime(Request.Params["expect_arrive_date"]);
                //}
                //if (!string.IsNullOrEmpty(Request.Params["expect_arrive_period"]))
                //{
                //    dCL.expect_arrive_period = Convert.ToInt32(Request.Params["expect_arrive_period"]);
                //    dmQuery.expect_arrive_period = Convert.ToInt32(Request.Params["expect_arrive_period"]);
                //}


                ModifyExpertArriveDateViewModel expertArriveDateViewModel = new ModifyExpertArriveDateViewModel();
                expertArriveDateViewModel.deliver_id = Convert.ToInt32(Request.Params["deliver_id"]);
                if (!string.IsNullOrEmpty(Request.Params["expect_arrive_date"]))
                {
                    expertArriveDateViewModel.newDate = Convert.ToDateTime(Request.Params["expect_arrive_date"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["expect_arrive_period"]))
                {
                    string period_num = Request.Params["expect_arrive_period"];

                    switch (period_num)
                    {
                        case "0": 
                            expertArriveDateViewModel.period = ExpectArrivePeriod.NoLimit;
                            break;
                        case "1":
                            expertArriveDateViewModel.period = ExpectArrivePeriod.Morning;
                            break;
                        case "2":
                            expertArriveDateViewModel.period = ExpectArrivePeriod.Afternoon;
                            break;
                        case "3":
                            expertArriveDateViewModel.period = ExpectArrivePeriod.Evening;
                            break;
                    }               
                }
                if (!string.IsNullOrEmpty(Request.Params["dcl_note"]))
                {
                    expertArriveDateViewModel.note = Request.Params["dcl_note"];
                }
                else
                {
                    expertArriveDateViewModel.note = " ";
                }

                string xmlPath = ConfigurationManager.AppSettings["SiteConfig"];//XML的設置
                string path = Server.MapPath(xmlPath);
                SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
                string APIServer = _siteConfigMgr.GetConfigByName("APIServer").Value;
                //修改期望到貨日
                bool result = _DeliverChangeLogMgr.ModifyExpertArriveDate(APIServer, expertArriveDateViewModel);

                if (result)
                {
                    json = "{success:true,msg:'保存成功'}";//
                }
                else
                {
                    json = "{success:false,msg:'保存失敗'}";//
                }
                
                ////更新deliver_mater表的 期望到貨日期、時段
                //int result1 = _DeliverMsterMgr.UpdateExpectArrive(dmQuery);
                ////向deliver_change_log表插入數據
                //int result2 = _DeliverChangeLogMgr.insertDeliverChangeLog(dCL);

                //if (result1 > 0)
                //{
                //    if (result2 > 0)
                //    {
                //        json = "{success:true,msg:'保存成功'}";//
                //    }
                //    else
                //    {
                //        json = "{success:true,msg:'deliver_mster表數據更新成功,<br/>deliver_change_log表數據添加失敗'}";
                //    }
                //}
                //else
                //{
                //    if (result2 > 0)
                //    {
                //        json = "{success:true,msg: 'deliver_mster表數據更新失敗,<br/>deliver_change_log數據添加成功'}";
                //    }
                //    else
                //    {
                //        json = "{success:true,msg:'deliver_mster表數據更新失敗,<br/>deliver_change_log表數據添加失敗'}";
                //    }
                //}                
            }
            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,msg:'保存失敗'}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Esempio n. 17
0
        /// <summary>
        /// 新增或修改供應商品牌信息
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase UpdVendorBrand()
        {
            List<VendorBrandSetQuery> stores = new List<VendorBrandSetQuery>();
            query = new VendorBrandSetQuery();
            VendorBrandSetQuery oldquery = new VendorBrandSetQuery();
            _IvendorBrandSet = new VendorBrandSetMgr(connectionString);
            _productMgr = new ProductMgr(connectionString);
            string json = string.Empty;
            string errorInfo = string.Empty;

            try
            {
                #region 獲取數據
                query.Brand_Id = UInt32.Parse(Request.Params["Brand_Id"]);
                oldquery = _IvendorBrandSet.GetModelById(Int32.Parse(Request.Params["Brand_Id"]));
                try
                {
                    query.Brand_Name = Request.Params["brandName"].ToString();
                }
                catch (Exception)
                {
                    query.Brand_Name = oldquery.Brand_Name;
                }
                try
                {
                    query.vendor_id = uint.Parse(Request.Params["vendorid"].ToString());
                }
                catch (Exception)
                {
                    query.vendor_id = oldquery.vendor_id;
                }
                try
                {
                    query.Brand_Sort = uint.Parse(Request.Params["brandsort"].ToString());
                }
                catch (Exception)
                {
                    query.Brand_Sort = oldquery.Brand_Sort;
                }
                try
                {
                    query.Brand_Status = uint.Parse(Request.Params["brandstatus"].ToString());
                }
                catch (Exception)
                {
                    query.Brand_Status = oldquery.Brand_Status;
                }
                try
                {
                    query.Image_Status = uint.Parse(Request.Params["imagestatus"].ToString());
                }
                catch (Exception)
                {
                    query.Image_Status = oldquery.Image_Status;
                }
                try
                {
                    query.Image_Link_Mode = uint.Parse(Request.Params["imagelinkmode"].ToString());
                }
                catch (Exception)
                {
                    query.Image_Link_Mode = oldquery.Image_Link_Mode;
                }
                try
                {
                    query.Image_Link_Url = Request.Params["imagelinkurl"].ToString();
                }
                catch (Exception)
                {
                    query.Image_Link_Url = oldquery.Image_Link_Url;
                }
                try
                {
                    query.Resume_Image_Link = Request.Params["resumeimagelink"].ToString();
                }
                catch (Exception)
                {
                    query.Resume_Image_Link = oldquery.Resume_Image_Link;
                }
                try
                {
                    query.Media_Report_Link_Url = Request.Params["mediareportlinkurl"].ToString();
                }
                catch (Exception)
                {
                    query.Media_Report_Link_Url = oldquery.Media_Report_Link_Url;
                }
                try
                {
                    query.Brand_Msg = Request.Params["brandmsg"].ToString();
                }
                catch (Exception)
                {
                    query.Brand_Msg = oldquery.Brand_Msg;
                }
                long start = CommonFunction.GetPHPTime(Request.Params["begin_time"].ToString());
                long end = CommonFunction.GetPHPTime(Request.Params["end_time"].ToString());
                try
                {
                    query.Brand_Msg_Start_Time = uint.Parse(start.ToString());
                }
                catch (Exception)
                {
                    query.Brand_Msg_Start_Time = oldquery.Brand_Msg_Start_Time;
                }
                try
                {
                    query.Brand_Msg_End_Time = uint.Parse(end.ToString());
                }
                catch (Exception)
                {
                    query.Brand_Msg_End_Time = oldquery.Brand_Msg_End_Time;
                }
                try
                {
                    query.Brand_Createdate = uint.Parse(CommonFunction.GetPHPTime(DateTime.Now.ToString()).ToString());
                }
                catch (Exception)
                {
                    query.Brand_Createdate = oldquery.Brand_Createdate;
                }
                try
                {
                    query.classIds = Request["shopclass"].ToString();
                }
                catch (Exception)
                {
                    query.classIds = oldquery.classIds;
                }
                query.Brand_Ipfrom = Request.UserHostAddress;
                try
                {
                    query.Cucumber_Brand = uint.Parse(Request.Params["cucumberbrand"].ToString());
                }
                catch
                {
                    query.Cucumber_Brand = oldquery.Cucumber_Brand;
                }
                try
                {
                    query.Image_Name = Request.Params["imagename"].ToString();
                }
                catch (Exception)
                {
                    query.Image_Name = oldquery.Image_Name;
                }
                try
                {
                    query.Promotion_Banner_Image_Link = Request.Params["promotionbannerimagelink"].ToString();
                }
                catch (Exception)
                {
                    query.Promotion_Banner_Image_Link = oldquery.Promotion_Banner_Image_Link;
                }
                try
                {
                    query.short_description = Request.Params["short_description"].ToString();
                }
                catch (Exception)
                {
                    query.short_description = oldquery.short_description;
                }
                query.Image_Name = oldquery.Image_Name;
                query.Resume_Image = oldquery.Resume_Image;
                query.Promotion_Banner_Image = oldquery.Promotion_Banner_Image;
                query.brand_logo = oldquery.brand_logo;
                #endregion
                #region 上傳圖片
                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_MinValue");
                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 + brandPath;//圖片存儲地址
                FileManagement fileLoad = new FileManagement();
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    string fileName = string.Empty;     //當前文件名
                    HttpPostedFileBase file = Request.Files[i];
                    fileName = Path.GetFileName(file.FileName);
                    if (string.IsNullOrEmpty(fileName))
                    {
                        continue;
                    }

                    fileLoad = new FileManagement();
                    string oldFileName = string.Empty;  //舊文件名
                    string fileExtention = string.Empty;//當前文件的擴展名
                    bool result = false;
                    string NewFileName = string.Empty;
                    string ServerPath = string.Empty;
                    string newRand = string.Empty;
                    string ErrorMsg = string.Empty;

                    newRand = hash.Md5Encrypt(fileLoad.NewFileName(fileName) + DateTime.Now.ToString(), "32");
                    fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                    NewFileName = newRand + fileExtention;

                    string folder1 = NewFileName.Substring(0, 2) + "/"; //圖片名前兩碼
                    string folder2 = NewFileName.Substring(2, 2) + "/"; //圖片名第三四碼

                    FTP f_cf = new FTP();
                    localPromoPath = imgLocalPath + brandPath + folder1 + folder2;  //圖片存儲地址
                    string s = localPromoPath.Substring(0, localPromoPath.Length - (brandPath + folder1 + folder2).Length + 1);
                    f_cf.MakeMultiDirectory(s, (brandPath + folder1 + folder2).Substring(1, (brandPath + folder1 + folder2).Length - 2).Split('/'), ftpuser, ftppwd);
                    ServerPath = Server.MapPath(imgLocalServerPath + brandPath + folder1 + folder2);
                    fileName = NewFileName;
                    NewFileName = localPromoPath + NewFileName;//絕對路徑
                    Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件

                    //上傳
                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                    if (result)//上傳成功
                    {
                        //圖片上傳成功后記錄新圖片名稱
                        switch (i)
                        {
                            case 0:
                                query.Image_Name = fileName;
                                break;
                            case 1:
                                query.Resume_Image = fileName;
                                break;
                            case 2:
                                query.Promotion_Banner_Image = fileName;
                                break;
                            case 3:
                                query.brand_logo = fileName;
                                break;
                            default:
                                break;
                        }

                        //圖片上傳成功后如果存在舊圖片則根據舊圖片名刪除舊圖片
                        if (!string.IsNullOrEmpty(oldFileName))
                        {
                            switch (i)
                            {
                                case 0:
                                    oldFileName = oldquery.Image_Name;
                                    break;
                                case 1:
                                    oldFileName = oldquery.Resume_Image;
                                    break;
                                case 2:
                                    oldFileName = oldquery.Promotion_Banner_Image;
                                    break;
                                case 3:
                                    oldFileName = oldquery.brand_logo;
                                    break;
                                default:
                                    break;
                            }
                            DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                        }
                    }
                    else
                    {
                        //圖片上傳失敗則圖片名稱為原有圖片名稱
                        switch (i)
                        {
                            case 0:
                                query.Image_Name = oldquery.Image_Name;//形象圖片
                                break;
                            case 1:
                                query.Resume_Image = oldquery.Resume_Image;//安心聲明圖片
                                break;
                            case 2:
                                query.Promotion_Banner_Image = oldquery.Promotion_Banner_Image;//促銷圖片
                                break;
                            case 3:
                                query.brand_logo = oldquery.brand_logo;//品牌logo
                                break;
                            default:
                                break;
                        }

                        errorInfo += "第" + (i + 1) + "張" + ErrorMsg + "<br/>";
                        //json = "{success:false,msg:\"第" + i + "張" + ErrorMsg + ",之後圖片未作處理" + "\"}";
                    }
                }
                #endregion
                //更新數據庫記錄
                if (_IvendorBrandSet.Update(query) > 0)
                {
                    if (_productMgr.UpdateSaleStatusByCondition(new Product { Vendor_Id = query.vendor_id, Brand_Id = query.Brand_Id }))
                    {
                        json = "{success:true,msg:\"數據保存成功!\"}";
                    }
                }
                if (!string.IsNullOrEmpty(errorInfo))
                {
                    json = "{success:true,msg:\"<div>數據保存成功!<br/>但<br/>" + errorInfo + "</div>\"}";
                }
            }
            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,msg:\"保存失敗,請稍后再試!\"}";
                if (!string.IsNullOrEmpty(errorInfo))
                {
                    json = "{success:false,msg:\"<div>保存失敗,請稍后再試!<br/>" + errorInfo + "</div>\"}";
                }
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        /// <summary>
        /// 新增編輯類別信息
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase ProductCategorySave()
        {
            string json = string.Empty;
            string jsonStr = string.Empty;
            CategoryQuery cq = new CategoryQuery();
            IAreaPactetImplMgr _iareaPacketMgr = new AreaPacketMgr(mySqlConnectionString);
            string errorInfo = string.Empty;
            try
            {
                _proCategoryImplMgr = new CategoryMgr(mySqlConnectionString);
                if (!string.IsNullOrEmpty(Request.Params["category_id"]))
                {
                    cq.category_id = Convert.ToUInt32(Request.Params["category_id"]);
                }
                CategoryQuery oldCq = _proCategoryImplMgr.GetProductCategoryById(cq);
                if (oldCq != null)
                {
                    cq.banner_image = oldCq.banner_image;
                    cq.category_image_in = oldCq.category_image_in;
                    cq.category_image_out = oldCq.category_image_out;
                    cq.category_image_app = oldCq.category_image_app;
                }
                #region 上傳圖片

                try
                {
                    if (Request.Files.Count != 0)
                    {
                        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_MinValue");
                        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;//圖片存儲地址                             

                        for (int a = 0; a < Request.Files.Count; a++)
                        {
                            string fileName = string.Empty;     //當前文件名
                            string fileExtention = string.Empty;//當前文件的擴展名
                            HttpPostedFileBase file = Request.Files[a];
                            fileName = Path.GetFileName(file.FileName);
                            if (string.IsNullOrEmpty(fileName))
                            {
                                continue;
                            }

                            bool result = false;
                            string NewFileName = string.Empty;
                            string ServerPath = string.Empty;
                            string ErrorMsg = string.Empty;
                            string oldFileName = string.Empty;  //舊文件名
                            //生成隨機數,用於圖片的重命名
                            Random rand = new Random();
                            int newRand = rand.Next(1000, 9999);
                            fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                            NewFileName = newRand + fileExtention;

                            //判斷目錄是否存在,不存在則創建
                            CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'));
                            fileName = NewFileName;
                            NewFileName = localPromoPath + NewFileName;//絕對路徑
                            ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                            FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd);
                            List<string> tem = ftp.GetFileList();
                            try
                            {
                                //上傳
                                FileManagement fileLoad = new FileManagement();
                                result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                if (result)//上傳成功
                                {
                                    switch (a)
                                    {
                                        case 0:
                                            cq.banner_image = fileName;
                                            break;
                                        case 1:
                                            cq.category_image_in = fileName;
                                            break;
                                        case 2:
                                            cq.category_image_out = fileName;
                                            break;
                                        case 3:
                                            cq.category_image_app = fileName;
                                            break;
                                        default:
                                            break;
                                    }
                                }
                                else
                                {
                                    //圖片上傳失敗則圖片名稱為原有圖片名稱
                                    switch (a)
                                    {
                                        case 0:
                                            cq.banner_image = fileName;
                                            break;
                                        case 1:
                                            cq.category_image_in = fileName;
                                            break;
                                        case 2:
                                            cq.category_image_out = fileName;
                                            break;
                                        case 3:
                                            cq.category_image_app = fileName;
                                            break;
                                        default:
                                            break;
                                    }
                                    errorInfo += "第" + (a + 1) + "張" + ErrorMsg + "<br/>";                                
                                }
                            }
                            catch (Exception ex)
                            {
                                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name + "->fileLoad.UpLoadFile()", ex.Source, ex.Message);
                                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                                log.Error(logMessage);
                                jsonStr = "{success:false,msg:'圖片上傳失敗'}";
                              
                            }
                        }
                    }

                }
                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);
                    jsonStr = "{success:false,msg:'圖片上傳失敗'}";
                  
                }


                #endregion              
                    if (!string.IsNullOrEmpty(Request.Params["comboFrontCage"]))
                    {
                        cq.category_father_id = Convert.ToUInt32(Request.Params["comboFrontCage"].ToString());
                    }

                    if (!string.IsNullOrEmpty(Request.Params["category_name"]))
                    {
                        cq.category_name = Request.Params["category_name"].ToString();
                    }

                    if (!string.IsNullOrEmpty(Request.Params["category_sort"]))
                    {
                        cq.category_sort = Convert.ToUInt32(Request.Params["category_sort"].ToString());
                    }
                    if (!string.IsNullOrEmpty(Request.Params["category_display"]))
                    {
                        cq.category_display = Convert.ToUInt32(Request.Params["category_display"]);
                    }
                    if (!string.IsNullOrEmpty(Request.Params["categorylinkmode"]))
                    {
                        cq.category_link_mode = Convert.ToUInt32(Request.Params["categorylinkmode"].ToString());
                    }
                    if (!string.IsNullOrEmpty(Request.Params["category_link_url"]))
                    {
                        cq.category_link_url = Request.Params["category_link_url"].ToString();
                    }
                    //if (!string.IsNullOrEmpty(Request.Params["photo"]))
                    //{
                    //    #region 上傳圖片

                    //    try
                    //    {
                    //        if (Request.Files.Count != 0)
                    //        {
                    //            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_MinValue");
                    //            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;//圖片存儲地址
                    //            //生成隨機數,用於圖片的重命名
                    //            Random rand = new Random();
                    //            int newRand = rand.Next(1000, 9999);



                    //            //獲取上傳的圖片
                    //            HttpPostedFileBase file = Request.Files[0];
                    //            string fileName = string.Empty;//當前文件名
                    //            string fileExtention = string.Empty;//當前文件的擴展名

                    //            fileName = Path.GetFileName(file.FileName);
                    //            if (!string.IsNullOrEmpty(fileName))
                    //            {
                    //                bool result = false;
                    //                string NewFileName = string.Empty;

                    //                fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                    //                //NewFileName = pacdModel.event_id + newRand + fileExtention;//圖片重命名為event_id+4位隨機數+擴展名
                    //                NewFileName = newRand + fileExtention;
                    //                string ServerPath = string.Empty;
                    //                //判斷目錄是否存在,不存在則創建
                    //                CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'));

                    //                //  returnName += promoPath + NewFileName;
                    //                fileName = NewFileName;
                    //                NewFileName = localPromoPath + NewFileName;//絕對路徑
                    //                ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                    //                string ErrorMsg = string.Empty;

                    //                //上傳之前刪除已有的圖片
                    //                //string oldFileName = olderpcmodel.banner_image;
                    //                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);//刪除ftp:71.159上的舊圖片
                    //                //    //DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                    //                //}
                    //                try
                    //                {
                    //                    //上傳
                    //                    FileManagement fileLoad = new FileManagement();
                    //                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                    //                    if (result)//上傳成功
                    //                    {
                    //                        cq.banner_image = fileName;
                    //                    }
                    //                }
                    //                catch (Exception ex)
                    //                {
                    //                    Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                    //                    logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name + "->fileLoad.UpLoadFile()", ex.Source, ex.Message);
                    //                    logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                    //                    log.Error(logMessage);
                    //                    jsonStr = "{success:false,msg:'圖片上傳失敗'}";

                    //                    //pacdModel.banner_image = olderpcmodel.banner_image;
                    //                }
                    //            }
                    //            else
                    //            {
                    //                //pacdModel.banner_image = olderpcmodel.banner_image;
                    //            }
                    //        }

                    //    }
                    //    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);
                    //        jsonStr = "{success:false,msg:'圖片上傳失敗'}";

                    //        //pacdModel.banner_image = olderpcmodel.banner_image;
                    //    }


                    //    #endregion
                    //}
                    if (!string.IsNullOrEmpty(Request.Params["banner_status"]))
                    {
                        cq.banner_status = Convert.ToUInt32(Request.Params["banner_status"].ToString());
                    }
                    if (!string.IsNullOrEmpty(Request.Params["banner_link_mode"]))
                    {
                        cq.banner_link_mode = Convert.ToUInt32(Request.Params["banner_link_mode"].ToString());
                    }
                    if (!string.IsNullOrEmpty(Request.Params["banner_link_url"]))
                    {
                        cq.banner_link_url = Request.Params["banner_link_url"].ToString();
                    }
                    if (!string.IsNullOrEmpty(Request.Params["startdate"]))
                    {
                        cq.banner_show_start = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Params["startdate"].ToString()));
                    }
                    if (!string.IsNullOrEmpty(Request.Params["enddate"]))
                    {
                        cq.banner_show_end = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Params["enddate"].ToString()));
                    } 
                    if (!string.IsNullOrEmpty(Request.Params["short_description"]))
                    {
                        cq.short_description = Request.Params["short_description"].ToString();
                    }

                    if (string.IsNullOrEmpty(Request.Params["category_id"]))
                    {
                        cq.category_ipfrom = CommonFunction.GetClientIP();
                        cq.category_createdate = Convert.ToUInt32(CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                        cq.category_updatedate = Convert.ToUInt32(CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                        cq.status = 1;
                        _proCategoryImplMgr = new CategoryMgr(mySqlConnectionString);

                        int i = _proCategoryImplMgr.ProductCategorySave(cq);
                        if (i > 0)
                        {
                            json = "{success:true}";
                        }
                    }

                    else
                    {
                        //_proCategoryImplMgr = new CategoryMgr(mySqlConnectionString);
                        //cq.category_id = Convert.ToUInt32(Request.Params["category_id"]);
                        //CategoryQuery oldCq = _proCategoryImplMgr.GetProductCategoryById(cq);
                        //if (!string.IsNullOrEmpty(Request.Params["comboFrontCage"]))
                        //{
                        //    cq.category_father_id = Convert.ToUInt32(Request.Params["comboFrontCage"].ToString());
                        //}
                        //else
                        //{
                        //    cq.category_father_id = oldCq.category_father_id;
                        //}

                        //if (!string.IsNullOrEmpty(Request.Params["category_name"]))
                        //{
                        //    cq.category_name = Request.Params["category_name"].ToString();
                        //}
                        //else
                        //{
                        //    cq.category_name = oldCq.category_name;
                        //}

                        //if (!string.IsNullOrEmpty(Request.Params["category_sort"]))
                        //{
                        //    cq.category_sort = Convert.ToUInt32(Request.Params["category_sort"].ToString());
                        //}
                        //else
                        //{
                        //    cq.category_sort = oldCq.category_sort;
                        //}
                        //if (!string.IsNullOrEmpty(Request.Params["category_display"]))
                        //{
                        //    cq.category_display = Convert.ToUInt32(Request.Params["category_display"]);
                        //}
                        //else
                        //{
                        //    cq.category_display = oldCq.category_display;
                        //}
                        //if (!string.IsNullOrEmpty(Request.Params["categorylinkmode"]))
                        //{
                        //    cq.category_link_mode = Convert.ToUInt32(Request.Params["categorylinkmode"].ToString());
                        //}
                        //else
                        //{
                        //    cq.category_link_mode = oldCq.category_link_mode;
                        //}

                        //cq.category_link_url = Request.Params["category_link_url"].ToString();

                        //if (!string.IsNullOrEmpty(Request.Params["photo"]))
                        //{
                        //    #region 上傳圖片

                        //    try
                        //    {
                        //        if (Request.Files.Count != 0)
                        //        {
                        //            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_MinValue");
                        //            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;//圖片存儲地址
                        //            生成隨機數,用於圖片的重命名
                        //            Random rand = new Random();
                        //            int newRand = rand.Next(1000, 9999);



                        //            獲取上傳的圖片
                        //            HttpPostedFileBase file = Request.Files[0];
                        //            string fileName = string.Empty;//當前文件名
                        //            string fileExtention = string.Empty;//當前文件的擴展名

                        //            fileName = Path.GetFileName(file.FileName);
                        //            if (!string.IsNullOrEmpty(fileName))
                        //            {
                        //                bool result = false;
                        //                string NewFileName = string.Empty;

                        //                fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                        //                NewFileName = pacdModel.event_id + newRand + fileExtention;//圖片重命名為event_id+4位隨機數+擴展名
                        //                NewFileName = newRand + fileExtention;
                        //                string ServerPath = string.Empty;
                        //                判斷目錄是否存在,不存在則創建
                        //                CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'));

                        //                  returnName += promoPath + NewFileName;
                        //                fileName = NewFileName;
                        //                NewFileName = localPromoPath + NewFileName;//絕對路徑
                        //                ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                        //                string ErrorMsg = string.Empty;

                        //                上傳之前刪除已有的圖片
                        //                string oldFileName = oldCq.banner_image;
                        //                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);//刪除ftp:71.159上的舊圖片
                        //                    DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                        //                }
                        //                try
                        //                {
                        //                    上傳
                        //                    FileManagement fileLoad = new FileManagement();
                        //                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                        //                    if (result)//上傳成功
                        //                    {
                        //                        cq.banner_image = fileName;
                        //                    }
                        //                }
                        //                catch (Exception ex)
                        //                {
                        //                    Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                        //                    logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name + "->fileLoad.UpLoadFile()", ex.Source, ex.Message);
                        //                    logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                        //                    log.Error(logMessage);
                        //                    jsonStr = "{success:false,msg:'圖片上傳失敗'}";

                        //                    cq.banner_image = oldCq.banner_image;
                        //                }
                        //            }
                        //            else
                        //            {
                        //                cq.banner_image = oldCq.banner_image;
                        //            }
                        //        }
                        //    }
                        //    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);
                        //        jsonStr = "{success:false,msg:'圖片上傳失敗'}";

                        //        cq.banner_image = oldCq.banner_image;
                        //    }


                        //    #endregion
                        //}
                        //else
                        //{
                        //    cq.banner_image = oldCq.banner_image;
                        //}
                        //if (!string.IsNullOrEmpty(Request.Params["banner_status"]))
                        //{
                        //    cq.banner_status = Convert.ToUInt32(Request.Params["banner_status"].ToString());
                        //}
                        //else
                        //{
                        //    cq.banner_status = oldCq.banner_status;
                        //}
                        //if (!string.IsNullOrEmpty(Request.Params["banner_link_mode"]))
                        //{
                        //    cq.banner_link_mode = Convert.ToUInt32(Request.Params["banner_link_mode"].ToString());
                        //}
                        //else
                        //{
                        //    cq.banner_link_mode = oldCq.banner_link_mode;
                        //}

                        //cq.banner_link_url = Request.Params["banner_link_url"].ToString();
                        //cq.short_description = Request.Params["short_description"].ToString();
                        //cq.banner_show_start = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Params["startdate"].ToString()));

                        //cq.banner_show_end = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Params["enddate"].ToString()));

                        cq.category_ipfrom = CommonFunction.GetClientIP();
                        cq.category_updatedate = Convert.ToUInt32(CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                        int j = _proCategoryImplMgr.ProductCategorySave(cq);
                        if (j > 0)
                        {
                            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,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Esempio n. 19
0
        public HttpResponseBase ReplyQuestion()
        {
            string timestr = string.Empty;
            string path = Server.MapPath(xmlPath);
            SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
            SiteConfig Mail_From = _siteConfigMgr.GetConfigByName("Mail_From");
            SiteConfig Mail_Host = _siteConfigMgr.GetConfigByName("Mail_Host");
            SiteConfig Mail_Port = _siteConfigMgr.GetConfigByName("Mail_Port");
            SiteConfig Mail_UserName = _siteConfigMgr.GetConfigByName("Mail_UserName");
            SiteConfig Mail_UserPasswd = _siteConfigMgr.GetConfigByName("Mail_UserPasswd");
            string EmailFrom = Mail_From.Value;//發件人郵箱
            string SmtpHost = Mail_Host.Value;//smtp服务器
            string SmtpPort = Mail_Port.Value;//smtp服务器端口
            string EmailUserName = Mail_UserName.Value;//郵箱登陸名
            string EmailPassWord = Mail_UserPasswd.Value;//郵箱登陸密碼
            string json = string.Empty;
            _IOrderQuesMgr = new OrderQuestionMgr(mySqlConnectionString);
            _IOrderResponseMgr = new OrderResponseMgr(mySqlConnectionString);
            OrderQuestionQuery query = new OrderQuestionQuery();
            OrderResponse ormodel = new OrderResponse();
            SmsQuery smsquery = new SmsQuery();

            //if (!string.IsNullOrEmpty(Request.Params["question_content"]))
            //{
            //    query.question_content = Request.Params["question_content"];

            //}

            //string order_id = Request.Params["OrderId"].ToString();
            //if (!string.IsNullOrEmpty(order_id))
            //{
            //    query.order_id = Convert.ToUInt32(order_id);
            //}
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["question_id"]))
                {
                    query.question_id = Convert.ToUInt32(Request.Params["question_id"]);
                    ormodel.question_id = query.question_id;

                }
                if (!string.IsNullOrEmpty(Request.Params["order_id"]))
                {
                    smsquery.order_id = Convert.ToInt32(Request.Params["order_id"]);
                }
                //if (!string.IsNullOrEmpty(Request.Params["status"]))
                //{
                //    query.question_status = Convert.ToUInt32(Request.Params["status"]);
                //}
                if (!string.IsNullOrEmpty(Request.Params["response_content"]))
                {
                    ormodel.response_content = Request.Params["response_content"].Replace("\\", "\\\\"); ;
                    smsquery.content = ormodel.response_content.Replace("\\", "\\\\"); ;
                }
                if (!string.IsNullOrEmpty(Request.Params["question_createdate"]))
                {
                    timestr = Request.Params["question_createdate"];
                }
                if (!string.IsNullOrEmpty(Request.Params["question_username"]))
                {
                    query.question_username = Request.Params["question_username"];
                }
                if (!string.IsNullOrEmpty(Request.Params["this_question_email"]))
                {
                    query.question_email = Request.Params["this_question_email"];

                }
                if (!string.IsNullOrEmpty(Request.Params["question_phone"]))
                {
                    smsquery.mobile = Request.Params["question_phone"].ToString();
                }

                //回複方式
                bool reply1 = false;
                bool reply2 = false;
                bool reply3 = false;
                if (!string.IsNullOrEmpty(Request.Params["reply_mail"]))
                {
                    reply1 = Convert.ToBoolean(Request.Params["reply_mail"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["reply_sms"]))
                {
                    reply2 = Convert.ToBoolean(Request.Params["reply_sms"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["reply_phone"]))
                {
                    reply3 = Convert.ToBoolean(Request.Params["reply_phone"]);
                }
                //如果選擇結案就更新問題狀態
                //更新order_question表狀態
                query.question_status = 1;
                _IOrderQuesMgr.UpdateQuestionStatus(query);
                //獲取數據往回覆表添加數據
                ormodel.user_id = uint.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString());
                ormodel.response_ipfrom = CommonFunction.GetIP4Address(Request.UserHostAddress.ToString()); ;
                ormodel.response_createdate = Convert.ToUInt32(CommonFunction.GetPHPTime(DateTime.Now.ToString()));
                //判斷選擇的回複方式
                if (reply1 || !reply1 && !reply2 && !reply3)
                {
                    ormodel.response_type = 1;
                    _IOrderResponseMgr.insert(ormodel);
                    FileStream fs = new FileStream(Server.MapPath("../ImportUserIOExcel/OrderQuestionResponse.html"), FileMode.OpenOrCreate, FileAccess.Read);
                    StreamReader sr = new StreamReader(fs, Encoding.UTF8);
                    string strTemp = sr.ReadToEnd();
                    sr.Close();
                    fs.Close();
                    strTemp = strTemp.Replace("{{$s_datetime$}}", timestr);//添加提問時間
                    strTemp = strTemp.Replace("{{$s_username$}}", query.question_username);//添加提問用戶名
                    strTemp = strTemp.Replace("{{$consultInfo$}}", query.question_content);//添加提問內容
                    strTemp = strTemp.Replace("{{$consultAnwser$}}", ormodel.response_content.Replace("\\\\", "\\"));
                    sendmail(EmailFrom, FromName, query.question_email, query.question_username, EmailTile, strTemp, "", SmtpHost, Convert.ToInt32(SmtpPort), EmailUserName, EmailPassWord);
                }
                else if (reply2)
                {
                    ormodel.response_type = 2;
                    _IOrderResponseMgr.insert(ormodel);
                    smsquery.type = 11;//10表示聯絡客服列表保存過去的
                    smsquery.send = 0;
                    smsquery.trust_send = "9";
                    smsquery.created = DateTime.Now;
                    smsquery.modified = DateTime.Now;
                    _ISmsMgr = new SmsMgr(mySqlConnectionString);
                    _ISmsMgr.InsertSms(smsquery);
                }
                else if (reply3)
                {
                    ormodel.response_type = 3;
                    _IOrderResponseMgr.insert(ormodel);
                }
                //if (!reply1 && !reply2 && !reply3)
                //{
                //    ormodel.response_type = 4;
                //    _IOrderResponseMgr.insert(ormodel);
                //}
                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,msg:0}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Esempio n. 20
0
        public HttpResponseBase BannerImageEdit()
        {
            string json = string.Empty;
            BannerContent bc = new BannerContent();
            Serial serial = new Serial();
            _bcMgr = new BannerContentMgr(mySqlConnectionString);
            _ISerImplMgr = new SerialMgr(mySqlConnectionString);
            serial = _ISerImplMgr.GetSerialById(72);
            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_MinValue");
            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 = imgLocalServerPath + promoPath;//圖片存儲地址 /aimg.gigade100.com/ +/promotion/dev/ 

            string NewName = string.Empty;//當前文件名
            string fileExtention = string.Empty;//當前文件的擴展名
            string NewFileName = string.Empty;
            FileManagement fileLoad = new FileManagement();

            try
            {
                string oldImg = string.Empty;
                serial = _ISerImplMgr.GetSerialById(6);
                List<BannerContent> store = new List<BannerContent>();
                if (!string.IsNullOrEmpty(Request.Params["banner_content_id"]))
                {
                    int totalCount = 0;
                    bc.IsPage = false;
                    bc.banner_content_id = uint.Parse(Request.Params["banner_content_id"]);
                    if (Request.Params["history"] == "1")
                    {
                        bc.banner_status = 3;
                    }
                    store = _bcMgr.GetList(bc, out totalCount);
                    foreach (var item in store)
                    {
                        oldImg = item.banner_image;
                    }
                }
                bc = new BannerContent();
                bc.banner_title = Request.Params["banner_title"];
                bc.banner_link_url = Request.Params["banner_link_url"];
                if (!string.IsNullOrEmpty(Request.Params["banner_site_id"]))
                {
                    bc.banner_site_id = uint.Parse(Request.Params["banner_site_id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["banner_link_mode"]))
                {
                    bc.banner_link_mode = int.Parse(Request.Params["banner_link_mode"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["banner_sort"]))
                {
                    bc.banner_sort = uint.Parse(Request.Params["banner_sort"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["banner_statuses"]))
                {
                    bc.banner_status = uint.Parse(Request.Params["banner_statuses"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["banner_start"]))
                {
                    bc.banner_start = DateTime.Parse(DateTime.Parse(Request.Params["banner_start"]).ToString("yyyy-MM-dd") + " 00:00:00");
                }
                if (!string.IsNullOrEmpty(Request.Params["banner_end"]))
                {
                    bc.banner_end = DateTime.Parse(DateTime.Parse(Request.Params["banner_end"]).ToString("yyyy-MM-dd") + " 23:59:59");
                }
                bc.banner_ipfrom = CommonFunction.GetClientIPNew();
                if (bc.banner_ipfrom == "::1")
                {
                    bc.banner_ipfrom = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName())[2].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["banner_content_id"]) && Request.Params["banner_image"] == oldImg)
                {
                    bc.banner_image = oldImg;
                }
                if (Request.Files["banner_image"] != null && Request.Files["banner_image"].ContentLength > 0)
                {
                    HttpPostedFileBase file = Request.Files["banner_image"];
                    if (file.ContentLength > int.Parse(minValue) * 1024 && file.ContentLength < int.Parse(maxValue) * 1024)
                    {
                        NewName = Path.GetFileName(file.FileName);
                        bool result = false;
                        string filename = NewName.Substring(0, NewName.LastIndexOf("."));
                        //獲得文件的後綴名
                        fileExtention = NewName.Substring(NewName.LastIndexOf(".")).ToLower();
                        //新的文件名是哈希字符串
                        BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                        NewFileName = hash.Md5Encrypt(filename, "32");

                        string firstFolder = NewFileName.Substring(0, 2) + "/";
                        string secondFolder = NewFileName.Substring(2, 2) + "/";
                        NewFileName = NewFileName + fileExtention;
                        NewName = NewFileName;
                        string ServerPath = string.Empty;
                        string localPromoDirectory = Server.MapPath(localPromoPath);
                        if (!System.IO.Directory.Exists(localPromoDirectory))
                        {
                            System.IO.Directory.CreateDirectory(localPromoDirectory);
                        }
                        FTP ftp = new FTP();
                        string directorys = promoPath + firstFolder + secondFolder;
                        ftp.MakeMultiDirectory(imgLocalPath+"/", directorys.Substring(1, directorys.Length - 2).Split('/'), ftpuser, ftppwd);
                        //NewFileName = localPromoPath + NewFileName;//絕對路徑
                        ServerPath = Server.MapPath(localPromoPath + firstFolder + secondFolder);
                        string ErrorMsg = string.Empty;
                        //上傳
                        result = fileLoad.UpLoadFile(file, ServerPath, imgLocalPath + directorys + NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                        if (!result)
                        {
                            json = "{success:false,msg:'圖片上傳失敗!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        bc.banner_image = NewName;
                        string oldImgPath = string.Empty;
                        string ftppath = string.Empty;
                        if (oldImg.Length >= 4)
                        {
                            oldImgPath = localPromoPath + oldImg.Substring(0, 2) + "/" + oldImg.Substring(2, 2) + "/" + oldImg;
                        }
                        if (System.IO.File.Exists(Server.MapPath(oldImgPath)))
                        {
                            ftppath=imgLocalPath + promoPath + oldImg.Substring(0, 2) + "/" + oldImg.Substring(2, 2) + "/";
                            System.IO.File.Delete(Server.MapPath(oldImgPath));
                            FTP ftp1 = new FTP(ftppath, ftpuser, ftppwd);
                            List<string> tem = ftp1.GetFileList();
                            if (tem.Contains(oldImg))
                            {
                                FTP ftps = new FTP(ftppath + oldImg, ftpuser, ftppwd);
                                ftps.DeleteFile(ftppath + oldImg);
                            }
                        }
                    }
                    else
                    {
                        json = "{success:false,msg:'上傳圖片不能超過" + maxValue + "K'}";
                        this.Response.Clear();
                        this.Response.Write(json);
                        this.Response.End();
                        return this.Response;
                    }
                }
                
                #region 新增
                if (String.IsNullOrEmpty(Request.Params["banner_content_id"]))
                {
                    bc.banner_content_id = uint.Parse((serial.Serial_Value + 1).ToString());
                    if (_bcMgr.Add(bc) > 0)
                    {
                        serial.Serial_Value = serial.Serial_Value + 1;/*所在操作表的列增加*/
                        _ISerImplMgr.Update(serial);/*修改所在的表的列對應的值*/
                        json = "{success:true,msg:\"" + "新增成功!" + "\"}";
                    }

                }
                #endregion
                #region 編輯
                else
                {
                    bc.banner_content_id = uint.Parse(Request.Params["banner_content_id"]);
                    if (_bcMgr.Update(bc) > 0)
                    {
                        json = "{success:true,msg:\"" + "修改成功!" + "\"}";
                    }

                }
                #endregion
            }
            catch (Exception ex)
            {
                json = "{success:false,msg:\"" + "異常" + "\"}";
                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 SecondSaveGift()
        {
            string jsonStr = String.Empty;
            try
            {
                string rowID = Request.Params["rowid"].ToString();
                string isEdit = Request.Params["isEdit"].ToString();
                _promoAmountGiftMgr = new PromotionsAmountGiftMgr(mySqlConnectionString);
                PromotionsAmountGiftQuery model = new PromotionsAmountGiftQuery();
                PromotionsAmountGiftQuery OldModel = _promoAmountGiftMgr.Select(Convert.ToInt32(rowID));
                OldModel.event_id = CommonFunction.GetEventId(OldModel.event_type, OldModel.id.ToString());

                #region 獲取數據
                if (!string.IsNullOrEmpty(Request.Params["rowid"]))
                {
                    model.id = Convert.ToInt32(Request.Params["rowid"]);
                }
                else
                {
                    model.id = OldModel.id;
                }
                model.category_id = OldModel.category_id;
                if (!string.IsNullOrEmpty(Request.Params["event_name"]))
                {
                    model.name = Request.Params["event_name"].ToString();
                }
                else
                {
                    model.name = OldModel.name;
                }
                if (!string.IsNullOrEmpty(Request.Params["event_desc"]))
                {
                    model.event_desc = Request.Params["event_desc"].ToString();
                }
                else
                {
                    model.event_desc = OldModel.event_desc;
                }
                if (!string.IsNullOrEmpty(Request.Params["vendor_coverage"]))
                {
                    model.vendor_coverage = Convert.ToInt32(Request.Params["vendor_coverage"].ToString());
                }
                else
                {
                    model.vendor_coverage = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["event_type"]))
                {
                    model.event_type = Request.Params["event_type"].ToString();
                }
                else
                {
                    model.event_type = OldModel.event_type;
                }
                if (Request.Params["amount"].ToString() != "" && Request.Params["amount"].ToString() != "0")
                {
                    if (!string.IsNullOrEmpty(Request.Params["amount"]))
                    {

                        model.amount = Convert.ToInt32(Request.Params["amount"].ToString());
                        model.quantity = 0;
                    }
                    else
                    {
                        model.amount = OldModel.amount;
                        model.quantity = 0;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(Request.Params["quantity"]))
                    {
                        model.quantity = Convert.ToInt32(Request.Params["quantity"].ToString());
                        model.amount = 0;
                    }
                    else
                    {
                        model.quantity = OldModel.quantity;
                        model.amount = 0;
                    }
                }

                if (model.id != 0)
                {
                    model.event_id = CommonFunction.GetEventId(model.event_type, model.id.ToString());
                }
                else
                {
                    model.event_id = CommonFunction.GetEventId(OldModel.event_type, OldModel.id.ToString());
                }
                #endregion

                #region 講圖片和鏈接保存至product_category中
                ////講圖片和鏈接保存至product_category中
                if (!string.IsNullOrEmpty(Request.Params["url_by"]))
                {
                    model.url_by = Convert.ToInt32(Request.Params["url_by"].ToString());
                    if (model.url_by == 1)//是專區
                    {
                        #region 上傳圖片
                        try
                        {
                            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_MinValue");
                            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;//圖片存儲地址

                            Random rand = new Random();
                            int newRand = rand.Next(1000, 9999);

                            FileManagement fileLoad = new FileManagement();

                            for (int iFile = 0; iFile < Request.Files.Count; iFile++)
                            {
                                HttpPostedFileBase file = Request.Files[iFile];
                                string fileName = string.Empty;//當前文件名

                                string fileExtention = string.Empty;//當前文件的擴展名

                                fileName = Path.GetFileName(file.FileName);

                                // string returnName = imgServerPath;
                                bool result = false;
                                string NewFileName = string.Empty;

                                fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                                NewFileName = model.event_id + newRand + fileExtention;

                                string ServerPath = string.Empty;
                                //判斷目錄是否存在,不存在則創建
                                //string[] mapPath = new string[1];
                                //mapPath[0] = promoPath.Substring(1, promoPath.Length - 2);
                                //string s = localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1);
                                CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'));

                                //  returnName += promoPath + NewFileName;
                                fileName = NewFileName;
                                NewFileName = localPromoPath + NewFileName;//絕對路徑
                                ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                                string ErrorMsg = string.Empty;


                                //上傳之前刪除已有的圖片
                                string oldFileName = OldModel.banner_image;
                                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);//刪除ftp:71.159上的舊圖片
                                    DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                                }

                                try
                                {
                                    //上傳
                                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                    if (result)//上傳成功
                                    {
                                        model.banner_image = fileName;
                                    }
                                }
                                catch (Exception)
                                {
                                    model.banner_image = OldModel.banner_image;
                                }
                            }
                        }
                        catch (Exception)
                        {
                            model.banner_image = OldModel.banner_image;
                        }

                        #endregion
                        if (!string.IsNullOrEmpty(Request.Params["banner_url"]))
                        {
                            model.category_link_url = Request.Params["banner_url"].ToString();
                        }
                        else
                        {
                            model.category_link_url = OldModel.category_link_url;
                        }

                        if (!string.IsNullOrEmpty(Request.Params["sbrand_id"].ToString()))
                        {
                            int brandTranId = 0;
                            if (int.TryParse(Request.Params["sbrand_id"].ToString(), out  brandTranId))
                            {
                                model.brand_id = Convert.ToInt32(Request.Params["sbrand_id"].ToString());
                            }
                            else
                            {
                                model.brand_id = OldModel.brand_id;
                            }
                        }
                        else
                        {
                            model.brand_id = 0;
                        }


                        if (!string.IsNullOrEmpty(Request.Params["sclass_id"].ToString()))
                        {
                            int classTranId = 0;
                            if (int.TryParse(Request.Params["sclass_id"].ToString(), out classTranId))
                            {
                                model.class_id = Convert.ToInt32(Request.Params["sclass_id"].ToString());

                            }
                            else
                            {
                                model.class_id = OldModel.class_id;
                            }
                        }
                        else
                        {
                            model.class_id = 0;
                        }

                        if (!string.IsNullOrEmpty(Request.Params["allClass"]))
                        {
                            if (Request.Params["allClass"] == "1")
                            {
                                model.quanguan = 1;
                                model.class_id = 0;
                                model.brand_id = 0;
                                model.product_id = 999999;
                            }
                            else
                            {
                                model.quanguan = 0;
                            }
                        }
                    }
                    else//非專區
                    {
                        model.category_link_url = "";
                        model.banner_image = "";

                        if (!string.IsNullOrEmpty(Request.Params["nobrand_id"].ToString()))
                        {
                            int brandTranId = 0;
                            if (int.TryParse(Request.Params["nobrand_id"].ToString(), out  brandTranId))
                            {
                                model.brand_id = Convert.ToInt32(Request.Params["nobrand_id"].ToString());
                            }
                            else
                            {
                                model.brand_id = OldModel.brand_id;
                            }
                        }
                        else
                        {
                            model.brand_id = OldModel.brand_id;
                        }


                        if (!string.IsNullOrEmpty(Request.Params["noclass_id"].ToString()))
                        {
                            int classTranId = 0;
                            if (int.TryParse(Request.Params["noclass_id"].ToString(), out classTranId))
                            {
                                model.class_id = Convert.ToInt32(Request.Params["noclass_id"].ToString());

                            }
                            else
                            {
                                model.class_id = OldModel.class_id;
                            }
                        }
                        else
                        {
                            model.class_id = OldModel.class_id;
                        }

                        if (!string.IsNullOrEmpty(Request.Params["product_id"]))
                        {
                            model.product_id = Convert.ToInt32(Request.Params["product_id"].ToString());
                        }
                        else
                        {
                            model.product_id = OldModel.product_id;
                        }

                        if (!string.IsNullOrEmpty(Request.Params["noallClass"]))
                        {
                            if (Request.Params["noallClass"] == "1" || Request.Params["noallClass"] == "true")
                            {
                                model.quanguan = 1;
                                model.class_id = 0;
                                model.brand_id = 0;
                                model.product_id = 999999;
                            }
                            else
                            {
                                model.quanguan = 0;
                            }
                        }
                    }
                }
                else
                {
                    model.url_by = OldModel.url_by;
                }
                #endregion

                #region 獲取數據
                if (Request.Params["group_id"].ToString() != "")
                {
                    int groupTryId = 0;
                    if (!string.IsNullOrEmpty(Request.Params["group_id"].ToString()) && int.TryParse(Request.Params["group_id"].ToString(), out groupTryId))
                    {
                        model.group_id = Convert.ToInt32(Request.Params["group_id"].ToString());
                    }
                    else
                    {
                        model.group_id = OldModel.group_id;
                    }

                    if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0")
                    {
                        UserCondition uc = new UserCondition();
                        uc.condition_id = Convert.ToInt32(Request.Params["condition_id"]);
                        if (_ucMgr.Delete(uc) > 0)
                        {
                            jsonStr = "{success:true}";
                            model.condition_id = 0;
                        }
                        else
                        {
                            jsonStr = "{success:false,msg:'user_condition刪除出錯!'}";
                            this.Response.Clear();
                            this.Response.Write(jsonStr.ToString());
                            this.Response.End();
                            return this.Response;
                        }
                    }
                }
                else if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0")
                {
                    if (!string.IsNullOrEmpty(Request.Params["condition_id"]))//condition_id
                    {
                        model.condition_id = Convert.ToInt32(Request.Params["condition_id"].ToString());
                    }
                    else
                    {
                        model.condition_id = OldModel.condition_id;
                    }
                    model.group_id = 0;
                }


                if (!string.IsNullOrEmpty(Request.Params["count_by"]))
                {
                    model.count_by = Convert.ToInt32(Request.Params["count_by"].ToString());
                }
                else
                {
                    model.count_by = OldModel.count_by;
                }
                if (!string.IsNullOrEmpty(Request.Params["numLimit"]))
                {
                    model.num_limit = Convert.ToInt32(Request.Params["numLimit"].ToString());
                }
                else
                {
                    model.num_limit = OldModel.num_limit;
                }
                if (!string.IsNullOrEmpty(Request.Params["IsRepeat"]))
                {
                    model.repeat = Convert.ToInt32(Request.Params["IsRepeat"].ToString()) == 1 ? true : false;
                }
                else
                {
                    model.repeat = OldModel.repeat;
                }
                if (!string.IsNullOrEmpty(Request.Params["frieghttype"].ToString()))
                {
                    int typeId = 0;
                    if (int.TryParse(Request.Params["frieghttype"].ToString(), out typeId))
                    {
                        model.type = Convert.ToInt32(Request.Params["frieghttype"].ToString());
                    }
                    else
                    {
                        model.type = OldModel.type;
                    }
                }
                else
                {
                    model.type = OldModel.type;
                }
                if (!string.IsNullOrEmpty(Request.Params["devicename"]))
                {
                    model.device = Convert.ToInt32(Request.Params["devicename"].ToString());
                }
                else
                {
                    model.device = OldModel.device;
                }
                if (!string.IsNullOrEmpty(Request.Params["payment"].ToString()))
                {
                    Regex reg = new Regex("^([0-9]+,)*[0-9]+$");
                    if (reg.IsMatch(Request.Params["payment"].ToString()))
                    {
                        model.payment_code = Request.Params["payment"].ToString();
                    }
                    else
                    {
                        model.payment_code = OldModel.payment_code;
                    }
                }

                if (!string.IsNullOrEmpty(Request.Params["start_time"]))
                {
                    model.startdate = Convert.ToDateTime(Request.Params["start_time"].ToString());
                }
                else
                {
                    model.startdate = OldModel.startdate;
                }
                if (!string.IsNullOrEmpty(Request.Params["end_time"]))
                {
                    model.enddate = Convert.ToDateTime(Request.Params["end_time"].ToString());
                }
                else
                {
                    model.enddate = OldModel.enddate;
                }
                //int siteTranId = 0;
                //if (!string.IsNullOrEmpty(Request.Params["site"].ToString()) && int.TryParse(Request.Params["site"].ToString(), out siteTranId))//site
                //{
                //    model.site = Convert.ToInt32(Request.Params["site"].ToString());
                //}
                //else
                //{
                //    model.site = OldModel.site;
                //}
                if (!string.IsNullOrEmpty(Request.Params["site"].ToString()))//修改時傳的值為siteName
                {

                    Regex reg = new Regex("^([0-9]+,)*[0-9]+$");
                    if (reg.IsMatch(Request.Params["site"].ToString()))
                    {
                        model.site = Request.Params["site"].ToString();// 將站台改為多選 edit by shuangshuang0420j 20140925 10:08
                    }
                    else
                    {
                        model.site = OldModel.site;
                    }
                }
                #endregion

                #region 贈品處理
                if (!string.IsNullOrEmpty(Request.Params["gift_type"]))//gift_type when 1 then '商品' WHEN 2 then '機會' when 3  then '購物金' when 4 then '抵用券' 
                {
                    model.gift_type = Convert.ToInt32(Request.Params["gift_type"].ToString());
                    if (OldModel.gift_type == 2)
                    {
                        if (model.gift_type == 2)
                        {
                            if (OldModel.ticket_id != 0)
                            {
                                model.ticket_id = OldModel.ticket_id;
                            }
                            else
                            {
                                model.ticket_id = 0;
                            }
                            model.ticket_name = model.name;
                        }
                        else
                        {
                            if (_ptMgr.Delete(OldModel.ticket_id) > 0)
                            {
                                jsonStr = "{success:success}";
                                model.ticket_id = 0;
                                model.ticket_name = "";
                            }
                            else
                            {
                                jsonStr = "{success:false,msg:'promo_ticket刪除出錯!'}";
                                this.Response.Clear();
                                this.Response.Write(jsonStr.ToString());
                                this.Response.End();
                                return this.Response;
                            }
                        }
                    }
                    if (model.gift_type == 1)
                    {
                        model.gift_id = Convert.ToInt32(Request.Params["gift_id"].ToString());
                        model.gift_product_number = Convert.ToInt32(Request.Params["gift_product_number"].ToString());
                    }
                    else if (model.gift_type == 3)
                    {
                        model.bonus_type = 1;
                    }
                    else if (model.gift_type == 4)
                    {
                        model.bonus_type = 2;
                    }



                    if (!string.IsNullOrEmpty(Request.Params["activeNow"]))
                    {
                        model.active_now = Convert.ToInt32(Request.Params["activeNow"].ToString());
                    }
                    else
                    {
                        model.active_now = OldModel.active_now;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["startdate"]))
                    {
                        model.use_start = Convert.ToDateTime(Request.Params["startdate"].ToString());
                    }
                    else
                    {

                        model.use_start = OldModel.use_start;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["enddate"]))
                    {
                        model.use_end = Convert.ToDateTime(Request.Params["enddate"].ToString());
                    }
                    else
                    {

                        model.use_end = OldModel.use_end;
                    }
                    try
                    {
                        TimeSpan ts1 = new TimeSpan(model.use_end.Ticks);
                        TimeSpan ts2 = new TimeSpan(model.use_start.Ticks);
                        TimeSpan ts3 = ts1.Subtract(ts2).Duration();
                        int isAddDay = ts3.Hours > 0 ? 1 : 0;
                        model.valid_interval = ts3.Days + isAddDay;
                    }
                    catch
                    {
                        model.valid_interval = OldModel.valid_interval;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["bonusAmount"]))
                    {
                        model.deduct_welfare = Convert.ToUInt32(Request.Params["bonusAmount"].ToString());
                    }
                    else
                    {
                        model.deduct_welfare = OldModel.deduct_welfare;
                    }
                }
                else
                {
                    model.gift_type = OldModel.gift_type;
                    model.ticket_id = OldModel.ticket_id;
                    model.ticket_name = OldModel.ticket_name;
                }
                #endregion

                model.status = 1;


                _promoAmountGiftMgr = new PromotionsAmountGiftMgr(mySqlConnectionString);
                if (string.IsNullOrEmpty(isEdit))
                {
                    model.kuser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                    model.created = DateTime.Now;
                    model.muser = model.kuser;
                    model.modified = model.created;
                    if (_promoAmountGiftMgr.Update(model, OldModel.event_id) > 0)
                    {
                        jsonStr = "{success:true,msg:0}";//返回json數據
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:0}";//返回json數據
                    }
                }
                else
                {
                    model.kuser = OldModel.kuser;
                    model.created = OldModel.created;
                    model.muser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                    model.modified = DateTime.Now;

                    if (_promoAmountGiftMgr.Update(model, OldModel.event_id) > 0)
                    {

                        jsonStr = "{success:true,msg:0}";//返回json數據
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:0}";//返回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);
                jsonStr = "{success:false,msg:0}";
            }
            this.Response.Clear();
            this.Response.Write(jsonStr.ToString());
            this.Response.End();
            return this.Response;
        }
Esempio n. 22
0
        public HttpResponseBase SaveChinatrust()
        {
            string json = string.Empty;
            try
            {
                _eventChinatrust = new EventChinatrustMgr(mySqlConnectionString);
                FileManagement fileLoad = new FileManagement();
                EventChinatrustQuery query = new EventChinatrustQuery();
                EventChinatrustQuery oldModel = new EventChinatrustQuery();
                List<EventChinatrustQuery> store = new List<EventChinatrustQuery>();
                if (!string.IsNullOrEmpty(Request.Params["row_id"]))
                {//如果是編輯獲取該id數據
                    int totalCount = 0;
                    query.IsPage = false;
                    query.event_active = -1;
                    query.row_id = int.Parse(Request.Params["row_id"]);
                    store = _eventChinatrust.GetEventChinatrustList(query, out totalCount);
                }
                #region 需要更改的屬性
                if (!string.IsNullOrEmpty(Request.Params["row_id"]))
                {
                    query.row_id = Convert.ToInt32(Request.Params["row_id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["event_name"]))
                {
                    query.event_name = Request.Params["event_name"];
                }
                if (!string.IsNullOrEmpty(Request.Params["event_desc"]))
                {
                    query.event_desc = Request.Params["event_desc"];
                }
                if (!string.IsNullOrEmpty(Request.Params["event_start_time"]))
                {
                    query.event_start_time = DateTime.Parse(Request.Params["event_start_time"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["event_end_time"]))
                {
                    query.event_end_time = DateTime.Parse(Request.Params["event_end_time"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["user_register_time"]))
                { 
                    query.user_register_time=DateTime.Parse(Request.Params["user_register_time"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["event_banner"]))
                {
                    query.event_banner = Request.Params["event_banner"];
                }
                #endregion
                query.event_type = "EC";
                #region 上傳圖片
                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 + PaperPath;//圖片存儲地址

                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;
                        BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                        NewFileName = hash.Md5Encrypt(fileName, "32");
                        string ServerPath = string.Empty;
                        FTP f_cf = new FTP();
                        f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1), PaperPath.Substring(1, PaperPath.Length - 2).Split('/'), ftpuser, ftppwd);
                        fileName = NewFileName + fileExtention;
                        NewFileName = localPromoPath + NewFileName + fileExtention;//絕對路徑
                        ServerPath = Server.MapPath(imgLocalServerPath + PaperPath);
                        string ErrorMsg = string.Empty;
                        //上傳之前刪除已有的圖片
                        if (query.row_id != 0)
                        {
                            oldModel = store.FirstOrDefault();
                            if (oldModel.event_banner != "")
                            {
                                string oldFileName = oldModel.event_banner;
                                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");//尋找product.resx中的資源文件
                            bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                            if (result)
                            {
                                query.event_banner = 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();
                            return this.Response;
                        }
                    }

                }
                #endregion
                if (query.row_id == 0)
                {
                    query.event_create_time = DateTime.Now;
                    query.event_update_time = query.event_create_time;
                    query.event_create_user = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id);
                    query.event_update_user = query.event_create_user;
                    if (_eventChinatrust.AddEventChinatrust(query) > 0)
                    {
                        json = "{success:true }";
                    }
                    else
                    {
                        json = "{success:false,msg:'新增失敗!'}";
                    }
                }
                else
                {
                    query.event_update_time = DateTime.Now;
                    query.event_update_user = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id);
                    if (_eventChinatrust.UpdateEventChinatrust(query) > 0)
                    {
                        json = "{success:true }";
                    }
                    else
                    {
                        json = "{success:false,msg:'修改失敗!'}";
                    }
                }
            }
            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.ToString());
            this.Response.End();
            return this.Response;
        }
Esempio n. 23
0
        public MailModel GetDeafultMailConfig(MailModel mailModel)
        {
            try
            {
                string xmlPath = System.Configuration.ConfigurationManager.AppSettings["SiteConfig"];//
                string path = System.Web.HttpContext.Current.Server.MapPath(xmlPath);
                SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
                BLL.gigade.Model.SiteConfig NETDoMain_Name;

                if (string.IsNullOrEmpty(mailModel.MailFromAddress))
                {
                    NETDoMain_Name = _siteConfigMgr.GetConfigByName("Mail_From");
                    mailModel.MailFromAddress = NETDoMain_Name.Value;
                }
                if (string.IsNullOrEmpty(mailModel.MailFromUser))
                {
                    NETDoMain_Name = _siteConfigMgr.GetConfigByName("Mail_UserName");
                    mailModel.MailFromUser = NETDoMain_Name.Value;
                }
                if (string.IsNullOrEmpty(mailModel.MailFormPwd))
                {
                    NETDoMain_Name = _siteConfigMgr.GetConfigByName("Mail_UserPasswd");
                    mailModel.MailFormPwd = NETDoMain_Name.Value;
                }
                if (string.IsNullOrEmpty(mailModel.MailPort))
                {
                    NETDoMain_Name = _siteConfigMgr.GetConfigByName("Mail_Port");
                    mailModel.MailPort = NETDoMain_Name.Value;
                }
                if (string.IsNullOrEmpty(mailModel.MailHost))
                {
                    NETDoMain_Name = _siteConfigMgr.GetConfigByName("Mail_Host");
                    mailModel.MailHost = NETDoMain_Name.Value;
                }
                
                return mailModel;

            }
            catch (Exception ex)
            {
                throw new Exception("ScheduleServiceMgr-->GetDeafultMailConfig-->" + ex.Message);
            }
        }
Esempio n. 24
0
        public HttpResponseBase EventChinaTrustBagSave()
        {
            string json = string.Empty;
            EventChinaTrustBagQuery query = new EventChinaTrustBagQuery();
            EventChinaTrustBagQuery oldModel = new EventChinaTrustBagQuery();
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["event_id"]))
                {
                    query.event_id = Request.Params["event_id"];
                }
                if (!string.IsNullOrEmpty(Request.Params["bag_name"]))
                {
                    query.bag_name = Request.Params["bag_name"];
                }
                if (!string.IsNullOrEmpty(Request.Params["bag_desc"]))
                {
                    query.bag_desc = Request.Params["bag_desc"];
                }
                if (!string.IsNullOrEmpty(Request.Params["bag_banner"]))
                {
                    query.bag_banner = Request.Params["bag_banner"];
                }
                if (!string.IsNullOrEmpty(Request.Params["bag_start_time"]))
                {
                    query.bag_start_time =Convert.ToDateTime( Request.Params["bag_start_time"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["bag_end_time"]))
                {
                    query.bag_end_time = Convert.ToDateTime(Request.Params["bag_end_time"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["bag_show_start_time"]))
                {
                    query.bag_show_start_time =  Convert.ToDateTime(Request.Params["bag_show_start_time"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["bag_show_end_time"]))
                {
                    query.bag_show_end_time =Convert.ToDateTime(Request.Params["bag_show_end_time"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["product_number"]))
                {
                    query.product_number =Convert.ToInt32(Request.Params["product_number"]);
                }
                if (string.IsNullOrEmpty(Request.Params["bag_id"]))//新增
                {
                    query.bag_create_user=(Session["caller"] as Caller).user_id;
                    query.bag_update_user = (Session["caller"] as Caller).user_id;
                    query.bag_create_time = DateTime.Now;
                    query.bag_update_time = query.bag_create_time;
                }
                else//編輯
                {
                    query.bag_id = Convert.ToInt32(Request.Params["bag_id"]);
                    query.bag_update_time = DateTime.Now;
                    query.bag_update_user = (Session["caller"] as Caller).user_id;
                }
                _eventChinaTrustBag = new EventChinaTrustBagMgr(mySqlConnectionString);
                #region  上傳圖片
                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 + PaperPath;//圖片存儲地址
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase file = Request.Files[0];
                    string fileName = string.Empty;//當前文件名
                    string fileExtention = string.Empty;//當前文件的擴展名
                    FileManagement fileLoad = new FileManagement();
                    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;
                        BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                        NewFileName = hash.Md5Encrypt(fileName, "32");
                        string ServerPath = string.Empty;
                        FTP f_cf = new FTP();
                        f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1), PaperPath.Substring(1, PaperPath.Length - 2).Split('/'), ftpuser, ftppwd);
                        fileName = NewFileName + fileExtention;
                        NewFileName = localPromoPath + NewFileName + fileExtention;//絕對路徑
                        ServerPath = Server.MapPath(imgLocalServerPath + PaperPath);
                        string ErrorMsg = string.Empty;
                        if (query.bag_id != 0)
                        {
                            oldModel = _eventChinaTrustBag.GetSinggleData(query);
                            if (oldModel.bag_banner != "")
                                {
                                    string oldFileName = oldModel.bag_banner;
                                    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.bag_banner = 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.bag_banner = oldModel.bag_banner;
                }
                #endregion
          
                if (_eventChinaTrustBag.EventChinaTrustBagSave(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;
        }
        /// <summary>
        /// 執行單個排程;只添加日誌
        /// </summary>
        /// <param name="schedule_api"></param>
        /// <param name="schedule_code"></param>
        /// <returns></returns>
        public bool ExeScheduleService(string schedule_api,string schedule_code)
        {
            bool result = false;
            try
            {
                //執行排程
                string path = System.Web.HttpContext.Current.Server.MapPath(xmlPath);
                SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
                BLL.gigade.Model.SiteConfig NETDoMain_Name = _siteConfigMgr.GetConfigByName("NETDoMain_Name");

                string api = "http://" + NETDoMain_Name.Value + "/" + schedule_api + "?schedule_code=" + schedule_code; ;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                result = _secheduleServiceMgr.ExeScheduleService(api);
                if (result)
                {
                    //添加排程日誌
                    ScheduleAddLog(schedule_code);
                }
                
            }
            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 result;
        }        
Esempio n. 26
0
        public HttpResponseBase SaveChinaTrustBagMap()
        {
            string json = string.Empty;
            bool pic = true;
            DataTable dt = new DataTable();
            try
            {
                _ChinatrustBMMgr = new EventChinaTrustBagMapMgr(mySqlConnectionString);
                EventChinaTrustBagMapQuery store = new EventChinaTrustBagMapQuery();
                EventChinaTrustBagMapQuery query = new EventChinaTrustBagMapQuery();
                if (!string.IsNullOrEmpty(Request.Params["id"]))
                {//如果是編輯獲取該id數據
                    int totalCount = 0;
                    query.IsPage = false;
                    query.map_id = int.Parse(Request.Params["id"]);
                    store = _ChinatrustBMMgr.GetChinaTrustBagMapList(query, out totalCount).FirstOrDefault();
                    query = store;
                }
                //product_id
                if (!string.IsNullOrEmpty(Request.Params["product_id"]))
                {
                    query.product_id = Convert.ToUInt32(Request.Params["product_id"]);
                }
                else
                {
                    query.product_id = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["bag_id"]))
                {
                    query.bag_id = Convert.ToInt32(Request.Params["bag_id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["linkurl"]))
                {
                    query.linkurl = Request.Params["linkurl"];
                }
                if (!string.IsNullOrEmpty(Request.Params["product_forbid_banner"]))
                {
                    query.product_forbid_banner = Request.Params["product_forbid_banner"];
                }
                if (!string.IsNullOrEmpty(Request.Params["product_active_banner"]))
                {
                    query.product_active_banner = Request.Params["product_active_banner"];
                }
                if (!string.IsNullOrEmpty(Request.Params["ad_product_id"]))
                {
                    string p_id = Request.Params["ad_product_id"];
                    RegexOptions options = RegexOptions.None;
                    Regex regex = new Regex(@"[ ]{2,}", options);
                    p_id = regex.Replace(p_id, @" ");
                    p_id = p_id.Replace(" ", ",");
                    for (int i = p_id.Length - 1; i > 0; i--)
                    {
                        if (p_id.Substring(p_id.Length - 1, 1) == ",")
                        {
                            p_id = p_id.Substring(0, p_id.Length - 1);
                        }
                    }
                    string[] pr_id = p_id.Split(',').Distinct().ToArray(); ;
                    string pro_id = "";
                    for (int i = 0; i < pr_id.Length; i++)
                    {
                        if (_ChinatrustBMMgr.IsProductId(pr_id[i].ToString()))
                        {
                            pro_id += pr_id[i].ToString() + ",";
                        }
                    }
                    if (pro_id.Length > 0)
                    {
                        query.ad_product_id = pro_id.Substring(0, pro_id.Length - 1);
                    }
                    else
                    {
                        query.ad_product_id = null;
                    }
                }
                else
                {
                    query.ad_product_id = null;
                }
                if (!string.IsNullOrEmpty(Request.Params["product_desc"]))
                {
                    query.product_desc = Request.Params["product_desc"];
                }
                else
                {
                    query.product_desc = null;
                }
                #region 上傳圖片
                try
                {
                    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_MinValue");
                    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 + PaperPath;//圖片存儲地址
                    Random rand = new Random();
                    FileManagement fileLoad = new FileManagement();
                    for (int iFile = 0; iFile < Request.Files.Count; iFile++)
                    {
                        //int newRand = rand.Next(1000, 9999);
                        HttpPostedFileBase file = Request.Files[iFile];
                        string fileName = string.Empty;//當前文件名
                        string fileExtention = string.Empty;//當前文件的擴展名
                        bool result = false;
                        string NewFileName = string.Empty;
                        string ServerPath = string.Empty;
                        fileName = Path.GetFileName(file.FileName);
                        string newRand = hash.Md5Encrypt(fileLoad.NewFileName(fileName), "32");
                        string ErrorMsg = string.Empty;
                        if (iFile == 0)
                        {
                            if (string.IsNullOrEmpty(file.FileName))
                            {
                                query.product_forbid_banner = store.product_forbid_banner;
                            }
                            else
                            {
                                fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                                NewFileName = newRand + fileExtention;
                                //判斷目錄是否存在,不存在則創建
                                string[] mapPath = new string[1];
                                mapPath[0] = PaperPath.Substring(1, PaperPath.Length - 1);
                                string s = localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1);
                                CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1), mapPath);
                                //  returnName += PaperPath + NewFileName;
                                fileName = NewFileName;
                                NewFileName = localPromoPath + NewFileName;//絕對路徑
                                ServerPath = Server.MapPath(imgLocalServerPath + PaperPath);
                                string oldFileName = "";
                                oldFileName = store.product_forbid_banner;
                                if (!string.IsNullOrEmpty(oldFileName))
                                {
                                    DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                                }
                                try
                                {   //上傳
                                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                    if (result)//上傳成功
                                    {
                                        query.product_forbid_banner = fileName;
                                    }
                                    else
                                    {
                                        pic = false;
                                    }
                                }
                                catch (Exception)
                                {
                                    query.product_forbid_banner = store.product_forbid_banner;
                                    query.product_active_banner = store.product_active_banner;
                                }
                            }
                        }
                        if (iFile == 1)
                        {
                            if (string.IsNullOrEmpty(file.FileName))
                            {
                                query.product_active_banner = store.product_active_banner;
                            }
                            else
                            {
                                fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                                NewFileName = newRand + fileExtention;
                                //判斷目錄是否存在,不存在則創建
                                string[] mapPath = new string[1];
                                mapPath[0] = PaperPath.Substring(1, PaperPath.Length - 1);
                                string s = localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1);
                                CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1), mapPath);
                                //  returnName += PaperPath + NewFileName;
                                fileName = NewFileName;

                                NewFileName = localPromoPath + NewFileName;//絕對路徑
                                ServerPath = Server.MapPath(imgLocalServerPath + PaperPath);
                                string oldFileName = "";
                                oldFileName = store.product_active_banner;
                                if (!string.IsNullOrEmpty(oldFileName))
                                {
                                    DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                                }
                                try
                                {
                                    //上傳
                                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                    if (result)//上傳成功
                                    {
                                        query.product_active_banner = fileName;
                                    }
                                    else
                                    {
                                        pic = false;
                                    }
                                }
                                catch (Exception)
                                {
                                    query.product_forbid_banner = store.product_forbid_banner;
                                    query.product_active_banner = store.product_active_banner;
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    query.product_forbid_banner = store.product_forbid_banner;
                    query.product_active_banner = store.product_active_banner;
                }
                #endregion             
              
                if (pic)
                {
                    if (query.map_id > 0)
                    {//編輯
                        if (!string.IsNullOrEmpty(Request.Params["map_sort"]))
                        {
                            query.map_sort = Convert.ToInt32(Request.Params["map_sort"]);
                        }
                        if (_ChinatrustBMMgr.Update(query) > 0)
                        {
                            json = "{success:true,msg:'修改成功!'}";
                        }
                        else
                        {
                            json = "{success:false,msg:'修改失敗!'}";
                        }
                    }
                    else
                    {//新增
                        dt = _ChinatrustBMMgr.GetMapSort(query);
                        if (dt.Rows.Count > 0)
                        {
                            query.map_sort = int.Parse(dt.Rows[0]["map_sort"].ToString()) + 1;
                        }
                        else
                        {
                            query.map_sort = 0;
                        }
                        query.map_active = 0;//默認不啟用
                        if (_ChinatrustBMMgr.Save(query) > 0)
                        {
                            json = "{success:true,msg:'新增成功!'}";
                        }
                        else
                        {
                            json = "{success:false,msg:'新增失敗!'}";
                        }
                    }
                }
                else
                {
                    json = "{success:false,msg:'圖片上傳失敗!'}";
                }
            }
            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,msg:'操作失敗!'}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Esempio n. 27
0
        public HttpResponseBase PromoPairEdit()
        {
            string jsonStr = String.Empty;
            _promopairMgr = new PromoPairMgr(mySqlConnectionString);
            PromoPair model = new PromoPair();
            PromoPair oldermodel = new PromoPair();
            PromoPairQuery PPQuery = new PromoPairQuery();
            ProductCategory olderpcmodel = new ProductCategory();
            PromoPairQuery oldPPQuery = new PromoPairQuery();
            if (!String.IsNullOrEmpty(Request.Params["rowid"]))
            {
                try
                {
                    model.id = Convert.ToInt32(Request.Params["rowid"].ToString());
                    model.category_id = Convert.ToInt32(Request.Params["categoryid"].ToString());
                    oldermodel = _promopairMgr.GetModelById(model.id);
                    olderpcmodel = _produCateMgr.GetModelById(Convert.ToUInt32(model.category_id));
                    model.event_name = Request.Params["event_name"].ToString();
                    model.event_desc = Request.Params["event_desc"].ToString();
                    model.event_type = oldermodel.event_type;
                    model.vendor_coverage = int.Parse(Request.Params["vendor_coverage"]);
                    #region 會員群組 會員條件
                    if (Request.Params["group_id"].ToString() != "")
                    {
                        try//group_id
                        {
                            model.group_id = Convert.ToInt32(Request.Params["group_id"].ToString());
                        }
                        catch (Exception)
                        {
                            model.group_id = oldermodel.group_id;
                        }

                        if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0")
                        {
                            UserCondition uc = new UserCondition();
                            uc.condition_id = Convert.ToInt32(Request.Params["condition_id"]);
                            if (_ucMgr.Delete(uc) > 0)
                            {
                                jsonStr = "{success:true}";

                            }
                            else
                            {
                                jsonStr = "{success:false,msg:'user_condition刪除出錯!'}";
                                this.Response.Clear();
                                this.Response.Write(jsonStr.ToString());
                                this.Response.End();
                                return this.Response;
                            }
                        }
                        model.condition_id = 0;
                    }
                    else if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0")
                    {
                        try//condition_id
                        {
                            model.condition_id = Convert.ToInt32(Request.Params["condition_id"].ToString());
                        }
                        catch (Exception)
                        {
                            model.condition_id = oldermodel.condition_id;
                        }
                        model.group_id = 0;
                    }
                    #endregion
                    model.deliver_type = Convert.ToInt32(Request.Params["deliver_id"].ToString());
                    model.device = Request.Params["device_id"].ToString();
                    //model.website = Request.Params["side"].ToString();
                    if (!string.IsNullOrEmpty(Request.Params["side"].ToString()))//修改時傳的值為siteName
                    {
                        Regex reg = new Regex("^([0-9]+,)*[0-9]+$");
                        if (reg.IsMatch(Request.Params["side"].ToString()))
                        {
                            model.website = Request.Params["side"].ToString();// 將站台改為多選 edit by shuangshuang0420j 20140925 10:08
                        }
                        else
                        {
                            model.website = oldermodel.website;
                        }
                    }
                    #region 紅+綠
                    if (Request.Params["price"].ToString() != "")
                    {
                        try//price
                        {
                            model.price = Convert.ToInt32(Request.Params["price"].ToString());
                        }
                        catch (Exception)
                        {
                            model.price = oldermodel.group_id;
                        }
                        model.discount = 0;
                    }
                    else if (Request.Params["discount"].ToString() != "")
                    {
                        try//discount
                        {
                            model.discount = Convert.ToInt32(Request.Params["discount"].ToString());
                        }
                        catch (Exception)
                        {
                            model.discount = oldermodel.condition_id;
                        }
                        model.price = 0;
                    }
                    #endregion
                    model.starts = Convert.ToDateTime(Request.Params["starts"].ToString());
                    model.end = Convert.ToDateTime(Request.Params["end"].ToString());
                    model.muser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                    model.modified = DateTime.Now;
                    PPQuery.event_id = CommonFunction.GetEventId(model.event_type, model.id.ToString());
                    #region 上傳圖片
                    try
                    {
                        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_MinValue");
                        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;//圖片存儲地址

                        Random rand = new Random();
                        int newRand = rand.Next(1000, 9999);

                        FileManagement fileLoad = new FileManagement();

                        for (int iFile = 0; iFile < Request.Files.Count; iFile++)
                        {
                            HttpPostedFileBase file = Request.Files[iFile];
                            string fileName = string.Empty;//當前文件名
                            string fileExtention = string.Empty;//當前文件的擴展名
                            fileName = Path.GetFileName(file.FileName);
                            // string returnName = imgServerPath;
                            bool result = false;
                            string NewFileName = string.Empty;

                            fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                            NewFileName = PPQuery.event_id + newRand + fileExtention;

                            string ServerPath = string.Empty;
                            //判斷目錄是否存在,不存在則創建
                            //string[] mapPath = new string[1];
                            //mapPath[0] = promoPath.Substring(1, promoPath.Length - 2);
                            //string s = localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1);
                            CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'));

                            //  returnName += promoPath + NewFileName;
                            fileName = NewFileName;
                            NewFileName = localPromoPath + NewFileName;//絕對路徑
                            ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                            string ErrorMsg = string.Empty;


                            //上傳之前刪除已有的圖片
                            string oldFileName = olderpcmodel.banner_image;
                            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);//刪除ftp:71.159上的舊圖片
                                DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                            }
                            try
                            {
                                //上傳
                                result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                if (result)//上傳成功
                                {
                                    PPQuery.banner_image = fileName;
                                }
                            }
                            catch (Exception)
                            {
                                PPQuery.banner_image = olderpcmodel.banner_image;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        PPQuery.banner_image = olderpcmodel.banner_image;
                    }
                    #endregion

                    #region  注釋上傳圖片
                    ////string nowtime = DateTime.Now.ToString("hhmm");
                    //Random rand = new Random();
                    //int nowtime = rand.Next(1000, 9999);
                    //try
                    //{
                    //    string saveFoler = Server.MapPath("~/aimg.gigade100.com/active/");
                    //    string savePath, fileName, oldsavePath;
                    //    for (int iFile = 0; iFile < Request.Files.Count; iFile++)
                    //    {
                    //        HttpPostedFileBase postedFile = Request.Files[iFile];
                    //        fileName = Path.GetFileName(postedFile.FileName);
                    //        if (fileName != "")
                    //        {
                    //            string fileType = fileName.Substring(fileName.LastIndexOf("."));
                    //            string newName = GetEventId(oldermodel.event_type, model.id.ToString()) + nowtime + fileType;
                    //            oldsavePath = olderpcmodel.banner_image;
                    //            oldsavePath = saveFoler + oldsavePath;
                    //            savePath = saveFoler + newName;                                 
                    //            if (System.IO.File.Exists(oldsavePath))
                    //            {//检查是否在服务器上已经存在用户上传的同名文件
                    //                System.IO.File.Delete(oldsavePath);
                    //            }
                    //            if (fileType.ToLower() == ".jpg" || fileType.ToLower() == ".png" || fileType.ToLower() == ".gif" || fileType.ToLower() == ".jpeg")
                    //            {
                    //                if (postedFile.ContentLength <= 300 * 1024)
                    //                {
                    //                    postedFile.SaveAs(savePath);
                    //                    PPQuery.banner_image = newName;
                    //                }
                    //                else
                    //                {
                    //                    jsonStr = "{success:false,msg:1}";
                    //                    this.Response.Clear();
                    //                    this.Response.Write(jsonStr.ToString());
                    //                    this.Response.End();
                    //                    return this.Response;
                    //                }
                    //            }
                    //            else
                    //            {
                    //                jsonStr = "{success:false,msg:2}";
                    //                this.Response.Clear();
                    //                this.Response.Write(jsonStr.ToString());
                    //                this.Response.End();
                    //                return this.Response;
                    //            }
                    //        }
                    //        else
                    //        {
                    //            PPQuery.banner_image = olderpcmodel.banner_image;
                    //        }
                    //    }
                    //}
                    //catch (Exception)
                    //{
                    //    PPQuery.banner_image = olderpcmodel.banner_image;
                    //}
                    #endregion
                    try//存連接地址 id是否也添加時間
                    {
                        PPQuery.category_link_url = phpwebhost + "/pair/red_green_match.php?event_id=" + PPQuery.event_id;
                    }
                    catch (Exception)
                    {
                        PPQuery.category_link_url = oldPPQuery.category_link_url;
                    }
                    //foreach (string rid in Request.Params["rowid"].ToString().Split('|'))
                    //{
                    //    if (!string.IsNullOrEmpty(rid))
                    //    {
                    //        query.id = Convert.ToInt32(rid);
                    //        _promopairMgr.Update(query);
                    //    }
                    //}                    
                    if (_promopairMgr.CategoryID(model).ToString() == "true")
                    {
                        _promopairMgr.Update(model, PPQuery);
                        jsonStr = "{success:true}";
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:3}";
                    }
                }
                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);
                    jsonStr = "{success:false}";
                }
            }
            this.Response.Clear();
            this.Response.Write(jsonStr);
            this.Response.End();
            return this.Response;
        }
Esempio n. 28
0
        public HttpResponseBase AddorEdit()
        {
            string json = string.Empty;
            string errorInfo = string.Empty;
            uint brand_id = 0;
            bool result = false;
            try
            {
                _promotionBannerMgr = new PromotionBannerMgr(mySqlConnectionString);
                int i = 0;
                PromotionBannerQuery query = new PromotionBannerQuery();
                PromotionBannerQuery oldquery = new PromotionBannerQuery();
                if (!string.IsNullOrEmpty(Request.Params["pb_id"]))
                {
                    oldquery.pb_id = Convert.ToInt32(Request.Params["pb_id"]);
                    List<PromotionBannerQuery> oldModel = _promotionBannerMgr.GetModelById(oldquery.pb_id);
                    if (oldModel != null)
                    {
                        query.pb_image = oldModel[0].pb_image;
                    }
                }
                #region 上傳圖片
                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_MinValue");
                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 + brandPath;//圖片存儲地址
                FileManagement fileLoad = new FileManagement();
                for (int j = 0; j < Request.Files.Count; j++)
                {
                    string fileName = string.Empty;//當前文件名
                    HttpPostedFileBase file = Request.Files[j];
                    fileName = Path.GetFileName(file.FileName);
                    if (string.IsNullOrEmpty(fileName))
                    {
                        continue;
                    }

                    fileLoad = new FileManagement();
                    string oldFileName = string.Empty;  //舊文件名
                    string fileExtention = string.Empty;//當前文件的擴展名                 
                    string NewFileName = string.Empty;
                    string ServerPath = string.Empty;
                    string newRand = string.Empty;
                    string ErrorMsg = string.Empty;

                    newRand = hash.Md5Encrypt(fileLoad.NewFileName(fileName) + DateTime.Now.ToString(), "32");
                    fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                    NewFileName = newRand + fileExtention;

                    string folder1 = NewFileName.Substring(0, 2) + "/"; //圖片名前兩碼
                    string folder2 = NewFileName.Substring(2, 2) + "/"; //圖片名第三四碼

                    FTP f_cf = new FTP();
                    localPromoPath = imgLocalPath + brandPath + folder1 + folder2;  //圖片存儲地址
                    string s = localPromoPath.Substring(0, localPromoPath.Length - (brandPath + folder1 + folder2).Length + 1);
                    f_cf.MakeMultiDirectory(s, (brandPath + folder1 + folder2).Substring(1, (brandPath + folder1 + folder2).Length - 2).Split('/'), ftpuser, ftppwd);
                    ServerPath = Server.MapPath(imgLocalServerPath + brandPath + folder1 + folder2);
                    fileName = NewFileName;
                    NewFileName = localPromoPath + NewFileName;//絕對路徑
                    Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件

                    //上傳
                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                    if (result)//上傳成功
                    {
                        query.pb_image = fileName;
                    }
                    else
                    {
                        errorInfo += ErrorMsg;
                    }
                }
                #endregion               
                if (!string.IsNullOrEmpty(Request.Params["image_link"]))
                {
                    query.pb_image_link = Request.Params["image_link"];
                }
                if (!string.IsNullOrEmpty(Request.Params["begin_time"]))
                {
                    query.pb_startdate = Convert.ToDateTime(Request.Params["begin_time"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["end_time"]))
                {
                    query.pb_enddate = Convert.ToDateTime(Request.Params["end_time"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["vb_ids"]))
                {
                    query.brandIDS = Request.Params["vb_ids"].Substring(0, Request.Params["vb_ids"].LastIndexOf(','));
                }
                if (!string.IsNullOrEmpty(Request.Params["multi"]))
                {
                    query.multi = Convert.ToInt32(Request.Params["multi"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["pb_id"]))
                {
                    //編輯
                    query.pb_id = Convert.ToInt32(Request.Params["pb_id"]);
                    query.pb_muser = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id);
                    result = _promotionBannerMgr.UpdateImageInfo(query, out brand_id);
                    if (result && string.IsNullOrEmpty(errorInfo))
                    {
                        json = "{success:true}"; 
                    }
                    else if (result == false && brand_id != 0)
                    {
                        json = "{success:false,msg:\"" + brand_id + "\"}";//brand_id重複
                    }

                    else if (result && !string.IsNullOrEmpty(errorInfo))
                    {
                        json = "{success:true,msg:\"數據保存成功<br/>但圖片保存失敗 <br/>" + errorInfo + "\"}";
                    }
                    else
                    {
                        json = "{success:false}";
                    }
                }
                else
                {
                    //新增
                    query.pb_kuser = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id);
                    query.pb_muser = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id);
                    result = _promotionBannerMgr.AddImageInfo(query, out brand_id);
                    if (result && string.IsNullOrEmpty(errorInfo))
                    {
                        json = "{success:true}";
                    }
                    else if (result == false && brand_id != 0)
                    {
                        json = "{success:false,msg:\"" + brand_id + "\"}";//brand_id重複
                    }
                    else if (result && !string.IsNullOrEmpty(errorInfo))
                    {
                        json = "{success:true,msg:\"數據保存成功<br/>但圖片保存失敗 <br/>" + errorInfo + "\"}";
                    }
                    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.ToString());
            this.Response.End();
            return this.Response;
        }
Esempio n. 29
0
        public HttpResponseBase InsertNewPromoCarnet()
        {
            NewPromoCarnetQuery query = new NewPromoCarnetQuery();
            NewPromoCarnetQuery oldModel = new NewPromoCarnetQuery();
            _INewPromoCarnetMgr = new NewPromoCarnetMgr(mySqlConnectionString);
            string json = string.Empty;

            try
            {
                if (!string.IsNullOrEmpty(Request.Params["row_id"]))
                {
                    query.row_id = Convert.ToInt32(Request.Params["row_id"].ToString());
                }
                if (!string.IsNullOrEmpty(Request.Params["present_event_id"]))
                {
                    query.present_event_id = Request.Params["present_event_id"].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["group_id"]))
                {
                    query.group_id = Convert.ToInt32(Request.Params["group_id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["new_user"]))
                {
                    query.new_user = Convert.ToInt32(Request.Params["new_user"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["new_user_date"]))
                {
                    query.new_user_date = Convert.ToDateTime(Request.Params["new_user_date"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["count_by"]))
                {
                    query.count_by = Convert.ToInt32(Request.Params["count_by"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["count"]))
                {
                    query.count = Convert.ToInt32(Request.Params["count"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["device"]))
                {
                    query.device = (Request.Params["device"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["message_mode"]))
                {
                    query.message_mode = Convert.ToInt32(Request.Params["message_mode"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["message_content"]))
                {
                    query.message_content = (Request.Params["message_content"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["link_url"]))
                {
                    query.link_url = (Request.Params["link_url"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["promo_image"]))
                {
                    query.promo_image = Request.Params["promo_image"];
                }
                if (!string.IsNullOrEmpty(Request.Params["active_now"]))
                {
                    query.active_now = Convert.ToInt32(Request.Params["active_now"]);
                }

                #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 + NewPromoPath;//圖片存儲地址
                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;
                        BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                        NewFileName = hash.Md5Encrypt(fileName, "32");
                        string ServerPath = string.Empty;
                        FTP f_cf = new FTP();
                        f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - NewPromoPath.Length + 1), NewPromoPath.Substring(1, NewPromoPath.Length - 2).Split('/'), ftpuser, ftppwd);
                        fileName = NewFileName + fileExtention;
                        NewFileName = localPromoPath + NewFileName + fileExtention;//絕對路徑
                        ServerPath = Server.MapPath(imgLocalServerPath + NewPromoPath);

                        //上傳之前刪除已有的圖片
                        if (query.row_id != 0)
                        {
                            oldModel = _INewPromoCarnetMgr.GetModel(query);
                            if (oldModel.promo_image != "")
                            {
                                string oldFileName = oldModel.promo_image;
                                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");//尋找product.resx中的資源文件
                            bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                            if (result)
                            {
                                query.promo_image = 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();
                            return this.Response;
                        }
                    }

                }
                else
                {
                    query.promo_image = oldModel.promo_image;
                }
                #endregion

                if (!string.IsNullOrEmpty(Request.Params["event_name"]))
                {
                    query.event_name = Request.Params["event_name"];
                }
                if (!string.IsNullOrEmpty(Request.Params["event_desc"]))
                {
                    query.event_desc = Request.Params["event_desc"];
                }
                if (!string.IsNullOrEmpty(Request.Params["start"]))
                {
                    query.start = Convert.ToDateTime(Request.Params["start"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["end"]))
                {
                    query.end = Convert.ToDateTime(Request.Params["end"]);
                }

                if (query.row_id == 0)
                {
                    query.kuser = (Session["caller"] as Caller).user_id;
                    query.muser = query.kuser;
                    query.created = DateTime.Now;
                    query.modified = query.created;
                    query.row_id = _INewPromoCarnetMgr.GetNewPromoCarnetMaxId();

                    query.event_id = BLL.gigade.Common.CommonFunction.GetEventId("F2", query.row_id.ToString());
                    if (_INewPromoCarnetMgr.InsertNewPromoCarnet(query) > 0)
                    {
                        json = "{success:true}";
                    }
                    else
                    {
                        json = "{success:false}";
                    }
                }
                else
                {
                    query.muser = (Session["caller"] as Caller).user_id;
                    query.modified = DateTime.Now;
                    if (_INewPromoCarnetMgr.UpdateNewPromoCarnet(query))
                    {
                        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;
        }
        public HttpResponseBase UpdateTrial()
        {
            string jsonStr = String.Empty;
            int isTranInt = 0;
            try
            {
                string trial_id = Request.Params["trial_id"].ToString();
                string isEdit = Request.Params["isEdit"].ToString();
                _promotionsAmountTrialMgr = new PromotionsAmountTrialMgr(mySqlConnectionString);
                _ucMgr = new UserConditionMgr(mySqlConnectionString);
                PromotionsAmountTrialQuery model = new PromotionsAmountTrialQuery();
                PromotionsAmountTrialQuery OldModel = new PromotionsAmountTrialQuery();


                #region 第一面板數據
                if (!string.IsNullOrEmpty(Request.Params["trial_id"]))
                {
                    model.id = Convert.ToInt32(Request.Params["trial_id"]);
                    OldModel = _promotionsAmountTrialMgr.Select(model.id);
                }
                if (!string.IsNullOrEmpty(Request.Params["name"]))
                {//活動名稱
                    model.name = Request.Params["name"].ToString();
                }


                int event_type = 0;
                if (!string.IsNullOrEmpty(Request.Params["event_type"]))
                {
                    if (int.TryParse(Request.Params["event_type"], out event_type))
                    {
                        if (event_type == 1)
                        {
                            model.event_type = "T1";
                        }
                        else if (event_type == 2)
                        {
                            model.event_type = "T2";
                        }
                    }
                }
                model.event_id = CommonFunction.GetEventId(model.event_type, model.id.ToString());

                int paper_id = 0;
                if (int.TryParse(Request.Params["paper_id"].ToString(), out paper_id))
                {
                    model.paper_id = paper_id;
                }
                if (!string.IsNullOrEmpty(Request.Params["event_url"].ToString()))
                {
                    model.url = Request.Params["event_url"];
                }
                if (!string.IsNullOrEmpty(Request.Params["start_date"]))
                {
                    model.start_date = Convert.ToDateTime(Request.Params["start_date"].ToString());
                }

                if (!string.IsNullOrEmpty(Request.Params["end_date"]))
                {
                    model.end_date = Convert.ToDateTime(Request.Params["end_date"].ToString());
                }
                //活動描述
                if (!string.IsNullOrEmpty(Request.Params["event_desc"]))
                {
                    model.event_desc = Request.Params["event_desc"].ToString();
                }

                #endregion
                #region 第二面板數據
                if (!string.IsNullOrEmpty(Request.Params["group_id"].ToString()))
                {
                    if (int.TryParse(Request.Params["group_id"].ToString(), out isTranInt))
                    {
                        model.group_id = Convert.ToInt32(Request.Params["group_id"].ToString());
                    }
                    else
                    {
                        model.group_id = OldModel.group_id;
                    }
                    //當編輯活動時將會員條件改為會員群組則刪除原有的會員條件
                    if (OldModel.condition_id != 0)
                    {
                        UserCondition uc = new UserCondition();
                        uc.condition_id = OldModel.condition_id;

                        if (_ucMgr.Delete(uc) > 0)
                        {
                            jsonStr = "{success:true}";
                            model.condition_id = 0;
                        }
                        else
                        {
                            jsonStr = "{success:false,msg:'user_condition刪除出錯!'}";
                            this.Response.Clear();
                            this.Response.Write(jsonStr.ToString());
                            this.Response.End();
                            return this.Response;
                        }
                    }
                    //當活動設置完會員條件又改為會員群組時刪除設置的會員條件
                    if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0")
                    {
                        UserCondition uc = new UserCondition();
                        uc.condition_id = Convert.ToInt32(Request.Params["condition_id"]);
                        if (_ucMgr.Delete(uc) > 0)
                        {
                            jsonStr = "{success:true}";
                            model.condition_id = 0;
                        }
                        else
                        {
                            jsonStr = "{success:false,msg:'user_condition刪除出錯!'}";
                            this.Response.Clear();
                            this.Response.Write(jsonStr.ToString());
                            this.Response.End();
                            return this.Response;
                        }
                    }
                }
                else if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0")
                {
                    model.condition_id = Convert.ToInt32(Request.Params["condition_id"].ToString());
                    model.group_id = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["count_by"]))
                {
                    model.count_by = Convert.ToInt32(Request.Params["count_by"].ToString());
                }
                if (!string.IsNullOrEmpty(Request.Params["numLimit"]))
                {
                    model.num_limit = Convert.ToInt32(Request.Params["numLimit"].ToString());
                }
                if (!string.IsNullOrEmpty(Request.Params["gift_mundane"]))
                {
                    model.gift_mundane = Convert.ToInt32(Request.Params["gift_mundane"].ToString());
                }

                if (!string.IsNullOrEmpty(Request.Params["IsRepeat"]))
                {
                    model.repeat = Convert.ToInt32(Request.Params["IsRepeat"].ToString()) == 1 ? true : false;
                }

                if (!string.IsNullOrEmpty(Request.Params["freight_type"].ToString()))
                {
                    if (int.TryParse(Request.Params["freight_type"].ToString(), out isTranInt))
                    {
                        model.freight_type = Convert.ToInt32(Request.Params["freight_type"].ToString());
                    }
                    else
                    {
                        model.freight_type = OldModel.freight_type;
                    }
                }

                if (!string.IsNullOrEmpty(Request.Params["device_name"]))
                {
                    model.device = Convert.ToInt32(Request.Params["device_name"].ToString());
                }

                if (!string.IsNullOrEmpty(Request.Params["site"].ToString()))//修改時傳的值為siteName
                {

                    Regex reg = new Regex("^([0-9]+,)*([0-9]+)$");
                    if (reg.IsMatch(Request.Params["site"].ToString()))
                    {
                        model.site = Request.Params["site"].ToString();// 將站台改為多選 edit by shuangshuang0420j 20140925 10:08
                    }
                    else
                    {
                        model.site = OldModel.site;
                    }
                }

                #endregion

                #region 第三面板數據

                if (!string.IsNullOrEmpty(Request.Params["product_id"]))
                {
                    model.product_id = Convert.ToInt32(Request.Params["product_id"].ToString());
                }
                if (!string.IsNullOrEmpty(Request.Params["product_name"]))
                {
                    model.product_name = Request.Params["product_name"].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["sale_product_id"]))
                {
                    model.sale_productid = Convert.ToInt32(Request.Params["sale_product_id"].ToString());
                }
                model.category_id = Convert.ToUInt32(Request.Params["category_id"].ToString());
                model.brand_id = Convert.ToInt32(Request.Params["brand_id"].ToString());
                model.market_price = Convert.ToInt32(Request.Params["market_price"].ToString());
                model.show_number = Convert.ToInt32(Request.Params["show_number"].ToString());
                model.apply_limit = Convert.ToInt32(Request.Params["apply_limit"].ToString());
                model.apply_sum = Convert.ToInt32(Request.Params["apply_sum"].ToString());

                #region 上傳圖片
                try
                {
                    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_MinValue");
                    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;//圖片存儲地址


                    string fileName = string.Empty;//當前文件名
                    string fileExtention = string.Empty;//當前文件的擴展名
                    bool result = false;
                    string NewFileName = string.Empty;//編譯后的文件名
                    string oldFile = "";
                    string ServerPath = string.Empty;
                    string ErrorMsg = string.Empty;


                    //判斷目錄是否存在,不存在則創建
                    CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'));

                    FileManagement fileLoad = new FileManagement();

                    for (int iFile = 0; iFile < Request.Files.Count; iFile++)
                    {
                        if (iFile == 0 && !string.IsNullOrEmpty(Request.Params["prod_file"]))
                        {
                            model.product_img = Request.Params["prod_file"].ToString().Substring(Request.Params["prod_file"].ToString().LastIndexOf("/") + 1);
                        }
                        else
                        {

                            HttpPostedFileBase file = Request.Files[iFile];

                            Random rand = new Random();
                            int newRand = rand.Next(1000, 9999);

                            fileName = Path.GetFileName(file.FileName);
                            if (fileName != "")
                            {

                                switch (iFile)
                                {
                                    case 1:
                                        oldFile = OldModel.event_img_small;
                                        break;
                                    case 2:
                                        oldFile = OldModel.event_img;
                                        break;
                                    case 0:
                                        oldFile = OldModel.product_img;
                                        break;
                                }

                                FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd);
                                List<string> tem = ftp.GetFileList();
                                if (tem.Contains(oldFile))
                                {
                                    FTP ftps = new FTP(localPromoPath + oldFile, ftpuser, ftppwd);
                                    ftps.DeleteFile(localPromoPath + oldFile);//刪除ftp:71.159上的舊圖片
                                    DeletePicFile(ServerPath + oldFile);//刪除本地圖片
                                }

                                fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                                NewFileName = model.event_id + newRand + fileExtention;

                                fileName = NewFileName;
                                NewFileName = localPromoPath + NewFileName;//絕對路徑
                                ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                                try
                                {
                                    //上傳
                                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                    if (result)//上傳成功
                                    {
                                        switch (iFile)
                                        {
                                            case 1:
                                                model.event_img_small = fileName;
                                                break;
                                            case 2:
                                                model.event_img = fileName;
                                                break;
                                            case 0:
                                                model.product_img = fileName;
                                                break;
                                        }

                                    }

                                }
                                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);
                                }
                            }
                            else
                            {
                                switch (iFile)
                                {
                                    case 1:
                                        model.event_img_small = OldModel.event_img_small;
                                        break;
                                    case 2:
                                        model.event_img = OldModel.event_img;
                                        break;
                                    case 0:
                                        model.product_img = OldModel.product_img;
                                        break;
                                }

                            }
                        }
                    }
                }
                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);
                }

                #endregion

                #endregion


                #region     更新表結構
                if (string.IsNullOrEmpty(isEdit))//新增數據
                {
                    model.active = 0;//默認不啟用
                    model.status = 1;//第二步保存為有效數據
                    model.kuser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                    model.created = DateTime.Now;
                    model.muser = model.kuser;
                    model.modified = model.created;
                    if (_promotionsAmountTrialMgr.Update(model) > 0)
                    {

                        jsonStr = "{success:true,msg:0}";//返回json數據
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:0}";//返回json數據
                    }
                }
                else//編輯數據
                {
                    model.active = OldModel.active;
                    model.status = OldModel.status;
                    model.kuser = OldModel.kuser;
                    model.created = OldModel.created;
                    model.muser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                    model.modified = DateTime.Now;
                    if (_promotionsAmountTrialMgr.Update(model) > 0)
                    {

                        jsonStr = "{success:true,msg:0}";//返回json數據
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:0}";//返回json數據
                    }
                }
                #endregion
            }
            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);
                jsonStr = "{success:false,msg:0}";
            }
            this.Response.Clear();
            this.Response.Write(jsonStr.ToString());
            this.Response.End();
            return this.Response;
        }