/// <summary> /// 登录到系统 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { string username = textBox1.Text; //用户名 string psw = textBox2.Text; //密码 if (username == "" | psw == "") { MessageBox.Show("用户名或密码不能为空!"); return; } string sql = "select * from lz_admin where username='******' and psw='" + psw + "' and type=3"; DataTable dt = GetConnection.GetDataTable(sql); if (dt.Rows.Count > 0) { double logindate = ConvertDateTimeInt(DateTime.Now); //登录时间 string ip = GetIpv4(); //注册时的IP int login_count = Int32.Parse(dt.Rows[0]["login_count"].ToString()) + 1; //登录次数+1 string sqlist = "update lz_admin set logindate = '" + logindate + "' ,login_count='" + login_count + "',ip='" + ip + "' where username = '******'"; GetConnection.NoSelect(sqlist); //更新信息 FileStream aFile = new FileStream("user.bin", FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(aFile); sw.WriteLine(textBox1.Text); sw.WriteLine(textBox2.Text); sw.Close(); aFile.Close(); this.Close(); this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBox.Show("登录失败!忘记密码,请联系QQ:1070387250"); } }