Ejemplo n.º 1
0
        public string GetAdvertisementList(int pageIndex, int pageSize, Guid siteFunId)
        {
            try
            {
                int               totalRecords = 0;
                Advertisement     bll          = new Advertisement();
                AdvertisementLink adlBll       = new AdvertisementLink();
                var               list         = bll.GetListByFunId(pageIndex, pageSize, out totalRecords, siteFunId);
                if (list == null || list.Count == 0)
                {
                    return("");
                }

                StringBuilder sb = new StringBuilder();
                sb.Append("<Rsp>");
                foreach (var model in list)
                {
                    string adLinkAppend = "";
                    var    adLinkList   = adlBll.GetDsByAdId(model.Id);
                    if (adLinkList != null && adLinkList.Tables.Count > 0 && adLinkList.Tables[0].Rows.Count > 0)
                    {
                        adLinkAppend += "<AdImages>";

                        DataRowCollection drc = adLinkList.Tables[0].Rows;

                        foreach (DataRow dr in drc)
                        {
                            string dir     = dr["FileDirectory"] == null ? "" : dr["FileDirectory"].ToString().Trim();
                            string rndCode = dr["RandomFolder"] == null ? "" : dr["RandomFolder"].ToString().Trim();
                            string fileEx  = dr["FileExtension"] == null ? "" : dr["FileExtension"].ToString().Trim();
                            Dictionary <string, string> dic = null;
                            if (!string.IsNullOrWhiteSpace(dir) && !string.IsNullOrWhiteSpace(rndCode) && !string.IsNullOrWhiteSpace(fileEx))
                            {
                                EnumData.Platform platform = EnumData.Platform.Android;
                                dic = PictureUrlHelper.GetUrlByPlatform(dir, rndCode, fileEx, platform);
                            }

                            adLinkAppend += "<AdImageInfo>";
                            adLinkAppend += string.Format(@"<ImageId>{0}</ImageId><AdId>{1}</AdId><ActionType>{2}</ActionType><Url>{3}</Url><Sort>{4}</Sort><OriginalPicture>{5}</OriginalPicture><BPicture>{6}</BPicture><MPicture>{7}</MPicture><SPicture>{8}</SPicture>",
                                                          dr["Id"], dr["AdvertisementId"], dr["ActionTypeCode"], dr["Url"], dr["Sort"], string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["OriginalPicture"]), string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["BPicture"]), string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["MPicture"]), string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["SPicture"]));
                            adLinkAppend += "</AdImageInfo>";
                        }
                        adLinkAppend += "</AdImages>";
                    }

                    sb.Append("<AdRes>");
                    sb.AppendFormat(@"<Id>{0}</Id><Title>{1}</Title><SiteFun>{2}</SiteFun><LayoutPosition>{3}</LayoutPosition><Duration>{4}</Duration><VirtualViewCount>{5}</VirtualViewCount><ViewCount>{6}</ViewCount><AdLink>{7}</AdLink>",
                                    model.Id, model.Title, model.SiteFunName, model.LayoutPositionName, model.Timeout, model.VirtualViewCount, model.ViewCount, adLinkAppend);
                    sb.Append("</AdRes>");
                }
                sb.Append("</Rsp>");

                return(sb.ToString());
            }
            catch
            {
                return("");
            }
        }
Ejemplo n.º 2
0
        public string GetAdvertisementList(int pageIndex, int pageSize, Guid siteFunId)
        {
            try
            {
                int               totalRecords = 0;
                Advertisement     bll          = new Advertisement();
                AdvertisementLink adlBll       = new AdvertisementLink();
                var               list         = bll.GetListByFunId(pageIndex, pageSize, out totalRecords, siteFunId);
                if (list == null || list.Count == 0)
                {
                    return("");
                }

                StringBuilder sb = new StringBuilder();
                sb.Append("<Rsp>");
                foreach (var model in list)
                {
                    string adLinkAppend = "";
                    var    adLinkList   = adlBll.GetListByAdId(model.Id);
                    if (adLinkList != null && adLinkList.Count > 0)
                    {
                        adLinkAppend += "<AdImages>";

                        foreach (var adlModel in adLinkList)
                        {
                            Dictionary <string, string> dic = null;
                            if (!string.IsNullOrWhiteSpace(adlModel.FileDirectory) && !string.IsNullOrWhiteSpace(adlModel.FileExtension) && !string.IsNullOrWhiteSpace(adlModel.RandomFolder))
                            {
                                EnumData.Platform platform = EnumData.Platform.Android;
                                dic = PictureUrlHelper.GetUrlByPlatform(adlModel.FileDirectory, adlModel.RandomFolder, adlModel.FileExtension, platform);
                            }

                            adLinkAppend += "<AdImageInfo>";

                            adLinkAppend += string.Format(@"<ImageId>{0}</ImageId><AdId>{1}</AdId><ActionType>{2}</ActionType><Url><![CDATA[{3}]]></Url><Sort>{4}</Sort><OriginalPicture>{5}</OriginalPicture><BPicture>{6}</BPicture><MPicture>{7}</MPicture><SPicture>{8}</SPicture>",
                                                          adlModel.Id, adlModel.AdvertisementId, adlModel.ActionTypeName, adlModel.Url, adlModel.Sort, string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["OriginalPicture"]), string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["BPicture"]), string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["MPicture"]), string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["SPicture"]));

                            adLinkAppend += "</AdImageInfo>";
                        }
                        adLinkAppend += "</AdImages>";
                    }

                    sb.Append("<AdRes>");
                    sb.AppendFormat("<Id>{0}</Id><Title><![CDATA[{1}]]></Title><SiteFun>{2}</SiteFun><LayoutPosition>{3}</LayoutPosition><Duration>{4}</Duration><AdLink>{5}</AdLink>", model.Id, model.Title, model.SiteFunName, model.LayoutPositionName, model.Timeout, adLinkAppend);
                    sb.Append("</AdRes>");
                }
                sb.Append("</Rsp>");

                return(sb.ToString());
            }
            catch
            {
                return("");
            }
        }
Ejemplo n.º 3
0
        private void Bind()
        {
            if (!Id.Equals(Guid.Empty))
            {
                Page.Title = "编辑广告";

                Advertisement bll = new Advertisement();

                var model = bll.GetModelByJoin(Id);
                if (model != null)
                {
                    hId.Value                 = Id.ToString();
                    txtTitle.Value            = model.Title;
                    txtTimeout.Value          = model.Timeout.ToString();
                    txtSort.Value             = model.Sort.ToString();
                    txtStartTime.Value        = model.StartTime.ToString("yyyy-MM-dd HH:mm:ss");
                    txtEndTime.Value          = model.EndTime.ToString("yyyy-MM-dd HH:mm:ss");
                    txtVirtualViewCount.Value = model.VirtualViewCount.ToString();
                    txtaDescr.Value           = model.Descr;
                    txtContent.Value          = model.ContentText;

                    string            imgContentPictureHtml = "";
                    AdvertisementLink alBll = new AdvertisementLink();
                    var picList             = alBll.GetDsByAdId(Id);
                    if (picList != null && picList.Tables.Count > 0 && picList.Tables[0].Rows.Count > 0)
                    {
                        string adTemplateText = File.ReadAllText(Server.MapPath("~/Templates/PartialAdvertisement.txt"));

                        DataRowCollection drc = picList.Tables[0].Rows;
                        foreach (DataRow dr in drc)
                        {
                            string currTemplateText = adTemplateText;

                            string dir       = dr["FileDirectory"] == null ? "" : dr["FileDirectory"].ToString().Trim();
                            string fileEx    = dr["FileExtension"] == null ? "" : dr["FileExtension"].ToString().Trim();
                            string rndCode   = dr["RandomFolder"] == null ? "" : dr["RandomFolder"].ToString().Trim();
                            string sMPicture = "";
                            if (!string.IsNullOrWhiteSpace(dir) && !string.IsNullOrWhiteSpace(fileEx) && !string.IsNullOrWhiteSpace(rndCode))
                            {
                                EnumData.PictureType picType  = EnumData.PictureType.MPicture;
                                EnumData.Platform    platform = EnumData.Platform.Android;
                                sMPicture = PictureUrlHelper.GetUrl(dir, rndCode, fileEx, picType, platform);
                            }

                            imgContentPictureHtml += string.Format(currTemplateText, sMPicture, dr["ContentPictureId"], dr["ActionTypeId"], dr["Url"], dr["Sort"], dr["IsDisable"], dr["Id"]);
                        }

                        ltrImgItem.Text = imgContentPictureHtml;
                    }

                    myDataAppend += "<div id=\"myDataForModel\">[{\"SiteFunId\":\"" + model.SiteFunId + "\",\"LayoutPositionId\":\"" + model.LayoutPositionId + "\",\"IsDisable\":\"" + model.IsDisable + "\"}]</div>";
                }
            }
        }
Ejemplo n.º 4
0
        public string GetAdvertisementModel(Guid Id)
        {
            try
            {
                if (Id.Equals(Guid.Empty))
                {
                    return("");
                }

                Advertisement bll   = new Advertisement();
                var           model = bll.GetModelByJoin(Id);
                if (model == null)
                {
                    return("");
                }

                Regex r = new Regex("(<img)(.*)src=\"([^\"]*?)\"(.*)/>");

                AdvertisementLink adlBll       = new AdvertisementLink();
                string            adLinkAppend = "";
                var adLinkList = adlBll.GetListByAdId(model.Id);
                if (adLinkList != null && adLinkList.Count > 0)
                {
                    adLinkAppend += "<AdImages>";

                    foreach (var adlModel in adLinkList)
                    {
                        Dictionary <string, string> dic = null;
                        if (!string.IsNullOrWhiteSpace(adlModel.FileDirectory) && !string.IsNullOrWhiteSpace(adlModel.FileExtension) && !string.IsNullOrWhiteSpace(adlModel.RandomFolder))
                        {
                            EnumData.Platform platform = EnumData.Platform.Android;
                            dic = PictureUrlHelper.GetUrlByPlatform(adlModel.FileDirectory, adlModel.RandomFolder, adlModel.FileExtension, platform);
                        }

                        adLinkAppend += "<AdImageInfo>";
                        adLinkAppend += string.Format(@"<ImageId>{0}</ImageId><AdId>{1}</AdId><ActionType>{2}</ActionType><Url><![CDATA[{3}]]></Url><Sort>{4}</Sort><OriginalPicture>{5}</OriginalPicture><BPicture>{6}</BPicture><MPicture>{7}</MPicture><SPicture>{8}</SPicture>",
                                                      adlModel.Id, adlModel.AdvertisementId, adlModel.ActionTypeName, adlModel.Url, adlModel.Sort, string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["OriginalPicture"]), string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["BPicture"]), string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["MPicture"]), string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["SPicture"]));
                        adLinkAppend += "</AdImageInfo>";
                    }
                    adLinkAppend += "</AdImages>";
                }

                StringBuilder sb = new StringBuilder();
                sb.Append("<Rsp>");
                sb.AppendFormat("<Id>{0}</Id><Title><![CDATA[{1}]]></Title><SiteFun>{2}</SiteFun><LayoutPosition>{3}</LayoutPosition><AdTime>{4}</AdTime><AdLink>{5}</AdLink><Descr>{6}</Descr><Content><![CDATA[{7}]]></Content>", model.Id, model.Title, model.SiteFunName, model.LayoutPositionName, model.LastUpdatedDate.ToString("yyyy-MM-dd HH:mm"), adLinkAppend, model.Descr, r.Replace(model.ContentText, "$1$2src=\"" + WebSiteHost + "$3\" />"));
                sb.Append("</Rsp>");

                return(sb.ToString());
            }
            catch
            {
                return("");
            }
        }
Ejemplo n.º 5
0
        private void Bind()
        {
            if (!Id.Equals(Guid.Empty))
            {
                Page.Title = "编辑广告";

                Advertisement bll = new Advertisement();

                var model = bll.GetModelByJoin(Id);
                if (model != null)
                {
                    hId.Value        = Id.ToString();
                    txtTitle.Value   = model.Title;
                    txtTimeout.Value = model.Timeout.ToString();
                    txtaDescr.Value  = model.Descr;
                    txtContent.Value = model.ContentText;

                    string            imgContentPictureHtml = "";
                    AdvertisementLink alBll = new AdvertisementLink();
                    var picList             = alBll.GetListByAdId(Id);
                    if (picList != null && picList.Count > 0)
                    {
                        string adTemplateText = File.ReadAllText(Server.MapPath("~/Templates/PartialAdvertisement.txt"));
                        foreach (var adlModel in picList)
                        {
                            string currTemplateText = adTemplateText;
                            imgContentPictureHtml += string.Format(currTemplateText, adlModel.MPicture, adlModel.ContentPictureId, adlModel.ActionTypeId, adlModel.Url, adlModel.Sort, adlModel.IsDisable, adlModel.Id);
                        }

                        ltrImgItem.Text = imgContentPictureHtml;
                    }

                    myDataAppend += "<div id=\"myDataForModel\">[{\"SiteFunId\":\"" + model.SiteFunId + "\",\"LayoutPositionId\":\"" + model.LayoutPositionId + "\"}]</div>";
                }
            }
        }
Ejemplo n.º 6
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 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 + "\"}");
            }
        }
Ejemplo n.º 7
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 + "\"}");
            }
        }
Ejemplo n.º 8
0
        public string GetAdvertisementModel(Guid Id)
        {
            try
            {
                if (Id.Equals(Guid.Empty))
                {
                    return("");
                }

                Advertisement bll   = new Advertisement();
                var           model = bll.GetModelByJoin(Id);
                if (model == null)
                {
                    return("");
                }

                AccessStatisticQueueClient queueClient = new AccessStatisticQueueClient();
                Services.HnztcQueueService.AccessStatisticInfo accessStatisticInfo = new Services.HnztcQueueService.AccessStatisticInfo();
                accessStatisticInfo.TableName = "Advertisement";
                accessStatisticInfo.Id        = Id;
                queueClient.SaveAccessStatistic(accessStatisticInfo);

                Regex r = new Regex("(<img)(.*)src=\"([^\"]*?)\"(.*)/>");

                AdvertisementLink adlBll       = new AdvertisementLink();
                string            adLinkAppend = "";
                var adLinkList = adlBll.GetDsByAdId(model.Id);
                if (adLinkList != null && adLinkList.Tables.Count > 0 && adLinkList.Tables[0].Rows.Count > 0)
                {
                    adLinkAppend += "<AdImages>";

                    DataRowCollection drc = adLinkList.Tables[0].Rows;
                    foreach (DataRow dr in drc)
                    {
                        string dir     = dr["FileDirectory"] == null ? "" : dr["FileDirectory"].ToString().Trim();
                        string rndCode = dr["RandomFolder"] == null ? "" : dr["RandomFolder"].ToString().Trim();
                        string fileEx  = dr["FileExtension"] == null ? "" : dr["FileExtension"].ToString().Trim();
                        Dictionary <string, string> dic = null;
                        if (!string.IsNullOrWhiteSpace(dir) && !string.IsNullOrWhiteSpace(rndCode) && !string.IsNullOrWhiteSpace(fileEx))
                        {
                            EnumData.Platform platform = EnumData.Platform.Android;
                            dic = PictureUrlHelper.GetUrlByPlatform(dir, rndCode, fileEx, platform);
                        }

                        adLinkAppend += "<AdImageInfo>";
                        adLinkAppend += string.Format(@"<ImageId>{0}</ImageId><AdId>{1}</AdId><ActionType>{2}</ActionType><Url>{3}</Url><Sort>{4}</Sort><OriginalPicture>{5}</OriginalPicture><BPicture>{6}</BPicture><MPicture>{7}</MPicture><SPicture>{8}</SPicture>",
                                                      dr["Id"], dr["AdvertisementId"], dr["ActionTypeCode"], dr["Url"], dr["Sort"], string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["OriginalPicture"]), string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["BPicture"]), string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["MPicture"]), string.Format("{0}{1}", WebSiteHost, dic == null ? "" : dic["SPicture"]));
                        adLinkAppend += "</AdImageInfo>";
                    }
                    adLinkAppend += "</AdImages>";
                }

                StringBuilder sb = new StringBuilder();
                sb.Append("<Rsp>");
                sb.AppendFormat(@"<Id>{0}</Id><Title>{1}</Title><SiteFun>{2}</SiteFun><LayoutPosition>{3}</LayoutPosition><AdTime>{4}</AdTime><AdLink>{5}</AdLink><Descr>{6}</Descr><Content><![CDATA[{7}]]></Content><VirtualViewCount>{8}</VirtualViewCount><ViewCount>{9}</ViewCount>",
                                model.Id, model.Title, model.SiteFunName, model.LayoutPositionName, model.LastUpdatedDate.ToString("yyyy-MM-dd HH:mm"), adLinkAppend, model.Descr, r.Replace(model.ContentText, "$1$2src=\"" + WebSiteHost + "$3\" />"), model.VirtualViewCount, model.ViewCount);
                sb.Append("</Rsp>");

                return(sb.ToString());
            }
            catch (Exception ex)
            {
                new CustomException(ex.Message, ex);
                return("");
            }
        }