Amrul Hakim

Amrul Hakim

  • NA
  • 19
  • 4k

How to display the messagebox if Qty "Stock It Out" c #

May 22 2017 1:31 PM
this my database Sql Server mines Qty
 
 
 
this my code C#
 
  1. private void btn_proses_Click(object sender, EventArgs e)  
  2.         {  
  3.             conn = Koneksi.Conn;  
  4.             try  
  5.             {  
  6.                 conn.Open();  
  7.                 cmd = new SqlCommand("INSERT INTO Tb_Transaksi VALUES ('" + txt_KodeTransaksi.Text + "', '" + cm_pilihBarang.SelectedItem.ToString() + "', '" + txt_jumlah.Text + "', '" + Datepicker1.Value.Date.ToString("M/d/yyyy") + "', '" + cm_select.SelectedItem.ToString() + "', '" + txt_mengetahui.Text + "', '" + txt_diketahui.Text + "', '" + txt_keterangan.Text + "', '" + cm_status.SelectedItem.ToString() + "' )", conn);  
  8.                 cmd.ExecuteNonQuery();  
  9.   
  10.                 if (cm_status.SelectedItem.ToString() == "Keluar")  
  11.                 {  
  12.                     cmd = new SqlCommand("UPDATE Tb_Barang SET Qty=Qty - '"+txt_jumlah.Text +"' WHERE Nama_Barang= '"+ cm_pilihBarang.SelectedItem.ToString() +"'", conn);  
  13.                     cmd.ExecuteNonQuery();  
  14.                 }  
  15.   
  16.                 if (cm_status.SelectedItem.ToString() == "Masuk")  
  17.                 {  
  18.                     cmd = new SqlCommand("UPDATE Tb_Barang SET Qty=Qty + '" + txt_jumlah.Text + "' WHERE Nama_Barang= '" + cm_pilihBarang.SelectedItem.ToString() + "'", conn);  
  19.                     cmd.ExecuteNonQuery();  
  20.                 }  
  21.                 MessageBox.Show("Data Telah Masuk");  
  22.   
  23.             }  
  24.             catch (Exception ex)  
  25.             {  
  26.                 MessageBox.Show("Erorr", ex.Message);  
  27.             }  
  28.             finally  
  29.             {  
  30.                 autokode_transaksi();  
  31.                 conn.Close();  
  32.                 Datagrid_Transaksi();  
  33.             }  
  34.         }  

Answers (3)

1
Nilesh Shah

Nilesh Shah

  • 13
  • 54.3k
  • 1.3m
May 22 2017 8:01 PM
you have posted all your code, but you did not tell us what problem you want to solve? what is not working in this code?
 
if you want to show some message based on some database value, then fetch its value using select query and show message.
 
what's special here you are asking?
0
Amrul Hakim

Amrul Hakim

  • 0
  • 19
  • 4k
May 23 2017 2:01 AM
[SOLVE}
0
Karthi Keyan

Karthi Keyan

  • 1k
  • 755
  • 239.8k
May 23 2017 12:12 AM
@Amrul,
      
   1st Your Database, 2nd Your Code. But Where is your 3rd one. I mean your need. you didn't ask what you want. then how we can give suggesstion. 
 
   By your  Keynote, you want to show messagebox if the stock is in minus or there is no stock. use condition to while load the item if there is no stock show the messagebox.