protected void btnSearch(object sender, EventArgs e) { String foodSearch = ""; if (txtSearch.Text != "") { } else { // show error } FoodItem.findNdbno(foodSearch); Server.Transfer("/WebForms/indexresult.aspx"); }
protected void btnSearch(object sender, EventArgs e) { if (txtSearch.Text != "") { String foodSearch = ""; foodSearch = txtSearch.Text; FoodItem.findNdbno(foodSearch); Response.Redirect("~/IndexResults.aspx"); } else { Response.Write("<script>alert('Please enter a value');</script>"); } }
protected void btnSearch(object sender, EventArgs e) { String foodSearch = ""; if (txtSearch.Text != "") { switch (ddlCategory.SelectedIndex) { case 0: foodSearch = txtSearch.Text; break; case 1: foodSearch = txtSearch.Text + "&fg=0100"; break; case 2: foodSearch = txtSearch.Text + "&fg=0200"; break; case 3: foodSearch = txtSearch.Text + "&fg=0300"; break; case 4: foodSearch = txtSearch.Text + "&fg=0400"; break; case 5: foodSearch = txtSearch.Text + "&fg=0500"; break; case 6: foodSearch = txtSearch.Text + "&fg=0600"; break; case 7: foodSearch = txtSearch.Text + "&fg=0700"; break; case 8: foodSearch = txtSearch.Text + "&fg=0800"; break; case 9: foodSearch = txtSearch.Text + "&fg=0900"; break; case 10: foodSearch = txtSearch.Text + "&fg=1000"; break; case 11: foodSearch = txtSearch.Text + "&fg=1100"; break; case 12: foodSearch = txtSearch.Text + "&fg=1200"; break; case 13: foodSearch = txtSearch.Text + "&fg=1300"; break; case 14: foodSearch = txtSearch.Text + "&fg=1400"; break; case 15: foodSearch = txtSearch.Text + "&fg=1500"; break; case 16: foodSearch = txtSearch.Text + "&fg=1600"; break; case 17: foodSearch = txtSearch.Text + "&fg=1700"; break; case 18: foodSearch = txtSearch.Text + "&fg=1800"; break; case 19: foodSearch = txtSearch.Text + "&fg=1900"; break; case 20: foodSearch = txtSearch.Text + "&fg=2000"; break; case 21: foodSearch = txtSearch.Text + "&fg=2100"; break; case 22: foodSearch = txtSearch.Text + "&fg=2200"; break; case 23: foodSearch = txtSearch.Text + "&fg=2500"; break; case 24: foodSearch = txtSearch.Text + "&fg=3500"; break; case 25: foodSearch = txtSearch.Text + "&fg=3600"; break; default: break; } } else { // show error } FoodItem.findNdbno(foodSearch); Server.Transfer("/WebForms/indexresult.aspx"); }
/*** * Get the ndbno from a hidden field in front-end. * Get data using FoodItem.findNdbno method and ndbno. * Style the NR Score accordingly. * Update data to modal section in front-end. */ protected void ExpandItem(object sender, EventArgs e) { // get data from front end string ceresid = hidden_ceresid.Value; string ceres_name = hidden_ceres_name.Value; string ndbno = hidden_ndbno.Value; string nrf6 = hidden_nrf6.Value; string view_mode = hidden_view_mode.Value; // To manage records with matched USDA items if (ndbno != "") { FoodItem.findNdbno(ndbno); double score = FoodItem.newFood.NRF6; String colorScaleStyle = "background-color: "; if (score <= 4.65) { colorScaleStyle += GradientColors.getColor1() + "; color: white;"; } else if ((score >= 4.66) && (score <= 27.99)) { colorScaleStyle += GradientColors.getColor2() + "; color: black;"; } else if (score >= 28) { colorScaleStyle += GradientColors.getColor3() + "; color: white;"; } else { // do nothing } switch (view_mode) { case "old": nd_old_score_panel.Attributes["style"] = colorScaleStyle; lblOldNdbno.Text = ndbno; lblOldCeresId.Text = ceresid; lblOldCeresName.Text = ceres_name; lblOldFoodName.Text = FoodItem.newFood.name; lblOldIndexResult.Text = Convert.ToString(Math.Round(score, 2)); txtOldKCal.Text = FoodItem.newFood.kCal.ToString(); txtOldSaturatedFat.Text = Math.Round(FoodItem.newFood.satFat, 2).ToString(); txtOldSodium.Text = Math.Round(FoodItem.newFood.sodium, 2).ToString(); txtOldFiber.Text = Math.Round(FoodItem.newFood.fiber, 2).ToString(); txtOldTotalSugar.Text = Math.Round(FoodItem.newFood.totalSugar, 2).ToString(); txtOldProtein.Text = Math.Round(FoodItem.newFood.protein, 2).ToString(); txtOldVitaminA.Text = Math.Round(FoodItem.newFood.vitaminA).ToString(); txtOldVitaminC.Text = Math.Round(FoodItem.newFood.vitaminC).ToString(); txtOldCalcium.Text = Math.Round(FoodItem.newFood.calcium).ToString(); txtOldIron.Text = Math.Round(FoodItem.newFood.iron).ToString(); lblNewCeresNumber.Text = ceresid; break; case "new": nd_new_score_panel.Attributes["style"] = colorScaleStyle; lblNewNdbno.Text = ndbno; lblNewCeresId.Text = ceresid; lblNewCeresName.Text = ceres_name; lblNewFoodName.Text = FoodItem.newFood.name; lblNewIndexResult.Text = Convert.ToString(Math.Round(score, 2)); txtNewCalories.Text = FoodItem.newFood.kCal.ToString(); txtNewSaturatedFat.Text = Math.Round(FoodItem.newFood.satFat, 2).ToString(); txtSodiumNew.Text = Math.Round(FoodItem.newFood.sodium, 2).ToString(); txtFiberNew.Text = Math.Round(FoodItem.newFood.fiber, 2).ToString(); txtAddedSugarNew.Text = Math.Round(FoodItem.newFood.totalSugar, 2).ToString(); txtProteinNew.Text = Math.Round(FoodItem.newFood.protein, 2).ToString(); txtVitaminDNew.Text = Math.Round((FoodItem.newFood.vitaminA / 5000) * 100).ToString(); txtCalciumNew.Text = Math.Round((FoodItem.newFood.calcium / 1000) * 100).ToString(); txtIronNew.Text = Math.Round((FoodItem.newFood.iron / 18) * 100).ToString(); txtPotassiumNew.Text = Math.Round((FoodItem.newFood.vitaminC / 60) * 100).ToString(); break; default: break; } // re-render bootstrap-select component ddlFBCategories.CssClass = "selectpicker"; ddlFBCategories.Attributes["title"] = "Select a category"; ddlFBCategories.Attributes["data-width"] = "100%"; ddlFBCategories.Attributes["data-live-search"] = "true"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "rerender", "$('.selectpicker').selectpicker('render');", true); } // To manage manually inputted items else { double score = Double.Parse(hidden_nrf6.Value); String colorScaleStyle = ""; if (score <= 4.65) { colorScaleStyle = GradientColors.getColor1(); } else if ((score >= 4.66) && (score <= 27.99)) { colorScaleStyle = GradientColors.getColor2(); } else if (score >= 28) { colorScaleStyle = GradientColors.getColor3(); } else { // do nothing } colorScaleStyle = "background-color: " + colorScaleStyle; switch (view_mode) { case "old": nd_old_score_panel.Attributes["style"] = colorScaleStyle; lblOldIndexResult.Text = Convert.ToString(Math.Round(score, 2)); lblNewCeresNumber.Text = ceresid; break; case "new": nd_new_score_panel.Attributes["style"] = colorScaleStyle; lblNewIndexResult.Text = Convert.ToString(Math.Round(score, 2)); break; default: break; } // re-render bootstrap-select component ddlFBCategories.CssClass = "selectpicker"; ddlFBCategories.Attributes["title"] = "Select a category"; ddlFBCategories.Attributes["data-width"] = "100%"; ddlFBCategories.Attributes["data-live-search"] = "true"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "rerender", "$('.selectpicker').selectpicker('render');", true); } }
/*** * Get the ndbno from a hidden field in front-end. * Get data using FoodItem.findNdbno method and ndbno. * Style the NR Score accordingly. * Update data to modal section in front-end. */ protected void ExpandItem(object sender, EventArgs e) { string ndbno = lblNdbno.Value; FoodItem.findNdbno(ndbno); String ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; //check if item already exists in database, if it does hide the save button and show the update button using (SqlConnection connection = new SqlConnection(ConnectionString)) { SqlCommand command = new SqlCommand("Select * FROM wholesome_item WHERE ndb_no = @ndbno", connection); command.Parameters.Add("@ndbno", SqlDbType.NVarChar, 8).Value = ndbno; connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { btnUpdate.Visible = true; btnSaveItem.Visible = false; txtCeresStatus.Text = "Matched"; } else { btnSaveItem.Visible = true; txtCeresStatus.Text = "Unmatched"; btnUpdate.Visible = true; } connection.Close(); } //saved into recent_index //check if they login if (!checkndbno(ndbno)) { if (HttpContext.Current.User.IsInRole("Admin") || HttpContext.Current.User.IsInRole("Purchasing_Staff") || HttpContext.Current.User.IsInRole("Warehouse_Staff")) { using (SqlConnection connection = new SqlConnection(ConnectionString)) { SqlCommand command = new SqlCommand("INSERT INTO RECENT_INDEX(NDB_NO,LOGINID,LastUpdated,LastUpdatedBy) VALUES (@NDB_NO, @ID,@LastUpdated, @LastUpdatedby);", connection); command.Parameters.Add("@NDB_NO", SqlDbType.NVarChar, 8).Value = ndbno; command.Parameters.Add("@ID", SqlDbType.Int).Value = getloginid(); command.Parameters.Add("@LastUpdatedBy", SqlDbType.NVarChar, 20).Value = HttpContext.Current.User.Identity.GetUserName(); command.Parameters.Add("@LastUpdated", SqlDbType.DateTime, 128).Value = DateTime.Now; connection.Open(); command.ExecuteNonQuery(); connection.Close(); } } else { using (SqlConnection connection = new SqlConnection(ConnectionString)) { SqlCommand command = new SqlCommand("INSERT INTO RECENT_INDEX(NDB_NO,LOGINID,LastUpdated,LastUpdatedBy) VALUES (@NDB_NO, @ID,@LastUpdated, @LastUpdatedby);", connection); command.Parameters.Add("@NDB_NO", SqlDbType.NVarChar, 8).Value = ndbno; command.Parameters.Add("@ID", SqlDbType.Int).Value = DBNull.Value; command.Parameters.Add("@LastUpdatedBy", SqlDbType.NVarChar, 20).Value = HttpContext.Current.User.Identity.GetUserName();; command.Parameters.Add("@LastUpdated", SqlDbType.DateTime, 128).Value = DateTime.Now; connection.Open(); command.ExecuteNonQuery(); connection.Close(); } } } else { //do nothing } double score = FoodItem.newFood.NRF6; String colorScaleStyle = "background-color: "; if (score < 4.66) { colorScaleStyle += GradientColors.getColor1() + "; color: white;"; } else if ((score >= 4.66) && (score <= 28)) { colorScaleStyle += GradientColors.getColor2() + "; color: black;"; } else if (score > 28) { colorScaleStyle += GradientColors.getColor3() + "; color: white;"; } else { // do nothing } nd_score_panel.Attributes["style"] = colorScaleStyle; lblFoodName.Text = FoodItem.newFood.name; lblFoodName.Attributes["style"] = "font-weight: bold;"; lblIndexResult.Text = Convert.ToString(Math.Round(score, 2)); lblNdbno.Value = FoodItem.newFood.ndbNo; lblName.Value = FoodItem.newFood.name; txtcalories.Text = FoodItem.newFood.kCal.ToString(); txtsatfat.Text = Math.Round(FoodItem.newFood.satFat, 2).ToString(); txtsodium.Text = Math.Round(FoodItem.newFood.sodium, 2).ToString(); txtfiber.Text = Math.Round(FoodItem.newFood.fiber, 2).ToString(); txtsugar.Text = Math.Round(FoodItem.newFood.totalSugar, 2).ToString(); txtprotein.Text = Math.Round(FoodItem.newFood.protein, 2).ToString(); txtva.Text = Math.Round(FoodItem.newFood.vitaminA, 2).ToString(); txtvc.Text = Math.Round(FoodItem.newFood.vitaminC, 2).ToString(); txtcalcium.Text = Math.Round(FoodItem.newFood.calcium, 2).ToString(); txtiron.Text = Math.Round(FoodItem.newFood.iron, 2).ToString(); // re-render bootstrap-select component ddlFBCategories.CssClass = "selectpicker"; ddlFBCategories.Attributes["title"] = "Select a category"; ddlFBCategories.Attributes["data-width"] = "100%"; ddlFBCategories.Attributes["data-live-search"] = "true"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "rerender", "$('.selectpicker').selectpicker('render');", true); }