コード例 #1
0
        /***
         * Take a data row (aka item) of the result set as argument.
         * Generate a string contains a snippet of HTML code and the item's name and score.
         * Style the foreground color of the score and the background color of the expand button.
         * Return generated string.
         */
        protected String GenerateHtmlForEachItem(DataRow item)
        {
            String returnValue     = "";
            String colorScaleStyle = "";
            double score           = double.Parse(item["ND Score"].ToString());

            if (score < 4.66)
            {
                colorScaleStyle = GradientColors.getColor1();
            }
            else if ((score >= 4.66) && (score <= 28))
            {
                colorScaleStyle = GradientColors.getColor2();
            }
            else if (score > 28)
            {
                colorScaleStyle = GradientColors.getColor3();
            }
            else
            {
                // do nothing
            }

            colorScaleStyle += " !important";

            returnValue = String.Format(@"
				<li>
					<div class='col-sm-6 col-md-4 col-lg-3'>
						<div class='panel panel-default' style='border-bottom: 5px solid {0};'>
							<div class='panel-body'>
								<h4 id='{3}_name' class='panel-title equal-height'>{1}</h4>
								<h4><strong>ND_Score: <span style='color: {0};'>{2}<span></strong></h4>
								<button id='{3}' class='btn btn-default btn-block expend-button' data-toggle='modal' data-target='#expanded_view'>Expand</button>
							</div>
						</div>
					</div>
				</li>
			"            ,
                                        colorScaleStyle,
                                        item["name"].ToString(),
                                        item["ND score"].ToString(),
                                        item["NDBno"].ToString());

            return(returnValue);
        }
コード例 #2
0
        /***
         * 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);
            }
        }
コード例 #3
0
ファイル: recent.aspx.cs プロジェクト: thyvo2904/wholesomeMVC
        /***
         * Generate html code for an recent item.
         *
         * ARGS:
         * Accept item index in newFoodArray as input.
         *
         * RETURN:
         * A string contains the html code for the item with input index.
         */
        protected String GenerateRecentItem(int intItemIndex)
        {
            String returnValue = "";

            String colorScaleStyle = "background-color: ";
            double score           = newFoodArray[intItemIndex].NRF6;

            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
            }

            returnValue = String.Format(@"
				<div class='col-sm-6 col-md-4 col-lg-3'>
					<div class='panel panel-default'>
						<div class='panel-heading'>
							<h4 class='panel-title equal-height'>
								{1}
							</h4>
						</div>

						<div class='panel-body' style='{0}'>
							<h4><strong>ND_Score: {2}</strong></h4>
						</div>

						<div class='panel-body'>
							<h4><strong>Nutrition Facts</strong></h4>
							<table class='table table-condensed table-hover'>
								<tbody>
									<tr class='fatter'>
										<th>Calories</th>
										<td>{3}</td>
										<td></td>
									</tr>
									<tr class='fat'>
										<th>Saturated Fat</th>
										<td>{4}</td>
										<td>g</td>
									</tr>
									<tr>
										<th>Sodium</th>
										<td>{5}</td>
										<td>g</td>
									</tr>
									<tr>
										<th>Dietary Fiber</th>
										<td>{6}</td>
										<td>g</td>
									</tr>
									<tr>
										<th>Total Sugars</th>
										<td>{7}</td>
										<td>g</td>
									</tr>
									<tr>
										<th>Protein</th>
										<td>{8}</td>
										<td>g</td>
									</tr>
									<tr class='fatter'>
										<th>Vitamin A</th>
										<td>{9}</td>
										<td>IU</td>
									</tr>
									<tr>
										<th>Vitamin C</th>
										<td>{10}</td>
										<td>IU</td>
									</tr>
									<tr>
										<th>Calcium</th>
										<td>{11}</td>
										<td>mg</td>
									</tr>
									<tr>
										<th>Iron</th>
										<td>{12}</td>
										<td>mg</td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			"            ,
                                        colorScaleStyle,
                                        newFoodArray[intItemIndex].name.ToString(),
                                        newFoodArray[intItemIndex].NRF6.ToString(),
                                        newFoodArray[intItemIndex].kCal.ToString(),
                                        newFoodArray[intItemIndex].satFat.ToString(),
                                        newFoodArray[intItemIndex].sodium.ToString(),
                                        newFoodArray[intItemIndex].fiber.ToString(),
                                        newFoodArray[intItemIndex].totalSugar.ToString(),
                                        newFoodArray[intItemIndex].protein.ToString(),
                                        newFoodArray[intItemIndex].vitaminA.ToString(),
                                        newFoodArray[intItemIndex].vitaminC.ToString(),
                                        newFoodArray[intItemIndex].calcium.ToString(),
                                        newFoodArray[intItemIndex].iron.ToString(),
                                        intItemIndex.ToString());

            return(returnValue);
        }
コード例 #4
0
        /***
         * 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);
        }