internal bool Save(SISEstoque_TO pSISEstoqueTO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); SqlDataReader reader = null; sql.AppendLine("INSERT INTO ESTOQUE "); sql.AppendLine("VALUES (@PRO_CODIGO"); sql.AppendLine(" ,@EST_QTD"); sql.AppendLine(" ,@EST_QTD_MINIMA"); sql.AppendLine(" ,GETDATE() "); sql.AppendLine(" ,@EST_OBSERVACAO )"); sql.Append(" SELECT @@IDENTITY AS 'ULTIMO_EST_CODIGO' "); try { command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@PRO_CODIGO", pSISEstoqueTO.SISProdutoTO.PRO_CODIGO); command.Parameters.AddWithValue("@EST_QTD", pSISEstoqueTO.EST_QTD); command.Parameters.AddWithValue("@EST_QTD_MINIMA", pSISEstoqueTO.EST_QTD_MINIMA); command.Parameters.AddWithValue("@EST_OBSERVACAO", pSISEstoqueTO.EST_OBSERVACAO); reader = command.ExecuteReader(); if (reader.Read()) { pSISEstoqueTO.EST_CODIGO = Convert.ToInt32(reader["ULTIMO_EST_CODIGO"]); retorno = true; } } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
internal DataTable GetProdutos(SISProduto_TO pSISProdutoTO) { SqlConnection connection = null; DataTable ldt = new DataTable(); try { // criando e abrindo a conexão connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); if (pSISProdutoTO.tag.Equals("PopGridCadProduto")) { sql.Append("SELECT PRO.PRO_CODIGO, "); sql.Append("PRO.PRO_NOME, "); sql.Append("PRO.PRO_UNIDADE, "); sql.Append("PRO.PRO_VALOR, "); sql.Append("CAT.CAT_NOME "); sql.Append("FROM PRODUTO PRO "); sql.Append("LEFT JOIN CATEGORIA CAT "); sql.AppendFormat("ON PRO.CAT_CODIGO = CAT.CAT_CODIGO ", pSISProdutoTO.query); } if (pSISProdutoTO.tag.Equals("PopComboxProduto")) { sql.Append(" SELECT "); sql.Append(" PROD.PRO_CODIGO,"); sql.Append(" PROD.PRO_NOME,"); sql.AppendFormat(" FROM PRODUTO PROD ", pSISProdutoTO.query); } try { command = new SqlCommand(sql.ToString(), connection); SqlDataAdapter a = new SqlDataAdapter(command); a.Fill(ldt); } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(ldt); }
private void CarregaStatusBar() { try { if (UtilConexion.CarregarConfiguracaoSistema() == true) { var vrs = new Version(Application.ProductVersion); Globais.VersaoPrograma = String.Format("{0}.{1}.{2}", vrs.Major, vrs.Minor, vrs.Revision); string teste; teste = string.Format("Servidor: {0} Database : {1} Usuário Banco: {2} Versão:{3}", Globais.NomeServidor, Globais.BancoDados, Globais.UsuarioBd, Globais.VersaoPrograma).ToString(); txtSistema.Text = teste.ToString(); Refresh(); } } catch (Exception ex) { Uteis.ExibirMensagem(ex.Message, titulo, TipoMensagem.Erro); } }
internal bool Save(SISItemPedido_TO pSISItemPedido_TO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); SqlDataReader reader = null; sql.AppendLine("INSERT INTO ITEM_PEDIDO "); sql.AppendLine("VALUES (@PED_CODIGO"); sql.AppendLine(",@PRO_CODIGO"); sql.AppendLine(",@ITE_ADICIONAL"); sql.AppendLine(",@COMP_ITENS"); sql.AppendLine(",@ITE_OBS)"); sql.Append("SELECT @@IDENTITY AS 'ULTIMO_ITE_CODIGO'"); try { command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@PED_CODIGO", pSISItemPedido_TO.PED_CODIGO); command.Parameters.AddWithValue("@PRO_CODIGO", pSISItemPedido_TO.PRO_CODIGO); command.Parameters.AddWithValue("@ITE_ADICIONAL", pSISItemPedido_TO.ITE_ADICIONAL ?? (object)DBNull.Value); command.Parameters.AddWithValue("@COMP_ITENS", pSISItemPedido_TO.COMP_ITENS ?? (object)DBNull.Value); command.Parameters.AddWithValue("@ITE_OBS", pSISItemPedido_TO.ITE_OBS ?? (object)DBNull.Value); reader = command.ExecuteReader(); if (reader.Read()) { pSISItemPedido_TO.ITE_CODIGO = Convert.ToInt32(reader["ULTIMO_ITE_CODIGO"]); retorno = true; } } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
internal bool Save(SISProduto_TO pSisProdutoTO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); SqlDataReader reader = null; sql.AppendLine("INSERT INTO PRODUTO "); sql.AppendLine("VALUES (@PRO_NOME"); sql.AppendLine(",@PRO_VALOR"); sql.AppendLine(",@PRO_UNIDADE"); sql.AppendLine(",@CAT_CODIGO)"); sql.Append("SELECT @@IDENTITY AS 'ULTIMO_PRO_CODIGO'"); try { command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@PRO_NOME", pSisProdutoTO.PRO_NOME); command.Parameters.AddWithValue("@PRO_VALOR", pSisProdutoTO.PRO_VALOR); command.Parameters.AddWithValue("@PRO_UNIDADE", pSisProdutoTO.PRO_UNIDADE); command.Parameters.AddWithValue("@CAT_CODIGO", pSisProdutoTO.CAT_CODIGO); reader = command.ExecuteReader(); if (reader.Read()) { pSisProdutoTO.PRO_CODIGO = Convert.ToInt32(reader["ULTIMO_PRO_CODIGO"]); retorno = true; } } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
internal bool Save(SISCategoria_TO pCategoriaTO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); SqlDataReader reader = null; sql.AppendLine("INSERT INTO CATEGORIA "); sql.AppendLine("VALUES (@CAT_NOME"); sql.AppendLine(" ,@CAT_DESCRICAO"); sql.AppendLine(" ,GETDATE() "); sql.AppendLine(" ,GETDATE() )"); sql.Append(" SELECT @@IDENTITY AS 'ULTIMO_CAT_CODIGO' "); try { command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@CAT_NOME", pCategoriaTO.CAT_NOME); command.Parameters.AddWithValue("@CAT_DESCRICAO", pCategoriaTO.CAT_DESCRICAO); reader = command.ExecuteReader(); if (reader.Read()) { pCategoriaTO.CAT_CODIGO = Convert.ToInt32(reader["ULTIMO_CAT_CODIGO"]); retorno = true; } } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
internal bool UpDate(SISProduto_TO pSISProdutoTO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); try { sql.AppendLine("UPDATE PRODUTO SET"); sql.AppendLine(" PRO_NOME = @PRO_NOME"); sql.AppendLine(",PRO_UNIDADE = @PRO_UNIDADE"); sql.AppendLine(",PRO_VALOR = @PRO_VALOR"); sql.AppendLine(",CAT_CODIGO = @CAT_CODIGO"); sql.AppendLine(" WHERE PRO_CODIGO = @PRO_CODIGO "); command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@PRO_CODIGO", pSISProdutoTO.PRO_CODIGO); command.Parameters.AddWithValue("@PRO_NOME", pSISProdutoTO.PRO_NOME); command.Parameters.AddWithValue("@PRO_UNIDADE", pSISProdutoTO.PRO_UNIDADE); command.Parameters.AddWithValue("@PRO_VALOR", pSISProdutoTO.PRO_VALOR); command.Parameters.AddWithValue("@CAT_CODIGO", pSISProdutoTO.CAT_CODIGO); command.ExecuteNonQuery(); retorno = true; } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
internal bool Delete(SISItemPedido_TO pSISItemPedido_TO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception ex) { throw new Exception(ex.Message); } SqlCommand command = null; StringBuilder sql = new StringBuilder(); try { sql.AppendLine("IF EXISTS (SELECT * FROM Item_Pedido WHERE ITE_ADICIONAL = @ITE_CODIGO) "); sql.AppendLine("BEGIN "); sql.AppendLine("DELETE Item_Pedido WHERE ITE_ADICIONAL IN (SELECT ITE_CODIGO FROM Item_Pedido WHERE ITE_ADICIONAL = @ITE_CODIGO ) "); sql.AppendLine("END "); sql.AppendLine("ELSE "); sql.AppendLine("BEGIN "); sql.AppendLine("DELETE TOP (1) FROM ITEM_PEDIDO WHERE PED_CODIGO = @PED_CODIGO AND ITE_CODIGO = @ITE_CODIGO "); sql.AppendLine("END "); command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@ITE_CODIGO", pSISItemPedido_TO.ITE_CODIGO); command.Parameters.AddWithValue("@PED_CODIGO", pSISItemPedido_TO.PED_CODIGO); command.ExecuteNonQuery(); retorno = true; } catch (Exception ex) { throw new Exception(ex.Message); } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
internal DataTable GetCategoriaProduto(SISCategoria_TO pSISCategoriaTO) { SqlConnection connection = null; DataTable ldt = new DataTable(); try { // criando e abrindo a conexão connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); if (pSISCategoriaTO.tag.Equals("PopularComboBoxCategoria")) { sql.Append(" SELECT "); sql.Append(" CAT_NOME, CAT_DESCRICAO , CAT_CODIGO "); sql.AppendFormat(" FROM CATEGORIA "); } if (pSISCategoriaTO.tag.Equals("PopularLookupCategoria")) { sql.Append(" SELECT "); sql.Append(" CAT_CODIGO, (CAST(CAT_CODIGO AS CHAR(3)) + ' -' + CAT_NOME) AS CAT_NOME "); sql.AppendFormat(" FROM CATEGORIA "); } try { command = new SqlCommand(sql.ToString(), connection); SqlDataAdapter a = new SqlDataAdapter(command); a.Fill(ldt); } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(ldt); }
internal bool UpDate(SISPedido_TO pSISPedidoTO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); try { sql.AppendLine(" UPDATE PEDIDO SET"); sql.AppendLine(" PED_STATUS = @MESA_HIST_STATUS"); sql.AppendLine(" ,PED_TOTAL = @PED_TOTAL"); sql.AppendLine(" ,PED_TROCO = @PED_TROCO"); sql.AppendLine(" ,PED_FRETE = @PED_FRETE"); sql.AppendLine(" ,PAG_CODIGO = @PAG_CODIGO"); sql.AppendLine(" WHERE PED_CODIGO = @PED_CODIGO "); command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@PED_CODIGO", pSISPedidoTO.PED_CODIGO); command.Parameters.AddWithValue("@MESA_HIST_STATUS", pSISPedidoTO.PED_STATUS); command.Parameters.AddWithValue("@PED_TOTAL", pSISPedidoTO.PED_TOTAL); command.Parameters.AddWithValue("@PED_TROCO", pSISPedidoTO.PED_TROCO ?? (object)DBNull.Value); command.Parameters.AddWithValue("@PED_FRETE", pSISPedidoTO.PED_FRETE ?? (object)DBNull.Value); command.Parameters.AddWithValue("@PAG_CODIGO", pSISPedidoTO.PAG_CODIGO ?? (object)DBNull.Value); command.ExecuteNonQuery(); retorno = true; } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
internal bool UpDate(SISCategoria_TO pSISCategoriaTO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); try { sql.AppendLine("UPDATE CATEGORIA SET "); sql.AppendLine("CAT_NOME = @CAT_NOME ,"); sql.AppendLine("CAT_DESCRICAO = @CAT_DESCRICAO "); sql.AppendLine("WHERE CAT_CODIGO = @CAT_CODIGO"); command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@CAT_NOME", pSISCategoriaTO.CAT_NOME); command.Parameters.AddWithValue("@CAT_DESCRICAO", pSISCategoriaTO.CAT_DESCRICAO); command.Parameters.AddWithValue("@CAT_CODIGO", pSISCategoriaTO.CAT_CODIGO); command.ExecuteNonQuery(); retorno = true; } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
internal bool UpDate(SISEstoque_TO pSISEstoqueTO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); try { sql.AppendLine("UPDATE ESTOQUE SET "); sql.AppendLine("EST_QTD = @EST_QTD ,"); sql.AppendLine("EST_OBSERVACAO = @EST_OBSERVACAO "); sql.AppendLine("WHERE EST_CODIGO = @EST_CODIGO"); command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@EST_QTD", pSISEstoqueTO.EST_QTD); command.Parameters.AddWithValue("@EST_OBSERVACAO", pSISEstoqueTO.EST_OBSERVACAO); command.Parameters.AddWithValue("@EST_CODIGO", pSISEstoqueTO.EST_CODIGO); command.ExecuteNonQuery(); retorno = true; } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
internal SISPedido_TO GetPedidoAberto(SISPedido_TO pSISPedidoTO) { SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception ex) { throw new Exception(ex.Message); } SqlCommand command = null; StringBuilder sql = new StringBuilder(); SqlDataReader reader = null; sql.Append("SELECT PED_CODIGO "); sql.AppendFormat("FROM PEDIDO {0}", pSISPedidoTO.query); try { command = new SqlCommand(sql.ToString(), connection); reader = command.ExecuteReader(); if (reader.Read()) { pSISPedidoTO.PED_CODIGO = Convert.ToInt32(reader["PED_CODIGO"]); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(pSISPedidoTO); }
internal bool Delete(SISCategoria_TO pSISCategoriaTO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception ex) { throw new Exception(ex.Message); } SqlCommand command = null; StringBuilder sql = new StringBuilder(); try { sql.AppendLine("DELETE TOP (1) FROM CATEGORIA "); sql.AppendLine(" WHERE CAT_CODIGO = @CAT_CODIGO "); command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@CAT_CODIGO", pSISCategoriaTO.CAT_CODIGO); command.ExecuteNonQuery(); retorno = true; } catch (Exception ex) { throw new Exception(ex.Message); } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
internal bool Delete(SISProduto_TO pSISProdutoTO) { bool retorno = false; SqlConnection connection = null; try { // criando e abrindo a conexão connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); try { sql.AppendLine("DELETE PRODUTO "); sql.AppendLine(" WHERE PRO_CODIGO = @PRO_CODIGO "); command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@PRO_CODIGO", pSISProdutoTO.PRO_CODIGO); command.ExecuteNonQuery(); retorno = true; } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
internal bool UpDate(SISItemPedido_TO pSISItemPedidoTO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); try { sql.AppendLine(" UPDATE ITEMPEDIDO SET"); sql.AppendLine(" ITE_ADICIONAL = @ITE_ADICIONAL"); sql.AppendLine(" WHERE ITE_CODIGO = @ITE_CODIGO "); command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@ITE_ADICIONAL", pSISItemPedidoTO.ITE_ADICIONAL); command.Parameters.AddWithValue("@ITE_CODIGO", pSISItemPedidoTO.ITE_CODIGO); command.ExecuteNonQuery(); retorno = true; } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
internal DataTable GetEstoqueProduto(SISEstoque_TO pSISEstoqueTO) { SqlConnection connection = null; DataTable ldt = new DataTable(); try { // criando e abrindo a conexão connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); if (pSISEstoqueTO.tag.Equals("PopularGridEstoque")) { sql.Append(" SELECT "); sql.Append(" P.PRO_NOME, P.PRO_UNIDADE, C.CAT_NOME, P.PRO_VALOR, E.EST_QTD_MINIMA, "); sql.Append(" E.EST_QTD, E.EST_CODIGO, E.EST_DATA_CADASTRO, E.PRO_CODIGO "); sql.Append(" FROM PRODUTO P "); sql.Append(" INNER JOIN ESTOQUE E "); sql.Append(" ON P.PRO_CODIGO = E.PRO_CODIGO "); sql.Append(" LEFT JOIN CATEGORIA C "); sql.AppendFormat(" ON P.CAT_CODIGO = C.CAT_CODIGO "); } else if (pSISEstoqueTO.tag.Equals("PopularItemEstoque")) { sql.Append(" SELECT "); sql.Append(" P.PRO_NOME, E.EST_CODIGO, E.PRO_CODIGO "); sql.Append(" FROM PRODUTO P "); sql.Append(" INNER JOIN ESTOQUE E "); sql.AppendFormat(" ON P.PRO_CODIGO = E.PRO_CODIGO {0} ", pSISEstoqueTO.query); } try { command = new SqlCommand(sql.ToString(), connection); SqlDataAdapter a = new SqlDataAdapter(command); a.Fill(ldt); } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(ldt); }
internal DataTable GetPedidoItem(SISPedido_TO pSISPedidoTO) { SqlConnection connection = null; DataTable ldt = new DataTable(); try { // criando e abrindo a conexão connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); if (pSISPedidoTO.tag.Equals("ResumoPedidoItem")) { sql.Append("SELECT * FROM PEDIDO ped "); sql.Append("INNER JOIN ITEM_PEDIDO ite "); sql.Append("ON ped.PED_CODIGO = ITE.PED_CODIGO "); sql.Append("INNER JOIN PRODUTO pro "); sql.Append("ON ITE.PRO_CODIGO = pro.PRO_CODIGO "); sql.AppendFormat("WHERE PED.PED_CODIGO = @PED_CODIGO "); } if (pSISPedidoTO.tag.Equals("GridResumoPedidoItem")) { sql.Append("SELECT pro.PRO_NOME as Item, CONVERT(MONEY, pro.PRO_VALOR) as Valor "); sql.Append("FROM PEDIDO ped "); sql.Append("INNER JOIN ITEM_PEDIDO ite "); sql.Append("ON ped.PED_CODIGO = ITE.PED_CODIGO "); sql.Append("INNER JOIN PRODUTO pro "); sql.Append("ON ITE.PRO_CODIGO = pro.PRO_CODIGO "); sql.AppendFormat("WHERE PED.PED_CODIGO = @PED_CODIGO "); } try { command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@PED_CODIGO", pSISPedidoTO.PED_CODIGO); SqlDataAdapter a = new SqlDataAdapter(command); a.Fill(ldt); } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(ldt); }
internal bool Save(SISPedido_TO pSISPedido_TO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); SqlDataReader reader = null; sql.AppendLine("INSERT INTO PEDIDO "); sql.AppendLine("VALUES (@PED_TOTAL"); sql.AppendLine(",@PED_TROCO"); sql.AppendLine(",@PED_ORDEM_ATENDIMENTO"); sql.AppendLine(",@PED_CAD_DATA"); sql.AppendLine(",@PED_STATUS"); sql.AppendLine(" ,@PED_FRETE"); sql.AppendLine(" ,@PAG_CODIGO)"); sql.Append(" SELECT @@IDENTITY AS 'ULTIMO_PED_CODIGO'"); try { command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@PED_TOTAL", pSISPedido_TO.PED_TOTAL); command.Parameters.AddWithValue("@PED_TROCO", pSISPedido_TO.PED_TROCO ?? (object)DBNull.Value); command.Parameters.AddWithValue("@PED_ORDEM_ATENDIMENTO", pSISPedido_TO.PED_ORDEM_ATENDIMENTO); command.Parameters.AddWithValue("@PED_CAD_DATA", pSISPedido_TO.PED_CAD_DATA); command.Parameters.AddWithValue("@PED_STATUS", pSISPedido_TO.PED_STATUS); command.Parameters.AddWithValue("@PED_FRETE", pSISPedido_TO.PED_FRETE ?? (object)DBNull.Value); command.Parameters.AddWithValue("@PAG_CODIGO", pSISPedido_TO.PAG_CODIGO ?? (object)DBNull.Value); reader = command.ExecuteReader(); if (reader.Read()) { pSISPedido_TO.PED_CODIGO = Convert.ToInt32(reader["ULTIMO_PED_CODIGO"]); retorno = true; } } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
internal DataTable GetProdutoAtivo(SISProduto_TO pSISProdutoTO) { SqlConnection connection = null; DataTable ldt = new DataTable(); try { // criando e abrindo a conexão connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); if (pSISProdutoTO.tag.Equals("PopComboxProduto")) { sql.Append(" SELECT "); sql.Append(" PROD.PRO_CODIGO,"); sql.Append(" PROD.PRO_NOME "); sql.AppendFormat(" FROM PRODUTO PROD {0}", pSISProdutoTO.query); } if (pSISProdutoTO.tag.Equals("LookUpEstoqueProduto")) { sql.Append(" SELECT "); sql.Append(" PRO.PRO_CODIGO,"); sql.Append(" PRO.PRO_NOME "); sql.Append(" FROM PRODUTO PRO "); sql.Append(" LEFT JOIN ESTOQUE EST "); sql.AppendFormat(" ON PRO.PRO_CODIGO = EST.EST_CODIGO {0}", pSISProdutoTO.query); } if (pSISProdutoTO.tag.Equals("LookUpProdutoNovo")) { sql.Append(" SELECT "); sql.Append(" P.PRO_CODIGO, P.PRO_NOME "); sql.Append(" FROM PRODUTO P WHERE "); sql.AppendFormat(" NOT EXISTS (SELECT E.PRO_CODIGO FROM Estoque E WHERE E.PRO_CODIGO = P.PRO_CODIGO) "); } if (pSISProdutoTO.tag.Equals("NavBarControl_MenuProduto")) { sql.Append(" SELECT "); sql.Append(" P.PRO_CODIGO, P.PRO_NOME, C.CAT_NOME "); sql.Append(" FROM PRODUTO P "); sql.Append(" LEFT JOIN Categoria C "); sql.AppendFormat(" ON P.CAT_CODIGO = C.CAT_CODIGO "); } if (pSISProdutoTO.tag.Equals("PopularMenuProduto")) { sql.Append(" SELECT "); sql.Append(" P.PRO_CODIGO, P.PRO_NOME, C.CAT_NOME "); sql.Append(" FROM PRODUTO P "); sql.Append(" LEFT JOIN Categoria C "); sql.AppendFormat(" ON P.CAT_CODIGO = C.CAT_CODIGO "); } if (pSISProdutoTO.tag.Equals("PopularComboBoxProduto")) { sql.Append(" SELECT "); sql.Append(" P.PRO_CODIGO, P.PRO_NOME "); sql.Append(" FROM PRODUTO P WHERE "); sql.AppendFormat(" NOT EXISTS (SELECT E.PRO_CODIGO FROM Estoque E WHERE E.PRO_CODIGO = P.PRO_CODIGO) "); } try { command = new SqlCommand(sql.ToString(), connection); SqlDataAdapter a = new SqlDataAdapter(command); a.Fill(ldt); } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(ldt); }