Beispiel #1
0
 private void QueryData(string namaQuery = "")
 {
     try
     {
         this.dgvData.DataSource = null;
         IEnumerable <AddressBook> listData = null;
         using (DALAddressBookDapper dal = new DALAddressBookDapper())
         {
             listData = dal.QueryData(namaQuery);
         }
         if (listData != null && listData.Count() > 0)
         {
             this.dgvData.DataSource = listData;
             this.dgvData.Columns[0].DataPropertyName = nameof(AddressBook.No);
             this.dgvData.Columns[1].DataPropertyName = nameof(AddressBook.Nama);
             this.dgvData.Columns[2].DataPropertyName = nameof(AddressBook.Alamat);
             this.dgvData.Columns[3].DataPropertyName = nameof(AddressBook.Kota);
             this.dgvData.Columns[4].DataPropertyName = nameof(AddressBook.KodePos);
             this.dgvData.Columns[5].DataPropertyName = nameof(AddressBook.NomorHP);
             this.dgvData.Columns[6].DataPropertyName = nameof(AddressBook.Keterangan);
             this.dgvData.Columns[7].DataPropertyName = nameof(AddressBook.CreatedDate);
             this.dgvData.Columns[8].DataPropertyName = nameof(AddressBook.UpdatedDate);
             this.dgvData.Columns[9].DataPropertyName = nameof(AddressBook.Picture);
         }
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         this.dgvData_SelectionChanged(null, null);
     }
 }
Beispiel #2
0
 private void hapusDataToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (this.dgvData.CurrentRow != null)
     {
         if (MessageBox.Show("Hapus Data Ini ?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             int no = Convert.ToInt32(this.dgvData.CurrentRow.Cells[0].Value);
             try
             {
                 using (DALAddressBookDapper dal = new DALAddressBookDapper())
                 {
                     dal.Delete(no);
                 }
                 this.btnBatal_Click(null, null);
                 QueryData(this.txtNamaQuery.Text.Trim());
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
 }
Beispiel #3
0
 private void btnSimpan_Click(object sender, EventArgs e)
 {
     if (this.txtNama.Text.Trim() == "")
     {
         MessageBox.Show("Sorry, data nama tidak boleh kosong ...", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
         this.txtNama.Focus();
     }
     else if (this.txtAlamat.Text.Trim() == "")
     {
         MessageBox.Show("Sorry, data alamat tidak boleh kosong ...", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
         this.txtAlamat.Focus();
     }
     else if (this.txtKota.Text.Trim() == "")
     {
         MessageBox.Show("Sorry, data kota tidak boleh kosong ...", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
         this.txtKota.Focus();
     }
     else if (this.txtNomorHP.Text.Trim() == "")
     {
         MessageBox.Show("Sorry, data nomor hp tidak boleh kosong ...", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
         this.txtNomorHP.Focus();
     }
     else
     {
         AddressBook itemData = new AddressBook
         {
             Nama        = this.txtNama.Text.Trim(),
             Alamat      = this.txtAlamat.Text.Trim(),
             Kota        = this.txtKota.Text.Trim(),
             KodePos     = this.txtKodePos.Text.Trim(),
             NomorHP     = this.txtNomorHP.Text.Trim(),
             Keterangan  = this.txtKeterangan.Text.Trim(),
             Picture     = this.pictBox.Tag?.ToString() ?? "",
             CreatedDate = DateTime.Now,
             UpdatedDate = DateTime.Now
         };
         try
         {
             using (DALAddressBookDapper dal = new DALAddressBookDapper())
             {
                 if (!_editMode)
                 {
                     // create new
                     dal.Save(itemData);
                 }
                 else
                 {
                     // update
                     itemData.No = _no;
                     dal.Update(itemData);
                 }
             }
             this.btnBatal_Click(null, null);
             QueryData(this.txtNamaQuery.Text.Trim());
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }