Advertisement
| Hall of Fame |
|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: |
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Web.Security;
using System.Configuration;
using User;
using Db;
namespace ChefMaha
{
/// <summary>
/// Summary description for fooditems.
/// </summary>
public class fooditems : System.Web.UI.Page
{
protected System.Data.OleDb.OleDbCommand FoodListOleDbCommand;
protected System.Web.UI.WebControls.DataList FoodDataList;
protected static System.Data.OleDb.OleDbConnection ChefMahaOleDbConn;
protected static string ConnectionStr;
protected static System.Data.OleDb.OleDbCommand FoodOleDbCommand;
protected System.Web.UI.WebControls.DropDownList CategoryDropDownList;
protected string ConnectionPhysicalPath;
protected System.Data.OleDb.OleDbCommand CategoryOleDbCommand;
protected static string SelectAllFromFood;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
//set connection string
ConnectionPhysicalPath = Server.MapPath("~/db/ChefMaha.mdb");
ConnectionStr = ConfigurationSettings.AppSettings.Get("ConnectionString") + ConnectionPhysicalPath;
SelectAllFromFood = FoodOleDbCommand.CommandText;
ChefMahaOleDbConn = new OleDbConnection(ConnectionStr);
LoadDropDownListWithData();
}
GetChosenCategory();
LoadDataListWithData();
}
private void LoadDataListWithData()
{
if(ChefMahaOleDbConn.State.ToString() == "Closed")
{
ChefMahaOleDbConn.Open();
}
FoodOleDbCommand.Connection = ChefMahaOleDbConn;
OleDbDataReader FoodDataReader = FoodOleDbCommand.ExecuteReader();
FoodDataList.DataSource = (object) FoodDataReader;
FoodDataList.DataBind();
ChefMahaOleDbConn.Close();
}
/// <summary>
/// gets the category chosen by the user
/// </summary>
private void GetChosenCategory()
{
string Category;
try
{
Category = Request.QueryString["Category"].ToString();
}
catch(NullReferenceException)
{
return;
}
ModifySelectedCategory(Category);
}
/// <summary>
/// modifies the SQL statement of the menu grid according to the selected category
/// </summary>
/// <param name="SelectedCategory">the category selected by the user</param>
private void ModifySelectedCategory(string SelectedCategory)
{
if(SelectedCategory == "All")
{
FoodOleDbCommand.CommandText = SelectAllFromFood;
}
else
{
string AppendedToSelectCmd = "WHERE FCtgEn = ";
try
{
string NewValue = AppendedToSelectCmd + "'" + SelectedCategory + "'";
FoodOleDbCommand.CommandText = SelectAllFromFood.Replace("ORDER BY FCtgEn", NewValue);
}
catch(NullReferenceException)
{
foreach (Control c in Page.Controls)
{
c.Visible=false;
}
Response.Write("An Error Occurred. Please refresh the Page.");
}
}
LoadDataListWithData();
if(CategoryDropDownList.SelectedValue != SelectedCategory)
{
try
{
CategoryDropDownList.SelectedValue = SelectedCategory;
}
catch(Exception ex)
{
for(int i=0; i<CategoryDropDownList.Items.Count; i++)
{
Response.Write(CategoryDropDownList.Items[i].Value);
}
}
}
}
/// <summary>
/// loads the category drop down list with the categories from db
/// </summary>
private void LoadDropDownListWithData()
{
ChefMahaOleDbConn.Open();
CategoryOleDbCommand.Connection = ChefMahaOleDbConn;
OleDbDataReader CategoryDataReader = CategoryOleDbCommand.ExecuteReader();
while(CategoryDataReader.Read())
{
string Category = CategoryDataReader.GetString(0);
string CategoryEn = CategoryDataReader.GetString(1);
ListItem CategoryListItem = new ListItem(Category, CategoryEn);
CategoryDropDownList.Items.Add(CategoryListItem);
}
CategoryDataReader.Close();
ChefMahaOleDbConn.Close();
}
private void CategoryDropDownList_SelectedIndexChanged(object sender, System.EventArgs e)
{
ChefMahaOleDbConn.Open();
ModifySelectedCategory(CategoryDropDownList.SelectedValue);
ChefMahaOleDbConn.Close();
}
#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);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
FoodOleDbCommand = new System.Data.OleDb.OleDbCommand();
this.CategoryOleDbCommand = new System.Data.OleDb.OleDbCommand();
this.CategoryDropDownList.SelectedIndexChanged += new System.EventHandler(this.CategoryDropDownList_SelectedIndexChanged);
//
// FoodOleDbCommand
//
FoodOleDbCommand.CommandText = "SELECT FCtg, FCtgEn, FName, FUnit, FUnitPrice, FDescr, FPhoto FROM FOOD ORDER BY" +
" FCtgEn";
//
// CategoryOleDbCommand
//
this.CategoryOleDbCommand.CommandText = "SELECT DISTINCT FCtg , FCtgEn FROM FOOD;";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
|