protected void Page_Load(object sender, EventArgs e) { GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); Guid catID = new Guid("b6385b44-1b6d-41ab-81df-d265d363dea7"); var data = db.uspProductsGetbyCat("e4db916e-5427-42d0-8a94-6ced86bedabe").ToArray(); int rows = data.Length; for (int i = 0; i < rows; i++) { Image picture = new Image(); picture.ID = "picture" + i; //picture.Width = 306; //picture.Height = 204; picture.Attributes.Add("class", "productImage"); TableRow row = new TableRow(); TableCell cellOne = new TableCell(); TableCell cellTwo = new TableCell(); string prodID = data[i].ProductID.ToString(); string prodName = data[i].Name; string prodPriceInfo = data[i].PriceInfo; string prodDesc = data[i].Description; picture.ImageUrl = data[i].ImagePath; cellOne.Controls.Add(picture); cellTwo.Text = "<p class=\"content-words\"><b>" + prodName + "</b><br />" + prodPriceInfo + "<br />" + prodDesc + "</p>"; cellTwo.HorizontalAlign = HorizontalAlign.Left; //cellOne.Width = 320; row.Cells.Add(cellOne); row.Cells.Add(cellTwo); Table1.Rows.Add(row); } }
protected void btnProdDelete_Click(object sender, EventArgs e) { Button btn = (Button)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; string prodID = gvProducts.DataKeys[gvr.RowIndex].Values[0].ToString(); GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); db.uspProductsDropSingle(prodID); gvProducts.DataBind(); }
protected void chkbxCategory2_SelectedIndexChanged(object sender, EventArgs e) { prodViewCat = chkbxCategory2.SelectedValue; if (prodViewCat != "" && prodViewCat != "none") { GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); var prodData = db.uspProductsGetbyCat(prodViewCat); gvProducts.DataSource = prodData; gvProducts.DataBind(); } }
protected void btnView4_Click(object sender, EventArgs e) { MultiView1.ActiveViewIndex = 3; plJournal.Visible = false; Calendar1.SelectedDate = DateTime.Now.Date; Calendar1.VisibleDate = DateTime.Now.Date; GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); var newses = db.uspNewsGetAll(); gvNews.DataSource = newses; gvNews.DataBind(); }
private void refreshImgsList() { GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); articleImages.Clear(); var data2 = db.uspNewsPicsGetByArticle(NewsID); foreach (var row in data2) { NewsImage img = new NewsImage(); img.imageID = row.NewsImgID.ToString(); img.fileName = row.Path; articleImages.Add(img); } }
public Stream GetPhoto(string photoId) { GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); Binary binary = db.uspGetAppleImage(photoId).FirstOrDefault().Image; byte[] result = binary.ToArray(); try { return(new MemoryStream(result)); } catch (ArgumentNullException e) { return(null); } }
protected void btnSbt_Click(object sender, EventArgs e) { Panel1.Visible = false; GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); if (TextBox3.Text != null && TextBox3.Text != String.Empty) { string phoneTxt = TextBox3.Text; string phone = (Regex.Replace(phoneTxt, "[^0-9]", "")); db.uspConnectionInsert(TextBox1.Text, TextBox2.Text, phone); } else { db.uspConnectionInsert(TextBox1.Text, TextBox2.Text, null); } Panel2.Visible = true; }
public void save() { GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); if (NewsID == null) { var result = db.uspNewsInsert(Content, newsDate).ToArray(); NewsID = result.FirstOrDefault().NewsID.ToString(); //System.Text.RegularExpressions.Regex.Replace(NewsID, @"\s+", ""); foreach (NewsImage imgInfo in articleImages) { db.uspNewsPicAdd(NewsID, imgInfo.fileName); } } else { db.uspNewsUpdate(NewsID, Content, newsDate); } }
public Article(string NewsID) { GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); var data = db.uspNewsGetSingle(NewsID).FirstOrDefault(); this.NewsID = NewsID; Content = data.NewsContent; newsDate = data.NewsDate; var data2 = db.uspNewsPicsGetByArticle(NewsID); foreach (var row in data2) { NewsImage img = new NewsImage(); img.imageID = row.NewsImgID.ToString(); img.fileName = row.Path; articleImages.Add(img); } }
protected void btnNewsDelete_Click(object sender, EventArgs e) { Button btn = (Button)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; string artId = gvNews.DataKeys[gvr.RowIndex].Values[0].ToString(); GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); try { db.uspNewsAndPicsDelete(artId); } catch (Exception ex) { ListItem li = new ListItem(); li.Text = ex.Message; blNewsErr.Items.Add(li); blNewsErr.Visible = true; } }
protected void btnProdEdit_Click(object sender, EventArgs e) { DataSet images = Methods.GetImages(Server.MapPath("~/Images/Products")); ddlImages.DataSource = images.Tables[0]; ddlImages.DataValueField = "FileName"; ddlImages.DataTextField = "FileName"; ddlImages.DataBind(); plProductsView.Visible = false; plEditProduct.Visible = true; Button btn = (Button)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; string prodID = gvProducts.DataKeys[gvr.RowIndex].Values[0].ToString(); for (int i = 1; i < 100; i++) { ListItem item = new ListItem(); item.Text = i.ToString(); item.Value = i.ToString(); ddlOrderIndex.Items.Add(item); } FileUpload2.Visible = false; ddlImages.Visible = true; imgSample.Visible = true; plUpdatProdSucc.Visible = false; //Response.Write(Methods.GetImages(Server.MapPath("~/Images/Products")).Tables[0].Rows[1][1].ToString()); GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); var data = db.uspProductsGetSingle(prodID).FirstOrDefault(); txtTitle2.Text = data.Name; txtPrice2.Text = data.PriceInfo; txtDesc2.Text = data.Description; lblProdID.Text = data.ProductID.ToString(); ddlOrderIndex.SelectedValue = data.OrderIndex.ToString(); lblTest.Text = "Originally was: " + data.Name; imgSample.ImageUrl = data.ImagePath; chkbxImage.SelectedValue = "Use Existing Photo"; ddlImages.SelectedValue = Path.GetFileName(data.ImagePath); plNewProduct.Visible = false; }
protected void ddlCategory2_SelectedIndexChanged(object sender, EventArgs e) { if (ddlCategory2.SelectedValue != "67a6ec19-a89b-43c9-8b69-a6711673c77e") { chkbxCategory2.Visible = false; prodViewCat = ddlCategory2.SelectedValue; } else { chkbxCategory2.Visible = true; } if (prodViewCat != "" && prodViewCat != "none") { GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); var prodData = db.uspProductsGetbyCat(prodViewCat); gvProducts.DataSource = prodData; gvProducts.DataBind(); } }
protected void SendMail() { // Gmail Address from where you send the mail var fromAddress = "*****@*****.**"; // any address where the email will be sending var toAddress = "*****@*****.**"; //Password of your gmail address const string fromPassword = "******"; // Passing the values and make a email formate to display string subject = YourSubject.Text.ToString(); string body = "From: " + YourName.Text + "\n"; body += "Email: " + YourEmail.Text + "\n"; body += "Subject: " + YourSubject.Text + "\n"; body += "Question: \n" + Comments.Text + "\n"; // smtp settings var smtp = new System.Net.Mail.SmtpClient(); { smtp.Host = "smtp-mail.outlook.com"; smtp.Port = 587; //IMap-MailDefinition.outlook.com=993 smtp.EnableSsl = true; smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; smtp.Credentials = new NetworkCredential(fromAddress, fromPassword); smtp.Timeout = 20000; } // Passing values to smtp object smtp.Send(fromAddress, toAddress, subject, body); if (chkbxOptIntoMail.Checked) { GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); db.uspConnectionInsert(YourName.Text, YourEmail.Text, null); } }
protected void Page_Load(object sender, EventArgs e) { GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); var data = db.uspNewsGetTopSeven().ToArray(); string output = ""; //foreach (var x in data) //{ // string modals = ""; // string content = x.NewsContent; // Article article = new Article(x.NewsID.ToString()); // foreach (NewsImage img in article.articleImages) { // string path = Path.Combine("/Images/News/", img.fileName); // string modal = string.Format("<img id=\"myImg\" src=\"{0}\" width=\"240\" height=\"135\" onclick=\"modalize(this)\">", path); // modals += modal; // } // output += string.Format("{0} <br /> {1}", modals, content); //} //Literal1.Text = output; foreach (var x in data) { Table tbl = new Table(); TableRow row1 = new TableRow(); TableRow row2 = new TableRow(); TableRow dateRow = new TableRow(); TableCell tc = new TableCell(); Article article = new Article(x.NewsID.ToString()); foreach (NewsImage img in article.articleImages) { string path = Path.Combine("/Images/News/", img.fileName); //240x150 string html = string.Format("<img id=\"myImg\" src=\"{0}\" width=\"170\" height=\"115\" onclick=\"modalize(this)\">", path); tc.Text += html; } row1.Cells.Add(tc); TableCell tc2 = new TableCell(); tc2.Text = string.Format("<br /><div class=\"news\">{0}</div><br /><hr>", x.NewsContent); row2.Cells.Add(tc2); TableCell tc3 = new TableCell(); tc3.Text = string.Format("<div class=\"newsP\">Posted on {0}</div><br /><br />", x.NewsDate.ToShortDateString()); dateRow.Cells.Add(tc3); tbl.Rows.Add(dateRow); tbl.Rows.Add(row1); tbl.Rows.Add(row2); //tbl.Width = 900; tbl.Attributes.Add("class", "newsTbl"); plNews.Controls.Add(tbl); } //foreach (var x in data) //{ // GridView tbl = new GridView(); // GridViewRow row1 = new GridViewRow(0, 0,DataControlRowType.DataRow, DataControlRowState.Normal); // GridViewRow row2 = new GridViewRow(1, 1, DataControlRowType.DataRow, DataControlRowState.Normal); // Article article = new Article(x.NewsID.ToString()); // foreach (NewsImage imgInfo in article.articleImages) // { // Image img = new Image(); // img.ImageUrl = Path.Combine("/Images/News/", imgInfo.fileName); // img.Width = 240; // img.Height = 150; // img.Attributes.Add("onclick", "mocalize(this)"); // row1.Controls.Add(img); // } // TextBox txtBox = new TextBox(); // txtBox.Text = x.NewsContent; // row2.Controls.Add(txtBox); // tbl // tbl.Rows.Add(row2); // plNews.Controls.Add(tbl); //} }
protected void btnProdUpdate_Click(object sender, EventArgs e) { bool hasTitle = false; bool validImage = false; lblErr2.Items.Clear(); if (txtTitle2.Text != null && txtTitle2.Text != "") { hasTitle = true; } else { lblErr2.Items.Add("there must be a title."); lblErr2.Visible = true; } if (chkbxImage.SelectedValue == "Use Existing Photo") { if (hasTitle == true) { string path = "~/Images/Products/" + ddlImages.SelectedValue; GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); db.uspProductUpdate(lblProdID.Text, txtTitle2.Text, txtPrice2.Text, txtDesc2.Text, path, Convert.ToInt32(ddlOrderIndex.SelectedValue)); plEditProduct.Visible = false; plUpdatProdSucc.Visible = true; } } if (chkbxImage.SelectedValue == "Upload New Photo") { if (FileUpload2.HasFile) { if (!Methods.isPictureFile(FileUpload2.FileName)) { validImage = false; lblErr2.Items.Add("Image file must be JPEG."); lblErr2.Visible = true; } else { validImage = true; } } else { validImage = true; } } if (hasTitle && validImage) { string fileName = FileUpload2.FileName; string tempFileName = fileName; string path = null; int somnum = 0; while (Methods.fileExists(Server.MapPath("~/Images/Products/"), tempFileName)) { tempFileName = "(" + somnum + ")" + fileName; somnum++; } try { GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); FileUpload2.PostedFile.SaveAs(Server.MapPath("~/Images/Products/") + tempFileName); path = "~/Images/Products/" + tempFileName; // If atleast a name, category, and file was given, and the file succesfully got saved. Upload all of it to the database. db.uspProductUpdate(lblProdID.Text, txtTitle2.Text, txtPrice2.Text, txtDesc2.Text, path, Convert.ToInt32(ddlOrderIndex.SelectedValue)); plEditProduct.Visible = false; plUpdatProdSucc.Visible = true; } catch (Exception ex) { lblErr2.Visible = true; lblErr2.Items.Add(ex.Message); } } }
// Uploads the new product form into the database. protected void sbtProduct_Click(object sender, EventArgs e) { // New product form variables. GoodEatsFarmDataContext db = new GoodEatsFarmDataContext(); string title = txtTitle.Text; string price = txtPrice.Text; string description = txtDesc.Text; string categoryID = "none"; HttpPostedFile picture = FileUpload1.PostedFile; string fileName = picture.FileName; string tempFileName = fileName; string path = null; // Reset form validation errors. blErrors.Visible = false; blErrors.Items.Clear(); // Server-side form validation variables. bool hasName = false; bool hasCategory = false; bool isValidImgFile = false; bool fileGiven = false; // If "Fruits" category selected, display fruit radio buttons. if (ddlCategory.SelectedValue == "67a6ec19-a89b-43c9-8b69-a6711673c77e") { categoryID = chkbxCategory.SelectedValue; } else { categoryID = ddlCategory.SelectedValue; } // If product name is not given, display error. if (txtTitle.Text == "" || txtTitle.Text == null) { hasName = false; blErrors.Visible = true; blErrors.Items.Add("You must give a product name."); } else { hasName = true; } // If no category is selected, display error. if (categoryID == "none" || categoryID == "" || categoryID == null) { hasCategory = false; blErrors.Visible = true; blErrors.Items.Add("A category must be selected."); } else { hasCategory = true; } // If file given and if file is valid JPEG. if (FileUpload1.HasFile) { fileGiven = true; if (Methods.isPictureFile(fileName)) { isValidImgFile = true; } } if (fileGiven == true && isValidImgFile == false) { blErrors.Visible = true; blErrors.Items.Add("The file you chose is not a valid file type. Must be a JPEG."); } /* * If there is a product name and category, submit form. * If no file is given, the path field in db is set "null". * If no description or price is given, the fields are set "" in db. */ if (hasName && hasCategory) { if (fileGiven) { if (isValidImgFile) { int somnum = 0; while (Methods.fileExists(Server.MapPath("~/Images/Products/"), tempFileName)) { tempFileName = "(" + somnum + ")" + fileName; somnum++; } try { picture.SaveAs(Server.MapPath("~/Images/Products/") + tempFileName); path = "~/Images/Products/" + tempFileName; // If atleast a name, category, and file was given, and the file succesfully got saved. Upload all of it to the database. db.uspProductInsert(title, price, description, categoryID, path); plNewProduct.Visible = false; plNewProdSuccess.Visible = true; } catch (Exception ex) { blErrors.Visible = true; blErrors.Items.Add(ex.Message); } } } // If only Product Name and Category given, submit them to database with null image path and empty string price and description. else { db.uspProductInsert(title, price, description, categoryID, path); plNewProduct.Visible = false; plNewProdSuccess.Visible = true; } } gvProducts.DataBind(); }