Ejemplo n.º 1
0
        private void CmbEstado_Leave(object sender, EventArgs e)
        {
            CmbEstado.SelectedIndex = CmbEstado.FindStringExact(CmbEstado.Text);

            if (CmbEstado.Text.Trim() != "" && CmbEstado.SelectedIndex == -1)
            {
                Geral.Pergunta("Estado não cadastrado. Deseja cadastrar agora?");

                if (Geral.Resposta)
                {
                    string       NovoEstado = CmbEstado.Text;
                    FrmCadEstado frm        = new FrmCadEstado();
                    frm.TxtEstado.Text = CmbEstado.Text;
                    frm.ShowDialog();
                    CarregarEstados();

                    CmbEstado.SelectedIndex = CmbEstado.FindStringExact(NovoEstado);
                }
            }
        }
Ejemplo n.º 2
0
        private void BtnCadastrar_Click_1(object sender, EventArgs e)
        {
            if (TxtNome.Text == "")
            {
                MessageBox.Show("Preencher Nome!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                TxtNome.Focus();
            }
            else if (TxtEndereco.Text == "")
            {
                MessageBox.Show("Preencher Endereço!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                TxtEndereco.Focus();
            }
            else if (CboSexo.Text == "Selecione")
            {
                MessageBox.Show("Selecione Sexo!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                CboSexo.Focus();
            }
            else if (TxtCidade.Text == "")
            {
                MessageBox.Show("Preencher Cidade!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                TxtCidade.Focus();
            }

            else if (TxtBairro.Text == "")
            {
                MessageBox.Show("Preencher Bairro!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                TxtBairro.Focus();
            }
            else if (CmbEstado.Text == "Selecione")
            {
                MessageBox.Show("Selecione Estado!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                CmbEstado.Focus();
            }
            else if (!MktCep.MaskCompleted)
            {
                MessageBox.Show("Preencher Cep!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                MktCep.Focus();
            }
            else if (!MktFoneFixo.MaskCompleted)
            {
                MessageBox.Show("Preencher Telefone Fixo!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                MktFoneFixo.Focus();
            }
            else if (!MkFoneComercial.MaskCompleted)
            {
                MessageBox.Show("Preencher Telefone Comercial!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                MkFoneComercial.Focus();
            }
            else if (!MktCelular.MaskCompleted)
            {
                MessageBox.Show("Preencher Telefone Celular!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                MktCelular.Focus();
            }
            else if (TxtRG.Text == "")
            {
                MessageBox.Show("Preencher RG!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                TxtRG.Focus();
            }

            else if (!MktCPF.MaskCompleted)
            {
                MessageBox.Show("Preencher CPF/CNPJ!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                MktCPF.Focus();
            }
            else if (TxtEmail.Text == "")
            {
                MessageBox.Show("Preencher E-mail!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                TxtEmail.Focus();
            }
            else if (CboCadPor.Text == "Selecione")
            {
                MessageBox.Show("Selecione o Usuário!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                CmbEstado.Focus();
            }
            else
            {
                conn.Open();
                try
                {
                    SqlCommand comando = new SqlCommand
                    {
                        CommandType = CommandType.Text,
                        CommandText = "INSERT INTO Clientes(Nome,Sexo,Endereco,Bairro,Cidade,Cep,Estado,FoneFixo,FoneComercial,Celular,RG,Email,CPF,DataNascimento,DataCad,Id_Usuario) VALUES ('" + TxtNome.Text + "','" + CboSexo.Text + "','" + TxtEndereco.Text + "','" + TxtBairro.Text + "','" + TxtCidade.Text + "','" + MktCep.Text + "','" + CmbEstado.Text + "','" + MktFoneFixo.Text + "','" + MkFoneComercial.Text + "','" + MktCelular.Text + "','" + TxtRG.Text + "','" + TxtEmail.Text + "','" + MktCPF.Text + "','" + dataNasc.Value.ToString("dd/MM/yyyy") + "','" + DateTime.Now + "',(select id_usuario from usuario where usuario.usuario='" + CboCadPor.Text + "'))",
                        Connection  = conn
                    };
                    comando.ExecuteNonQuery();
                    MessageBox.Show("Cliente Cadastrado com Sucesso!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("Erro ao Cadastrar Cliente!", "SIG", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                /*
                 *
                 * VERIFICAR ERRO
                 *
                 *
                 * string sql = "INSERT INTO NotaFiscalItens(Id_Produto,Qtd,Descricao,PrecoUnitario,NFNumero,Id_NotaFiscal) VALUES (@Id_Produto,@Qtd,@Descricao,@PrecoUnitario,@NfNumero,@Id_NotaFiscal)";
                 *  UPDATEESTOQUE.CommandText = (@"Update Produto set produto.qtde=10 from produto");
                 *
                 *  SqlCommand comandos = new SqlCommand(sql, conn);
                 *  for (int i = 0; i < dataGridView1.Rows.Count; i++)
                 *  {
                 *      comandos.Parameters.Clear();
                 *      comandos.Parameters.AddWithValue("@Id_Produto",
                 *          dataGridView1.Rows[i].Cells[0].Value);
                 *      comandos.Parameters.AddWithValue("@Qtd",
                 *          dataGridView1.Rows[i].Cells[1].Value);
                 *      comandos.Parameters.AddWithValue("@Descricao",
                 *          dataGridView1.Rows[i].Cells[2].Value);
                 *      comandos.Parameters.AddWithValue("@PrecoUnitario",
                 *          dataGridView1.Rows[i].Cells[3].Value);
                 *      comandos.Parameters.AddWithValue("@NFNumero",
                 *          dataGridView1.Rows[i].Cells[4].Value);
                 *      comandos.Parameters.AddWithValue("@Id_NotaFiscal",
                 *          dataGridView1.Rows[i].Cells[5].Value);
                 *      comandos.ExecuteNonQuery();
                 *  }
                 *
                 *  UPDATEESTOQUE.ExecuteNonQuery();
                 *  comandos.ExecuteNonQuery();
                 */


                LimpaDados();
                TxtNome.Focus();
                conn.Close();
            }
        }