public IList <AdvertisementItemInfo> GetList() { string cmdText = @"select AdvertisementId,Descr,ContentText from AdvertisementItem order by LastUpdatedDate desc " ; IList <AdvertisementItemInfo> list = new List <AdvertisementItemInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText)) { if (reader != null && reader.HasRows) { while (reader.Read()) { AdvertisementItemInfo model = new AdvertisementItemInfo(); model.AdvertisementId = reader.GetGuid(0); model.Descr = reader.GetString(1); model.ContentText = reader.GetString(2); list.Add(model); } } } return(list); }
public IList <AdvertisementItemInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms) { string cmdText = @"select AdvertisementId,Descr,ContentText from AdvertisementItem"; if (!string.IsNullOrEmpty(sqlWhere)) { cmdText += " where 1=1 " + sqlWhere; } IList <AdvertisementItemInfo> list = new List <AdvertisementItemInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { AdvertisementItemInfo model = new AdvertisementItemInfo(); model.AdvertisementId = reader.GetGuid(0); model.Descr = reader.GetString(1); model.ContentText = reader.GetString(2); list.Add(model); } } } return(list); }
public IList <AdvertisementItemInfo> GetList(int pageIndex, int pageSize, string sqlWhere, params SqlParameter[] cmdParms) { int startIndex = (pageIndex - 1) * pageSize + 1; int endIndex = pageIndex * pageSize; string cmdText = @"select * from(select row_number() over(order by LastUpdatedDate desc) as RowNumber, AdvertisementId,Descr,ContentText from AdvertisementItem" ; if (!string.IsNullOrEmpty(sqlWhere)) { cmdText += " where 1=1 " + sqlWhere; } cmdText += ")as objTable where RowNumber between " + startIndex + " and " + endIndex + " "; IList <AdvertisementItemInfo> list = new List <AdvertisementItemInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { AdvertisementItemInfo model = new AdvertisementItemInfo(); model.AdvertisementId = reader.GetGuid(1); model.Descr = reader.GetString(2); model.ContentText = reader.GetString(3); list.Add(model); } } } return(list); }
public AdvertisementItemInfo GetModel(object AdvertisementId) { AdvertisementItemInfo model = null; string cmdText = @"select top 1 AdvertisementId,Descr,ContentText from AdvertisementItem where AdvertisementId = @AdvertisementId " ; SqlParameter parm = new SqlParameter("@AdvertisementId", SqlDbType.UniqueIdentifier); parm.Value = Guid.Parse(AdvertisementId.ToString()); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parm)) { if (reader != null) { while (reader.Read()) { model = new AdvertisementItemInfo(); model.AdvertisementId = reader.GetGuid(0); model.Descr = reader.GetString(1); model.ContentText = reader.GetString(2); } } } return(model); }
public int Update(AdvertisementItemInfo model) { string cmdText = @"update AdvertisementItem set Descr = @Descr,ContentText = @ContentText where AdvertisementId = @AdvertisementId" ; SqlParameter[] parms = { new SqlParameter("@AdvertisementId", SqlDbType.UniqueIdentifier), new SqlParameter("@Descr", SqlDbType.NVarChar,300), new SqlParameter("@ContentText", SqlDbType.NVarChar, 3000) }; parms[0].Value = model.AdvertisementId; parms[1].Value = model.Descr; parms[2].Value = model.ContentText; return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms)); }
public int Insert(AdvertisementItemInfo model) { string cmdText = @"insert into AdvertisementItem (AdvertisementId,Descr,ContentText) values (@AdvertisementId,@Descr,@ContentText) " ; SqlParameter[] parms = { new SqlParameter("@AdvertisementId", SqlDbType.UniqueIdentifier), new SqlParameter("@Descr", SqlDbType.NVarChar,300), new SqlParameter("@ContentText", SqlDbType.NVarChar, 3000) }; parms[0].Value = model.AdvertisementId; parms[1].Value = model.Descr; parms[2].Value = model.ContentText; return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms)); }
private void SaveAdvertisement(HttpContext context) { try { string Id = context.Request.Form["ctl00$cphMain$hId"].Trim(); string title = context.Request.Form["ctl00$cphMain$txtTitle"].Trim(); string sSiteFunId = context.Request.Form["siteFunId"].Trim(); string sLayoutPositionId = context.Request.Form["layoutPositionId"].Trim(); string sTimeout = context.Request.Form["ctl00$cphMain$txtTimeout"].Trim(); string sAdLinkJson = context.Request.Form["adLinkJson"].Trim(); sAdLinkJson = sAdLinkJson.Trim(','); int timeout = 0; if (!string.IsNullOrWhiteSpace(sTimeout)) { int.TryParse(sTimeout, out timeout); } Guid siteFunId = Guid.Empty; Guid.TryParse(sSiteFunId, out siteFunId); Guid layoutPositionId = Guid.Empty; Guid.TryParse(sLayoutPositionId, out layoutPositionId); string sDescr = context.Request.Form["ctl00$cphMain$txtaDescr"].Trim(); string content = context.Request.Form["content"].Trim(); content = HttpUtility.HtmlDecode(content); Guid gId = Guid.Empty; if (!string.IsNullOrWhiteSpace(Id)) { Guid.TryParse(Id, out gId); } AdvertisementInfo model = new AdvertisementInfo(); model.Id = gId; model.LastUpdatedDate = DateTime.Now; model.Title = title; model.Timeout = timeout; model.SiteFunId = siteFunId; model.LayoutPositionId = layoutPositionId; AdvertisementItemInfo adiModel = null; if (gId.Equals(Guid.Empty)) { if (!(string.IsNullOrWhiteSpace(sDescr) && string.IsNullOrWhiteSpace(content))) { adiModel = new AdvertisementItemInfo(); adiModel.Descr = sDescr; adiModel.ContentText = content; } } else { adiModel = new AdvertisementItemInfo(); adiModel.Descr = sDescr; adiModel.ContentText = content; adiModel.AdvertisementId = gId; } IList <AdvertisementLinkInfo> listAdLink = null; if (!string.IsNullOrWhiteSpace(sAdLinkJson)) { DataTable dtPostData = JsonConvert.DeserializeObject <DataTable>(sAdLinkJson); if (dtPostData != null && dtPostData.Rows.Count > 0) { listAdLink = new List <AdvertisementLinkInfo>(); foreach (DataRow dr in dtPostData.Rows) { AdvertisementLinkInfo postAdlModel = new AdvertisementLinkInfo(); postAdlModel.Id = dr["AdLinkId"] == DBNull.Value ? Guid.Empty : Guid.Parse(dr["AdLinkId"].ToString()); postAdlModel.AdvertisementId = gId; postAdlModel.ContentPictureId = dr["ContentPictureId"] == DBNull.Value ? Guid.Empty : Guid.Parse(dr["ContentPictureId"].ToString()); postAdlModel.ActionTypeId = dr["ActionTypeId"] == DBNull.Value ? Guid.Empty : Guid.Parse(dr["ActionTypeId"].ToString()); postAdlModel.Url = dr["Url"] == DBNull.Value ? "" : dr["Url"].ToString(); postAdlModel.Sort = dr["Sort"] == DBNull.Value ? 0 : int.Parse(dr["Sort"].ToString()); postAdlModel.IsDisable = dr["IsDisable"] == DBNull.Value ? false : bool.Parse(dr["IsDisable"].ToString()); listAdLink.Add(postAdlModel); } } } Advertisement bll = new Advertisement(); AdvertisementItem aiBll = new AdvertisementItem(); AdvertisementLink adlBll = new AdvertisementLink(); int effect = -1; if (!gId.Equals(Guid.Empty)) { using (TransactionScope scope = new TransactionScope()) { bll.Update(model); aiBll.Update(adiModel); if (listAdLink != null) { foreach (var adlModel in listAdLink) { adlBll.Update(adlModel); } } scope.Complete(); effect = 1; } } else { using (TransactionScope scope = new TransactionScope()) { Guid adId = bll.InsertByOutput(model); if (listAdLink != null && listAdLink.Count > 0) { foreach (var adlModel in listAdLink) { adlModel.AdvertisementId = adId; adlBll.Insert(adlModel); } } if (adiModel != null) { adiModel.AdvertisementId = adId; aiBll.Insert(adiModel); } scope.Complete(); effect = 1; } } if (effect < 1) { context.Response.Write("{\"success\": false,\"message\": \"操作失败,请正确输入\"}"); return; } context.Response.Write("{\"success\": true,\"message\": \"操作成功\"}"); } catch (Exception ex) { context.Response.Write("{\"success\": false,\"message\": \"异常:" + ex.Message + "\"}"); } }
/// <summary> /// 修改数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Update(AdvertisementItemInfo model) { return(dal.Update(model)); }
/// <summary> /// 添加数据到数据库 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Insert(AdvertisementItemInfo model) { return(dal.Insert(model)); }
private void SaveAdvertisement(HttpContext context) { try { string Id = context.Request.Form["ctl00$cphMain$hId"].Trim(); string title = context.Request.Form["ctl00$cphMain$txtTitle"].Trim(); string sSiteFunId = context.Request.Form["siteFunId"].Trim(); string sLayoutPositionId = context.Request.Form["layoutPositionId"].Trim(); string sTimeout = context.Request.Form["ctl00$cphMain$txtTimeout"].Trim(); string sSort = context.Request.Form["ctl00$cphMain$txtSort"].Trim(); string sStartTime = context.Request.Form["ctl00$cphMain$txtStartTime"].Trim(); string sEndTime = context.Request.Form["ctl00$cphMain$txtEndTime"].Trim(); string sVirtualViewCount = context.Request.Form["ctl00$cphMain$txtVirtualViewCount"].Trim(); string sIsDisable = context.Request.Form["isDisable"].Trim(); string sAdLinkJson = context.Request.Form["adLinkJson"].Trim(); sAdLinkJson = sAdLinkJson.Trim(','); int timeout = 0; if (!string.IsNullOrWhiteSpace(sTimeout)) { int.TryParse(sTimeout, out timeout); } Guid siteFunId = Guid.Empty; Guid.TryParse(sSiteFunId, out siteFunId); Guid layoutPositionId = Guid.Empty; Guid.TryParse(sLayoutPositionId, out layoutPositionId); int sort = 0; if (!string.IsNullOrWhiteSpace(sSort)) { int.TryParse(sSort, out sort); } int virtualViewCount = 0; if (!string.IsNullOrWhiteSpace(sVirtualViewCount)) { int.TryParse(sVirtualViewCount, out virtualViewCount); } DateTime startTime = DateTime.MinValue; if (!string.IsNullOrWhiteSpace(sStartTime)) { DateTime.TryParse(sStartTime, out startTime); } DateTime endTime = DateTime.MinValue; if (!string.IsNullOrWhiteSpace(sEndTime)) { DateTime.TryParse(sEndTime, out endTime); } string sDescr = context.Request.Form["ctl00$cphMain$txtaDescr"].Trim(); string content = context.Request.Form["content"].Trim(); content = HttpUtility.HtmlDecode(content); Guid gId = Guid.Empty; if (!string.IsNullOrWhiteSpace(Id)) { Guid.TryParse(Id, out gId); } AdvertisementInfo model = new AdvertisementInfo(); model.Id = gId; model.LastUpdatedDate = DateTime.Now; model.Title = title; model.Timeout = timeout; model.Sort = sort; model.StartTime = startTime; model.EndTime = endTime; model.VirtualViewCount = virtualViewCount; model.SiteFunId = siteFunId; model.LayoutPositionId = layoutPositionId; model.IsDisable = sIsDisable == "1" ? true : false; AdvertisementItemInfo adiModel = null; if (gId.Equals(Guid.Empty)) { if (!(string.IsNullOrWhiteSpace(sDescr) && string.IsNullOrWhiteSpace(content))) { adiModel = new AdvertisementItemInfo(); adiModel.Descr = sDescr; adiModel.ContentText = content; } } else { adiModel = new AdvertisementItemInfo(); adiModel.Descr = sDescr; adiModel.ContentText = content; adiModel.AdvertisementId = gId; } IList <AdvertisementLinkInfo> listAdLink = null; if (!string.IsNullOrWhiteSpace(sAdLinkJson)) { DataTable dtPostData = JsonConvert.DeserializeObject <DataTable>(sAdLinkJson); if (dtPostData != null && dtPostData.Rows.Count > 0) { listAdLink = new List <AdvertisementLinkInfo>(); foreach (DataRow dr in dtPostData.Rows) { AdvertisementLinkInfo postAdlModel = new AdvertisementLinkInfo(); postAdlModel.Id = dr["AdLinkId"] == DBNull.Value ? Guid.Empty : Guid.Parse(dr["AdLinkId"].ToString()); postAdlModel.AdvertisementId = gId; postAdlModel.ContentPictureId = dr["ContentPictureId"] == DBNull.Value ? Guid.Empty : Guid.Parse(dr["ContentPictureId"].ToString()); postAdlModel.ActionTypeId = dr["ActionTypeId"] == DBNull.Value ? Guid.Empty : Guid.Parse(dr["ActionTypeId"].ToString()); postAdlModel.Url = dr["Url"] == DBNull.Value ? "" : dr["Url"].ToString(); postAdlModel.Sort = dr["Sort"] == DBNull.Value ? 0 : int.Parse(dr["Sort"].ToString()); postAdlModel.IsDisable = dr["IsDisable"] == DBNull.Value ? false : bool.Parse(dr["IsDisable"].ToString()); listAdLink.Add(postAdlModel); } } } Advertisement bll = new Advertisement(); AdvertisementItem aiBll = new AdvertisementItem(); AdvertisementLink adlBll = new AdvertisementLink(); int effect = -1; List <AdvertisementLinkInfo> oldListAdLink = null; if (!gId.Equals(Guid.Empty)) { oldListAdLink = adlBll.GetListByAdId(gId).ToList <AdvertisementLinkInfo>(); } using (TransactionScope scope = new TransactionScope()) { if (!gId.Equals(Guid.Empty)) { bll.Update(model); aiBll.Update(adiModel); if (listAdLink != null) { foreach (var adlModel in listAdLink) { if (oldListAdLink != null && oldListAdLink.Count > 0) { var delModel = oldListAdLink.Find(m => m.Id.ToString() == adlModel.Id.ToString()); if (delModel != null) { oldListAdLink.Remove(delModel); adlBll.Update(adlModel); } else { adlBll.Insert(adlModel); } } else { adlBll.Insert(adlModel); } } } if (oldListAdLink != null && oldListAdLink.Count > 0) { IList <object> adlIdList = new List <object>(); foreach (var oldModel in oldListAdLink) { adlIdList.Add(oldModel.Id); } adlBll.DeleteBatch(adlIdList); } effect = 1; } else { Guid adId = Guid.NewGuid(); model.Id = adId; effect = bll.Insert(model); if (listAdLink != null && listAdLink.Count > 0) { foreach (var adlModel in listAdLink) { adlModel.AdvertisementId = adId; adlBll.Insert(adlModel); } } if (adiModel != null) { adiModel.AdvertisementId = adId; aiBll.Insert(adiModel); } } scope.Complete(); } if (effect == 110) { context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Exist + "\"}"); return; } if (effect < 1) { context.Response.Write("{\"success\": false,\"message\": \"操作失败,请正确输入\"}"); return; } context.Response.Write("{\"success\": true,\"message\": \"操作成功\"}"); } catch (Exception ex) { context.Response.Write("{\"success\": false,\"message\": \"异常:" + ex.Message + "\"}"); } }