public bool AddWarna(WarnaBarang warna)
        {
            bool result = false;

            query = "INSERT INTO warna_barang VALUES('" + warna.Id_warna_barang + "','" + warna.Nama_warna + "')";

            try
            {
                connect.Open();
                cmd = new MySqlCommand(query, connect);
                cmd.ExecuteNonQuery();
                result = true;
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message.ToString());
                result = false;
            }
            finally
            {
                connect.Close();
            }

            return result;
        }
        public bool UpdateWarna(WarnaBarang warna)
        {
            bool result = false;

            query = "UPDATE warna_barang SET nama_warna = '" + warna.Nama_warna + "' WHERE id_warna_barang = '" + warna.Id_warna_barang + "'";

            try
            {
                connect.Open();
                cmd = new MySqlCommand(query, connect);
                cmd.ExecuteNonQuery();
                result = true;
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message.ToString());
                result = false;
            }
            finally
            {
                connect.Close();
            }

            return result;
        }
Esempio n. 3
0
 private void btn_AddWarnaBarang_Click(object sender, EventArgs e)
 {
     if (txt_NamaWarnaBarang.TextLength > 0)
     {
         s_WarnaBarang = new WarnaBarang(Utils.ConcatMaxID(txt_IdWarnaBarang.Text.ToString(), txt_IdWarnaBarangNum.Text.ToString()), txt_NamaWarnaBarang.Text.ToString());
         if (s_MerekBarangManager.AddWarna(s_WarnaBarang))
         {
             MessageBox.Show("Data berhasil ditambah");
             txt_IdWarnaBarangNum.Text = Utils.DisplayMaxID(s_MerekBarangManager.GetMaxIDWarnaBarang().Substring((s_MerekBarangManager.GetMaxIDWarnaBarang().IndexOf("-")) + 1));
             ClearFieldWarna();
         }
         else
         {
             MessageBox.Show("Data gagal ditambah");
         }
     }
     else
     {
         MessageBox.Show("Mohon data-data dilengkapi");
     }
 }