Esempio n. 1
0
		private void RefreshDataTimerCallback(object state)
		{
			refreshDataTimer.Change(Timeout.Infinite, Timeout.Infinite);
			try
			{
				var conn = DbFactory.GetConnection();
				var dal = new Dal(conn);
				var productionData = dal.GetProductionData(lastUpdateTime);
				if (productionData == null)
					return;

				// Need to refresh two charts the first time
				var alwaysRefresh = (!lastUpdateTime.HasValue);

				lastUpdateTime = productionData.LastUpdate;

				RefreshData(productionData);

				var reporter = new Reporter(conn);
				var ds = reporter.GetCurrentMonthData();
				RefreshCharts(ds, alwaysRefresh);
			}
			finally
			{
				refreshDataTimer.Change(2000, Timeout.Infinite);
			}
		}
Esempio n. 2
0
		private void DoLogin()
		{
			if (loginMode == LoginMode.IdCard)
			{
				DialogResult = DialogResult.OK;
				return;
			}

			var loginId = textBoxUserId.Text.Trim();
			var pwd = textBoxPwd.Text;

			// TODO: encrypt the inputted pwd and compare with the one in db
			try
			{
				using (var db = DbFactory.GetConnection())
				{
					var dal = new Dal(db);
					var user = dal.GetUser(loginId);
					if (user == null)
					{
						MessageBox.Show(string.Format("用户[{0}]不存在。", loginId));
						return;
					}
					
					if (user.Status != "A")
					{
						MessageBox.Show("用户[{0}]状态异常,不允许登录。", loginId);
						return;
					}

					// todo encrypt inputted pwd
					var encryptedPwd = pwd;
					if (encryptedPwd != user.Password)
					{
						MessageBox.Show("用户名或密码错误,请重新输入。");
						textBoxPwd.Select();
						return;
					}

					// Validate passed
					CurrentUser = user;
					DialogResult = DialogResult.OK;

					OpenNextForm();

					Close();
				}
			}
			catch (Exception ex)
			{
				Logger.Error(ex, "Failed to get user info.");
				MessageBox.Show("登录时遇到错误,请重试.");
			}
		}
Esempio n. 3
0
		private void ShowIdCardContent(string idCard)
		{			
			if (string.IsNullOrWhiteSpace(idCard))
				return;

			try
			{
				using (var db = DbFactory.GetConnection())
				{
					var dal = new Dal(db);
					var user = dal.GetUserByIdCard(idCard);

					// Data validated
					var statusValid = string.Equals(user.Status, "A", StringComparison.OrdinalIgnoreCase);
					labelFlashCard.Hide();
					while (listViewUserInfo.Items.Count > 0) { listViewUserInfo.Items.RemoveAt(0); }
					listViewUserInfo.Show();
					listViewUserInfo.Items.AddRange(new ListViewItem[] {
						new ListViewItem(new string[] { "登录ID", user.LoginId }),
						new ListViewItem(new string[] { "姓名", user.Name }),
						new ListViewItem(new string[] { "状态", statusValid ? "正常" : "异常" })
					});

					buttonLogin.Enabled = statusValid;

					if (statusValid)
					{
						CurrentUser = user;
					}
				}
			}
			catch (Exception ex)
			{
				Logger.Error(ex, "Failed to get user by ID card.");
				MessageBox.Show("无法获取ID Card信息.");
				return;
			}

		}