public Boolean CheckUserLogin(UserEmployeeModel userEmployeeModel) { UserEmployeeModel user = userDAL.getUserByEmployeeNumber(userEmployeeModel.EmployeeNumber); if (user != null && this.CheckPassword(user, userEmployeeModel.Password)) { return true; } else { return false; } }
public ActionResult Login(UserEmployeeModel userEmployeeModel) { BLLUserAccount bllUserAccount = new BLLUserAccount(); Boolean result = bllUserAccount.CheckUserLogin(userEmployeeModel); if (result == true) { FormsAuthentication.SetAuthCookie(Convert.ToString(userEmployeeModel.EmployeeNumber), false); return RedirectToAction("Index", "Index"); } else { ViewData["errorMsg"] = "用户名和密码错误"; return View(); } }
public Boolean CreateUserAccount(UserEmployeeModel userEmployeeModel) { geekinsidekmsEntities context = new geekinsidekmsEntities(); DAL.UserEmployee userEmployee = ConvertToDB(userEmployeeModel); context.AddToUserEmployees(userEmployee); DAL.UserEmployeeDetail userDetail = new DAL.UserEmployeeDetail(); userDetail.Name = userEmployeeModel.Name; userDetail.Email = userEmployeeModel.Email; userDetail.EmployeeNumber = userEmployeeModel.EmployeeNumber; userDetail.Phone = userEmployeeModel.Phone; context.AddToUserEmployeeDetails(userDetail); context.SaveChanges(); return true; }
public Boolean DeleteUserAccount(UserEmployeeModel userEmployeeModel, UserEmployeeDetailModel userEmployeeDetailModel) { geekinsidekmsEntities context = new geekinsidekmsEntities(); UserEmployeeDetail dbDetail = (from detail in context.UserEmployeeDetails where detail.EmployeeNumber == userEmployeeDetailModel.EmployeeNumber select detail).FirstOrDefault(); context.DeleteObject(dbDetail); context.SaveChanges(); UserEmployee dbUser = (from user in context.UserEmployees where user.EmployeeNumber == userEmployeeModel.EmployeeNumber select user).FirstOrDefault(); context.DeleteObject(dbUser); context.SaveChanges(); return true; }
public Boolean UpdateUserAccount(UserEmployeeModel userEmployeeModel) { geekinsidekmsEntities context = new geekinsidekmsEntities(); UserEmployeeDetail empDetal = (from d in context.UserEmployeeDetails where d.EmployeeNumber == userEmployeeModel.EmployeeNumber select d).FirstOrDefault(); empDetal.EmployeeNumber = userEmployeeModel.EmployeeNumber; empDetal.Name = userEmployeeModel.Name; empDetal.Email = userEmployeeModel.Email; empDetal.Phone = userEmployeeModel.Phone; context.SaveChanges(); UserEmployee emp = (from u in context.UserEmployees where u.EmployeeNumber == userEmployeeModel.EmployeeNumber select u).FirstOrDefault(); emp.EmployeeNumber = userEmployeeModel.EmployeeNumber; emp.Password = userEmployeeModel.Password; emp.DepartmentId = userEmployeeModel.DepartmentId; emp.IsManager = userEmployeeModel.IsManager; emp.IsAvailable = userEmployeeModel.IsAvailable; emp.IsChecker = userEmployeeModel.IsChecker; emp.LastLoginTime = userEmployeeModel.LastLoginTime; context.SaveChanges(); return true; }
private UserEmployee ConvertToDB(UserEmployeeModel userEmployeeModel) { if (userEmployeeModel == null) return null; DAL.UserEmployee userEmployee = new DAL.UserEmployee(); userEmployee.EmployeeNumber = userEmployeeModel.EmployeeNumber; userEmployee.Password = userEmployeeModel.Password; userEmployee.IsChecker = userEmployeeModel.IsChecker; userEmployee.IsAvailable = userEmployeeModel.IsAvailable; userEmployee.LastLoginTime = userEmployeeModel.LastLoginTime; userEmployee.DepartmentId = userEmployeeModel.DepartmentId; userEmployee.IsManager = userEmployeeModel.IsManager; return userEmployee; }
public ActionResult doCreateUser() { BLLUserAccount bllUserAccount = new BLLUserAccount(); UserEmployeeModel userEmployeeModel = new UserEmployeeModel(); UserEmployeeDetailModel userEmployeeDetailModel = new UserEmployeeDetailModel(); userEmployeeModel.EmployeeNumber = bllUserAccount.GetMaxEmployeeNumber() + 1; userEmployeeModel.Password = "******"; userEmployeeModel.DepartmentId = Convert.ToInt32(Request.Form["dept_name"]); userEmployeeModel.IsManager = (Convert.ToInt32(Request.Form["isManager"]) == 0 ? false : true); userEmployeeModel.IsChecker = (Convert.ToInt32(Request.Form["isChecker"]) == 0 ? false : true); userEmployeeModel.IsAvailable = (Convert.ToInt32(Request.Form["isAvailable"]) == 0 ? false : true); userEmployeeModel.Name = Request.Form["name"]; userEmployeeModel.Email = Request.Form["email"]; userEmployeeModel.Phone = Request.Form["phone"]; if (userEmployeeModel.Email == null || !isEmail(userEmployeeModel.Email)) { TempData["employeeNumberErrorMsg"] = "请输入正确的邮箱地址!"; return RedirectToAction("CreateUser", "Employee"); } if (userEmployeeModel.Phone == null ||!isPhone(userEmployeeModel.Phone)) { TempData["phoneErrorMsg"] = "请输入正确的手机号!"; return RedirectToAction("CreateUser", "Employee"); } Boolean result = bllUserAccount.CreateUserAccount(userEmployeeModel); if (result == true) { ViewData["successMsg"] = "添加成功"; return RedirectToAction("Index", "Employee"); } else { ViewData["errorMsg"] = "添加失败"; return RedirectToAction("Index", "Employee"); } }
public ActionResult StationImport(HttpPostedFileBase filebase) { BLLUserAccount bllUserAccount = new BLLUserAccount(); HttpPostedFileBase file = Request.Files["files"]; string FileName; string savePath; if (file == null || file.ContentLength <= 0) { ViewData["errorMsg"] = "文件不能为空"; return View(); } else { string filename = Path.GetFileName(file.FileName); int filesize = file.ContentLength;//获取上传文件的大小单位为字节byte string fileEx = System.IO.Path.GetExtension(filename);//获取上传文件的扩展名 string NoFileName = System.IO.Path.GetFileNameWithoutExtension(filename);//获取无扩展名的文件名 int Maxsize = 4000 * 1024;//定义上传文件的最大空间大小为4M string FileType = ".xls,.xlsx,.cvs";//定义上传文件的类型字符串 FileName = NoFileName + DateTime.Now.ToString("yyyyMMddhhmmss") + fileEx; if (!FileType.Contains(fileEx)) { ViewData["errorMsg"] = "文件类型不对,只能导入xls和xlsx格式的文件"; return View(); } if (filesize >= Maxsize) { ViewData["errorMsg"] = "上传文件超过4M,不能上传"; return View(); } string path = AppDomain.CurrentDomain.BaseDirectory + "Content\\uploads\\excel\\"; if (!Directory.Exists(Path.GetDirectoryName(path))) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } savePath = Path.Combine(path, FileName); file.SaveAs(savePath); } //string result = string.Empty; string strConn; strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + savePath + ";" + "Extended Properties=Excel 8.0"; OleDbConnection conn = new OleDbConnection(strConn); conn.Open(); OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from [Sheet1$]", strConn); DataSet myDataSet = new DataSet(); try { myCommand.Fill(myDataSet, "ExcelInfo"); } catch (Exception ex) { ViewData["errorMsg"] = ex.Message; return View(); } DataTable table = myDataSet.Tables["ExcelInfo"].DefaultView.ToTable(); //引用事务机制,出错时,事物回滚 using (TransactionScope transaction = new TransactionScope()) { for (int i = 0; i < table.Rows.Count; i++) { UserEmployeeModel temp = new UserEmployeeModel(); temp.EmployeeNumber = bllUserAccount.GetMaxEmployeeNumber() + 1; temp.Password = "******"; temp.Name = table.Rows[i].ItemArray[0].ToString(); temp.Email = table.Rows[i].ItemArray[1].ToString(); temp.Phone = table.Rows[i].ItemArray[2].ToString(); temp.DepartmentId = Convert.ToInt32(table.Rows[i].ItemArray[3].ToString()); temp.IsManager = (Convert.ToInt32(table.Rows[i].ItemArray[4].ToString()) == 0 ? false : true); temp.IsChecker = (Convert.ToInt32(table.Rows[i].ItemArray[5].ToString()) == 0 ? false : true); temp.IsAvailable = (Convert.ToInt32(table.Rows[i].ItemArray[6].ToString()) == 0 ? false : true); bllUserAccount.CreateUserAccount(temp); } transaction.Complete(); } ViewData["successMsg"] = "导入成功"; System.Threading.Thread.Sleep(2000); return RedirectToAction("Index"); }
public Boolean UpdateUserAccount(UserEmployeeModel userEmployeeModel) { userDAL.UpdateUserAccount(userEmployeeModel); return true; }
public Boolean DeleteUserAccount(UserEmployeeModel userEmployeeModel, UserEmployeeDetailModel userEmployeeDetailModel) { userDAL.DeleteUserAccount(userEmployeeModel, userEmployeeDetailModel); return true; }
public Boolean CreateUserAccount(UserEmployeeModel userEmployeeModel) { userEmployeeModel.Password = Helper.EncryptByMD5(userEmployeeModel.Password); userDAL.CreateUserAccount(userEmployeeModel); return true; }
public Boolean CheckPassword(UserEmployeeModel userEmployeeModel, string password) { string encryptPassword = Helper.EncryptByMD5(password); return userEmployeeModel.Password == encryptPassword; //return true; }