private void LoginOk() { if (string.IsNullOrEmpty(txtName.Text)) { MessageBox.Show("用户名必填"); return; } WmsCon = PDAFunction.GetWmsConstring(); KisCon = PDAFunction.GetKisConstring(); lUser = txtName.Text; if (!PDAFunction.IsCanCon()) { MessageBox.Show(@"无法连接到SQL服务器,无法验证", @"Warning"); return; } var strTemp = PDAFunction.GetServerTime(); if (strTemp != null) { var dt = DateTime.Parse(strTemp); var sysdt = new SystemTime { wYear = (short)dt.Year, wMonth = (short)dt.Month, wDay = (short)dt.Day, wHour = (short)dt.Hour, wMinute = (short)dt.Minute, wSecond = (short)dt.Second }; Win32API.SetLocalTime(ref sysdt); } var con = new SqlConnection(WmsCon); var cmd = new SqlCommand { Connection = con, CommandText = "select uName,uRole from BUser where (uName=@uName or uCode=@uName) and uPassword=@uPassword" }; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@uName", txtName.Text); cmd.Parameters.AddWithValue("@uPassword", PDAFunction.GetMd5Hash(txtPwd.Text)); con.Open(); var dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (dr.Read()) //直接登陆 { lUser = dr["uName"].ToString(); //把登陆名和登陆服务器保存到静态变量中 dr.Close(); Hide(); using (var fMain = new frmMain()) { fMain.ShowDialog(); } Show(); } else { MessageBox.Show(@"用户名或密码错误,请联系管理员!", @"Warning"); } }