private void insertContact() { Obj.AddressBook obj = new Obj.AddressBook(); obj.txtPersonName = cbxContactPerson.Text; if (txtCompanyName.Text.Trim() == "") { obj.txtCompanyName = "na"; } else { obj.txtCompanyName = txtCompanyName.Text; } obj.txtMobileNo1 = txtMobileNo1.Text; obj.cboCatagoryId = Convert.ToInt32(this.cbxCategory.SelectedValue); if (this.cboCity.SelectedIndex < 1) { obj.City = ""; } else { obj.City = this.cboCity.Text; } new Bll.AddressBook().InsertContacts(obj); MessageBox.Show("This contact has been saved in contacts", "saved", MessageBoxButtons.OK, MessageBoxIcon.Information); }
//if (validationOfCtrls()) // { // if (this.btnSave.Text == "Save") // { // try // { // new Bll.MainWindow().InsertContacts(assignToObj()); // ctrlctrlClear(); // } // catch (Exception ex) // { // throw ex; // } // } // else if (this.btnSave.Text=="Update") // { // } // } private Obj.AddressBook assignToObj() { Obj.AddressBook obj = new Obj.AddressBook(); if (this.txtContactIdHiden.Text != string.Empty) { obj.txtContactId = Convert.ToInt32(this.txtContactIdHiden.Text); } else { obj.txtContactId = 0; } obj.cboCatagoryId = Convert.ToInt32(this.cbxCategory.SelectedValue); obj.txtPersonName = this.txtPersonName.Text; obj.txtCompanyName = this.txtCompanyName.Text; obj.txtMobileNo1 = this.txtMobileNo1.Text; obj.txtMobileNo2 = this.txtMobileNo2.Text; obj.txtLandlineNo1 = this.txtLandlineNo1.Text; obj.txtLandlineNo2 = this.txtLandlineNo2.Text; obj.txtHomeAddress = this.txtHomeAddress.Text; obj.txtOfficeAddress = this.txtOfficeAddress.Text; if (this.txtCity.Text.Trim() != "") { obj.City = this.txtCity.Text; } else { obj.City = ""; } return(obj); }
public void InsertContacts(Obj.AddressBook obj) { try { parameters.Add(new SqlParameter("@CategoryID", SqlDbType.TinyInt), obj.cboCatagoryId); parameters.Add(new SqlParameter("@PersonName", SqlDbType.VarChar, 50), obj.txtPersonName); parameters.Add(new SqlParameter("@CompanyName", SqlDbType.VarChar, 50), obj.txtCompanyName); parameters.Add(new SqlParameter("@MobileNo1", SqlDbType.VarChar, 20), obj.txtMobileNo1); parameters.Add(new SqlParameter("@MobileNo2", SqlDbType.VarChar, 20), obj.txtMobileNo2); parameters.Add(new SqlParameter("@LandlineNo1", SqlDbType.VarChar, 20), obj.txtLandlineNo1); parameters.Add(new SqlParameter("@LandlineNo2", SqlDbType.VarChar, 20), obj.txtLandlineNo2); parameters.Add(new SqlParameter("@HomeAddress", SqlDbType.VarChar, 200), obj.txtHomeAddress); parameters.Add(new SqlParameter("@OfficeAddress", SqlDbType.VarChar, 200), obj.txtOfficeAddress); if (obj.City == "") { parameters.Add(new SqlParameter("@City", SqlDbType.VarChar, 50), null); } else { parameters.Add(new SqlParameter("@City", SqlDbType.VarChar, 50), obj.City); } new Database().ExecuteNonQueryOnly("Sp_Insert_Contact", parameters); } catch (Exception ex) { //Sp_Update_Contact throw ex; } }
public void UpdateContacts(Obj.AddressBook obj) { try { new DAL.AddressBook().UpdateContacts(obj); } catch (Exception ex) { throw ex; } }