Пример #1
0
 private void Login()
 {
     UserValidationModel model=new UserValidationModel();
     model.LoginName = textBoxName.Text.TrimStart().TrimEnd();
     model.Password = textBoxPassWord.Text;
     if (String.IsNullOrEmpty(model.LoginName) || String.IsNullOrEmpty(model.Password))
     {
         labelMessage.Text = "请录入登录信息";
     }
     else
     {
         HandlingResult result = new HandlingResult();
         ValidationAction action = new ValidationAction();
         result = action.ValidateLogin(model);
         if (result.Successed)
         {
             UserInformationModel user = (UserInformationModel)result.Result;
             UserInformationContext.ID = user.Id;
             UserInformationContext.Name = user.Name;
             UserInformationContext.LoginName = user.LoginName;
             UserInformationContext.LoginTime = DateTime.Now;
             UserInformationContext.LoginPass = true;
             UserInformationContext.StoreId = "";
             Close();
         }
         else
         {
             labelMessage.Text = result.Message;
         }
     }
 }
Пример #2
0
 public HandlingResult ValidateLogin(UserValidationModel model)
 {
     HandlingResult result=new HandlingResult();
     result.Successed = false;
     DataTable dt = null;
     String sql = String.Format("SELECT * FROM BPSYS_USER WHERE LOGINNAME='{0}'", model.LoginName);
     using (DataBaseProcess process = new DataBaseProcess())
     {
         dt = process.Query(sql);
     }
     if (dt != null && dt.Rows.Count > 0)
     {
         UserInformationModel usermodel = new UserInformationModel()
         {
             Id = Guid.Parse(dt.Rows[0]["ID"].ToString()),
             LoginName = dt.Rows[0]["LOGINNAME"].ToString(),
             Name = dt.Rows[0]["NAME"].ToString(),
             StoreId = dt.Rows[0]["STOREID"].ToString(),
         };
         String pw = Md5Helper.GetMD5String(model.Password);
         if (pw.Equals(dt.Rows[0]["PASSWORD"].ToString()))
         {
             result.Result = usermodel;
             result.Successed = true;
         }
         else
         {
             result.Message = "用户名或密码错误!";
         }
     }
     else
     {
         result.Message = "用户名或密码错误";
     }
     return result;
 }