using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Drawing.Imaging; using System.IO; using System.Data.SqlClient; namespace WebApp2 { public partial class Default : System.Web.UI.Page { protected System.Data.SqlClient.SqlConnection sqlConnectionPicDB; com.harbormist.PictureService websvc = null; protected void Page_Load(object sender, System.EventArgs e) { websvc = new com.harbormist.PictureService(); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.sqlConnectionPicDB = new System.Data.SqlClient.SqlConnection(); this.sqlConnectionPicDB.ConnectionString = "workstation id=TABBY;packet size=4096;" + "user id=SQL2005_229378_harbor_user;" + "data source=\"sql2k502.discountasp.net\";" + "persist security info=True;" + "initial catalog=SQL2005_229378_harbor;" + "password=pal2003mer"; } #endregion protected void ButtonKeywordGet_Click(object sender, System.EventArgs e) { if (this.TextBoxGetKeyword.Text.Trim()!="") { MemoryStream strm = new MemoryStream(); string img = websvc.GetKeywordPicture(TextBoxGetKeyword.Text); if (img!=null) { this.bodyElement.Attributes["background"] = img; this.Label1.Text = "Background picture updated "; } else { this.Label1.Text = "None found with that keyword"; } } else { this.Label1.Text= "Please put a keyword"; } } protected void ButtonRandomGet_Click(object sender, System.EventArgs e) { MemoryStream strm = new MemoryStream(); string img = websvc.GetPicture(); if (img!=null) { // Update background image this.bodyElement.Attributes["background"] = img; this.Label1.Text = "Background picture updated "; } else { this.Label1.Text= "No picture found"; } } protected void ButtonUpload_Click(object sender, System.EventArgs e) { if (this.TextBoxUploadKeyword.Text.Trim()!="" && this.TextBoxUploadURL.Text.Trim()!="") { if (this.TextBoxUploadKeyword.Text.Length>10) { this.Label1.Text="Please use a keyword of 10 chars or less"; } else { int id= websvc.generatePicID(); try { this.sqlConnectionPicDB.Open(); SqlCommand cmd = new SqlCommand ("insert into WebBackgroundImages (pictureid, keyword, url) " + "values (@id, @keyword, @pic)", this.sqlConnectionPicDB); cmd.Parameters.Add("@id", id); cmd.Parameters.Add("@keyword", this.TextBoxUploadKeyword.Text); cmd.Parameters.Add("@pic", this.TextBoxUploadURL.Text); cmd.ExecuteNonQuery(); this.Label1.Text = "Uploaded!"; } finally { this.sqlConnectionPicDB.Close(); } } } else { this.Label1.Text="Please insert a keyword and filename"; } } } // end class } // end namespace