/// <summary> /// Sets datasources and bind data to controls. /// </summary> private void Bind() { // Retrieve orders via Customer Facade. CustomerController controller = new CustomerController(); GridViewOrders.DataSource = controller.GetCustomersWithOrderStatistics(SortExpression); GridViewOrders.DataBind(); }
/// <summary> /// Sets datasources and bind data to controls. /// </summary> private void Bind() { // Get customer via Customer Controller. CustomerController controller = new CustomerController(); ActionServiceReference.Customer customer = controller.GetCustomerWithOrders(CustomerId); // Set company name LabelHeader.Text = "<font color='black'>Orders for:</font> " + customer.Company + " (" + customer.Country + ")"; GridViewOrders.DataSource = customer.Orders; GridViewOrders.DataBind(); }
/// <summary> /// Deletes selected customer from database. /// </summary> protected void GridViewCustomers_RowDeleting(object sender, GridViewDeleteEventArgs e) { GridViewRow row = GridViewCustomers.Rows[e.RowIndex]; int customerId = int.Parse(row.Cells[0].Text); CustomerController controller = new CustomerController(); int rowsAffected = controller.DeleteCustomer(customerId); if (rowsAffected == 0) { string customerName = row.Cells[1].Text; LabelError.Text = "Cannot delete " + customerName + " because they have existing orders!"; } else { Bind(); } }
/// <summary> /// Saves data for new or edited customer to database. /// </summary> protected void ButtonSave_Click(object sender, EventArgs e) { CustomerController controller = new CustomerController(); ActionServiceReference.Customer customer; if (CustomerId == 0) customer = new ActionServiceReference.Customer(); else customer = controller.GetCustomer(CustomerId); // Get Company name from page. DetailsViewRow row = DetailsViewCustomer.Rows[1]; TextBox textBox = row.Cells[1].Controls[0] as TextBox; customer.Company = textBox.Text.Trim(); // Get City from page. row = DetailsViewCustomer.Rows[2]; textBox = row.Cells[1].Controls[0] as TextBox; customer.City = textBox.Text.Trim(); // Get Country from page. row = DetailsViewCustomer.Rows[3]; textBox = row.Cells[1].Controls[0] as TextBox; customer.Country = textBox.Text.Trim(); try { if (CustomerId == 0) controller.AddCustomer(customer); else controller.UpdateCustomer(customer); } catch (ApplicationException ex) { LabelError.Text = ex.Message.Replace(Environment.NewLine, "<br />"); LabelError.Visible = true; return; } // Return to list of customers. Response.Redirect("Customers.aspx"); }
/// <summary> /// Sets datasources and bind data. /// </summary> private void Bind() { CustomerController controller = new CustomerController(); GridViewCustomers.DataSource = controller.GetCustomers(SortExpression); GridViewCustomers.DataBind(); }