📄 loginapp.cs
字号:
Public.currentUserName = DBConn.GetUserRealName(Public.currentUserID);
//记录到本地配置文件
Public.configXml.Rows[0]["LastUserID"] = this.user.Text.Trim();
Public.configXml.Rows[0]["LastUserPwd"] = Public.Encode("ESST_PWD",this.pwd.Text);
Public.configXml.Rows[0]["LastUserIP"] = this.IP.Text.Trim();
if(this.autoLogin.Checked ) Public.configXml.Rows[0]["AutoLogin"] = "1";
else Public.configXml.Rows[0]["AutoLogin"] = "0";
//保存到XML
SRXML.SaveDataTableToXML(Public.configXml,Public.configFile);
try{
//取出提醒时间段
DataTable alertTimes = DBConn.GetAlertTime();
string today = DBConn.GetServerTime().Date.ToString().Replace("0:00:00","");
//MessageBox.Show(today + alertTimes.Rows[0]["StartTime"].ToString());
Public.startTime = Convert.ToDateTime(today + alertTimes.Rows[0]["StartTime"].ToString());
Public.endTime = Convert.ToDateTime(today + alertTimes.Rows[0]["EndTime"].ToString());
if(alertTimes.Rows[0]["isMod"].ToString() == "1"){
Public.alertingIsMod = true;
}else{
Public.alertingIsMod = false;
}
}catch(Exception ex){
MessageBox.Show(ex.Message.ToString());
return;
}
this.Visible = false;
this.notifyIcon1.Visible = false;
Public.currentRCS = "CLIENT";
//
//Public.loginWin = null;
if(this.mainForm == null){
this.mainForm = new Form1();
this.mainForm.Show();
}
//System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(this.ShowMainForm));
//thread.IsBackground = true;
//thread.Start();
//
//XFMAS.Admin.MainForm mf = new XFMAS.Admin.MainForm();
//mf.Show();
}else{
MessageBox.Show("用户名或密码不正确,不能登录服务器!");
return;
}
}
/// <summary>
/// 显示主窗口
/// </summary>
private void ShowMainForm(){
if(this.mainForm == null){
this.mainForm = new Form1();
this.mainForm.Show();
}
}
private void button2_Click(object sender, System.EventArgs e) {
linkLabel1_LinkClicked(null,null);
}
#region 读取xml文件里的配置
/// <summary>
/// 读取磁盘中事先设置好的配置参数
/// 主要是数据库和自动登录的配置
/// </summary>
public void ReadConfigXml(){
bool isSetWin = false;
//检查System.Config 是否存在
if(!File.Exists(Public.configFile)){
isSetWin = true;
}else{
Public.configXml = SRXML.ConfigTable();
}
if(!isSetWin){
//读取配置
try{
Public.configXml = SRXML.ReadDataTaBleFromXML(Public.configFile);
}catch(Exception ex){
isSetWin = true;
}
this.Text = "登录[检测服务器连接....]";
//验证连接串
if(!isSetWin){
try{
//检测数据库的连接是否正确
try{
Public.Conn(Public.configXml.Rows[0]["SqlServer"].ToString(),Public.configXml.Rows[0]["SqlUser"].ToString(),Public.DeCode("ESST_PWD",Public.configXml.Rows[0]["SqlPwd"].ToString()));
}catch(Exception ex){
this.ChangeNotIcon(false);
string msg = "服务器连接出错,点击“是”重新设置服务器参数,点击“否”关闭程序!\r\n\r\n系统异常信息:" + ex.Message.ToString();
if(MessageBox.Show(msg,"启动失败",MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes){
SetWin sw = new SetWin();
sw.ShowDialog();
this.ReadConfigXml();
}else{
Application.Exit();
}
return;
}
this.Text = "登录[应用配置....]";
this.isLoadConfig = true;
}catch(Exception ex){
isSetWin = true;
}
}
}
if(isSetWin){
if(MessageBox.Show("本地配置文件不存在或已失效,请重新配置服务器连接的参数!") == DialogResult.OK){
SetWin sw = new SetWin();
sw.ShowDialog();
this.ReadConfigXml();
}
}
}
/// <summary>
/// 根据IP取出绑定的用户名
/// </summary>
private void LoadUserName(){
if(this.IP.Text.Trim() != ""){
this.user.Items.Clear();
//检查IP是否符合要求
string ipStr = this.IP.Text.Trim();
string[] xx = ipStr.Split('.');
for(int i=0;i<xx.Length;i++){
string xxx = xx[i].ToString();
try{
if(xxx.Length > 3) throw new Exception("IP输入不符合要求");
int __xx = Int32.Parse(xxx);
}catch{
MessageBox.Show("IP地址输入不正确!");
return;
}
}
DataTable users = DBConn.UsersForIP(this.IP.Text.Trim());
if(users != null){
foreach(DataRow row in users.Rows){
this.user.Items.Add(row["userName"].ToString());
}
}
}
}
#endregion
/// <summary>
/// 载入配置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
//this.Text = "登录[检查升级....]";
this.timer1.Stop();
//this.ReadConfigXml();
//System.Threading.Thread u = new System.Threading.Thread(new System.Threading.ThreadStart(this.CheckUpdate));
//u.IsBackground = true;
//u.Start();
//System.Threading.Thread.Sleep(1000);
this.Text = "登录[载入配置....]";
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(this.ReadConfigXml));
thread.IsBackground = true;
thread.Start();
}
/// <summary>
/// 变更了IP后
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void IP_TextChanged(object sender, System.EventArgs e) {
this.LoadUserName();
}
private void IP_Leave(object sender, System.EventArgs e) {
this.IP_TextChanged(sender,e);
}
/// <summary>
/// 不能关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void notifyIcon1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
if(e.Clicks == 2) this.Visible = true;
}
private void LoginApp_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
e.Cancel = !this.isExitApp;
this.Visible = false;
}
private void menuItem1_Click(object sender, System.EventArgs e) {
AboutUs au = new AboutUs();
au.ShowDialog();
}
/// <summary>
/// 是否新版本
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CheckUpdate(){
String temp = "";
try{
WebRequest Wrequest = WebRequest.Create("http://10.227.64.92/AMS/ClientUpdate.htm");
WebResponse Wresponse = Wrequest.GetResponse();
Stream Sm = Wresponse.GetResponseStream();
StreamReader Sr = new StreamReader(Sm,Encoding.GetEncoding("GB2312"));
temp = Sr.ReadToEnd().ToString();
Sr.Close();
}catch(Exception ex){
MessageBox.Show("升级检查失败:" + ex.Message.ToString());
return;
}
int oneI = temp.IndexOf("]");
string softVer = temp.Substring(1,oneI-1).ToString();
try{
//if(Public.configXml.Rows[0]["SoftVer"].ToString() != softVer && MessageBox.Show("系统检查到有升级文件可供更新,确定升级吗?","升级确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK){
if(Public.configXml.Rows[0]["SoftVer"].ToString() != softVer){
Public.configXml.Rows[0]["SoftVer"] = softVer;
//保存到XML
SRXML.SaveDataTableToXML(Public.configXml,Public.configFile);
System.Diagnostics.Process p = new Process();
p.StartInfo.FileName = Application.StartupPath + "\\UpdateEr.exe";
p.Start();
this.notifyIcon1.Icon = null;
Application.Exit();
}
}catch(Exception ex){
MessageBox.Show("开始升级时出错:" + ex.Message.ToString());
}
}
/// <summary>
/// 改变托盘图标
/// </summary>
/// <param name="conn"></param>
public void ChangeNotIcon(bool conn){
try{
Icon icon = null;
if(conn){
icon = new Icon(this.iconFile + "conn.ico");
}else{
icon = new Icon(this.iconFile + "noconn.ico");
}
if(icon != null){
this.notifyIcon1.Icon = icon;
this.Icon = icon;
}
}catch{}
}
/// <summary>
/// 检测是否进行自动处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
if(this.isLoadConfig){
this.timer2.Stop();
this.IsAvaliable();
}
}
/// <summary>
/// 使程序可使用
/// </summary>
private void IsAvaliable(){
//记住上次输入的登录信息
if(Public.configXml.Rows[0]["LastUserIP"].ToString() != "") this.IP.Text = Public.configXml.Rows[0]["LastUserIP"].ToString();
this.user.Text = Public.configXml.Rows[0]["LastUserID"].ToString();
//从服务器端获取系统相关配置参数,如授权文件、用户表连接串等
try{
DataSet ds = DBConn.GetSystemInfo();
DataRow row = ds.Tables[0].Rows[0];
//用户表数据库的配置
Public.usersDbInfo = row["UsersSqlServer"].ToString();
//验证用户数据库登录信息
string usersDBconn = DBConn.CheckUsersDBConn();
//如果有异常则抛出
if(usersDBconn != "OK"){
throw new Exception(usersDBconn);
}
//系统名称
Public.systemName = row["systemName"].ToString();
this.notifyIcon1.Text = this.Text;
}catch(Exception ex){
MessageBox.Show("从服务器端读取系统配置时出错:" + ex.Message.ToString());
return;
}
//应用配置到界面
if(Public.configXml.Rows[0]["autoLogin"].ToString() == "1"){
this.autoLogin.Checked = true;
this.pwd.Text = Public.DeCode("ESST_PWD",Public.configXml.Rows[0]["LastUserPwd"].ToString());
//自动登录
b222_Click(null,null);
}
//根据IP取出绑定的用户名
this.LoadUserName();
this.Text = "登录["+ Public.systemName +"]";
this.b222.Enabled = true;
this.user.Enabled = true;
this.pwd.Enabled = true;
this.button1.Enabled = true;
this.button2.Enabled = true;
this.autoLogin.Enabled = true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -