/// <summary> /// 更新IIS缓存中指定Id记录 /// </summary> /// <param name="model">记录实体</param> public void SetModelForCache(UploadFile model) { SetModelForCache(Transform(model)); }
/// <summary> /// 将UploadFile记录实体(SubSonic实体)转换为普通的实体(DataAccess.Model.UploadFile) /// </summary> /// <param name="model">SubSonic插件生成的实体</param> /// <returns>DataAccess.Model.UploadFile</returns> public DataAccess.Model.UploadFile Transform(UploadFile model) { if (model == null) return null; return new DataAccess.Model.UploadFile { Id = model.Id, Name = model.Name, Path = model.Path, Ext = model.Ext, Src = model.Src, Size = model.Size, PicWidth = model.PicWidth, PicHeight = model.PicHeight, UploadConfig_Id = model.UploadConfig_Id, JoinName = model.JoinName, JoinId = model.JoinId, UserType = model.UserType, UserId = model.UserId, UserName = model.UserName, UserIp = model.UserIp, AddDate = model.AddDate, InfoText = model.InfoText, RndKey = model.RndKey, }; }
public void ProcessRequest(HttpContext context) { //--------------------------------------------------- var m_r = new UploadFile(); int vid = 0, userId = 0; const int userType = 1; string key = "", msg = "", userName = ""; //--------------------------------------------------- bool isSwf = (RequestHelper.PostText("swf", 1) == "1"); if (isSwf) { vid = RequestHelper.PostInt0("vid"); key = RequestHelper.PostText("key", 20); if (!StringHelper.IsRndKey(key)) { key = ""; } if (vid < 1 || key.Length < 10) { ShowMsg_Swf("缺少参数:key或sid"); return; } //--------------------------------------------------- #region 判断权限 userId = RequestHelper.PostInt0("uid"); if (userId < 1) { ShowMsg_Swf("缺少参数:uid"); return; } string uk = RequestHelper.PostText("uk", 32); if (uk.Length < 10) { ShowMsg_Swf("缺少参数:uk"); return; } string userKey = OnlineUsersBll.GetInstence().GetMd5(ConvertHelper.Cint0(userId)); if (userKey != uk) { ShowMsg_Swf("还未登陆,权限不足!"); return; } userName = OnlineUsersBll.GetInstence().GetManagerCName(ConvertHelper.Cint0(userId)); #endregion //--------------------------------------------------- msg = new UploadFileBll().Upload_Web(vid, key, userId, userName, m_r, "imgFile", userType, false, true); //--------------------------------------------------- if (msg.Length > 0) { ShowMsg_Swf(msg); } else { //上传成功,输出结果 ShowMsg_Swf("", 0, ConvertHelper.Cint0(m_r.Id), m_r.Name, m_r.Path, m_r.Src); } } else { //--------------------------------------------------- bool isEditor = (RequestHelper.GetQueryString("act") == "edit"); vid = RequestHelper.GetInt0("vid"); key = RequestHelper.GetKeyChar("key", 20); if (vid < 1 || key.Length < 10) { ShowMsg_Swf("缺少参数:key或sid"); return; } //--------------------------------------------------- #region 判断权限 if (SessionHelper.GetSession("UserHashKey") != null) { var uinfo = OnlineUsersBll.GetInstence().GetOnlineUsersModel(); userId = uinfo.Manager_Id; userName = uinfo.Manager_CName; } else { msg = "还未登陆,权限不足!"; if (isEditor)//编辑器 (ke4) { ShowMsg_Editor(msg); } else { //RequestHelper.AlertUtf8(msg, 3, ""); FineUI.Alert.Show(msg, "提示", MessageBoxIcon.Warning, "history.back();"); } return; } #endregion //--------------------------------------------------- msg = new UploadFileBll().Upload_Web(vid, key, userId, userName, m_r, "imgFile", userType, isEditor, false); if (msg.Length > 0) { if (isEditor)//编辑器 (ke4) { ShowMsg_Editor(msg); } else { //RequestHelper.AlertUtf8(msg, 3, ""); FineUI.Alert.Show(msg, "提示", MessageBoxIcon.Warning, "history.back();"); } } else { //上传成功,输出结果 if (isEditor)//编辑器 (ke4) { ShowMsg_Editor("上传成功", m_r.Path); } else { //RequestHelper.AlertUtf8("window.parent.OnUploadCompleted('" + m_r.Name + "','" + m_r.Path + "'," + m_r.Id.ToString() + ",'" + m_r.Src + "');", 7, ""); FineUI.Alert.Show("上传失败", "提示", MessageBoxIcon.Warning, "window.parent.OnUploadCompleted('" + m_r.Name + "','" + m_r.Path + "'," + m_r.Id.ToString() + ",'" + m_r.Src + "');"); } } } Write("系统暂时禁止上传文件!"); return; }
/// <summary> /// 添加与编辑UploadFile记录 /// </summary> /// <param name="page">当前页面指针</param> /// <param name="model">UploadFile表实体</param> /// <param name="content">更新说明</param> /// <param name="isCache">是否更新缓存</param> /// <param name="isAddUseLog">是否添加用户操作日志</param> public void Save(Page page, UploadFile model, string content = null, bool isCache = true, bool isAddUseLog = true) { try { //保存 model.Save(); //判断是否启用缓存 if (CommonBll.IsUseCache() && isCache) { SetModelForCache(model); } if (isAddUseLog) { if (string.IsNullOrEmpty(content)) { content = "{0}" + (model.Id == 0 ? "添加" : "编辑") + "UploadFile记录成功,ID为【" + model.Id + "】"; } //添加用户访问记录 UseLogBll.GetInstence().Save(page, content); } } catch (Exception e) { var result = "执行UploadFileBll.Save()函数出错!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } }
/// <summary> /// 数据保存 /// </summary> /// <returns></returns> public override string Save() { string result = string.Empty; int id = ConvertHelper.Cint0(hidId.Text); try { #region 数据验证 if (string.IsNullOrEmpty(txtTitle.Text.Trim())) { return txtTitle.Label + "不能为空!"; } if (ddlInformationClass_Id.SelectedValue == "0") { return ddlInformationClass_Id.Label + "为必选项,请选择!"; } //判断是否重复 var sTitle = StringHelper.FilterSql(txtTitle.Text, true); var icId = ConvertHelper.Cint0(ddlInformationClass_Id.SelectedValue); if ( DataAccess.DataModel.Information.Exists( x => x.Title == sTitle && x.InformationClass_Id == icId && x.Id != id)) { return txtTitle.Label + "已存在!请重新输入!"; } #endregion #region 赋值 //获取实体 var model = new Information(x => x.Id == id); //------------------------------------------ //设置名称 model.Title = StringHelper.Left(txtTitle.Text, 100); //取得分类 model.InformationClass_Id = ConvertHelper.Cint0(ddlInformationClass_Id.SelectedValue); model.InformationClass_Root_Id = ConvertHelper.Cint0(InformationClassBll.GetInstence() .GetFieldValue(model.InformationClass_Id, InformationClassTable.ParentId)); if (model.InformationClass_Root_Id > 0) { model.InformationClass_Root_Name = InformationClassBll.GetInstence() .GetName(this, model.InformationClass_Root_Id); } model.InformationClass_Name = StringHelper.Left(ddlInformationClass_Id.SelectedText, 20); //重定向 model.RedirectUrl = StringHelper.Left(txtRedirectUrl.Text, 250); //------------------------------------------ //编辑器 model.Content = StringHelper.Left(txtText.Text, 0, true, false); model.Upload = StringHelper.Left(txtUpload.Text, 0, true, false); //这里必须用回前端存放的Key,不然删除时无法同步删除编辑器上传的图片 RndKey = StringHelper.Left(txtRndKey.Text, 0); //检查用户上传的文件和最后保存的文件是否有出入, //如果上传的文件大于保存的文件,把不保存,但本次操作已经上传的文件删除。 model.Upload = UploadFileBll.GetInstence().FCK_BatchDelPic(model.Content, model.Upload); //------------------------------------------ //其它值 model.NewsTime = dpNewsTime.SelectedDate ?? DateTime.Now; model.AddYear = model.NewsTime.Year; model.AddMonth = model.NewsTime.Month; model.AddDay = model.NewsTime.Day; model.Notes = StringHelper.Left(txtNotes.Text, 200); model.Keywords = StringHelper.Left(txtKeywords.Text, 50); model.Author = StringHelper.Left(txtAuthor.Text, 50); model.FromName = StringHelper.Left(txtFromName.Text, 50); model.SeoTitle = StringHelper.Left(txtSeoTitle.Text, 100); model.SeoKey = StringHelper.Left(txtSeoKey.Text, 100); model.SeoDesc = StringHelper.Left(txtSeoDesc.Text, 200); model.Sort = 0; //设定当前项是否显示 model.IsDisplay = ConvertHelper.StringToByte(rblIsDisplay.SelectedValue); model.IsHot = ConvertHelper.StringToByte(rblIsHot.SelectedValue); model.IsTop = ConvertHelper.StringToByte(rblIsTop.SelectedValue); //------------------------------------------ //判断是否是新增 if (model.Id == 0) { //添加时间与用户 model.AddDate = DateTime.Now; //修改时间与用户 model.UpdateDate = DateTime.Now; } else { //修改时间与用户 model.UpdateDate = DateTime.Now; } model.Manager_Id = OnlineUsersBll.GetInstence().GetManagerId(); model.Manager_CName = OnlineUsersBll.GetInstence().GetManagerCName(); #endregion //------------------------------------------ #region 上传图片 if (this.filePhoto.HasFile && this.filePhoto.FileName.Length > 3) { int vid = 3; //3 文章封面 //--------------------------------------------------- var upload = new UploadFile(); result = new UploadFileBll().Upload_AspNet(this.filePhoto.PostedFile, vid, RndKey, OnlineUsersBll.GetInstence().GetManagerId(), OnlineUsersBll.GetInstence().GetManagerCName(), upload); this.filePhoto.Dispose(); //--------------------------------------------------- if (result.Length == 0) //上传成功 { model.FrontCoverImg = upload.Path; } else { CommonBll.WriteLog("上传出错:" + result); //收集异常信息 return "上传出错!" + result; } } //如果是修改,检查用户是否重新上传过封面图片,如果是删除旧的图片 if (model.Id > 0) { UploadFileBll.GetInstence() .Upload_DiffFile(InformationTable.Id, InformationTable.FrontCoverImg, InformationTable.TableName, model.Id, model.FrontCoverImg); //同步UploadFile上传表 UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, InformationTable.TableName, model.Id); } #endregion //---------------------------------------------------------- //存储到数据库 InformationBll.GetInstence().Save(this, model); #region 同步更新上传图片表绑定Id if (id == 0) { //同步UploadFile上传表记录,绑定刚刚上传成功的文件Id为当前记录Id UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, InformationTable.TableName, model.Id); } #endregion } catch (Exception e) { result = "保存失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } return result; }
/// <summary> /// 数据保存 /// </summary> /// <returns></returns> public override string Save() { string result = string.Empty; int id = ConvertHelper.Cint0(hidId.Text); try { #region 数据验证 if (string.IsNullOrEmpty(txtLoginName.Text.Trim())) { return txtLoginName.Label + "不能为空!"; } var logName = StringHelper.Left(txtLoginName.Text, 20); if (Manager.Exists(x => x.LoginName == logName && x.Id != id)) { return txtLoginName.Label + "已存在!请重新输入!"; } //新增用户时,密码不能为空 if (id == 0 && string.IsNullOrEmpty(txtLoginPass.Text.Trim())) { return "密码不能为空!"; } //密码长度不能短于6位 if (!string.IsNullOrEmpty(txtLoginPass.Text.Trim()) && txtLoginPass.Text.Trim().Length < 6) { return "密码长度必须6位以上,请重新输入!"; } if (!txtLoginPass.Text.Equals(txtLoginPassaAgin.Text)) return "两次输入的密码不一样,请重新输入!"; if (string.IsNullOrEmpty(txtCName.Text.Trim())) { return txtCName.Label + "不能为空!"; } //所属部门 if (ConvertHelper.Cint0(ddlBranch_Id.SelectedValue) < 1) { return ddlBranch_Id.Label + "为必选项,请选择!"; } //所属职位 if (string.IsNullOrEmpty(hidPositionId.Text)) { return txtPosition.Label + "为必选项,请选择!"; } #endregion #region 赋值 //获取实体 var model = new Manager(x => x.Id == id); model.LoginName = logName; //如果是添加管理员 if (id == 0) { model.CreateTime = DateTime.Now; model.UpdateTime = DateTime.Now; model.Manager_Id = OnlineUsersBll.GetInstence().GetManagerId(); model.Manager_CName = OnlineUsersBll.GetInstence().GetManagerCName(); model.LoginPass = Encrypt.Md5(Encrypt.Md5(txtLoginPass.Text)); model.IsWork = 1; } else { //修改时间与管理员 model.UpdateTime = DateTime.Now; model.Manager_Id = OnlineUsersBll.GetInstence().GetManagerId(); model.Manager_CName = OnlineUsersBll.GetInstence().GetManagerCName(); //修改用户时,填写了密码,则更新密码 if (txtLoginPass.Text.Trim().Length >= 6) { model.LoginPass = Encrypt.Md5(Encrypt.Md5(txtLoginPass.Text)); } } model.Branch_Id = ConvertHelper.Cint0(ddlBranch_Id.SelectedValue); var branch = BranchBll.GetInstence().GetModelForCache(x => x.Id == model.Branch_Id); if (branch != null) { model.Branch_Code = branch.Code; model.Branch_Name = branch.Name; } model.Position_Id = StringHelper.Left(hidPositionId.Text, 100); model.Position_Name = StringHelper.Left(txtPosition.Text, 500); model.CName = StringHelper.Left(txtCName.Text, 20); model.EName = StringHelper.Left(txtEName.Text, 50); model.Sex = StringHelper.Left(rblSex.SelectedValue, 4); model.Birthday = StringHelper.Left(dpBirthday.Text, 20); model.Record = StringHelper.Left(txtRecord.Text, 25); model.GraduateCollege = StringHelper.Left(txtGraduateCollege.Text, 30); model.GraduateSpecialty = StringHelper.Left(txtGraduateSpecialty.Text, 50); model.Tel = StringHelper.Left(txtTel.Text, 30); model.Mobile = StringHelper.Left(txtMobile.Text, 30); model.Email = StringHelper.Left(txtEmail.Text, 50); model.Qq = StringHelper.Left(txtQq.Text, 30); model.Msn = StringHelper.Left(txtMsn.Text, 30); model.Address = StringHelper.Left(txtAddress.Text, 100); model.IsEnable = ConvertHelper.Ctinyint(rblIsEnable.SelectedValue); model.IsMultiUser = ConvertHelper.Ctinyint(rblIsMultiUser.SelectedValue); model.Content = StringHelper.Left(txtContent.Text, 0); model.NationalName = StringHelper.Left(txtNationalName.Text, 50); model.NativePlace = StringHelper.Left(txtNativePlace.Text, 100); #region 上传图片 if (this.fuSinger_AvatarPath.HasFile && this.fuSinger_AvatarPath.FileName.Length > 3) { int vid = 1; //1 管理员头像(头像图片) //--------------------------------------------------- var upload = new UploadFile(); result = new UploadFileBll().Upload_AspNet(this.fuSinger_AvatarPath.PostedFile, vid, RndKey, OnlineUsersBll.GetInstence().GetManagerId(), OnlineUsersBll.GetInstence().GetManagerCName(), upload); this.fuSinger_AvatarPath.Dispose(); //--------------------------------------------------- if (result.Length == 0)//上传成功 { model.PhotoImg = upload.Path; } else { CommonBll.WriteLog("上传管理员头像图片未成功:" + result, null);//收集异常信息 return "上传管理员头像图片未成功!" + result; } } //如果是修改,检查用户是否重新上传过封面图片,如果是删除旧的图片 if (model.Id > 0) { UploadFileBll.GetInstence().Upload_DiffFile(ManagerTable.Id, ManagerTable.PhotoImg, ManagerTable.TableName, model.Id, model.PhotoImg); //同步UploadFile上传表 UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, ManagerTable.TableName, model.Id); } #endregion #endregion //---------------------------------------------------------- //存储到数据库 ManagerBll.GetInstence().Save(this, model); #region 同步更新上传图片表绑定Id if (id == 0) { //同步UploadFile上传表记录,绑定刚刚上传成功的文件Id为当前记录Id UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, ManagerTable.TableName, model.Id); } #endregion } catch (Exception e) { result = "保存失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } return result; }
/// <summary> /// 数据保存 /// </summary> /// <returns></returns> public override string Save() { string result = string.Empty; int id = ConvertHelper.Cint0(hidId.Text); try { #region 数据验证 if (string.IsNullOrEmpty(txtName.Text.Trim())) { return txtName.Label + "不能为空!"; } var sName = StringHelper.Left(txtName.Text, 20); if (InformationClassBll.GetInstence().Exist(x => x.Name == sName && x.Id != id)) { return txtName.Label + "已存在!请重新输入!"; } #endregion #region 赋值 //定义是否更新其他关联表变量 bool isUpdate = false; var oldParentId = ConvertHelper.Cint0(txtParent.Text); //获取实体 var model = new InformationClass(x => x.Id == id); //判断是否有改变名称 if (id > 0 && sName != model.Name) { isUpdate = true; } //修改时间与管理员 model.UpdateDate = DateTime.Now; model.Manager_Id = OnlineUsersBll.GetInstence().GetManagerId(); model.Manager_CName = OnlineUsersBll.GetInstence().GetManagerCName(); //设置名称 model.Name = sName; //对应的父类id model.ParentId = oldParentId; //设置备注 model.Notes = StringHelper.Left(txtNotes.Text, 100); //由于限制了编辑时不能修改父节点,所以这里只对新建记录时处理 if (id == 0) { //设定当前的深度与设定当前的层数级 if (model.ParentId == 0) { //设定当前的层数级 model.Depth = 0; //父Id为0时,根Id也为0 model.RootId = 0; } else { //设定当前的层数 model.Depth = ConvertHelper.Cint0(InformationClassBll.GetInstence().GetFieldValue(ConvertHelper.Cint0(ddlParentId.SelectedValue),InformationClassTable.Depth)) + 1; //获取父类的父Id model.RootId = ConvertHelper.Cint0(InformationClassBll.GetInstence().GetFieldValue(model.ParentId, InformationClassTable.ParentId)); } //限制分类层数只能为3层 if (model.Depth > 3) { return "信息分类只能创建3层分类!"; } } //设置排序 model.Sort = ConvertHelper.Cint0(txtSort.Text); if (model.Sort == 0) { model.Sort = InformationClassBll.GetInstence().GetSortMax(model.ParentId) + 1; } //设定当前项是否显示 model.IsShow = ConvertHelper.StringToByte(rblIsShow.SelectedValue); //设定当前项是否单页 model.IsPage = ConvertHelper.StringToByte(rblIsPage.SelectedValue); //SEO model.SeoTitle = StringHelper.Left(txtSeoTitle.Text, 100); model.SeoKey = StringHelper.Left(txtSeoKey.Text, 100); model.SeoDesc = StringHelper.Left(txtSeoDesc.Text, 200); #endregion #region 上传图片 //上传分类大图 if (this.fuClassImg.HasFile && this.fuClassImg.FileName.Length > 3) { int vid = 2; //2 信息(新闻)分类图 //--------------------------------------------------- var upload = new UploadFile(); result = new UploadFileBll().Upload_AspNet(this.fuClassImg.PostedFile, vid, RndKey, OnlineUsersBll.GetInstence().GetManagerId(), OnlineUsersBll.GetInstence().GetManagerCName(), upload); this.fuClassImg.Dispose(); //--------------------------------------------------- if (result.Length == 0)//上传成功 { model.ClassImg = upload.Path; } else { CommonBll.WriteLog("上传出错:" + result, null);//收集异常信息 return "上传出错!" + result; } } //如果是修改,检查用户是否重新上传过新图片,如果是删除旧的图片 if (model.Id > 0) { UploadFileBll.GetInstence().Upload_DiffFile(InformationClassTable.Id, InformationClassTable.ClassImg, InformationClassTable.TableName, model.Id, model.ClassImg); //同步UploadFile上传表 UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, InformationClassTable.TableName, model.Id); } #endregion //---------------------------------------------------------- //存储到数据库 InformationClassBll.GetInstence().Save(this, model); #region 同步更新上传图片表绑定Id if (id == 0) { //同步UploadFile上传表记录,绑定刚刚上传成功的文件Id为当前记录Id UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, InformationClassTable.TableName, model.Id); } #endregion //如果本次修改改变了相关名称,则同步更新其他关联表的对应名称 if (isUpdate) { InformationBll.GetInstence().UpdateValue_For_InformationClass_Id(this, model.Id, InformationTable.InformationClass_Name, model.Name); InformationBll.GetInstence().UpdateValue_For_InformationClass_Root_Id(this, model.Id, InformationTable.InformationClass_Root_Name, model.Name); } } catch (Exception e) { result = "保存失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } return result; }
/// <returns>上传成功返回"",并填充 UploadFile(AspNet上传控件专用)</returns> /// <param name="oFile">System.Web.HttpPostedFile</param> /// <param name="vid">上传配置模块id,即Id</param> /// <param name="key">随机key</param> /// <param name="userId">上传者id</param> /// <param name="userName">上传者UserName</param> /// <param name="m_r">UploadFile</param> /// <param name="userType">0=未知,1=后台管理员上传,2=前台会员上传</param> /// <returns>上传成功返回"",并填充 UploadFile</returns> public string Upload_AspNet(System.Web.HttpPostedFile oFile, int vid, string key, int userId, string userName, UploadFile m_r, int userType = 1) { #region 检查参数 //--------------------------------------------------- if (vid < 1 || key.Length < 10) { return "缺少参数:key或sid"; } //--------------------------------------------------- UploadConfig mC = Read_UploadConfig(vid); if (mC.Id != vid) { return "缺少参数:Id!"; } if (mC.IsPost != 1) { return "系统暂时禁止上传文件2!"; } if (mC.IsEditor == 1) { return "非编辑器类别!"; } #endregion //--------------------------------------------------- #region 检查登陆 m_r.UserId = 0; if (mC.UserType == 1)//管理员 { if (userType == 1) { m_r.UserId = userId; m_r.UserName = userName; } } else { if (userType == 2)//一般会员 { m_r.UserId = userId; m_r.UserName = userName; } } if (m_r.UserId == 0) { return "您的权限不足!"; } #endregion //------------------------------------------------ #region 设置上传参数 var oUp = new Uploader(); oUp.IsEnabled = true; oUp.IsChkSrcPost = true; oUp.CutType = ConvertHelper.Cint0(mC.CutType); oUp.AllowedExt = Get_Ext(mC.UploadType_TypeKey); oUp.MaxSize = (mC.UploadType_TypeKey == "image") ? ConvertHelper.Cint0(mC.PicSize) : ConvertHelper.Cint0(mC.FileSize); oUp.SavePath = mC.SaveDir; oUp.SetPic((mC.IsFixPic == 1), ConvertHelper.Cint0(mC.PicWidth), ConvertHelper.Cint0(mC.PicHeight), ConvertHelper.Cint0(mC.PicQuality)); oUp.SetBig((mC.IsBigPic == 1), ConvertHelper.Cint0(mC.BigWidth), ConvertHelper.Cint0(mC.BigHeight), ConvertHelper.Cint0(mC.BigQuality)); oUp.SetMid((mC.IsMidPic == 1), ConvertHelper.Cint0(mC.MidWidth), ConvertHelper.Cint0(mC.MidHeight), ConvertHelper.Cint0(mC.MidQuality)); oUp.SetMin((mC.IsMinPic == 1), ConvertHelper.Cint0(mC.MinWidth), ConvertHelper.Cint0(mC.MinHeight), ConvertHelper.Cint0(mC.MinQuality)); oUp.SetHot((mC.IsHotPic == 1), ConvertHelper.Cint0(mC.HotWidth), ConvertHelper.Cint0(mC.HotHeight), ConvertHelper.Cint0(mC.HotQuality)); oUp.IsWaterPic = (mC.IsWaterPic == 1); #endregion #region 上传 //------------------------------------------------ bool isOk = oUp.UploadFile(oFile); if (!isOk) { //上传出错 return StringHelper.XssTextClear(oUp.GetErrMsg() + mC.Id); } #endregion //---------------------------------------------------------------- #region 保存入数据库 m_r.UploadConfig_Id = mC.Id; m_r.JoinName = mC.JoinName; m_r.JoinId = 0; m_r.UserType = mC.UserType; m_r.UserIp = IpHelper.GetUserIp(); m_r.AddDate = DateTime.Now; m_r.InfoText = ""; m_r.RndKey = key; m_r.Name = oUp.NewFile; m_r.Path = oUp.NewPath; m_r.Src = StringHelper.Left(oUp.SrcName, 90, false); m_r.Ext = oUp.FileExt; m_r.Size = oUp.GetFileSize(); m_r.PicWidth = oUp.NewWidth; m_r.PicHeight = oUp.NewHeight; //保存入数据库 Add_UploadFile(m_r); #endregion //------------------------------------ //上传成功,输出结果 return ""; }
public void ProcessRequest(HttpContext context) { //--------------------------------------------------- int vid = RequestHelper.GetInt0("vid"); string key = RequestHelper.GetKeyChar("key", 20); if (vid < 1 || key.Length < 10) { ShowMsg_Editor("缺少参数:key或sid"); return; } string pic = RequestHelper.PostText("pic", 200, false); if (!isRemotePic(pic)) { ShowMsg_Editor("图片地址格式不正确!"); return; } //--------------------------------------------------- #region 判断权限 int userId = 0; string userName = ""; if (SessionHelper.GetSession("UserHashKey") != null) { var uinfo = OnlineUsersBll.GetInstence().GetOnlineUsersModel(); userId = uinfo.Manager_Id; userName = uinfo.Manager_CName; } else { ShowMsg_Editor("还未登陆,权限不足!"); return; } #endregion /* 测试使用 int vid = 52; string key = RandomHelp.GetRndKey(); string pic = "http://bidhtml.july.com/Images/ad/indexHotAd.jpg"; int userId = 4; string userName = "******"; */ //--------------------------------------------------- var m_r = new UploadFile(); string msg = new UploadFileBll().Upload_RemotePic(vid, key, userId, userName, pic, m_r); if (msg.Length > 0) { ShowMsg_Editor(msg); } else { ShowMsg_Editor("上传成功", m_r.Path); } Write("系统暂时禁止上传文件!"); //RequestHelper.AlertUtf8("系统暂时禁止上传文件!", 8, ""); return; }
public static void Setup(UploadFile item) { SetTestRepo(); _testRepo._items.Add(item); }
/// <summary> /// 数据保存 /// </summary> /// <returns></returns> public override string Save() { string result = string.Empty; int id = ConvertHelper.Cint0(hidId.Text); try { #region 数据验证 if (string.IsNullOrEmpty(txtName.Text.Trim())) { return txtName.Label + "不能为空!"; } //判断是否重复 var sName = StringHelper.Left(txtName.Text, 50); if (AdvertisementBll.GetInstence().Exist(x => x.Name == sName && x.Id != id)) { return txtName.Label + "已存在!请重新输入!"; } if (ddlAdvertisingPosition.SelectedValue == "0") { return ddlAdvertisingPosition.Label + "为必选项,请选择!"; } if (dpStartTime.SelectedDate == null || TimeHelper.IsDateTime(dpStartTime.SelectedDate) == false) { return "请选择" + dpStartTime.Label; } if (dpEndTime.SelectedDate == null || TimeHelper.IsDateTime(dpEndTime.SelectedDate) == false) { return "请选择" + dpEndTime.Label; } if (dpStartTime.SelectedDate > dpEndTime.SelectedDate) { return dpStartTime.Label + "不能大于" + dpEndTime.Label; } #endregion #region 赋值 //获取实体 var model = new Advertisement(x => x.Id == id); //------------------------------------------ //设置名称 model.Name = sName; model.Keyword = StringHelper.Left(txtKeyword.Text, 50); model.Url = StringHelper.Left(txtUrl.Text, 200, true, false); //说明 model.Content = StringHelper.Left(txtContent.Text, 100); //取得位置 model.AdvertisingPosition_Id = ConvertHelper.Cint0(ddlAdvertisingPosition.SelectedValue); model.AdvertisingPosition_Name = StringHelper.Left(ddlAdvertisingPosition.SelectedText, 50); //开始时间与结束时间 model.StartTime = dpStartTime.SelectedDate ?? DateTime.Now; model.EndTime = dpEndTime.SelectedDate ?? DateTime.Now.AddDays(1); //设定当前项是否显示 model.IsDisplay = ConvertHelper.StringToByte(rblIsDisplay.SelectedValue); model.Sort = ConvertHelper.Cint0(txtSort.Text); ; //修改时间与用户 model.UpdateDate = DateTime.Now; model.Manager_Id = OnlineUsersBll.GetInstence().GetManagerId(); model.Manager_CName = OnlineUsersBll.GetInstence().GetManagerCName(); #endregion //------------------------------------------ #region 上传图片 //判断前端的ASP.NET上传控件是否选择有上传文件 if (this.filePhoto.HasFile && this.filePhoto.FileName.Length > 3) { //将当前页面上传文件绑定上传配置表Id为7的记录,给上传组件的逻辑层函数调用 int vid = 7; //7 广告 //--------------------------------------------------- //创建上传实体 var upload = new UploadFile(); //调用ASP.NET上传控件上传函数,并获取上传成功或失败信息 result = new UploadFileBll().Upload_AspNet(this.filePhoto.PostedFile, vid, RndKey, OnlineUsersBll.GetInstence().GetManagerId(), OnlineUsersBll.GetInstence().GetManagerCName(), upload); this.filePhoto.Dispose(); //--------------------------------------------------- //没有返回信息时表示上传成功 if (result.Length == 0) { //将上传到服务器后的路径赋给广告实体对应字段 model.AdImg = upload.Path; } else { //将出错写入日志中 CommonBll.WriteLog("上传出错:" + result); //收集异常信息 //弹出出错提示 return "上传出错!" + result; } } //如果是修改,检查用户是否重新上传过广告图片,如果是删除旧的图片 if (model.Id > 0) { //删除旧图片 UploadFileBll.GetInstence() .Upload_DiffFile(AdvertisementTable.Id, AdvertisementTable.AdImg, AdvertisementTable.TableName, model.Id, model.AdImg); //同步UploadFile上传表记录,绑定刚刚上传成功的文件Id为当前记录Id UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, AdvertisementTable.TableName, model.Id); } #endregion //---------------------------------------------------------- //存储到数据库 AdvertisementBll.GetInstence().Save(this, model); #region 同步更新上传图片表绑定Id if (id == 0) { //同步UploadFile上传表记录,绑定刚刚上传成功的文件Id为当前记录Id UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, AdvertisementTable.TableName, model.Id); } #endregion //这里放置清空前端页面缓存的代码(如果前端使用了页面缓存的话,必须进行清除操作) } catch (Exception e) { result = "保存失败!"; //出现异常,保存出错日志广告 CommonBll.WriteLog(result, e); } return result; }
/// <returns>上传成功返回"",并填充 UploadFile</returns> /// <param name="vid">上传配置模块id,即Id</param> /// <param name="key">随机key</param> /// <param name="userId">上传者id</param> /// <param name="userName">上传者UserName</param> /// <param name="m_r">UploadFile</param> /// <param name="filePostName">上传文件框控件的名称,默认"imgFile",uploadify 默认 "Filedata"</param> /// <param name="userType">0=未知,1=后台管理员上传,2=前台会员上传</param> /// <param name="isEditor">从GetAction返回判断是否为编辑器</param> /// <param name="isSwf">是否通过flash上传</param> /// <returns>上传成功返回"",并填充 UploadFile</returns> public string Upload_Web(int vid, string key, int userId, string userName, UploadFile m_r, string filePostName = "imgFile", int userType = 1, bool isEditor = false, bool isSwf = false) { #region 检查参数 //--------------------------------------------------- if (vid < 1 || key.Length < 10) { return "缺少参数:key或sid"; } string dir = RequestHelper.GetKeyChar("dir");//编辑器专用:image,flash,media,file if (dir.Length > 0) { if (Array.IndexOf("image,flash,media,file".Split(','), dir) == -1) { return "缺少参数:dir"; } } //--------------------------------------------------- UploadConfig mC = Read_UploadConfig(vid); if (mC == null || mC.Id != vid) { return "缺少参数:上传配置Id设置不正确!"; } if (mC.IsPost != 1) { return "系统暂时禁止上传文件2!"; } if (mC.IsEditor == 1 && isEditor == false) { return "非编辑器类别!"; } if (mC.IsSwf == 0 && isSwf == true) { return "不能从flash中上传!"; } #endregion //--------------------------------------------------- #region 检查登陆 m_r.UserId = 0; if (mC.UserType == 1)//管理员 { if (userType == 1) { m_r.UserId = userId; m_r.UserName = userName; } } else { if (userType == 2)//一般会员 { m_r.UserId = userId; m_r.UserName = userName; } } if (m_r.UserId == 0) { return "您的权限不足!"; } #endregion //------------------------------------------------ #region 设置上传参数 var oUp = new Uploader(); oUp.IsEnabled = true; if (isSwf) { oUp.IsChkSrcPost = false; //如果swf提交,必须设置为 o_up.isChkSrcPost = false; } else { //o_up.isChkSrcPost = (m_c.isChkSrcPost == "1"); //如果swf提交,必须设置为 o_up.isChkSrcPost = false; oUp.IsChkSrcPost = true; } oUp.CutType = ConvertHelper.Cint0(mC.CutType); oUp.FilePostName = filePostName; if (isEditor && mC.UploadType_TypeKey == "editor") { mC.UploadType_TypeKey = dir; } oUp.AllowedExt = Get_Ext(mC.UploadType_TypeKey); oUp.MaxSize = (mC.UploadType_TypeKey == "image") ? ConvertHelper.Cint0(mC.PicSize) : ConvertHelper.Cint0(mC.FileSize); oUp.SavePath = mC.SaveDir; oUp.SetPic((mC.IsFixPic == 1), ConvertHelper.Cint0(mC.PicWidth), ConvertHelper.Cint0(mC.PicHeight), ConvertHelper.Cint0(mC.PicQuality)); oUp.SetBig((mC.IsBigPic == 1), ConvertHelper.Cint0(mC.BigWidth), ConvertHelper.Cint0(mC.BigHeight), ConvertHelper.Cint0(mC.BigQuality)); oUp.SetMid((mC.IsMidPic == 1), ConvertHelper.Cint0(mC.MidWidth), ConvertHelper.Cint0(mC.MidHeight), ConvertHelper.Cint0(mC.MidQuality)); oUp.SetMin((mC.IsMinPic == 1), ConvertHelper.Cint0(mC.MinWidth), ConvertHelper.Cint0(mC.MinHeight), ConvertHelper.Cint0(mC.MinQuality)); oUp.SetHot((mC.IsHotPic == 1), ConvertHelper.Cint0(mC.HotWidth), ConvertHelper.Cint0(mC.HotHeight), ConvertHelper.Cint0(mC.HotQuality)); oUp.IsWaterPic = (mC.IsWaterPic == 1); #endregion #region 上传 //------------------------------------------------ bool isOk = oUp.UploadFile(); if (!isOk) { //上传出错 return StringHelper.XssTextClear(oUp.GetErrMsg() + mC.Id); } #endregion //---------------------------------------------------------------- #region 保存入数据库 m_r.UploadConfig_Id = mC.Id; m_r.JoinName = mC.JoinName; m_r.JoinId = 0; m_r.UserType = mC.UserType; m_r.UserIp = IpHelper.GetUserIp(); m_r.AddDate = DateTime.Now; m_r.InfoText = ""; m_r.RndKey = key; m_r.Name = oUp.NewFile; m_r.Path = oUp.NewPath; m_r.Src = StringHelper.Left(oUp.SrcName, 90); m_r.Ext = oUp.FileExt; m_r.Size = oUp.GetFileSize(); m_r.PicWidth = oUp.NewWidth; m_r.PicHeight = oUp.NewHeight; //保存入数据库 Add_UploadFile(m_r); #endregion //------------------------------------ //上传成功,输出结果 return ""; }
/// <returns>上传成功返回"",并填充 Model.UploadFile</returns> /// <param name="vid">上传配置模块id,即UploadConfig_Id</param> /// <param name="key">随机key</param> /// <param name="userId">上传者id</param> /// <param name="userName">上传者UserName</param> /// <param name="remotePicUrl">远程图片的url地址</param> /// <param name="m_r">Model.UploadFile</param> /// <returns>上传成功返回"",并填充 Model.UploadFile</returns> public string Upload_RemotePic(int vid, string key, int userId, string userName, string remotePicUrl, UploadFile m_r) { #region 检查参数 //--------------------------------------------------- if (vid < 1 || key.Length < 10) { return "缺少参数:key或sid"; } //--------------------------------------------------- #region 检查登陆 m_r.UserId = userId; m_r.UserName = userName; if (m_r.UserId == 0) { return "您的权限不足!"; } #endregion //--------------------------------------------------- UploadConfig mC = Read_UploadConfig(vid); if (mC.Id != vid) { return "缺少参数:UploadConfig_Id!"; } if (mC.IsPost != 1) { return "系统暂时禁止上传文件2!"; } if (mC.IsEditor != 1) { return "非编辑器类别!"; } mC.UploadType_TypeKey = "image"; #endregion //---------------------------------------------- #region 生成暂时目录 string sCfgSavePath = new Uploader().SavePath; string sSavePath = DirFileHelper.FixDirPath(sCfgSavePath + mC.SaveDir) + DateTime.Now.ToString("yyMM") + "/"; if (!DirFileHelper.CheckSaveDir(sSavePath)) { return "SavePath设置不当:" + sSavePath + ", 或权限不足!"; } string sServerDir = sCfgSavePath + "remote/"; if (!DirFileHelper.CheckSaveDir(sServerDir)) { return "ServerDir设置不当:" + sServerDir + ", 或权限不足!"; } //---------------------------------------------- string sSrcName = StringHelper.Left(DirFileHelper.GetFileName(remotePicUrl), 90); string sFileExt = DirFileHelper.GetFileExtension(sSrcName); //因部部分网站不是标准的jpg、gif扩展名,所以修改下面代码 if (sFileExt.Length > 0) { string sAllowed = ",jpg,gif,png,bmp,"; string sExt = "," + sFileExt.ToLower() + ","; if (sAllowed.IndexOf(sExt) == -1) { sFileExt = "jpg"; } } else { sFileExt = "jpg"; } //---------------------------------------------- string sNewFile = DirFileHelper.GetRndFileName("." + sFileExt); if (sServerDir.IndexOf(":") < 0) { sServerDir = DirFileHelper.FixDirPath(DirFileHelper.GetMapPath(sServerDir)); } string sNewRoot = System.IO.Path.Combine(sServerDir, sNewFile); #endregion //---------------------------------------------- #region 上传到暂时目录 try { var wc = new System.Net.WebClient(); wc.DownloadFile(remotePicUrl, sNewRoot); } catch (Exception ex) { //throw ex; return ex.Message.ToLower(); } if (!DirFileHelper.IsExistFile(sNewRoot)) { return "上传失败"; } #endregion //---------------------------------------------- #region 判断是否真实图片格式,并取得图片宽高 int ww = 0, hh = 0; if (!Uploader.Get_Pic_WW_HH(sNewRoot, out ww, out hh)) { DirFileHelper.DeleteFile(sNewRoot); return "非法格式!不是图片文件。"; } int iMaxSize = mC.PicSize; long iFileSize = DirFileHelper.GetFileSize(sNewRoot); /* if (iFileSize > iMaxSize) { return "上传文件大小超过了限制.最多上传(" + DirFileHelper.FmtFileSize2(iMaxSize) + ")."; } */ #endregion #region 把上传的暂时文件复制到相关模块目录中 string sNewPath = sSavePath + sNewFile; string orgImg = DirFileHelper.GetFilePathPostfix(sNewPath, "o"); //复制到原始图 DirFileHelper.CopyFile(sNewRoot, orgImg); //删除暂时上传的图片 DirFileHelper.DeleteFile(sNewRoot); //生成相关缩略图 OneMakeThumbImage(sNewPath, mC); #endregion //---------------------------------------------- #region 保存入数据库 m_r.UploadConfig_Id = mC.Id; m_r.JoinName = mC.JoinName; m_r.JoinId = 0; m_r.UserType = mC.UserType; m_r.UserIp = IpHelper.GetUserIp(); m_r.AddDate = DateTime.Now; m_r.InfoText = ""; m_r.RndKey = key; m_r.Name = sNewFile; m_r.Path = sNewPath; m_r.Src = sSrcName; m_r.Ext = sFileExt; m_r.Size = ConvertHelper.Cint0(iFileSize); m_r.PicWidth = ww; m_r.PicHeight = hh; //保存入数据库 Add_UploadFile(m_r); #endregion //------------------------------------ //上传成功,输出结果 return ""; }
/// <summary> /// 数据保存 /// </summary> /// <returns></returns> public override string Save() { string result = string.Empty; int id = ConvertHelper.Cint0(hidId.Text); try { #region 数据验证 if (string.IsNullOrEmpty(txtName.Text.Trim())) { return txtName.Label + "不能为空!"; } var sName = StringHelper.Left(txtName.Text, 50); if (AdvertisingPositionBll.GetInstence().Exist(x => x.Name == sName && x.Id != id)) { return txtName.Label + "已存在!请重新输入!"; } if (string.IsNullOrEmpty(txtKey.Text.Trim())) { return txtKey.Label + "不能为空!"; } var sKeyword = StringHelper.Left(txtKey.Text, 50); if (AdvertisingPositionBll.GetInstence().Exist(x => x.Keyword == sKeyword && x.Id != id)) { return txtKey.Label + "已存在!请重新输入!"; } #endregion #region 赋值 //定义是否更新其他关联表变量 bool isUpdate = false; //读取当前地址信息 var model = new AdvertisingPosition(x => x.Id == id); //判断是否更新关联表 if (model.Id > 0 && sName != model.Name) isUpdate = true; //设置名称 model.Name = StringHelper.Left(txtName.Text, 50); //KEY model.Keyword = StringHelper.Left(txtKey.Text, 50); //对应的父类id model.ParentId = ConvertHelper.Cint0(txtParent.Text); //由于限制了编辑时不能修改父节点,所以这里只对新建记录时处理 if (id == 0) { //设定当前的深度与设定当前的层数级 if (model.ParentId == 0) { //设定当前的层数级 model.Depth = 0; } else { //设定当前的层数 model.Depth = ConvertHelper.Cint0(AdvertisingPositionBll.GetInstence().GetFieldValue(ConvertHelper.Cint0(ddlParentId.SelectedValue), AdvertisingPositionTable.Depth)) + 1; } //限制分类层数只能为2层 if (model.Depth > 2) { return "广告位置只能创建2层分类!"; } } //设置排序 if (txtSort.Text == "0") { model.Sort = AdvertisingPositionBll.GetInstence().GetSortMax(model.ParentId) + 1; } else { model.Sort = ConvertHelper.Cint0(txtSort.Text); } //设定当前项是否显示 model.IsDisplay = ConvertHelper.StringToByte(rblIsDisplay.SelectedValue); //广告宽与高 model.Width = ConvertHelper.Cint0(txtWidth.Text); model.Height = ConvertHelper.Cint0(txtHeight.Text); //添加最后修改人员 model.Manager_Id = OnlineUsersBll.GetInstence().GetManagerId(); model.Manager_CName = OnlineUsersBll.GetInstence().GetManagerCName(); model.AddDate = DateTime.Now; #endregion #region 上传图片 //上传广告位置图 if (this.MapImg.HasFile && this.MapImg.FileName.Length > 3) { int vid = 5; //5 广告位置图 //--------------------------------------------------- var upload = new UploadFile(); result = new UploadFileBll().Upload_AspNet(this.MapImg.PostedFile, vid, RndKey, OnlineUsersBll.GetInstence().GetManagerId(), OnlineUsersBll.GetInstence().GetManagerCName(), upload); this.MapImg.Dispose(); //--------------------------------------------------- if (result.Length == 0)//上传成功 { model.MapImg = upload.Path; } else { CommonBll.WriteLog("上传出错:" + result, null);//收集异常信息 return "上传出错!" + result; } } //如果是修改,检查用户是否重新上传过新图片,如果是删除旧的图片 if (model.Id > 0) { UploadFileBll.GetInstence().Upload_DiffFile(AdvertisingPositionTable.Id, AdvertisingPositionTable.MapImg, AdvertisingPositionTable.TableName, model.Id, model.MapImg); //同步UploadFile上传表 UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, AdvertisingPositionTable.TableName, model.Id); } //—————————————————————————————————————————————————————————————————————— //上传广告默认图 if (this.PicImg.HasFile && this.PicImg.FileName.Length > 3) { int vid = 6; //6 广告默认图 //--------------------------------------------------- var upload = new UploadFile(); result = new UploadFileBll().Upload_AspNet(this.PicImg.PostedFile, vid, RndKey, OnlineUsersBll.GetInstence().GetManagerId(), OnlineUsersBll.GetInstence().GetManagerCName(), upload); this.PicImg.Dispose(); //--------------------------------------------------- if (result.Length == 0)//上传成功 { model.PicImg = upload.Path; } else { CommonBll.WriteLog("上传出错:" + result, null);//收集异常信息 return "上传出错!" + result; } } //如果是修改,检查用户是否重新上传过默认图片,如果是删除旧的图片 if (model.Id > 0) { UploadFileBll.GetInstence().Upload_DiffFile(AdvertisingPositionTable.Id, AdvertisingPositionTable.PicImg, AdvertisingPositionTable.TableName, model.Id, model.PicImg); //同步UploadFile上传表 UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, AdvertisingPositionTable.TableName, model.Id); } #endregion //---------------------------------------------------------- //存储到数据库 AdvertisingPositionBll.GetInstence().Save(this, model); #region 同步更新上传图片表绑定Id if (id == 0) { //同步UploadFile上传表记录,绑定刚刚上传成功的文件Id为当前记录Id UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, AdvertisingPositionTable.TableName, model.Id); } #endregion //如果本次修改改变了相关名称,则同步更新其他关联表的对应名称 if (isUpdate) { AdvertisementBll.GetInstence().UpdateValue_For_AdvertisingPosition_Id(this, model.Id, AdvertisementTable.AdvertisingPosition_Name, model.Name); } } catch (Exception e) { result = "保存失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } return result; }
public static void Setup(int testItems) { SetTestRepo(); for(int i=0;i<testItems;i++){ UploadFile item=new UploadFile(); _testRepo._items.Add(item); } }
/// <summary>添加--UploadFile</summary> /// <param name="model">UploadFile实体</param> /// <returns></returns> public void Add_UploadFile(UploadFile model) { model.Save(); }