/// <summary>
        /// thuc thi thay doi
        /// </summary>
        private void apply()
        {
            int roleID = 1;

            if (rdUser.Checked)
            {
                roleID = 2;
            }

            try
            {
                if (FunctionSession1.updateUserRole(uid, roleID))
                {
                    MessageBox.Show("Successfully changed!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    loadData();
                }
                else
                {
                    MessageBox.Show("Change Failure!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error: can not load data", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            string reason = "";

            if (rdSoftwareCash.Checked)
            {
                reason += "Software cash!";
            }
            else if (rdSystemCash.Checked)
            {
                reason += "System cash!";
            }

            if (richTextBox1.Text != "")
            {
                reason += " " + richTextBox1.Text;
            }
            if (reason != "")
            {
                bool success = FunctionSession1.UpdateLogs(GlobalClass.UserID, LastLoginTime, TimeSpan.Zero, reason);
                this.Close();
            }
            else
            {
                MessageBox.Show("You must input the reason !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #3
0
        public void LoadUser(int officeId = -1)
        {
            lvUser.Items.Clear();
            DataTable dt = FunctionSession1.getAllUser(officeId);

            foreach (DataRow r in dt.Rows)
            {
                ListViewItem item = new ListViewItem();
                item.Text = r["FirstName"] + string.Empty;
                item.SubItems.Add(r["LastName"] + string.Empty);
                item.SubItems.Add(r["Age"] + string.Empty);
                item.SubItems.Add(r["RoleTitle"] + string.Empty);
                item.SubItems.Add(r["Email"] + string.Empty);
                item.SubItems.Add(r["OfficeTitle"] + string.Empty);
                item.SubItems.Add(r["ID"] + string.Empty);
                item.SubItems.Add(r["Active"] + string.Empty);
                if (!bool.Parse(r["Active"] + string.Empty))
                {
                    item.BackColor = Color.Red;
                    item.ForeColor = Color.White;
                }
                lvUser.Items.Add(item);
            }
            if (lvUser.Items.Count > 0)
            {
                lvUser.Items[selectPos].Selected = true;
            }
        }
Beispiel #4
0
        /// <summary>
        ///enable or disable user
        /// </summary>
        private void enableUser()
        {
            ListView.SelectedListViewItemCollection row = lvUser.SelectedItems;
            int uid    = Convert.ToInt32(row[0].SubItems[6].Text + string.Empty);
            int active = bool.Parse(row[0].SubItems[7].Text + string.Empty)?0:1;

            FunctionSession1.enableUser(uid, active);
            selectPos = row[0].Index;
            LoadUser();
        }
Beispiel #5
0
 private void btnExit_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Do you want to exit ?", "Warning !!!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         if (GlobalClass.UserID != -1)
         {
             FunctionSession1.Logout(GlobalClass.UserID, GlobalClass.LoginTime);
         }
         this.Close();
     }
 }
Beispiel #6
0
        private void loadLogs()
        {
            lvLogs.Items.Clear();
            DataTable dtLogs = FunctionSession1.getLogs();
            TimeSpan  totalTimeSpentOnSystem = new TimeSpan();
            int       numOfCashes            = 0;

            for (int i = 0; i < dtLogs.Rows.Count - 1; i++)
            {
                DateTime loginTime     = DateTime.Parse(dtLogs.Rows[i]["LoginTime"].ToString());
                string   strLogoutTime = "**";
                //string strReason = "";
                string timeSpent = "**";
                if (!DBNull.Value.Equals(dtLogs.Rows[i]["LogoutTime"]))
                {
                    if (!TimeSpan.Parse(dtLogs.Rows[i]["LogoutTime"].ToString()).Equals(TimeSpan.Zero))
                    {
                        DateTime logoutTime = DateTime.Parse(dtLogs.Rows[i]["LogoutTime"].ToString());
                        strLogoutTime = loginTime.ToString("HH:mm");
                        TimeSpan timeS = logoutTime.Subtract(loginTime);
                        totalTimeSpentOnSystem = totalTimeSpentOnSystem.Add(timeS);
                        timeSpent = timeS.ToString(@"hh\:mm\:ss");
                    }
                }
                else
                {
                    numOfCashes++;
                }

                string[] arrayItem =
                {
                    DateTime.Parse(dtLogs.Rows[i]["DateLogin"].ToString()).ToString("dd/MM/yyyy"),
                    loginTime.ToString("HH:mm"),
                    strLogoutTime,
                    timeSpent,
                    dtLogs.Rows[i]["Reason"].ToString()
                };
                ListViewItem item = new ListViewItem(arrayItem);
                if (strLogoutTime == "**")
                {
                    item.BackColor = Color.Red;
                }
                lvLogs.Items.Add(item);
            }

            lblTimeSpent.Text      = "Time spent on system: " + totalTimeSpentOnSystem.ToString(@"hh\:mm\:ss");
            lblNumberOfCashes.Text = "Number of cashes: " + numOfCashes.ToString();
        }
Beispiel #7
0
 private void frmUser_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (isClose)
     {
         return;
     }
     if (MessageBox.Show("Do you want to exit ?", "Warning !!!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
     {
         e.Cancel = true;
     }
     else
     {
         if (GlobalClass.UserID != -1)
         {
             FunctionSession1.Logout(GlobalClass.UserID, GlobalClass.LoginTime);
         }
         this.Close();
     }
 }
        private void saveData()
        {
            Dictionary <String, Object> param = new Dictionary <string, object>();

            param.Add("Email", tbEmail.Text.ToString());
            param.Add("Password", FunctionSession1.MD5(tbPassword.Text.ToString()));
            param.Add("FirstName", tbFName.Text.ToString());
            param.Add("LastName", tbLName.Text.ToString());
            param.Add("OfficeID", cbOffice.SelectedValue.ToString());
            param.Add("Birthdate", tbBdate.Text.ToString());
            if (FunctionSession1.insertUser(param))
            {
                MessageBox.Show("Saved successfully!!!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
                FrmAdmin.LoadUser();
                emptyField();
            }
            else
            {
                MessageBox.Show("save failed!!!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// load data
        /// </summary>
        private void loadData()
        {
            DataTable dt = FunctionSession1.getOneUser(uid);

            try
            {
                tbEmail.Text  = dt.Rows[0]["Email"].ToString();
                tbFName.Text  = dt.Rows[0]["FirstName"].ToString();
                tbLName.Text  = dt.Rows[0]["LastName"].ToString();
                cbOffice.Text = dt.Rows[0]["Title"].ToString();
                if (dt.Rows[0]["RoleID"].ToString() == "1")
                {
                    rdAdmin.Checked = true;
                }
                else
                {
                    rdUser.Checked = true;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error: can not load data", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 /// <summary>
 /// load data
 /// </summary>
 public void loadData()
 {
     cbOffice.DataSource    = FunctionSession1.getAllOffices();
     cbOffice.DisplayMember = "Title";
     cbOffice.ValueMember   = "ID";
 }
Beispiel #11
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            isValidate = true;
            this.ValidateChildren();
            string    username = txtUsername.Text;
            string    password = txtPassword.Text;
            DataTable dtUser   = FunctionSession1.Login(username, password);

            if (dtUser.Rows.Count > 0)
            {
                // Login successful :D
                int role = Int32.Parse(dtUser.Rows[0]["RoleID"].ToString());
                GlobalClass.RoleID    = role;
                GlobalClass.FirstName = dtUser.Rows[0]["FirstName"].ToString();
                GlobalClass.UserID    = Int32.Parse(dtUser.Rows[0]["ID"].ToString());
                GlobalClass.LoginTime = DateTime.Now.TimeOfDay;
                Boolean isActive = Boolean.Parse(dtUser.Rows[0]["Active"].ToString());

                if (isActive)
                {
                    DataTable userLogs  = FunctionSession1.getLogByUserId(GlobalClass.UserID);
                    int       logsCount = userLogs.Rows.Count;
                    if (logsCount >= 1 && DBNull.Value.Equals(userLogs.Rows[logsCount - 1]["LogoutTime"]))
                    {
                        this.Hide();
                        frmNoLogoutDetected frmReport = new frmNoLogoutDetected();
                        frmReport.LastDateLogin = DateTime.Parse(userLogs.Rows[logsCount - 1]["DateLogin"].ToString());
                        frmReport.LastLoginTime = TimeSpan.Parse(userLogs.Rows[logsCount - 1]["LoginTime"].ToString());
                        frmReport.ShowDialog();
                    }

                    if (role == 1)
                    {
                        MessageBox.Show("Login successful. You're Admin");
                    }
                    else
                    {
                        bool success = FunctionSession1.InsertLogs(GlobalClass.UserID, DateTime.Now.Date, GlobalClass.LoginTime);
                        if (success)
                        {
                            isClose = true;
                            this.Close();
                            frmUser frmUser = new frmUser();
                            frmUser.Show();
                        }
                        else
                        {
                            MessageBox.Show("Cannot write the logs to database !!!");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Your account was disabled !!!");
                }
            }
            else
            {
                loginCount++;
                if (loginCount >= 3)
                {
                    txtUsername.Enabled = false;
                    txtPassword.Enabled = false;
                    btnLogin.Enabled    = false;
                    timer.Enabled       = true;
                    loginCount          = 0;
                }
                MessageBox.Show("Username or password was wrong !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            isValidate = false;
        }