📄 flogon.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Qeb.Control;
using Qeb.Support;
using Qeb.Support.Common;
using Qeb.DBProxy;
namespace Qeb.GY
{
public partial class FLogon : FBase
{
private DataTable m_dtUser = null;
private string m_UserFile = Application.StartupPath + "\\User.bin";
public FLogon()
{
InitializeComponent();
}
#region 记录用户名
private void RememberUser()
{
int index = this.cmbUserGH.SelectedIndex;
if (index > -1)
{
if (this.chbMark.Checked)
m_dtUser.DefaultView[index]["flag"] = "1";
else
{
m_dtUser.DefaultView.Delete(index);
}
m_dtUser.WriteXml(m_UserFile);
}
}
#endregion
#region 登陆
private bool Logon()
{
User user = new User();
string outMsg = "";
try
{
string appId = this.cmbAppId.SelectedItem == null ? "" : this.cmbAppId.SelectedValue.ToString();
if (appId == null || appId.Length !=4)
{
MessageBox.Show("请选择要登陆的应用程序!",MsgTitle.Prompt);
this.cmbAppId.Focus();
return false;
}
string gh = this.cmbUserGH.SelectedItem ==null?"":this.cmbUserGH.SelectedValue.ToString();
if (gh == "")
{
MessageBox.Show("请输入您的工号!", MsgTitle.Prompt);
this.cmbUserGH.Focus();
return false;
}
if (this.txtPassword.Text == "")
{
MessageBox.Show("请输入密码,系统不允许空密码!", MsgTitle.Prompt);
this.txtPassword.Focus();
return false;
}
bool isLogon = user.Logon(gh, this.txtPassword.Text, appId, out outMsg);
if (!isLogon)
{
MessageBox.Show(outMsg,MsgTitle.Prompt);
return false;
}
else
{
//设置应用名称
App.yyMc = this.cmbAppId.Text;
//SetConfig 最后一次选择的应用
//记录用户名
this.RememberUser();
return true;
}
}
catch (System.Exception ex)
{
MessageBox.Show("登陆发生异常,请与信息中心联系\n"+ex.Message, MsgTitle.Error);
return false;
}
}
private void btnLogon_Click(object sender, EventArgs e)
{
if (Logon())
{
this.DialogResult = DialogResult.OK;
this.Close();
}
}
#endregion
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.No;
this.Close();
}
#region 绑定本机可用的应用列表
private void BindAppList()
{
QDataStore dsClientApp = null;
DbProxyClient proxy = App.DbProxy;
try
{
dsClientApp = new QDataStore();
dsClientApp.LibraryList = PBL.GyPbl;
dsClientApp.DataWindowObject = GyDataObjects.D_Gy_GzzYyLb;
proxy.Clear();
proxy.AddRetrieveParam("p_wkdz", ComputerInfo.MAC);
proxy.Retrieve(dsClientApp);
this.cmbAppId.Items.Clear();
dsClientApp.SetSort("yyid");
dsClientApp.Sort();
DataTable dtAppList = dsClientApp.CovertToDataTable();
this.cmbAppId.DataSource = dtAppList;
this.cmbAppId.DisplayMember = "yymc";
this.cmbAppId.ValueMember = "yyid";
}
catch(Exception ex)
{
MessageBox.Show("取本机可用的应用程序列表发生异常:" + ex.Message, MsgTitle.Error);
}
finally
{
if (dsClientApp != null)
dsClientApp.Dispose();
}
}
#endregion
#region 绑定登陆过的用户名
private void BindUserInfo()
{
//取用户登陆记录
m_dtUser = new DataTable("User");
m_dtUser.CaseSensitive = false;
m_dtUser.Columns.Add("Gh", typeof(string)); //用户工号
m_dtUser.Columns.Add("YhMc", typeof(string)); //用户名称
m_dtUser.Columns.Add("flag", typeof(string)); //记录标志
if (File.Exists(m_UserFile))
{
try
{
m_dtUser.ReadXml(m_UserFile);
}
catch
{
File.Delete(m_UserFile);
}
}
m_dtUser.DefaultView.Sort = "Gh";
this.cmbUserGH.DataSource = m_dtUser.DefaultView;
this.cmbUserGH.DisplayMember = "YhMc";
this.cmbUserGH.ValueMember = "Gh";
this.cmbUserGH.SelectedIndex = -1;
}
#endregion
#region SetUI
private void SetUI()
{
string info = "网卡地址:" + ComputerInfo.MAC + " IP:" + ComputerInfo.IP;
lableMac.Text = info;
//取工作站可用应用列表
this.BindAppList();
if (this.cmbAppId.Items.Count == 0)
this.btnLogon.Enabled = false;
else
this.btnLogon.Enabled = true;
this.BindUserInfo();
}
#endregion
private void FLogon_Load(object sender, EventArgs e)
{
SetUI();
Win32Api.AnimateWindow(this.Handle, 500, Win32Api.AW_BLEND);
this.qPanel1.Refresh();
}
private void FLogon_FormClosed(object sender, FormClosedEventArgs e)
{
if (m_dtUser != null)
m_dtUser.Dispose();
Win32Api.AnimateWindow(this.Handle, 200, Win32Api.AW_CENTER | Win32Api.AW_HIDE);
}
private void lableMac_DoubleClick(object sender, EventArgs e)
{
Clipboard.SetText(ComputerInfo.MAC);
MessageBox.Show("网卡地址已拷贝取剪贴板!", MsgTitle.Prompt);
}
private void cmbUserGh_Leave(object sender, EventArgs e)
{
if (this.cmbUserGH.SelectedItem == null && this.cmbUserGH.Text != "")
{
try
{
string userName = new User().GetUserName(this.cmbUserGH.Text);
if (string.IsNullOrEmpty(userName))
{
MessageBox.Show("您输入的工号不存在,请重新输入!",MsgTitle.Warning);
this.cmbUserGH.Text = "";
this.cmbUserGH.Focus();
return;
}
else
{
int index = m_dtUser.DefaultView.Find(this.cmbUserGH.Text);
if (index > -1)
{
this.cmbUserGH.SelectedIndex = index;
}
else
{
this.m_dtUser.Rows.Add(this.cmbUserGH.Text, userName);
this.cmbUserGH.SelectedIndex = this.cmbUserGH.Items.Count-1;
}
}
}
catch(Exception ex)
{
this.cmbUserGH.Text = "";
MessageBox.Show("设置用户名发生异常,请重试或者与信息中心联系!\n"+ex.Message,MsgTitle.Error);
}
}
}
private void cmbUserGh_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter && ((ComboBox)sender).Text.Trim() != "")
{
this.txtPassword.Focus();
}
}
private void cmbAppId_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
SendKeys.Send("{Tab}");
}
private void txtPassword_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
//SendKeys.Send("{Tab}");
if (txtPassword.Text != "")
{
if (cmbUserGH.Text == "")
cmbUserGH.Focus();
else
btnLogon_Click(txtPassword, null);
}
}
}
private void cmbUserGh_SelectedIndexChanged(object sender, EventArgs e)
{
int index = ((ComboBox)sender).SelectedIndex;
bool check = false;
if (index > -1)
{
string flag = ((DataView)((ComboBox)sender).DataSource)[index]["flag"].ToString();
if (flag == "1")
{
check = true;
}
}
this.chbMark.Checked = check;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -