Ejemplo n.º 1
0
 /// <summary>
 /// 密码登录
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void passwordbtn_Click(object sender, EventArgs e)
 {       
     try
     {
         if (txtUserName.Text == "" || txtPassWord.Text == "")
         {
             MessageBox.Show("用户名或密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         else
         {
             //输入用户名
              username = txtUserName.Text.Trim();
             //输入密码
              userpwd = txtPassWord.Text.Trim();
             //定义连接数据库的字符串
             string conStr = "Data Source='101.200.210.193'; Initial Catalog=db_WMS;User ID=sa;Password=1010";
             SqlConnection conn = new SqlConnection(conStr);
             conn.Open();
             //创建数据库命令对象
             SqlCommand command = new SqlCommand("select * from tb_user where UserName='******' and UserPwd='" + userpwd + "'",conn);
             //创建数据库读取器对象
             SqlDataReader reader = command.ExecuteReader();
             //读取一条记录
             reader.Read();
             if (reader.HasRows)//判断是否包含数据
             {
                 string time = DateTime.Now.ToString();
                 string sql = "update tb_user set LoginTime='" + time + "' where UserName='******'";
                 Sqloperate sqloperate = new Sqloperate();
                 sqloperate.SqlCommands(sql);
                 conn.Close();
                 this.Hide();
                 UserCenter userCenter = new UserCenter();
                 UserCenter.userCenter.Show();
             }
             else
             {
                 txtUserName.Text = "";
                 txtPassWord.Text = "";
                 MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 2
0
 public UserCenter()
 {
     userCenter = this;
     InitializeComponent();
 }