Beispiel #1
0
		public int userLogin(User user)
		{
			int loginState = 0;

			using(UsersDataAccess usersDataAccess = new UsersDataAccess())
			{
				loginState = usersDataAccess.userLogin(user);
			}

			return loginState;
		}
Beispiel #2
0
		private void simpleButton_Login_Click(object sender, System.EventArgs e)
		{
            StartSqlExpressIfStopped();


			simpleButton_Login.Enabled = false;

			string userLoginID = textEdit_UserLoginID.Text.Trim();
			string userPassword = textEdit_UserLoginPwd.Text.Trim();

			new UserSystem().DeleteSpecialRole();

#if SoftwareRegister
			try
			{
				RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey("Software");
				RegistryKey winSysDataKey = softwareKey.OpenSubKey("WindowsDataSystem");

				if ( winSysDataKey == null )
				{
					MessageBox.Show("您还未进行注册,请用供应商提供的序列号进行注册!","系统信息!",
						MessageBoxButtons.OK,MessageBoxIcon.Information);

					return;
				}

				RegistryKey ctppKey = winSysDataKey.OpenSubKey("Corporation");

				if ( ctppKey == null )
				{
					MessageBox.Show("您还未进行注册,请用供应商提供的序列号进行注册!","系统信息!",
						MessageBoxButtons.OK,MessageBoxIcon.Information);

					return;
				}
				else
				{
					DateTime createDate = Convert.ToDateTime(ctppKey.GetValue("CreateDate"));

					if ( Convert.ToInt32(ctppKey.GetValue("RegisterUser")) == 1 )
					{
						if ( Convert.ToInt32(ctppKey.GetValue("RegisterDays")) >= 30 )
						{
							MessageBox.Show("您的软件已经过期,请与您的供应商取得联系!","系统信息!",
								MessageBoxButtons.OK,MessageBoxIcon.Information);

							return;
						}
						else if ( 30 - Convert.ToInt32(ctppKey.GetValue("RegisterDays")) <= 5 )
						{
							if ( createDate.Date < DateTime.Now.Date || createDate > DateTime.Now ) 
							{
								int registerDays = Convert.ToInt32(ctppKey.GetValue("RegisterDays"))+1;
		
								ctppKey.Close();
								winSysDataKey.Close();
								softwareKey.Close();

								softwareKey = Registry.LocalMachine.OpenSubKey("Software",true);
								winSysDataKey = softwareKey.CreateSubKey("WindowsDataSystem");
								ctppKey = winSysDataKey.CreateSubKey("Corporation");

								ctppKey.SetValue("CreateDate",DateTime.Now);
								ctppKey.SetValue("RegisterDays",registerDays);
							}

							string messageShow = string.Format("您的软件还有{0}天即将过期,请与您的供应商取得联系!",
								30-Convert.ToInt32(ctppKey.GetValue("RegisterDays")));
	
							MessageBox.Show(messageShow,"系统信息!",MessageBoxButtons.OK,MessageBoxIcon.Information);
						}
						else
						{
							if ( createDate.Date < DateTime.Now.Date || createDate > DateTime.Now ) 
							{
								int registerDays = Convert.ToInt32(ctppKey.GetValue("RegisterDays"))+1;

								ctppKey.Close();
								winSysDataKey.Close();
								softwareKey.Close();

								softwareKey = Registry.LocalMachine.OpenSubKey("Software",true);
								winSysDataKey = softwareKey.CreateSubKey("WindowsDataSystem");
								ctppKey = winSysDataKey.CreateSubKey("Corporation");

								ctppKey.SetValue("CreateDate",DateTime.Now);
								ctppKey.SetValue("RegisterDays",registerDays);
							}
						}
					}
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show("在登录系统的时候出现未知程序错误,请与您的供应商取得联系!","系统信息!",MessageBoxButtons.OK,MessageBoxIcon.Information);
				CPTT.SystemFramework.Util.WriteLog(ex.Message,CPTT.SystemFramework.Util.EXCEPTION_LOG_TITLE);

				return;
			}
#endif

			if(!userLoginID.Equals(string.Empty)&&!userPassword.Equals(string.Empty))
			{
				loginUser = new User(userLoginID,userPassword);

				int loginState = 0;

				try
				{
					loginState = userSystem.userLogin(loginUser);

					//					if(loginState == -1)
					//					{
					//						MessageBox.Show("该用户不存在,请重试!!","系统信息!",
					//							MessageBoxButtons.OK,MessageBoxIcon.Information);
					//						textEdit_UserLoginID.Focus();
					//						return;
					//					}
					//					else if(loginState == 2)
					//					{
					//						MessageBox.Show("密码错误,请重试!!","系统信息!",
					//							MessageBoxButtons.OK,MessageBoxIcon.Information);
					//						textEdit_UserLoginPwd.SelectAll();
					//						return;
					//					}
					//					else 
					if(loginState == 1)
					{
						textEdit_UserLoginID.Text = string.Empty;
						textEdit_UserLoginPwd.Text = string.Empty;

						AssignUniqueGardenID();

#if MaxClients
						if ( utilSystem.IsSessionClient(Thread.CurrentPrincipal.Identity.Name) )
						{
							if ( utilSystem.UpdateSessionClient(Thread.CurrentPrincipal.Identity.Name) != 1 )
							{
								MessageBox.Show("更新服务器会话时发生错误,请联系供应商");
								return;
							}
						}
						else
						{
							if ( utilSystem.GetCurrentClients() < CPTT.SystemFramework.Util.MaxClients )
							{
								if ( utilSystem.InsertSessionClient(Thread.CurrentPrincipal.Identity.Name) != 1 )
								{
									MessageBox.Show("更新服务器会话时发生错误,请联系供应商");
									return;
								}
							}
							else
							{
								MessageBox.Show("服务器最大连接数已满,登陆失败!");
								return;
							}
						}
#endif

						//加载MainForm
						mainForm = new MainForm();

						formShowing = false;
						//fadeTimer.Start();
					

						this.Visible = false;
						mainForm.Owner = this;
						mainForm.WindowState = FormWindowState.Maximized;
						mainForm.Refresh();
						mainForm.Show();
					}
					else
					{
						MessageBox.Show("登陆帐号错误,请检查用户名与密码是否正确!!","系统信息!",
							MessageBoxButtons.OK,MessageBoxIcon.Information);

						textEdit_UserLoginPwd.SelectAll();

						simpleButton_Login.Enabled = true;
					}
				}
				catch(Exception ex)
				{
					MessageBox.Show("登陆时发生异常,请重试!!","系统信息!",
						MessageBoxButtons.OK,MessageBoxIcon.Warning);
					CPTT.SystemFramework.Util.WriteLog(ex.Message,CPTT.SystemFramework.Util.EXCEPTION_LOG_TITLE);

					simpleButton_Login.Enabled = true;
				}
			}
			else
			{
				MessageBox.Show("用户名和密码都必须填写!","系统信息!",
					MessageBoxButtons.OK,MessageBoxIcon.Warning);
				textEdit_UserLoginID.Focus();

				simpleButton_Login.Enabled = true;
			}

		}
Beispiel #3
0
		public int userLogin(User user)
		{
			return new UserRule().userLogin(user);
		}