//写入数据库 private void writeToDB() { string user_name = textBox1.Text.Trim(); string user_pass = textBox2.Text.Trim(); ToMD5 md5 = new ToMD5();//将密码加密为md5 user_pass = md5.Encrypt(user_pass); string user_realname = textBox4.Text.Trim(); string user_bankAccount = bankAccount.Text.Trim(); string user_id = textBox5.Text.Trim(); string user_phone = textBox9.Text.Trim(); string user_qq = textBox10.Text.Trim(); string user_province = ""; string province = textBox7.Text.Trim(); string city = textBox6.Text.Trim(); if (province.Contains("省")) { province = province.Substring(0, province.IndexOf("省")); } if (city.Contains("市")) { city = city.Substring(0, city.IndexOf("市")); } user_province = province + "省" + city + "市"; if (textBox7.Text.Trim().Equals("") && textBox6.Text.Trim() != "") { user_province = textBox6.Text.Trim() + "市"; } if (user_province.Equals("省市")) { user_province = "暂无"; } if (user_province.IndexOf("市") - user_province.IndexOf("省") == 1) { user_province = user_province.Substring(0, user_province.IndexOf("省") + 1); } string machinecode = textBox8.Text.Trim(); string registtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); try { DataTable dtMCode = LinkMySql.MySqlQuery("select * from " + Global.sqlUserTable + " where user_name='" + user_name + "'"); if (dtMCode.Rows.Count == 0) { LinkMySql.MySqlExcute("insert into " + Global.sqlUserTable + "(user_name,user_pass,user_realname,user_bankAccount,user_id,user_phone,user_qq,user_province,machinecode,registtime,registplace) values('" + user_name + "','" + user_pass + "','" + user_realname + "','" + user_bankAccount + "','" + user_id + "','" + user_phone + "','" + user_qq + "','" + user_province + "','" + machinecode + "','" + registtime + "','" + getIP.GetWebCity() + "')"); MessageBox.Show("申请成功,请联系管理等待开通。", "恭喜"); this.Close(); } else { MessageBox.Show("用户名已存在,请换一个用户名再试!", "温馨提示"); } } catch { MessageBox.Show("申请失败,请稍后重试!", "温馨提示"); } }
//第一页前面主条件选择框 private void provinceCbx_SelectedIndexChanged(object sender, EventArgs e) { if (provinceCbx.Text.Equals("显示全部")) { onlineCbx.Visible = false; dgvGetInfo(); } if (provinceCbx.Text.Equals("省区")) { onlineCbx.Visible = true; onlineCbx.DataSource = null; DataTable tb = LinkMySql.MySqlQuery("select user_province from " + Global.sqlUserTable + " group by user_province"); onlineCbx.DataSource = tb; onlineCbx.DisplayMember = "user_province"; } if (provinceCbx.Text.Equals("在线状态")) { onlineCbx.Visible = true; onlineCbx.DataSource = null; string[] stu = { "在线", "离线" }; onlineCbx.Items.Clear(); onlineCbx.Items.AddRange(stu); } if (provinceCbx.Text.Equals("区域代理")) { onlineCbx.Visible = true; onlineCbx.DataSource = null; DataTable tb = LinkMySql.MySqlQuery("select user_name from " + Global.sqlUserTable + " where user_vali='5' and isdel='1'"); onlineCbx.DataSource = tb; onlineCbx.DisplayMember = "user_name"; } this.searchInput.Text = ""; }
private Boolean userPassVali() { bool tf = false; DataTable dt1 = LinkMySql.MySqlQuery("select * from " + Global.sqlUserTable + " where user_name='" + Global.user_name + "'"); DataRow dr1 = dt1.Rows[0]; string oldPass = textBox2.Text; string newPass = textBox3.Text; ToMD5 md5 = new ToMD5(); oldPass = md5.Encrypt(oldPass); newPass = md5.Encrypt(newPass); if (oldPass.Equals(dr1["user_pass"].ToString())) { label5.Text = ""; if (label5.Text.Equals("") && label6.Text.Equals("") && label7.Text.Equals("")) { LinkMySql.MySqlExcute("update " + Global.sqlUserTable + " set user_pass='******' where user_name='" + Global.user_name + "'"); tf = true; } } else { label5.ForeColor = Color.Red; label5.Text = "原密码输入有误,请检查!"; } return(tf); }
private void machineLoginStart() { try { //用来终止登录线程 setLoginResult("正在登录中...请稍后"); disabledControls(); clearControls(); string d = mc.GetCpuID(); string g = mc.GetMacAddress(); string machinecode = d + g; for (int i = 4; i < machinecode.Length; i += 5) { machinecode = machinecode.Insert(i, "-"); } DataTable dt1 = LinkMySql.MySqlQuery("select * from " + Global.sqlUserTable + " where machinecode='" + machinecode + "' and registtime=(select min(registtime) from " + Global.sqlUserTable + " where machinecode='" + machinecode + "') and isdel='1'"); if (dt1 != null && dt1.Rows.Count > 0) { DataRow dr1 = dt1.Rows[0]; Global.user_name = dr1["user_name"].ToString(); Global.user_realname = dr1["user_realname"].ToString(); Global.user_province = dr1["user_province"].ToString(); Global.user_vali = dr1["user_vali"].ToString(); Global.allowlogin = dr1["allowlogin"].ToString(); Global.loginType = "2"; if (dr1["allowlogin"].ToString().Equals("1")) { string mysql = "UPDATE " + Global.sqlUserTable + " SET `online`='2',lastloginip='" + getIP.GetWebIP() + "',lastlogintime=now(),lastloginplace='" + getIP.GetWebCity() + "',soft_version='" + Global.version + "',onlinetime=now() " + " where user_name='" + Global.user_name + "'"; int res = LinkMySql.MySqlExcute(mysql); if (res == 0) { setLoginResult("登录失败,请稍后重试!"); return; } //clearUserProfile();//清空用户配置文档 loginToMain(); } else { setLoginResult("您没有使用权限!"); } } else { setLoginResult("请您进行申请,并由管理员为您开通以后再进行此项操作。"); } enabledControls(); } catch (Exception err) { MessageBox.Show(err.Message, "友情提示"); throw err; } }
//点击“登录”按钮以后的文本框输入验证操作 private Boolean loginValidate(string user_name, string user_pass) { ToMD5 md5 = new ToMD5(); if (string.IsNullOrEmpty(user_name)) { setLabel3Text("请输入用户名!"); setLoginResult("请输入用户名!"); return(false); } if (string.IsNullOrEmpty(user_pass)) { setLabel4Text("请输入密码!"); setLoginResult("请输入密码!"); return(false); } user_pass = md5.Encrypt(user_pass); DataTable dt1 = LinkMySql.MySqlQuery("select * from " + Global.sqlUserTable + " where user_name='" + user_name + "' and isdel='1'"); if (dt1 == null || dt1.Rows.Count == 0)//如果没有返回来数据,证明用户名错了 { setLabel3Text("用户名错误或者该用户未找到,请检查!"); setLoginResult("用户名错误或者该用户未找到,请检查!"); return(false); } setLabel3Text(""); DataRow dr1 = dt1.Rows[0]; if (!dr1["user_pass"].Equals(user_pass)) { setLabel4Text("密码不正确,请检查!"); setLoginResult("密码不正确,请检查!"); return(false); } setLabel4Text(""); if (dr1["allowlogin"].Equals("0")) { setLabel3Text("您没有使用权限!"); setLoginResult("您没有使用权限!"); return(false); } if (dr1["online"].Equals("1") || dr1["online"].Equals("2")) { setLabel3Text("该账号已在别处登录!"); setLoginResult("该账号已在别处登录!"); return(false); } Global.user_name = dr1["user_name"].ToString(); Global.user_realname = dr1["user_realname"].ToString(); Global.user_province = dr1["user_province"].ToString(); Global.user_vali = dr1["user_vali"].ToString(); Global.allowlogin = dr1["allowlogin"].ToString(); Global.loginType = "1"; return(true); }
//启动全员下线机制 private void setUsersOffline_Tick(object sender, EventArgs e) { try { DataTable tb = LinkMySql.MySqlQuery("select user_name,`onlinetime`,user_realname from " + Global.sqlUserTable + " where `online`!='0' and isdel!='-1' and allowlogin!='0' and user_name!='" + Global.user_name + "'"); if (tb != null && tb.Rows.Count > 0) { foreach (DataRow dr in tb.Rows) { string user_name = dr["user_name"].ToString(); string user_realname = dr["user_realname"].ToString(); string onlinetime = dr["onlinetime"].ToString(); if (string.IsNullOrEmpty(onlinetime)) { continue; } TimeSpan ts1 = new TimeSpan(Convert.ToDateTime(onlinetime).Ticks); //服务器最后更新时间 TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks); //现在时间 TimeSpan ts = ts1.Subtract(ts2).Duration(); //绝对值 int diffHours = Convert.ToInt32(ts.TotalMinutes); //如果相差时间超过10分钟,那么就把该用户下线 if (diffHours > 10) { //MessageBox.Show(diffHours + ":::" + user_realname + ""); LinkMySql.MySqlExcute("update " + Global.sqlUserTable + " set `online`='0' where user_name='" + user_name + "' "); } } } } catch { } }
/// <summary> /// 绑定区域代理的combobox数据 /// </summary> private void bindQuYuCbx() { qyCbx.DataSource = null; DataTable tb = LinkMySql.MySqlQuery("select user_name,user_realname from " + Global.sqlUserTable + " where user_vali='5' and isdel='1'"); qyCbx.DataSource = tb; qyCbx.DisplayMember = "user_realname"; qyCbx.ValueMember = "user_name"; }
private void getGg() { DataTable dt = LinkMySql.MySqlQuery("select * from msg"); if (dt != null && dt.Rows.Count > 0) { DataRow dr = dt.Rows[0]; SetMsgText8Box(dr["msg_login"].ToString()); SetMsgText11Box(dr["msg_main"].ToString()); } if (string.IsNullOrEmpty(textBox8.Text) == false && string.IsNullOrEmpty(textBox11.Text) == false) { msgT.Abort(); } }
/// <summary> /// 刷新datagridview时执行的sql /// 参数where是查询条件 /// </summary> private void dgvGetInfoSqlExecute(string where) { //设定给datagridview的select列名 string displaySqlSelect = "user_name as '用户名',user_realname as '姓名',user_phone as '手机/电话',user_qq as 'QQ/MSN'," + "CASE allowlogin when '1' then'是' ELSE'否' end AS '允许登录',case online when '1' then '在线' when '2' then '在线' else '离线' end as '当前是否在线'," + "soft_version as '软件版本' "; DataTable tb = LinkMySql.MySqlQuery("select " + displaySqlSelect + " from " + Global.sqlUserTable + " " + where + ""); dataGridView1.DataSource = tb; dataGridView1.DataMember = tb.TableName; DataTable cu = LinkMySql.MySqlQuery("select count(user_id) as 总计 from " + Global.sqlUserTable + " " + where + ""); DataRow dr = cu.Rows[0]; this.sumUserLabel.Text = "共有 " + dr[0].ToString() + " 位用户"; }
/// <summary> /// 刷新datagridview时执行的sql /// 参数where是查询条件 /// </summary> private void dgvGetInfoSqlExecute(string where) { //设定给datagridview的select列名 string displaySqlSelect = "user_name as '用户名',user_realname as '姓名',user_bankAccount as '银行账号',user_id as '身份证号',user_phone as '手机/电话',user_qq as 'QQ/MSN',user_province as '所在地区'," + "CASE user_vali when '1' then'总代理' when '3' then '省级代理' when '4' then '市级代理' when '5' then '区域代理' when '6' then '市场专员' when '7' then '业务员' when '8' then '省代(虚)' ELSE '普通用户' end AS '用户权限'," + "CASE allowlogin when '1' then'是' ELSE'否' end AS '允许登录',machinecode as '机器码',lastloginplace as '上次登录地点',lastlogintime as '上次登录时间'," + "registplace as '注册地点',registtime as '注册时间',case online when '1' then '用户在线' when '2' then '机器在线' else '离线' end as '当前是否在线',`content` as '用户备注',parent_realname as '区域领导'," + "soft_version as '软件版本' "; DataTable tb = LinkMySql.MySqlQuery("select " + displaySqlSelect + " from " + Global.sqlUserTable + " " + where + ""); dataGridView1.DataSource = tb; dataGridView1.DataMember = tb.TableName; DataTable cu = LinkMySql.MySqlQuery("select count(user_id) as 总计 from " + Global.sqlUserTable + " " + where + ""); DataRow dr = cu.Rows[0]; this.sumUserLabel.Text = "共有 " + dr[0].ToString() + " 位用户"; }
//写入数据库 private void writeToDB() { string user_realname = textBox4.Text; string user_id = textBox5.Text; string user_phone = textBox9.Text; string user_qq = textBox10.Text; string user_province = ""; string province = textBox7.Text; string city = textBox6.Text; if (province.Contains("省")) { province = province.Substring(0, province.IndexOf("省")); } if (city.Contains("市")) { city = city.Substring(0, city.IndexOf("市")); } user_province = province + "省" + city + "市"; if (textBox7.Text.Equals("") && textBox6.Text != "") { user_province = textBox6.Text + "市"; } if (user_province.Equals("省市")) { user_province = "暂无"; } if (user_province.IndexOf("市") - user_province.IndexOf("省") == 1) { user_province = user_province.Substring(0, user_province.IndexOf("省") + 1); } try { LinkMySql.MySqlQuery("update " + Global.sqlUserTable + " set user_realname='" + user_realname + "',user_province='" + user_province + "',user_id='" + user_id + "',user_phone='" + user_phone + "',user_qq='" + user_qq + "' where user_name='" + Global.user_name + "'"); MessageBox.Show("修改成功", "恭喜"); this.Close(); } catch { MessageBox.Show("修改失败,请稍后重试", "提示"); } }
//启动下线机制 private void offlineUserTimer_Tick(object sender, EventArgs e) { DataTable tb = LinkMySql.MySqlQuery("select allowlogin,`online`,isdel from " + Global.sqlUserTable + " where user_name='" + Global.user_name + "'"); if (tb != null && tb.Rows.Count > 0) { DataRow dr = tb.Rows[0]; string allowlogin = dr["allowlogin"].ToString(); string online = dr["online"].ToString(); string isdel = dr["isdel"].ToString(); if (allowlogin.Equals("0")) { MessageBox.Show("账号已被禁止登录,软件即将关闭\r\n请重新登录或者检查账号安全"); } else if (isdel.Equals("-1")) { MessageBox.Show("账号已被删除,软件即将关闭\r\n请重新登录或者检查账号安全"); } else if (online.Equals("0")) { MessageBox.Show("账号已被下线,软件即将关闭\r\n请重新登录或者检查账号安全"); } else if (online.Equals("2") && Global.loginType.Equals("1"))//机器码登录下线机制 { MessageBox.Show("账号已从机器码登录,软件即将关闭\r\n请重新登录或者检查账号安全"); } else { return; } Global.isNormalStatus = false;// 设置为非正常关闭 this.offlineUserTimer.Enabled = false; this.Dispose(); this.Close(); } }
//得到跑马灯文字信息 private void getLoadMsg() { try { //用来外部终止跑马灯线程 while (startTPMD) { DataTable dt1 = LinkMySql.MySqlQuery("select * from msg"); DataRow dr1 = dt1.Rows[0]; setLabel5Text(dr1["msg_login"].ToString()); Global.main_msg = dr1["msg_main"].ToString(); startTPMD = false; } } catch { setLabel5Text("无法连接到服务器,请重新打开软件或者检查网络。"); } finally { //启用相关控件 enabledControls(); } }
//第二个选项卡添加用户写入数据库 private void writeToDB() { string user_name = textBox1.Text; string user_pass = textBox2.Text; if (user_pass.Equals("")) { user_pass = "******"; } ToMD5 md5 = new ToMD5();//将密码加密为md5 user_pass = md5.Encrypt(user_pass); string user_realname = textBox4.Text; string user_bankAccount = bankAccount.Text.Trim(); string user_id = textBox5.Text; string user_phone = textBox9.Text; string user_qq = textBox10.Text; string user_province = textBox7.Text + "省" + textBox6.Text + "市"; if (textBox7.Text.Equals("") && textBox6.Text != "") { user_province = textBox6.Text + "市"; } if (user_province.Equals("省市")) { user_province = "暂无"; } string machinecode = textBox3.Text; string registtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string registplace = getIP.GetWebCity(); int i = registplace.LastIndexOf(":") + 1; int j = registplace.IndexOf("市"); registplace = registplace.Substring(i, j - i + 1); string allowlogin = ""; if (this.radioButton1.Checked == true) { allowlogin = "******"; } if (this.radioButton2.Checked == true) { allowlogin = "******"; } try { DataTable dtMCode = LinkMySql.MySqlQuery("select * from " + Global.sqlUserTable + " where user_name='" + user_name + "'"); if (dtMCode.Rows.Count == 0) { int res = LinkMySql.MySqlExcute("insert into " + Global.sqlUserTable + "(user_name,user_pass,user_realname,user_bankAccount,user_id,user_phone,user_qq,user_province,allowlogin,machinecode,registtime,registplace) values('" + user_name + "','" + user_pass + "','" + user_realname + "','" + user_bankAccount + "','" + user_id + "','" + user_phone + "','" + user_qq + "','" + user_province + "','" + allowlogin + "','" + machinecode + "','" + registtime + "','" + registplace + "')"); if (res == 0) { MessageBox.Show("添加失败,请检查输入然后重试此操作。", "提示"); return; } MessageBox.Show("添加成功", "温馨提示"); clrTbx(); } else { MessageBox.Show("用户名已存在,请换一个用户名再试", "温馨提示"); } } catch { MessageBox.Show("添加失败,请稍后重试。", "温馨提示"); } }
private void ModifyInfoByAdmin_Load(object sender, EventArgs e) { DataTable dt1 = LinkMySql.MySqlQuery("select * from " + Global.sqlUserTable + " where user_name='" + un + "'"); DataRow dr1 = dt1.Rows[0]; string user_realname = dr1["user_realname"].ToString(); if (user_realname == null || user_realname.Equals("")) { user_realname = ""; } string user_id = dr1["user_id"].ToString(); if (user_id == null || user_id.Equals("")) { user_id = ""; } string user_phone = dr1["user_phone"].ToString(); if (user_phone == null || user_phone.Equals("")) { user_phone = ""; } string user_qq = dr1["user_qq"].ToString(); if (user_qq == null || user_qq.Equals("")) { user_qq = ""; } string user_province = dr1["user_province"].ToString(); if (user_province.Equals("暂无")) { user_province = ""; } if (user_province != "暂无" && user_province.IndexOf("省") > 0 && user_province.IndexOf("市") > 0) { this.textBox7.Text = (user_province.Substring(0, user_province.IndexOf("省"))); this.textBox6.Text = (user_province.Substring(user_province.IndexOf("省") + 1, user_province.IndexOf("市") - user_province.IndexOf("省") - 1)); } if (user_province != "暂无" && user_province.IndexOf("省") < 0 && user_province.IndexOf("市") > 0) { this.textBox6.Text = (user_province.Substring(0, user_province.IndexOf("市"))); } if (user_province != "暂无" && user_province.IndexOf("省") > 0 && user_province.IndexOf("市") < 0) { this.textBox7.Text = (user_province.Substring(0, user_province.IndexOf("省"))); } this.textBox4.Text = user_realname; this.textBox5.Text = user_id; this.textBox9.Text = dr1["user_phone"].ToString(); this.textBox10.Text = dr1["user_qq"].ToString(); this.bankAccount.Text = dr1["user_bankAccount"].ToString(); string allowlogin = dr1["allowlogin"].ToString(); if (allowlogin.Equals("1")) { this.radioButton1.Checked = true; } if (allowlogin.Equals("0")) { this.radioButton2.Checked = true; } }
private void ModifyInfo_Load(object sender, EventArgs e) { this.textBox1.Text = Global.user_name; DataTable dt1 = LinkMySql.MySqlQuery("select user_realname,user_bankAccount,user_id,user_phone,user_qq,user_province from " + Global.sqlUserTable + " where user_name='" + Global.user_name + "'"); DataRow dr1 = dt1.Rows[0]; string user_realname = dr1["user_realname"].ToString(); if (user_realname == null || user_realname.Equals("")) { user_realname = ""; } string user_id = dr1["user_id"].ToString(); if (user_id == null || user_id.Equals("")) { user_id = ""; } string user_phone = dr1["user_phone"].ToString(); if (user_phone == null || user_phone.Equals("")) { user_phone = ""; } string user_qq = dr1["user_qq"].ToString(); if (user_qq == null || user_qq.Equals("")) { user_qq = ""; } string user_province = dr1["user_province"].ToString(); if (user_province.Equals("暂无")) { user_province = ""; } if (user_province != "暂无" && user_province.IndexOf("省") > 0 && user_province.IndexOf("市") > 0) { this.textBox7.Text = (user_province.Substring(0, user_province.IndexOf("省"))); this.textBox6.Text = (user_province.Substring(user_province.IndexOf("省") + 1, user_province.IndexOf("市") - user_province.IndexOf("省") - 1)); } if (user_province != "暂无" && user_province.IndexOf("省") < 0 && user_province.IndexOf("市") > 0) { this.textBox6.Text = (user_province.Substring(0, user_province.IndexOf("市"))); } if (user_province != "暂无" && user_province.IndexOf("省") > 0 && user_province.IndexOf("市") < 0) { this.textBox7.Text = (user_province.Substring(0, user_province.IndexOf("省"))); } this.textBox4.Text = user_realname; this.textBox5.Text = user_id; this.textBox9.Text = dr1["user_phone"].ToString(); this.textBox10.Text = dr1["user_qq"].ToString(); this.bankAccount.Text = dr1["user_bankAccount"].ToString(); if (Global.user_vali.Equals("3") || Global.user_vali.Equals("4")) { this.textBox7.Enabled = false; this.textBox6.Enabled = false; } }