コード例 #1
0
        private bool validateform()
        {
            bool output = true;
            int  hrg_jual = 0, min_qty = 0, cogs_awal = 0;
            bool valid_Hrg_Jual  = int.TryParse(Txt_Inv_Hrg_Jual.Text, out hrg_jual);
            bool valid_min_qty   = int.TryParse(Txt_Inv_Min_Qty.Text, out min_qty);
            bool valid_cogs_awal = int.TryParse(Txt_Inv_Cogs_Awal.Text, out cogs_awal);

            if (Txt_Inv_Nama.Text == "")
            {
                output = false;
                MessageBox.Show("Nama Barang harus diisi", "Perhatian", MessageBoxButtons.OK);
                Txt_Inv_Nama.Focus();
            }
            else
            if (!valid_Hrg_Jual)
            {
                output = false;
                MessageBox.Show("Hrg Jual salah", "Perhatian", MessageBoxButtons.OK);
                Txt_Inv_Hrg_Jual.Focus();
            }
            else
            if (!valid_min_qty)
            {
                output = false;
                MessageBox.Show("Qty Minimum salah", "Perhatian", MessageBoxButtons.OK);
                Txt_Inv_Min_Qty.Focus();
            }
            else
            if (!valid_cogs_awal)
            {
                output = false;
                MessageBox.Show("Hrg Pokok Awal salah", "Perhatian", MessageBoxButtons.OK);
                Txt_Inv_Cogs_Awal.Focus();
            }

            try
            {
                using (IDbConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[db].ConnectionString))
                {
                    var p = new DynamicParameters();
                    p.Add("@Inv_Id", inv_Id);
                    p.Add("@Inv_Nama", Txt_Inv_Nama.Text);

                    var Hitung = connection.ExecuteScalar <int>("dbo.SpInv_Cek_Nama", p, commandType: CommandType.StoredProcedure);
                    if (Hitung == 1)
                    {
                        output = false;
                        MessageBox.Show($"Nama Barang {Txt_Inv_Nama.Text} sudah ada", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        Txt_Inv_Nama.Focus();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(output);
        }
コード例 #2
0
 private void Txt_Qty_Awal_KeyPress(object sender, KeyPressEventArgs e)
 {
     e.Handled = !char.IsDigit(e.KeyChar) && e.KeyChar != (char)8;
     if (e.KeyChar == (char)13 || e.KeyChar == (char)9)
     {
         Txt_Inv_Awal.Text = string.Format("{0:n0}", double.Parse(Txt_Inv_Awal.Text));
         //var nilai_awal = double.Parse(Txt_Inv_Awal.Text) * double.Parse(Txt_Inv_Cogs_Awal.Text);
         var nilai_awal = Convert.ToInt32(Txt_Inv_Awal) * Convert.ToInt32(Txt_Inv_Cogs_Awal);
         lb_Nilai_awal.Text = nilai_awal.ToString();
         Txt_Inv_Cogs_Awal.Focus();
     }
 }