/// <summary> /// Event handler to find a customer by their last name. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks> /// Possibly refactor to a seperate function. /// </remarks> protected void btnFindLastName_OnClick(object sender, EventArgs e) { // NMeggos // Define the location of the remote or local db. // Possibly refactor connection string assigned here to a global constant // configuration type property. var tempPath = Server.MapPath("~/App_Data/Accounts.mdb"); var dataLayerObj = new clsDataLayer(tempPath); try { var dsFindLastName = myBusinessLayer.FindCustomer(txtLastName.Text); // NMeggos // Check if the returned object has any records returned, // and assigned to the object. Else apply message to end-user, no records found. // If true, assign each control the returned value of the object. if (dsFindLastName.tblCustomers.Rows.Count > 0) { txtFirstName.Text = dsFindLastName.tblCustomers[0].FirstName; txtLastName.Text = dsFindLastName.tblCustomers[0].LastName; txtLine1.Text = dsFindLastName.tblCustomers[0].Address1; txtLine2.Text = dsFindLastName.tblCustomers[0].Address2; txtCity.Text = dsFindLastName.tblCustomers[0].City; txtState.Text = dsFindLastName.tblCustomers[0].State; txtPhone.Text = dsFindLastName.tblCustomers[0].PhoneNumber; lblCustomerId.Text = dsFindLastName.tblCustomers[0].CustomerID.ToString(); Master.UserFeedBack.Text = "Record Found."; } else { // NMeggos // If no record is found, display message to client Master.UserFeedBack.Text = "No records were found!"; } } catch (Exception ex) { // NMeggos // If an exception occurs, provide message to client. // Append the error message to the initial event message. var message = "Something went wrong: "; Master.UserFeedBack.Text = $@"{message} {ex.Message}"; } }
/// <summary> /// NMeggos /// Method that will be called on page load in the build page /// that will bind to the customer list grid. /// </summary> /// <returns></returns> private dsAccounts BindCustomerGridView() { // NMeggos // Path to the Access DB asset. // New instance of data layer object, passing the connection string for data access. string tempPath = Server.MapPath("~/App_Data/Accounts.mdb"); clsDataLayer myDataLayer = new clsDataLayer(tempPath); // NMeggos // Create a cache of the returned data set of customers. dsAccounts customerListing = myBusinessLayer.SelectAllCustomers(); // NMeggos // Bind the returned results assigned to customerListing // to gvCustomerList gvCustomerList.DataSource = customerListing.tblCustomers; gvCustomerList.DataBind(); // NMeggos // Create the cache object of the page Cache.Insert("CustomerDataSet", customerListing); return customerListing; }