public Form_AddressBook(bool isSelectMode = false) { InitializeComponent(); currentState = isSelectMode ? AddressBookState.Select : AddressBookState.View; companies = new BindingList<Company>(); LoadPhoneNumberFormat(); LoadAddressBook(companies); customControl1.DataSource = companies; txtCompanyName.DataBindings.Add("Text", companies, "CompanyName"); txtPresident.DataBindings.Add("Text", companies, "President"); txtContact.DataBindings.Add("Text", companies, "Contact"); txtAddress1.DataBindings.Add("Text", companies, "Address1"); txtAddress2.DataBindings.Add("Text", companies, "Address2"); mtxtTel.DataBindings.Add("Text", companies, "Tel"); mtxtFax.DataBindings.Add("Text", companies, "Fax"); mtxtCellphone.DataBindings.Add("Text", companies, "Cellphone"); mtxtSerialNumber.DataBindings.Add("Text", companies, "SerialNumber"); cbbState.DataBindings.Add("Text", companies, "State"); cbbPhoneFormat.DataBindings.Add("SelectedIndex", companies, "PhoneFormatId"); UpdateControls(); }
public new DialogResult ShowDialog() { Cancel(); Hide(); currentState = AddressBookState.Select; return base.ShowDialog(); }
public new void Show() { currentState = AddressBookState.View; base.Show(); Focus(); }
void Cancel() { //Cancel all changes switch (currentState) { case AddressBookState.Add: companies.Remove(CurrentCompany); break; case AddressBookState.Modify: Company.Copy(modifyCompanyTemp, CurrentCompany); companies.ResetItem(customControl1.SelectedIndex); break; } currentState = AddressBookState.View; UpdateControls(); }
private void btnModify_Click(object sender, EventArgs e) { currentState = AddressBookState.Modify; modifyCompanyTemp = (Company)CurrentCompany.Clone(); UpdateControls(); }
private void btnConfirm_Click(object sender, EventArgs e) { if (txtCompanyName.Text == string.Empty) { txtCompanyName.Focus(); return; } //Submit all changes if (currentState == AddressBookState.Add) { using (var cmd = new System.Data.SQLite.SQLiteCommand(DataBase.Instance.sqlConnection)) { cmd.CommandText = "insert into AddressBook(CompanyName,President,Contact,Tel,Fax,Cellphone,Address1,Address2,SerialNumber,State,PhoneFormatId) values(@CompanyName,@President,@Contact,@Tel,@Fax,@Cellphone,@Address1,@Address2,@SerialNumber,@State,@PhoneFormatId); Select last_insert_rowid()"; System.Data.SQLite.SQLiteParameter[] parameters = new System.Data.SQLite.SQLiteParameter[11]; parameters[0] = new System.Data.SQLite.SQLiteParameter("CompanyName", txtCompanyName.Text); parameters[1] = new System.Data.SQLite.SQLiteParameter("President", txtPresident.Text); parameters[2] = new System.Data.SQLite.SQLiteParameter("Contact", txtContact.Text); parameters[3] = new System.Data.SQLite.SQLiteParameter("Tel", mtxtTel.Text); parameters[4] = new System.Data.SQLite.SQLiteParameter("Fax", mtxtFax.Text); parameters[5] = new System.Data.SQLite.SQLiteParameter("Cellphone", mtxtCellphone.Text); parameters[6] = new System.Data.SQLite.SQLiteParameter("Address1", txtAddress1.Text); parameters[7] = new System.Data.SQLite.SQLiteParameter("Address2", txtAddress2.Text); parameters[8] = new System.Data.SQLite.SQLiteParameter("SerialNumber", mtxtSerialNumber.Text); parameters[9] = new System.Data.SQLite.SQLiteParameter("State", cbbState.SelectedText); parameters[10] = new System.Data.SQLite.SQLiteParameter("PhoneFormatId", cbbPhoneFormat.SelectedIndex); cmd.Parameters.AddRange(parameters); long insertedId = (long)cmd.ExecuteScalar(); CurrentCompany.Id = (int)insertedId; } } else if (currentState == AddressBookState.Modify) { using (var cmd = new System.Data.SQLite.SQLiteCommand(DataBase.Instance.sqlConnection)) { cmd.Parameters.Add(cmd.CreateParameter()); cmd.CommandText = "update AddressBook set CompanyName = @CompanyName,President = @President,Contact = @Contact,Tel = @Tel,Fax = @Fax,Cellphone = @Cellphone,Address1 = @Address1,Address2 = @Address2, SerialNumber = @SerialNumber, State = @State, PhoneFormatId = @PhoneFormatId where Id = @Id"; System.Data.SQLite.SQLiteParameter[] parameters = new System.Data.SQLite.SQLiteParameter[12]; parameters[0] = new System.Data.SQLite.SQLiteParameter("CompanyName", txtCompanyName.Text); parameters[1] = new System.Data.SQLite.SQLiteParameter("President", txtPresident.Text); parameters[2] = new System.Data.SQLite.SQLiteParameter("Contact", txtContact.Text); parameters[3] = new System.Data.SQLite.SQLiteParameter("Tel", mtxtTel.Text); parameters[4] = new System.Data.SQLite.SQLiteParameter("Fax", mtxtFax.Text); parameters[5] = new System.Data.SQLite.SQLiteParameter("Cellphone", mtxtCellphone.Text); parameters[6] = new System.Data.SQLite.SQLiteParameter("Address1", txtAddress1.Text); parameters[7] = new System.Data.SQLite.SQLiteParameter("Address2", txtAddress2.Text); parameters[8] = new System.Data.SQLite.SQLiteParameter("Id", CurrentCompany.Id); parameters[9] = new System.Data.SQLite.SQLiteParameter("SerialNumber", mtxtSerialNumber.Text); parameters[10] = new System.Data.SQLite.SQLiteParameter("State", cbbState.Text); parameters[11] = new System.Data.SQLite.SQLiteParameter("PhoneFormatId", cbbPhoneFormat.SelectedIndex); cmd.Parameters.AddRange(parameters); cmd.ExecuteNonQuery(); } } currentState = AddressBookState.View; companies.ResetItem(customControl1.SelectedIndex); UpdateControls(); }
private void btnAdd_Click(object sender, EventArgs e) { currentState = AddressBookState.Add; Company newCompany = new Company(); companies.Add(newCompany); companies.ResetItem(companies.IndexOf(newCompany)); customControl1.SelectedItem = newCompany; UpdateControls(); }