Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public DataTable GetEstoque(SISEstoque_TO pSISEstoqueTO)
        {
            if (!string.IsNullOrEmpty(pSISEstoqueTO.tag))
            {
                if (pSISEstoqueTO.tag.Equals("PopularGridEstoque"))
                {
                    //pSISPedidoTO.query = " AND EMP_STATUS = 'A' ";
                    //pSISEstoqueTO.PED_CODIGO = pSISEstoqueTO.PED_CODIGO;
                }
                if (pSISEstoqueTO.tag.Equals("PopularItemEstoque"))
                {
                    pSISEstoqueTO.query = string.Format(" WHERE P.PRO_CODIGO = '{0}' ", pSISEstoqueTO.SISProdutoTO.PRO_CODIGO);
                }
            }

            return(new SISEstoque_DAO().GetEstoqueProduto(pSISEstoqueTO));
            //return new SISPedido_DAO().GetPedidoItem(pSISPedidoTO);
        }
Esempio n. 4
0
        public bool Save(SISEstoque_TO pEstoqueTO, bool pOpcao)
        {
            bool lresultado = false;

            try
            {
                //SISCliente_TO SISClienteTO = new SISCliente_TO();
                //SISEndereco_TO SISEnderecoTO = new SISEndereco_TO();

                using (var transacao = TransactionScopeDefault.CreateTransactionScope())
                {
                    if (pEstoqueTO.tag != null)
                    {
                        if (pEstoqueTO.tag.Equals("ProdNovoEstoque"))
                        {
                            new SISEstoque_DAO().Save(pEstoqueTO);
                        }

                        if (pEstoqueTO.tag.Equals("ProdAtualizarEstoque"))
                        {
                            new SISEstoque_DAO().UpDate(pEstoqueTO);
                        }

                        //if (pEstoqueTO.tag.Equals("ExcluirProduto"))
                        //{
                        //    new SISEstoque_DAO().Delete(pEstoqueTO);
                        //}
                    }

                    transacao.Complete();
                    lresultado = true;
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(lresultado);
        }
Esempio n. 5
0
        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);
        }