コード例 #1
0
        public JsonResult AddMessage(string content, int majorID)
        {
            CheckUserData(out int userID, out int userAccess);
            List <HttpPostedFileBase> postFile = new List <HttpPostedFileBase>();
            ReturnJSON returnJSON = new ReturnJSON()
            {
                isOK = false,
                msg  = string.Empty
            };

            returnJSON.msg = CheckCreateMesaage(content, userID);
            if (Request.Files.Count > 0)
            {
                postFile.Add(Request.Files[0]);
                var fileCheck = PicTool.CheckUplaodFiles(postFile[0], @"\.(?i:jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga|svg|jpeg2000)$", 1);
                if (!fileCheck.Item1)
                {
                    foreach (var item in fileCheck.Item2)
                    {
                        returnJSON.msg += $"<br/> * {item}";
                    }
                }
            }

            if (string.IsNullOrWhiteSpace(returnJSON.msg))
            {
                try
                {
                    Message message;
                    if (majorID == 0)   // 建立新主題
                    {
                        MajorMessageList majorMessage = InsertMajorMessage(userID);
                        InsertMessage(content, userID, majorMessage.MajorID, out message);
                    }
                    else
                    {                   // 回覆留言
                        InsertMessage(content, userID, majorID, out message);
                    }

                    // 儲存圖片
                    if (postFile.Count > 0)
                    {
                        PicTool.SaveMessagePic(postFile[0], userID, message.MessageID);
                    }

                    returnJSON.isOK = true;
                    returnJSON.msg  = "文章新增成功";
                }
                catch (Exception err)
                {
                    LogTool.DoErrorLog($"#{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff")}:{err.Message}\r\n");
                    returnJSON.msg = "<br/> * 儲存時發生錯誤";
                }
            }

            return(Json(returnJSON, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public ActionResult UserRegister(string userAccount, string userPW1, string userPW2, string userEmail)
        {
            ReturnJSON    returnJSON   = new ReturnJSON();
            List <string> errorList    = new List <string>();
            bool          isRegisterOK = false;
            string        returnMsg    = "註冊失敗";

            if (Request.Files.Count == 0)
            {
                errorList.Add("請上傳頭像圖檔");
            }
            else
            {
                HttpPostedFileBase postFile = Request.Files[0];
                var fileCheck = PicTool.CheckUplaodFiles(postFile, @"\.(?i:jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga|svg|jpeg2000)$", 1);
                if (!fileCheck.Item1)
                {
                    foreach (var item in fileCheck.Item2)
                    {
                        errorList.Add(item);
                    }
                }
            }

            if (!errorList.Any())
            {
                HttpPostedFileBase postFile = Request.Files[0];
                userAccount = HttpUtility.UrlDecode(userAccount);
                userPW1     = HttpUtility.UrlDecode(userPW1);
                userPW2     = HttpUtility.UrlDecode(userPW2);
                userEmail   = HttpUtility.UrlDecode(userEmail);
                var registerResult = userTool.RegisterUser(userAccount, userPW1, userPW2, userEmail);
                isRegisterOK = registerResult.Item1;
                errorList    = registerResult.Item2;
                returnMsg    = registerResult.Item3;

                if (registerResult.Item1)
                {
                    PicTool.SaveUserPic(postFile, registerResult.Item4.UserID);
                }
            }

            returnJSON = new ReturnJSON()
            {
                isOK      = isRegisterOK,
                errorList = errorList,
                msg       = returnMsg
            };

            return(Json(returnJSON));
        }
コード例 #3
0
        public JsonResult SavePorfile(string pw1, string pw2, int userID)
        {
            pw1 = HttpUtility.UrlDecode(pw1);
            pw2 = HttpUtility.UrlDecode(pw2);
            var        userLogin  = userTool.GetLoginedUser(HttpContext.Request).FirstOrDefault();
            string     dgMsg      = "儲存成功";
            bool       isCatch    = false;
            ReturnJSON returnJSON = new ReturnJSON()
            {
                isOK = false,
                msg  = "發生未預期的錯誤"
            };

            try
            {
                if (pw1 != pw2)
                {
                    dgMsg += "<br/> * 前後兩次密碼輸入不一致";
                }
                else if (userTool.isSetNewPW(userLogin.UserName, userLogin.UserEmail, pw1))
                {
                    dgMsg          += "<br/> * 更新密碼成功";
                    returnJSON.isOK = true;
                }
            }
            catch (Exception)
            {
                isCatch = true;
            }

            try
            {
                if (Request.Files.Count > 0)
                {
                    bool isFileCorrect          = true;
                    HttpPostedFileBase postFile = Request.Files[0];
                    var fileCheck = PicTool.CheckUplaodFiles(postFile, @"\.(?i:jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga|svg|jpeg2000)$", 1);
                    if (!fileCheck.Item1)
                    {
                        isFileCorrect = false;
                        foreach (var item in fileCheck.Item2)
                        {
                            dgMsg += $"<br/> * {item}";
                        }
                    }

                    if (isFileCorrect)
                    {
                        returnJSON.isOK = true;
                        dgMsg          += "<br/> * 頭像更新成功";
                        PicTool.SaveUserPic(postFile, userLogin.UserID);
                    }
                }

                returnJSON.isOK = true;
            }
            catch (Exception)
            {
                isCatch = true;
            }

            returnJSON.msg = isCatch ? returnJSON.msg : dgMsg;
            return(Json(returnJSON));
        }
コード例 #4
0
        public static void ComPressProductPic()
        {
            bool IsFtpServer = bool.Parse(ConfigurationManager.AppSettings["IsFtpServer"]);
            int  Num_i       = Convert.ToInt16(ConfigurationManager.AppSettings["NumOnceDeal"]);

            int SleepTime = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SleepTime"]);
            IList <ConfigPicComPressEntity> picconfig = ConfigPicComPressBLL.Instance.GetConfigListByPicSource((int)SourcePicTypeEnum.Product);

            while (true)
            {
                IList <ProductStylePicsEntity> _piclist = new List <ProductStylePicsEntity>();
                _piclist = ProductStylePicsBLL.Instance.GetStylePicsNoComPress(Num_i);
                if (_piclist != null && _piclist.Count > 0)
                {
                    //ParallelOptions po = new ParallelOptions();
                    //po.MaxDegreeOfParallelism = 15; //最多并发50个任务
                    string FtpServerPath = "";
                    string ImagePath     = "";
                    if (IsFtpServer)
                    {
                        FtpServerPath = ConfigurationManager.AppSettings["FtpServerPathPrefix"].ToString();
                    }
                    ImagePath = ConfigurationManager.AppSettings["ImagePath"].ToString();

                    if (picconfig != null && picconfig.Count > 0)
                    {
                        string allids     = "0";
                        string successids = "0";
                        string failids    = "0";
                        string error      = "1";
                        foreach (ProductStylePicsEntity o in _piclist)
                        {
                            allids = allids + "," + o.Id.ToString();
                            string filepath = FtpServerPath + ImagePath.Replace("/", "\\") + o.PicUrl.Replace("/", "\\") + "." + o.PicSuffix;
                            try
                            {
                                if (IsFtpServer)
                                {
                                    foreach (ConfigPicComPressEntity en in picconfig)
                                    {
                                        Image       sourceImg = Image.FromFile(filepath);
                                        ImageFormat _imgf     = sourceImg.RawFormat;
                                        string      savepath  = FtpServerPath + ImagePath.Replace("/", "\\") + o.PicUrl.Replace("/", "\\") + en.PicName + "." + o.PicSuffix;

                                        int Width  = en.Width;
                                        int Height = en.Height;
                                        using (Image ThumbImgl = PicTool.GetImageThumb(sourceImg, Width, Height))
                                        {
                                            ThumbImgl.Save(savepath, _imgf);
                                            ThumbImgl.Dispose();
                                        }
                                        sourceImg.Dispose();
                                    }
                                }
                                else
                                {
                                    FtpUtil _ftp         = new FtpUtil();
                                    string  downloadpath = ImagePath + o.PicUrl + "." + o.PicSuffix;
                                    byte[]  _byt         = _ftp.DownloadFile(downloadpath);
                                    Image   sourceImg    = PicTool.GetImageByBytes(_byt);



                                    foreach (ConfigPicComPressEntity en in picconfig)
                                    {
                                        int    Width      = en.Width;
                                        int    Height     = en.Height;
                                        string uploadpath = ImagePath + o.PicUrl + en.PicName + "." + o.PicSuffix;
                                        using (Image ThumbImgl = PicTool.GetImageThumb(sourceImg, Width, Height))
                                        {
                                            byte[] _byts = PicTool.GetByteByImage(ThumbImgl);
                                            _ftp.UploadFile(uploadpath, _byts, false);
                                            ThumbImgl.Dispose();
                                        }
                                    }
                                    sourceImg.Dispose();
                                }
                                successids = successids + "," + o.Id.ToString();
                            }
                            catch (Exception ex)
                            {
                                LogUtil.Log(ex);

                                failids = failids + "," + o.Id.ToString();
                            }
                        }
                        ProductStylePicsBLL.Instance.ComPressComplete(allids, successids, failids);
                    }

                    Thread.Sleep(SleepTime);
                }
            }
        }