/// <summary>
 /// 获取本逻辑类单例
 /// </summary>
 /// <returns></returns>
 public static UploadFileBll GetInstence()
 {
     if (_UploadFileBll == null) {
         _UploadFileBll = new UploadFileBll();
     }
     return _UploadFileBll;
 }
        /// <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;
        }
        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>
        /// 数据保存
        /// </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(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;
        }
        /// <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;
        }
        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;
        }
        /// <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;
        }