protected void btnSaveOrder_Click(object sender, EventArgs e) { //check the date entered is valid //if the data entered is valid and the customer name is not null or empty dateValidator.Validate(); if (dateValidator.IsValid && !string.IsNullOrEmpty(txtCustomerName.Text)) { //create new service instance //create new order and set the values equal to what is inside the text fields //update the existing order and let the user know of any changes var service = new CharityKitchenDataServiceSoapClient(); Order orderToUpdate = new Order(); orderToUpdate.OrderID = int.Parse(lblOrderID.Text); orderToUpdate.OrderCustomer = txtCustomerName.Text; orderToUpdate.OrderDate = DateTime.Parse(txtOrderDate.Text); int rowsAffected = service.UpdateExistingOrder(orderToUpdate); if (rowsAffected == 0) { lblChangesSaved.Text = string.Empty; lblErrorSaving.Text = "Error saving changes.."; } else { lblChangesSaved.Text = "Changes saved successfully."; lblErrorSaving.Text = string.Empty; } } else { //do not update order } }
protected void btnLogin_Click(object sender, EventArgs e) { var service = new CharityKitchenDataServiceSoapClient(); //bool authenticated = service.ValidateCredentials(txtUsername.Text, txtPassword.Text); //if (authenticated) //{ // FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, persist.Checked); //} //else //{ // lblLoginFailed.Text = "Invalid username and/or password.."; //} var user = service.ValidateLoginCredentials(txtUsername.Text, txtPassword.Text); if (string.IsNullOrEmpty(user.Username)) { lblLoginFailed.Text = "Invalid username and/or password.."; } else { FormsAuthentication.RedirectFromLoginPage(user.Username, persist.Checked); } }
protected void Page_Load(object sender, EventArgs e) { //get passed id from URL //set ID label text to the ID pulled //create new service instance //set the grid view data source to the ingredients in the meal selected string idFromQueryString = Request.QueryString["id"]; lblMealID.Text = idFromQueryString; var service = new CharityKitchenDataServiceSoapClient(); gvIngredientList.DataSource = service.GetIngredientsForMeal(int.Parse(lblMealID.Text)); gvIngredientList.DataBind(); //if page is not a post back: if (!Page.IsPostBack) { //get the meal that we are editing //populate the fields with the meal values //set the drop down list to contain all ingredients Meal meal = service.GetOneMeal(int.Parse(lblMealID.Text)); txtMealName.Text = meal.MealName; txtMealDesc.Text = meal.MealDescription; ddlIngredients.DataSource = service.GetAllIngredients(); ddlIngredients.DataTextField = "IngredientName"; ddlIngredients.DataValueField = "IngredientID"; ddlIngredients.DataBind(); } SetTotal(); }
protected void btnCreateUser_Click(object sender, EventArgs e) { var service = new CharityKitchenDataServiceSoapClient(); User userToCreate = new User(); userToCreate.UserName = txtUsername.Text; //userToCreate.UserPassword = txtPassword.Text; //implement hashing algorithm and salt text first //userToCreate.UserPassword = service.HashPassword("password"); userToCreate.UserPassword = "******"; int rowsAffected = 0; if (!string.IsNullOrEmpty(txtUsername.Text)) { rowsAffected = service.InsertNewUser(userToCreate); } if (rowsAffected == 0) { lblUserCreated.Text = string.Empty; lblUserError.Text = "Error creating user.."; } else { lblUserCreated.Text = "User created successfully."; lblUserError.Text = string.Empty; } txtUsername.Text = string.Empty; gvUserList.DataSource = null; gvUserList.DataSource = service.GetAllUsers(); gvUserList.DataBind(); }
protected void btnSaveMeal_Click(object sender, EventArgs e) { //create new service instance //create new meal and pass it the text field values var service = new CharityKitchenDataServiceSoapClient(); Meal mealToUpdate = new Meal(); mealToUpdate.MealID = int.Parse(lblMealID.Text); mealToUpdate.MealName = txtMealName.Text; mealToUpdate.MealDescription = txtMealDesc.Text; //if text fields are not null or empty: //update existing meal and let the user know of any changes int rowsAffected = 0; if (!string.IsNullOrEmpty(txtMealName.Text) && !string.IsNullOrEmpty(txtMealDesc.Text)) { rowsAffected = service.UpdateExistingMeal(mealToUpdate); } if (rowsAffected == 0) { lblChangesSaved.Text = string.Empty; lblErrorSaving.Text = "Error saving changes.."; } else { lblChangesSaved.Text = "Changes saved successfully."; lblErrorSaving.Text = string.Empty; } }
protected void btnSaveIngredient_Click(object sender, EventArgs e) { //create new service instance //create a new ingredient and fill it with the information to update var service = new CharityKitchenDataServiceSoapClient(); Ingredient ingredientToUpdate = new Ingredient(); ingredientToUpdate.IngredientID = int.Parse(lblIngredientID.Text); ingredientToUpdate.IngredientName = txtIngredientName.Text; ingredientToUpdate.IngredientPrice = decimal.Parse(txtIngredientPrice.Text); //if textfields are not null or empty, update ingredient and let the user know if the changes were successful or not int rowsAffected = 0; if (!string.IsNullOrEmpty(txtIngredientName.Text) && !string.IsNullOrEmpty(txtIngredientPrice.Text) && service.IsNumeric(txtIngredientPrice.Text)) { rowsAffected = service.UpdateExistingIngredient(ingredientToUpdate); } if (rowsAffected == 0) { lblChangesSaved.Text = string.Empty; lblErrorSaving.Text = "Error saving changes.."; } else { lblChangesSaved.Text = "Changes saved successfully."; lblErrorSaving.Text = string.Empty; } }
protected void Page_Load(object sender, EventArgs e) { var service = new CharityKitchenDataServiceSoapClient(); gvUserList.DataSource = service.GetAllUsers(); gvUserList.DataBind(); }
/// <summary> /// Event for when the "Delete" Button is clicked. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDelete_Click(object sender, EventArgs e) { // Get currently selected record's ID. int mealIngredientID = int.Parse(lblID.Text); if (mealIngredientID != 0) { // Tell DB to delete it. CharityKitchenDataServiceSoapClient svc = new CharityKitchenDataServiceSoapClient(); ServiceOperation operation = svc.DeleteMealIngredient(mealIngredientID); if (operation.Success) { lblInfo.ForeColor = System.Drawing.Color.DarkGreen; lblInfo.Text = operation.Message; // Refresh GridView if data was modified. GetMealIngredients(svc); } else { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = operation.Message + Environment.NewLine + operation.Exception; } } }
protected void ingredientList_SelectedIndexChanged(object sender, EventArgs e) { //create new service instance //get ID of selected ingredient //try to remove the ingredient from the list and let the user know of any changes var service = new CharityKitchenDataServiceSoapClient(); string idFromGridview = gvIngredientList.SelectedRow.Cells[0].Text; int id = int.Parse(idFromGridview); int rowsAffected = service.DeleteMealIngredient(id); if (rowsAffected == 0) { lblIngredientSuccessful.Text = string.Empty; lblIngredientError.Text = "Error deleting ingredient from meal.."; } else { lblIngredientSuccessful.Text = "Ingredient deleted from meal successfully."; lblIngredientError.Text = string.Empty; } //reset the datasources //set the totals gvIngredientList.DataSource = null; gvIngredientList.DataSource = service.GetIngredientsForMeal(int.Parse(lblMealID.Text)); gvIngredientList.DataBind(); SetTotal(); }
protected void gvMealList_SelectedIndexChanged(object sender, EventArgs e) { //create new insance of service //get id from selected meal in the order //try to delete the meal from the order and let the user know of any changes var service = new CharityKitchenDataServiceSoapClient(); string idFromGridview = gvMealList.SelectedRow.Cells[0].Text; int id = int.Parse(idFromGridview); int rowsAffected = service.DeleteOrderMeal(id); if (rowsAffected == 0) { lblMealSuccessful.Text = string.Empty; lblMealError.Text = "Error deleting meal from order.."; } else { lblMealSuccessful.Text = "Meal deleted from order successfully."; lblMealError.Text = string.Empty; } //rebind the datasource and set the total order cost gvMealList.DataSource = null; gvMealList.DataSource = service.GetMealsForOrder(int.Parse(lblOrderID.Text)); gvMealList.DataBind(); SetTotal(); }
protected void Page_Load(object sender, EventArgs e) { //get ID from URL and set label text to it //create new service instance //set the grid view to show the meals in an order string idFromQueryString = Request.QueryString["id"]; lblOrderID.Text = idFromQueryString; var service = new CharityKitchenDataServiceSoapClient(); gvMealList.DataSource = service.GetMealsForOrder(int.Parse(lblOrderID.Text)); gvMealList.DataBind(); //if page is not a post back if (!Page.IsPostBack) { //get an order based on the ID passed and set the text fields accordingly //set the drop down list to the list of meals Order order = service.GetOneOrder(int.Parse(lblOrderID.Text)); txtCustomerName.Text = order.OrderCustomer; txtOrderDate.Text = order.OrderDate.ToShortDateString(); ddlMeals.DataSource = service.GetAllMeals(); ddlMeals.DataTextField = "MealName"; ddlMeals.DataValueField = "MealID"; ddlMeals.DataBind(); } //set total cost of Order SetTotal(); }
/// <summary> /// Event for when the "Save" Button is clicked. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { // Some sanity checks for TextBox contents. if (txtMealName.Text == "") { lblInfo.ForeColor = System.Drawing.Color.DarkGreen; lblInfo.Text = "Please enter a name for the Meal."; return; } if (!txtMealName.Text.IsAlphaNumeric()) { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = "Meal Name is not allowed. Needs to be AlphaNumeric (Letters and numbers only). Please enter a valid Meal Name."; return; } // Bundle data from page controls into object to send to DB. Meal meal = new Meal(); try { meal.ID = int.Parse(lblMealID.Text); meal.Name = txtMealName.Text; } catch (Exception ex) { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = ex.Message; return; } // Send data to DB. CharityKitchenDataServiceSoapClient svc = new CharityKitchenDataServiceSoapClient(); ServiceOperation operation; if (meal.ID == 0) { operation = svc.AddMeal(meal); } else { operation = svc.UpdateMeal(meal); } if (operation.Success) { lblInfo.ForeColor = System.Drawing.Color.DarkGreen; lblInfo.Text = operation.Message; // Refresh GridView if data was modified. gvMeals.DataSource = svc.GetMeals().Data; gvMeals.DataBind(); } else { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = operation.Message + Environment.NewLine + operation.Exception; } }
protected void btnSaveCredentials_Click(object sender, EventArgs e) { //if old password, new password and confirmation password are not blank: if (!string.IsNullOrEmpty(txtOldPassword.Text) && !string.IsNullOrEmpty(txtNewPassword.Text) && !string.IsNullOrEmpty(txtConfirmPassword.Text)) { //create new server instance //create new user instance and validate his credentials var service = new CharityKitchenDataServiceSoapClient(); var user = service.ValidateLoginCredentials(Context.User.Identity.Name, txtOldPassword.Text); //if the returned username is not empty: if (!string.IsNullOrEmpty(user.Username)) { //update the user's password //let the user know if changes were successful or not User userToUpdate = service.GetOneUserByUsername(Context.User.Identity.Name); userToUpdate.UserPassword = txtConfirmPassword.Text; int rowsAffected = service.UpdateExistingUser(userToUpdate); if (rowsAffected == 0) { lblChangesSaved.Text = string.Empty; lblErrorSaving.Text = "Error saving changes.."; } else { lblChangesSaved.Text = "Changes saved successfully."; lblErrorSaving.Text = string.Empty; } } else { lblErrorSaving.Text = "Credentials entered were not valid.."; } } }
private void SetTotal() { //create new service instance //set the total cost of the meal with a calculation in the database var service = new CharityKitchenDataServiceSoapClient(); lblTotal.Text = service.GetTotalForMealIngredients(int.Parse(lblMealID.Text)).ToString("C"); }
private void SetTotal() { //create new service instance //set total cost of order through calculation done in database var service = new CharityKitchenDataServiceSoapClient(); lblTotal.Text = service.GetTotalForOrderMeals(int.Parse(lblOrderID.Text)).ToString("C"); }
/// <summary> /// Event ffor when the Save Button is clicked. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { // Some sanity checks for TextBox contents. if (txtUsername.Text == "") { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = "Please enter a Username."; return; } if (!txtUsername.Text.IsAlphaNumeric()) { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = "Username is not allowed. Needs to be AlphaNumeric (Letters and numbers only). Please enter a valid Username."; return; } // Bundle data from page controls into object to send to DB. UserIDNameCombo userCombo = new UserIDNameCombo(); try { userCombo.ID = int.Parse(lblUserID.Text); userCombo.Username = txtUsername.Text; } catch (Exception ex) { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = ex.Message; return; } if (userCombo.ID == 0) { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = "ID for existing User is somehow 0. THIS SHOULD NOT BE HAPPENING. Saving Halted."; return; } // Send object to DB. CharityKitchenDataServiceSoapClient svc = new CharityKitchenDataServiceSoapClient(); ServiceOperation operation = svc.UpdateUser(userCombo); if (operation.Success) { lblInfo.ForeColor = System.Drawing.Color.DarkGreen; lblInfo.Text = operation.Message; // Refresh GridView if data was modified. gvUsers.DataSource = svc.GetUserIDNameCombos().Data; gvUsers.DataBind(); } else { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = operation.Message + Environment.NewLine + operation.Exception; } }
/// <summary> /// Method to Get all the OrderMeals for a specified Oredr from the DB and display in a GridView on the page. /// </summary> /// <param name="svc">The Instantiated service objedct to use.</param> private void GetOrderMeals(CharityKitchenDataServiceSoapClient svc) { // get OrderID of Order-to-edit stored in Session data by Orders page. int orderID = 0; //default try { orderID = (int)Session["OrderToEdit_ID"]; } catch { Response.Redirect("~/Orders"); } // If OrderID is an actual ID, continue, else kick user back to Orders page. if (orderID != 0) { // Get data from DB. ServiceOperation operation = svc.GetOrderMeals(orderID); if (operation.Success) { // Display data on page. gvOrderMeals.DataSource = operation.Data; gvOrderMeals.DataBind(); lblOrderIDName.Text = orderID.ToString() + " - " + (string)Session["OrderToEdit_Name"]; // Prettyifying things, makes GridView display Order's name for user instead of ID. if (operation.Data.Count > 0) { gvOrderMeals.HeaderRow.Cells[3].Text = "MealName"; for (int i = 0; i < gvOrderMeals.Rows.Count; i++) { foreach (ListItem ml in meals) { if (ml.Value == gvOrderMeals.Rows[i].Cells[3].Text) { gvOrderMeals.Rows[i].Cells[3].Text = ml.Text; } } } } } else { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = operation.Message + Environment.NewLine + operation.Exception; } } else { Response.Redirect("~/Orders"); } }
/// <summary> /// Method to Get all the MealIngredients for a specified Meal from the DB and display in a GridView on the page. /// </summary> /// <param name="svc">The Instantiated service objedct to use.</param> private void GetMealIngredients(CharityKitchenDataServiceSoapClient svc) { // get MealID of Meal-to-edit stored in Session data by Meals page. int mealID = 0; //default try { mealID = (int)Session["MealToEdit_ID"]; } catch { Response.Redirect("~/Meals"); } // If MealID is an actual ID, continue, else kick user back to Meals page. if (mealID != 0) { // Get data from DB. ServiceOperation operation = svc.GetMealIngredients(mealID); if (operation.Success) { // Display data on page. lblMealName.Text = (string)Session["MealToEdit_Name"]; gvMealIngredients.DataSource = operation.Data; gvMealIngredients.DataBind(); // Prettyifying things, makes GridView display Ingredient's name for user instead of ID. if (operation.Data.Count > 0) { gvMealIngredients.HeaderRow.Cells[3].Text = "IngredientName"; for (int i = 0; i < gvMealIngredients.Rows.Count; i++) { foreach (ListItem ing in ingredients) { if (ing.Value == gvMealIngredients.Rows[i].Cells[3].Text) { gvMealIngredients.Rows[i].Cells[3].Text = ing.Text; } } } } } else { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = operation.Message + Environment.NewLine + operation.Exception; } } else { Response.Redirect("~/Meals"); } }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { return; } //create a new service instance //bind the orders to display to the grid view var service = new CharityKitchenDataServiceSoapClient(); gvOrderList.DataSource = service.GetOrdersToDisplay(); gvOrderList.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { //create new service instance //set meal grid view datasource to the meals to display //set ingredient grid view datasource to all the ingredients in the database var service = new CharityKitchenDataServiceSoapClient(); gvMealList.DataSource = service.GetMealsToDisplay(); gvMealList.DataBind(); gvIngredientList.DataSource = service.GetAllIngredients(); gvIngredientList.DataBind(); }
/// <summary> /// Default event for Page Load. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { // Get the User's Access Level for this page try { usersAccess = (int)Session["UsersAccess"]; } catch { Response.Redirect("~/Default"); } // If they have No Access to this page, kick them out. if (usersAccess < 1) { Response.Redirect("~/Default"); } // If they have only Read access, disable all saving controls. if (usersAccess < 2) { btnNewUser.Enabled = false; btnNewUserCreate.Enabled = false; btnPasswordReset.Enabled = false; btnSave.Enabled = false; } // Get the UserIDs and Usernames from DB (but NOT Passwords). CharityKitchenDataServiceSoapClient svc = new CharityKitchenDataServiceSoapClient(); ServiceOperation operation = svc.GetUserIDNameCombos(); // Bind data to GridView on page. if (operation.Success) { gvUsers.DataSource = operation.Data; gvUsers.DataBind(); } else { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = operation.Message; } // If UserID is 0 (meaning no User selected), disable Edit/Saving controls. if (int.Parse(lblUserID.Text) == 0) { btnSave.Enabled = false; btnUserRolesEdit.Enabled = false; } }
/// <summary> /// Default event for Page Load. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { // Get the User's Access Level for this page. int mealsAccess = 0; try { mealsAccess = (int)Session["MealsAccess"]; } catch { Response.Redirect("~/Default"); } // If they have No Access to this page, kick them out. if (mealsAccess < 1) { Response.Redirect("~/Default"); } // If they have only Read access, disable all saving controls. if (mealsAccess < 2) { btnNew.Enabled = false; btnSave.Enabled = false; } // Get Meals data from DB. CharityKitchenDataServiceSoapClient svc = new CharityKitchenDataServiceSoapClient(); ServiceOperation operation = svc.GetMeals(); // Bind data to GridView on page. if (operation.Success) { gvMeals.DataSource = operation.Data; gvMeals.DataBind(); } else { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = operation.Message; } // If no Meal is selected, disable "View/Edit Meal Contents" button. if (int.Parse(lblMealID.Text) == 0) { btnMealIngredientsEdit.Enabled = false; } }
//enable button if user has appropriate roles protected bool AuthorizedToView() { //if the user has the WAREHOUSE role, allow them to see the VIEW button var service = new CharityKitchenDataServiceSoapClient(); UserLogin user = service.GetLoggedInUserByUsername(Context.User.Identity.Name); if (user.Roles.Contains("Warehouse")) { return(true); } else { return(false); } }
//enable button if user has appropriate roles protected bool AuthorizedToEdit() { //if the user has the ADMIN role, allow them to see the EDIT button var service = new CharityKitchenDataServiceSoapClient(); UserLogin user = service.GetLoggedInUserByUsername(Context.User.Identity.Name); if (user.Roles.Contains("Admin")) { return(true); } else { return(false); } }
protected void Page_Load(object sender, EventArgs e) { //get ID passed from URL and get an order from the service using that ID //populate the labels for viewing string idFromQueryString = Request.QueryString["id"]; var service = new CharityKitchenDataServiceSoapClient(); var order = service.GetOneOrder(int.Parse(idFromQueryString)); lblOrderID.Text = order.OrderID.ToString(); lblCustomerName.Text = order.OrderCustomer; lblOrderDate.Text = order.OrderDate.ToShortDateString(); //set the list of ingredients by getting the list of ingredients for the current order gvIngredientList.DataSource = service.GetIngredientsForOrder(order.OrderID); gvIngredientList.DataBind(); }
/// <summary> /// Event for when the "Save" Button is clicked. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { // Bundle data from page controls into object to send to DB. MealIngredient mealIngredient = new MealIngredient(); try { int mealID = (int)Session["MealToEdit_ID"]; mealIngredient.ID = int.Parse(lblID.Text); mealIngredient.MealID = mealID; mealIngredient.IngredientID = int.Parse(ddlIngredients.SelectedValue); mealIngredient.RequiredQty = int.Parse(txtReqQty.Text); } catch (Exception ex) { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = ex.Message; return; } // Send data to DB. CharityKitchenDataServiceSoapClient svc = new CharityKitchenDataServiceSoapClient(); ServiceOperation operation = new ServiceOperation(); if (mealIngredient.ID == 0) { operation = svc.AddMealIngredient(mealIngredient); } else { operation = svc.UpdateMealIngredient(mealIngredient); } if (operation.Success) { lblInfo.ForeColor = System.Drawing.Color.DarkGreen; lblInfo.Text = operation.Message; // Refresh GridView if data was modified. GetMealIngredients(svc); } else { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = operation.Message; } }
/// <summary> /// Event for when the "Save" Button is clicked. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { // Bundle data from page controls into object to send to DB. UserRole userRole = new UserRole(); try { int userID = (int)Session["UserToEdit_ID"]; userRole.ID = int.Parse(lblUserRoleID.Text); userRole.UserID = userID; userRole.RoleID = int.Parse(ddlRoles.SelectedValue); userRole.AccessLevel = int.Parse(ddlAccesLevel.SelectedValue); } catch (Exception ex) { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = ex.Message; return; } // Send data to DB. CharityKitchenDataServiceSoapClient svc = new CharityKitchenDataServiceSoapClient(); ServiceOperation operation = new ServiceOperation(); if (userRole.ID == 0) { operation = svc.AddUserRole(userRole); } else { operation = svc.UpdateUserRole(userRole); } if (operation.Success) { lblInfo.ForeColor = System.Drawing.Color.DarkGreen; lblInfo.Text = operation.Message; // Refresh GridView if data was modified. GetUserRoles(svc); } else { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = operation.Message; } }
/// <summary> /// Default even for Page Load /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { // Get the User's Access Level for this page int usersAccess = 0; try { usersAccess = (int)Session["UsersAccess"]; } catch { Response.Redirect("~/Default"); } // If they have No Access to this page, kick them out. if (usersAccess < 1) { Response.Redirect("~/Default"); } // If they have only Read access, disable all saving controls. if (usersAccess < 2) { btnNew.Enabled = false; btnSave.Enabled = false; } CharityKitchenDataServiceSoapClient svc = new CharityKitchenDataServiceSoapClient(); // Get and store list of roles on page load. if (!PopulateRoles(svc)) { return; } if (IsPostBack) { return; } // if not a postback, setup DropDownLists and GridView with data from DB. BindRolesDDL(); BindAccessDDL(); GetUserRoles(svc); }
/// <summary> /// Default event for Page Load. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { // Get the User's Access Level for this page. int ordersAccess = 0; try { ordersAccess = (int)Session["OrdersAccess"]; } catch { Response.Redirect("~/Default"); } // If they have No Access to this page, kick them out. if (ordersAccess < 1) { Response.Redirect("~/Default"); } // If they have only Read access, disable all saving controls. if (ordersAccess < 2) { btnNew.Enabled = false; btnSave.Enabled = false; } // Get Meals data from DB. CharityKitchenDataServiceSoapClient svc = new CharityKitchenDataServiceSoapClient(); ServiceOperation operation = svc.GetOrders(); // Bind data to GridView on page. if (operation.Success) { gvOrders.DataSource = operation.Data; gvOrders.DataBind(); } else { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = operation.Message; } // Refresh the state of the "View/Edit Order Contents" button RefreshOrderMealEditBtn(); }
protected void Page_Load(object sender, EventArgs e) { //when page loads, grabbed the passed id value //set label to ID value //create new service instance string idFromQueryString = Request.QueryString["id"]; lblIngredientID.Text = idFromQueryString; var service = new CharityKitchenDataServiceSoapClient(); //if the page is not a post back: //get an ingredient and set the textfields if (!Page.IsPostBack) { Ingredient ingredient = service.GetOneIngredient(int.Parse(lblIngredientID.Text)); txtIngredientName.Text = ingredient.IngredientName; txtIngredientPrice.Text = ingredient.IngredientPrice.ToString(); } }