Exemplo n.º 1
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());
            }
        }
Exemplo n.º 2
0
        private void btnCari_Click(object sender, EventArgs e)
        {
            var list = new HewanControl();

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

                    hewan                     = list.SearchHewan(txtCari.Text);
                    txtNamaHewan.Text         = hewan.Nama_Hewan;
                    dateTimePickerHewan.Value = DateTime.Parse(hewan.Tgl_Lahir_Hewan);

                    string          connStr       = "datasource=127.0.0.1;port=3306;username=root;password=;database=kouvee;Convert Zero Datetime=True;";
                    MySqlConnection conn          = new MySqlConnection(connStr);
                    string          sqlpelanggan  = "SELECT * FROM pelanggan WHERE ID_PELANGGAN = '" + hewan.ID_Pelanggan + "';";
                    string          sqljenishewan = "SELECT * FROM jenis_hewan WHERE ID_JENISHEWAN = '" + hewan.ID_Jenis + "';";

                    conn.Open();
                    try
                    {
                        MySqlCommand    cmd1    = new MySqlCommand(sqlpelanggan, conn);
                        MySqlDataReader result1 = cmd1.ExecuteReader();
                        if (result1 != null)
                        {
                            while (result1.Read())
                            {
                                comboBoxNamaPelanggan.Text = result1.GetString("Nama_Pelanggan");
                            }
                        }
                    }
                    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();
                }
                else
                {
                    MessageBox.Show("Pencarian Tidak Ditemukan");
                    throw null;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }