Example #1
0
        public void RegisterEmploye()
        {
            Employee      lEmployee = new Employee();
            employeeQuery da        = new employeeQuery();

            //Verificar se é um funcionario novo ou ja existente
            if (txtId.Text != string.Empty)
            {
                lEmployee.Id = Convert.ToInt32(txtId.Text);
                if (txtName.Text != string.Empty)
                {
                    lEmployee.Name = txtName.Text;
                }
                else
                {
                    MessageBox.Show(Config.lFied + "NOME" + Config.lRequired, Config.lAlert);
                }

                if (txtCep.Text != string.Empty)
                {
                    lEmployee.ZipCode = txtCep.Text;
                }
                else
                {
                    MessageBox.Show(Config.lFied + "CEP" + Config.lRequired, Config.lAlert);
                }

                lEmployee.CivilState = txtCivilState.Text;
                lEmployee.BirthDate  = txtBirthDate.Text;
                lEmployee.Telephone  = txtFone.Text;
                lEmployee.Number     = txtNumber.Text;
                lEmployee.State      = txtState.Text;
                lEmployee.City       = txtCity.Text;
                lEmployee.Street     = txtStreet.Text;
                lEmployee.District   = txtDistrict.Text;

                if (txtCellphone.Text != string.Empty)
                {
                    lEmployee.CellPhone = txtCellphone.Text;
                }
                else
                {
                    MessageBox.Show(Config.lFied + "CELULAR" + Config.lRequired, Config.lAlert);
                }

                if (txtEmail.Text != string.Empty)
                {
                    lEmployee.Email = txtEmail.Text;
                }
                else
                {
                    MessageBox.Show(Config.lFied + "E-MAIL" + Config.lRequired, Config.lAlert);
                }

                if (txtUsername.Text != string.Empty)
                {
                    lEmployee.Username = txtUsername.Text;
                }
                else
                {
                    MessageBox.Show(Config.lFied + "LOGIN" + Config.lRequired, Config.lAlert);
                }

                if (txtPassword.Text != string.Empty)
                {
                    if (txtPassword.Text.Length >= 8)
                    {
                        lEmployee.Password = txtPassword.Text;
                    }
                    else
                    {
                        MessageBox.Show("A senha deve conter pelo menos 8 caracteres", Config.lAlert);
                    }
                }
                else
                {
                    MessageBox.Show(Config.lFied + "SENHA" + Config.lRequired, Config.lAlert);
                }

                if (txtRole.Text != string.Empty)
                {
                    lEmployee.Role = txtRole.Text;
                }
                else
                {
                    MessageBox.Show(Config.lFied + "CARGO" + Config.lRequired, Config.lAlert);
                }

                if (txtCPF.Text != string.Empty)
                {
                    lEmployee.Document = txtCPF.Text;
                }
                else
                {
                    MessageBox.Show(Config.lFied + "CPF" + Config.lRequired, Config.lAlert);
                }

                if (txtStatus.Text == "Ativo" && txtStatus.Text != string.Empty)
                {
                    lEmployee.Status = "A";
                }
                else if (txtStatus.Text != string.Empty)
                {
                    lEmployee.Status = "I";
                }
                else
                {
                    MessageBox.Show(Config.lFied + "STATUS" + Config.lRequired, Config.lAlert);
                }


                if (txtName.Text != string.Empty && txtStreet.Text != string.Empty && txtCity.Text != string.Empty && txtState.Text != string.Empty &&
                    txtCellphone.Text != string.Empty && txtEmail.Text != string.Empty && txtUsername.Text != string.Empty && txtPassword.Text != string.Empty &&
                    txtRole.Text != string.Empty && txtCPF.Text != string.Empty && txtStatus.Text != string.Empty && txtPassword.Text.Length >= 8)
                {
                    da.Update(lEmployee);
                    MessageBox.Show(MessageBoxResult.lUpdate);
                    CleanMethod();
                }
                else
                {
                    MessageBox.Show(Config.lErrorRegister, MessageBoxResult.lErrorUpdate);
                }
            }
            else if (MessageBox.Show("Deseja receber um e-mail para confirmar o cadastro?", Config.lAlert, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                MySqlConnection con = new MySqlConnection(Connection.lConnection);
                con.Open();
                string       consulta = "SELECT empUsername,empDocument, empEmail FROM employee WHERE empDocument = @CPF OR empUsername = @LOGIN OR empEmail = @EMAIL";
                MySqlCommand cmd      = new MySqlCommand(consulta, con);

                //Passo o parametro
                cmd.Parameters.Add("@CPF", MySqlDbType.VarChar).Value   = txtCPF.Text;
                cmd.Parameters.Add("@LOGIN", MySqlDbType.VarChar).Value = txtUsername.Text;
                cmd.Parameters.Add("@EMAIL", MySqlDbType.VarChar).Value = txtEmail.Text;

                MySqlDataReader le = null;
                le = cmd.ExecuteReader();

                //se o usuario já estiver cadastrado
                if (le.Read())
                {
                    if (MessageBox.Show("Este usuario já está cadastrado, gostaria de pesquisar o mesmo?", Config.lAlert, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        tabControl1.SelectedTab = tabPage2;
                    }
                }
                //se não estiver
                else
                {
                    if (txtName.Text != string.Empty)
                    {
                        lEmployee.Name = txtName.Text;
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "NOME" + Config.lRequired, Config.lAlert);
                    }

                    if (txtCep.Text != string.Empty)
                    {
                        lEmployee.ZipCode = txtCep.Text;
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "CEP" + Config.lRequired, Config.lAlert);
                    }

                    lEmployee.State    = txtState.Text;
                    lEmployee.City     = txtCity.Text;
                    lEmployee.Street   = txtStreet.Text;
                    lEmployee.District = txtDistrict.Text;

                    lEmployee.CivilState = txtCivilState.Text;
                    lEmployee.BirthDate  = txtBirthDate.Text;
                    lEmployee.Telephone  = txtFone.Text;
                    lEmployee.Number     = txtNumber.Text;

                    if (txtCellphone.Text != string.Empty)
                    {
                        lEmployee.CellPhone = txtCellphone.Text;
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "CELULAR" + Config.lRequired, Config.lAlert);
                    }

                    if (txtEmail.Text != string.Empty)
                    {
                        lEmployee.Email = txtEmail.Text;
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "E-MAIL" + Config.lRequired, Config.lAlert);
                    }

                    if (txtUsername.Text != string.Empty)
                    {
                        lEmployee.Username = txtUsername.Text;
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "LOGIN" + Config.lRequired, Config.lAlert);
                    }

                    if (txtPassword.Text != string.Empty)
                    {
                        if (txtPassword.Text.Length >= 8)
                        {
                            lEmployee.Password = txtPassword.Text;
                        }
                        else
                        {
                            MessageBox.Show("A senha deve conter pelo menos 8 caracteres", Config.lAlert);
                        }
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "SENHA" + Config.lRequired, Config.lAlert);
                    }

                    if (txtRole.Text != string.Empty)
                    {
                        lEmployee.Role = txtRole.Text;
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "CARGO" + Config.lRequired, Config.lAlert);
                    }

                    if (txtCPF.Text != string.Empty)
                    {
                        lEmployee.Document = txtCPF.Text;
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "CPF" + Config.lRequired, Config.lAlert);
                    }

                    if (txtStatus.Text == "Ativo" && txtStatus.Text != string.Empty)
                    {
                        lEmployee.Status = "A";
                    }
                    else if (txtStatus.Text != string.Empty)
                    {
                        lEmployee.Status = "I";
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "STATUS" + Config.lRequired, Config.lAlert);
                    }

                    if (txtName.Text != string.Empty && txtStreet.Text != string.Empty && txtCity.Text != string.Empty && txtState.Text != string.Empty &&
                        txtCellphone.Text != string.Empty && txtEmail.Text != string.Empty && txtUsername.Text != string.Empty && txtPassword.Text != string.Empty &&
                        txtRole.Text != string.Empty && txtCPF.Text != string.Empty && txtStatus.Text != string.Empty && txtPassword.Text.Length >= 8)
                    {
                        da.Add(lEmployee);
                        MessageBox.Show(MessageBoxResult.lSucess);
                        CleanMethod();
                    }
                    else
                    {
                        MessageBox.Show(Config.lErrorRegister, MessageBoxResult.lError);
                    }
                }
            }
            else
            {
                MySqlConnection con = new MySqlConnection(Connection.lConnection);
                con.Open();
                string       consulta = "SELECT empUsername,empDocument, empEmail FROM employee WHERE empDocument = @CPF OR empUsername = @LOGIN OR empEmail = @EMAIL";
                MySqlCommand cmd      = new MySqlCommand(consulta, con);

                //Passo o parametro
                cmd.Parameters.Add("@CPF", MySqlDbType.VarChar).Value   = txtCPF.Text;
                cmd.Parameters.Add("@LOGIN", MySqlDbType.VarChar).Value = txtUsername.Text;
                cmd.Parameters.Add("@EMAIL", MySqlDbType.VarChar).Value = txtEmail.Text;

                MySqlDataReader le = null;
                le = cmd.ExecuteReader();


                //se o usuario já estiver cadastrado
                if (le.Read())
                {
                    if (MessageBox.Show("Este usuario já está cadastrado, gostaria de pesquisar o mesmo?", Config.lAlert, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        tabControl1.SelectedTab = tabPage2;
                    }
                }
                else
                {
                    if (txtName.Text != string.Empty)
                    {
                        lEmployee.Name = txtName.Text;
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "NOME" + Config.lRequired, Config.lAlert);
                    }

                    lEmployee.State    = txtState.Text;
                    lEmployee.City     = txtCity.Text;
                    lEmployee.Street   = txtStreet.Text;
                    lEmployee.District = txtDistrict.Text;

                    lEmployee.CivilState = txtCivilState.Text;
                    lEmployee.BirthDate  = txtBirthDate.Text;
                    lEmployee.Telephone  = txtFone.Text;
                    lEmployee.Number     = txtNumber.Text;

                    if (txtCellphone.Text != string.Empty)
                    {
                        lEmployee.CellPhone = txtCellphone.Text;
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "CELULAR" + Config.lRequired, Config.lAlert);
                    }

                    if (txtEmail.Text != string.Empty)
                    {
                        lEmployee.Email = txtEmail.Text;
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "E-MAIL" + Config.lRequired, Config.lAlert);
                    }

                    if (txtUsername.Text != string.Empty)
                    {
                        lEmployee.Username = txtUsername.Text;
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "LOGIN" + Config.lRequired, Config.lAlert);
                    }

                    if (txtPassword.Text != string.Empty)
                    {
                        if (txtPassword.Text.Length >= 8)
                        {
                            lEmployee.Password = txtPassword.Text;
                        }
                        else
                        {
                            MessageBox.Show("A senha deve conter pelo menos 8 caracteres", Config.lAlert);
                        }
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "SENHA" + Config.lRequired, Config.lAlert);
                    }

                    if (txtRole.Text != string.Empty)
                    {
                        lEmployee.Role = txtRole.Text;
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "CARGO" + Config.lRequired, Config.lAlert);
                    }

                    if (txtCPF.Text != string.Empty)
                    {
                        lEmployee.Document = txtCPF.Text;
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "CPF" + Config.lRequired, Config.lAlert);
                    }

                    if (txtStatus.Text == "Ativo" && txtStatus.Text != string.Empty)
                    {
                        lEmployee.Status = "A";
                    }
                    else if (txtStatus.Text != string.Empty)
                    {
                        lEmployee.Status = "I";
                    }
                    else
                    {
                        MessageBox.Show(Config.lFied + "STATUS" + Config.lRequired, Config.lAlert);
                    }

                    if (txtName.Text != string.Empty && txtCep.Text != string.Empty && txtStreet.Text != string.Empty && txtCity.Text != string.Empty && txtState.Text != string.Empty &&
                        txtCellphone.Text != string.Empty && txtEmail.Text != string.Empty && txtUsername.Text != string.Empty && txtPassword.Text != string.Empty &&
                        txtRole.Text != string.Empty && txtCPF.Text != string.Empty && txtStatus.Text != string.Empty && txtPassword.Text.Length >= 8)
                    {
                        da.Add(lEmployee);
                        MessageBox.Show(MessageBoxResult.lSucess);
                    }
                    else
                    {
                        MessageBox.Show(Config.lErrorRegister, MessageBoxResult.lError);
                    }

                    try
                    {
                        MySqlConnection conn = new MySqlConnection(Connection.lConnection);
                        conn.Open();
                        string       consulta1 = "SELECT empName,empEmail FROM employee WHERE empEmail = @empEmail";
                        MySqlCommand cmd1      = new MySqlCommand(consulta1, conn);
                        //Passo o parametro
                        cmd1.Parameters.AddWithValue("@empEmail", txtEmail.Text);
                        MySqlDataReader reader = cmd1.ExecuteReader();
                        string          lEmail = string.Empty;
                        string          lName  = string.Empty;
                        while (reader.Read())
                        {
                            lName  = reader["empName"].ToString();
                            lEmail = reader["empEmail"].ToString();
                        }
                        Email = new MailMessage();
                        Email.To.Add(new MailAddress(lEmail));
                        Email.From       = (new MailAddress(Credentials.lAdress));
                        Email.Subject    = "Bem Vindo a Farmalife";
                        Email.IsBodyHtml = true;
                        Email.Body       = "Ceo:Giovanni Nascimento Santos <br/> FarmaLife Enterprise 2018 ® </br> <b>Bem vindo a nossa equipe senhor(a)," + lName + " seu cadastro foi concluído perfeitamente e o senhor(a) já pode utilizar nosso sistema.</br> </b> </br> <i> Não responder esse e-mail</i></br>";
                        SmtpClient employee = new SmtpClient(Credentials.lSmtpLive, Credentials.lSmtpLivePort);
                        using (employee)
                        {
                            employee.Credentials = new System.Net.NetworkCredential(Credentials.lAdress, Credentials.lPassword);
                            employee.EnableSsl   = true;
                            employee.Send(Email);
                        }
                        conn.Close();
                        CleanMethod();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, MessageBoxResult.lEmailError);
                        errorQuery lerrorQuery = new errorQuery();
                        lerrorQuery.AddError(Principal.lUser, MessageBoxResult.lEmailError, ex.Message.Replace("'", ""), DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), "Cadastro Funcionario");
                    }
                }
            }
        }
Example #2
0
        // nível de hierarquia ao logar
        private void Principal_Load(object sender, EventArgs e)
        {
            if (Login.lType == "1")
            {
                //visible
                cadastrarPesquisarFuncionarioToolStripMenuItem.Visible = true;
                cadastrarPesquisarRemédiosToolStripMenuItem.Visible    = true;
                controleDeVendasToolStripMenuItem.Visible   = true;
                pesquisarRemédiosToolStripMenuItem.Visible  = false;
                apagarBancoDeDadosToolStripMenuItem.Visible = false;

                //enable
                cadastrarPesquisarFuncionarioToolStripMenuItem.Enabled = true;
                cadastrarPesquisarRemédiosToolStripMenuItem.Enabled    = true;
                controleDeVendasToolStripMenuItem.Enabled   = true;
                pesquisarRemédiosToolStripMenuItem.Enabled  = false;
                apagarBancoDeDadosToolStripMenuItem.Enabled = false;
            }
            if (Login.lType == "2")
            {
                //visible
                cadastrarPesquisarFuncionarioToolStripMenuItem.Visible = false;
                cadastrarPesquisarRemédiosToolStripMenuItem.Visible    = true;
                controleDeVendasToolStripMenuItem.Visible   = true;
                pesquisarRemédiosToolStripMenuItem.Visible  = false;
                apagarBancoDeDadosToolStripMenuItem.Visible = false;

                //enable
                cadastrarPesquisarFuncionarioToolStripMenuItem.Enabled = false;
                cadastrarPesquisarRemédiosToolStripMenuItem.Enabled    = true;
                controleDeVendasToolStripMenuItem.Enabled   = true;
                pesquisarRemédiosToolStripMenuItem.Enabled  = false;
                apagarBancoDeDadosToolStripMenuItem.Enabled = false;
            }
            if (Login.lType == "3")
            {
                //visible
                cadastrarPesquisarFuncionarioToolStripMenuItem.Visible = false;
                cadastrarPesquisarRemédiosToolStripMenuItem.Visible    = false;
                controleDeVendasToolStripMenuItem.Visible   = true;
                pesquisarRemédiosToolStripMenuItem.Visible  = true;
                apagarBancoDeDadosToolStripMenuItem.Visible = false;
                //enable
                cadastrarPesquisarFuncionarioToolStripMenuItem.Enabled = false;
                cadastrarPesquisarRemédiosToolStripMenuItem.Enabled    = false;
                controleDeVendasToolStripMenuItem.Enabled   = true;
                pesquisarRemédiosToolStripMenuItem.Enabled  = true;
                apagarBancoDeDadosToolStripMenuItem.Enabled = false;
            }
            if (Login.lType == "0")
            {
                //visible
                cadastrarPesquisarFuncionarioToolStripMenuItem.Visible = true;
                cadastrarPesquisarRemédiosToolStripMenuItem.Visible    = true;
                controleDeVendasToolStripMenuItem.Visible   = true;
                pesquisarRemédiosToolStripMenuItem.Visible  = true;
                apagarBancoDeDadosToolStripMenuItem.Visible = true;
                //enable
                cadastrarPesquisarFuncionarioToolStripMenuItem.Enabled = true;
                cadastrarPesquisarRemédiosToolStripMenuItem.Enabled    = true;
                controleDeVendasToolStripMenuItem.Enabled   = true;
                pesquisarRemédiosToolStripMenuItem.Enabled  = true;
                apagarBancoDeDadosToolStripMenuItem.Enabled = true;
            }
            lblDate.Text = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");

            if (Login.lType != "0")
            {
                employeeQuery lEmployeeQuery = new employeeQuery();
                lblUser.Text = lEmployeeQuery.GetEmployeeById(lUser);
            }
            else
            {
                lblUser.Text = "Admin";
            }
        }