public void Incluir(ModeloItensCompra modelo)
        {
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = conexao.ObjetoConexao;
                cmd.CommandText = "insert into itenscompra (itc_cod, itc_qtde, itc_valor, com_cod, pro_cod)" +
                                  "values(@cod, @qtde, @valor, @comCod, @proCod);";
                cmd.Parameters.AddWithValue("@cod", modelo.itc_cod);
                cmd.Parameters.AddWithValue("@qtde", modelo.itc_qtde);
                cmd.Parameters.AddWithValue("@valor", modelo.itc_valor);
                cmd.Parameters.AddWithValue("@comCod", modelo.com_cod);
                cmd.Parameters.AddWithValue("@proCod", modelo.pro_cod);

                conexao.Conectar();
                cmd.ExecuteNonQuery();
                conexao.Desconectar();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Example #2
0
        public void Incluir(ModeloCompra modeloCompra)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = conexao.ObjetoConexao;
            cmd.CommandText = "insert into compra(com_data, com_nfiscal, com_total, com_nparcelas, com_status, for_cod, tpa_cod)" +
                              " values (@data, @nfiscal, @total, @nparcelas, @status, @forcod, @tpacod); select @@IDENTITY;";
            cmd.Parameters.AddWithValue("@data", modeloCompra.com_data);
            cmd.Parameters.AddWithValue("@nfiscal", modeloCompra.com_nfiscal);
            cmd.Parameters.AddWithValue("@total", modeloCompra.com_total);
            cmd.Parameters.AddWithValue("@nparcelas", modeloCompra.com_nparcelas);
            cmd.Parameters.AddWithValue("@status", modeloCompra.com_status);
            cmd.Parameters.AddWithValue("@forcod", modeloCompra.for_cod);
            cmd.Parameters.AddWithValue("tpacod", modeloCompra.tpa_cod);

            conexao.Conectar();
            modeloCompra.com_cod = Convert.ToInt32(cmd.ExecuteScalar());
            conexao.Desconectar();
        }