/// <summary> /// 更新一条记录(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <bool> UpdateAsync(AdvertisementEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "Update Advertisement SET " + "UserID = @UserID," + "ADType = @ADType," + "ADName = @ADName," + "ImgUrl = @ImgUrl," + "ImgWidth = @ImgWidth," + "ImgHeight = @ImgHeight," + "FlashWmode = @FlashWmode," + "ADIntro = @ADIntro," + "LinkUrl = @LinkUrl," + "LinkTarget = @LinkTarget," + "LinkAlt = @LinkAlt," + "Priority = @Priority," + "Setting = @Setting," + "IsCountView = @IsCountView," + "Views = @Views," + "IsCountClick = @IsCountClick," + "Clicks = @Clicks," + "IsAbsolutePath = @IsAbsolutePath," + "IsPassed = @IsPassed," + "OverdueDate = @OverdueDate" + " WHERE " + "ADID = @ADID"; return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict))); }
/// <summary> /// 通过数据读取器生成实体类 /// </summary> /// <param name="rdr"></param> /// <returns></returns> private static AdvertisementEntity GetEntityFromrdr(NullableDataReader rdr) { AdvertisementEntity info = new AdvertisementEntity(); info.ADID = rdr.GetInt32("ADID"); info.UserID = rdr.GetInt32("UserID"); info.ADType = rdr.GetInt32("ADType"); info.ADName = rdr.GetString("ADName"); info.ImgUrl = rdr.GetString("ImgUrl"); info.ImgWidth = rdr.GetInt32("ImgWidth"); info.ImgHeight = rdr.GetInt32("ImgHeight"); info.FlashWmode = rdr.GetInt32("FlashWmode"); info.ADIntro = rdr.GetString("ADIntro"); info.LinkUrl = rdr.GetString("LinkUrl"); info.LinkTarget = rdr.GetInt32("LinkTarget"); info.LinkAlt = rdr.GetString("LinkAlt"); info.Priority = rdr.GetInt32("Priority"); info.Setting = rdr.GetString("Setting"); info.IsCountView = rdr.GetBoolean("IsCountView"); info.Views = rdr.GetInt32("Views"); info.IsCountClick = rdr.GetBoolean("IsCountClick"); info.Clicks = rdr.GetInt32("Clicks"); info.IsAbsolutePath = rdr.GetBoolean("IsAbsolutePath"); info.IsPassed = rdr.GetBoolean("IsPassed"); info.OverdueDate = rdr.GetNullableDateTime("OverdueDate"); return(info); }
/// <summary> /// 增加一条记录(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <bool> AddAsync(AdvertisementEntity entity) { if (entity.ADID <= 0) { entity.ADID = GetNewID(); } Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "insert into Advertisement (" + "ADID," + "UserID," + "ADType," + "ADName," + "ImgUrl," + "ImgWidth," + "ImgHeight," + "FlashWmode," + "ADIntro," + "LinkUrl," + "LinkTarget," + "LinkAlt," + "Priority," + "Setting," + "IsCountView," + "Views," + "IsCountClick," + "Clicks," + "IsAbsolutePath," + "IsPassed," + "OverdueDate) " + "values(" + "@ADID," + "@UserID," + "@ADType," + "@ADName," + "@ImgUrl," + "@ImgWidth," + "@ImgHeight," + "@FlashWmode," + "@ADIntro," + "@LinkUrl," + "@LinkTarget," + "@LinkAlt," + "@Priority," + "@Setting," + "@IsCountView," + "@Views," + "@IsCountClick," + "@Clicks," + "@IsAbsolutePath," + "@IsPassed," + "@OverdueDate)"; return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict))); }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveForm(string keyValue, AdvertisementEntity entity) { try { service.SaveForm(keyValue, entity); } catch (Exception e) { Console.WriteLine(e.Message); throw; } }
public bool Delete(AdvertisementEntity entity) { try { _advertisementRepository.Delete(entity); return(true); } catch (Exception e) { _log.Error(e, "数据库操作出错"); return(false); } }
public AdvertisementEntity Update(AdvertisementEntity entity) { try { _advertisementRepository.Update(entity); return(entity); } catch (Exception e) { _log.Error(e, "数据库操作出错"); return(null); } }
/// <summary> /// 获取实体(异步方式) /// </summary> /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param> /// <param name="dict">参数的名/值集合</param> /// <returns></returns> public virtual async Task <AdvertisementEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null) { AdvertisementEntity obj = null; string strSQL = "select top 1 * from Advertisement where 1=1 " + strWhere; using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict))) { if (reader.Read()) { obj = GetEntityFromrdr(reader); } } return(obj); }
public HttpResponseMessage Create(AdvertisementModel model) { var newContent = _contentService.GetContentById(model.ContentId); var advertisement = new AdvertisementEntity { Title = model.Title, Detail = model.Detail, Continue = Convert.ToDateTime(model.Continue), Content = newContent, Adduser = _workContent.CurrentUser.Id, Addtime = DateTime.Now, UpdUser = _workContent.CurrentUser.Id, UpdTime = DateTime.Now }; if (_advertisementService.Create(advertisement) != null) { return(PageHelper.toJson(PageHelper.ReturnValue(true, "数据添加成功"))); } else { return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据添加失败"))); } }
/// <summary> /// 把实体类转换成键/值对集合 /// </summary> /// <param name="entity"></param> /// <param name="dict"></param> private static void GetParameters(AdvertisementEntity entity, Dictionary <string, object> dict) { dict.Add("ADID", entity.ADID); dict.Add("UserID", entity.UserID); dict.Add("ADType", entity.ADType); dict.Add("ADName", entity.ADName); dict.Add("ImgUrl", entity.ImgUrl); dict.Add("ImgWidth", entity.ImgWidth); dict.Add("ImgHeight", entity.ImgHeight); dict.Add("FlashWmode", entity.FlashWmode); dict.Add("ADIntro", entity.ADIntro); dict.Add("LinkUrl", entity.LinkUrl); dict.Add("LinkTarget", entity.LinkTarget); dict.Add("LinkAlt", entity.LinkAlt); dict.Add("Priority", entity.Priority); dict.Add("Setting", entity.Setting); dict.Add("IsCountView", entity.IsCountView); dict.Add("Views", entity.Views); dict.Add("IsCountClick", entity.IsCountClick); dict.Add("Clicks", entity.Clicks); dict.Add("IsAbsolutePath", entity.IsAbsolutePath); dict.Add("IsPassed", entity.IsPassed); dict.Add("OverdueDate", entity.OverdueDate); }
/// <summary> /// 更新 /// </summary> /// <param name="pEntity">实体实例</param> public void Update(AdvertisementEntity pEntity) { _currentDAO.Update(pEntity); }
/// <summary> /// 分页根据实体条件查询实体 /// </summary> /// <param name="pQueryEntity">以实体形式传入的参数</param> /// <param name="pOrderBys">排序组合</param> /// <returns>符合条件的实体集</returns> public PagedQueryResult <AdvertisementEntity> PagedQueryByEntity(AdvertisementEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex) { return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex)); }
/// <summary> /// 根据实体条件查询实体 /// </summary> /// <param name="pQueryEntity">以实体形式传入的参数</param> /// <param name="pOrderBys">排序组合</param> /// <returns>符合条件的实体集</returns> public AdvertisementEntity[] QueryByEntity(AdvertisementEntity pQueryEntity, OrderBy[] pOrderBys) { return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys)); }
/// <summary> /// 创建一个新实例 /// </summary> /// <param name="pEntity">实体实例</param> public void Create(AdvertisementEntity pEntity) { _currentDAO.Create(pEntity); }
public ExhibitionEntity GetEntity(int id) { ExhibitionEntity item = null; DataSet ds = this.GetExhibitionDataSet(id); if (ds != null && ds.Tables.Count == 2) { if (ds.Tables[0].Rows.Count > 0) { item = new ExhibitionEntity(); DataRow row = ds.Tables[0].Rows[0]; if (row["ExhibitionID"] != null && row["ExhibitionID"].ToString() != "") { item.ExhibitionID = int.Parse(row["ExhibitionID"].ToString()); } if (row["ExhibitionTitle"] != null) { item.ExhibitionTitle = row["ExhibitionTitle"].ToString(); } if (row["ExhibitionLogoUrl"] != null) { item.ExhibitionLogoUrl = row["ExhibitionLogoUrl"].ToString(); } if (row["ExhibitionStartTime"] != null && row["ExhibitionStartTime"].ToString() != "") { item.ExhibitionStartTime = DateTime.Parse(row["ExhibitionStartTime"].ToString()); } if (row["ExhibitionEndTime"] != null && row["ExhibitionEndTime"].ToString() != "") { item.ExhibitionEndTime = DateTime.Parse(row["ExhibitionEndTime"].ToString()); } if (row["ExhibitionAddress"] != null) { item.ExhibitionAddress = row["ExhibitionAddress"].ToString(); } if (row["ExhibitionTraffic"] != null) { item.ExhibitionTraffic = row["ExhibitionTraffic"].ToString(); } if (row["ExhibitionLocation"] != null) { item.ExhibitionLocation = row["ExhibitionLocation"].ToString(); } if (row["ExhibitionAbstract"] != null) { item.ExhibitionAbstract = row["ExhibitionAbstract"].ToString(); } if (row["ExhibitionAbout"] != null) { item.ExhibitionAbout = row["ExhibitionAbout"].ToString(); } if (row["ExhibitionOrder"] != null && row["ExhibitionOrder"].ToString() != "") { item.ExhibitionOrder = int.Parse(row["ExhibitionOrder"].ToString()); } if (row["ExhibitionBookListDesc"] != null) { item.ExhibitionBookListDesc = row["ExhibitionBookListDesc"].ToString(); } if (row["StateTypeID"] != null && row["StateTypeID"].ToString() != "") { item.StateTypeID = int.Parse(row["StateTypeID"].ToString()); } if (row["IsPublish"] != null && row["IsPublish"].ToString() != "") { if ((row["IsPublish"].ToString() == "1") || (row["IsPublish"].ToString().ToLower() == "true")) { item.IsPublish = true; } else { item.IsPublish = false; } } if (row["BookListDownloadUrl"] != null) { item.BookListDownloadUrl = row["BookListDownloadUrl"].ToString(); } if (row["IsDownloadBookList"] != null && row["IsDownloadBookList"].ToString() != "") { if ((row["IsDownloadBookList"].ToString() == "1") || (row["IsDownloadBookList"].ToString().ToLower() == "true")) { item.IsDownloadBookList = true; } else { item.IsDownloadBookList = false; } } if (row["CreateUserID"] != null) { item.CreateUserID = row["CreateUserID"].ToString(); } if (row["CreateTime"] != null && row["CreateTime"].ToString() != "") { item.CreateTime = DateTime.Parse(row["CreateTime"].ToString()); } item.AdvertisementList = new List <AdvertisementEntity>(); if (ds.Tables[1].Rows.Count > 0) { foreach (DataRow dra in ds.Tables[1].Rows) { if (dra != null) { AdvertisementEntity _item = new AdvertisementEntity(); if (dra["AdvertisementID"] != null && dra["AdvertisementID"].ToString() != "") { _item.AdvertisementID = int.Parse(dra["AdvertisementID"].ToString()); } if (dra["ExhibitionID"] != null && dra["ExhibitionID"].ToString() != "") { _item.ExhibitionID = int.Parse(dra["ExhibitionID"].ToString()); } if (dra["AdvertisementUrl"] != null) { _item.AdvertisementUrl = dra["AdvertisementUrl"].ToString(); } if (dra["AdvertisementTitle"] != null) { _item.AdvertisementTitle = dra["AdvertisementTitle"].ToString(); } if (dra["AdvertisementOrder"] != null && dra["AdvertisementOrder"].ToString() != "") { _item.AdvertisementOrder = int.Parse(dra["AdvertisementOrder"].ToString()); } if (dra["StateTypeID"] != null && dra["StateTypeID"].ToString() != "") { _item.StateTypeID = int.Parse(dra["StateTypeID"].ToString()); } if (dra["CreateUserID"] != null) { _item.CreateUserID = dra["CreateUserID"].ToString(); } if (dra["CreateTime"] != null && dra["CreateTime"].ToString() != "") { _item.CreateTime = DateTime.Parse(dra["CreateTime"].ToString()); } item.AdvertisementList.Add(_item); } } } } } return(item); }
/// <summary> /// 增加或更新一条记录(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <param name="IsSave">是否增加</param> /// <returns></returns> public virtual async Task <bool> AddOrUpdateAsync(AdvertisementEntity entity, bool IsSave) { return(IsSave ? await AddAsync(entity) : await UpdateAsync(entity)); }
/// <summary> /// 更新 /// </summary> /// <param name="pEntity">实体实例</param> /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param> public void Update(AdvertisementEntity pEntity, IDbTransaction pTran) { _currentDAO.Update(pEntity, pTran); }
/// <summary> /// 增加或更新一条记录 /// </summary> /// <param name="entity">实体模型</param> /// <param name="IsSave">是否增加</param> /// <returns></returns> public virtual bool AddOrUpdate(AdvertisementEntity entity, bool IsSave) { return(IsSave ? Add(entity) : Update(entity)); }
public HttpResponseMessage SaveAdvertisement(SaveAdvertisementArgEntity arg) { BaseJson <string> resultMsg = new BaseJson <string> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null }; Logger(typeof(AdvertisementController), arg.TryToJson(), "保存广告-SaveAdvertisement", () => { if (!string.IsNullOrEmpty(arg.t) && !string.IsNullOrEmpty(arg.Appkey) && !string.IsNullOrEmpty(arg.AccessToken)) { if (arg.t.CheckTimeStamp()) { //获取缓存Token信息 Token_Preview token = CacheFactory.Cache().GetCache <Token_Preview>(arg.Appkey); if (token != null) { //校验授权码 string tokenStr = token.AccessToken; if (!string.IsNullOrEmpty(tokenStr) && tokenStr.Equals(arg.AccessToken)) { AdvertisementEntity entity = new AdvertisementEntity { Title = arg.Title, Category = arg.Which == "0" ? "主站" : arg.Which == "1" ? "开奖网" : arg.Which == "2" ? "手机站" : "", CategoryId = arg.Which, Position = arg.Position, Href = arg.Href, TermOfValidity = arg.OverTime }; if (!string.IsNullOrEmpty(arg.Id)) { entity.IsEnable = true; advertisementBll.SaveForm(arg.Id, entity); } else { AdvertisementEntity temp = advertisementBll.GetEntity(a => a.CategoryId.Equals(arg.Which) && a.Position == arg.Position); if (temp != null) { entity.IsEnable = true; advertisementBll.SaveForm(temp.ID, entity); } } //清理缓存 Cache.Factory.CacheFactory.Cache().RemoveCache("Advertisement_Html_" + arg.Which); resultMsg = new BaseJson <string> { Status = (int)JsonObjectStatus.Success, Data = null, Message = JsonObjectStatus.Success.GetEnumText(), BackUrl = null }; } else { resultMsg = new BaseJson <string> { Status = (int)JsonObjectStatus.TokenInvalid, Data = null, Message = JsonObjectStatus.TokenInvalid.GetEnumText(), BackUrl = null }; } } else { resultMsg = new BaseJson <string> { Status = (int)JsonObjectStatus.TokenInvalid, Data = null, Message = JsonObjectStatus.TokenInvalid.GetEnumText(), BackUrl = null }; } } else { resultMsg = new BaseJson <string> { Status = (int)JsonObjectStatus.Fail, Data = null, Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。", BackUrl = null }; } } else { resultMsg = new BaseJson <string> { Status = (int)JsonObjectStatus.Fail, Data = null, Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。", BackUrl = null }; } }, e => { resultMsg = new BaseJson <string> { Status = (int)JsonObjectStatus.Exception, Data = null, Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message, BackUrl = null }; }); return(resultMsg.TryToJson().ToHttpResponseMessage()); }
protected void btn_submit_Click(object sender, EventArgs e) { StringBuilder strJs = new StringBuilder(); strJs.Append("<script type='text/javascript'>"); strJs.Append("bootbox.alert('保存失败');"); strJs.Append("</script>"); try { #region 填充 int eid = 0; int.TryParse(this.hid_eid.Value, out eid); ExhibitionEntity item = new ExhibitionEntity() { ExhibitionID = eid, ExhibitionTitle = this.txt_exhibitionname.Value, ExhibitionLocation = this.txt_exhibitionlocation.Value, ExhibitionStartTime = Convert.ToDateTime(this.txt_starttime.Value), ExhibitionEndTime = Convert.ToDateTime(this.txt_endTime.Value), ExhibitionAddress = this.txt_exhibitionaddress.Value, ExhibitionTraffic = this.txt_exhibitiontraffic.Value, ExhibitionAbstract = this.txt_exhibitionabstract.Value, ExhibitionAbout = this.txt_exhibitionabout.Value, ExhibitionBookListDesc = this.txt_exhibitionbooklistdesc.Value, BookListDownloadUrl = this.txt_booklistdownloadurl.Value, CreateTime = DateTime.Now, CreateUserID = this.CurrentAdmin.Sys_UserID, ExhibitionOrder = 1000, StateTypeID = this.chk_statetype.Checked ? 1 : 0, IsPublish = this.chk_ispublish.Checked, IsDownloadBookList = this.chk_isdownloadbooklist.Checked }; item.AdvertisementList = new List <AdvertisementEntity>(); string[] elocs = this.txt_advertisementtitle.Value.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); if (elocs != null) { foreach (string loc in elocs) { AdvertisementEntity locEntity = new AdvertisementEntity() { ExhibitionID = eid, CreateTime = DateTime.Now, CreateUserID = this.CurrentAdmin.Sys_UserID, AdvertisementOrder = 1000, AdvertisementTitle = loc, AdvertisementUrl = "", StateTypeID = this.chk_statetype.Checked ? 1 : 0 }; item.AdvertisementList.Add(locEntity); } } #endregion if (this.txt_imageurl.HasFile) { string fileName = txt_imageurl.FileName; string tempPath = Server.MapPath("~/UploadFile/ExhibitionLogo/"); if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } fileName = System.IO.Path.GetFileName(fileName); //获取文件名(不带路径) string currFileExtension = System.IO.Path.GetExtension(fileName); //获取文件的扩展名 string currFilePath = tempPath + fileName; //获取上传后的文件路径 记录到前面声明的全局变量 this.txt_imageurl.SaveAs(currFilePath); item.ExhibitionLogoUrl = "/UploadFile/ExhibitionLogo/" + fileName; } else { item.ExhibitionLogoUrl = hid_imgurl.Value; } BCtrl_Exhibition bll = new BCtrl_Exhibition(); if (bll.Save(item)) { strJs = strJs.Clear(); strJs.Append("<script type='text/javascript'>"); strJs.Append("bootbox.alert('保存成功', function () {"); strJs.Append(@"if (window.parent != undefined) { window.parent.TObj('tmpExhibitionList')._prmsData.ts = new Date().getTime(); window.parent.TObj('tmpExhibitionList').S(); window.parent.asyncbox.close('exhibition'); } })"); strJs.Append("</script>"); } } catch (Exception ex) { Utils.LogUtil.WriteLog(ex); strJs = strJs.Clear(); strJs.Append("<script type='text/javascript'>"); strJs.Append("bootbox.alert('保存失败');"); strJs.Append("</script>"); } ClientScript.RegisterStartupScript(this.GetType(), "LoadExhibitionScript", strJs.ToString()); }
/// <summary> /// 删除 /// </summary> /// <param name="pEntity"></param> public void Delete(AdvertisementEntity pEntity) { _currentDAO.Delete(pEntity); }
public ActionResult SaveForm(string keyValue, AdvertisementEntity entity) { advertisementbll.SaveForm(keyValue, entity); return(Success("操作成功。")); }