Ejemplo n.º 1
0
        protected void btCadastrarprodutos_Click(object sender, EventArgs e)
        {
            if ((txtId.Text == "") || (txtNome.Text == "") || (txtDescricao.Text == "") || (txtPreco.Text == ""))
            {
                lblMsg.Text = "Preencha os dados de cadastro corretamente";
                return;
            }
            else
            {
                //Abrindo conexão
                SuplementosEntities conec = new SuplementosEntities();

                Produtos itens = new Produtos();

                itens.Id          = Convert.ToInt32(txtId.Text);
                itens.Nomeproduto = txtNome.Text;
                itens.Descricao   = txtDescricao.Text;
                itens.Preco       = Convert.ToDouble(txtPreco.Text);

                conec.Produtos.Add(itens);
                conec.SaveChanges();

                txtId.Text        = "";
                txtNome.Text      = "";
                txtDescricao.Text = "";
                txtPreco.Text     = "";;

                lblMsg.Text = "Cadastro realizado com sucesso";
            }
        }
Ejemplo n.º 2
0
        protected void btnCadastrar_Click(object sender, EventArgs e)
        {
            if ((txtNome.Text == "") || (txtSenha.Text == "") || (txtEmail.Text == "") || (txtEndereco.Text == "") || (txtTelefone.Text == ""))
            {
                lblMsg.Text = "Preencha os dados de cadastro corretamente";
                return;
            }
            else
            {
                //Abrindo conexão
                SuplementosEntities conec = new SuplementosEntities();

                Usuarios users = new Usuarios();

                users.id       = Convert.ToInt32(txtId.Text);
                users.Nome     = txtNome.Text;
                users.Senha    = txtSenha.Text;
                users.Email    = txtEmail.Text;
                users.Telefone = txtTelefone.Text;
                users.Endereco = txtEndereco.Text;

                conec.Usuarios.Add(users);
                conec.SaveChanges();

                txtId.Text       = "";
                txtNome.Text     = "";
                txtSenha.Text    = "";
                txtEmail.Text    = "";
                txtTelefone.Text = "";
                txtEndereco.Text = "";

                lblMsg.Text = "Cadastro realizado com sucesso";
            }
        }