private void FormMain_Load(object sender, EventArgs e) { FormLogin login = new FormLogin(); if (login.ShowDialog() == DialogResult.OK) { using (IDataReader dr = DataAccess.ExecuteReader( String.Format("select ID,userName from users where userNo='{0}' or UserName='******'", login.UserNo))) { if (dr.Read() == false) { dr.Close(); MessageBox.Show("用户名称或者编号不存在!"); Application.Exit(); } else { AppHelper.UserID = Int32.Parse(dr["id"].ToString()); AppHelper.UserName = (dr["UserName"] == DBNull.Value) ? "" : dr["UserName"].ToString(); dr.Close(); ShowStatus(""); } } } else Application.Exit(); }
private void FormMain_Load(object sender, EventArgs e) { if (!String.IsNullOrEmpty(AppHelper.LocalUserNo)) { AppHelper.UserID = Int32.Parse(AppHelper.LocalUserNo); AppHelper.UserName = "******"; ShowStatus(""); } else { FormLogin login = new FormLogin(); int icount = 0; while (icount < 3) { if (login.ShowDialog() == DialogResult.OK) { if (login.UserNo == "999") { AppHelper.UserID = 999; AppHelper.UserName = "******"; ShowStatus("管理员登录"); break; } else { using (IDataReader dr = DataAccess.ExecuteReader( String.Format("select ID,userName from users where userNo='{0}' or UserName='******'", login.UserNo))) { if (dr.Read() == false) { dr.Close(); MessageBox.Show("用户名称或者编号不存在!"); } else { AppHelper.UserID = Int32.Parse(dr["id"].ToString()); AppHelper.UserName = (dr["UserName"] == DBNull.Value) ? "" : dr["UserName"].ToString(); dr.Close(); ShowStatus(""); break; } } } } else { Application.Exit(); } icount++; } if (icount == 3) { Application.Exit(); } } }
private void FormMain_Load(object sender, EventArgs e) { if (!String.IsNullOrEmpty(AppHelper.LocalUserNo)) { AppHelper.UserID = Int32.Parse(AppHelper.LocalUserNo); AppHelper.UserName = "******"; ShowStatus(""); } else { FormLogin login = new FormLogin(); int icount = 0; while (icount < 3) { if (login.ShowDialog() == DialogResult.OK) { if (login.UserNo == "999") { AppHelper.UserID = 999; AppHelper.UserName = "******"; ShowStatus("管理员登录"); break; } else { using (IDataReader dr = DataAccess.ExecuteReader( String.Format("select ID,userName from users where userNo='{0}' or UserName='******'", login.UserNo))) { if (dr.Read() == false) { dr.Close(); MessageBox.Show("用户名称或者编号不存在!"); } else { AppHelper.UserID = Int32.Parse(dr["id"].ToString()); AppHelper.UserName = (dr["UserName"] == DBNull.Value) ? "" : dr["UserName"].ToString(); dr.Close(); ShowStatus(""); break; } } } } else Application.Exit(); icount++; } if (icount == 3) Application.Exit(); } }
private void FormMain_Closing(object sender, CancelEventArgs e) { e.Cancel = true; FormLogin login = new FormLogin(); if (login.ShowDialog() == DialogResult.OK) { if (login.UserNo == "999") { AppHelper.UserID = 999; AppHelper.UserName = "******"; ShowStatus("管理员登录"); e.Cancel = false; } } }