Example #1
0
 public static void Setup(int testItems)
 {
     SetTestRepo();
     for(int i=0;i<testItems;i++){
         Advertisement item=new Advertisement();
         _testRepo._items.Add(item);
     }
 }
Example #2
0
 public static void Setup(Advertisement item)
 {
     SetTestRepo();
     _testRepo._items.Add(item);
 }
Example #3
0
        /// <summary>
        /// 将Advertisement记录实体(SubSonic实体)转换为普通的实体(DataAccess.Model.Advertisement)
        /// </summary>
        /// <param name="model">SubSonic插件生成的实体</param>
        /// <returns>DataAccess.Model.Advertisement</returns>
        public DataAccess.Model.Advertisement Transform(Advertisement model)
        {
            if (model == null)
                return null;

            return new DataAccess.Model.Advertisement
            {
                Id = model.Id,
                Name = model.Name,
                Content = model.Content,
                Url = model.Url,
                Keyword = model.Keyword,
                AdvertisingPosition_Id = model.AdvertisingPosition_Id,
                AdvertisingPosition_Name = model.AdvertisingPosition_Name,
                AdImg = model.AdImg,
                ShowRate = model.ShowRate,
                StartTime = model.StartTime,
                EndTime = model.EndTime,
                IsDisplay = model.IsDisplay,
                HitCount = model.HitCount,
                Sort = model.Sort,
                Manager_Id = model.Manager_Id,
                Manager_CName = model.Manager_CName,
                UpdateDate = model.UpdateDate,
            };
        }
Example #4
0
 /// <summary>
 /// 更新IIS缓存中指定Id记录
 /// </summary>
 /// <param name="model">记录实体</param>
 public void SetModelForCache(Advertisement model)
 {
     SetModelForCache(Transform(model));
 }
Example #5
0
        /// <summary>
        /// 添加与编辑Advertisement记录
        /// </summary>
        /// <param name="page">当前页面指针</param>
        /// <param name="model">Advertisement表实体</param>
        /// <param name="content">更新说明</param>
        /// <param name="isCache">是否更新缓存</param>
        /// <param name="isAddUseLog">是否添加用户操作日志</param>
        public void Save(Page page, Advertisement 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 ? "添加" : "编辑") + "Advertisement记录成功,ID为【" + model.Id + "】";
                    }

                    //添加用户访问记录
                    UseLogBll.GetInstence().Save(page, content);
                }
            }
            catch (Exception e) {
                var result = "执行AdvertisementBll.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(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;
        }