Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.RawUrl.StartsWith("/dollarsaver/index"))
                {
                    //Response.Redirect("~/Default.aspx?station_id=" + StationId);
                    DollarSaverRedirect("~/Default.aspx");
                }


                DateTime currentDate = DateTime.Now;
                currentDate = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day);

                StationTableAdapter stationAdapter = new StationTableAdapter();

                DollarSaverDB.StationRow station = stationAdapter.GetStation(StationId)[0];
                siteType = (SiteType)station.SiteTypeId;

                CertificateTableAdapter certificateAdapter = new CertificateTableAdapter();


                //stationNameLabel.Text = station.Name;
                if (!station.IsContent1Null())
                {
                    content1Label.Text = station.Content1;
                }

                if (!station.IsContent2Null())
                {
                    content2Label.Text = station.Content2;
                }

                String ImageDir = Request.PhysicalApplicationPath + station.ImageDirUrl;
                if (station.StationSiteType == SiteType.Standard)
                {
                    standardHolder.Visible = true;
                    dealHolder.Visible     = false;

                    signUpTopLink.NavigateUrl = GetUrl(signUpTopLink.NavigateUrl);

                    SpecialSettingsTableAdapter            specialSettingsAdapter = new SpecialSettingsTableAdapter();
                    DollarSaverDB.SpecialSettingsDataTable specialSettingsTable   = specialSettingsAdapter.GetSpecialSettings(StationId);

                    bool dailyHeader = false;
                    if (specialSettingsTable.Count == 1)
                    {
                        dailyHeader = specialSettingsTable[0].DailyHeader;
                    }

                    Image dailyWeeklyImage = new Image();

                    if (dailyHeader)
                    {
                        //dailyWeeklyImage.SkinID = "dailyImage";

                        if (!station.Content.IsDailyDealImageNull() && File.Exists(ImageDir + station.Content.DailyDealImage))
                        {
                            dailyWeeklyImage.ImageUrl = station.ImageDirUrl + station.Content.DailyDealImage;
                        }
                        else
                        {
                            dailyWeeklyImage.ImageUrl = "~/images/boxtop_daily.gif";
                        }
                    }
                    else
                    {
                        //dailyWeeklyImage.SkinID = "weeklyImage";
                        if (!station.Content.IsWeeklyDealImageNull() && File.Exists(ImageDir + station.Content.WeeklyDealImage))
                        {
                            dailyWeeklyImage.ImageUrl = station.ImageDirUrl + station.Content.WeeklyDealImage;
                        }
                        else
                        {
                            dailyWeeklyImage.ImageUrl = "~/images/boxtop_weekly.gif";
                        }
                    }

                    dailyWeeklyImageHolder.Controls.Add(dailyWeeklyImage);

                    DollarSaverDB.CertificateDataTable daily = certificateAdapter.GetSpecial(StationId, 1);
                    if (daily.Count == 1)
                    {
                        SpecialCert1.DisplayCertificate = daily[0];
                        if (HitCounterEnabled)
                        {
                            LogHit(currentDate, daily[0].CertificateId, PageHitType.HomePage);
                        }
                    }

                    DollarSaverDB.CertificateDataTable cert2 = certificateAdapter.GetSpecial(StationId, 2);
                    if (cert2.Count == 1)
                    {
                        SpecialCert2.DisplayCertificate = cert2[0];
                        if (HitCounterEnabled)
                        {
                            LogHit(currentDate, cert2[0].CertificateId, PageHitType.HomePage);
                        }
                    }

                    DollarSaverDB.CertificateDataTable cert3 = certificateAdapter.GetSpecial(StationId, 3);
                    if (cert3.Count == 1)
                    {
                        SpecialCert3.DisplayCertificate = cert3[0];
                        if (HitCounterEnabled)
                        {
                            LogHit(currentDate, cert3[0].CertificateId, PageHitType.HomePage);
                        }
                    }

                    DollarSaverDB.CertificateDataTable cert4 = certificateAdapter.GetSpecial(StationId, 4);
                    if (cert4.Count == 1)
                    {
                        SpecialCert4.DisplayCertificate = cert4[0];
                        if (HitCounterEnabled)
                        {
                            LogHit(currentDate, cert4[0].CertificateId, PageHitType.HomePage);
                        }
                    }

                    if (!station.Content.IsOtherDealsImageNull() && File.Exists(ImageDir + station.Content.OtherDealsImage))
                    {
                        otherDealsImage.ImageUrl = station.ImageDirUrl + station.Content.OtherDealsImage;
                    }

                    if (!station.Content.IsLogoImageNull() && File.Exists(ImageDir + station.Content.LogoImage))
                    {
                        logoImage.ImageUrl = station.ImageDirUrl + station.Content.LogoImage;
                    }
                }
                else     // Deal of the Week
                {
                    standardHolder.Visible = false;
                    dealHolder.Visible     = true;

                    if (!Station.IsSiteNameNull() && Station.SiteName != String.Empty)
                    {
                        dotwStationNameLabel.Text = Regex.Replace(Station.SiteName, "<[^>]+>", "");
                    }
                    else
                    {
                        dotwStationNameLabel.Text = "DollarSaver Deal of the Week";
                    }

                    if (!Station.Content.IsDotwSubheaderImageNull() && File.Exists(ImageDir + station.Content.DotwSubheaderImage))
                    {
                        subheaderCell.Style["background-image"] = "url(" + station.ImageDirUrl + station.Content.DotwSubheaderImage + ")";
                    }
                    else
                    {
                        subheaderCell.Style["background-image"] = "url(" + ResolveUrl("~/images/dotw_background.gif") + ")";
                    }

                    DollarSaverDB.CertificateDataTable certificateTable = certificateAdapter.GetCurrentDeal(StationId);

                    if (certificateTable.Count == 1)
                    {
                        dealOfTheWeek.Deal = certificateTable[0];
                        if (HitCounterEnabled)
                        {
                            LogHit(currentDate, certificateTable[0].CertificateId, PageHitType.HomePage);
                        }
                    }
                }
            }
        }
        void saveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                specialTable = new DollarSaverDB.StationSpecialDataTable();

                bool specialOneNew = false;
                if (specialOne == null)
                {
                    specialOneNew        = true;
                    specialOne           = specialTable.NewStationSpecialRow();
                    specialOne.StationId = StationId;
                    specialOne.SeqNo     = 1;
                }

                bool specialTwoNew = false;
                if (specialTwo == null)
                {
                    specialTwoNew        = true;
                    specialTwo           = specialTable.NewStationSpecialRow();
                    specialTwo.StationId = StationId;
                    specialTwo.SeqNo     = 2;
                }

                bool specialThreeNew = false;
                if (specialThree == null)
                {
                    specialThreeNew        = true;
                    specialThree           = specialTable.NewStationSpecialRow();
                    specialThree.StationId = StationId;
                    specialThree.SeqNo     = 3;
                }

                bool specialFourNew = false;
                if (specialFour == null)
                {
                    specialFourNew        = true;
                    specialFour           = specialTable.NewStationSpecialRow();
                    specialFour.StationId = StationId;
                    specialFour.SeqNo     = 4;
                }

                // Special One
                //if (specialOneCertificateBox.Checked) {
                bool dailyHeader = false;
                if (dailyWeeklyList.SelectedValue == "1")
                {
                    dailyHeader = true;
                }

                SpecialSettingsTableAdapter            specialSettingsAdapter = new SpecialSettingsTableAdapter();
                DollarSaverDB.SpecialSettingsDataTable specialSettingsTable   = specialSettingsAdapter.GetSpecialSettings(StationId);

                if (specialSettingsTable.Count == 1)
                {
                    specialSettingsTable[0].DailyHeader = dailyHeader;
                    specialSettingsAdapter.Update(specialSettingsTable[0]);
                }
                else
                {
                    specialSettingsAdapter.Insert(StationId, dailyHeader);
                }

                specialOne.CertificateId = Convert.ToInt32(specialOneCertificateList.SelectedValue);
                specialOne.SetCategoryIdNull();

                /*
                 * } else if (specialOneCategoryBox.Checked) {
                 *  specialOne.CategoryId = Convert.ToInt32(specialOneCategoryList.SelectedValue);
                 *  specialOne.SetCertificateIdNull();
                 * } else {
                 *  specialOne.SetCertificateIdNull();
                 *  specialOne.SetCategoryIdNull();
                 * }
                 * */

                if (specialOneNew)
                {
                    specialTable.AddStationSpecialRow(specialOne);
                }
                else
                {
                    specialTable.ImportRow(specialOne);
                }

                // Special Two
                if (specialTwoCertificateBox.Checked)
                {
                    specialTwo.CertificateId = Convert.ToInt32(specialTwoCertificateList.SelectedValue);
                    specialTwo.SetCategoryIdNull();
                }
                else if (specialTwoCategoryBox.Checked)
                {
                    specialTwo.CategoryId = Convert.ToInt32(specialTwoCategoryList.SelectedValue);
                    specialTwo.SetCertificateIdNull();
                }
                else
                {
                    specialTwo.SetCertificateIdNull();
                    specialTwo.SetCategoryIdNull();
                }

                if (specialTwoNew)
                {
                    specialTable.AddStationSpecialRow(specialTwo);
                }
                else
                {
                    specialTable.ImportRow(specialTwo);
                }

                // Special Three
                if (specialThreeCertificateBox.Checked)
                {
                    specialThree.CertificateId = Convert.ToInt32(specialThreeCertificateList.SelectedValue);
                    specialThree.SetCategoryIdNull();
                }
                else if (specialThreeCategoryBox.Checked)
                {
                    specialThree.CategoryId = Convert.ToInt32(specialThreeCategoryList.SelectedValue);
                    specialThree.SetCertificateIdNull();
                }
                else
                {
                    specialThree.SetCertificateIdNull();
                    specialThree.SetCategoryIdNull();
                }

                if (specialThreeNew)
                {
                    specialTable.AddStationSpecialRow(specialThree);
                }
                else
                {
                    specialTable.ImportRow(specialThree);
                }

                // Special Four
                if (specialFourCertificateBox.Checked)
                {
                    specialFour.CertificateId = Convert.ToInt32(specialFourCertificateList.SelectedValue);
                    specialFour.SetCategoryIdNull();
                }
                else if (specialFourCategoryBox.Checked)
                {
                    specialFour.CategoryId = Convert.ToInt32(specialFourCategoryList.SelectedValue);
                    specialFour.SetCertificateIdNull();
                }
                else
                {
                    specialFour.SetCertificateIdNull();
                    specialFour.SetCategoryIdNull();
                }

                if (specialFourNew)
                {
                    specialTable.AddStationSpecialRow(specialFour);
                }
                else
                {
                    specialTable.ImportRow(specialFour);
                }



                specialAdapter.Update(specialTable);

                InfoMessage = "Specials updated";
                Response.Redirect("~/admin/Default.aspx");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            saveButton.Click   += new EventHandler(saveButton_Click);
            cancelButton.Click += new EventHandler(cancelButton_Click);


            if (Station.SiteTypeId != (int)SiteType.Standard)
            {
                Response.Redirect("~/admin/Default.aspx");
            }

            specialTable = specialAdapter.GetStationSpecial(StationId, 1);
            if (specialTable.Count == 1)
            {
                specialOne = specialTable[0];
            }
            specialTable = specialAdapter.GetStationSpecial(StationId, 2);
            if (specialTable.Count == 1)
            {
                specialTwo = specialTable[0];
            }
            specialTable = specialAdapter.GetStationSpecial(StationId, 3);
            if (specialTable.Count == 1)
            {
                specialThree = specialTable[0];
            }
            specialTable = specialAdapter.GetStationSpecial(StationId, 4);
            if (specialTable.Count == 1)
            {
                specialFour = specialTable[0];
            }

            if (!Page.IsPostBack)
            {
                CategoryTableAdapter            categoryAdapter = new CategoryTableAdapter();
                DollarSaverDB.CategoryDataTable categories      = categoryAdapter.GetPrimaryCategoriesByStation(StationId);

                CertificateTableAdapter            certificateAdapter = new CertificateTableAdapter();
                DollarSaverDB.CertificateDataTable certificates       = certificateAdapter.GetActive(StationId);

                //certificates.DefaultView.Sort

                SpecialSettingsTableAdapter            specialSettingsAdapter = new SpecialSettingsTableAdapter();
                DollarSaverDB.SpecialSettingsDataTable specialSettingsTable   = specialSettingsAdapter.GetSpecialSettings(StationId);

                if (specialSettingsTable.Count == 1)
                {
                    if (specialSettingsTable[0].DailyHeader)
                    {
                        dailyWeeklyList.SelectedValue = "1";
                    }
                    else
                    {
                        dailyWeeklyList.SelectedValue = "2";
                    }
                }

                // Daily/Weekly Special 1

                /*
                 * specialOneCategoryList.DataSource = categories;
                 * specialOneCategoryList.DataTextField = "Name";
                 * specialOneCategoryList.DataValueField = "CategoryId";
                 * specialOneCategoryList.DataBind();
                 */

                specialOneCertificateList.DataSource     = certificates.Rows;
                specialOneCertificateList.DataTextField  = "AdvertiserAndCertificate";
                specialOneCertificateList.DataValueField = "CertificateId";
                specialOneCertificateList.DataBind();


                if (specialOne != null)
                {
                    if (!specialOne.IsCertificateIdNull())
                    {
                        //specialOneCertificateBox.Checked = true;

                        if (certificates.FindByCertificateId(specialOne.CertificateId) != null)
                        {
                            specialOneCertificateList.SelectedValue = specialOne.CertificateId.ToString();
                        }
                    }

                    /*
                     * else if (!specialOne.IsCategoryIdNull()) {
                     *  specialOneCategoryBox.Checked = true;
                     *
                     *  specialOneCategoryList.SelectedValue = specialOne.CategoryId.ToString();
                     * } else {
                     *  specialOneRandomBox.Checked = true;
                     * }
                     */
                }

                // Special 2
                specialTwoCategoryList.DataSource     = categories;
                specialTwoCategoryList.DataTextField  = "Name";
                specialTwoCategoryList.DataValueField = "CategoryId";
                specialTwoCategoryList.DataBind();

                specialTwoCertificateList.DataSource     = certificates.Rows;
                specialTwoCertificateList.DataTextField  = "AdvertiserAndCertificate";
                specialTwoCertificateList.DataValueField = "CertificateId";
                specialTwoCertificateList.DataBind();

                if (specialTwo != null)
                {
                    if (!specialTwo.IsCertificateIdNull())
                    {
                        specialTwoCertificateBox.Checked = true;

                        if (certificates.FindByCertificateId(specialTwo.CertificateId) != null)
                        {
                            specialTwoCertificateList.SelectedValue = specialTwo.CertificateId.ToString();
                        }
                    }
                    else if (!specialTwo.IsCategoryIdNull())
                    {
                        specialTwoCategoryBox.Checked = true;

                        specialTwoCategoryList.SelectedValue = specialTwo.CategoryId.ToString();
                    }
                    else
                    {
                        specialTwoRandomBox.Checked = true;
                    }
                }


                // Special 3
                specialThreeCategoryList.DataSource     = categories;
                specialThreeCategoryList.DataTextField  = "Name";
                specialThreeCategoryList.DataValueField = "CategoryId";
                specialThreeCategoryList.DataBind();

                specialThreeCertificateList.DataSource     = certificates.Rows;
                specialThreeCertificateList.DataTextField  = "AdvertiserAndCertificate";
                specialThreeCertificateList.DataValueField = "CertificateId";
                specialThreeCertificateList.DataBind();

                if (specialThree != null)
                {
                    if (!specialThree.IsCertificateIdNull())
                    {
                        specialThreeCertificateBox.Checked = true;

                        if (certificates.FindByCertificateId(specialThree.CertificateId) != null)
                        {
                            specialThreeCertificateList.SelectedValue = specialThree.CertificateId.ToString();
                        }
                    }
                    else if (!specialThree.IsCategoryIdNull())
                    {
                        specialThreeCategoryBox.Checked = true;

                        specialThreeCategoryList.SelectedValue = specialThree.CategoryId.ToString();
                    }
                    else
                    {
                        specialThreeRandomBox.Checked = true;
                    }
                }

                // Special 4
                specialFourCategoryList.DataSource     = categories;
                specialFourCategoryList.DataTextField  = "Name";
                specialFourCategoryList.DataValueField = "CategoryId";
                specialFourCategoryList.DataBind();

                specialFourCertificateList.DataSource     = certificates.Rows;
                specialFourCertificateList.DataTextField  = "AdvertiserAndCertificate";
                specialFourCertificateList.DataValueField = "CertificateId";
                specialFourCertificateList.DataBind();

                if (specialFour != null)
                {
                    if (!specialFour.IsCertificateIdNull())
                    {
                        specialFourCertificateBox.Checked = true;

                        if (certificates.FindByCertificateId(specialFour.CertificateId) != null)
                        {
                            specialFourCertificateList.SelectedValue = specialFour.CertificateId.ToString();
                        }
                    }
                    else if (!specialFour.IsCategoryIdNull())
                    {
                        specialFourCategoryBox.Checked = true;

                        specialFourCategoryList.SelectedValue = specialFour.CategoryId.ToString();
                    }
                    else
                    {
                        specialFourRandomBox.Checked = true;
                    }
                }
            }
        }
        private void GenerateFeed()
        {
            CertificateTableAdapter certificateAdapter = new CertificateTableAdapter();


            String description = "";

            String siteUrl     = "http://" + EnvDomain;
            String homePageUrl = siteUrl + ResolveUrl("~/Default.aspx") + "?station_id=" + StationId;

            //mainFeed.Title = TextSyndicationContent.CreatePlaintextContent(Station.SiteNamePlainText);
            //mainFeed.Links.Add(SyndicationLink.CreateSelfLink(new Uri(homePageUrl)));


            List <DollarSaverDB.CertificateRow> listCertificates = new List <DollarSaverDB.CertificateRow>();

            if (Station.StationSiteType == SiteType.Standard)
            {
                SpecialSettingsTableAdapter            specialSettingsAdapter = new SpecialSettingsTableAdapter();
                DollarSaverDB.SpecialSettingsDataTable specialSettingsTable   = specialSettingsAdapter.GetSpecialSettings(StationId);

                bool dailyHeader = false;
                if (specialSettingsTable.Count == 1)
                {
                    dailyHeader = specialSettingsTable[0].DailyHeader;
                }

                if (dailyHeader)
                {
                    description = "Daily Deal";
                }
                else
                {
                    description = "Weekly Deal";
                }

                DollarSaverDB.CertificateDataTable daily = certificateAdapter.GetSpecial(StationId, 1);
                if (daily.Count == 1)
                {
                    listCertificates.Add(daily[0]);
                }
            }
            else
            {
                description = "Deal of the Week";

                DollarSaverDB.CertificateDataTable certificateTable = certificateAdapter.GetCurrentDeal(StationId);

                if (certificateTable.Count == 1)
                {
                    listCertificates.Add(certificateTable[0]);
                }
            }

            List <SyndicationItem> items = new List <SyndicationItem>();

            foreach (DollarSaverDB.CertificateRow certificate in listCertificates)
            {
                SyndicationItem item = new SyndicationItem();

                item.Title = TextSyndicationContent.CreatePlaintextContent(certificate.AdvertiserName);

                String advertiserUrl = siteUrl + ResolveUrl("~/Advertiser.aspx?advertiser_id=" + certificate.AdvertiserId);

                item.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(advertiserUrl)));


                StringBuilder content = new StringBuilder();


                if (certificate.Advertiser.LogoUrl != String.Empty)
                {
                    String logoUrl = siteUrl + ResolveUrl(certificate.Advertiser.LogoUrl);

                    int logoWidth  = 125;
                    int logoHeight = 75;

                    if (certificate.Advertiser.IsLogoImageVertical)
                    {
                        logoWidth  = 75;
                        logoHeight = 125;
                    }

                    content.Append("<div>");
                    content.Append("<a href=\"" + advertiserUrl + "\">");
                    content.Append("<img src=\"" + logoUrl + "\"  alt=\"" + Server.HtmlEncode(certificate.AdvertiserName) + "\" style=\"border-color:#404040;border-width:1px;border-style:solid;height:" + logoHeight + "px;width:" + logoWidth + "px;\">");
                    content.Append("</a>");
                    content.Append("</div>");
                }

                content.Append("<div style=\"font-family: Arial;\">");

                //content.Append("<a href=\"" + advertiserUrl + "\" style=\"font-weight: bold; font-size: 1.3em; line-height: 1.7em;\">" + Server.HtmlEncode(certificate.AdvertiserName) + "</a>");

                content.Append("<p>");
                content.Append(certificate.Advertiser.Description);
                content.Append("</p>");
                content.Append("<a href=\"" + advertiserUrl + "\" style=\"font-weight: bold; font-size: 1.1em; line-height: 1.5em;\">" + Server.HtmlEncode(certificate.ShortName) + "<a>");
                content.Append("<p> ");
                content.Append(certificate.Description);
                content.Append("</p>");
                content.Append("<p style=\"font-weight: bold;\"> ");
                content.Append("Certificate Value: " + certificate.FaceValue.ToString("$0.00") + "<br />");
                content.Append("Price: <span style=\"color: red;\">" + certificate.DiscountValue.ToString("$0.00") + "</span><br />");
                content.Append("Your Savings: " + certificate.Savings + "<br />");
                content.Append("</p>");
                content.Append("<a href=\"" + advertiserUrl + "\" style=\"font-weight: bold; font-size: 1.1em; line-height: 1.5em;\">BUY NOW</a>");
                content.Append("</div>");
                content.Append("<div style=\"clear: both;\"></div>");


                item.Content = SyndicationContent.CreateHtmlContent(content.ToString());

                items.Add(item);
            }


            SyndicationFeed mainFeed = new SyndicationFeed(Station.SiteNamePlainText, description, new Uri(homePageUrl));

            mainFeed.Description = TextSyndicationContent.CreatePlaintextContent(description);

            mainFeed.Items = items;

            Response.ContentType = "application/rss+xml";

            using (XmlWriter xmlWriter = XmlWriter.Create(Response.OutputStream)) {
                Rss20FeedFormatter rssFeed = new Rss20FeedFormatter(mainFeed);
                rssFeed.WriteTo(xmlWriter);
            }
        }