protected override void OnClosing(CancelEventArgs e) { DialogResult tt = MessageBox.Show("您确定要退出本登陆吗?", "退出...", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (tt != DialogResult.OK) { return; } else { if(user != null) { user = null; } base.OnClosing(e); } }
public static UserClass GetInstance() { if(user1 == null) { lock(SyncRoot) { if(user1 == null) { user1 = new UserClass(); } } } return user1; }
private void pwd_mod_Load(object sender, EventArgs e) { user = UserClass.GetInstance(); tBox_userName.Text = user.UserName; tBox_pre_pwd.Focus(); }
private void button1_Click(object sender, EventArgs e) { #region 11月3号之前 //try //{ // //string s = "Data Source=.;Initial Catalog=db_DMSystem;Integrated Security=True"; // SqlConnection conn = new SqlConnection(services.DBservice.strConn); // //if (login_name.Text == "" || pwd.Text == "") // //{ MessageBox.Show("用户名和密码不能为空!请输入!"); } // if(login_name.Text.Trim() == "") // { // login_name.Focus(); // label2.Text = "请输入帐号"; // } // else if (pwd.Text.Trim() == "") // { // pwd.Focus(); // label2.Text = "请输入密码"; // } // else // { // label2.Text = "信息填写完整。"; // SqlCommand cmd = new SqlCommand("upload", conn); // cmd.CommandType = CommandType.StoredProcedure; // cmd.Parameters.AddWithValue("@userName",login_name.Text.Trim()); // cmd.Parameters.AddWithValue("@pwd",new Encryption.encryption().getHashString(pwd.Text.Trim())); // cmd.Parameters.Add("@power", SqlDbType.VarChar, 10).Direction = ParameterDirection.Output; // cmd.Parameters.Add("@exact", SqlDbType.Bit).Direction = ParameterDirection.Output; // cmd.Parameters.Add("@name", SqlDbType.VarChar, 30).Direction = ParameterDirection.Output; // conn.Open(); // //SqlDataReader dr = cmd.ExecuteReader(); // int status2 = cmd.ExecuteNonQuery(); // if (status2 ==1) // { // //UserClass.GlobAdminName = login_name.Text.Trim(); // UserClass.GlobalPower = cmd.Parameters["@power"].Value.ToString(); // //UserClass. = cmd.Parameters["@name"].Value.ToString(); // UserClass.InitUser(login_name.Text.Trim(),cmd.Parameters["@name"].Value.ToString()); // int status = (bool)cmd.Parameters["@exact"].Value == true ? 1 : 0; // conn.Close(); // if (status == 1) // { // System.Threading.Thread mainForm = new System.Threading.Thread(new System.Threading.ThreadStart(delegate { Application.Run(new MainForm()); })); // //mainForm.SetApartmentState(System.Threading.ApartmentState.STA); // mainForm.TrySetApartmentState(System.Threading.ApartmentState.STA); // mainForm.Name = "mainForm";//设置进程的名字。 // mainForm.Start(); // this.Dispose(); // } // else // { // label2.Text = "重复登录"; // } // } // else // { // label2.Text = "用户不存在或者密码错误!"; // pwd.Text = ""; // } // } //} //catch (SqlException sqle) //{ // label2.Text = "系统网络参数设置失败"; // throw sqle; //} //catch(Exception ex) //{ // label2.Text = "系统异常,请稍后再试!"; // MessageBox.Show(ex.StackTrace.ToString()); // //throw ex; //} #endregion 不要的 if (user == null) user = UserClass.GetInstance(); else { MessageBox.Show(string.Format("用户【{0}】已经登录本机系统,请通知他是否下线操作再使用!",user.UserName)); return; } Dictionary<string, string> dict = new Dictionary<string, string>(); dict.Add("userID",login_name.Text.Trim()); dict.Add("pwd",new encryption().getHashString(pwd.Text.Trim())); user.InitUserData(dict); switch(user.Upload()) { case 0:label2.Text = services.FileService.UploadStatus[0]; break; case 1: { System.Threading.Thread mainForm = new System.Threading.Thread(new System.Threading.ThreadStart(delegate { Application.Run(new MainForm()); })); //mainForm.SetApartmentState(System.Threading.ApartmentState.STA); mainForm.TrySetApartmentState(System.Threading.ApartmentState.STA); mainForm.Name = "mainForm";//设置进程的名字。 mainForm.Start(); this.Dispose(); } break; case 2: { login_name.Text = ""; login_name.Focus(); label2.Text = services.FileService.UploadStatus[2]; } break; case 3: { pwd.Text = ""; pwd.Focus(); label2.Text = services.FileService.UploadStatus[3]; } break; case 4: label2.Text = services.FileService.UploadStatus[4]; break; case 5:label2.Text = services.FileService.UploadStatus[5];break; default: { MessageBox.Show("系统错误,程序即将关闭!"); System.Threading.Thread.Sleep(1000); this.Dispose(); }break; } }
public MainForm() { #region 不要的 //if (user == null || user.UserName == "") //{ // System.Threading.Thread upload = new System.Threading.Thread(new System.Threading.ThreadStart(delegate { Application.Run(new login()); })); // upload.TrySetApartmentState(System.Threading.ApartmentState.STA); // upload.Name = "upload";//设置进程的名字。 // upload.Start(); // this.Dispose(); //} #endregion 不要的 user = UserClass.GetInstance(); InitializeComponent(); }