Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(textBox1.Text) == false)
            {
                Int64 qtde2;
                if (Int64.TryParse(textBox1.Text.Trim(), out qtde2) == false)
                {
                    MessageBox.Show("O campo Código EAN só aceita valores numéricos");
                    textBox1.Text = "";
                    textBox1.Focus();
                    return;
                }
                if (textBox1.Text.Length < 5)
                {
                    MessageBox.Show("Formato EAN incorreto");
                    textBox1.Text = "";
                    textBox1.Focus();
                    return;
                }
                if (String.IsNullOrEmpty(textBox2.Text) == false && String.IsNullOrEmpty(textBox3.Text) == false &&
                    String.IsNullOrEmpty(textBox4.Text) == false && String.IsNullOrEmpty(textBox5.Text) == false)
                {
                    DataTable testa = DALCadastro.produtoVenda(textBox1.Text);
                    if (testa.Rows.Count == 1)
                    {
                        MessageBox.Show("Existe produto cadastrado com este código de barras.\n" + testa.Rows[0]["DescInterna"].ToString());
                    }
                    if (testa.Rows.Count <= 0)
                    {
                        textBox3.Text = textBox3.Text.Replace(",", ".");

                        textBox4.Text = textBox4.Text.Replace(",", ".");

                        string emp = Global.Margem.EmpresaCaixa;
                        DALCadastro.CadProdRapido(textBox1.Text, comboBox5.Text, textBox2.Text, emp, textBox3.Text, textBox4.Text, textBox5.Text);
                        MessageBox.Show("Cadastrado com sucesso.");
                        Global.Margem.EANCadRapido = textBox1.Text;
                        Global.Margem.CadRapido    = "EAN";
                        this.Close();
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Campos obrigatórios não foram preenchidos");
                    if (String.IsNullOrEmpty(textBox2.Text) == true)
                    {
                        textBox2.Focus();
                        return;
                    }
                    if (String.IsNullOrEmpty(textBox3.Text) == true)
                    {
                        textBox3.Focus();
                        return;
                    }
                    if (String.IsNullOrEmpty(textBox5.Text) == true)
                    {
                        textBox5.Focus();
                        return;
                    }
                }
            }
            if (String.IsNullOrEmpty(textBox1.Text) == true)
            {
                string            message = "Você deseja cadastrar produto sem código de barras?";
                string            caption = "EAN";
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      result;

                // Displays the MessageBox.
                result = MessageBox.Show(this, message, caption, buttons,
                                         MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    if (String.IsNullOrEmpty(textBox2.Text) == false && String.IsNullOrEmpty(textBox3.Text) == false &&
                        String.IsNullOrEmpty(textBox4.Text) == false && String.IsNullOrEmpty(textBox5.Text) == false)
                    {
                        DataTable tem = DALCadastro.TemDesc(textBox2.Text);
                        if (tem.Rows.Count > 0)
                        {
                            MessageBox.Show("Existe cadastro com esta descrição interna.");
                            return;
                        }
                        else
                        {
                            textBox3.Text = textBox3.Text.Replace(",", ".");

                            textBox4.Text = textBox4.Text.Replace(",", ".");

                            string emp = Global.Margem.EmpresaCaixa;
                            DALCadastro.CadProdRapido(textBox1.Text, comboBox5.Text, textBox2.Text, emp, textBox3.Text, textBox4.Text, textBox5.Text);
                            MessageBox.Show("Cadastrado com sucesso.");
                            Global.Margem.CadRapido = "SemEAN";
                            this.Close();
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Campos obrigatórios não foram preenchidos");
                        if (String.IsNullOrEmpty(textBox2.Text) == true)
                        {
                            textBox2.Focus();
                            return;
                        }
                        if (String.IsNullOrEmpty(textBox3.Text) == true)
                        {
                            textBox3.Focus();
                            return;
                        }
                        if (String.IsNullOrEmpty(textBox5.Text) == true)
                        {
                            textBox5.Focus();
                            return;
                        }
                    }
                }
                if (result == DialogResult.No)
                {
                    textBox1.Focus();
                    return;
                }
            }
        }