protected void dg_UpdateCommand(object source, DataGridCommandEventArgs e) { try { string strID = dg.DataKeys[e.Item.ItemIndex].ToString(); int nStrID = Convert.ToInt32(strID); TextBox txtItem = e.Item.FindControl("txtMPSubItemE") as TextBox; CheckBox chkBull = e.Item.FindControl("chkMPIsSubItemBulletedE") as CheckBox; if (txtItem != null && chkBull != null) { var db = new Pizza15Model(); tblMainPageSubItem SubPageItem = db.tblMainPageSubItems.FirstOrDefault(x => x.SubItemID.Equals(nStrID)); if (SubPageItem != null) { SubPageItem.SubItem = txtItem.Text; SubPageItem.IsSubItemBulleted = chkBull.Checked; db.SaveChanges(); } } else { lblError.Text = "Error finding the MainPageSubItem"; } dg.EditItemIndex = -1; dg.ShowFooter = true; Session["SubPageItem"] = null; GetData(); } catch (Exception ex) { lblError.Text = ex.Message; } }
protected void dg_UpdateCommand(object source, DataGridCommandEventArgs e) { try { string strID = dg.DataKeys[e.Item.ItemIndex].ToString(); int nStrID = Convert.ToInt32(strID); TextBox txtNewsE = e.Item.FindControl("txtNewsE") as TextBox; CheckBox chkActiveE = e.Item.FindControl("chkActiveE") as CheckBox; if (txtNewsE != null && chkActiveE != null) { var db = new Pizza15Model(); tblNewsEvent Events = db.tblNewsEvents.FirstOrDefault(x => x.NewsID.Equals(nStrID)); if (Events != null) { Events.News = txtNewsE.Text; Events.Active = Convert.ToBoolean(chkActiveE.Checked); db.SaveChanges(); } } else { lblError.Text = "Error finding the News & Event"; } dg.EditItemIndex = -1; dg.ShowFooter = true; Session["Event"] = null; GetData(); } catch (Exception ex) { lblError.Text = ex.Message; } }
protected void dg_UpdateCommand(object source, DataGridCommandEventArgs e) { try { string strID = dg.DataKeys[e.Item.ItemIndex].ToString(); int nStrID = Convert.ToInt32(strID); TextBox txtDay = e.Item.FindControl("txtDayE") as TextBox; TextBox txtSpecial = e.Item.FindControl("txtSpecialE") as TextBox; if (txtDay != null && txtSpecial != null) { var db = new Pizza15Model(); tblDailySpecial UpdateDailySpecial = db.tblDailySpecials.FirstOrDefault(x => x.DailyID.Equals(nStrID)); if (UpdateDailySpecial != null) { UpdateDailySpecial.Day = txtDay.Text.Trim(); UpdateDailySpecial.Special = txtSpecial.Text.Trim(); db.SaveChanges(); } } else { lblError.Text = "Error finding the Daily Special"; } dg.EditItemIndex = -1; dg.ShowFooter = true; Session["DailySpecial"] = null; GetData(); } catch (Exception ex) { lblError.Text = ex.Message; } }
private void SwapIndex(int nNewsID1, int nIndex1, int nNewsID2, int nIndex2) { try { var db = new Pizza15Model(); tblNewsEvent Events = db.tblNewsEvents.Single(x => x.NewsID.Equals(nNewsID1)); if (Events != null) { Events.Indx = nIndex2; db.SaveChanges(); } tblNewsEvent NewsEvents = db.tblNewsEvents.Single(x => x.NewsID.Equals(nNewsID2)); if (NewsEvents != null) { NewsEvents.Indx = nIndex1; db.SaveChanges(); } } catch (Exception ex) { throw ex; } }
protected void OuterRptRandomStuff_OnItemDataBound(object sender, RepeaterItemEventArgs e) { try { var db = new Pizza15Model(); RepeaterItem item = e.Item; if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem)) { HiddenField id = item.FindControl("HiddenRandomStuff") as HiddenField; int subcat = Convert.ToInt32(id.Value); Repeater innerRepRandomStuff = (Repeater)item.FindControl("innerRepRandomStuff"); var RandomStuffImages = (from q in db.tbl_Images where q.CategoryID == 6 && q.SubCategoryID == subcat select new { q.ImageUrl }).ToList(); innerRepRandomStuff.DataSource = RandomStuffImages; innerRepRandomStuff.DataBind(); } } catch (Exception ex) { throw ex; } }
protected void btnCategoryupdate_Click(object sender, EventArgs e) { var db = new Pizza15Model(); var extsubcatgname = (from q in db.tbl_ImageCategory where q.CategoryID == 19 select new { q }).FirstOrDefault(); if (TxtCategory.Text.Trim() != null) { extsubcatgname.q.SubCategoryName = TxtCategory.Text; } db.SaveChanges(); lblerror.Text = " The new name been updated successfully"; lblerror.ForeColor = System.Drawing.Color.ForestGreen; lblCategory.Visible = false; TxtCategory.Visible = false; btnCategoryupdate.Visible = false; btnCategoryCancel.Visible = false; lnkupdtCategory.Visible = true; }
protected void AddFBcustdetails() { tbl_FBcustdet addFBcustdtls = new tbl_FBcustdet(); Pizza15Model db = new Pizza15Model(); var excustdtls = (from q in db.tbl_FBcustdet where q.CustemailID == Lblemail.Text.Trim() select new { q.CustemailID }).ToList(); if (excustdtls.Count == 0) { addFBcustdtls.CustemailID = Lblemail.Text.Trim(); addFBcustdtls.CustName = Lblname.Text.Trim(); addFBcustdtls.Custgend = Lblgend.Text.Trim(); addFBcustdtls.Custcreats = DateTime.Now; addFBcustdtls.CustFBID = LblFBid.Text.Trim(); db.tbl_FBcustdet.Add(addFBcustdtls); db.SaveChanges(); } else { Response.Redirect("Default.aspx", false); } }
private void SwapIndex(int nID1, int nIndex1, int nID2, int nIndex2) { try { var db = new Pizza15Model(); tblMainPageSubItem SubPage = db.tblMainPageSubItems.Single(x => x.SubItemID.Equals(nID1)); if (SubPage != null) { SubPage.Indx = nIndex2; db.SaveChanges(); } tblMainPageSubItem SubPageItem = db.tblMainPageSubItems.Single(x => x.SubItemID.Equals(nID2)); if (SubPageItem != null) { SubPageItem.Indx = nIndex1; db.SaveChanges(); } } catch (Exception ex) { throw ex; } }
private void SwapIndex(int nPizzaID1, int nIndex1, int nPizzaID2, int nIndex2) { try { var db = new Pizza15Model(); tbl_pizzaspecials PizzaSpecial = db.tbl_pizzaspecials.Single(x => x.PizzaSpecID.Equals(nPizzaID1)); if (PizzaSpecial != null) { PizzaSpecial.ItemId = nIndex2; db.SaveChanges(); } tbl_pizzaspecials Pizzaspec = db.tbl_pizzaspecials.Single(x => x.PizzaSpecID.Equals(nPizzaID2)); if (Pizzaspec != null) { Pizzaspec.ItemId = nIndex1; db.SaveChanges(); } } catch (Exception ex) { throw ex; } }
protected void btnSubCategorySave_Click(object sender, EventArgs e) { try { var db = new Pizza15Model(); var imgSubCategory = new tbl_ImageCategory(); var maxid = (from q in db.tbl_ImageCategory select new { q.ID }).ToList(); if (maxid.Count != 0) { imgSubCategory.ID = maxid.Max(x => x.ID) + 1; } imgSubCategory.CategoryID = Convert.ToInt32(ddlCategory.SelectedValue); var maxSubCategoryid = (from q in db.tbl_ImageCategory where q.CategoryID == imgSubCategory.CategoryID select new { q.SubCategoryID }).ToList(); if (maxSubCategoryid.Count != 0) { imgSubCategory.SubCategoryID = maxSubCategoryid.Max(x => x.SubCategoryID) + 1; } imgSubCategory.CategoryName = ddlCategory.SelectedItem.Text; imgSubCategory.SubCategoryName = TxtNewSubcategory.Text; var DuplicateSubCat = (from q in db.tbl_ImageCategory where q.CategoryName == imgSubCategory.CategoryName && q.SubCategoryName == imgSubCategory.SubCategoryName select new { }).Count(); if (DuplicateSubCat == 0) { if (ddlCategory.SelectedValue != "0") { db.tbl_ImageCategory.Add(imgSubCategory); db.SaveChanges(); lblerror.Text = "New Sub Category Created Successfully"; lblerror.ForeColor = System.Drawing.Color.ForestGreen; lblSelectCategory.Visible = false; lblnewSubCategory.Visible = false; ddlCategory.Visible = false; TxtNewSubcategory.Visible = false; btnSubCategorySave.Visible = false; btnSubCategoryCancel.Visible = false; lnkNewCategory.Visible = true; lnkNewSubCategory.Visible = true; TxtNewSubcategory.Text = string.Empty; } else { lblerror.Text = "Please Select Category"; lblerror.ForeColor = System.Drawing.Color.Red; } } else { lblerror.Text = "Sub Category Name already exists"; lblerror.ForeColor = System.Drawing.Color.Red; } } catch (Exception ex) { lblerror.Text = ex.Message; } }
public void getimgs() { var db = new Pizza15Model(); //var BrewFestCat = (from q in db.tbl_ImageCategory // where q.CategoryID == 1 // select new { q.CategoryID, q.SubCategoryID, q.SubCategoryName }).ToList(); //OuterRptBrewFest.DataSource = BrewFestCat; //OuterRptBrewFest.DataBind(); var EmployeesCat = (from q in db.tbl_ImageCategory where q.CategoryID == 2 select new { q.CategoryID, q.SubCategoryID, q.SubCategoryName }).ToList(); OuterRptEmployees.DataSource = EmployeesCat; OuterRptEmployees.DataBind(); var FoodPicturesCat = (from q in db.tbl_ImageCategory where q.CategoryID == 3 select new { q.CategoryID, q.SubCategoryID, q.SubCategoryName }).ToList(); OuterRptFoodPictures.DataSource = FoodPicturesCat; OuterRptFoodPictures.DataBind(); var OurFriendssCat = (from q in db.tbl_ImageCategory where q.CategoryID == 4 select new { q.CategoryID, q.SubCategoryID, q.SubCategoryName }).ToList(); OuterRptOurFriends.DataSource = OurFriendssCat; OuterRptOurFriends.DataBind(); var PubPicturesCat = (from q in db.tbl_ImageCategory where q.CategoryID == 5 select new { q.CategoryID, q.SubCategoryID, q.SubCategoryName }).ToList(); OuterRptPubPictures.DataSource = PubPicturesCat; OuterRptPubPictures.DataBind(); var RandomStuffCat = (from q in db.tbl_ImageCategory where q.CategoryID == 6 select new { q.CategoryID, q.SubCategoryID, q.SubCategoryName }).ToList(); OuterRptRandomStuff.DataSource = RandomStuffCat; OuterRptRandomStuff.DataBind(); //carousel repeaters var BrewFestcarousel = (from q in db.tbl_Images where q.CategoryID == 1 select new { q.ImageUrl }).ToList(); RptcarouselBrewFest.DataSource = BrewFestcarousel; RptcarouselBrewFest.DataBind(); var Employeescarousel = (from q in db.tbl_Images where q.CategoryID == 2 select new { q.ImageUrl }).ToList(); RptcarouselEmployees.DataSource = Employeescarousel; RptcarouselEmployees.DataBind(); var FoodPicturescarousel = (from q in db.tbl_Images where q.CategoryID == 3 select new { q.ImageUrl }).ToList(); RptcarouselFoodPictures.DataSource = FoodPicturescarousel; RptcarouselFoodPictures.DataBind(); var OurFriendscarousel = (from q in db.tbl_Images where q.CategoryID == 4 select new { q.ImageUrl }).ToList(); RptcarouselOurFriends.DataSource = OurFriendscarousel; RptcarouselOurFriends.DataBind(); var PubPicturescarousel = (from q in db.tbl_Images where q.CategoryID == 5 select new { q.ImageUrl }).ToList(); RptcarouselPubPictures.DataSource = PubPicturescarousel; RptcarouselPubPictures.DataBind(); var RandomStuffcarousel = (from q in db.tbl_Images where q.CategoryID == 6 select new { q.ImageUrl }).ToList(); RptcarouselRandomStuff.DataSource = RandomStuffcarousel; RptcarouselRandomStuff.DataBind(); }
protected void Btnsearch_Click(object sender, EventArgs e) { var db = new Pizza15Model(); string srchstr = Txtsearch.Text.Trim(); // string filepath = Server.MapPath("/content/") + "15thPDFMenu.pdf"; // searchFortext(filepath, srchstr); string actflg = string.Empty; var appsearch = (from q in db.tbl_Srchmenu join p in db.tbl_Srchrmenuitem on q.Srchmenuid equals p.Srchmenuid where p.Srch_itemcategory == "APPETIZERS" where p.Srch_Itemname.Contains(srchstr) select new { p.Srch_Itemname }).ToList(); if (appsearch.Count != 0) { actflg = "A"; Response.Redirect("http://15thstreetpizza.com/RegularMenu.aspx?actflag=" + actflg); } var chknsrch = (from q in db.tbl_Srchmenu join p in db.tbl_Srchrmenuitem on q.Srchmenuid equals p.Srchmenuid where p.Srch_itemcategory == "CHICKEN" where p.Srch_Itemname.Contains(srchstr) select new { p.Srch_Itemname }).ToList(); if (chknsrch.Count != 0) { actflg = "CH"; Response.Redirect("http://15thstreetpizza.com/RegularMenu.aspx?actflag=" + actflg); } var burgsearch = (from q in db.tbl_Srchmenu join p in db.tbl_Srchrmenuitem on q.Srchmenuid equals p.Srchmenuid where p.Srch_itemcategory == "BURGERS" where p.Srch_Itemname.Contains(srchstr) select new { p.Srch_Itemname }).ToList(); if (burgsearch.Count != 0) { actflg = "B"; Response.Redirect("http://15thstreetpizza.com/RegularMenu.aspx?actflag=" + actflg); } var saldsrch = (from q in db.tbl_Srchmenu join p in db.tbl_Srchrmenuitem on q.Srchmenuid equals p.Srchmenuid where p.Srch_itemcategory == "SALADS" where p.Srch_Itemname.Contains(srchstr) select new { p.Srch_Itemname }).ToList(); if (saldsrch.Count != 0) { actflg = "SD"; Response.Redirect("http://15thstreetpizza.com/RegularMenu.aspx?actflag=" + actflg); } var pizsrch = (from q in db.tbl_Srchmenu join p in db.tbl_Srchrmenuitem on q.Srchmenuid equals p.Srchmenuid where p.Srch_itemcategory == "PIZZAS" where p.Srch_Itemname.Contains(srchstr) select new { p.Srch_Itemname }).ToList(); if (pizsrch.Count != 0) { actflg = "P"; Response.Redirect("http://15thstreetpizza.com/RegularMenu.aspx?actflag=" + actflg); } var subsearch = (from q in db.tbl_Srchmenu join p in db.tbl_Srchrmenuitem on q.Srchmenuid equals p.Srchmenuid where p.Srch_itemcategory == "SUBS" where p.Srch_Itemname.Contains(srchstr) select new { p.Srch_Itemname }).ToList(); if (subsearch.Count != 0) { actflg = "S"; Response.Redirect("http://15thstreetpizza.com/RegularMenu.aspx?actflag=" + actflg); } var entsrch = (from q in db.tbl_Srchmenu join p in db.tbl_Srchrmenuitem on q.Srchmenuid equals p.Srchmenuid where p.Srch_itemcategory == "ENTREES" where p.Srch_Itemname.Contains(srchstr) select new { p.Srch_Itemname }).ToList(); if (entsrch.Count != 0) { actflg = "E"; Response.Redirect("http://15thstreetpizza.com/RegularMenu.aspx?actflag=" + actflg); } var calzsrch = (from q in db.tbl_Srchmenu join p in db.tbl_Srchrmenuitem on q.Srchmenuid equals p.Srchmenuid where p.Srch_itemcategory == "CALZONE" where p.Srch_Itemname.Contains(srchstr) select new { p.Srch_Itemname }).ToList(); if (calzsrch.Count != 0) { actflg = "C"; Response.Redirect("http://15thstreetpizza.com/RegularMenu.aspx?actflag=" + actflg); } var desbevsrch = (from q in db.tbl_Srchmenu join p in db.tbl_Srchrmenuitem on q.Srchmenuid equals p.Srchmenuid where p.Srch_itemcategory == "BEVERAGES" where p.Srch_Itemname.Contains(srchstr) select new { p.Srch_Itemname }).ToList(); if (desbevsrch.Count != 0) { actflg = "BV"; Response.Redirect("http://15thstreetpizza.com/RegularMenu.aspx?actflag=" + actflg); } var kdmnusrch = (from q in db.tbl_Srchmenu join p in db.tbl_Srchrmenuitem on q.Srchmenuid equals p.Srchmenuid where p.Srch_itemcategory == "KIDS MENU" where p.Srch_Itemname.Contains(srchstr) select new { p.Srch_Itemname }).ToList(); if (kdmnusrch.Count != 0) { actflg = "KM"; Response.Redirect("http://15thstreetpizza.com/RegularMenu.aspx?actflag=" + actflg); } }
protected void dg_ItemCommand(object source, DataGridCommandEventArgs e) { try { if (e.CommandName == "AddANewRow") { var db = new Pizza15Model(); TextBox txtNewsF = e.Item.FindControl("txtNewsF") as TextBox; CheckBox chkActiveF = e.Item.FindControl("chkActiveF") as CheckBox; if (txtNewsF != null && chkActiveF != null) { int nMaxID = 0; try { var strQueryMax = db.tblNewsEvents.Max(x => x.NewsID); nMaxID = Convert.ToInt32(strQueryMax); } catch { nMaxID = 0; } var strQuery = new tblNewsEvent(); if (nMaxID != 0) { strQuery.NewsID = nMaxID + 1; } else { strQuery.NewsID = 1; } strQuery.News = txtNewsF.Text; strQuery.Indx = nMaxID + 1; strQuery.Active = Convert.ToBoolean(chkActiveF.Checked); db.tblNewsEvents.Add(strQuery); db.SaveChanges(); } else { lblError.Text = "Error finding the News & Events"; } Session["Event"] = null; GetData(); } if (e.CommandName == "MoveUp") { if (e.Item.ItemIndex == 0) { lblError.Text = "This item cannot be moved further up"; } else { int nNewsID = Convert.ToInt32((e.Item.FindControl("lblNewsID") as Label).Text); int nIndex = Convert.ToInt32((e.Item.FindControl("lblIndex") as Label).Text); int nNewsIDAbove = Convert.ToInt32((dg.Items[e.Item.ItemIndex - 1].FindControl("lblNewsID") as Label).Text); int nIndexAbove = Convert.ToInt32((dg.Items[e.Item.ItemIndex - 1].FindControl("lblIndex") as Label).Text); SwapIndex(nNewsIDAbove, nIndexAbove, nNewsID, nIndex); Session["Event"] = null; GetData(); } } if (e.CommandName == "MoveDown") { if (e.Item.ItemIndex == (dg.Items.Count - 1)) { lblError.Text = "This item cannot be moved further down"; } else { int nNewsID = Convert.ToInt32((e.Item.FindControl("lblNewsID") as Label).Text); int nIndex = Convert.ToInt32((e.Item.FindControl("lblIndex") as Label).Text.Trim().ToString()); int nNewsIDBelow = Convert.ToInt16((dg.Items[e.Item.ItemIndex + 1].FindControl("lblNewsID") as Label).Text); int nIndexBelow = Convert.ToInt16((dg.Items[e.Item.ItemIndex + 1].FindControl("lblIndex") as Label).Text.Trim().ToString()); SwapIndex(nNewsID, nIndex, nNewsIDBelow, nIndexBelow); Session["Event"] = null; GetData(); } } } catch (Exception ex) { throw ex; //lblError.Text = ex.Message; } }
protected void dg_ItemCommand(object source, DataGridCommandEventArgs e) { try { if (e.CommandName == "AddANewRow") { var db = new Pizza15Model(); TextBox txtItem = e.Item.FindControl("txtMPSubItemF") as TextBox; CheckBox chkBull = e.Item.FindControl("chkMPIsSubItemBulletedF") as CheckBox; if (txtItem != null && chkBull != null) { var strQueryMax = db.tblMainPageSubItems.Max(x => x.SubItemID); int nMaxID = Convert.ToInt32(strQueryMax); var strQuery = new tblMainPageSubItem(); if (nMaxID != 0) { strQuery.SubItemID = nMaxID + 1; } else { strQuery.SubItemID = 1; } strQuery.SubItem = txtItem.Text; strQuery.ItemID = Convert.ToInt32(ddlMainPageItem.SelectedItem.Value); strQuery.IsSubItemBulleted = false; strQuery.Indx = nMaxID + 1; db.tblMainPageSubItems.Add(strQuery); db.SaveChanges(); } else { lblError.Text = "Error finding the Main Page Sub Item"; } Session["SubPageItem"] = null; GetData(); } if (e.CommandName == "MoveUp") { if (e.Item.ItemIndex == 0) { lblError.Text = "This item cannot be moved further up"; } else { int nMPMItemID = Convert.ToInt32((e.Item.FindControl("lblMPSubItemID") as Label).Text); int nIndex = Convert.ToInt32((e.Item.FindControl("lblIndex") as Label).Text); int nMPMItemIDAbove = Convert.ToInt32((dg.Items[e.Item.ItemIndex - 1].FindControl("lblMPSubItemID") as Label).Text); int nIndexAbove = Convert.ToInt32((dg.Items[e.Item.ItemIndex - 1].FindControl("lblIndex") as Label).Text); SwapIndex(nMPMItemIDAbove, nIndexAbove, nMPMItemID, nIndex); Session["SubPageItem"] = null; GetData(); } } if (e.CommandName == "MoveDown") { if (e.Item.ItemIndex == (dg.Items.Count - 1)) { lblError.Text = "This item cannot be moved further down"; } else { int nMPMItemID = Convert.ToInt32((e.Item.FindControl("lblMPSubItemID") as Label).Text); int nIndex = Convert.ToInt32((e.Item.FindControl("lblIndex") as Label).Text.Trim().ToString()); int nMPMItemIDBelow = Convert.ToInt16((dg.Items[e.Item.ItemIndex + 1].FindControl("lblMPSubItemID") as Label).Text); int nIndexBelow = Convert.ToInt16((dg.Items[e.Item.ItemIndex + 1].FindControl("lblIndex") as Label).Text.Trim().ToString()); SwapIndex(nMPMItemID, nIndex, nMPMItemIDBelow, nIndexBelow); Session["SubPageItem"] = null; GetData(); } } } catch (Exception ex) { lblError.Text = ex.Message; } }
protected void Save_Click(object sender, EventArgs e) { try { var db = new Pizza15Model(); tblSpecialsVlddate itemvlddates = new tblSpecialsVlddate(); string itemname = Itmdrplist.SelectedItem.Text.ToString(); DateTime startdate = Convert.ToDateTime(TxtVldst.Value); DateTime enddate = Convert.ToDateTime(TxtVldend.Value); var dailysplcount = (from q in db.tblSpecialsVlddates where q.Itemname == itemname where q.Specialtype == "DailySpecials" select new { q }).Count(); if (dailysplcount == 0) { if (enddate >= startdate) { if (enddate >= System.DateTime.Today & startdate >= System.DateTime.Today) { itemvlddates.Itemname = itemname; itemvlddates.Specialtype = "DailySpecials"; itemvlddates.vldstartdate = startdate; itemvlddates.vldenddate = enddate; db.tblSpecialsVlddates.Add(itemvlddates); db.SaveChanges(); lblmsg.Text = "Details saved successfully."; lblmsg.ForeColor = System.Drawing.Color.Green; clearfields(); } else { lblmsg.Text = "Start date & End date cannot be less than today's date."; lblmsg.ForeColor = System.Drawing.Color.Red; } } else { lblmsg.Text = "Start date cannot be greater than end date."; lblmsg.ForeColor = System.Drawing.Color.Red; } } else { if (enddate >= startdate) { if (enddate >= System.DateTime.Today & startdate >= System.DateTime.Today) { var dailysp = (from q in db.tblSpecialsVlddates where q.Itemname == itemname where q.Specialtype == "DailySpecials" select new { q }).FirstOrDefault(); dailysp.q.vldstartdate = startdate; dailysp.q.vldenddate = enddate; db.SaveChanges(); lblmsg.Text = "Details saved successfully."; lblmsg.ForeColor = System.Drawing.Color.Green; } else { lblmsg.Text = "Start date & End date cannot be less than today's date."; lblmsg.ForeColor = System.Drawing.Color.Red; } } else { lblmsg.Text = "Start date cannot be greater than end date."; lblmsg.ForeColor = System.Drawing.Color.Red; } } } catch (Exception ex) { throw (ex); } }
protected void btnCategorySave_Click(object sender, EventArgs e) { try { var db = new Pizza15Model(); var imgCategory = new tbl_ImageCategory(); var maxid = (from q in db.tbl_ImageCategory select new { q.ID }).ToList(); if (maxid.Count != 0) { imgCategory.ID = maxid.Max(x => x.ID) + 1; } imgCategory.CategoryID = imgCategory.ID; imgCategory.CategoryName = TxtCategory.Text; imgCategory.SubCategoryID = 1; imgCategory.SubCategoryName = imgCategory.CategoryName; if (TxtCategory.Text == "") { lblerror.Text = "Please enter a category name "; lblerror.ForeColor = System.Drawing.Color.Red; lblCategory.Visible = true; TxtCategory.Visible = true; btnCategorySave.Visible = true; btnCategoryCancel.Visible = true; } else { var duplicatecatid = (from q in db.tbl_ImageCategory where q.CategoryName == TxtCategory.Text select new { }).Count(); if (duplicatecatid == 0) { db.tbl_ImageCategory.Add(imgCategory); db.SaveChanges(); lblerror.Text = "New Category Created Successfully"; lblerror.ForeColor = System.Drawing.Color.ForestGreen; lblCategory.Visible = false; TxtCategory.Visible = false; btnCategorySave.Visible = false; btnCategoryCancel.Visible = false; lnkNewCategory.Visible = true; lnkNewSubCategory.Visible = true; TxtCategory.Text = string.Empty; } else { lblerror.Text = " The Category Name Already exists, Please choose a different One"; lblerror.ForeColor = System.Drawing.Color.Red; lblCategory.Visible = true; TxtCategory.Visible = true; btnCategorySave.Visible = true; btnCategoryCancel.Visible = true; } } } catch (Exception ex) { lblerror.Text = ex.Message; } }
protected void dgImages_UpdateCommand(object source, DataGridCommandEventArgs e) { try { string strID = dgImages.DataKeys[e.Item.ItemIndex].ToString(); int nStrID = Convert.ToInt32(strID); TextBox txtImageHeaderE = e.Item.FindControl("txtImageHeaderE") as TextBox; TextBox txtNamesE = e.Item.FindControl("txtNamesE") as TextBox; TextBox txtImageURLE = e.Item.FindControl("txtImageURLE") as TextBox; FileUpload ImageuploadE = e.Item.FindControl("ImageuploadE") as FileUpload; var db = new Pizza15Model(); tbl_Images imgtbl = db.tbl_Images.FirstOrDefault(x => x.ID == nStrID); var infoimgid = (from q in db.tbl_Images join r in db.tbl_ImageCategory on q.CategoryID equals r.CategoryID where q.ID == nStrID where q.CategoryID == r.CategoryID select new { r.SubCategoryName, r.CategoryName }).FirstOrDefault(); string rowcatname = infoimgid.CategoryName; string rowsubcatname = infoimgid.SubCategoryName; if (imgtbl != null) { imgtbl.ImageHeader = txtImageHeaderE.Text; imgtbl.Name = txtNamesE.Text; if (ImageuploadE.FileName != string.Empty) { if (rowcatname == "Season Specials") { ImageuploadE.PostedFile.SaveAs(Server.MapPath("~/images/GalleryPhotos/Season Specials/Season Specials/" + ImageuploadE.FileName)); imgtbl.ImageUrl = ("images/GalleryPhotos/Season Specials/Season Specials/" + ImageuploadE.FileName); imgtbl.ImageLink = ("images/GalleryPhotos/Season Specials/Season Specials/" + ImageuploadE.FileName); } else { ImageuploadE.PostedFile.SaveAs(Server.MapPath("~/images/GalleryPhotos/" + ddlImageCategory.SelectedItem.Text + "/" + ddlImageSubCategory.SelectedItem.Text + "/" + ImageuploadE.FileName)); imgtbl.ImageUrl = ("images/GalleryPhotos/" + ddlImageCategory.SelectedItem.Text + "/" + ddlImageSubCategory.SelectedItem.Text + "/" + ImageuploadE.FileName); imgtbl.ImageLink = ("images/GalleryPhotos/" + ddlImageCategory.SelectedItem.Text + "/" + ddlImageSubCategory.SelectedItem.Text + "/" + ImageuploadE.FileName); } } else { imgtbl.ImageUrl = txtImageURLE.Text; imgtbl.ImageLink = txtImageURLE.Text; } imgtbl.CategoryID = Convert.ToInt32(ddlImageCategory.SelectedValue); imgtbl.SubCategoryID = Convert.ToInt32(ddlImageSubCategory.SelectedValue); db.SaveChanges(); lblError.Text = "Record Updated Successfully"; lblError.ForeColor = System.Drawing.Color.ForestGreen; } dgImages.EditItemIndex = -1; dgImages.ShowFooter = true; Getdata(); } catch (Exception ex) { lblError.Text = ex.Message; lblError.ForeColor = System.Drawing.Color.Red; } }
protected void dg_ItemCommand(object source, DataGridCommandEventArgs e) { try { if (e.CommandName == "AddANewRow") { var db = new Pizza15Model(); TextBox txtItem = e.Item.FindControl("txtpizzItemF") as TextBox; TextBox txtday = e.Item.FindControl("txtpizzdayF") as TextBox; TextBox txtsmlPrice = e.Item.FindControl("txtsmlPriceF") as TextBox; TextBox txtperPrice = e.Item.FindControl("txtperPriceF") as TextBox; TextBox txtmedPrice = e.Item.FindControl("txtmedPriceF") as TextBox; TextBox txtlrgPrice = e.Item.FindControl("txtlrgPriceF") as TextBox; if (txtItem != null && txtday != null && txtsmlPrice != null && txtperPrice != null && txtmedPrice != null && txtlrgPrice != null) { var PizzaSpecials = db.tbl_pizzaspecials.Select(x => new { PizzaID = x.PizzaSpecID, Day = x.day, Item = x.Name, Itemid = x.ItemId, Sizsml = x.col_Small, Sizpers = x.col_Personal, Sizmed = x.col_Medium, Sizlarge = x.col_large }).ToList(); if (PizzaSpecials.Count != 0) { var strQueryMax = db.tbl_pizzaspecials.Max(x => x.PizzaSpecID); int nMaxID = Convert.ToInt32(strQueryMax); var strQuery = new tbl_pizzaspecials(); strQuery.PizzaSpecID = nMaxID + 1; strQuery.day = txtday.Text; strQuery.ItemId = 2; strQuery.Name = txtItem.Text; strQuery.col_Small = txtsmlPrice.Text; strQuery.col_Medium = txtmedPrice.Text; strQuery.col_Personal = txtperPrice.Text; strQuery.col_large = txtlrgPrice.Text; db.tbl_pizzaspecials.Add(strQuery); db.SaveChanges(); } else { var strQuery = new tbl_pizzaspecials(); strQuery.PizzaSpecID = 1; strQuery.day = txtday.Text; strQuery.ItemId = 2; strQuery.Name = txtItem.Text; strQuery.col_Small = txtsmlPrice.Text; strQuery.col_Medium = txtmedPrice.Text; strQuery.col_Personal = txtperPrice.Text; strQuery.col_large = txtlrgPrice.Text; db.tbl_pizzaspecials.Add(strQuery); db.SaveChanges(); } } else { lblError.Text = "Error finding the Pizza Specials"; } Session["PizzaSpecial"] = null; GetData(); } if (e.CommandName == "Update") { string strID = dg.DataKeys[e.Item.ItemIndex].ToString(); int nStrID = Convert.ToInt32(strID); TextBox txtItem = e.Item.FindControl("txtpizzItemE") as TextBox; TextBox txtday = e.Item.FindControl("txtpizzdayE") as TextBox; TextBox txtsmlPrice = e.Item.FindControl("txtsmlPriceE") as TextBox; TextBox txtperPrice = e.Item.FindControl("txtperPriceE") as TextBox; TextBox txtmedPrice = e.Item.FindControl("txtmedPriceE") as TextBox; TextBox txtlrgPrice = e.Item.FindControl("txtlrgPriceE") as TextBox; if (txtItem != null && txtday != null && txtsmlPrice != null && txtperPrice != null && txtmedPrice != null && txtlrgPrice != null) { var db = new Pizza15Model(); tbl_pizzaspecials UpdatePizzaSpecial = db.tbl_pizzaspecials.FirstOrDefault(x => x.PizzaSpecID.Equals(nStrID)); if (UpdatePizzaSpecial != null) { UpdatePizzaSpecial.Name = txtItem.Text.Trim(); UpdatePizzaSpecial.day = txtday.Text.Trim(); UpdatePizzaSpecial.col_Small = txtsmlPrice.Text.Trim(); UpdatePizzaSpecial.col_Personal = txtperPrice.Text.Trim(); UpdatePizzaSpecial.col_Medium = txtmedPrice.Text.Trim(); UpdatePizzaSpecial.col_large = txtlrgPrice.Text.Trim(); db.SaveChanges(); } } else { lblError.Text = "Error finding the Pizza Special"; } dg.EditItemIndex = -1; dg.ShowFooter = true; Session["PizzaSpecial"] = null; GetData(); } if (e.CommandName == "MoveUp") { if (e.Item.ItemIndex == 0) { lblError.Text = "This item cannot be moved further up"; } else { int nPizzaID = Convert.ToInt32((e.Item.FindControl("lblPizzaID") as Label).Text); int nIndex = Convert.ToInt32((e.Item.FindControl("lblIndex") as Label).Text); int nPizzaIDAbove = Convert.ToInt32((dg.Items[e.Item.ItemIndex - 1].FindControl("lblPizzaID") as Label).Text); int nIndexAbove = Convert.ToInt32((dg.Items[e.Item.ItemIndex - 1].FindControl("lblIndex") as Label).Text); SwapIndex(nPizzaIDAbove, nIndexAbove, nPizzaID, nIndex); Session["PizzaSpecial"] = null; GetData(); } } if (e.CommandName == "MoveDown") { if (e.Item.ItemIndex == (dg.Items.Count - 1)) { lblError.Text = "This item cannot be moved further down"; } else { int nPizzaID = Convert.ToInt32((e.Item.FindControl("lblPizzaID") as Label).Text); int nIndex = Convert.ToInt32((e.Item.FindControl("lblIndex") as Label).Text); int nPizzaIDAbove = Convert.ToInt32((dg.Items[e.Item.ItemIndex + 1].FindControl("lblPizzaID") as Label).Text); int nIndexBelow = Convert.ToInt16((dg.Items[e.Item.ItemIndex + 1].FindControl("lblIndex") as Label).Text.Trim().ToString()); SwapIndex(nPizzaID, nIndex, nPizzaIDAbove, nIndexBelow); Session["Event"] = null; GetData(); } } } catch (Exception ex) { lblError.Text = ex.Message; } }