protected void cmdSaveAd_Click(object sender, EventArgs e) { SiteAdsTableAdapter tbaAds = new SiteAdsTableAdapter(); string adID = Request.QueryString["itemID"]; int newID; //If there is an ad ID specified, save a new ad record. Otherwise, update the specified ad. try { if (adID != null) { tbaAds.Update("AndrewComeau.com", textIntroText.Text, textTextLink.Text, textImageLink.Text, textAltLink.Text, textProdDesc.Text, textManuf.Text, chkProdActive.Checked, DateTime.Today, int.Parse(adID)); } else { tbaAds.Insert("AndrewComeau.com", textIntroText.Text, textTextLink.Text, textImageLink.Text, textAltLink.Text, textProdDesc.Text, textManuf.Text, chkProdActive.Checked, out newID); Response.Redirect("adminpanel.aspx?catID=ads&itemID=" + newID.ToString(), false); } } catch (Exception ex) { General.ErrorHandler(ex, "Error thrown by adminpanel.aspx.cmdSaveAd_Click()"); } }
public static AppData.SiteAdsRow GetRandomAd(String PageName) { SiteAdsTableAdapter tbaAds = new SiteAdsTableAdapter(); AppData.SiteAdsDataTable dtAds = new AppData.SiteAdsDataTable(); AppData.SiteAdsRow result; Random numberGen = new Random(); int rowCount; // If no ads specific to the page were found, get all active. if (dtAds.Rows.Count == 0) { dtAds = tbaAds.GetActiveAds(); } // Return a random row. if (dtAds.Rows.Count > 1) { rowCount = dtAds.Rows.Count; result = (AppData.SiteAdsRow)dtAds.Rows[numberGen.Next(rowCount)]; } else { result = (AppData.SiteAdsRow)dtAds.Rows[0]; } return(result); }
protected void LoadAd(int adID) { SiteAdsTableAdapter tbaAds = new SiteAdsTableAdapter(); // Load the ad record and fill in the appropriate fields. try { AppData.SiteAdsRow rwAd = (AppData.SiteAdsRow)tbaAds.GetDataByID(adID).Rows[0]; if (!rwAd.IsDescriptionNull()) { textProdDesc.Text = rwAd.Description; } textManuf.Text = rwAd.Author; textTextLink.Text = rwAd.TextLink.ToString(); textImageLink.Text = rwAd.ImageLink.ToString(); if (!rwAd.IsAltLinkNull()) { textAltLink.Text = rwAd.AltLink.ToString(); } if (!rwAd.IsIntroTextNull()) { textIntroText.Text = rwAd.IntroText; } chkProdActive.Checked = rwAd.Active; } catch { throw; } }