コード例 #1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            var sqlstr = "UpdatePwd";
            var con    = new SqlConnection(WmsLogin.WmsConstring);
            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;
            }
        }
コード例 #2
0
ファイル: WmsLogin.cs プロジェクト: UpjdTeam/LPaper
        private void OK_Login()
        {
            if (string.IsNullOrEmpty(WmsConstring))
            {
                MessageBox.Show(@"服务器填写错误,或者服务器端未配置正确!", @"注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }


            lblLogin.Image = Properties.Resources.LoginForm_login_btn_click;

            if (string.IsNullOrEmpty(utxtUser.Text.Trim()) || string.IsNullOrEmpty(utxtPassword.Text))
            {
                MessageBox.Show(@"用户名和密码必填!", @"注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            //记住账套信息
            if (utxtAccount.Value == null || WmsConstring == null)
            {
                MessageBox.Show(@"账套、服务器选择有误!", @"注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var con = new SqlConnection(WmsConstring);
            var cmd = new SqlCommand
            {
                Connection  = con,
                CommandText =
                    "select uName,uRole,uCode from BUser where (uName=@uName or uCode=@uName) and uPassword=@uPassword"
            };

            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@uName", utxtUser.Text);
            cmd.Parameters.AddWithValue("@uPassword", WmsFunction.GetMd5Hash(utxtPassword.Text));
            con.Open();
            var dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            if (dr.Read()) //直接登陆
            {
                Account = utxtAccount.Text;
                Server  = utxtServer.Text;
                Properties.Settings.Default.cUser    = utxtUser.Text;
                Properties.Settings.Default.cServer  = Server;
                Properties.Settings.Default.cAccount = Account;
                Properties.Settings.Default.Save();

                Lname = dr["uName"].ToString(); //把登陆名和登陆服务器保存到静态变量中
                Ltime = udDate.DateTime;
                Lrole = dr["uRole"].ToString();
                LCode = dr["uCode"].ToString();
                dr.Close();
                Hide();
                var bmsloading = new WmsLoading();
                bmsloading.ShowDialog();
            }
            else
            {
                MessageBox.Show(@"用户名或密码错误,请联系管理员!", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }