Пример #1
0
        public int Update(AdvertisementLinkInfo model)
        {
            string cmdText = @"update AdvertisementLink set AdvertisementId = @AdvertisementId,ActionTypeId = @ActionTypeId,ContentPictureId = @ContentPictureId,Url = @Url,Sort = @Sort,IsDisable = @IsDisable 
			                 where Id = @Id"            ;

            SqlParameter[] parms =
            {
                new SqlParameter("@Id",               SqlDbType.UniqueIdentifier),
                new SqlParameter("@AdvertisementId",  SqlDbType.UniqueIdentifier),
                new SqlParameter("@ActionTypeId",     SqlDbType.UniqueIdentifier),
                new SqlParameter("@ContentPictureId", SqlDbType.UniqueIdentifier),
                new SqlParameter("@Url",              SqlDbType.VarChar,100),
                new SqlParameter("@Sort",             SqlDbType.Int),
                new SqlParameter("@IsDisable",        SqlDbType.Bit)
            };
            parms[0].Value = model.Id;
            parms[1].Value = model.AdvertisementId;
            parms[2].Value = model.ActionTypeId;
            parms[3].Value = model.ContentPictureId;
            parms[4].Value = model.Url;
            parms[5].Value = model.Sort;
            parms[6].Value = model.IsDisable;

            return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms));
        }
Пример #2
0
        public IList <AdvertisementLinkInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms)
        {
            string cmdText = @"select Id,AdvertisementId,ActionTypeId,ContentPictureId,Url,Sort,IsDisable
                              from AdvertisementLink";

            if (!string.IsNullOrEmpty(sqlWhere))
            {
                cmdText += " where 1=1 " + sqlWhere;
            }

            IList <AdvertisementLinkInfo> list = new List <AdvertisementLinkInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        AdvertisementLinkInfo model = new AdvertisementLinkInfo();
                        model.Id = reader.GetGuid(0);
                        model.AdvertisementId  = reader.GetGuid(1);
                        model.ActionTypeId     = reader.GetGuid(2);
                        model.ContentPictureId = reader.GetGuid(3);
                        model.Url       = reader.GetString(4);
                        model.Sort      = reader.GetInt32(5);
                        model.IsDisable = reader.GetBoolean(6);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Пример #3
0
        public IList <AdvertisementLinkInfo> GetList()
        {
            string cmdText = @"select Id,AdvertisementId,ActionTypeId,ContentPictureId,Url,Sort,IsDisable 
			                from AdvertisementLink
							order by LastUpdatedDate desc "                            ;

            IList <AdvertisementLinkInfo> list = new List <AdvertisementLinkInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        AdvertisementLinkInfo model = new AdvertisementLinkInfo();
                        model.Id = reader.GetGuid(0);
                        model.AdvertisementId  = reader.GetGuid(1);
                        model.ActionTypeId     = reader.GetGuid(2);
                        model.ContentPictureId = reader.GetGuid(3);
                        model.Url       = reader.GetString(4);
                        model.Sort      = reader.GetInt32(5);
                        model.IsDisable = reader.GetBoolean(6);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Пример #4
0
        public AdvertisementLinkInfo GetModel(object Id)
        {
            AdvertisementLinkInfo model = null;

            string       cmdText = @"select top 1 Id,AdvertisementId,ActionTypeId,ContentPictureId,Url,Sort,IsDisable 
			                   from AdvertisementLink
							   where Id = @Id "                            ;
            SqlParameter parm    = new SqlParameter("@Id", SqlDbType.UniqueIdentifier);

            parm.Value = Guid.Parse(Id.ToString());

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parm))
            {
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        model    = new AdvertisementLinkInfo();
                        model.Id = reader.GetGuid(0);
                        model.AdvertisementId  = reader.GetGuid(1);
                        model.ActionTypeId     = reader.GetGuid(2);
                        model.ContentPictureId = reader.GetGuid(3);
                        model.Url       = reader.GetString(4);
                        model.Sort      = reader.GetInt32(5);
                        model.IsDisable = reader.GetBoolean(6);
                    }
                }
            }

            return(model);
        }
Пример #5
0
        public IList <AdvertisementLinkInfo> GetList(int pageIndex, int pageSize, out int totalRecords, string sqlWhere, params SqlParameter[] cmdParms)
        {
            string cmdText = @"select count(*) from AdvertisementLink ";

            if (!string.IsNullOrEmpty(sqlWhere))
            {
                cmdText += " where 1=1 " + sqlWhere;
            }
            totalRecords = (int)SqlHelper.ExecuteScalar(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, cmdParms);

            if (totalRecords == 0)
            {
                return(new List <AdvertisementLinkInfo>());
            }

            int startIndex = (pageIndex - 1) * pageSize + 1;
            int endIndex   = pageIndex * pageSize;

            cmdText = @"select * from(select row_number() over(order by LastUpdatedDate desc) as RowNumber,
			          Id,AdvertisementId,ActionTypeId,ContentPictureId,Url,Sort,IsDisable
					  from AdvertisementLink "                    ;
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                cmdText += "where 1=1 " + sqlWhere;
            }
            cmdText += ")as objTable where RowNumber between " + startIndex + " and " + endIndex + " ";

            IList <AdvertisementLinkInfo> list = new List <AdvertisementLinkInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        AdvertisementLinkInfo model = new AdvertisementLinkInfo();
                        model.Id = reader.GetGuid(1);
                        model.AdvertisementId  = reader.GetGuid(2);
                        model.ActionTypeId     = reader.GetGuid(3);
                        model.ContentPictureId = reader.GetGuid(4);
                        model.Url       = reader.GetString(5);
                        model.Sort      = reader.GetInt32(6);
                        model.IsDisable = reader.GetBoolean(7);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Пример #6
0
        public IList <AdvertisementLinkInfo> GetListByJoin(string sqlWhere, params SqlParameter[] cmdParms)
        {
            string cmdText = @"select adl.Id,adl.AdvertisementId,adl.ActionTypeId,adl.ContentPictureId,adl.Url,adl.Sort,adl.IsDisable
                              ,ct.TypeValue
                              ,pa.FileExtension,pa.FileDirectory,pa.RandomFolder
                              from AdvertisementLink adl 
                              left join Picture_Advertisement pa on pa.Id = adl.ContentPictureId
                              left join ContentType ct on ct.Id = adl.ActionTypeId
                              ";

            if (!string.IsNullOrEmpty(sqlWhere))
            {
                cmdText += " where 1=1 " + sqlWhere;
            }

            IList <AdvertisementLinkInfo> list = new List <AdvertisementLinkInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        AdvertisementLinkInfo model = new AdvertisementLinkInfo();
                        model.Id = reader.GetGuid(0);
                        model.AdvertisementId  = reader.GetGuid(1);
                        model.ActionTypeId     = reader.GetGuid(2);
                        model.ContentPictureId = reader.GetGuid(3);
                        model.Url            = reader.GetString(4);
                        model.Sort           = reader.GetInt32(5);
                        model.IsDisable      = reader.GetBoolean(6);
                        model.ActionTypeName = reader.IsDBNull(7) ? "" : reader.GetString(7);
                        model.FileExtension  = reader.IsDBNull(8) ? "" : reader.GetString(8);
                        model.FileDirectory  = reader.IsDBNull(9) ? "" : reader.GetString(9);
                        model.RandomFolder   = reader.IsDBNull(10) ? "" : reader.GetString(10);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Пример #7
0
        public IList <AdvertisementLinkInfo> GetListByJoin(string sqlWhere, params SqlParameter[] cmdParms)
        {
            StringBuilder sb = new StringBuilder(300);

            sb.Append(@"select adl.Id,adl.AdvertisementId,adl.ActionTypeId,adl.ContentPictureId,adl.Url,adl.Sort,adl.IsDisable
                              ,ct.TypeValue 
                              from AdvertisementLink adl 
                              left join AdvertisementPicture adp on adp.Id = adl.ContentPictureId
                              left join ContentType ct on ct.Id = adl.ActionTypeId
                              ");
            if (!string.IsNullOrEmpty(sqlWhere))
            {
                sb.Append(" where 1=1 " + sqlWhere);
            }
            sb.Append(" order by adl.Sort ");

            IList <AdvertisementLinkInfo> list = new List <AdvertisementLinkInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, sb.ToString(), cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        AdvertisementLinkInfo model = new AdvertisementLinkInfo();
                        model.Id = reader.GetGuid(0);
                        model.AdvertisementId  = reader.GetGuid(1);
                        model.ActionTypeId     = reader.GetGuid(2);
                        model.ContentPictureId = reader.GetGuid(3);
                        model.Url            = reader.GetString(4);
                        model.Sort           = reader.GetInt32(5);
                        model.IsDisable      = reader.GetBoolean(6);
                        model.ActionTypeName = reader.IsDBNull(7) ? "" : reader.GetString(7);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
        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 + "\"}");
            }
        }
Пример #9
0
        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 + "\"}");
            }
        }
Пример #10
0
 /// <summary>
 /// 修改数据
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Update(AdvertisementLinkInfo model)
 {
     return(dal.Update(model));
 }
Пример #11
0
 /// <summary>
 /// 添加数据到数据库
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Insert(AdvertisementLinkInfo model)
 {
     return(dal.Insert(model));
 }