コード例 #1
0
        private void loginLogic()
        {
            if (txtUserNo.Text.Trim() == "")
            {
                MessageBox.Show("Please fill the UserNo");
            }
            else if (txtPassword.Text.Trim() == "")
            {
                MessageBox.Show("Please fill the Password box");
            }
            else
            {
                string password = txtPassword.Text;
                if (Convert.ToInt32(txtUserNo.Text) > 6)
                {
                    password = PasswordEncryption.CreateMD5Hash(password);
                }
                List <EMPLOYEE> employeeList = EmployeeBLL.GetEmployees(Convert.ToInt32(txtUserNo.Text), password);

                if (employeeList.Count == 0)
                {
                    MessageBox.Show("Wrong username or password!");
                }
                else
                {
                    EMPLOYEE employee = new EMPLOYEE();
                    employee = employeeList.First();
                    UserStatic.EmployeeID = employee.ID;
                    UserStatic.UserNo     = employee.UserNo;
                    UserStatic.isAdmin    = employee.isAdmin;
                    FrmMain frm = new FrmMain();
                    this.Hide();
                    frm.ShowDialog();
                }
            }
        }
コード例 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtUserNo.Text.Trim() == "")
            {
                MessageBox.Show("User No is empty!");
            }

            else if (txtPassword.Text.Trim() == "")
            {
                MessageBox.Show("User has no password!");
            }
            else if (txtName.Text.Trim() == "")
            {
                MessageBox.Show("User Name is empty!");
            }
            else if (txtSurname.Text.Trim() == "")
            {
                MessageBox.Show("User Surname is empty!");
            }
            else if (txtSalary.Text.Trim() == "")
            {
                MessageBox.Show("User has no salary!");
            }
            else if (cmbDepartment.SelectedIndex == -1)
            {
                MessageBox.Show("Select a department!");
            }
            else if (cmbPosition.SelectedIndex == -1)
            {
                MessageBox.Show("Select a position!");
            }
            else
            {
                if (!isUpdated)
                {
                    if (!EmployeeBLL.isUnique(Convert.ToInt32(txtUserNo.Text)))
                    {
                        MessageBox.Show("This user No is already taken!");
                    }
                    else
                    {
                        EMPLOYEE employee = new EMPLOYEE();
                        employee.UserNo       = Convert.ToInt32(txtUserNo.Text);
                        employee.Password     = PasswordEncryption.CreateMD5Hash(txtPassword.Text);
                        employee.isAdmin      = chAdmin.Checked;
                        employee.Name         = txtName.Text;
                        employee.Surname      = txtSurname.Text;
                        employee.Salary       = Convert.ToInt32(txtSalary.Text);
                        employee.DepartmentID = Convert.ToInt32(cmbDepartment.SelectedValue);
                        employee.PositionID   = Convert.ToInt32(cmbPosition.SelectedValue);
                        employee.Address      = txtAddress.Text;
                        employee.Birthday     = dateTimePicker1.Value;
                        employee.ImagePath    = fileName;
                        EmployeeBLL.AddEmployee(employee);
                        File.Copy(txtImagePath.Text, @"Images\\" + fileName);
                        MessageBox.Show("Employee successfuly added!");
                        txtUserNo.Clear();
                        txtPassword.Clear();
                        chAdmin.Checked = false;
                        txtName.Clear();
                        txtSurname.Clear();
                        txtSalary.Clear();
                        txtAddress.Clear();
                        txtImagePath.Clear();
                        pictureBox1.Image           = null;
                        comboFull                   = false;
                        cmbDepartment.SelectedIndex = -1;
                        cmbPosition.DataSource      = dto.Positions;
                        cmbPosition.SelectedIndex   = -1;
                        comboFull                   = true;
                        dateTimePicker1.Value       = DateTime.Today;
                        fileName = "";
                    }
                }

                else
                {
                    DialogResult dialogResult = MessageBox.Show("Are you sure?", "Warning", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        EMPLOYEE employee = new EMPLOYEE();
                        if (txtImagePath.Text != imagePath)
                        {
                            if (File.Exists(@"Images\\" + detail.ImagePath))
                            {
                                File.Delete(@"Images\\" + detail.ImagePath);
                            }
                            File.Copy(txtImagePath.Text, @"Images\\" + fileName);
                            employee.ImagePath = fileName;
                        }
                        else
                        {
                            employee.ImagePath = detail.ImagePath;
                        }
                        employee.ID           = detail.EmployeeID;
                        employee.UserNo       = Convert.ToInt32(txtUserNo.Text);
                        employee.Address      = txtAddress.Text;
                        employee.Birthday     = dateTimePicker1.Value;
                        employee.Name         = txtName.Text;
                        employee.Surname      = txtSurname.Text;
                        employee.Password     = txtPassword.Text;
                        employee.isAdmin      = chAdmin.Checked;
                        employee.DepartmentID = Convert.ToInt32(cmbDepartment.SelectedValue);
                        employee.PositionID   = Convert.ToInt32(cmbPosition.SelectedValue);
                        employee.Salary       = Convert.ToInt32(txtSalary.Text);
                        EmployeeBLL.UpdateEmployee(employee);
                        MessageBox.Show("Employee updated!");
                        this.Close();
                    }
                }
            }
        }