private void btnCari_Click(object sender, EventArgs e) { var list = new LayananControl(); try { if (txtCari.Text != null && list.SearchLayanan(txtCari.Text) != null) { buttonUbah.Enabled = true; layanan = list.SearchLayanan(txtCari.Text); txtNamaLayanan.Text = layanan.Nama_Layanan; txtHargaLayanan.Text = System.Convert.ToString(layanan.Harga_Layanan); string connStr = "datasource=127.0.0.1;port=3306;username=root;password=;database=kouvee;Convert Zero Datetime=True;"; MySqlConnection conn = new MySqlConnection(connStr); string sqlukuran = "SELECT * FROM ukuran WHERE ID_UKURAN = '" + layanan.ID_Ukuran + "';"; string sqljenishewan = "SELECT * FROM jenis_hewan WHERE ID_JENISHEWAN = '" + layanan.ID_JenisHewan + "';"; conn.Open(); try { MySqlCommand cmd1 = new MySqlCommand(sqlukuran, conn); MySqlDataReader result1 = cmd1.ExecuteReader(); if (result1 != null) { while (result1.Read()) { comboBoxUkuran.Text = result1.GetString("Ukuran"); } } } catch (Exception ex) { Console.WriteLine("Failed to read..."); Console.WriteLine(ex.ToString()); } conn.Close(); conn.Open(); try { MySqlCommand cmd2 = new MySqlCommand(sqljenishewan, conn); MySqlDataReader result2 = cmd2.ExecuteReader(); if (result2 != null) { while (result2.Read()) { comboBoxJenisHewan.Text = result2.GetString("Jenishewan"); } } } catch (Exception ex) { Console.WriteLine("Failed to read..."); Console.WriteLine(ex.ToString()); } conn.Close(); txtNamaLayanan.Enabled = true; txtHargaLayanan.Enabled = true; comboBoxUkuran.Enabled = true; comboBoxJenisHewan.Enabled = true; } else { MessageBox.Show("Pencarian Tidak Ditemukan"); throw null; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
private void btnCari_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtCari.Text.Trim())) { MessageBox.Show("Text Pencarian Kosong"); throw null; } if (stat == "customer") { var ctrl = new CustomerControl(); if (ctrl.SearchCustomer(txtCari.Text) == null) { MessageBox.Show("Pencarian Tidak Ditemukan"); throw null; } else { List <Customer> CustomerList = new List <Customer>(); CustomerList.Add(ctrl.SearchCustomer(txtCari.Text)); dataGridViewTampil.DataSource = CustomerList; } } else if (stat == "hewan") { var ctrl = new HewanControl(); if (ctrl.SearchHewan(txtCari.Text) == null) { MessageBox.Show("Pencarian Tidak Ditemukan"); throw null; } else { List <Hewan> HewanList = new List <Hewan>(); HewanList.Add(ctrl.SearchHewan(txtCari.Text)); dataGridViewTampil.DataSource = HewanList; } } else if (stat == "jenishewan") { var ctrl = new JenisHewanControl(); if (ctrl.SearchJenisHewan(txtCari.Text) == null) { MessageBox.Show("Pencarian Tidak Ditemukan"); throw null; } else { List <JenisHewan> JenisHewanList = new List <JenisHewan>(); JenisHewanList.Add(ctrl.SearchJenisHewan(txtCari.Text)); dataGridViewTampil.DataSource = JenisHewanList; } } else if (stat == "layanan") { var ctrl = new LayananControl(); if (ctrl.SearchLayanan(txtCari.Text) == null) { MessageBox.Show("Pencarian Tidak Ditemukan"); throw null; } else { List <Layanan> LayananList = new List <Layanan>(); LayananList.Add(ctrl.SearchLayanan(txtCari.Text)); dataGridViewTampil.DataSource = LayananList; } } else if (stat == "pegawai") { var ctrl = new PegawaiControl(); if (ctrl.SearchPegawai(txtCari.Text) == null) { MessageBox.Show("Pencarian Tidak Ditemukan"); throw null; } else { List <Pegawai> PegawaiList = new List <Pegawai>(); PegawaiList.Add(ctrl.SearchPegawai(txtCari.Text)); dataGridViewTampil.DataSource = PegawaiList; } } else if (stat == "produk") { string connStr = "datasource=127.0.0.1;port=3306;username=root;password=;database=kouvee;Convert Zero Datetime=True;"; MySqlConnection conn = new MySqlConnection(connStr); string selectQuery = "SELECT * FROM produk WHERE NAMA_PRODUK = '" + txtCari.Text + "'"; MySqlCommand command = new MySqlCommand(selectQuery, conn); MySqlDataAdapter da = new MySqlDataAdapter(command); DataTable table = new DataTable(); da.Fill(table); if (table.Rows.Count == 0) { MessageBox.Show("Pencarian Tidak Ditemukan"); da.Dispose(); throw null; } else { dataGridViewTampil.DataSource = table; DataGridViewImageColumn imageColumn = new DataGridViewImageColumn(); imageColumn = (DataGridViewImageColumn)dataGridViewTampil.Columns[9]; dataGridViewTampil.Columns[8].Visible = false; imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch; da.Dispose(); } } else if (stat == "supplier") { var ctrl = new SupplierControl(); if (ctrl.SearchSupplier(txtCari.Text) == null) { MessageBox.Show("Pencarian Tidak Ditemukan"); throw null; } else { List <Supplier> SupplierList = new List <Supplier>(); SupplierList.Add(ctrl.SearchSupplier(txtCari.Text)); dataGridViewTampil.DataSource = SupplierList; } } else if (stat == "ukuranhewan") { var ctrl = new UkuranHewanControl(); if (ctrl.SearchUkuran(txtCari.Text) == null) { MessageBox.Show("Pencarian Tidak Ditemukan"); throw null; } else { List <UkuranHewan> UkuranHewanList = new List <UkuranHewan>(); UkuranHewanList.Add(ctrl.SearchUkuran(txtCari.Text)); dataGridViewTampil.DataSource = UkuranHewanList; } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }