예제 #1
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            if (txt_old_password.Text.Trim() == "")
            {
                MessageBox.Show("Old Password is empty.", "Validation");
                txt_old_password.Focus();
            }
            else if (txt_new_password.Text.Trim() == "")
            {
                MessageBox.Show("New Password is empty.", "Validation");
                txt_new_password.Focus();
            }
            else if (txt_v_new_password.Text.Trim() == "")
            {
                MessageBox.Show("Verify Password is empty.", "Validation");
                txt_v_new_password.Focus();
            }
            else if (Cryptography.Encrypt(txt_old_password.Text.Trim()) != Cryptography.Encrypt(Global.Account_Password))
            {
                MessageBox.Show("Incorrect old password.", "Error");
                txt_old_password.Focus();
            }
            else if (txt_old_password.Text.Trim() == txt_new_password.Text.Trim())
            {
                MessageBox.Show("Old password and new password is equal.", "Validation");
                txt_old_password.Focus();
                txt_new_password.Clear();
                txt_v_new_password.Clear();
            }
            else if (txt_new_password.Text.Trim() != txt_v_new_password.Text.Trim())
            {
                MessageBox.Show("New paassword is not equal to validate password.", "Validation");
                txt_new_password.Clear();
                txt_v_new_password.Clear();
                txt_new_password.Focus();
            }
            else
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure you want to save new password?", "New Password", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    try
                    {
                        using (MySqlConnection conn = new MySqlConnection(Global.MyConn))
                        {
                            conn.Open();
                            string       password = Cryptography.Encrypt(txt_new_password.Text.Trim());
                            string       query    = "UPDATE tbl_user Set password = '******' where id='" + Global.AccountID + "'";
                            MySqlCommand command  = new MySqlCommand(query, conn);
                            command.ExecuteReader();
                            conn.Close();
                            MessageBox.Show("Save Successfully");

                            SetAccount();
                            this.Hide();
                            if (Global.FromLogin)
                            {
                                var frm_login = new frm_login();
                                frm_login.ShowDialog();
                            }


                            this.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
예제 #2
0
        private void btn_login_Click(object sender, EventArgs e)
        {
            if (txt_username.Text == "admin" && txt_password.Text == "sysadmin")
            {
                Global.AccountType = "admin";
                Global.AccountName = "System Administrator";
                Global.AccountID   = "1";

                this.Hide();
                var frm_admin = new frm_admin();
                frm_admin.ShowDialog();
                this.Close();
            }
            else
            {
                try
                {
                    using (MySqlConnection conn = new MySqlConnection(Global.MyConn))
                    {
                        conn.Open();
                        string       password = Cryptography.Encrypt(txt_password.Text.Trim());
                        string       query    = "SELECT * from tbl_user where username='******' and password='******'";
                        MySqlCommand command  = new MySqlCommand(query, conn);
                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    Global.AccountEmp_ID    = reader.GetString(1).ToString();
                                    Global.AccountType      = reader.GetString(5).ToString();
                                    Global.AccountName      = reader.GetString(2).ToString();
                                    Global.AccountID        = reader.GetString(0).ToString();
                                    Global.Account_Password = txt_password.Text;

                                    if (Cryptography.Encrypt(Global.AccountEmp_ID) == password)
                                    {
                                        Global.FromLogin = true;
                                        this.Hide();
                                        var frm_change_password = new frm_change_password();
                                        frm_change_password.ShowDialog();
                                        this.Close();
                                    }
                                    else
                                    {
                                        if (Global.AccountType == "Admin")
                                        {
                                            this.Hide();
                                            var frm_admin = new frm_admin();
                                            frm_admin.ShowDialog();
                                            this.Close();
                                        }
                                        else if (Global.AccountType == "Registrar")
                                        {
                                            this.Hide();
                                            var frm_registrar = new frm_registrar();
                                            frm_registrar.ShowDialog();
                                            this.Close();
                                        }
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show("Incorrect Username or password.", "Error");
                                txt_password.Clear();
                                txt_password.Focus();
                            }
                        }
                        conn.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
예제 #3
0
 private void btn_save_Click(object sender, EventArgs e)
 {
     if (txt_empId.Text.Trim() == "")
     {
         MessageBox.Show("Invalid Employee ID", "Error");
         txt_empId.Focus();
     }
     else if (txt_AccountName.Text.Trim() == "")
     {
         MessageBox.Show("Invalid Account Name", "Error");
         txt_AccountName.Focus();
     }
     else if (txt_username.Text.Trim() == "")
     {
         MessageBox.Show("Invalid Username", "Error");
         txt_username.Focus();
     }
     else if (cmb_usertype.SelectedItem.ToString().Trim() == "")
     {
         MessageBox.Show("Invalid Usertype", "Error");
         cmb_usertype.Focus();
     }
     else
     {
         if (Global.AddAccount)
         {
             DialogResult dialogResult = MessageBox.Show("Are you sure you want to add this Account?", "Adding Account", MessageBoxButtons.YesNo);
             if (dialogResult == DialogResult.Yes)
             {
                 try
                 {
                     using (MySqlConnection conn = new MySqlConnection(Global.MyConn))
                     {
                         conn.Open();
                         string       query   = "SELECT * from tbl_user where Emp_id='" + txt_empId.Text + "' or Account_name='" + txt_AccountName.Text + "' or username='******' order by Account_name";
                         MySqlCommand command = new MySqlCommand(query, conn);
                         using (MySqlDataReader reader = command.ExecuteReader())
                         {
                             if (reader.HasRows)
                             {
                                 MessageBox.Show("Employee Id or Account name is already exist or username is alredy used by other account", "Conplict");
                             }
                             else
                             {
                                 using (MySqlConnection conn1 = new MySqlConnection(Global.MyConn))
                                 {
                                     conn1.Open();
                                     string       password = Cryptography.Encrypt(txt_empId.Text);
                                     string       query1   = "Insert into tbl_user(Emp_id,Account_name,username,password,UserType) values ('" + txt_empId.Text + "','" + txt_AccountName.Text + "','" + txt_username.Text + "','" + password + "','" + cmb_usertype.SelectedItem.ToString() + "')";
                                     MySqlCommand command1 = new MySqlCommand(query1, conn1);
                                     command1.ExecuteReader();
                                     conn1.Close();
                                     MessageBox.Show(txt_AccountName.Text + " successfully added.", "Procccess Done");
                                 }
                             }
                         }
                         conn.Close();
                         Load_Account_list();
                     }
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message);
                 }
             }
         }
         else if (Global.EditAccount)
         {
             DialogResult dialogResult = MessageBox.Show("Are you sure you want to update this Account?", "Edit Account", MessageBoxButtons.YesNo);
             if (dialogResult == DialogResult.Yes)
             {
                 try
                 {
                     using (MySqlConnection conn = new MySqlConnection(Global.MyConn))
                     {
                         conn.Open();
                         string       query   = "SELECT * from tbl_user where Account_name!='" + Global.AffectedAccount + "' and (Emp_id='" + txt_empId.Text + "' or Account_name='" + txt_AccountName.Text + "' or username='******') order by Account_name";
                         MySqlCommand command = new MySqlCommand(query, conn);
                         using (MySqlDataReader reader = command.ExecuteReader())
                         {
                             if (reader.HasRows)
                             {
                                 MessageBox.Show("Employee Id or Account name is already exist or username is alredy used by other account", "Conplict");
                             }
                             else
                             {
                                 using (MySqlConnection conn1 = new MySqlConnection(Global.MyConn))
                                 {
                                     conn1.Open();
                                     string       query1   = "UPDATE tbl_user SET Emp_id='" + txt_empId.Text + "',Account_name='" + txt_AccountName.Text + "',username='******',UserType='" + cmb_usertype.SelectedItem.ToString() + "' where Account_name='" + Global.AffectedAccount + "'";
                                     MySqlCommand command1 = new MySqlCommand(query1, conn1);
                                     command1.ExecuteReader();
                                     conn1.Close();
                                     MessageBox.Show(Global.AffectedAccount + " Successfully updated.", "Procccess Done");
                                 }
                             }
                         }
                         conn.Close();
                         Load_Account_list();
                     }
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message);
                 }
             }
         }
     }
 }