コード例 #1
0
        private void btnInserir_Click(object sender, EventArgs e)
        {
            btnInserir.Enabled    = false;
            btnAlterar.Enabled    = false;
            btnExcluir.Enabled    = false;
            btnGravar.Enabled     = true;
            btnCancelar.Enabled   = true;
            txtNome.Enabled       = true;
            txtFornecedor.Enabled = true;
            txtPreco.Enabled      = true;
            txtQtd.Enabled        = true;
            produtoTableAdapter taProduto = new produtoTableAdapter();
            string novoID;
            int    valorID;

            try
            {
                novoID = taProduto.UltimoID().ToString();

                if (int.TryParse(novoID.ToString(), out valorID))
                {
                    txtID.Text = (valorID + 1).ToString();
                }
                else
                {
                    MessageBox.Show("ID com valor errado. Tente novamente.");
                }
            }
            catch
            {
                txtID.Text = "1";
            }
        }
コード例 #2
0
        public frmCadastroProduto()
        {
            InitializeComponent();
            txtID.Enabled = true;
            btnOK.Enabled = false;
            produtoTableAdapter taProduto = new produtoTableAdapter();

            string novoID;
            int    valorID;

            try
            {
                novoID = taProduto.UltimoID().ToString();

                if (int.TryParse(novoID.ToString(), out valorID))
                {
                    txtID.Text = (valorID + 1).ToString();
                }
                else
                {
                    MessageBox.Show("ID com valor errado. Tente novamente.");
                }
            }
            catch
            {
                txtID.Text = "1";
            }
            txtNome.Enabled       = false;
            txtPreco.Enabled      = false;
            txtQtd.Enabled        = false;
            txtFornecedor.Enabled = false;
        }
コード例 #3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Confirma alteração?", "Alterando...", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                produtoTableAdapter taProduto = new produtoTableAdapter();
                taProduto.UpdateQuery(txtID.Text, txtNome.Text, txtQtd.Text, txtPreco.Text, txtFornecedor.Text, txtID.Text);
                Limpar_Caixas();
                txtID.Enabled         = true;
                txtNome.Enabled       = false;
                txtPreco.Enabled      = false;
                txtQtd.Enabled        = false;
                txtFornecedor.Enabled = false;
                btnInserir.Enabled    = true;
                btnExcluir.Enabled    = true;
                btnAlterar.Enabled    = true;
                btnCancelar.Enabled   = false;
                btnOK.Enabled         = false;
                string novoID;
                int    valorID;
                try
                {
                    novoID = taProduto.UltimoID().ToString();

                    if (int.TryParse(novoID.ToString(), out valorID))
                    {
                        txtID.Text = (valorID + 1).ToString();
                    }
                    else
                    {
                        MessageBox.Show("ID com valor errado. Tente novamente.");
                    }
                }
                catch
                {
                    txtID.Text = "1";
                }
            }
        }
コード例 #4
0
        private void btnExcluir_Click(object sender, EventArgs e)
        {
            txtNome.Enabled       = true;
            txtPreco.Enabled      = true;
            lblWUad.Enabled       = true;
            txtID.Enabled         = true;
            txtFornecedor.Enabled = true;

            produtoTableAdapter taProduto = new produtoTableAdapter();

            DataTable dtPessoa;

            dtPessoa = taProduto.PesquisaProduto(txtID.Text);

            if (dtPessoa.Rows.Count == 0)
            {
                MessageBox.Show("Produto não cadastrado.");
                txtNome.Enabled  = false;
                txtPreco.Enabled = false;
                lblWUad.Enabled  = false;

                txtFornecedor.Enabled = false;
                txtID.Enabled         = true;
            }
            else
            {
                txtID.Text         = dtPessoa.Rows[0]["codProduto"].ToString();
                txtNome.Text       = dtPessoa.Rows[0]["nomeProduto"].ToString();
                txtQtd.Text        = dtPessoa.Rows[0]["qtdProduto"].ToString();
                txtPreco.Text      = dtPessoa.Rows[0]["precoProduto"].ToString();
                txtFornecedor.Text = dtPessoa.Rows[0]["fornecedorProduto"].ToString();


                txtNome.Enabled       = true;
                txtPreco.Enabled      = true;
                txtQtd.Enabled        = true;
                txtID.Enabled         = true;
                txtFornecedor.Enabled = true;

                if (MessageBox.Show("Confirma exclusão?", "Excluindo...", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    taProduto.DeleteQuery(txtID.Text);
                    Limpar_Caixas();
                    txtNome.Enabled       = false;
                    txtPreco.Enabled      = false;
                    txtQtd.Enabled        = false;
                    txtID.Enabled         = true;
                    txtFornecedor.Enabled = false;
                    string novoID;
                    int    valorID;
                    txtNome.Text        = "";
                    txtPreco.Text       = "R$";
                    txtQtd.Text         = "";
                    txtFornecedor.Text  = "";
                    btnCancelar.Enabled = false;
                    MessageBox.Show("Excluído com sucesso.");
                    try
                    {
                        novoID = taProduto.UltimoID().ToString();

                        if (int.TryParse(novoID.ToString(), out valorID))
                        {
                            txtID.Text = (valorID + 1).ToString();
                        }
                        else
                        {
                            MessageBox.Show("ID com valor errado. Tente novamente.");
                        }
                    }
                    catch
                    {
                        txtID.Text = "1";
                    }
                }
                else
                {
                    btnCancelar.Enabled   = true;
                    txtNome.Enabled       = false;
                    txtPreco.Enabled      = false;
                    txtQtd.Enabled        = false;
                    txtFornecedor.Enabled = false;
                    txtNome.Text          = "";
                    txtPreco.Text         = "R$";
                    txtQtd.Text           = "";
                    txtFornecedor.Text    = "";
                }
            }
        }