public void SaveData(ModAdActive t) { BllAdActive bll = new BllAdActive(); ModJsonResult json = new ModJsonResult(); if (CurrentMaster != null) { if (CurrentMaster.Id == Request["LoginUserId"].ToString()) { t.CreaterId = CurrentMaster.Id; //添加人 t.Info = t.Info == null ? "" : t.Info; //公告内容 if (t.ActionType == 2) { t.ActiveStartTime = Convert.ToDateTime(Request["ActiveStartTime"]); //开始时间 t.ActiveEndTime = Convert.ToDateTime(Request["ActiveEndTime"]); //结束时间 } t.ActionFormId = Request["ActionFormId"]; #region ===保存修改数据 if (!string.IsNullOrEmpty(Request["modify"])) //修改 { var Category = bll.LoadData(t.Id); if (String.IsNullOrEmpty(t.Img)) { t.Img = Category.Img;//图片 } t.CreateTime = Category.CreateTime; t.Status = Category.Status;//数据状态 if (t.ActiveEndTime > DateTime.Now && t.Status != (int)StatusEnum.禁用) { t.Status = (int)StatusEnum.正常; } if (t.ActionType == 1) //无时间限制 { if (t.Status == (int)StatusEnum.未激活) //已过期 { t.Status = (int)StatusEnum.正常; //数据状态 } } int result = bll.Update(t); if (result <= 0) { json.success = false; json.msg = "修改失败,请稍后再操作!"; } else { json.msg = "/Advertise/SaveData?Id='" + t.Id + "'&modify=1"; } } else { t.Id = Guid.NewGuid().ToString(); t.Status = (int)StatusEnum.正常;//状态 t.CreateTime = DateTime.Now; int result = bll.Insert(t); if (result <= 0) { json.success = false; json.msg = " 保存失败,请稍后再操作!"; } else { json.msg = "/Advertise/SaveData?ID='" + t.Id + "'&modify=1"; } } #endregion LogInsert(OperationTypeEnum.操作, "新闻公告", CurrentMaster.UserName + "公告新增或修改操作正常."); } else { json.success = false; json.msg = "用户信息已失效,请刷新或登陆."; } } else { json.success = false; json.msg = "用户信息已过期,请重新登陆."; } WriteJsonToPage(json.ToString()); }
public void SaveData(ModAdActive t) { BllAdActive bll = new BllAdActive(); ModJsonResult json = new ModJsonResult(); try { //获取文件 HttpPostedFileBase postedFile = Request.Files["Img"]; string filename = postedFile.FileName; //获取上传的文件路径 t.CreaterId = CurrentMaster.Id; //添加人 t.Info = t.Info == null ? "" : t.Info; //广告内容 t.ActionType = int.Parse(Request["ActionType"]); t.ShowType = int.Parse(Request["ShowType"]); if (t.ActionType == (int)AdvertiseEnum.内部广告 || t.ActionType == (int)AdvertiseEnum.外部广告 || t.ActionType == (int)AdvertiseEnum.资讯广告) { if (t.ActionType == (int)AdvertiseEnum.外部广告)//外部广告 { t.Info = Request["Link"]; t.ActionFormId = ""; //清空外键 } else if (t.ActionType == (int)AdvertiseEnum.资讯广告) //外部广告 { t.Info = Request["Link"]; t.ActionFormId = Request["ActionFormId"]; } else { t.ActionFormId = "";//清空外键 } } if (t.ShowType == 2) //自动下架 { t.ActiveStartTime = Convert.ToDateTime(Request["ActiveStartTime"]); //开始时间 t.ActiveEndTime = Convert.ToDateTime(Request["ActiveEndTime"]); //结束时间 } string str = ""; string path = "";//文件路径 bool succ = true; #region ===上传广告图 if (!String.IsNullOrEmpty(filename) || (!string.IsNullOrEmpty(Request["modify"]) && !string.IsNullOrEmpty(Request["isUpLoad"]))) //判断是否修改图片 { string configPath = System.Configuration.ConfigurationManager.AppSettings["PathAdvertise"]; //广告图片保存路径 if (new PicFileUpLoad().UpLoad("Advertise", postedFile, configPath, filename, out path, out str)) { t.Img = path; } else { succ = false; } } #endregion #region ===保存修改数据 if (succ) //判断广告图是否上传正确 { if (!string.IsNullOrEmpty(Request["modify"])) //修改 { var Category = bll.LoadData(t.Id); if (String.IsNullOrEmpty(t.Img)) { t.Img = Category.Img;//图片 } t.CreateTime = Category.CreateTime; t.Status = Category.Status;//数据状态 if (t.ActiveEndTime > DateTime.Now && t.Status != (int)StatusEnum.禁用) { t.Status = (int)StatusEnum.正常; } int result = bll.Update(t); if (result <= 0) { json.success = false; json.msg = "修改失败,请稍后再操作!"; } else { json.msg = "/Advertise/SaveData?Id='" + t.Id + "'&modify=1"; } LogInsert(OperationTypeEnum.操作, "广告修改操作", "广告修改操作成功"); } else { t.Id = Guid.NewGuid().ToString(); t.Status = (int)StatusEnum.正常;//状态 t.CreateTime = DateTime.Now; t.CompanyId = CurrentMaster.Cid; if (t.Img == null) { t.Img = "/Resource/img/null.jpg"; } int result = bll.Insert(t); if (result <= 0) { json.success = false; json.msg = " 保存失败,请稍后再操作!"; } else { json.msg = "/Advertise/SaveData?ID='" + t.Id + "'&modify=1"; } LogInsert(OperationTypeEnum.操作, "广告保存操作", "广告保存操作成功"); } } else { json.success = false; json.msg = str; } #endregion } catch (Exception ex) { LogInsert(OperationTypeEnum.异常, "广告保存/修改操作", "操作异常信息:" + ex); } WriteJsonToPage(json.ToString()); }