예제 #1
0
 private void IncluirCapsulas()
 {
     if (string.IsNullOrEmpty(tbxDescricao.Text))
     {
         MessageBox.Show("Digite uma descrição para a Cápsula!");
         tbxDescricao.Focus();
         return;
     }
     else if (cbxForca.SelectedIndex < 1)
     {
         MessageBox.Show("Escolha uma força para a Cápsula!");
         cbxForca.Focus();
         return;
     }
     else
     {
         try
         {
             Capsula capsula = new Capsula();
             capsula.Descricao = tbxDescricao.Text;
             capsula.Forca     = cbxForca.SelectedIndex;
             string result = capsula.IncluirCapsula(capsula);
             if (result == "ok")
             {
                 MessageBox.Show("Cápsula Inserida com sucesso!");
                 LimparFormulario();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("ERROR : " + ex.ToString());
             throw;
         }
     }
 }
예제 #2
0
        public string IncluirCapsula(Capsula capsula)
        {
            string result = "ok";

            try
            {
                Conexao conexao = new Conexao();
                using (NpgsqlConnection conn = new NpgsqlConnection(conexao.ConnString))
                {
                    conn.Open();
                    NpgsqlCommand cmd = new NpgsqlCommand();
                    cmd.Connection  = conn;
                    cmd.CommandText = "Insert into cafeteria.\"capsulas\" (descricao,forca) values (@descricao,@forca)";
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Add(new NpgsqlParameter("@descricao", capsula.Descricao));
                    cmd.Parameters.Add(new NpgsqlParameter("@forca", capsula.Forca));
                    cmd.ExecuteNonQuery();
                    cmd.Dispose();
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                return("ERROR : " + ex.ToString());
            }
            return(result);
        }
예제 #3
0
        private void PreencheCbxTipoDeCapsula()
        {
            Capsula   capsula   = new Capsula();
            DataTable dtCapsula = capsula.ListarCapsulas();

            cbxTipoDeCapsula.DataSource    = dtCapsula;
            cbxTipoDeCapsula.DisplayMember = "descricao";
            cbxTipoDeCapsula.ValueMember   = "capsula_id";
        }
예제 #4
0
 public void EditarCapsulas(Capsula capsula)
 {
 }