Ejemplo n.º 1
0
        private bool Update_user_details()
        {
            string   str_username = txt_username.Text.Trim();
            string   str_name     = txt_name.Text.Trim();
            string   str_ic_no    = txt_ic_no.Text.Trim();
            DateTime date_join    = dtp_join.Value;
            DateTime?date_leave   = (ch_empty_leave_date.Checked) ? (DateTime?)null : dtp_leave.Value;

            byte[] byte_image = null;

            if (str_username.Length == 0 || str_name.Length == 0)
            {
                MessageBox.Show("Username and Name is required.", "Missing input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (!User.Is_username_valid(str_username))
            {
                MessageBox.Show("Username is invalid. Only aphanumeric characters allowed for username. Please retry",
                                "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (!User.Is_username_available(str_username, Obj_user.UserID))
            {
                MessageBox.Show("Username is taken.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (date_leave != null && date_leave < date_join)
            {
                MessageBox.Show("Leave date cannot be before Join Date.", "Invalid input",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (grd_usergroup.SelectedRows.Count == 0)
            {
                MessageBox.Show("Usergroup is required. Please go to 'Permission' tab to select usergroup.", "Invalid input",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            if (picbox_image.Image != null)
            {
                Image img = picbox_image.Image;
                using (MemoryStream ms = new MemoryStream())
                {
                    img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    byte_image = ms.ToArray();
                }
            }
            string str_usergroup = grd_usergroup.SelectedRows[0].Cells["usergroup"].Value.ToString();

            User_ds.Update_user(Obj_user.UserID, str_username, str_name, str_ic_no, date_join, date_leave, byte_image, str_usergroup);

            if (Obj_user.UserID == Program.System_user.UserID)
            {
                Program.System_user = new User(Obj_user.UserID);                 // refresh current user details
            }
            return(true);
        }
Ejemplo n.º 2
0
        private bool Log_in()
        {
            string str_username = txt_username.Text.Trim();
            string str_password = txt_password.Text;

            User_ds.sp_user_loginDataTable dttable_user = User_ds.Select_password(str_username);

            if (dttable_user.Rows.Count == 0 || !((bool)dttable_user.Rows[0]["is_active"]))
            {
                return(false);
            }

            return(VerifyHash(str_password, dttable_user.Rows[0]["password"].ToString()));
        }
Ejemplo n.º 3
0
        private void Btn_ok_Click(object sender, EventArgs e)
        {
            if (txt_new_pw.Text.Length == 0)
            {
                MessageBox.Show("New password cannot be empty.", "Input invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!Form_log_in.VerifyHash(txt_old_pw.Text, Program.System_user.Password))
            {
                MessageBox.Show("Old password entered is invalid.", "Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            User_ds.Update_user_password(Form_log_in.ComputeHash(txt_new_pw.Text, null));

            MessageBox.Show("Password successfully changed.");

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Ejemplo n.º 4
0
 private void Btn_return_by_Click(object sender, EventArgs e)
 {
     // TODO: select only active user instead of all!!
     using (Form_datagridview_select dlg_select = new Form_datagridview_select(User_ds.Select_user_all(),
                                                                               new string[] { "name", "usergroup", "ic_no", "is_active", "join_date", "leave_date" }, "user",
                                                                               btn_return_by.Tag.ToString()))
     {
         if (dlg_select.ShowDialog() == DialogResult.OK && dlg_select.grd_main.SelectedCells.Count > 0)
         {
             txt_return_by.Text = dlg_select.Get_selected_value_as_string("name");
             btn_return_by.Tag  = dlg_select.Get_selected_value_as_int("user");
         }
     }
 }
Ejemplo n.º 5
0
 public static bool Is_username_available(string str_username, int exclude_user_id = 0)
 {
     return(User_ds.Check_username_available(str_username, exclude_user_id));
 }
Ejemplo n.º 6
0
 public bool Has_permission(string permission)
 {
     return(User_ds.Check_user_has_permission(UserID, permission));
 }
Ejemplo n.º 7
0
 public User(int user_id)
 {
     Init_obj(User_ds.Select_user(user_id));
 }
Ejemplo n.º 8
0
 public User(string str_username)
 {
     Init_obj(User_ds.Select_user(str_username));
 }