private void TxtNumVenda_Validated(object sender, EventArgs e) { MvVenda Vendas = new MvVenda(); Vendas.Controle = Controle; if (StaFormEdicao) { if (TxtNumVenda.Value > 0) { Vendas.LerDados(int.Parse(TxtNumVenda.Value.ToString())); if (Vendas.IdVenda == 0) { MessageBox.Show("Atenção: Venda não localizada", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); TxtNumVenda.Value = 0; } else { LstVendedor.SelectedValue = Vendas.IdVendedor.ToString(); SetaPessoa(Vendas.IdPessoa); TxtTelefone.Text = Vendas.Fone.Trim(); TxtEndereco.Text = Vendas.Endereco.Trim(); } } } }
private bool CancelaLocalEntrega(int IdVenda) { MvVenda Vendas = new MvVenda(); Vendas.Controle = Controle; Vendas.LerDados(IdVenda); // Conectando ao Servidor Origem da Venda SqlConnection ServidorOrigem; Filiais FilialOrigem = new Filiais(); FilialOrigem.Controle = Controle; FilialOrigem.LerDados(Vendas.IdFilialOrigem); if (FilialOrigem.ServidorRemoto == "") { MessageBox.Show("Atenção: Configuração do Servidor de Origem inválido", "Conclusão", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } try { string conexao = ""; conexao = "Data Source=" + FilialOrigem.ServidorRemoto + FilialOrigem.Porta + "; Initial Catalog=BD_ERP_SGE; User ID=talimpo; Password=systalimpo; MultipleActiveResultSets=True;"; ServidorOrigem = new SqlConnection(conexao); ServidorOrigem.Open(); } catch { MessageBox.Show("Atenção: Ocorreu um erro ao conectar ao servidor destino, tente novamente", "Conclusão", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } Funcoes ControleOrigem = new Funcoes(); ControleOrigem.Conexao = ServidorOrigem; MvVenda MvOrigem = new MvVenda(); MvOrigem.Controle = ControleOrigem; MvOrigem.LerDados(Vendas.IdVdOrigem); // if (MvOrigem.Status == 3) { MessageBox.Show("Solicite primeiro o Cancelamento da Entrega na Filial de Origem da Venda ", "Conclusão", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } return(true); }
private void BtnConcluir_Click(object sender, EventArgs e) { decimal Total = 0; bool TpDoc = false; for (int I = 0; I <= GridDados.RowCount - 1; I++) { Total = Total + decimal.Parse(GridDados.Rows[I].Cells[3].Value.ToString()); if (int.Parse(GridDados.Rows[I].Cells[4].Value.ToString()) == 0) { TpDoc = true; } } if (TpDoc) { MessageBox.Show("Favor informar o Tipo de Documento", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); GridDados.Focus(); return; } if (Math.Round(Total, 2) != Math.Round(TxtVlrTotal.Value, 2)) { MessageBox.Show("Soma das Parcela(s) diferente do total do movimento", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); GridDados.Focus(); } else { MvVenda Venda = new MvVenda(); Venda.Controle = Controle; Venda.LerDados(NumVd); if (Venda.Status == 2 && Venda.IdEntregador != 0 && !FechaPDV) { MessageBox.Show("Movimento já Faturado e em Rota", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (Venda.Status == 3) { MessageBox.Show("Movimento já Entregue", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (MessageBox.Show("Confirma o Fechamento do Movimento", "Confirmação", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { BtnConcluir.Enabled = false; FrmPrincipal.BSta_BarProcesso.Value = 0; FrmPrincipal.BSta_BarProcesso.Maximum = Source_Lanc.Count; // if (NumMov > 0) { Controle.ExecutaSQL("DELETE FROM LANCFINANCEIRO WHERE ID_MOV=" + NumMov.ToString()); } else if (NumVd > 0) { Controle.ExecutaSQL("DELETE FROM LANCFINANCEIRO WHERE ID_VENDA=" + NumVd.ToString()); } // Financeiro MvFinanc = new Financeiro(); Pessoas Pessoa = new Pessoas(); Pessoa.Controle = Controle; MvFinanc.Controle = Controle; Pessoa.LerDados(IdPessoa); // Processando os Dados for (int i = 0; i <= Source_Lanc.Count - 1; i++) { if (decimal.Parse(GridDados.Rows[i].Cells[3].Value.ToString()) > 0) { MvFinanc.LerDados(0); MvFinanc.PagRec = PagRec; MvFinanc.IdMov = NumMov; MvFinanc.IdVenda = NumVd; MvFinanc.IdPessoa = IdPessoa; if (IdFilial > 0) { MvFinanc.IdFilial = IdFilial; } else { MvFinanc.IdFilial = FrmPrincipal.Perfil_Usuario.IdFilial; } MvFinanc.Vencimento = DateTime.Parse(GridDados.Rows[i].Cells[2].Value.ToString()); MvFinanc.VlrOriginal = decimal.Parse(GridDados.Rows[i].Cells[3].Value.ToString()); MvFinanc.IdTipoDocumento = int.Parse(GridDados.Rows[i].Cells[4].Value.ToString()); MvFinanc.IdCusto = Pessoa.IdCusto; MvFinanc.IdDepartamento = Pessoa.IdDepartamento; MvFinanc.IdVendedor = Venda.IdVendedor; MvFinanc.IdFormaPgto = int.Parse(LstFormaPgto.SelectedValue.ToString()); MvFinanc.IdAgente = int.Parse(LstAgente.SelectedValue.ToString()); MvFinanc.NumDoc = NumDoc.Trim() + "/" + string.Format("{0:D2}", i + 1); MvFinanc.Referente = Referente; MvFinanc.NotaFiscal = NotaFiscal; MvFinanc.IdUsuLanc = FrmPrincipal.Perfil_Usuario.IdUsuario; MvFinanc.Observacao = Obs; MvFinanc.GravarDados(); if (FrmPgto.Baixa == 1 && FrmPrincipal.Perfil_Usuario.UsuCaixaLj == 1) { MvFinanc.DtBaixa = MvFinanc.Vencimento; MvFinanc.VlrBaixa = MvFinanc.VlrOriginal; MvFinanc.Baixar(); } } FrmPrincipal.BSta_BarProcesso.Value = FrmPrincipal.BSta_BarProcesso.Value + 1; } FrmPrincipal.BSta_BarProcesso.Value = 0; Concluido = true; Close(); } catch { MessageBox.Show("Ocorreu um erro ao tentar confirmar tente novamento", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); if (NumMov > 0) { Controle.ExecutaSQL("DELETE FROM LANCFINANCEIRO WHERE ID_MOV=" + NumMov.ToString()); } else if (NumVd > 0) { Controle.ExecutaSQL("DELETE FROM LANCFINANCEIRO WHERE ID_VENDA=" + NumVd.ToString()); } BtnConcluir.Enabled = true; FrmPrincipal.BSta_BarProcesso.Value = 0; } } } }
private void BtnBaixaAut_Click(object sender, EventArgs e) { Controles.ControleEstoque ControleEstoque = new ControleEstoque(); ControleEstoque.Controle = Controle; int IdCX = int.Parse(LstCaixa.SelectedValue.ToString()); if (GridVenda.CurrentRow == null) { MessageBox.Show("Não existe Registro para Confirmar", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (Cb_IncCx.Checked && IdCX == 0) { MessageBox.Show("Favor Selecionar o Caixa", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else { if (MessageBox.Show("Atenção: Apenas os movimentos faturamentos são confirmados, Confirma Baixa Geral de Entrega ?", "Confirmação", MessageBoxButtons.YesNo) == DialogResult.Yes) { SqlDataReader TabMapa; for (int I = 0; I <= GridVenda.Rows.Count - 1; I++) { int IdVenda = 0; IdVenda = int.Parse(GridVenda.Rows[I].Cells[0].Value.ToString()); decimal VlrVenda = decimal.Parse(GridVenda.Rows[I].Cells[6].Value.ToString()); TabMapa = Controle.ConsultaSQL("SELECT T2.STATUS FROM MapaEntregaItens T1 LEFT JOIN MAPAENTREGA T2 ON (T2.ID_MAPA=T1.ID_MAPA) WHERE T1.STATUS=0 AND T1.ID_VENDA=" + IdVenda.ToString()); if (TabMapa.HasRows) { TabMapa.Read(); if (TabMapa["STATUS"].ToString() == "0") { continue; } } if (IdCX > 0 && Cb_IncCx.Checked) { Controle.ExecutaSQL("Update MvVenda Set Id_Caixa=" + IdCX.ToString() + ",Status=3,DataConfirmacao=Convert(DateTime,'" + DateTime.Now.Date.ToShortDateString() + "',103) where Id_Venda=" + IdVenda.ToString()); } else { Controle.ExecutaSQL("Update MvVenda Set Status=3,DataConfirmacao=Convert(DateTime,'" + DateTime.Now.Date.ToShortDateString() + "',103) where Id_Venda=" + IdVenda.ToString()); } Controle.ExecutaSQL("DELETE FROM LANCFINANCEIRO WHERE ID_VENDA IN (SELECT ID_VENDA FROM MVVENDA WHERE TPVENDA='OE' AND VINCULOVD='" + string.Format("{0:D6}", IdVenda.ToString()) + "')"); Controle.ExecutaSQL("UPDATE MvVenda Set Faturado=1 Where VinculoVd='" + string.Format("{0:D6}", IdVenda.ToString()) + "'"); Controle.ExecutaSQL("Update MapaEntregaItens set Status=1 where Id_Venda=" + IdVenda.ToString() + " and Status=0"); //Verificando se credito um credito pro cliente if (VlrVenda < 0) { Controle.ExecutaSQL("UPDATE PESSOAS SET CREDITO=Round(CREDITO+" + Controle.FloatToStr(-1 * VlrVenda, 2) + ",2) WHERE ID_PESSOA=" + int.Parse(GridVenda.Rows[I].Cells[15].Value.ToString())); } //Atualizando o Troca de Estoque MvVenda Vendas = new MvVenda(); Vendas.Controle = Controle; Vendas.LerDados(IdVenda); if (Vendas.TpVenda == "TROCA") { if (Vendas.SemMovEst == 0) { SqlDataReader TabEntrada = Controle.ConsultaSQL("SELECT T1.*, '' AS NCM FROM MvVendaItens T1 WHERE T1.TipoItem='E' and T1.Id_Venda=" + Vendas.IdVenda.ToString()); if (TabEntrada.HasRows) { ControleEstoque.MovimentoEstoque(TabEntrada, 1, 1, false, Vendas.TpVenda, Vendas.Data, 0); } } } //Registrando Movimento de Auditoria FrmPrincipal.RegistrarAuditoria(this.Text, int.Parse(GridVenda.Rows[I].Cells[0].Value.ToString()), GridVenda.Rows[I].Cells[3].Value.ToString(), 7, "Confirmação da Entrega Automatica"); GridVenda.Rows[I].Cells[14].Value = "3"; GridVenda.Rows[I].Cells[2].Value = "Entregue"; } MessageBox.Show("Confirmação de Entrega Concluida", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void BtnCancMov_Click(object sender, EventArgs e) { int IdVenda = 0; IdVenda = int.Parse(GridVenda.CurrentRow.Cells[0].Value.ToString()); MvVenda Vendas = new MvVenda(); Vendas.Controle = Controle; if (GridVenda.CurrentRow == null) { MessageBox.Show("Não existe Registro para Confirmar", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (int.Parse(GridVenda.CurrentRow.Cells[14].Value.ToString()) != 3) { MessageBox.Show("Entrega não foi confirmada", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else if (GridVenda.CurrentRow.Cells[8].Value.ToString().Trim() == "") { MessageBox.Show("Entregador não informado", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (int.Parse(GridVenda.CurrentRow.Cells[14].Value.ToString()) == 3 && (GridVenda.CurrentRow.Cells[19].Value.ToString().Trim() != "AM" && GridVenda.CurrentRow.Cells[19].Value.ToString().Trim() != "BONIF")) { Vendas.LerDados(IdVenda); if (Vendas.IdCaixa > 0) { if (VerificaCaixa(Vendas.IdCaixa)) { MessageBox.Show("Movimento já Entregue e Caixa já fechado", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } } if (MessageBox.Show("Confirma o Cancelamento da Entrega ?", "Confirmação", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (int.Parse(GridVenda.CurrentRow.Cells[17].Value.ToString()) > 0) { if (!CancelaLocalEntrega(IdVenda)) { return; } } decimal VlrVenda = decimal.Parse(GridVenda.CurrentRow.Cells[6].Value.ToString()); Controle.ExecutaSQL("Update MvVenda Set ID_Entregador=0,Status=2, DataConfirmacao=Null where Id_Venda=" + IdVenda.ToString()); Controle.ExecutaSQL("UPDATE MvVenda Set Faturado=0 Where VinculoVd='" + string.Format("{0:D6}", IdVenda.ToString()) + "'"); Controle.ExecutaSQL("Update MapaEntregaItens set Status=2 where Id_Venda=" + IdVenda.ToString() + " and Status=1"); //Verificando se credito um credito pro cliente if (VlrVenda < 0 && int.Parse(GridVenda.CurrentRow.Cells[17].Value.ToString()) == 0) { Controle.ExecutaSQL("UPDATE PESSOAS SET CREDITO=Round(CREDITO-" + Controle.FloatToStr(-1 * VlrVenda, 2) + ",2) WHERE ID_PESSOA=" + int.Parse(GridVenda.CurrentRow.Cells[15].Value.ToString())); } //Atualizando o Troca de Estoque Vendas.LerDados(IdVenda); if (Vendas.TpVenda == "TROCA") { if (Vendas.SemMovEst == 0) { Controles.ControleEstoque ControleEstoque = new ControleEstoque(); ControleEstoque.Controle = Controle; SqlDataReader TabEntrada = Controle.ConsultaSQL("SELECT T2.* FROM MVVENDA T1 LEFT JOIN MVVENDAITENS T2 ON (T2.ID_VENDA=T1.ID_VENDA) WHERE T2.TipoItem='E' AND T1.ID_VDMASTER=" + Vendas.IdVdMaster.ToString()); if (TabEntrada.HasRows) { ControleEstoque.MovimentoEstoque(TabEntrada, 1, 2, false, Vendas.TpVenda, Vendas.Data, 0); } } } //Registrando Movimento de Auditoria FrmPrincipal.RegistrarAuditoria(this.Text, int.Parse(GridVenda.CurrentRow.Cells[0].Value.ToString()), GridVenda.CurrentRow.Cells[3].Value.ToString(), 7, "Cancelando a confirmação da Entrega"); MessageBox.Show("Entrega cancelada", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); GridVenda.CurrentRow.Cells[14].Value = "2"; GridVenda.CurrentRow.Cells[2].Value = "Faturado"; PopularGridVenda(); } } }
private bool ConfirmaLocalEntrega(int IdVenda) { MvVenda Vendas = new MvVenda(); Vendas.Controle = Controle; Vendas.LerDados(IdVenda); // Conectando ao Servidor Origem da Venda SqlConnection ServidorOrigem; Filiais FilialOrigem = new Filiais(); FilialOrigem.Controle = Controle; FilialOrigem.LerDados(Vendas.IdFilialOrigem); if (FilialOrigem.ServidorRemoto == "") { MessageBox.Show("Atenção: Configuração do Servidor de Origem inválido", "Conclusão", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } try { string conexao = ""; conexao = "Data Source=" + FilialOrigem.ServidorRemoto + FilialOrigem.Porta + "; Initial Catalog=BD_ERP_SGE; User ID=talimpo; Password=systalimpo; MultipleActiveResultSets=True;"; ServidorOrigem = new SqlConnection(conexao); ServidorOrigem.Open(); } catch { MessageBox.Show("Atenção: Ocorreu um erro ao conectar ao servidor destino, tente novamente", "Conclusão", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } Funcoes ControleOrigem = new Funcoes(); ControleOrigem.Conexao = ServidorOrigem; Controles.Verificar Verifica = new Verificar(); Verifica.Controle = ControleOrigem; int IdEntregador = Verifica.Verificar_ExisteCadastro("ID_ENTREGADOR", "SELECT ISNULL(ID_ENTREGADOR,0) AS ID_ENTREGADOR FROM PARAMETROS WHERE ID_FILIAL=" + Vendas.IdFilialEntrega.ToString()); if (IdEntregador == 0) { MessageBox.Show("Atenção: Entregador não configurado na Filial de Origem da Venda", "Conclusão", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } MvVenda MvOrigem = new MvVenda(); MvOrigem.Controle = ControleOrigem; MvOrigem.LerDados(Vendas.IdVdOrigem); // if (MvOrigem.Status == 2 || MvOrigem.Status == 3) { decimal VlrVenda = decimal.Parse(GridVenda.CurrentRow.Cells[6].Value.ToString()); if (MvOrigem.Status == 3 && Vendas.VlrTotal == 0) { ControleOrigem.ExecutaSQL("Update MvVenda Set Status=3,Id_Entregador=" + IdEntregador.ToString() + ", DataConfirmacao=Convert(DateTime,'" + Vendas.PrevEntrega.Date.ToShortDateString() + "',103) where Id_Venda=" + MvOrigem.IdVenda.ToString()); } else { ControleOrigem.ExecutaSQL("Update MvVenda Set Status=3,Id_Entregador=" + IdEntregador.ToString() + ", PrevEntrega=Convert(DateTime,'" + Vendas.PrevEntrega.Date.ToShortDateString() + "',103), DataConfirmacao=Convert(DateTime,'" + Vendas.PrevEntrega.Date.ToShortDateString() + "',103) where Id_Venda=" + MvOrigem.IdVenda.ToString()); } ControleOrigem.ExecutaSQL("UPDATE MvVenda Set Faturado=1 Where VinculoVd='" + string.Format("{0:D6}", MvOrigem.IdVenda.ToString()) + "'"); if (MvOrigem.TpVenda == "CO") { Controle.ExecutaSQL("UPDATE PESSOAS SET COMODATO=1 WHERE ID_PESSOA=" + MvOrigem.IdPessoa.ToString()); } if (MvOrigem.Status == 2 && VlrVenda < 0 && int.Parse(GridVenda.CurrentRow.Cells[17].Value.ToString()) == 0) { Controle.ExecutaSQL("UPDATE PESSOAS SET CREDITO=Round(CREDITO+" + Controle.FloatToStr(-1 * VlrVenda, 2) + ",2) WHERE ID_PESSOA=" + MvOrigem.IdPessoa.ToString()); } } return(true); }
private void Confirma_Entrega() { int IdCX = int.Parse(LstCaixa.SelectedValue.ToString()); if (GridVenda.CurrentRow == null) { MessageBox.Show("Não existe Registro para Confirmar", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { int IdVenda = 0; IdVenda = int.Parse(GridVenda.CurrentRow.Cells[0].Value.ToString()); if (int.Parse(GridVenda.CurrentRow.Cells[16].Value.ToString()) > 0 && int.Parse(GridVenda.CurrentRow.Cells[18].Value.ToString()) == 0) { MessageBox.Show("Solicite a Confirmação na Filial de Entrega", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (int.Parse(GridVenda.CurrentRow.Cells[14].Value.ToString()) == 3) { MessageBox.Show("Entrega ja confirmada", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); if (int.Parse(GridVenda.CurrentRow.Cells[17].Value.ToString()) > 0) { if (!ConfirmaLocalEntrega(IdVenda)) { return; } } } else if (GridVenda.CurrentRow.Cells[8].Value.ToString().Trim() == "") { MessageBox.Show("Entregador não informado", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (Cb_IncCx.Checked && IdCX == 0) { MessageBox.Show("Favor Selecionar o Caixa", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (IdCX > 0) { if (VerificaCaixa(IdCX)) { MessageBox.Show("Entrega não pode ser confirmada e incluida no caixa (caixa ja fechado)", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } if (int.Parse(GridVenda.CurrentRow.Cells[18].Value.ToString()) > 0) { if (VerificaCaixa(int.Parse(GridVenda.CurrentRow.Cells[18].Value.ToString()))) { MessageBox.Show("Entrega não pode ser confirmada, em um caixa ja fechado", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } //Verificando o Mapa de Entrega SqlDataReader TabMapa = Controle.ConsultaSQL("SELECT T2.STATUS FROM MapaEntregaItens T1 LEFT JOIN MAPAENTREGA T2 ON (T2.ID_MAPA=T1.ID_MAPA) WHERE T1.STATUS=0 AND T1.ID_VENDA=" + IdVenda.ToString()); if (TabMapa.HasRows) { TabMapa.Read(); if (TabMapa["STATUS"].ToString() == "0") { MessageBox.Show("Mapa de Entrega não foi Concluido", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } string TpVd = GridVenda.CurrentRow.Cells[19].Value.ToString().Trim(); if (int.Parse(GridVenda.CurrentRow.Cells[14].Value.ToString()) != 2 && (TpVd == "PV" || TpVd == "TROCA" || TpVd == "OE" || TpVd == "AM")) { MessageBox.Show("Atenção: Movimento não Faturado", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (MessageBox.Show("Confirma a Entrega ?", "Confirmação", MessageBoxButtons.YesNo) == DialogResult.Yes) { //Atualizando o Troca de Estoque MvVenda Vendas = new MvVenda(); Vendas.Controle = Controle; Vendas.LerDados(IdVenda); if (Vendas.TpVenda != "PV" && Vendas.TpVenda != "TROCA" && IdCX > 0) { MessageBox.Show("Atenção: Esse movimento não pode ser incluido no caixa", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } decimal VlrVenda = decimal.Parse(GridVenda.CurrentRow.Cells[6].Value.ToString()); if (int.Parse(GridVenda.CurrentRow.Cells[17].Value.ToString()) > 0) { if (!ConfirmaLocalEntrega(IdVenda)) { return; } } if (IdCX > 0 && Cb_IncCx.Checked) { Controle.ExecutaSQL("Update MvVenda Set Id_Caixa=" + IdCX.ToString() + ",Status=3,DataConfirmacao=Convert(DateTime,'" + DateTime.Now.Date.ToShortDateString() + "',103),PrevEntrega=Convert(DateTime,'" + DateTime.Now.Date.ToShortDateString() + "',103) where Id_Venda=" + IdVenda.ToString()); } else { Controle.ExecutaSQL("Update MvVenda Set Status=3,DataConfirmacao=Convert(DateTime,'" + DateTime.Now.Date.ToShortDateString() + "',103) where Id_Venda=" + IdVenda.ToString()); } Controle.ExecutaSQL("DELETE FROM LANCFINANCEIRO WHERE ID_VENDA IN (SELECT ID_VENDA FROM MVVENDA WHERE TPVENDA='OE' AND VINCULOVD='" + string.Format("{0:D6}", IdVenda.ToString()) + "')"); Controle.ExecutaSQL("UPDATE MvVenda Set Faturado=1 Where VinculoVd='" + string.Format("{0:D6}", IdVenda.ToString()) + "'"); Controle.ExecutaSQL("Update MapaEntregaItens set Status=1 where Id_Venda=" + IdVenda.ToString() + " and Status=0"); //Verificando se credito um credito pro cliente if (VlrVenda < 0 && int.Parse(GridVenda.CurrentRow.Cells[17].Value.ToString()) == 0) { Controle.ExecutaSQL("UPDATE PESSOAS SET CREDITO=Round(CREDITO+" + Controle.FloatToStr(-1 * VlrVenda, 2) + ",2) WHERE ID_PESSOA=" + int.Parse(GridVenda.CurrentRow.Cells[15].Value.ToString())); } if (Vendas.TpVenda == "CO") { Controle.ExecutaSQL("UPDATE PESSOAS SET COMODATO=1 WHERE ID_PESSOA=" + Vendas.IdPessoa.ToString()); } if (Vendas.TpVenda == "TROCA") { if (Vendas.SemMovEst == 0) { Controles.ControleEstoque ControleEstoque = new ControleEstoque(); ControleEstoque.Controle = Controle; SqlDataReader TabEntrada = Controle.ConsultaSQL("SELECT T1.*, '' AS NCM FROM MvVendaItens T1 WHERE T1.TipoItem='E' and T1.Id_Venda=" + Vendas.IdVenda.ToString()); if (TabEntrada.HasRows) { ControleEstoque.MovimentoEstoque(TabEntrada, 1, 1, false, Vendas.TpVenda, Vendas.Data, 0); } } } //Registrando Movimento de Auditoria FrmPrincipal.RegistrarAuditoria(this.Text, int.Parse(GridVenda.CurrentRow.Cells[0].Value.ToString()), GridVenda.CurrentRow.Cells[3].Value.ToString(), 7, "Confirmação da Entrega"); MessageBox.Show("Entrega confirmada", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); GridVenda.CurrentRow.Cells[14].Value = "3"; GridVenda.CurrentRow.Cells[2].Value = "Entregue"; //PopularGridVenda(); } } } }
private void BtnConfirmar_Click(object sender, EventArgs e) { if (TxtIdVenda.Value > 0) { if (int.Parse(LstFilial.SelectedValue.ToString()) == FrmPrincipal.IdFilialConexao) { Vendas.LerDados(int.Parse(TxtIdVenda.Value.ToString())); if (Vendas.IdVenda == 0) { MessageBox.Show("Venda não localizada", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } if (MessageBox.Show("Confirma a liberação", "Confirmação", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (LiberaPrd) { SqlDataReader Tabela; Tabela = Controle.ConsultaSQL("SELECT * FROM LiberacaoProduto WHERE Id_Filial=" + LstFilial.SelectedValue.ToString() + "and Id_Venda=" + TxtIdVenda.Value.ToString() + " and Id_Produto=" + IdProduto.ToString()); if (Tabela.HasRows) { Controle.ExecutaSQL("Update LiberacaoProduto Set Id_Filial=" + LstFilial.SelectedValue.ToString() + ", Id_Usuario=" + FrmPrincipal.Perfil_Usuario.IdUsuario.ToString() + ",Data=Convert(DateTime,'" + DateTime.Now.Date.ToShortDateString() + "',103),Estoque=" + Controle.FloatToStr(Saldo, 3) + " Where Id_Venda=" + TxtIdVenda.Value.ToString() + " and Id_Produto=" + IdProduto.ToString()); } else { Controle.ExecutaSQL("Insert into LiberacaoProduto (Id_Venda,Id_Produto,Id_Usuario,Data,Id_Filial,Estoque) Values (" + TxtIdVenda.Value.ToString() + "," + IdProduto.ToString() + "," + FrmPrincipal.Perfil_Usuario.IdUsuario.ToString() + ",Convert(DateTime,'" + DateTime.Now.Date.ToShortDateString() + "',103)," + LstFilial.SelectedValue.ToString() + "," + Controle.FloatToStr(Saldo, 3) + ")"); } MessageBox.Show("liberação concluida", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } else { if (int.Parse(LstFilial.SelectedValue.ToString()) == FrmPrincipal.IdFilialConexao) { Vendas.LerDados(int.Parse(TxtIdVenda.Value.ToString())); if (Rb_Financeira.Checked) { Vendas.SetaAutDebito(FrmPrincipal.Perfil_Usuario.IdUsuario, TxtVlrLiberado.Value); } else if (Rb_Parcela.Checked) { Vendas.SetaAutParcelas(FrmPrincipal.Perfil_Usuario.IdUsuario, Ck_NaoPrzPg.Checked); } else if (Rb_PessoaF.Checked) { Vendas.SetaAutPessoaF(FrmPrincipal.Perfil_Usuario.IdUsuario, Ck_NaoPrzPg.Checked); } else if (Rb_PrimeiraCompra.Checked) { Vendas.SetaAutPrimeira(FrmPrincipal.Perfil_Usuario.IdUsuario, Ck_NaoPrzPg.Checked); } else { Vendas.SetaAutDebito(FrmPrincipal.Perfil_Usuario.IdUsuario, TxtVlrLiberado.Value); Vendas.SetaAutParcelas(FrmPrincipal.Perfil_Usuario.IdUsuario, Ck_NaoPrzPg.Checked); Vendas.SetaAutPessoaF(FrmPrincipal.Perfil_Usuario.IdUsuario, Ck_NaoPrzPg.Checked); Vendas.SetaAutPrimeira(FrmPrincipal.Perfil_Usuario.IdUsuario, Ck_NaoPrzPg.Checked); } MessageBox.Show("Liberação concluida", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } else { SqlConnection ServidorDestino; Filiais FilialDest = new Filiais(); FilialDest.Controle = Controle; FilialDest.LerDados(int.Parse(LstFilial.SelectedValue.ToString())); if (FilialDest.ServidorRemoto == "") { MessageBox.Show("Atenção: Configuração do Servidor Destino inválida", "Conclusão", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { string conexao = ""; conexao = "Data Source=" + FilialDest.ServidorRemoto + FilialDest.Porta + "; Initial Catalog=BD_ERP_SGE; User ID=talimpo; Password=systalimpo; MultipleActiveResultSets=True;"; ServidorDestino = new SqlConnection(conexao); ServidorDestino.Open(); } catch { MessageBox.Show("Atenção: Ocorreu um erro ao conectar ao servidor destino, tente novamente", "Conclusão", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Funcoes ControleDest = new Funcoes(); ControleDest.Conexao = ServidorDestino; MvVenda VendaDest = new MvVenda(); VendaDest.Controle = ControleDest; VendaDest.LerDados(int.Parse(TxtIdVenda.Value.ToString())); if (VendaDest.IdVenda == 0) { MessageBox.Show("Venda não localizada", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (Rb_Financeira.Checked) { VendaDest.SetaAutDebito(FrmPrincipal.Perfil_Usuario.IdUsuario, TxtVlrLiberado.Value); } else if (Rb_Parcela.Checked) { VendaDest.SetaAutParcelas(FrmPrincipal.Perfil_Usuario.IdUsuario, Ck_NaoPrzPg.Checked); } else if (Rb_PessoaF.Checked) { VendaDest.SetaAutPessoaF(FrmPrincipal.Perfil_Usuario.IdUsuario, Ck_NaoPrzPg.Checked); } else if (Rb_PrimeiraCompra.Checked) { VendaDest.SetaAutPrimeira(FrmPrincipal.Perfil_Usuario.IdUsuario, Ck_NaoPrzPg.Checked); } else { VendaDest.SetaAutDebito(FrmPrincipal.Perfil_Usuario.IdUsuario, TxtVlrLiberado.Value); VendaDest.SetaAutParcelas(FrmPrincipal.Perfil_Usuario.IdUsuario, Ck_NaoPrzPg.Checked); VendaDest.SetaAutPessoaF(FrmPrincipal.Perfil_Usuario.IdUsuario, Ck_NaoPrzPg.Checked); VendaDest.SetaAutPrimeira(FrmPrincipal.Perfil_Usuario.IdUsuario, Ck_NaoPrzPg.Checked); } MessageBox.Show("Liberação concluida", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } }
protected void BtnEnviar_Click(object sender, EventArgs e) { if (BtnEnviar.Enabled) { if (TabItens.Rows.Count == 0) { return; } BtnEnviar.Enabled = false; try { decimal VlrTotal = 0; for (int I = 0; I <= TabItens.Rows.Count - 1; I++) { VlrTotal = VlrTotal + decimal.Parse(TabItens.Rows[I]["VLRTOTAL"].ToString()); } MvVenda Venda = new MvVenda(); Venda.Controle = Controle; Venda.LerDados(0); // if (LstTpPedido.SelectedIndex == 1) { Venda.TpVenda = "EMVF"; } else { Venda.TpVenda = "PI"; } Venda.IdFilial = ((Controle_Dados.Pessoas)(((System.Web.UI.UserControl)(this.Master)).Session["LoginUsuario"])).IdFilial; Venda.IdVendedor = ((Controle_Dados.Pessoas)(((System.Web.UI.UserControl)(this.Master)).Session["LoginUsuario"])).IdVendedor; Venda.IdPessoa = ((Controle_Dados.Pessoas)(((System.Web.UI.UserControl)(this.Master)).Session["LoginUsuario"])).IdPessoa; Venda.IdFormaPgto = 0; // int.Parse(LstFormaPgto.SelectedValue.ToString()); Venda.Observacao = TxtObs.Text; Venda.VlrSubTotal = VlrTotal; Venda.VlrTotal = VlrTotal; Venda.NmPessoa = ((Controle_Dados.Pessoas)(((System.Web.UI.UserControl)(this.Master)).Session["LoginUsuario"])).RazaoSocial; Venda.CnpjCpf = ((Controle_Dados.Pessoas)(((System.Web.UI.UserControl)(this.Master)).Session["LoginUsuario"])).Cnpj; Venda.Endereco = ((Controle_Dados.Pessoas)(((System.Web.UI.UserControl)(this.Master)).Session["LoginUsuario"])).Endereco; Venda.InscUF = ((Controle_Dados.Pessoas)(((System.Web.UI.UserControl)(this.Master)).Session["LoginUsuario"])).InscUF; Venda.Cep = ((Controle_Dados.Pessoas)(((System.Web.UI.UserControl)(this.Master)).Session["LoginUsuario"])).Cep; Venda.Numero = ((Controle_Dados.Pessoas)(((System.Web.UI.UserControl)(this.Master)).Session["LoginUsuario"])).Numero; Venda.Complemento = ((Controle_Dados.Pessoas)(((System.Web.UI.UserControl)(this.Master)).Session["LoginUsuario"])).Complemento; Venda.Bairro = ((Controle_Dados.Pessoas)(((System.Web.UI.UserControl)(this.Master)).Session["LoginUsuario"])).Bairro; Venda.Cidade = ((Controle_Dados.Pessoas)(((System.Web.UI.UserControl)(this.Master)).Session["LoginUsuario"])).Cidade; Venda.IdUF = ((Controle_Dados.Pessoas)(((System.Web.UI.UserControl)(this.Master)).Session["LoginUsuario"])).IdUF; Venda.Fone = ((Controle_Dados.Pessoas)(((System.Web.UI.UserControl)(this.Master)).Session["LoginUsuario"])).Fone; Venda.PrazoPgto = TxtPrazoPgto.Text; Venda.ImpNF = 0; Venda.GravarDados(); // if (Venda.IdVenda > 0) { MvVendaItens Itens = new MvVendaItens(); Itens.Controle = Controle; CadPrd.Controle = Controle; for (int P = 0; P <= TabItens.Rows.Count - 1; P++) { CadPrd.LerDados(int.Parse(TabItens.Rows[P]["ID_PRODUTO"].ToString())); if (CadPrd.IdProduto > 0) { Itens.LerDados(0); Itens.TipoItem = "S"; Itens.IdVenda = Venda.IdVenda; Itens.IdProduto = CadPrd.IdProduto; Itens.Qtde = decimal.Parse(TabItens.Rows[P]["QTDE"].ToString()); Itens.VlrUnitario = decimal.Parse(TabItens.Rows[P]["VLRUNITARIO"].ToString()); Itens.VlrTotal = decimal.Parse(TabItens.Rows[P]["VLRTOTAL"].ToString()); Itens.VlrUntComissao = decimal.Parse(TabItens.Rows[P]["VLRUNITARIO"].ToString()); Itens.PrcEspecial = CadPrd.PrcEspecial; Itens.PrcCusto = CadPrd.Custo; Itens.PrcMinimo = CadPrd.PrcMinimo; Itens.PrcVarejo = CadPrd.PrcVarejo; Itens.PrcAtacado = CadPrd.PrcAtacado; Itens.GravarDados(); } } } ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Pedido Enviado');", true); Response.Redirect("TelaPrincipal.aspx"); } catch { ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Atenção: Erro no envio do arquivo, tente novamente');", true); BtnEnviar.Enabled = true; } } }
public int RegistrarVenda(int IdFilial, int IdPessoa, int IdVendedor, int IdFormaPgto, string PrazoPgto, string Obs, string Subtotal, string Desconto, string Credito, string Total, string XmlItens) { try { //string StringConexao = "Data Source=SERVIDOR;Initial Catalog=BD_ERP_SGE; User ID=talimpo; Password=systalimpo; MultipleActiveResultSets=True;"; Conexao = new SqlConnection(StringConexao); Conexao.Open(); Funcoes Executar = new Funcoes(); Executar.Conexao = Conexao; RegAuditoria.Controle = Executar; Parametros ParamFilial = new Parametros(); ParamFilial.Controle = Executar; ParamFilial.LerDados(1); Controles.ControleEstoque ControleEstoque = new ControleEstoque(); ControleEstoque.Controle = Executar; Pessoas CadPessoa = new Pessoas(); CadPessoa.Controle = Executar; CadPessoa.LerDados(IdPessoa); MvVenda Venda = new MvVenda(); Venda.Controle = Executar; MvVendaItens MvItens = new MvVendaItens(); MvItens.Controle = Executar; Venda.LerDados(0); Venda.TpVenda = "PV"; Venda.IdPessoa = IdPessoa; Venda.IdVendedor = IdVendedor; Venda.IdFormaPgto = IdFormaPgto; Venda.PrazoPgto = PrazoPgto; Venda.Observacao = Obs; Venda.NmPessoa = CadPessoa.RazaoSocial; Venda.CnpjCpf = CadPessoa.Cnpj; Venda.InscUF = CadPessoa.InscUF; Venda.Endereco = CadPessoa.Endereco; Venda.Numero = CadPessoa.Numero; Venda.Complemento = CadPessoa.Complemento; Venda.Fone = CadPessoa.Fone; Venda.Cep = CadPessoa.Cep; Venda.Bairro = CadPessoa.Bairro; Venda.Cidade = CadPessoa.Cidade; Venda.IdUF = CadPessoa.IdUF; Venda.Pais = CadPessoa.Pais; Venda.VlrSubTotal = decimal.Parse(Subtotal.ToString().Replace(".", ",")); Venda.VlrDesconto = decimal.Parse(Desconto.ToString().Replace(".", ",")); Venda.VlrCredito = decimal.Parse(Credito.ToString().Replace(".", ",")); Venda.VlrTotal = decimal.Parse(Total.ToString().Replace(".", ",")); if (CadPessoa.IdFilial == 0) { Venda.IdFilial = IdFilial; } else { Venda.IdFilial = CadPessoa.IdFilial; } Venda.GravarDados(); RegistrarAuditoria("Venda Mobile Venda", Venda.IdVenda, Venda.NumDocumento, 1, "Pessoa:" + Venda.NmPessoa); //Incluindo os Itens; System.IO.StringReader Xml = new System.IO.StringReader(XmlItens); DataSet Tab = new DataSet(); Tab.ReadXml(Xml); for (int i = 0; i < Tab.Tables[0].Rows.Count; i++) { MvItens.LerDados(0); MvItens.IdVenda = Venda.IdVenda; MvItens.TipoItem = "S"; MvItens.IdProduto = int.Parse(Tab.Tables[0].Rows[i]["cProd"].ToString()); MvItens.PrcEspecial = decimal.Parse(Tab.Tables[0].Rows[i]["cPrcE"].ToString().Replace(".", ",")); MvItens.PrcVarejo = decimal.Parse(Tab.Tables[0].Rows[i]["cPrcV"].ToString().Replace(".", ",")); MvItens.PrcMinimo = decimal.Parse(Tab.Tables[0].Rows[i]["cPrcM"].ToString().Replace(".", ",")); MvItens.PrcAtacado = decimal.Parse(Tab.Tables[0].Rows[i]["cPrcA"].ToString().Replace(".", ",")); MvItens.Qtde = decimal.Parse(Tab.Tables[0].Rows[i]["cQtde"].ToString().Replace(".", ",")); MvItens.VlrUnitario = decimal.Parse(Tab.Tables[0].Rows[i]["cPrcU"].ToString().Replace(".", ",")); MvItens.VlrTotal = MvItens.Qtde * MvItens.VlrUnitario; MvItens.GravarDados(); RegistrarAuditoria("Venda Mobile Item", MvItens.IdItem, Venda.NumDocumento, 1, "Incluindo Item Produto:" + MvItens.IdProduto.ToString() + " Vr.Unit:" + MvItens.VlrUnitario.ToString() + " Qtde:" + MvItens.Qtde.ToString()); } //Atualizando o Estoque e Concluindo a Venda //Atualizando o Credito do Cliente if (Venda.VlrCredito > 0) { Executar.ExecutaSQL("UPDATE PESSOAS SET CREDITO=CREDITO-" + Executar.FloatToStr(Venda.VlrCredito, 2) + " WHERE ID_PESSOA=" + Venda.IdPessoa.ToString()); } //Calculando a comissao SqlDataReader TabComissao = Executar.ConsultaSQL("SELECT T1.*,T3.COMISSAO AS PCOMVEND FROM MvVendaItens T1 LEFT JOIN MVVENDA T2 ON (T2.ID_VENDA=T1.ID_VENDA)" + " LEFT JOIN VENDEDORES T3 ON (T3.ID_VENDEDOR=T2.ID_VENDEDOR) WHERE T1.TipoItem<>'E' and T1.Id_Venda=" + Venda.IdVenda.ToString()); Controles.Comissao CalcComissao = new Controles.Comissao(); CalcComissao.Controle = Executar; decimal PDesconto = 0; if ((Venda.VlrDesconto + Venda.VlrCredito) > 0) { PDesconto = 100 / (Venda.VlrSubTotal / (Venda.VlrDesconto + Venda.VlrCredito)); } CalcComissao.CalcularMovimento(TabComissao, PDesconto, CadPessoa.Clie_Forn == 3, ParamFilial, CadPessoa.ComissaoFixa, CadPessoa.IdPessoa); //Atualizando o Saldo do Estoque SqlDataReader TabSaida = Executar.ConsultaSQL("SELECT * FROM MvVendaItens WHERE TipoItem='S' and Id_Venda=" + Venda.IdVenda.ToString()); ControleEstoque.MovimentoEstoque(TabSaida, 2, 1, false, Venda.TpVenda, Venda.Data, 0); //Finalizando a venda Venda.Concluir(1); RegistrarAuditoria("Venda Mobile", Venda.IdVenda, Venda.NumDocumento, 5, "Confirmação do Movimento"); } catch { Conexao.Dispose(); return(-1); } Conexao.Dispose(); return(0); }