private void BtnDeletar_Click(object sender, EventArgs e) { if (TxtNotaFiscal.Text == "") { MessageBox.Show("Favor Digitar Nº Nota Fiscal!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { try { conn.Open(); SqlCommand comando = new SqlCommand(@"DELETE FROM NotaFiscal where (NotaFiscalNumero='" + TxtNotaFiscal.Text + "')", conn); SqlCommand comandos = new SqlCommand(@"DELETE FROM NotaFiscalItens where (NFNumero='" + TxtNotaFiscal.Text + "')", conn); comando.CommandType = CommandType.Text; comandos.CommandType = CommandType.Text; comando.ExecuteNonQuery(); comandos.ExecuteNonQuery(); MessageBox.Show("Nota Fiscal Deletada com Sucesso!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("Erro ao Deletar Nota Fiscal! Tente Novamente", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Error); } } conn.Close(); LimpaCampos(); BtnFechaNota.Enabled = true; BtnInserirProduto.Enabled = true; BtnRemoverItem.Enabled = true; BtnDeletar.Enabled = false; TxtNotaFiscal.Focus(); }
private void TxtNotaFiscal_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { conn.Open(); if (TxtNotaFiscal.Text == "") { //TxtNotaFiscal.Focus(); //MessageBox.Show("Nenhum Código Digitado!"); } else { string cadSql = "SELECT totalnota,datalanc,datavenc,razaosocial,usuario from NotaFiscal inner join usuario on notafiscal.id_usuario=usuario.id_usuario inner join fornecedor on notafiscal.id_fornecedor=fornecedor.id_fornecedor where NotaFiscalNumero='" + TxtNotaFiscal.Text + "'"; SqlCommand comand = new SqlCommand(cadSql, conn); SqlDataReader ler = comand.ExecuteReader(); if (ler.Read() == true) { TxtTotalNota.Text = ler["TotalNota"].ToString(); CboFornecedor.Text = ler["razaosocial"].ToString(); DataVencNF.Text = ler["DataVenc"].ToString(); CmbCadPor.Text = ler["Usuario"].ToString(); ler.Close(); CarregaGrid(); BtnFechaNota.Enabled = false; BtnDeletar.Enabled = true; BtnRemoverItem.Enabled = false; BtnInserirProduto.Enabled = false; CboFornecedor.Enabled = false; CmbCadPor.Enabled = false; TxtProduto.Enabled = false; TxtQuant.Enabled = false; TxtPrecoCusto.Enabled = false; TxtTotalNota.Enabled = false; DataVencNF.Enabled = false; } else { TxtNotaFiscal.Clear(); LimpaCampos(); MessageBox.Show("Nota Fiscal Não Encontrada!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } conn.Close(); } }
private void LimpaCampos() { TxtNotaFiscal.Clear(); TxtTotalNota.Clear(); CboFornecedor.Text = "Selecione"; dgvProdutos.Rows.Clear(); TxtNotaFiscal.Focus(); BtnFechaNota.Enabled = true; LblTotalParcial.Text = ""; CboFornecedor.Enabled = true; TxtProduto.Enabled = true; TxtQuant.Enabled = true; TxtPrecoCusto.Enabled = true; TxtTotalNota.Enabled = true; DataVencNF.Enabled = true; CmbCadPor.Text = "Selecione"; CmbCadPor.Enabled = true; }
private void BtnFechaNota_Click(object sender, EventArgs e) { if (TxtNotaFiscal.Text == "") { MessageBox.Show("Falta Número Nota Fiscal!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning); TxtNotaFiscal.Focus(); } else if (TxtTotalNota.Text == "") { MessageBox.Show("Falta Total da Nota Fiscal!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning); TxtTotalNota.Focus(); } else if (CboFornecedor.Text == "" || CboFornecedor.Text == "Selecione") { MessageBox.Show("Selecione o Fornecedor!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning); CboFornecedor.Focus(); } else if (CmbCadPor.Text == "Selecione") { MessageBox.Show("Selecione o Usuário", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning); CmbCadPor.Focus(); } else if (dgvProdutos.RowCount == 0) { MessageBox.Show("Nenhum Item na Nota Fiscal!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning); TxtFabricante.Focus(); } else { try { conn.Open(); SqlCommand INSERIRNOTAFISCAL = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = "INSERT INTO NotaFiscal(NotaFiscalNumero,TotalNota,DataLanc,DataVenc,Id_Fornecedor,Id_Usuario) VALUES ('" + TxtNotaFiscal.Text + "','" + TxtTotalNota.Text.Replace(',', '.') + "','" + DateTime.Now + "','" + DataVencNF.Value.ToString("dd/MM/yyyy") + "',(select Id_Fornecedor from Fornecedor where fornecedor.RazaoSocial='" + CboFornecedor.Text + "'),(select id_usuario from usuario where usuario.usuario='" + CmbCadPor.Text + "'))", }; INSERIRNOTAFISCAL.ExecuteNonQuery(); SqlCommand INSERIRNOTAFISCALITENS = new SqlCommand { Connection = conn, CommandType = CommandType.Text, //CommandText = "insert into NotaFiscalItens values(1, 555, 'c#', 5.55, 1, 3)" CommandText = "INSERT INTO NotaFiscalItens VALUES (@Id_Produto,@Qtd,@Descricao,@PrecoUnitario,'" + Convert.ToInt16(TxtNotaFiscal.Text) + "',select notafiscal.id_notafiscal from NotaFiscal inner join notafiscalitens on notafiscal.Id_NotaFiscal=notafiscalitens.Id_NotaFiscal)", }; for (int i = 0; i < dgvProdutos.Rows.Count; i++) { INSERIRNOTAFISCALITENS.Parameters.Clear(); INSERIRNOTAFISCALITENS.Parameters.AddWithValue("@Id_Produto", dgvProdutos.Rows[i].Cells[0].Value); INSERIRNOTAFISCALITENS.Parameters.AddWithValue("@Qtd", dgvProdutos.Rows[i].Cells[4].Value); INSERIRNOTAFISCALITENS.Parameters.AddWithValue("@Descricao", dgvProdutos.Rows[i].Cells[2].Value); INSERIRNOTAFISCALITENS.Parameters.AddWithValue("@Precounitario", dgvProdutos.Rows[i].Cells[3].Value); INSERIRNOTAFISCALITENS.ExecuteNonQuery(); } INSERIRNOTAFISCALITENS.ExecuteNonQuery(); MessageBox.Show("Nota Fiscal Gravada com Sucesso!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Information); conn.Close(); LimpaCampos(); } catch { MessageBox.Show("Erro ao Gravar Nota Fiscal! Verifique.", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Error); } conn.Close(); } }