Esempio n. 1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            var sqlstr = "UpdatePwd";
            var con    = new SqlConnection(BaseStructure.WmsCon);
            var cmd    = new SqlCommand(sqlstr, con)
            {
                CommandType = CommandType.StoredProcedure
            };

            cmd.Parameters.AddWithValue("@uName", utxtUser.Text);
            cmd.Parameters.AddWithValue("@uPassword", WmsFunction.GetMd5Hash(utxtPassword.Text));
            cmd.Parameters.AddWithValue("@uPwd", WmsFunction.GetMd5Hash(utxtPwd.Text));
            try
            {
                con.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(@"发生异常" + ex.Message, @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cmd.ExecuteNonQuery() < 1)
            {
                MessageBox.Show(@"修改失败", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                MessageBox.Show(@"修改成功", @"Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                DialogResult = DialogResult.OK;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 判断是否登录成功
 /// </summary>
 /// <returns></returns>
 public static bool OkLogin(string uName, string uPassword)
 {
     using (var con = new SqlConnection(BaseStructure.WmsCon))
     {
         using (var cmd = new SqlCommand {
             Connection = con
         })
         {
             cmd.CommandText = "select * from View_BUserRole where (cCode=@cCode or cName=@cCode) and cPwd=@cPwd";
             cmd.Parameters.AddWithValue("@cCode", uName);
             cmd.Parameters.AddWithValue("@cPwd", WmsFunction.GetMd5Hash(uPassword));
             con.Open();
             using (var dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
             {
                 if (dr.Read())                                            //直接登陆
                 {
                     BaseStructure.LoginId       = dr["cCode"].ToString(); //把登陆名和登陆服务器保存到静态变量中
                     BaseStructure.LoginName     = dr["cName"].ToString();
                     BaseStructure.LoginRoleId   = dr["rCode"].ToString();
                     BaseStructure.LoginRoleName = dr["rName"].ToString();
                     return(true);
                 }
                 MessageBox.Show(@"用户名或密码错误,请联系管理员!", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 return(false);
             }
         }
     }
 }