Beispiel #1
0
        public MyUserInfo(int userID)
        {
            try
            {
                MyHREntities hrEntities = new MyHREntities();
                //抓員工資料
                var q = (hrEntities.Users.Where(o => o.EmployeeID == userID).Select(o => new { o.Photo, o.EmployeeName, o.EmployeeEnglishName, o.Department, o.JobTitle, o.Phone, Supervisor = o.Supervisor == null ? o.EmployeeID : o.Supervisor })).ToList();
                //var q = (hrEntities.Users
                //    .Join(hrEntities.Departments, u => u.Department, d => d.DepartmentID, (u, d) => new { u.EmployeeID, u.EmployeeName, u.EmployeeEnglishName, u.Department, d.DepartmentName, u.JobTitle, u.Phone, u.Supervisor })
                //    //.Join(hrEntities.Departments, u => u.Department, d => d.DepartmentID, (u, d) => new { U = u, D = d})
                //    .Join(hrEntities.JobTitles, u => u.JobTitle, j => j.JobTitleID, (u, j) => new { u, j.JobTitle1 })
                //    .Where(o => o.u.EmployeeID == userID))
                //    .ToList();
                //抓員工部門名稱
                var q2 = (hrEntities.Users
                          .Join(hrEntities.Departments,
                                u => u.Department,
                                d => d.DepartmentID,
                                (u, d) => new
                {
                    u.EmployeeID,
                    DepartmentName = d.DepartmentName
                })
                          .Where(ud => ud.EmployeeID == userID))
                         .ToList();
                //抓員工職稱名稱
                var q3 = (hrEntities.Users
                          .Join(hrEntities.JobTitles,
                                u => u.JobTitle,
                                j => j.JobTitleID,
                                (u, j) => new
                {
                    u.EmployeeID,
                    JobTitleName = j.JobTitle1,
                })
                          .Where(uj => uj.EmployeeID == userID))
                         .ToList();

                ID           = userID;
                Photo        = q[0].Photo;
                Name         = q[0].EmployeeName;
                EnglishName  = q[0].EmployeeEnglishName;
                Dept         = (int)q[0].Department;
                DeptName     = q2[0].DepartmentName;
                JobTitle     = (int)q[0].JobTitle;
                JobTitleName = q3[0].JobTitleName;
                Phone        = q[0].Phone;
                Supervisor   = (int)q[0].Supervisor;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        int count = 1;//計算登入次數

        private void OK_Click(object sender, EventArgs e)
        {
            try
            {
                int    UserID   = int.Parse(this.UsernameTextBox.Text);
                string password = this.PasswordTextBox.Text;

                string connstring = Settings.Default.MyHR;
                using (SqlConnection conn = new SqlConnection())
                {
                    conn.ConnectionString = connstring;

                    SqlCommand command = new SqlCommand();
                    command.Connection  = conn;
                    command.CommandText = $"select AccountEnable,EmployeeName from [User] where EmployeeID=@UserID and PassWord=@Password";

                    command.Parameters.Add("@UserID", SqlDbType.NVarChar, 16).Value   = UserID;
                    command.Parameters.Add("@Password", SqlDbType.NVarChar, 40).Value = password;

                    conn.Open();
                    SqlDataReader dataReader = command.ExecuteReader();
                    int           x          = 0;

                    MyHREntities hr = new MyHREntities();

                    dataReader.Read();

                    if (dataReader.HasRows)
                    {
                        x = int.Parse(dataReader[0].ToString());

                        if (x == 1)
                        {
                            MessageBox.Show($"登入成功,歡迎~{dataReader[1]},祝您有個美好的一天");

                            Frm_HomePage hp = new Frm_HomePage();
                            hp.UserID    = UserID;//傳 UserID 到 Hompage
                            this.Visible = false;
                            hp.ShowDialog();
                            this.Dispose();
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("帳號未啟用[AccountEnable],請通知管理員");
                        }
                    }
                    else
                    {
                        MessageBox.Show("登入失敗,請確認帳號密碼是否輸入錯誤");

                        count++;

                        if (count > 3)
                        {
                            MessageBox.Show("帳號已關閉,請聯絡管理員!");

                            var q = from p in hr.Users
                                    where p.EmployeeID == UserID
                                    select p;

                            foreach (var i in q)
                            {
                                i.AccountEnable = 0;
                            }
                            hr.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }