protected void BTN_ShowGoods_Click(object sender, EventArgs e) { IList <UserAdsInfo> list = new List <UserAdsInfo>(); string nick = ""; if (Request.Cookies["nick"] != null) { nick = HttpUtility.UrlDecode(Request.Cookies["nick"].Value); //"nick"; } else { nick = Session["snick"].ToString(); } CateService cateDal = new CateService(); IList <CateInfo> cateList = cateDal.SelectAllCateByNick(nick).ToList(); UserAdsService userAdsDal = new UserAdsService(); foreach (RepeaterItem item in Rpt_GoodsList.Items) { CheckBox cb = (CheckBox)item.FindControl("CBOX_Goods"); if (cb.Checked) { UserAdsInfo info = new UserAdsInfo(); info.AdsTitle = ((Label)item.FindControl("LB_GoodsName")).Text; info.Id = Guid.NewGuid(); info.UserAdsState = 0; info.AdsUrl = "http://item.taobao.com/item.htm?id=" + ((Label)item.FindControl("LB_GoodsId")).Text; string cateId = ((Label)item.FindControl("LB_CateId")).Text; IList <CateInfo> thiscList = cateList.Where(o => o.CateId == cateId).ToList(); info.CateIds = ((Label)item.FindControl("LB_TaoBaoCId")).Text; string cname = thiscList.Count == 0 ? "" : thiscList[0].CateName; info.SellCateName = GetTaoBaoCName(info.CateIds, cname); info.AliWang = nick; info.Nick = nick; info.AdsPic = ((Label)item.FindControl("LB_Img")).Text; info.Price = decimal.Parse(((Label)item.FindControl("LB_Price")).Text); list.Add(info); } } if (list.Count == 0) { return; } IList <BuyInfo> buyList = CacheCollection.GetAllBuyInfo().Where(o => o.Nick == nick).ToList(); //投放的广告 IList <UserAdsInfo> useradsList = userAdsDal.SelectAllUserAds(nick); //购买类型 foreach (BuyInfo binfo in buyList) { //未过期的 if (!binfo.IsExpied) { //收费类型 FeeInfo feeInfo = CacheCollection.GetAllFeeInfo().Where(o => o.FeeId == binfo.FeeId).ToList()[0]; if (feeInfo.AdsCount > 0) { int count = feeInfo.AdsCount > list.Count ? list.Count : feeInfo.AdsCount; //已经投放了的该收费类型的广告集合 IList <UserAdsInfo> myUseradsList = useradsList.Where(o => o.FeeId == feeInfo.FeeId && o.UserAdsState == 1).ToList(); //真正可以添加的广告数量 int realcount = 0; if (feeInfo.AdsCount - myUseradsList.Count <= 0) { realcount = 0; } else { realcount = (feeInfo.AdsCount - myUseradsList.Count) >= count ? count : feeInfo.AdsCount - myUseradsList.Count; } if (realcount > 0) { if (feeInfo.AdsType == 5) { //这里需要查询空闲的广告(或者说是可以用的广告位) IList <UserAdsInfo> usedadsList = userAdsDal.SelectAllUsedAds(); IList <AdsInfo> allads = CacheCollection.GetAllAdsInfo().Where(o => o.AdsType == 5).ToList(); if (allads.Count > usedadsList.Count) { //得到没有使用的广告位 IList <AdsInfo> hasads = new List <AdsInfo>(); foreach (AdsInfo ainfo in allads) { if (usedadsList.Where(o => o.AdsId == ainfo.AdsId).ToList().Count == 0) { hasads.Add(ainfo); } } for (int i = 0; i < realcount; i++) { list[i].AddTime = DateTime.Now; list[i].AdsId = GetRand(hasads); //不需要旺旺 list[i].AliWang = ""; //nick; list[i].FeeId = binfo.FeeId; list[i].AdsShowStartTime = DateTime.Now; list[i].AdsShowFinishTime = DateTime.Now.AddDays(feeInfo.ShowDays); list[i].Nick = nick; list[i].UserAdsState = 1; //不需要分类 //string taoId = list[i].CateIds; list[i].CateIds = ""; // GetTaoBaoCId(taoId, ref taoId); } } else { Page.RegisterStartupScript("通知", "<script>alert('请联系我们的客服人员为您添加广告');</script>"); } continue; } //可以放多少个 for (int i = 0; i < realcount; i++) { list[i].AddTime = DateTime.Now; list[i].AdsId = GetRand(CacheCollection.GetAllAdsInfo().Where(o => o.AdsType == 1).ToList()); list[i].AliWang = nick; list[i].FeeId = binfo.FeeId; list[i].AdsShowStartTime = DateTime.Now; list[i].AdsShowFinishTime = DateTime.Now.AddDays(feeInfo.ShowDays); list[i].Nick = nick; list[i].UserAdsState = 1; string taoId = list[i].CateIds; list[i].CateIds = GetTaoBaoCId(taoId, taoId); } } } } } foreach (UserAdsInfo info in list) { userAdsDal.InsertUserAds(info); } Response.Redirect("UserAdsList.aspx?istou=1"); }
protected void BTN_Tui_Click(object sender, EventArgs e) { string nick = ""; if (Request.Cookies["nick"] != null) { nick = HttpUtility.UrlDecode(Request.Cookies["nick"].Value); //"nick"; } else { nick = Session["snick"].ToString(); } if (DDL_AdsType.SelectedValue == Guid.Empty.ToString() || DDL_App.SelectedValue == Guid.Empty.ToString() || DDL_Position.SelectedValue == Guid.Empty.ToString()) { Page.RegisterStartupScript("通知", "<script>alert('请选择投放的应用,类型以及位置,请按您购买的服务类型选择!');</script>"); return; } //购买类型 IList <BuyInfo> buyList = CacheCollection.GetAllBuyInfo().Where(o => o.Nick == nick).ToList(); //投放的广告 IList <UserAdsInfo> useradsList = userAdsDal.SelectAllUserAds(nick); bool notou = true; //新的添加广告方法 if (buyList.Count > 0) { if (!buyList[0].IsExpied) { SiteAdsInfo sadsinfo = CacheCollection.GetAllSiteAdsInfo().Where(o => o.Id.ToString() == DDL_Position.SelectedValue).ToList()[0]; FeeInfo feeInfo = CacheCollection.GetAllFeeInfo().Where(o => o.FeeId == buyList[0].FeeId).ToList()[0]; //已经投放了的该收费类型的广告集合 IList <UserAdsInfo> myUseradsList = useradsList.Where(o => o.FeeId == feeInfo.FeeId && o.UserAdsState == 1).ToList(); int calScore = 0; calScore = feeInfo.Score; for (int i = 0; i < myUseradsList.Count; i++) { SiteAdsInfo sainfo = CacheCollection.GetAllSiteAdsInfo().Where(o => o.Id == myUseradsList[i].AdsId).ToList()[0]; calScore -= sainfo.Score; } UserAdsInfo info = new UserAdsInfo(); info.AdsTitle = TB_ShppName.Text.Trim(); info.Id = Guid.NewGuid(); info.UserAdsState = 0; info.AdsUrl = TB_ShowUrl.Text.Trim(); string cateId = ViewState["shopcid"].ToString(); TaoBaoGoodsClassInfo tcinfo = new TaoBaoGoodsClassService().SelectGoodsClass(cateId); info.CateIds = ViewState["shopcid"].ToString(); string cname = tcinfo == null ? "" : tcinfo.name; info.SellCateName = GetTaoBaoCName(info.CateIds, cname); info.AliWang = nick; info.Nick = nick; info.AdsPic = ShopImg; //店铺图标 if (FUD_Img.HasFile && CheckImg()) { Guid imgurl = Guid.NewGuid(); FUD_Img.SaveAs(Server.MapPath("~/adsimg") + "/" + imgurl + ".jpg"); info.AdsPic = "/adsimg/" + imgurl + ".jpg"; } //不能继续投放 if (calScore < sadsinfo.Score) { } //可以投放 else { if (sadsinfo.AdsCount != -1) { //这里需要查询空闲的广告(或者说是可以用的广告位) IList <UserAdsInfo> usedadsList = userAdsDal.SelectAllUsedAds(); IList <SiteAdsInfo> allads = CacheCollection.GetAllSiteAdsInfo().Where(o => o.Id.ToString() == DDL_Position.SelectedValue).ToList(); if (allads.Count > 0 && allads[0].AdsCalCount > 0) { info.AddTime = DateTime.Now; info.AdsId = new Guid(DDL_Position.SelectedValue); //不需要旺旺 info.AliWang = ""; //nick; info.FeeId = buyList[0].FeeId; info.AdsShowStartTime = DateTime.Now; info.AdsShowFinishTime = DateTime.Now.AddDays(feeInfo.ShowDays); info.Nick = nick; info.UserAdsState = 1; //不需要分类 //string taoId = list[i].CateIds; info.CateIds = ""; // GetTaoBaoCId(taoId, ref taoId); } else { Page.RegisterStartupScript("通知", "<script>alert('请联系我们的客服人员为您添加广告');</script>"); } } else { info.AddTime = DateTime.Now; info.AdsId = new Guid(DDL_Position.SelectedValue); info.AliWang = nick; info.FeeId = buyList[0].FeeId; info.AdsShowStartTime = DateTime.Now; info.AdsShowFinishTime = DateTime.Now.AddDays(feeInfo.ShowDays); info.Nick = nick; info.UserAdsState = 1; string taoId = info.CateIds; info.CateIds = GetTaoBaoCId(taoId, taoId); } notou = false; } string uid = CacheCollection.GetAllSiteList().Where(o => o.SiteId.ToString() == DDL_App.SelectedValue).ToList()[0].SiteUrl; int area = CacheCollection.GetAllSiteAdsInfo().Where(o => o.Id.ToString() == DDL_Position.SelectedValue).ToList()[0].PositionCode; int typ = 0; if (DDL_AdsType.SelectedValue == "1A4AB7A8-49A1-41FC-A5A6-788FD582DB82" || DDL_AdsType.SelectedValue == "7CE41706-582D-4270-82C4-81420F923D6A") { typ = 0; } if (DDL_AdsType.SelectedValue == "68A5E23C-6CFD-427D-BD0E-1E2B1B160875" || DDL_AdsType.SelectedValue == "C1F928EF-CA82-4FED-B960-CA33FCE417E9") { typ = 1; } if (DDL_AdsType.SelectedValue == "813F256D-D83A-43CE-8CC4-273C965DBF84") { typ = 2; } Guid ggid = Guid.Empty; if (info.AdsId != Guid.Empty) { ggid = PostIphone.InsertAds(uid, area, typ, info.AdsPic, info.AdsUrl, info.Price, info.AdsTitle); if (ggid == Guid.Empty) { Page.RegisterStartupScript("通知", "<script>alert('发送添加广告错误');</script>"); return; } userAdsDal.InsertUserAds(info, ggid); } } } //if (notou) // Response.Redirect("UserAdsList.aspx"); //else Response.Redirect("UserAdsList.aspx?istou=1"); }
protected void RPT_AdsList_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "De") { Guid id = new Guid(e.CommandArgument.ToString()); uasDal.DelteUserAds(id); Response.Redirect("UserAdsList.aspx"); } if (e.CommandName == "Insert") { Guid id = new Guid(e.CommandArgument.ToString()); UserAdsInfo info = uasDal.SelectUserAdsById(id); string nick = ""; if (Request.Cookies["nick"] != null) { nick = HttpUtility.UrlDecode(Request.Cookies["nick"].Value); //"nick"; } else { nick = Session["snick"].ToString(); } IList <BuyInfo> buyList = CacheCollection.GetAllBuyInfo().Where(o => o.Nick == nick).ToList(); bool noads = true; //投放的广告 IList <UserAdsInfo> useradsList = uasDal.SelectAllUserAds(nick); //购买类型 foreach (BuyInfo binfo in buyList) { //未过期的 if (!binfo.IsExpied) { //收费类型 FeeInfo feeInfo = CacheCollection.GetAllFeeInfo().Where(o => o.FeeId == binfo.FeeId).ToList()[0]; if (feeInfo.AdsCount > 0) { //已经投放了的该收费类型的广告集合 IList <UserAdsInfo> myUseradsList = useradsList.Where(o => o.FeeId == feeInfo.FeeId && o.UserAdsState == 1).ToList(); //真正可以添加的广告数量 int realcount = feeInfo.AdsCount - myUseradsList.Count; if (realcount > 0) { if (feeInfo.AdsType == 5) { //这里需要查询空闲的广告(或者说是可以用的广告位) IList <UserAdsInfo> usedadsList = uasDal.SelectAllUsedAds(); IList <AdsInfo> allads = CacheCollection.GetAllAdsInfo().Where(o => o.AdsType == 5).ToList(); if (allads.Count > usedadsList.Count) { //得到没有使用的广告位 IList <AdsInfo> hasads = new List <AdsInfo>(); foreach (AdsInfo ainfo in allads) { if (usedadsList.Where(o => o.AdsId == ainfo.AdsId).ToList().Count == 0) { hasads.Add(ainfo); } } info.AddTime = DateTime.Now; info.AdsId = GetRand(hasads); //不需要旺旺 info.AliWang = ""; //nick; info.FeeId = binfo.FeeId; info.AdsShowStartTime = DateTime.Now; info.AdsShowFinishTime = DateTime.Now.AddDays(feeInfo.ShowDays); info.Nick = nick; info.UserAdsState = 1; //不需要分类 //string taoId = info.CateIds; info.CateIds = ""; // GetTaoBaoCId(taoId, ref taoId); } else { Page.RegisterStartupScript("通知", "<script>alert('请联系我们的客服人员为您添加广告');</script>"); } continue; } info.AddTime = DateTime.Now; info.AdsId = info.AdsId == Guid.Empty ? GetRand(CacheCollection.GetAllAdsInfo().Where(o => o.AdsType == 1).ToList()) : info.AdsId; info.AliWang = nick; info.FeeId = binfo.FeeId; info.AdsShowStartTime = DateTime.Now; info.AdsShowFinishTime = DateTime.Now.AddDays(feeInfo.ShowDays); info.Nick = nick; info.UserAdsState = 1; string taoId = info.CateIds; info.CateIds = GetTaoBaoCId(taoId, ref taoId); info.Id = id; uasDal.UpdateUserAdsState(info); // noads = false; break; } } } } if (noads) { Response.Redirect("/qubie.html"); } else { Response.Redirect("UserAdsList.aspx?istou=1"); } } if (e.CommandName == "Result") { Guid id = new Guid(e.CommandArgument.ToString()); Response.Redirect("ShowClick.aspx?id=" + id); } if (e.CommandName == "See") { Guid id = new Guid(e.CommandArgument.ToString()); Response.Redirect("ShowAds.aspx?adsid=" + id); } if (e.CommandName == "Stop") { Guid id = new Guid(e.CommandArgument.ToString()); uasDal.StopUserAds(2, id); Response.Redirect("UserAdsList.aspx"); } if (e.CommandName == "Add") { } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string nick = ""; if (Request.Cookies["nick"] != null) { nick = HttpUtility.UrlDecode(Request.Cookies["nick"].Value); //"nick"; } else { nick = Session["snick"].ToString(); } if (nick == "") { Response.Write("请重新登录"); return; } IList <UserAdsInfo> list = uasDal.SelectAllUserAdsList(nick); //IList<UserAdsInfo> useradsList = uasDal.SelectAllUserAds(nick); IList <BuyInfo> buyList = CacheCollection.GetAllBuyInfo().Where(o => o.Nick == nick).ToList(); ViewState["toucount"] = list.Where(o => o.UserAdsState == 1).ToList().Count; ViewState["notoucount"] = list.Where(o => o.UserAdsState != 1).ToList().Count; if (buyList.Count > 0) { ViewState["adscount"] = CacheCollection.GetAllFeeInfo().Where(o => o.FeeId == buyList[0].FeeId).ToList()[0].AdsCount; } if (Request.QueryString["istou"] == "1") { list = list.Where(o => o.UserAdsState == 1).ToList(); Lbl_ShowAdsDec.Text = "投放中的广告"; } else { list = list.Where(o => o.UserAdsState != 1).ToList(); Lbl_ShowAdsDec.Text = "未投放的广告"; } int TotalCount = list.Count; int TotalPage = 1; //总页数 int page = 1; try { if (!string.IsNullOrEmpty(Request.QueryString["Page"])) { page = int.Parse(Request.QueryString["Page"]); } } catch { } pds.DataSource = list; pds.AllowPaging = true; pds.PageSize = 5; if (TotalCount == 0) { TotalPage = 1; } else { if (TotalCount % pds.PageSize == 0) { TotalPage = TotalCount / pds.PageSize; } else { TotalPage = TotalCount / pds.PageSize + 1; } } pds.CurrentPageIndex = page - 1; lblCurrentPage.Text = "共" + TotalCount.ToString() + "条记录 当前页:" + page + "/" + TotalPage; string paramArray = Request.QueryString["istou"] == "1" ? "&istou=1" : ""; lnkFrist.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1" + paramArray; if (!pds.IsFirstPage) { lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + (page - 1) + paramArray; } if (!pds.IsLastPage) { lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + (page + 1) + paramArray; } lnkEnd.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + TotalPage + paramArray; RPT_AdsList.DataSource = pds; RPT_AdsList.DataBind(); } }
protected void BTN_Tui_Click(object sender, EventArgs e) { string nick = ""; if (Request.Cookies["nick"] != null) { nick = HttpUtility.UrlDecode(Request.Cookies["nick"].Value); //"nick"; } else { nick = Session["snick"].ToString(); } //购买类型 IList <BuyInfo> buyList = CacheCollection.GetAllBuyInfo().Where(o => o.Nick == nick).ToList(); //投放的广告 IList <UserAdsInfo> useradsList = userAdsDal.SelectAllUserAds(nick); bool notou = true; foreach (BuyInfo binfo in buyList) { //未过期的 if (!binfo.IsExpied) { //收费类型 FeeInfo feeInfo = CacheCollection.GetAllFeeInfo().Where(o => o.FeeId == binfo.FeeId).ToList()[0]; if (feeInfo.AdsCount > 0) { //已经投放了的该收费类型的广告集合 IList <UserAdsInfo> myUseradsList = useradsList.Where(o => o.FeeId == feeInfo.FeeId && o.UserAdsState == 1).ToList(); //真正可以添加的广告数量 int realcount = feeInfo.AdsCount - myUseradsList.Count; UserAdsInfo info = new UserAdsInfo(); info.AdsTitle = TB_ShppName.Text.Trim(); info.Id = Guid.NewGuid(); info.UserAdsState = 0; info.AdsUrl = TB_ShowUrl.Text.Trim(); string cateId = ViewState["shopcid"].ToString(); TaoBaoGoodsClassInfo tcinfo = new TaoBaoGoodsClassService().SelectGoodsClass(cateId); info.CateIds = ViewState["shopcid"].ToString(); string cname = tcinfo == null ? "" : tcinfo.name; info.SellCateName = GetTaoBaoCName(info.CateIds, cname); info.AliWang = nick; info.Nick = nick; info.AdsPic = ShopImg; //店铺图标 if (FUD_Img.HasFile && CheckImg()) { Guid imgurl = Guid.NewGuid(); FUD_Img.SaveAs(Server.MapPath("~/adsimg") + "/" + imgurl + ".jpg"); info.AdsPic = "/adsimg/" + imgurl + ".jpg"; } if (realcount > 0) { if (feeInfo.AdsType == 5) { //这里需要查询空闲的广告(或者说是可以用的广告位) IList <UserAdsInfo> usedadsList = userAdsDal.SelectAllUsedAds(); IList <AdsInfo> allads = CacheCollection.GetAllAdsInfo().Where(o => o.AdsType == 5).ToList(); if (allads.Count > usedadsList.Count) { //得到没有使用的广告位 IList <AdsInfo> hasads = new List <AdsInfo>(); foreach (AdsInfo ainfo in allads) { if (usedadsList.Where(o => o.AdsId == ainfo.AdsId).ToList().Count == 0) { hasads.Add(ainfo); } } info.AddTime = DateTime.Now; info.AdsId = GetRand(hasads); //不需要旺旺 info.AliWang = ""; //nick; info.FeeId = binfo.FeeId; info.AdsShowStartTime = DateTime.Now; info.AdsShowFinishTime = DateTime.Now.AddDays(feeInfo.ShowDays); info.Nick = nick; info.UserAdsState = 1; //不需要分类 //string taoId = list[i].CateIds; info.CateIds = ""; // GetTaoBaoCId(taoId, ref taoId); } else { Page.RegisterStartupScript("通知", "<script>alert('请联系我们的客服人员为您添加广告');</script>"); } } if (feeInfo.AdsType == 1) { info.AddTime = DateTime.Now; info.AdsId = GetRand(CacheCollection.GetAllAdsInfo().Where(o => o.AdsType == 1).ToList()); info.AliWang = nick; info.FeeId = binfo.FeeId; info.AdsShowStartTime = DateTime.Now; info.AdsShowFinishTime = DateTime.Now.AddDays(feeInfo.ShowDays); info.Nick = nick; info.UserAdsState = 1; string taoId = info.CateIds; info.CateIds = GetTaoBaoCId(taoId, taoId); } notou = false; } userAdsDal.InsertUserAds(info); break; } } } if (notou) { Response.Redirect("UserAdsList.aspx"); } else { Response.Redirect("UserAdsList.aspx?istou=1"); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { IList <AdsInfo> adsList = CacheCollection.GetAllAdsInfo(); Random rand = new Random(); AdsInfo info = adsList[rand.Next(adsList.Count)]; IList <UserAdsInfo> list = uasDal.SelectAllUserAdsByAdsId(info.AdsId, 1); IList <ClickInfo> clickList = clickDal.SelectAllClickCount(DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("yyyyMMdd")); //获取访问IP string ip = Request.ServerVariables["REMOTE_ADDR"]; //获取当天已经访问来了的IP IList <ClickIPInfo> ipList = clickDal.SelectAllClickIPByDate(DateTime.Now.ToString("yyyyMMdd")); //和当前IP相同的 ipList = ipList.Where(o => o.VisitIP == ip).ToList(); foreach (ClickIPInfo ipinfo in ipList) { //已经访问了该广告 IList <UserAdsInfo> hadlist = list.Where(o => o.Id == ipinfo.UserAdsId).ToList(); if (hadlist.Count > 0) { list.Remove(hadlist[0]); } } if (list.Count == 0) { return; } foreach (ClickInfo cinfo in clickList) { if (cinfo.ClickCount >= rand.Next(6, 15))//10) { IList <UserAdsInfo> hadlist = list.Where(o => o.Id == cinfo.UserAdsId).ToList(); if (hadlist.Count > 0) { FeeInfo finfo = CacheCollection.GetAllFeeInfo().Where(o => o.FeeId == hadlist[0].FeeId).ToList()[0]; if (finfo.AdsType == 1) { if (finfo.AdsCount == 1) { list.Remove(hadlist[0]); } else { if (cinfo.ClickCount >= rand.Next(14, 23))//18) { list.Remove(hadlist[0]); } } } if (finfo.AdsType == 5) { if (cinfo.ClickCount >= rand.Next(22, 33)) //27) { list.Remove(hadlist[0]); } } } } } if (list.Count == 0) { return; } UserAdsInfo uinfo = list[0]; if (list.Count > 1) { uinfo = list[rand.Next(list.Count)]; } ClickIPInfo iinfo = new ClickIPInfo(); iinfo.VisitIP = ip; iinfo.ClickId = Guid.NewGuid(); iinfo.VisitDate = DateTime.Now.ToString("yyyyMMdd"); iinfo.UserAdsId = uinfo.Id; clickDal.InsertClickIP(iinfo); string param = "id=" + uinfo.Id + "&url=" + uinfo.AdsUrl; Response.Redirect("getclick.aspx?" + HttpUtility.UrlEncode(param)); } }
protected void BTN_ShowGoods_Click(object sender, EventArgs e) { IList <UserAdsInfo> list = new List <UserAdsInfo>(); string nick = ""; if (Request.Cookies["nick"] != null) { nick = HttpUtility.UrlDecode(Request.Cookies["nick"].Value); //"nick"; } else { nick = Session["snick"].ToString(); } if (DDL_AdsType.SelectedValue == Guid.Empty.ToString() || DDL_App.SelectedValue == Guid.Empty.ToString() || DDL_Position.SelectedValue == Guid.Empty.ToString()) { Page.RegisterStartupScript("通知", "<script>alert('请选择投放的应用,类型以及位置,请按您购买的服务类型选择!');</script>"); return; } CateService cateDal = new CateService(); IList <CateInfo> cateList = cateDal.SelectAllCateByNick(nick).ToList(); UserAdsService userAdsDal = new UserAdsService(); foreach (RepeaterItem item in Rpt_GoodsList.Items) { CheckBox cb = (CheckBox)item.FindControl("CBOX_Goods"); if (cb.Checked) { UserAdsInfo info = new UserAdsInfo(); info.AdsTitle = ((Label)item.FindControl("LB_GoodsName")).Text; info.Id = Guid.NewGuid(); info.UserAdsState = 0; info.AdsUrl = "http://item.taobao.com/item.htm?id=" + ((Label)item.FindControl("LB_GoodsId")).Text; string cateId = ((Label)item.FindControl("LB_CateId")).Text; IList <CateInfo> thiscList = cateList.Where(o => o.CateId == cateId).ToList(); info.CateIds = ((Label)item.FindControl("LB_TaoBaoCId")).Text; string cname = thiscList.Count == 0 ? "" : thiscList[0].CateName; info.SellCateName = GetTaoBaoCName(info.CateIds, cname); info.AliWang = nick; info.Nick = nick; info.AdsPic = ((Label)item.FindControl("LB_Img")).Text; info.Price = decimal.Parse(((Label)item.FindControl("LB_Price")).Text); list.Add(info); } } if (list.Count == 0) { return; } SiteAdsInfo sadsinfo = CacheCollection.GetAllSiteAdsInfo().Where(o => o.Id.ToString() == DDL_Position.SelectedValue).ToList()[0]; int needScore = sadsinfo.Score * list.Count; //购买类型 IList <BuyInfo> buyList = CacheCollection.GetAllBuyInfo().Where(o => o.Nick == nick).ToList(); //投放的广告 IList <UserAdsInfo> useradsList = userAdsDal.SelectAllUserAds(nick); //新的添加广告方法 if (buyList.Count > 0) { if (!buyList[0].IsExpied) { FeeInfo feeInfo = CacheCollection.GetAllFeeInfo().Where(o => o.FeeId == buyList[0].FeeId).ToList()[0]; //已经投放了的该收费类型的广告集合 IList <UserAdsInfo> myUseradsList = useradsList.Where(o => o.FeeId == feeInfo.FeeId && o.UserAdsState == 1).ToList(); int calScore = 0; calScore = feeInfo.Score; for (int i = 0; i < myUseradsList.Count; i++) { SiteAdsInfo sainfo = CacheCollection.GetAllSiteAdsInfo().Where(o => o.Id == myUseradsList[i].AdsId).ToList()[0]; calScore -= sainfo.Score; } int canTou = calScore / needScore; //可以投放的个数 if (canTou > 0) { canTou = canTou > list.Count ? list.Count : canTou; } //不能继续投放 if (canTou == 0) { Page.RegisterStartupScript("通知", "<script>alert('您不能投放该类型广告');</script>"); } //可以投放 else { if (sadsinfo.AdsCount != -1) { //这里需要查询空闲的广告(或者说是可以用的广告位) IList <UserAdsInfo> usedadsList = userAdsDal.SelectAllUsedAds(); IList <SiteAdsInfo> allads = CacheCollection.GetAllSiteAdsInfo().Where(o => o.Id.ToString() == DDL_Position.SelectedValue).ToList(); if (allads.Count > 0 && allads[0].AdsCalCount > 0) { //可以放多少个 for (int i = 0; i < canTou; i++) { list[i].AddTime = DateTime.Now; list[i].AliWang = nick; list[i].FeeId = feeInfo.FeeId; list[i].AdsShowStartTime = DateTime.Now; list[i].AdsShowFinishTime = DateTime.Now.AddDays(feeInfo.ShowDays); list[i].Nick = nick; list[i].UserAdsState = 1; string taoId = list[i].CateIds; list[i].CateIds = GetTaoBaoCId(taoId, taoId); list[i].AdsId = new Guid(DDL_Position.SelectedValue); } } else { Page.RegisterStartupScript("通知", "<script>alert('请联系我们的客服人员为您添加广告');</script>"); } } else { //可以放多少个 for (int i = 0; i < canTou; i++) { list[i].AddTime = DateTime.Now; list[i].AliWang = nick; list[i].FeeId = feeInfo.FeeId; list[i].AdsShowStartTime = DateTime.Now; list[i].AdsShowFinishTime = DateTime.Now.AddDays(feeInfo.ShowDays); list[i].Nick = nick; list[i].UserAdsState = 1; string taoId = list[i].CateIds; list[i].CateIds = GetTaoBaoCId(taoId, taoId); list[i].AdsId = new Guid(DDL_Position.SelectedValue); } } } } } string uid = CacheCollection.GetAllSiteList().Where(o => o.SiteId.ToString() == DDL_App.SelectedValue).ToList()[0].SiteUrl; int area = CacheCollection.GetAllSiteAdsInfo().Where(o => o.Id.ToString() == DDL_Position.SelectedValue).ToList()[0].PositionCode; int typ = 0; if (DDL_AdsType.SelectedValue.ToLower() == "1A4AB7A8-49A1-41FC-A5A6-788FD582DB82".ToLower() || DDL_AdsType.SelectedValue.ToLower() == "7CE41706-582D-4270-82C4-81420F923D6A".ToLower()) { typ = 0; } if (DDL_AdsType.SelectedValue.ToLower() == "68A5E23C-6CFD-427D-BD0E-1E2B1B160875".ToLower() || DDL_AdsType.SelectedValue.ToLower() == "C1F928EF-CA82-4FED-B960-CA33FCE417E9".ToLower()) { typ = 1; } if (DDL_AdsType.SelectedValue.ToLower() == "813F256D-D83A-43CE-8CC4-273C965DBF84".ToLower()) { typ = 2; } foreach (UserAdsInfo info in list) { Guid ggid = info.Id; if (info.AdsId != Guid.Empty) { ggid = PostIphone.InsertAds(uid, area, typ, info.AdsPic, info.AdsUrl, info.Price, info.AdsTitle); if (ggid == Guid.Empty) { Page.RegisterStartupScript("通知", "<script>alert('发送添加广告错误');</script>"); continue; } userAdsDal.InsertUserAds(info, ggid); } } Response.Redirect("UserAdsList.aspx?istou=1"); }