/** * method btnDoCreate_Click * inserts a new Customer with * the supplied parameters. * Little to no validation is being done. * NOTE: a new Customer always get a new Contact * timestamped with NOW * and a note saying "Created" */ protected void btnDoCreate_Click(object sender, EventArgs e) { Customer cu = new Customer(); int res = cu.insertCustomer(txtCreateFirstName.Text, txtCreateLastName.Text, txtCreatePhoneNumber.Text, txtCreateEmail.Text); if (res == 0) { //error lblError.Text = cu.errorMessage; lblError.Visible = true; } else { CustomerCollection cc = new CustomerCollection(); if (!cc.getAllCustomers()) { //error lblError.Text = cc.errorMessage; lblError.Visible = true; } else { //clear fields after success txtCreateFirstName.Text = ""; txtCreateLastName.Text = ""; txtCreatePhoneNumber.Text = ""; txtCreateEmail.Text = ""; txtSearchFirstName.Text = ""; txtSearchLastName.Text = ""; txtSearchPhoneNumber.Text = ""; txtSearchEmail.Text = ""; refreshCustomerList(cc); } } }
/** * method Page_Load * On load, default the new Contact DateTime to now * init the Customer for this page * Fill in the Customer name * Display the Contact List for this Customer */ protected void Page_Load(object sender, EventArgs e) { txtAddContactDateTime.Text = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(); Customer cu = new Customer(); if (! cu.initCustomer(int.Parse(Request.QueryString["customerid"].ToString()))) { //error lblError.Text = cu.errorMessage; lblError.Visible = true; } else { lblCustomerName.Text = cu.firstName + " " + cu.lastName; Repeater1.DataSource = cu.contacts; Repeater1.DataBind(); } }