示例#1
0
        private void UploadSitePicture(HttpContext context, string funType)
        {
            HttpFileCollection files = context.Request.Files;

            if (files.Count == 0)
            {
                context.Response.Write("{\"success\": false,\"message\": \"未找到任何可上传的文件,请检查!\"}");
                return;
            }

            var          userId = WebCommon.GetUserId();
            int          effect = 0;
            ImagesHelper ih     = new ImagesHelper();

            using (TransactionScope scope = new TransactionScope())
            {
                foreach (string item in files.AllKeys)
                {
                    HttpPostedFile file = files[item];
                    if (file == null || file.ContentLength == 0)
                    {
                        continue;
                    }

                    int fileSize       = file.ContentLength;
                    int uploadFileSize = int.Parse(WebConfigurationManager.AppSettings["UploadFileSize"]);
                    if (fileSize > uploadFileSize)
                    {
                        throw new ArgumentException("文件【" + file.FileName + "】大小超出字节" + uploadFileSize + ",无法上传,请正确操作!");
                    }
                    if (!UploadFilesHelper.IsFileValidated(file.InputStream, fileSize))
                    {
                        throw new ArgumentException("文件【" + file.FileName + "】为受限制的文件,请正确操作!");
                    }

                    //string fileName = file.FileName;
                    var bll = new SitePicture();
                    //if (bll.IsExist(userId, file.FileName, fileSize)) throw new ArgumentException("文件【" + file.FileName + "】已存在,请勿重复上传!");

                    string originalUrl = UploadFilesHelper.UploadOriginalFile(file, "SitePicture");

                    var model = new SitePictureInfo(Guid.Empty, userId, VirtualPathUtility.GetFileName(originalUrl), fileSize, VirtualPathUtility.GetExtension(originalUrl).ToLower(), VirtualPathUtility.GetDirectory(originalUrl.Replace("~", "")), Path.GetFileNameWithoutExtension(context.Server.MapPath(originalUrl)), funType, DateTime.Now);
                    CreateThumbnailImage(context, ih, context.Server.MapPath(originalUrl));

                    bll.Insert(model);
                    effect++;
                }

                scope.Complete();
            }

            if (effect > 0)
            {
                context.Response.Write("{\"success\": true,\"message\": \"已成功上传文件数:" + effect + "个\"}");
            }
            else
            {
                context.Response.Write("{\"success\": false,\"message\": \"上传失败,请检查!\"}");
            }
        }
示例#2
0
        public void KindeditorFilesUpload()
        {
            HttpPostedFile file = context.Request.Files["imgFile"];

            if (file == null || file.ContentLength == 0)
            {
                UploadResult(false, "请选择文件!", "");
            }
            string dir = context.Request.QueryString["dir"];

            if (string.IsNullOrWhiteSpace(dir))
            {
                dir = "image";
            }

            try
            {
                if (!UploadFilesHelper.IsFileValidated(file.InputStream, file.ContentLength))
                {
                    UploadResult(false, "该文件已被禁止上传", "");
                }
                string fileExt = Path.GetExtension(file.FileName).ToLower();

                string virtualPath = string.Empty;
                string fullPath    = GetFullPath(Path.Combine("Kindeditor", dir), fileExt, out virtualPath);

                file.SaveAs(fullPath);

                UploadResult(true, "", WebCommon.ToVirtualAbsolutePath(virtualPath));
            }
            catch (Exception ex)
            {
                UploadResult(false, "上传异常:" + ex.Message, "");
            }
        }
 public AdsController()
     : base()
 {
     _objectTypesService = DiProxy.Get <IObjectTypesService>();
     _objectsService     = DiProxy.Get <IObjectsService>();
     _adsService         = DiProxy.Get <IAdsService>();
     _filesService       = DiProxy.Get <IFilesService>();
     _uploadFilesHelper  = new UploadFilesHelper(uploadFileMaxBytes: 30 * 1024 * 1024);
     _adMapper           = new AdEditInfoMapper();
 }
示例#4
0
        private void FileValidated(HttpPostedFile file)
        {
            int fileSize       = file.ContentLength;
            int uploadFileSize = int.Parse(WebConfigurationManager.AppSettings["UploadFileSize"]);

            if (fileSize > uploadFileSize)
            {
                throw new ArgumentException("文件【" + file.FileName + "】大小超出字节" + uploadFileSize + ",无法上传,请正确操作!");
            }
            if (!UploadFilesHelper.IsFileValidated(file.InputStream, fileSize))
            {
                new CustomException("上传了非法文件--" + file.FileName);
                throw new ArgumentException("文件【" + file.FileName + "】为受限制的文件,请正确操作!");
            }
        }
示例#5
0
        public virtual JsonResult FileUpload(long?timespan, string token, int fileType, string pathFormat, int sizeLimit)
        {
            var fileUpload = new UploadFilesHelper((UploadFileType)fileType)
            {
                UploadConfig = { SizeLimit = sizeLimit }
            };

            if (pathFormat.IsNullOrEmpty() == false)
            {
                fileUpload.UploadConfig.PathFormat = pathFormat;
            }

            var uploadResult = fileUpload.UploadFile("file", Guid.NewGuid().ToString());

            return(Json(uploadResult));
        }
示例#6
0
        private void OnUploadCommunionPicture(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string errorMsg = "";

            try
            {
                HttpFileCollection files = context.Request.Files;
                if (files.Count == 0)
                {
                    context.Response.Write("{\"success\": false,\"message\": \"未找到任何可上传的文件,请检查!\"}");
                    return;
                }

                int effect            = 0;
                UploadFilesHelper ufh = new UploadFilesHelper();
                ImagesHelper      ih  = new ImagesHelper();

                using (TransactionScope scope = new TransactionScope())
                {
                    foreach (string item in files.AllKeys)
                    {
                        HttpPostedFile file = files[item];
                        if (file == null || file.ContentLength == 0)
                        {
                            continue;
                        }

                        int fileSize       = file.ContentLength;
                        int uploadFileSize = int.Parse(ConfigHelper.GetValueByKey("UploadFileSize"));
                        if (fileSize > uploadFileSize)
                        {
                            throw new ArgumentException("文件【" + file.FileName + "】大小超出字节" + uploadFileSize + ",无法上传,请正确操作!");
                        }
                        if (!UploadFilesHelper.IsFileValidated(file.InputStream, fileSize))
                        {
                            throw new ArgumentException("文件【" + file.FileName + "】为受限制的文件,请正确操作!");
                        }

                        CommunionPicture bll = new CommunionPicture();
                        if (bll.IsExist(file.FileName, fileSize))
                        {
                            throw new ArgumentException("文件【" + file.FileName + "】已存在,请勿重复上传!");
                        }

                        string originalUrl = UploadFilesHelper.UploadOriginalFile(file, "CommunionPicture");

                        //获取随机生成的文件名代码
                        string randomFolder = string.Format("{0}_{1}", DateTime.Now.ToString("MMdd"), UploadFilesHelper.GetRandomFolder("cmp"));

                        CommunionPictureInfo model = new CommunionPictureInfo();
                        model.FileName        = VirtualPathUtility.GetFileName(originalUrl);
                        model.FileSize        = fileSize;
                        model.FileExtension   = VirtualPathUtility.GetExtension(originalUrl).ToLower();
                        model.FileDirectory   = VirtualPathUtility.GetDirectory(originalUrl.Replace("~", ""));
                        model.RandomFolder    = randomFolder;
                        model.LastUpdatedDate = DateTime.Now;

                        bll.Insert(model);

                        string rndDirFullPath = context.Server.MapPath(string.Format("~{0}{1}", model.FileDirectory, model.RandomFolder));
                        if (!Directory.Exists(rndDirFullPath))
                        {
                            Directory.CreateDirectory(rndDirFullPath);
                        }
                        File.Copy(context.Server.MapPath(originalUrl), string.Format("{0}\\{1}{2}", rndDirFullPath, randomFolder, model.FileExtension), true);

                        string[] platformNames = Enum.GetNames(typeof(EnumData.Platform));
                        foreach (string name in platformNames)
                        {
                            string platformUrl         = string.Format("{0}/{1}/{2}", model.FileDirectory, model.RandomFolder, name);
                            string platformUrlFullPath = context.Server.MapPath("~" + platformUrl);
                            if (!Directory.Exists(platformUrlFullPath))
                            {
                                Directory.CreateDirectory(platformUrlFullPath);
                            }
                            string   sizeAppend = ConfigHelper.GetValueByKey(name);
                            string[] sizeArr    = sizeAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                            for (int i = 0; i < sizeArr.Length; i++)
                            {
                                string   bmsPicUrl = string.Format("{0}\\{1}_{2}{3}", platformUrlFullPath, model.RandomFolder, i, model.FileExtension);
                                string[] wh        = sizeArr[i].Split('*');

                                ih.CreateThumbnailImage(context.Server.MapPath(originalUrl), bmsPicUrl, int.Parse(wh[0]), int.Parse(wh[1]), "DB", model.FileExtension);
                            }
                        }

                        effect++;
                    }

                    scope.Complete();
                }

                if (effect == 0)
                {
                    context.Response.Write("{\"success\": false,\"message\": \"未找到任何可上传的文件,请检查!\"}");
                    return;
                }

                context.Response.Write("{\"success\": true,\"message\": \"已成功上传文件数:" + effect + "个\"}");

                return;
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
            }

            context.Response.Write("{\"success\": false,\"message\": \"" + errorMsg + "\"}");
        }
        /// <summary>
        /// 内容相册上传
        /// </summary>
        /// <param name="context"></param>
        private void OnUploadPictureContent(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string errorMsg = "";

            try
            {
                HttpFileCollection files = context.Request.Files;
                if (files.Count == 0)
                {
                    context.Response.Write("{\"success\": false,\"message\": \"未找到任何可上传的文件,请检查!\"}");
                    return;
                }

                object            userId = WebCommon.GetUserId();
                int               effect = 0;
                UploadFilesHelper ufh    = new UploadFilesHelper();
                ImagesHelper      ih     = new ImagesHelper();

                using (TransactionScope scope = new TransactionScope())
                {
                    foreach (string item in files.AllKeys)
                    {
                        HttpPostedFile file = files[item];
                        if (file == null || file.ContentLength == 0)
                        {
                            continue;
                        }

                        int fileSize       = file.ContentLength;
                        int uploadFileSize = int.Parse(WebConfigurationManager.AppSettings["UploadFileSize"]);
                        if (fileSize > uploadFileSize)
                        {
                            throw new ArgumentException("文件【" + file.FileName + "】大小超出字节" + uploadFileSize + ",无法上传,请正确操作!");
                        }
                        if (!UploadFilesHelper.IsFileValidated(file.InputStream, fileSize))
                        {
                            throw new ArgumentException("文件【" + file.FileName + "】为受限制的文件,请正确操作!");
                        }

                        string fileName = file.FileName;

                        PictureContent bll = new PictureContent();
                        if (bll.IsExist(userId, file.FileName, fileSize))
                        {
                            throw new ArgumentException("文件【" + file.FileName + "】已存在,请勿重复上传!");
                        }

                        string originalUrl = UploadFilesHelper.UploadOriginalFile(file, "PictureContent");

                        //获取随机生成的文件名代码
                        string randomFolder = UploadFilesHelper.GetRandomFolder(originalUrl);

                        PictureContentInfo model = new PictureContentInfo();
                        model.UserId          = userId;
                        model.FileName        = VirtualPathUtility.GetFileName(originalUrl);
                        model.FileSize        = fileSize;
                        model.FileExtension   = VirtualPathUtility.GetExtension(originalUrl).ToLower();
                        model.FileDirectory   = VirtualPathUtility.GetDirectory(originalUrl.Replace("~", ""));
                        model.RandomFolder    = randomFolder;
                        model.LastUpdatedDate = DateTime.Now;

                        bll.Insert(model);

                        CreateThumbnailImage(context, ih, originalUrl, model.FileDirectory, model.RandomFolder, model.FileExtension);

                        effect++;
                    }

                    scope.Complete();
                }

                if (effect == 0)
                {
                    context.Response.Write("{\"success\": false,\"message\": \"未找到任何可上传的文件,请检查!\"}");
                    return;
                }

                context.Response.Write("{\"success\": true,\"message\": \"已成功上传文件数:" + effect + "个\"}");

                return;
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
            }

            context.Response.Write("{\"success\": false,\"message\": \"" + errorMsg + "\"}");
        }
        private void OnUpload(HttpContext context)
        {
            string errorMsg = "";

            try
            {
                int  effect              = 0;
                bool isCreateThumbnail   = ConfigHelper.GetValueByKey("IsCteateServicePictureThumbnail") == "1";
                UploadFilesHelper  ufh   = new UploadFilesHelper();
                HttpFileCollection files = context.Request.Files;
                if (files == null || files.Count == 0)
                {
                    context.Response.Write("{\"success\": false,\"message\": \"未找到任何可上传的文件,请检查!\"}");
                    return;
                }
                foreach (string item in files.AllKeys)
                {
                    if (files[item] == null || files[item].ContentLength == 0)
                    {
                        continue;
                    }
                    string[]           paths   = ufh.Upload(files[item], "ServicePictures", isCreateThumbnail);
                    ServicePicture     ppBll   = new ServicePicture();
                    ServicePictureInfo ppModel = new ServicePictureInfo();

                    string originalPicturePath = "";
                    string bPicturePath        = "";
                    string mPicturePath        = "";
                    string sPicturePath        = "";
                    string otherPicturePath    = "";
                    for (int i = 0; i < paths.Length; i++)
                    {
                        switch (i)
                        {
                        case 0:
                            originalPicturePath = paths[i].Replace("~", "");
                            break;

                        case 1:
                            bPicturePath = paths[i].Replace("~", "");
                            break;

                        case 2:
                            mPicturePath = paths[i].Replace("~", "");
                            break;

                        case 3:
                            sPicturePath = paths[i].Replace("~", "");
                            break;

                        case 4:
                            otherPicturePath = paths[i].Replace("~", "");
                            break;

                        default:
                            break;
                        }
                    }
                    ppModel.OriginalPicture = originalPicturePath;
                    ppModel.BPicture        = bPicturePath;
                    ppModel.MPicture        = mPicturePath;
                    ppModel.SPicture        = sPicturePath;
                    ppModel.OtherPicture    = otherPicturePath;
                    ppModel.LastUpdatedDate = DateTime.Now;
                    ppBll.Insert(ppModel);
                    effect++;
                }
                if (effect == 0)
                {
                    context.Response.Write("{\"success\": false,\"message\": \"未找到任何可上传的文件,请检查!\"}");
                    return;
                }

                context.Response.Write("{\"success\": true,\"message\": \"已成功上传文件数:" + effect + "个\"}");
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
            }

            if (errorMsg != "")
            {
                context.Response.Write("{\"success\": false,\"message\": \"" + errorMsg + "\"}");
            }
        }
示例#9
0
        private void UploadPdaOrderProcess(HttpContext context)
        {
            #region 请求参数集

            var Id = Guid.Empty;
            if (context.Request.Form["Id"] != null)
            {
                Guid.TryParse(context.Request.Form["Id"], out Id);
            }
            if (Id.Equals(Guid.Empty))
            {
                throw new ArgumentException(MC.Request_Params_InvalidError);
            }
            //string orderCode = string.Empty;
            //if (context.Request.Form["OrderCode"] != null) orderCode = context.Request.Form["OrderCode"].Trim();
            //string customerCode = string.Empty;
            //if (context.Request.Form["CustomerCode"] != null) customerCode = context.Request.Form["CustomerCode"].Trim();
            string stepName = string.Empty;
            if (context.Request.Form["OrderStep"] != null)
            {
                stepName = context.Request.Form["OrderStep"].Trim();
            }
            string staffCode = string.Empty;
            if (context.Request.Form["LoginId"] != null)
            {
                staffCode = context.Request.Form["LoginId"].Trim();
            }
            var    picture  = string.Empty;
            string deviceId = string.Empty;
            if (context.Request.Form["DeviceId"] != null)
            {
                deviceId = context.Request.Form["DeviceId"].Trim();
            }
            string latlng = string.Empty;
            if (context.Request.Form["Latlng"] != null)
            {
                latlng = context.Request.Form["Latlng"].Trim();
            }
            string latlngPlace = string.Empty;
            string ip          = HttpClientHelper.GetClientIp(context);
            string ipPlace     = string.Empty;

            #endregion

            new CustomException(string.Format("Id:{0}--stepName:{1}--staffCode:{2}--picture:{3}--deviceId:{4}--latlng:{5}--ip:{6}", Id, stepName, staffCode, picture, deviceId, latlng, ip));

            HttpFileCollection files = context.Request.Files;
            if (files.Count > 0)
            {
                ImagesHelper ih = new ImagesHelper();
                foreach (string item in files.AllKeys)
                {
                    HttpPostedFile file = files[item];
                    if (file == null || file.ContentLength == 0)
                    {
                        continue;
                    }

                    FileValidated(file);

                    string originalUrl = UploadFilesHelper.UploadOriginalFile(file, "PdaPictures");
                    picture = originalUrl.Trim('~');

                    CreateThumbnailImage(context, ih, context.Server.MapPath(originalUrl));
                }
            }

            var pictures = new List <string>();
            //var orderId = Guid.Empty;
            //var oldOrderInfo = new OrderMake().GetModel(orderCode, customerCode);
            //if (oldOrderInfo != null) orderId = oldOrderInfo.Id;

            var opBll  = new OrderProcess();
            var effect = 0;

            var currTime  = DateTime.Now;
            var opInfo    = new OrderProcessInfo(Id, Guid.Empty, staffCode, stepName, picture, deviceId, latlng, latlngPlace, ip, ipPlace, currTime, currTime);
            var oldOpInfo = opBll.GetModel(Id);
            if (oldOpInfo != null)
            {
                opInfo.OrderId = oldOpInfo.OrderId;
                if (!string.IsNullOrWhiteSpace(oldOpInfo.Pictures))
                {
                    pictures = oldOpInfo.Pictures.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    if (!pictures.Any(s => s.Equals(picture)))
                    {
                        pictures.Add(picture);
                    }
                }
                else
                {
                    pictures.Add(picture);
                }
                opInfo.Pictures = string.Join("|", pictures);
                if (oldOpInfo.Ip == ip)
                {
                    opInfo.IpPlace = oldOpInfo.IpPlace;
                }
                if (oldOpInfo.Latlng == latlng)
                {
                    opInfo.LatlngPlace = oldOpInfo.LatlngPlace;
                }
                effect = opBll.Update(opInfo);
            }
            else
            {
                throw new ArgumentException(MC.Data_NotExist);
            }

            if (effect > 0)
            {
                context.Response.Write(ResResult.ResJsonString(true, "", string.Join("|", pictures)));
            }
            else
            {
                context.Response.Write(ResResult.ResJsonString(false, MC.M_Save_Error, ""));
            }
        }
示例#10
0
        private void UploadContentFile(HttpContext context)
        {
            #region 请求参数集

            var contentId = Guid.Empty;
            if (context.Request.Form["ContentId"] != null)
            {
                Guid.TryParse(context.Request.Form["ContentId"], out contentId);
            }
            if (contentId.Equals(Guid.Empty))
            {
                throw new ArgumentException(MC.Request_Params_InvalidError);
            }
            var appCode = context.Request.Form["AppCode"];
            if (string.IsNullOrWhiteSpace(appCode))
            {
                throw new ArgumentException(MC.Request_Params_InvalidError);
            }
            var userId = WebCommon.GetUserId();
            if (userId.Equals(Guid.Empty))
            {
                throw new ArgumentException(MC.L_InvalidError);
            }
            var currTime = DateTime.Now;
            var effect   = 0;

            #endregion

            HttpFileCollection files = context.Request.Files;
            if (files.Count > 0)
            {
                var          ufh = new UploadFilesHelper();
                ImagesHelper ih  = new ImagesHelper();
                foreach (string item in files.AllKeys)
                {
                    HttpPostedFile file = files[item];
                    if (file == null || file.ContentLength == 0)
                    {
                        continue;
                    }
                    var ext = Path.GetExtension(file.FileName);

                    FileValidated(file);

                    string originalUrl  = ufh.UploadOriginalFile(file, "ContentFiles", currTime);
                    var    originalPath = UploadFilesHelper.ToFullPath(originalUrl);
                    var    htmlFullPath = string.Empty;
                    if (ext == ".doc" || ext == ".docx")
                    {
                        htmlFullPath = OoxmlConvert.WordToHtml(originalPath, Path.GetFileNameWithoutExtension(file.FileName));
                    }
                    else if (ext == ".xls" || ext == ".xlsx")
                    {
                        htmlFullPath = AsposeConvert.ExcelToHtml(originalPath, Path.GetFileNameWithoutExtension(file.FileName));
                    }

                    var cfInfo = new ContentFileInfo(Guid.Empty, appCode.Trim(), userId, contentId, file.FileName, file.ContentLength, VirtualPathUtility.GetExtension(file.FileName).ToLower(), originalUrl.Trim('~'), UploadFilesHelper.ToVirtualPath(htmlFullPath), currTime);
                    var cfBll  = new ContentFile();
                    effect += cfBll.Insert(cfInfo);

                    //if (ufh.IsImage(file))
                    //    CreateThumbnailImage(context, ih, context.Server.MapPath(originalUrl));
                }
            }

            if (effect > 0)
            {
                context.Response.Write(ResResult.ResJsonString(true, MC.M_Save_Ok, null));
            }
            else
            {
                context.Response.Write(ResResult.ResJsonString(false, MC.M_Save_Error, ""));
            }
        }
示例#11
0
        /// <summary>
        /// 批量删除数据
        /// </summary>
        private void OnDelete()
        {
            string itemsAppend = hV.Value.Trim();

            if (string.IsNullOrEmpty(itemsAppend))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "请至少勾选一行进行操作", "操作错误", "error");
                return;
            }

            if (bll == null)
            {
                bll = new BLL.Product();
            }
            string[]      itemsAppendArr = itemsAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            string        pIdAppend      = "";
            List <string> list           = new List <string>();

            foreach (string item in itemsAppendArr)
            {
                list.Add(item);
                pIdAppend += string.Format("'{0}',", item);
            }

            pIdAppend = pIdAppend.Trim(',');
            IList <ProductInfo> imagesList = bll.GetImagesListInProductIds(pIdAppend);

            UploadFilesHelper ufh      = new UploadFilesHelper();
            string            errorMsg = "";

            try
            {
                TransactionOptions options = new TransactionOptions();
                options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
                options.Timeout        = TimeSpan.FromSeconds(90);
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
                {
                    if (bll.DeleteBatch(list))
                    {
                        if (imagesList != null)
                        {
                            foreach (ProductInfo model in imagesList)
                            {
                                ufh.DeleteProductImage(model.ImagesUrl);

                                var sLImages = model.LImagesUrl.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string item in sLImages)
                                {
                                    ufh.DeleteProductImage(item);
                                }
                                var sMImages = model.MImagesUrl.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string item in sMImages)
                                {
                                    ufh.DeleteProductImage(item);
                                }
                                var sSImages = model.SImagesUrl.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string item in sSImages)
                                {
                                    ufh.DeleteProductImage(item);
                                }
                            }
                        }
                    }

                    //提交事务
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
            }

            if (!string.IsNullOrEmpty(errorMsg))
            {
                WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, errorMsg, "系统异常提示");
                return;
            }

            WebHelper.MessageBox.MessagerShow(this.Page, lbtnPostBack, "操作成功");
            Bind();
        }