private void btnCari_Click(object sender, EventArgs e)
        {
            var list = new UkuranHewanControl();

            try
            {
                if (txtCari.Text != null && list.SearchUkuran(txtCari.Text) != null)
                {
                    buttonHapus.Enabled = true;

                    ukuranHewan         = list.SearchUkuran(txtCari.Text);
                    txtUkuranHewan.Text = ukuranHewan.Ukuran;
                }
                else
                {
                    MessageBox.Show("Pencarian Tidak Ditemukan");
                    throw null;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Beispiel #2
0
        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());
            }
        }