private void buttonSimpan_Click(object sender, EventArgs e) { try { if (textBoxIdCustomer.Text != "" && textBoxNama.Text != "" && textBoxAlamat.Text != "" && textBoxNomerHp.Text != "") { int jumHurufNoHP = Regex.Matches(textBoxNomerHp.Text, @"[a-zA-Z]").Count; if (jumHurufNoHP > 0) { MessageBox.Show("Nilai Nomer HP Tidak Boleh Ada Huruf"); } else { // Ciptakan objek yg akan ditambahkan Customer c = new Customer(int.Parse(textBoxIdCustomer.Text), textBoxNama.Text, textBoxAlamat.Text, textBoxNomerHp.Text); // Panggil static method TambahData di class kategori string hasilTambah = Customer.TambahData(c); if (hasilTambah == "1") { MessageBox.Show("Customer telah tersimpan.", "Informasi"); frmDaftar.FormDaftarCustomer_Load(sender, e); FormTambahCustomer_Load(sender, e); } else { MessageBox.Show("Gagal menambah Customer. Pesan kesalahan: " + hasilTambah); } } } else { MessageBox.Show("Tolong isi semua nilai pada text box"); } } catch (Exception exc) { MessageBox.Show(exc.Message); } }
private void buttonHapus_Click(object sender, EventArgs e) { // Pastikan dulu kepada user apakah akan menghapus data DialogResult konfirmasi = MessageBox.Show("Data customer akan terhapus. Apakah Anda yakin ? ", "Konfirmasi", MessageBoxButtons.YesNo); if (konfirmasi == System.Windows.Forms.DialogResult.Yes) // Jika user yakin menghapus data { try { int id = int.Parse(textBoxIdCustomer.Text); string nama = textBoxNama.Text; string alamat = textBoxAlamat.Text; string nomerHp = textBoxNomerHp.Text; Customer c = new Customer(id, nama, alamat, nomerHp); // Panggil static method HapusData di class kategori string hasilHapus = Customer.HapusData(c); if (hasilHapus == "1") { MessageBox.Show("Customer telah dihapus.", "Informasi"); buttonKosongi_Click(sender, e); frmDaftar.FormDaftarCustomer_Load(sender, e); } else { MessageBox.Show("Gagal menghapus pelanggan. Pesan kesalahan : " + hasilHapus); } } catch (Exception exc) { MessageBox.Show(exc.Message); } } }