private void lstCustomers_SelectedIndexChanged(object sender, EventArgs e) { try { if (loaded) { btnEdit.Enabled = true; if (lstCustomers.SelectedIndex != -1) { ClearForm(); SelectedCustomer = (lstCustomers.SelectedItem as cCustomer); txtName.Text = SelectedCustomer.Name; txtContactName.Text = SelectedCustomer.ContactFirstName + ' ' + SelectedCustomer.ContactLastName; txtContactNumber.Text = SelectedCustomer.ContactNumber; txtAddresss.Text = SelectedCustomer.Street + "\r\n" + SelectedCustomer.City + " " + SelectedCustomer.Prov + "\r\n" + SelectedCustomer.PostalCode; switch (SelectedCustomer.AccountType) { case "Visa": rdoVisa.Checked = true; break; case "Master Card": rdomasterCard.Checked = true; break; case "AmEx": rdoAmEx.Checked = true; break; default: rdoOther.Checked = true; txtCreditType.Text = SelectedCustomer.AccountType; break; } // end switch txtCardNumber.Text = SelectedCustomer.AccountNumber; txtCreditLimit.Text = SelectedCustomer.AccountLimit.ToString("c"); dtpExpDate.Value = SelectedCustomer.AccountExp; //creditCardExpiryControl1.Value = SelectedCustomer.AccountExp; chkCreditcheck.Checked = SelectedCustomer.CreditCheck; if (chkCreditcheck.Checked) { txtBank.Text = SelectedCustomer.BankName; txtBankAddress.Text = SelectedCustomer.BankStreet + "\r\n" + SelectedCustomer.BankCity + " " + SelectedCustomer.BankProv + "\r\n" + SelectedCustomer.BankPostalCode; txtBranch.Text = SelectedCustomer.Branch; txtBankContactName.Text = SelectedCustomer.BankContactName1 + " " + SelectedCustomer.BankContactName2; txtBankContactNumber.Text = SelectedCustomer.BankContactNumber; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } // end lstcustomers_selectedindexedchanged
private void cmbCustomers_SelectionChangeCommitted(object sender, EventArgs e) { foreach (object item in cmbCustomers.Items) { if (cmbCustomers.Text == (item as cCustomer).Name) { SelectedCustomer = (cCustomer)item; FillForm(); loadCustomerInfo(); } } FillForm(); }
public static cCustomer Create() { cCustomer cust = new cCustomer(); if (new StackFrame(1).GetMethod().ReflectedType.Name == "cCustomerSQL") { mTrusted = true; } else { mTrusted = false; } return(cust); }
private void FillForm() { cCustomer selected = (cCustomer)cmbCustomers.SelectedItem; txtCompName.Text = selected.Name; txtCardNo.Text = selected.AccountNumber; txtContactName.Text = selected.ContactFirstName + " " + selected.ContactLastName; txtContactNumber.Text = selected.ContactNumber; txtCreditLimit.Text = selected.AccountLimit.ToString("c2"); txtExpDate.Text = selected.AccountExp.ToString("d"); switch (selected.AccountType) { case "visa": { rdoVisa.Checked = true; break; } case "Master Card": { rdoMaster.Checked = true; break; } case "AmEx": { rdoAmEx.Checked = true; break; } default: { rdoOther.Checked = true; txtCreditType.Text = selected.AccountType; break; } } }
public frmRentals() { InitializeComponent(); SelectedCustomer = cCustomer.Create(); NewInvoice = cInvoice.Create(0.14M); }
private void btnSave_Click(object sender, EventArgs e) { bool reccount = false; cCustomer customer = cCustomer.Create(); try { if (formState == DatabseMode.Update) { customer.CustomerId = (int)lstCustomers.SelectedValue; } customer.Name = txtName.Text; string[] contactName = Regex.Split(txtContactName.Text, " "); customer.ContactFirstName = contactName[0]; customer.ContactLastName = contactName[1]; customer.ContactNumber = txtContactNumber.Text; string[] addresslines = Regex.Split(txtAddresss.Text, "\r\n"); string[] addresslines2 = Regex.Split(addresslines[1], " "); customer.Street = addresslines[0]; customer.City = addresslines2[0]; customer.Prov = addresslines2[1]; customer.PostalCode = addresslines[2]; customer.CreditCheck = chkCreditcheck.Checked; customer.AccountNumber = txtCardNumber.Text; foreach (Control ctl in grpCustomerDetails.Controls) { if (ctl is RadioButton) { if ((ctl as RadioButton).Checked) { if (ctl.Text == "Other (Specify)") { customer.AccountType = txtCreditType.Text; } else { customer.AccountType = ctl.Text; } } } } customer.AccountExp = dtpExpDate.Value; string creditLimit; if (txtCreditLimit.Text.StartsWith("$")) { creditLimit = txtCreditLimit.Text.Remove(0, 1); } else { creditLimit = txtCreditLimit.Text; } customer.AccountLimit = Convert.ToDecimal(creditLimit); if (customer.CreditCheck) { customer.BankName = txtBank.Text; customer.Branch = txtBranch.Text; string[] bankContact = Regex.Split(txtBankContactName.Text, " "); customer.BankContactName1 = bankContact[0]; customer.BankContactName2 = bankContact[1]; customer.BankContactNumber = txtBankContactNumber.Text; string[] bankaddress1 = Regex.Split(txtBankAddress.Text, "\r\n"); string[] bankaddress2 = Regex.Split(bankaddress1[1], " "); customer.BankStreet = bankaddress1[0]; customer.BankCity = bankaddress2[0]; customer.BankProv = bankaddress2[1]; customer.BankPostalCode = bankaddress1[2]; } switch (formState) { case DatabseMode.Update: reccount = cCustomerCU.Update(customer); break; case DatabseMode.Insert: reccount = cCustomerCU.Insert(customer); break; } // end switch if (reccount) { MessageBox.Show("Record has been saved."); formState = DatabseMode.None; // return form state to default } // end if else { throw new DataException("Error - Record not saved."); } formSetup(); } // end try catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } }