private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
            LoginMain loginMain = new LoginMain();

            loginMain.Show();
        }
Ejemplo n.º 2
0
        private void SuccessedLogin(string userName, string password)
        {
            var accountType = (from u in db.Users where u.Email.CompareTo(userName) == 0 && u.Password.CompareTo(password) == 0
                               select new { roleID = u.RoleID,
                                            name = u.FirstName });

            if (accountType.First().roleID == 1)
            {
                Constain.userName = accountType.First().name.ToString();
                this.Hide();
                LoginMain loginMain = new LoginMain();
                loginMain.ShowDialog();
                this.Show();
            }
            else
            {
                Constain.userName = accountType.First().name.ToString();
                Setup();
                this.Hide();
                Crashes();
                MainLoginUser mainLoginUser = new MainLoginUser();
                mainLoginUser.ShowDialog();
                this.Show();
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            int    a = 0, b = 0, c = 0, d = 0, e1 = 0, f = 0, g = 0, h = 0;
            string email     = txtEmail.Text;
            string firstName = txtFirstName.Text;
            string lastName  = txtLastName.Text;
            string office    = cbOffice.SelectedText;

            //string date = txtDate.Text;
            DateTime date;

            DateTime.TryParseExact(txtDate.Text, "dd/MM/yy", null,
                                   System.Globalization.DateTimeStyles.None, out date);
            string pass = txtPassword.Text;

            int temp = (from u in db.Users where (u.Email == email) select u).Count();


            if (email == "")
            {
                txtEmail.Text      = "* What's your email adress?";
                txtEmail.ForeColor = Color.Red;
                a = 1;
            }

            if (temp == 1)
            {
                txtEmail.Text      = "* This email have been used!";
                txtEmail.ForeColor = Color.Red;
                b = 1;
            }


            if (firstName == "")
            {
                txtFirstName.Text      = "* What's your first name?";
                txtFirstName.ForeColor = Color.Red;
                c = 1;
            }

            if (lastName == "")
            {
                txtLastName.Text      = "* What's your last name?";
                txtLastName.ForeColor = Color.Red;
                d = 1;
            }

            if (pass == "")
            {
                txtPassword.UseSystemPasswordChar = false;
                txtPassword.Text      = "* Input your password!?";
                txtPassword.ForeColor = Color.Red;
                e1 = 1;
            }

            if (date == null)
            {
                txtPassword.Text      = "* Input your password!?";
                txtPassword.ForeColor = Color.Red;
                f = 1;
            }

            if (cbOffice.Text == "Office name" || cbOffice.Text == "")
            {
                cbOffice.ForeColor = Color.Red;
                cbOffice.Text      = "* Choose your office name correctly!";
                g = 1;
            }

            if (txtDate.Text == "[ dd/MM/yy ]" || txtDate.Text == "")
            {
                txtDate.Text      = "* Input your birthday!";
                txtDate.ForeColor = Color.Red;
                h = 1;
            }

            if (txtEmail.Text == "* What's your email adress?" ||
                txtEmail.Text == "* This email have been used!" ||
                txtFirstName.Text == "* What's your first name?" ||
                txtLastName.Text == "* What's your last name?" ||
                txtPassword.Text == "* Input your password!?" ||
                cbOffice.Text == "* Choose your office name correctly!" ||
                txtDate.Text == "* Input your birthday!")
            {
                MessageBox.Show("You must input all information!", "Notify", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (a == 0 && b == 0 && c == 0 && d == 0 && e1 == 0 && f == 0 && g == 0 && h == 0)
            {
                using (session_1_dbDataContext db = new session_1_dbDataContext())
                {
                    User user = new User();
                    user.Email     = email;
                    user.Birthdate = date;
                    user.Active    = true;
                    user.FirstName = firstName;
                    user.LastName  = lastName;
                    int idx = cbOffice.SelectedIndex;
                    if (idx < 1)
                    {
                        idx += 1;
                    }
                    else
                    {
                        idx += 2;
                    }
                    user.OfficeID = idx;
                    user.Password = GenerateMD5(pass);
                    user.RoleID   = 2;
                    user.ID       = (from u in db.Users select(u)).Count() + 1;

                    db.Users.InsertOnSubmit(user);

                    try
                    {
                        db.SubmitChanges();
                        MessageBox.Show("Added successfuly!", "Notify", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadData();
                        LoginMain loginMain = new LoginMain();
                        loginMain.LoadData();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Can't add this account!\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                return;
            }
        }