private void buttonOK_Click(object sender, EventArgs e) { string name = this.comboBoxName.Text.Trim(); string pwd = this.textBoxPwd.Text; if ((name == "") || (pwd == "")) { MessageBox.Show("请输入用户名和密码", "提示"); return; } try { OperatorDBClass operatordb = new OperatorDBClass(); if (operatordb.FindUserPwd(name) == pwd) { FormMain formain = new FormMain(); formain.usename = name; //传递登录名和时间给主窗口 formain.userlogintime = DateTime.Now.ToString(); this.Hide(); formain.Show(); } else { MessageBox.Show("密码错误,请重新输入!", "错误"); return; } } catch (Exception ex) { MessageBox.Show("登录系统时发生了 " + ex.Message + "错误!"); } finally { } }