murtaza1234 -2 Newbie Poster

i have a database table named AffiliateBanners_description having fields Image_id,Image_description,Image_Url,Width,Heigth.I want to replace arraylist in my code below and want to do it from this table from database.Please do help me its very urgent.


----------------------------------------------

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Collections.Specialized;
using DollarDays;

public partial class affiliateSignup : System.Web.UI.Page {

	#region Affiliate Banner Structure
	struct AffiliateBanner {
		string title;
		string url;
		int width;
		int height;

		public AffiliateBanner(string _title, string _url, int _width, int _height) {
			title = _title;
			url = _url;
			width = _width;
			height = _height;
		}

		public string Title {
			get { return title; }
			set { title = value; }
		}

		public string Url {
			get { return url; }
			set { url = value; }
		}

		public int Width {
			get { return width; }
			set { width = value; }
		}

		public int Height {
			get { return height; }
			set { height = value; }
		}
	}
	#endregion

	#region Members
	protected DollarDays.Site site;
	protected DollarDays.CleanConversions oFunc = null;
	protected DollarDays.Datasets.Countries countries = null;
	DollarDays.DBTool dbTool;
	int affiliateId = 0;
	protected string selectedcountry = "";
	protected string bannerurl = "";
	protected string adtype = "";
	protected bool affExisting = false;	
#endregion

	protected void Page_Load(object sender, EventArgs e) {
		try {
			oFunc = DollarDays.CleanConversions.Instance;
			dbTool = DollarDays.DBTool.Instance;
			site = DollarDays.Site.Instance;
			countries = DollarDays.Datasets.Countries.Instance;

			selectedcountry = oFunc.NoNull(Request.Form["txtCountry"]);
			if (selectedcountry.Equals("")) { selectedcountry = "USA"; }
			bannerurl = oFunc.NoNull(Request.Form["rdBanner"]);
			adtype = oFunc.NoNull(Request.Form["rdShowType"]);
			affExisting = oFunc.NoNull(Request.Form["rdAffiliateOpt"]).Contains("1");  
			StringBuilder bannermenu = new StringBuilder();
			int bnum = 0;
			foreach (AffiliateBanner ab in setAffiliateBanner()) {
				bannermenu.Append("<tr>")
					.Append("<td class=\"vm\"><label for=\"banner").Append(bnum).Append("\"><input type=\"radio\" name=\"rdBanner\" value=\"").Append(oFunc.HTMLEnc(ab.Url)).Append("\" id=\"banner").Append(bnum).Append("\" ").Append(oFunc.CheckedTag(bannerurl.Equals(ab.Url))).Append(" />").Append(oFunc.HTMLEnc(ab.Title)).Append("</label></td>")
					.Append("<td><img src=\"").Append(ab.Url).Append("\" alt=\"").Append(oFunc.HTMLEnc(ab.Title)).Append("\" width=\"").Append(ab.Width).Append("\" height=\"").Append(ab.Height).Append("\" /></td>")
					.Append("</tr>\n");
				bnum++;
			}
			if (bannermenu.Length > 0) {
				bannermenu.Insert(0, "<table border=\"1\" class=\"content\" cellspacing=\"0\">\n<tr><td class=\"bd ctr lrgtxt\">Size</td><td class=\"bd ctr lrgtxt\">Banner</td></tr>\n").Append("</table>");
				litBanner.Text = bannermenu.ToString();
			}

		}
		catch (Exception ex) {
			litMessage.Text = "Error " + ex.Message;
		}
	}

	protected void rptBanner_ItemDataBound(object sender, RepeaterItemEventArgs e) {
		if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) {
			RadioButton rdBannerType = (RadioButton)e.Item.FindControl("rdBannerType");
			rdBannerType.Attributes.Add("onclick", "SetUniqueRadioButton('ctl.*\\\\$rptBanner\\\\$ctl.*\\\\$optbannertype',this)");
		}
	}

	private ArrayList setAffiliateBanner() {
		ArrayList banners = new ArrayList();
		banners.Add(new AffiliateBanner("135 x 31, 3KB", "/icons/adbanners/DD_135x31_a.gif", 135, 31));
		banners.Add(new AffiliateBanner("161 x 37, 3KB", "/icons/adbanners/DD_161x37_a.gif", 161, 37));
		banners.Add(new AffiliateBanner("121 x 28, 2KB", "/icons/adbanners/DD_121x28_a.gif", 121, 28));
		banners.Add(new AffiliateBanner("88 x 31, 2KB", "/icons/adbanners/DD_88x31_a.gif", 88, 31));
		banners.Add(new AffiliateBanner("125 x 100, 4KB", "/icons/adbanners/DD_125x100_a.gif", 125, 100));
		banners.Add(new AffiliateBanner("358 x 83, 5KB", "/icons/adbanners/DD_358x83.gif", 358, 83));
		banners.Add(new AffiliateBanner("145 x 100, 3KB", "/icons/adbanners/DD_145x100.gif", 145, 100));
		banners.Add(new AffiliateBanner("129 x 43, 2KB", "/icons/adbanners/DD_129x43_a.gif", 129, 43));
		banners.Add(new AffiliateBanner("468 x 60, 8KB", "/icons/adbanners/DD_468x60_a.gif", 468, 60));
		banners.Add(new AffiliateBanner("261 x 60, 3KB", "/icons/adbanners/DD_261x60.gif", 261, 60));
		banners.Add(new AffiliateBanner("468 x 60, 6KB", "/icons/adbanners/DD_468x60_stat.gif", 468, 60));
		banners.Add(new AffiliateBanner("135 X 31, 1KB", "/icons/adbanners/DD_135x31.gif", 135, 31));
		banners.Add(new AffiliateBanner("125 X 100, 2KB", "/icons/adbanners/DD_125x100.gif", 125, 100));
		banners.Add(new AffiliateBanner("121 X 28, 1KB", "/icons/adbanners/dd_121x28.gif", 121, 28));
		banners.Add(new AffiliateBanner("161 X 37, 2KB", "/icons/adbanners/DD_161x37.gif", 161, 37));
		banners.Add(new AffiliateBanner("261 X 60, 3KB", "/icons/adbanners/dd_261x60_v2.gif", 261, 60));
		banners.Add(new AffiliateBanner("468 X 60 IAB Standard Full Banner, 3KB", "/icons/adbanners/dd_468x60_v2.gif", 468, 60));
		banners.Add(new AffiliateBanner("468 X 60 IAB Standard Full Banner, 15KB Animation", "/icons/adbanners/dd_468x60_v3.gif", 468, 60));
		banners.Add(new AffiliateBanner("358 X 83, 6KB", "/icons/adbanners/dd_358x83_v2.gif", 358, 83));
		banners.Add(new AffiliateBanner("88 x 31 IAB Standard Micro Bar, 2KB", "/icons/adbanners/dd_88x31.gif", 88, 31));
		banners.Add(new AffiliateBanner("145 x 100, 4KB", "/icons/adbanners/dd_145x100_v2.gif", 145, 100));
		banners.Add(new AffiliateBanner("129 x 43, 3KB", "/icons/adbanners/dd_129x43_v2.gif", 129, 43));
		banners.Add(new AffiliateBanner("129 x 43, 3KB", "/icons/adbanners/dd_129x43_v2.gif", 129, 43));
		banners.Add(new AffiliateBanner("480 x 60 , 14KB", "/icons/adbanners/plat_468x60.jpg", 480, 60));
		banners.Add(new AffiliateBanner("160 x 600 , 34KB", "/icons/adbanners/plat_160x600.jpg", 160, 600));
		banners.Add(new AffiliateBanner("120 x 600 , 25KB", "/icons/adbanners/plat_120x600.jpg", 120, 600));
		banners.Add(new AffiliateBanner("120 x 120 , 25KB", "/icons/adbanners/plat_120x120.jpg", 120, 120));
		banners.Add(new AffiliateBanner("480 x 60 , 11KB", "/icons/adbanners/ddi_wedding_468x60.gif", 480, 60));
		banners.Add(new AffiliateBanner("160 x 600 , 35KB", "/icons/adbanners/ddi_wedding_160x600.gif", 160, 600));
		banners.Add(new AffiliateBanner("125 x 125 , 11KB", "/icons/adbanners/ddi_wedding_125x125.gif", 125, 125));
		banners.Add(new AffiliateBanner("120 x 600 , 28KB", "/icons/adbanners/ddi_wedding_120x600.gif", 120, 600));
		banners.Add(new AffiliateBanner("468 x 60 , 12KB", "/icons/adbanners/ddi_obama_468x60.gif", 468, 60));
		banners.Add(new AffiliateBanner("160 x 600 , 38KB", "/icons/adbanners/ddi_obama_160x600.gif", 160, 600));
		banners.Add(new AffiliateBanner("125 x 125 , 7KB", "/icons/adbanners/ddi_obama_125x125.gif", 125, 125));
		banners.Add(new AffiliateBanner("120 x 600 , 23KB", "/icons/adbanners/ddi_obama_120x600.gif", 120, 600));
		banners.Add(new AffiliateBanner("468 x 60 , 12KB", "/icons/adbanners/ddi_ff_468x60.gif", 468, 60));
		banners.Add(new AffiliateBanner("160 x 600 , 27KB", "/icons/adbanners/ddi_ff_160x600.gif", 160, 600));
		banners.Add(new AffiliateBanner("125 x 125 , 6KB", "/icons/adbanners/ddi_ff_125x125.gif", 125, 125));
		banners.Add(new AffiliateBanner("120 x 600 , 20KB", "/icons/adbanners/ddi_ff_120x600.gif", 120, 600));
		banners.Add(new AffiliateBanner("468 x 60 , 11KB", "/icons/adbanners/ddi_b2s_468x60.gif", 468, 60));
		banners.Add(new AffiliateBanner("160 x 600 , 29KB", "/icons/adbanners/ddi_b2s_160x600.gif", 160, 600));
		banners.Add(new AffiliateBanner("125 x 125 , 13KB", "/icons/adbanners/ddi_b2s_125x125.gif", 125, 125));
		banners.Add(new AffiliateBanner("120 x 600 , 21KB", "/icons/adbanners/ddi_b2s_120x600.gif", 120, 600));
		banners.Add(new AffiliateBanner("125 x 125 , 6KB", "/icons/adbanners/ddi_flu_125x125.gif", 125, 125));
		banners.Add(new AffiliateBanner("160 x 600 , 38KB", "/icons/adbanners/ddi_flu_160x600.gif", 160, 600));
		banners.Add(new AffiliateBanner("486 x 60 , 12KB", "/icons/adbanners/ddi_flu_468x60.gif", 486, 60));
		banners.Add(new AffiliateBanner("120 x 600 , 25KB", "/icons/adbanners/ddi_flu_120x600.gif", 120, 600));
		banners.Add(new AffiliateBanner("160 x 600 , 33KB", "/icons/adbanners/ddi_homedecor_160x600.gif", 160, 600));
		banners.Add(new AffiliateBanner("125 x 125 , 7KB", "/icons/adbanners/ddi_homedecor_125x125.gif", 125, 125));
		banners.Add(new AffiliateBanner("486 x 60 , 11KB", "/icons/adbanners/ddi_homedecor_468x60.gif", 486, 60));
		banners.Add(new AffiliateBanner("120 x 600 , 21KB", "/icons/adbanners/ddi_homedecor_120x600.gif", 120, 600));
		banners.Add(new AffiliateBanner("125 x 125 , 7KB", "/icons/adbanners/ddi_jewelry_125x125.gif", 125, 125));
		banners.Add(new AffiliateBanner("160 x 600 , 36KB", "/icons/adbanners/ddi_jewelry_160x600.gif", 160, 600));
		banners.Add(new AffiliateBanner("486 x 160 , 12KB", "/icons/adbanners/ddi_jewelry_468x60.gif", 486, 160));
		banners.Add(new AffiliateBanner("120 x 600 , 22KB", "/icons/adbanners/ddi_jewelry_120x600.gif", 120, 600));
		return banners;
	}

	private Validate Create() {
		try {
			Validate validate = validateData();
			if (validate.Valid) {
				validate.Valid = false;
				string strSql = "set nocount on;insert into dbo.salesrep(fname, lname, password, phone, fax, active, lastupdate, email,addr1, addr2, city, state, zip, country,website) " +
					"values(" + oFunc.SQLText(txtFName.Text.Trim()) + "," + oFunc.SQLText(txtLName.Text.Trim()) + "," + oFunc.SQLText(txtPassword.Text.Trim()) + "," + oFunc.SQLText(txtPhone.Text.Trim()) + "," +
					oFunc.SQLText(txtFax.Text.Trim()) + ",'Y',getdate()," + oFunc.SQLText(txtEmail.Text.Trim()) + "," + oFunc.SQLText(txtAddress.Text.Trim()) + "," + oFunc.SQLText(txtAddress2.Text.Trim()) + "," +
					oFunc.SQLText(txtCity.Text.Trim()) + "," + oFunc.SQLText(txtState.Text.Trim()) + "," + oFunc.SQLText(txtZip.Text.Trim()) + "," + oFunc.SQLText(selectedcountry) + "," + oFunc.SQLText(txtUrl.Text.Trim()) + ");select scope_identity() as NewID;";
				DataTable dt = dbTool.DBDataTable(strSql, "Inserting new affiliate");
				if (dt != null) {
					DataTableReader dtr = dt.CreateDataReader();
					if (dtr.Read()) {
						affiliateId = oFunc.CInt(dtr["NewID"]);
						validate.Valid = !affiliateId.Equals(0);
					}
				}
			}
			return validate;
		}
		catch { throw; }
	}

	private Validate validateData() {
		Validate validate = new Validate();
		validate.Valid = true;
		if (txtFName.Text.Trim().Equals("")) {
			validate.Valid = false;
			validate.ErrMessage += "<div>First name is required.</div>";
		}
		if (txtLName.Text.Trim().Equals("")) {
			validate.Valid = false;
			validate.ErrMessage += "<div>Last name is required.</div>";
		}
		if (txtEmail.Text.Trim().Equals("")) {
			validate.Valid = false;
			validate.ErrMessage += "<div>Email is required.</div>";
		}
		if (!oFunc.ValidEmail(txtEmail.Text)) {
			validate.Valid = false;
			validate.ErrMessage += "<div>Email is not valid.</div>";
		}
		if (txtPassword.Text.Trim().Equals("")) {
			validate.Valid = false;
			validate.ErrMessage += "<div>Password is required.</div>";
		}
		if (!oFunc.IsAlphanumeric(txtPassword.Text)) {
			validate.Valid = false;
			validate.ErrMessage += "<div>Password is not valid, only letters and numbers are allowed.</div>";
		}
		if (txtPassword.Text.Trim().Length < 3) {
			validate.Valid = false;
			validate.ErrMessage += "<div>Password is not valid, at least 4 characters long.</div>";
		}
		if (txtPhone.Text.Trim().Length < 10) {
			validate.Valid = false;
			validate.ErrMessage += "<div>Phone is required and must include area code and/or international dialing codes.</div>";
		}
		if (txtUrl.Text.Trim().Length < 4 || !txtUrl.Text.Contains(".")) {
			validate.Valid = false;
			validate.ErrMessage += "<div>URL is required.</div>";
		}
		if (txtAddress.Text.Trim().Equals("")) {
			validate.Valid = false;
			validate.ErrMessage += "<div>Address is required.</div>";
		}
		if (txtCity.Text.Trim().Equals("")) {
			validate.Valid = false;
			validate.ErrMessage += "<div>City is required.</div>";
		}
		if (txtState.Text.Trim().Equals("") && (selectedcountry.Equals("USA") || selectedcountry.Equals("CAN"))) {
			validate.Valid = false;
			validate.ErrMessage += "<div>State or province is required.</div>";
		}
		if (txtZip.Text.Equals("") && selectedcountry.Equals("USA")) {
			validate.Valid = false;
			validate.ErrMessage += "<div>Zip is required for USA.</div>";
		}
		if (selectedcountry.Equals("")) {
			validate.Valid = false;
			validate.ErrMessage += "<div>Country is required.</div>";
		}
		if (adtype.Equals("")) {
			validate.Valid = false;
			validate.ErrMessage += "<div>Select &quot;Show Text&quot; or &quot;Show Banner&quot;.</div>";
		}
		if (adtype.Equals("text") && txtBannerText.Text.Equals("")) {
			validate.Valid = false;
			validate.ErrMessage += "<div>Enter text to show.</div>";
		}
		if (adtype.Equals("banner") && bannerurl.Equals("")) {
			validate.Valid = false;
			validate.ErrMessage += "<div>Select Banner.</div>";
		}
		return validate;
	}

	private bool SendEmail(int affiliateId) {
		StringBuilder body = new StringBuilder();
		body.Append("<html><body>")
			.Append("<div><img src=\"http://www.dollardays.com/icons/dollardays_wholesale_sun_logo.gif\"></div>")
			.Append("<div>Dear ").Append(txtFName.Text + " " + txtLName.Text)
			.Append("</div><br>\n")
			.Append("Thanks for joining our affiliate program. You are affiliate # ").Append(affiliateId).Append(".<br><br>\n")
			.Append("Copy and paste following HTML code snippets into your website:<br><br>\n");
		if (adtype.Equals("text")) {
			body.Append(oFunc.HTMLEnc("<a href=\"http://www.dollardays.com/?affilid=" + affiliateId.ToString() + "\">" + txtBannerText.Text + "</a>"));
		} else if (adtype.Equals("banner")) {
			body.Append(oFunc.HTMLEnc("<a href=\"http://www.dollardays.com/?affilid=" + affiliateId.ToString() + "\"><img src=\"http://www.dollardays.com" + bannerurl + "\" border=0 alt=\"DollarDays\"></a>"));
		}
		body.Append("<br><br>\n")
			.Append("To see everyone signing up through your site and everyone buying,here is a URL you can visit at anytime:<br>")
			.Append("<a  href=\"http://dollardays.com/affiliatestats.asp?affilid=" + affiliateId.ToString() + "&amp;pw=" + txtPassword.Text + "\">http://dollardays.com/affiliatestats.asp?affilid=" + affiliateId.ToString() + "&amp;pw=" + txtPassword.Text + "</a>")
			.Append("<br><br>\n")
			.Append("I also highly recommend you buying copies of my new book which just came out last fall <em>\"The Secrets of Retailing...How To Beat Walmart\"</em>.\n")
			.Append("You can either reserve the book on Amazon or on our site at <a href=\"http://www.dollardays.com/\">www.dollardays.com</a> (at a discount of course). Here is a link to buy your copies now:\n")
			.Append("<div><a href=\"http://www.dollardays.com/promo.asp?ex=secrets_of_retailing\">www.dollardays.com/promo.asp?ex=secrets_of_retailing</a></div><div>It is the perfect book to share with your customers, because the\n")
			.Append("book is a gut check for current businesses to make sure they have all bases covered. Also, it is a great read for you and your staff because it gives an insight into what a business is thinking when they are sitting on the other side of the table or on the other end of a phone call.</div>\n")
			.Append("<br><br>\n")
			.Append("DollarDays International, LLC<br>7575 E. Redfield Rd., Suite 201<br>Scottsdale, AZ 85260")
			.Append("</body></html>");
		if (affiliateId > 0) {
			EmailUtility em = new EmailUtility();
			em.From = "affiliates@dollardays.com";
			em.To = txtEmail.Text;
			//em.To = "kashif@ollardays.com";
			em.CC = "mark@dollardays.com,kashif@dollardays.com";
			em.SendAsHtml = true;
			em.Subject = "Affiliate Confirmation";
			em.MsgText = body.ToString();
			return em.SendEmail();
		} else {
			return false;
		}
	}

	protected void btnSubmit_Click(object sender, EventArgs e) {
		Validate validate = new Validate();
		if (!affExisting) {//New
			validate = Create();
			if (validate.Valid) {
				if (affiliateId > 0) {
					bool send = SendEmail(affiliateId);
					plhForms.Visible = false;
					plhSuccessNew.Visible = true;
				}
			} else {
				litMessage.Text = "<div class=\"hdln lrgtxt\">" + validate.ErrMessage + "</div>";
			}
		} else if (affExisting) {
			int affiliateId = oFunc.CInt(txtAffiliateId.Text);
			if (affiliateId > 0) {
				validate.Valid = true; 
				if (adtype.Equals("")) {
					validate.Valid = false;
					validate.ErrMessage += "<div>Select &quot;Show Text&quot; or &quot;Show Banner&quot;.</div>";
				}
				if (adtype.Equals("text") && txtBannerText.Text.Equals("")) {
					validate.Valid = false;
					validate.ErrMessage += "<div>Enter text to show.</div>";
				}
				if (adtype.Equals("banner") && bannerurl.Equals("")) {
					validate.Valid = false;
					validate.ErrMessage += "<div>Select Banner.</div>";
				}
				if (validate.Valid) {
					string strSql = "select * from salesrep with (NOLOCK) where salesrepid=" + affiliateId;
					DataTable dt = dbTool.DBDataTable(strSql, "Retrieving existing affiliate");
					if (dt != null) {
						DataTableReader dtr = dt.CreateDataReader();
						if (dtr.Read()) {
							affiliateId = oFunc.CInt(dtr["salesrepid"]);
							txtFName.Text = oFunc.NoNull(dtr["fname"]);
							txtLName.Text = oFunc.NoNull(dtr["lname"]);
							txtPassword.Text = oFunc.NoNull(dtr["password"]);
							txtEmail.Text = oFunc.NoNull(dtr["email"]); 
							if (affiliateId > 0) {
								bool send = SendEmail(affiliateId);
								plhForms.Visible = false;
								plhSuccessUpdate.Visible = true;
							}
						} else {
							litMessage.Text = "<div class=\"hdln lrgtxt\">Not a valid Affiliate Id.</div>";
						}
					}
				} else {
					litMessage.Text = "<div class=\"hdln lrgtxt\">" + validate.ErrMessage + "</div>";
				}
			} else {
				litMessage.Text = "<div class=\"hdln lrgtxt\">Affiliate Id is required.</div>";
			}
		}
	}
}