예제 #1
0
        /// <summary>
        /// 按条件查询
        /// </summary>
        /// <returns></returns>
        public List <HRUser> FindByWhere(HRUser vo)
        {
            string whereSql = "";

            if (!EmptyUtils.EmptyStr(vo.Id))
            {
                whereSql += " and u.id=@Id";
            }
            if (!EmptyUtils.EmptyStr(vo.EmpId))
            {
                whereSql += " and u.Emp_Id=@EmpId";
            }
            if (!EmptyUtils.EmptyStr(vo.UserName))
            {
                whereSql += " and u.UserName=@UserName";
            }
            if (vo.UserType > 0)
            {
                whereSql += " and u.User_Type=@UserType";
            }

            string baseSql = @"SELECT u.*, e.name as EMP_NAME FROM HR_USER u , HR_EMPLOYEE e where u.emp_id = e.id";

            return(conn.Query <HRUser>(baseSql + whereSql, new {
                Id = vo.Id,
                EmpId = vo.EmpId,
                UserName = vo.UserName,
                UserType = vo.UserType,
            }).ToList());
        }
예제 #2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            lblError.Text = "";
            HRUser user = dao.Login(txtUserName.Text, txtPwd.Text);

            if (user == null)
            {
                lblError.Text = "用户名或者密码不正确,请重新输入。";
            }
            else
            {
                GlobalInfo.loginUser = user;
                GlobalInfo.loginEmp  = empDao.FindById(user.EmpId);

                if (GlobalInfo.loginEmp.Status == 2)
                {
                    lblError.Text = "用户已经被停用,请联系管理员。";
                }
                else
                {
                    this.Hide();
                    MainForm main = new MainForm();
                    main.Show();
                }
            }
        }
예제 #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!validateInput())
            {
                return;
            }

            btnSaveEnbaled(false);

            if (opration == OP_ADD)
            {
                HRUser vo = InputToVo(null);

                int ret = dao.Add(vo);
                if (ret > 0)
                {
                    listSource.Add(vo);
                }
            }
            else if (opration == OP_UPDATE)
            {
                HRUser vo = list[grid.CurrentRow.Index];
                vo = InputToVo(vo);
                dao.Update(vo);
                grid.Refresh();
            }

            CleanData();
        }
예제 #4
0
        public async Task SendTwoFactorCodeAsync(HRUser user)
        {
            int code = _random.Next(0, 999999);

            user.TwoFactorCode         = code.ToString("000000");
            user.TwoFactorCodeDateTime = DateTime.Now;
            await _userManager.UpdateAsync(user);

            _emailService.EmailTwoFactorCode(user);
        }
예제 #5
0
        private void btnFind_Click(object sender, EventArgs e)
        {
            HRUser vo = InputToVo(null);

            list = dao.FindByWhere(vo);

            var bindingList = new BindingList <HRUser>(list);

            listSource      = new BindingSource(bindingList, null);
            grid.DataSource = listSource;
        }
예제 #6
0
        // 新增
        public int Add(HRUser vo)
        {
            var ret = conn.Execute(@"insert HR_USER(ID,EMP_ID,PASSWORD,USERNAME,USER_TYPE) values (@Id,@EmpId,@Password,@Username,@UserType)",
                                   new[] { new { Id       = vo.Id,
                                                 EmpId    = vo.EmpId,
                                                 Password = vo.Password,
                                                 Username = vo.UserName,
                                                 UserType = vo.UserType } });

            Console.WriteLine(string.Format("插入数据库成功{0}", ret));
            return(ret);
        }
예제 #7
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <returns></returns>
 public int Update(HRUser vo)
 {
     return(conn.Execute(@"update HR_USER SET Id=@Id,EMP_ID=@EmpId,PASSWORD=@Password,USERNAME=@Username,USER_TYPE=@UserType WHERE id = @Id",
                         new
     {
         Id = vo.Id,
         EmpId = vo.EmpId,
         Password = vo.Password,
         Username = vo.UserName,
         UserType = vo.UserType,
     }));
 }
예제 #8
0
 private void ddlStatus_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (ddlStatus.SelectedIndex == 0)
     {
         dtpAffDate.Value   = HRUser.nextPaydate();
         dtpAffDate.Enabled = false;
     }
     else if (ddlStatus.SelectedIndex == 1)
     {
         dtpAffDate.Enabled = true;
     }
 }
예제 #9
0
 private void dtpAffDate_ValueChanged(object sender, EventArgs e)
 {
     if (ddlStatus.SelectedIndex == 1)
     {
         DateTime nextPay = HRUser.nextPaydate();
         if (dtpAffDate.Value < nextPay.AddDays(-14) || dtpAffDate.Value > nextPay)
         {
             dtpAffDate.Value = nextPay;
             MessageBox.Show("Must terminate within this pay period: " + nextPay.AddDays(-14).ToShortDateString() + " to " + nextPay.ToShortDateString(), "Invalid");
         }
     }
 }
        public async Task <ActionResult <LoginResponseViewModel> > Post([FromBody] SecondFactorRequestViewModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Username) || string.IsNullOrWhiteSpace(model.Password) || string.IsNullOrWhiteSpace(model.SecondFactorValue))
            {
                return(new UnauthorizedResult());
            }

            HRUser user = await _userManager.FindByNameAsync(model.Username);

            if (user != null)
            {
                Microsoft.AspNetCore.Identity.SignInResult result = await _signInManager.CheckPasswordSignInAsync(user, model.Password, false);

                if (result.Succeeded)
                {
                    if (_hrServices.ValidateTwoFactorCodeAsync(user, model.SecondFactorValue))
                    {
                        IList <string> roles = await _userManager.GetRolesAsync(user);

                        string role = "";
                        if (roles.Contains("Admin"))
                        {
                            role = "Admin";
                        }
                        else if (roles.Contains("User"))
                        {
                            role = "User";
                        }

                        JwtSecurityTokenHandler handler         = new JwtSecurityTokenHandler();
                        SymmetricSecurityKey    securityKey     = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_configuration["JwtKey"]));
                        SecurityTokenDescriptor tokenDescriptor = new SecurityTokenDescriptor
                        {
                            Subject = new ClaimsIdentity(new Claim[]
                            {
                                new Claim(ClaimTypes.Name, user.Id.ToString()),
                                new Claim(ClaimTypes.Role, role)
                            }),
                            Expires            = DateTime.UtcNow.AddDays(7),
                            SigningCredentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature),
                        };
                        SecurityToken          securityToken = handler.CreateToken(tokenDescriptor);
                        LoginResponseViewModel responseModel = new LoginResponseViewModel();
                        responseModel.Token = handler.WriteToken(securityToken);
                        return(new OkObjectResult(responseModel));
                    }
                }
            }
            return(new UnauthorizedResult());
        }
예제 #11
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            String   strRaise   = txtPercent.Text;
            DateTime affectDate = dtpAffDate.Value;

            if (strRaise == "" && affectDate < DateTime.Today)
            {
                MessageBox.Show("You must enter a raise percent and a date earlier than today", "Invalid");
            }
            else
            {
                try
                {
                    double raise = Convert.ToDouble(strRaise);

                    PayRaise payRaise = PayFactory.Create();
                    payRaise.payIn      = raise;
                    payRaise.newAffDate = dtpAffDate.Value;


                    if (rdoPer.Checked)
                    {
                        payRaise.empId = Main.currEmp.Id;
                        payRaise.selfCheck(Settings.Default.EmployeeId);
                        payRaise           = HRUser.UpdateRaise(payRaise);
                        pnlPayInfo.Visible = true;
                        txtNewPay.Text     = payRaise.newPay.ToString("C");
                        txtOldPay.Text     = payRaise.oldPay.ToString("C");
                        txtOldDate.Text    = payRaise.oldAffDate.ToShortDateString();
                    }
                    else
                    {
                        HRUser.UpdateAllRaises(payRaise);
                    }
                    lblSaved.Visible = true;
                }
                catch (InvalidCastException exCast)
                {
                    MessageBox.Show("Raise must be a number", "Invalid");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
예제 #12
0
 public bool ValidateTwoFactorCodeAsync(HRUser user, string code)
 {
     if (user.TwoFactorEnabled && user.TwoFactorCodeDateTime != null && !string.IsNullOrEmpty(user.TwoFactorCode))
     {
         TimeSpan codeTimeSpan = DateTime.Now - user.TwoFactorCodeDateTime;
         if (codeTimeSpan <= TimeSpan.FromMinutes(5))
         {
             if (code == user.TwoFactorCode)
             {
                 user.TwoFactorCode = "";
                 _userManager.UpdateAsync(user);
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #13
0
        private void grid_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }

            btnDelete.Enabled = true;
            btnUpdate.Enabled = true;

            HRUser vo = list[e.RowIndex];

            txtId.Text                = vo.Id;
            txtUserName.Text          = vo.UserName;
            txtPwd.Text               = vo.Password;
            cboEmp.SelectedValue      = vo.EmpId;
            cboUserType.SelectedValue = vo.UserType;
        }
예제 #14
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (grid.CurrentRow.Index < 0)
            {
                MessageBox.Show("请选择一条数据,在进行操作");
                return;
            }
            DialogResult result = MessageBox.Show(this, "确认要删除吗?", "", MessageBoxButtons.YesNo);

            //如果点击的是"YES"按钮,将form关闭.
            if (result == DialogResult.Yes)
            {
                HRUser vo = list[grid.CurrentRow.Index];
                dao.Delete(vo.Id);
                list.RemoveAt(grid.CurrentRow.Index);
                InitData();
            }
        }
예제 #15
0
        /// <summary>
        /// 输入转VO
        /// </summary>
        /// <returns></returns>
        private HRUser InputToVo(HRUser vo)
        {
            if (vo == null)
            {
                vo    = new HRUser();
                vo.Id = txtId.Text;
            }
            if (!EmptyUtils.EmptyObj(cboEmp.SelectedItem))
            {
                HREmployee empVo = cboEmp.SelectedItem as HREmployee;

                vo.EmpId   = empVo.Id;
                vo.EmpName = empVo.Name;
            }
            vo.UserName = txtUserName.Text;
            vo.Password = txtPwd.Text;
            vo.UserType = !EmptyUtils.EmptyObj(cboUserType.SelectedValue) ? int.Parse(cboUserType.SelectedValue.ToString()) : -1;

            return(vo);
        }
예제 #16
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!validateInput())
            {
                return;
            }
            HRUser user = dao.Login(GlobalInfo.loginUser.UserName, txtOldPwd.Text);

            if (user == null)
            {
                lblError.Text = "原始密码输入不正确。";
            }
            else
            {
                user.Password = txtNewPwd.Text;
                dao.Update(user);
                MessageBoxEx.Show(this, "密码修改成功");
                Close();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            AlertErrorPanel.Visible   = false;
            AlertSuccessPanel.Visible = false;
            if (Session["user"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            HRUser currentUser = (HRUser)Session["user"];

            UserFullNameLabel.Text = currentUser.Name;

            if (currentUser.isAdmin())
            {
                admin = true;
            }
            else
            {
                admin = false;
            }
        }
예제 #18
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     try
     {
         string username = TextBox1.Text;
         string password = TextBox2.Text;
         HRUser user     = HRUser.authenticate(username, password);
         if (user == null)
         {
             Label2.Text     = "Username and Password are incorrect!";
             Panel1.Visible  = true;
             Session["user"] = null;
         }
         else
         {
             Session["user"]  = user;
             Session["admin"] = user.isAdmin().ToString();
             Response.Redirect("Default.aspx");
         }
     }catch (Exception exception) {
         Panel1.Visible = true;
         Label2.Text    = exception.Message + exception.StackTrace;
     }
 }
        public async Task <ActionResult> Post([FromBody] LoginRequestViewModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Username) || string.IsNullOrWhiteSpace(model.Password))
            {
                return(new UnauthorizedResult());
            }

            HRUser user = await _userManager.FindByNameAsync(model.Username);

            if (user != null)
            {
                SignInResult result = await _signInManager.CheckPasswordSignInAsync(user, model.Password, false);

                if (result.Succeeded)
                {
                    //await _signInManager.SignInAsync(user,false);

                    await _hrServices.SendTwoFactorCodeAsync(user);

                    return(new OkResult());
                }
            }
            return(new UnauthorizedResult());
        }
예제 #20
0
        public void PerformPayroll(String pc)
        {
            Passcode frmPasscode = new Passcode();

            frmPasscode.ShowDialog();

            if (frmPasscode.DialogResult == DialogResult.OK)
            {
                if (frmPasscode.InPass == pc)
                {
                    DataTable currData = HRUser.generatePay();
                    dgvPayStubs.DataSource = currData;
                    frmPasscode.Close();

                    //personal info
                    txtId.DataBindings.Add(new Binding("Text", currData, "Employee ID"));
                    txtName.DataBindings.Add(new Binding("Text", currData, "Name"));
                    txtDob.DataBindings.Add(new Binding("Text", currData, "Birthday"));
                    txtAddress.DataBindings.Add(new Binding("Text", currData, "Address"));
                    txtPayrate.DataBindings.Add(new Binding("Text", currData, "Payrate"));

                    //current pay
                    txtGross.DataBindings.Add(new Binding("Text", currData, "Gross pay"));
                    txtTax.DataBindings.Add(new Binding("Text", currData, "Tax"));
                    txtCPP.DataBindings.Add(new Binding("Text", currData, "CPP"));
                    txtEi.DataBindings.Add(new Binding("Text", currData, "EI"));
                    txtPension.DataBindings.Add(new Binding("Text", currData, "Pension"));
                    txtNet.DataBindings.Add(new Binding("Text", currData, "Net pay"));

                    //YTD pay
                    txtYTDGross.DataBindings.Add(new Binding("Text", currData, "YTD Gross pay"));
                    txtYTDTax.DataBindings.Add(new Binding("Text", currData, "YTD Tax"));
                    txtYTDCPP.DataBindings.Add(new Binding("Text", currData, "YTD CPP"));
                    txtYTDEI.DataBindings.Add(new Binding("Text", currData, "YTD EI"));
                    txtYTDPension.DataBindings.Add(new Binding("Text", currData, "YTD Pension"));
                    txtYTDNet.DataBindings.Add(new Binding("Text", currData, "YTD Pay"));

                    //emails
                    List <String> emails = HRUser.PayrollEmails();
                    foreach (String e in emails)
                    {
                        MailMessage mail = new MailMessage();
                        mail.To.Add(e);
                        mail.From = new MailAddress("*****@*****.**");
                        SmtpClient client = new SmtpClient();
                        client.Port                  = 25;
                        client.EnableSsl             = false;
                        client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                        client.UseDefaultCredentials = true;
                        client.Host                  = "localhost";
                        mail.Subject                 = "Payroll has been processed.";
                        mail.Body = "You have been payed for working during the latest pay period for GearWorks, check your bank.";
                        client.Send(mail);
                    }
                }
                else
                {
                    MessageBox.Show("You must enter the correct code to generate pay", "Invalid");
                }
            }

            frmPasscode.Dispose();
        }
        public async Task <ActionResult <ResponseStatusViewModel> > Put(RegisterRequestViewModel model)
        {
            ResponseStatusViewModel responseModel = new ResponseStatusViewModel();

            responseModel.Result = true;
            if (string.IsNullOrWhiteSpace(model.FirstName))
            {
                responseModel.Result = false;
                responseModel.Messages.Add("First name cannot be blank.");
            }
            if (string.IsNullOrWhiteSpace(model.LastName))
            {
                responseModel.Result = false;
                responseModel.Messages.Add("Last name cannot be blank.");
            }
            if (string.IsNullOrWhiteSpace(model.Username))
            {
                responseModel.Result = false;
                responseModel.Messages.Add("Last name cannot be blank.");
            }
            if (string.IsNullOrWhiteSpace(model.Email))
            {
                responseModel.Result = false;
                responseModel.Messages.Add("Email cannot be blank.");
            }
            if (string.IsNullOrWhiteSpace(model.Password))
            {
                responseModel.Result = false;
                responseModel.Messages.Add("Password cannot be blank.");
            }
            if (!responseModel.Result)
            {
                return(new BadRequestObjectResult(responseModel));
            }

            HRUser hruser = new HRUser()
            {
                Email            = model.Email,
                UserName         = model.Username,
                FirstName        = model.FirstName,
                LastName         = model.LastName,
                TwoFactorEnabled = true
            };
            IdentityResult result = await _userManager.CreateAsync(hruser, model.Password);

            if (result.Succeeded)
            {
                IdentityRole userRole = _roleManager.Roles.FirstOrDefault(r => r.Name == "User");
                if (userRole == null)
                {
                    await _roleManager.CreateAsync(new IdentityRole("User"));
                }
                await _userManager.AddToRoleAsync(hruser, userRole.Name);

                responseModel.Result = true;
                responseModel.Messages.Add("Thank you for registering your account.");
                return(new OkObjectResult(responseModel));
            }
            else
            {
                responseModel.Result = false;
                responseModel.Messages.Add("Unable to create your user account.");
                return(new BadRequestObjectResult(responseModel));
            }
        }
예제 #22
0
        public void EmailTwoFactorCode(HRUser user)
        {
            string message = $"Hello {user.FirstName} {user.LastName},\n\nYour code is: {user.TwoFactorCode}";

            SendEmailAsync(user.Email, "Two Factor Code", message);
        }
    protected override DbRowParameter GetParameter()
    {
        HRUser user = new HRUser();

        return user.Parameter;
    }