Пример #1
0
        protected void btn_Registrar_Click(object sender, EventArgs e)
        {
            try
            {
                Tb_Produto Obj = new Tb_Produto();

                Obj.iCod_Conta       = Convert.ToInt32(ID_USUARIO);
                Obj.vNom_Produto     = txt_NomProduto.Text;
                Obj.dPreco_Custo     = Convert.ToDouble(txt_PrecoCusto.Text);
                Obj.dPreco_Venda     = Convert.ToDouble(txt_PrecoVenda.Text);
                Obj.vQtd_Estoque     = txt_QtdEstoque.Text;
                Obj.vQtd_Min_Estoque = txt_QtdMinEstoque.Text;
                Obj.dData_Cadastro   = Convert.ToDateTime(DateTime.Now);

                Tb_Categoria_Produto Categoria = new Tb_Categoria_Produto();
                string NomeCategoria           = drplstCategoriaProduto.SelectedItem.Text;

                Categoria          = categorias.Where(x => x.vNom_Categoria == NomeCategoria).FirstOrDefault();
                Obj.iCod_Categoria = Categoria.iCod_Categoria;

                string retorno = Produto_BO.Valida_Produto(Obj);

                if (retorno == "1")
                {
                    string vStrSuccess = "'Produto cadastrado com sucesso!'";
                    ClientScript.RegisterStartupScript(GetType(), Guid.NewGuid().ToString(), "Msg_Sucesso(" + vStrSuccess + ");", true);
                    Limpa_Campos();
                    Response.Redirect("~/Forms/Cadastro/Lista-Produtos.aspx");
                }
                else if (retorno == "2")
                {
                    string vStrSuccess = "'Produto atualizado com sucesso!'";
                    ClientScript.RegisterStartupScript(GetType(), Guid.NewGuid().ToString(), "Msg_Sucesso(" + vStrSuccess + ");", true);
                    Limpa_Campos();
                    Response.Redirect("~/Forms/Cadastro/Lista-Produtos.aspx");
                }
                else
                {
                    string vStrWarning = "'" + retorno + "'";
                    ClientScript.RegisterStartupScript(GetType(), Guid.NewGuid().ToString(), "Msg_Warning(" + vStrWarning + ");", true);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        public List <Tb_Categoria_Produto> Retrieve(String Sql)
        {
            List <Tb_Categoria_Produto> Lista = new List <Tb_Categoria_Produto>();
            Tb_Categoria_Produto        Obj   = new Tb_Categoria_Produto();

            MySqlConnection Conexao = new MySqlConnection();
            MySqlCommand    Comando = new MySqlCommand();

            try
            {
                Conexao = Db.GetConexao();

                Comando.CommandTimeout = 120;
                Comando.CommandText    = Sql;
                Comando.CommandType    = System.Data.CommandType.Text;
                Comando.Connection     = Conexao;
                MySqlDataReader Reader = Comando.ExecuteReader();

                if (Reader.HasRows)
                {
                    while (Reader.Read())
                    {
                        Obj = new Tb_Categoria_Produto();

                        Obj.iCod_Categoria = Convert.ToInt32(Reader["iCod_Categoria"]);
                        Obj.vNom_Categoria = Convert.ToString(Reader["vNom_Categoria"]);
                        Lista.Add(Obj);
                    }
                }
                Reader.Close();
            }
            catch (Exception ex)
            {
                string erro = ex.Message;
                return(null);
            }
            finally
            {
                if (Conexao.State == System.Data.ConnectionState.Open)
                {
                    Conexao.Close();
                }
            }

            return(Lista);
        }