void Add() { //create an instance MyClassLibrary.clsCustomerCollection CustomerBook = new MyClassLibrary.clsCustomerCollection(); //validate the data on webform Boolean OK = CustomerBook.ThisCustomer.Valid(txtSalesmanCustomerAddress.Text, txtSalesmanCustomerEmail.Text, txtCustomerNumber.Text, txtSalesmanFirstName.Text, txtSalesmanLastName.Text, txtSalesmanCustomerPostCode.Text, txtSalesmanDateAddedOK.Text); //if data is okay then add to object if (OK == true) { //Fetch data entered by user CustomerBook.ThisCustomer.CustomerAddress = txtSalesmanCustomerAddress.Text; CustomerBook.ThisCustomer.CustomerEmail = txtSalesmanCustomerEmail.Text; CustomerBook.ThisCustomer.CustomerFirstName = txtSalesmanFirstName.Text; CustomerBook.ThisCustomer.CustomerLastName = txtSalesmanLastName.Text; CustomerBook.ThisCustomer.CustomerPostCodeOK = txtSalesmanCustomerPostCode.Text; CustomerBook.ThisCustomer.DateAddedOK = Convert.ToDateTime(txtSalesmanDateAddedOK.Text); CustomerBook.ThisCustomer.ActiveOK = chkSalesmanActiveOK.Checked; CustomerBook.ThisCustomer.CustomerNumber = txtCustomerNumber.Text; //add record CustomerBook.Add(); Response.Redirect("SalesmanHomepage.aspx"); lblSalesmanError.Text = "Customer successfully added"; } else { //report error lblSalesmanError.Text = "There were problems with the data you have entered, please try again"; } }
//function for adding new records void Add() { //create an instance of the customer store MyClassLibrary.clsCustomerCollection CustomerStore = new MyClassLibrary.clsCustomerCollection(); //validate the data on the web form string Error = CustomerStore.ThisCustomer.Valid(txtFirstName.Text, txtSurName.Text, txtStreet.Text, txtHouseNo.Text, txtPostCode.Text, txtPhoneNo.Text); //if the data is OK then add it to the object if (Error == "") { //get the data entered by the user CustomerStore.ThisCustomer.FirstName = txtFirstName.Text; CustomerStore.ThisCustomer.SurName = txtSurName.Text; CustomerStore.ThisCustomer.Street = txtStreet.Text; CustomerStore.ThisCustomer.HouseNo = txtHouseNo.Text; CustomerStore.ThisCustomer.PostCode = txtPostCode.Text; CustomerStore.ThisCustomer.PhoneNo = Convert.ToInt32(txtPhoneNo.Text); CustomerStore.ThisCustomer.Active = chkActive.Checked; CustomerStore.ThisCustomer.CountyNo = Convert.ToInt32(ddlCounty.SelectedValue); //add the record CustomerStore.Add(); //all done so redirect back to the main page Response.Redirect("Default.aspx"); } else { //report an error lblError.Text = "There were problem with the data entered" + Error; } }
void DisplayCustomers() { //create an instance of the customer collection MyClassLibrary.clsCustomerCollection Customer = new MyClassLibrary.clsCustomerCollection(); lstSalesmanBox.DataSource = Customer.CustomerList;////set the data dource to the list of customer in the collection ////set the name of the primary key lstSalesmanBox.DataValueField = "CustomerID"; ////set the data field to display lstSalesmanBox.DataTextField = "CustomerFirstName"; lstSalesmanBox.DataBind(); }
void DisplayCustomers() { //create an instance of the Customer Collection MyClassLibrary.clsCustomerCollection Customers = new MyClassLibrary.clsCustomerCollection(); //set the data source to the list of Customers in the collection lstCustomers.DataSource = Customers.CustomerList; //set the name of the primary key lstCustomers.DataValueField = "CustomerID"; //set the data field to display lstCustomers.DataTextField = "PostCode"; //bind the data to the list lstCustomers.DataBind(); }
void FilterCustomerAddress() { //create an instance of the customer collection MyClassLibrary.clsCustomerCollection Customer = new MyClassLibrary.clsCustomerCollection(); //set the data dource to the list of customer in the collection Customer.ThisCustomer.CustomerAddress = txtSalesmanAddress.Text; Customer.FilterByCustomerAddress(Customer.ThisCustomer.CustomerAddress); lstSalesmanBox.DataSource = Customer.CustomerList; //set the name of the primary key lstSalesmanBox.DataValueField = "CustomerID"; //set the data field to display lstSalesmanBox.DataTextField = "CustomerAddress"; lstSalesmanBox.DataBind(); }
void DisplayRecordData() { //fuction to display selected customer data CustomerID = Convert.ToInt32(Session["CustomerID"]); ////create an instance of the Customer addresses MyClassLibrary.clsCustomerCollection CustomerBook = new MyClassLibrary.clsCustomerCollection(); CustomerBook.ThisCustomer.Find(CustomerID);////find the record to update //display the data for the record txtSalesmanCustomerID.Text = Convert.ToString(CustomerBook.ThisCustomer.CustomerID); txtSalesmanCustomerAddress.Text = CustomerBook.ThisCustomer.CustomerAddress; txtSalesmanCustomerEmail.Text = CustomerBook.ThisCustomer.CustomerEmail; txtSalesmanFirstName.Text = CustomerBook.ThisCustomer.CustomerFirstName; txtSalesmanLastName.Text = CustomerBook.ThisCustomer.CustomerLastName; txtSalesmanCustomerPostCode.Text = CustomerBook.ThisCustomer.CustomerPostCodeOK; txtSalesmanDateAddedOK.Text = CustomerBook.ThisCustomer.DateAddedOK.ToString(); chkSalesmanActiveOK.Checked = CustomerBook.ThisCustomer.ActiveOK; txtCustomerNumber.Text = CustomerBook.ThisCustomer.CustomerNumber; }