private void Bind() { GetSearchItem(); int totalRecords = 0; PictureContent bll = new PictureContent(); rpData.DataSource = bll.GetList(pageIndex, pageSize, out totalRecords, sqlWhere, parms == null ? null : parms.ToArray()); rpData.DataBind(); myDataAppend += "<div id=\"myDataForPage\" style=\"display:none;\">[{\"PageIndex\":\"" + pageIndex + "\",\"PageSize\":\"" + pageSize + "\",\"TotalRecord\":\"" + totalRecords + "\",\"QueryStr\":\"" + queryStr + "\"}]</div>"; }
private void Bind() { if (!string.IsNullOrEmpty(funName)) { int totalRecords = 0; switch (funName) { case "PictureContent": PictureContent adpBll = new PictureContent(); rpData.DataSource = adpBll.GetList(pageIndex, pageSize, out totalRecords, sqlWhere, parms == null ? null : parms.ToArray()); rpData.DataBind(); break; default: break; } myDataAppend.Replace("{TotalRecord}", totalRecords.ToString()); myDataAppend.Replace("{PageIndex}", pageIndex.ToString()); myDataAppend.Replace("{PageSize}", pageSize.ToString()); } }
/// <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 + "\"}"); }
public string DelPictureContent(string itemAppend) { try { itemAppend = itemAppend.Trim(); if (string.IsNullOrEmpty(itemAppend)) { return(MC.Submit_InvalidRow); } string[] items = itemAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string inIds = ""; Guid gId = Guid.Empty; foreach (string item in items) { if (!Guid.TryParse(item, out gId)) { throw new ArgumentException(MC.GetString(MC.Submit_Params_GetInvalidRegex, item)); } inIds += string.Format("'{0}',", item); } PictureContent bll = new PictureContent(); var list = bll.GetList(" and Id in (" + inIds.Trim(',') + ")"); if (list != null || list.Count() > 0) { using (TransactionScope scope = new TransactionScope()) { foreach (var model in list) { string dir = Server.MapPath("~" + string.Format("{0}{1}", model.FileDirectory, model.RandomFolder)); if (Directory.Exists(dir)) { string[] subDirArr = Directory.GetDirectories(dir); if (subDirArr != null) { foreach (string subDir in subDirArr) { Directory.Delete(subDir, true); } } Directory.Delete(dir, true); } dir = Server.MapPath("~" + string.Format("{0}{1}", model.FileDirectory, model.FileName)); if (File.Exists(dir)) { File.Delete(dir); } } bll.DeleteBatch(items.ToList <object>()); scope.Complete(); } } return("1"); } catch (Exception ex) { return(ex.Message); } }