public bool GetInfo(ref UserInfo userinfo) { string str = string.Empty; if (UserType == 1) { str = @"select UserName,学号,姓名,组别,电话,座右铭,年级 from [member] where USERNAME='******'"; } else if (UserType == 2) { str = @"select UserName,学号,姓名,组别,电话,座右铭,年级 from [member] where MAC='" + UserFunction.GetMacByNetworkInterface() + "'"; } DatabaseCmd databasecmd = new DatabaseCmd(); SqlDataReader myreader; databasecmd.SqlExecuteReader(str, out myreader); if (myreader.Read()) { userinfo.UserName = myreader.GetString(0).ToString(); userinfo.StuNum = myreader.GetString(1).ToString(); userinfo.user = myreader.GetString(2).ToString(); userinfo.Team = myreader.GetString(3).ToString(); userinfo.Phone = myreader.GetString(4).ToString(); userinfo.HappyMotto = myreader.GetString(5).ToString(); userinfo.Grade = myreader.GetString(6).ToString(); return(true); } else { return(false); } }
private void Button1_Click(object sender, EventArgs e) { if (MessageBox.Show("是否将本机绑定为签到机器?", "绑定MAC", MessageBoxButtons.YesNo) == DialogResult.Yes) { string Pwd = UserFunction.Md5(TextBox_pwd.Text.ToString()); string selectcmd = "select 学号 from [member] where 学号 = '" + TextBox_num.Text.ToString() + "' and 密码 = '" + Pwd + "'"; DatabaseCmd database = new DatabaseCmd(); SqlDataReader myreader; database.SqlExecuteReader(selectcmd, out myreader); if (myreader.Read()) { string updatestr = "update [member] set MAC = '" + UserFunction.GetMacByNetworkInterface() + "' where 学号 = '" + myreader.GetString(0) + "'"; DatabaseCmd database2 = new DatabaseCmd(); database2.SqlExecuteNonQuery(updatestr); } else { MessageBox.Show("学号或密码错误!"); } database.SqlReaderClose(); MessageBox.Show("绑定成功! MAC地址为:" + UserFunction.GetMacByNetworkInterface()); this.Close(); } }
static public DateTime GetServerTime() { string str = "select getdate() as serverDate"; DatabaseCmd datacmd = new DatabaseCmd(); SqlDataReader myreader; try { datacmd.SqlExecuteReader(str, out myreader); if (myreader.Read()) { return(myreader.GetDateTime(0)); } else { return(DateTime.Now); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); return(DateTime.Now); } finally { datacmd.SqlReaderClose(); } }
static public int GetWeek() { int week = 0; string str = @"select top 1 datediff(day,[开学日期],getdate())/7+1 from [开学日期]"; DatabaseCmd databasecmd = new DatabaseCmd(); SqlDataReader myreader = null; databasecmd.SqlExecuteReader(str, out myreader); week = (myreader.Read()) ? (myreader.GetInt32(0)) : (-1); databasecmd.SqlReaderClose(); return(week); }
static public string GetSemester() { string Semester = string.Empty; string str = "select 学期 from [开学日期]"; DatabaseCmd databasecmd = new DatabaseCmd(); SqlDataReader myreader; databasecmd.SqlExecuteReader(str, out myreader); if (myreader.Read()) { Semester = myreader.GetString(0); } databasecmd.SqlReaderClose(); return(Semester); }
public float SumOnlineTime(UserInfo userinfo) { float OnlineTime = -1; string str_time = "select SUM(合计时间) from 时间统计 where 学号 = '" + userinfo.StuNum + "' and 周次 = " + NowWeek + " and 学期 ='" + Semester + "'"; DatabaseCmd databasecmd = new DatabaseCmd(); SqlDataReader myreader; databasecmd.SqlExecuteReader(str_time, out myreader); if (myreader.Read()) { OnlineTime = (float)myreader.GetDouble(0); } databasecmd.SqlReaderClose(); return(OnlineTime); }
public void SignOut(UserInfo userinfo) { if (IsSignIn) { SignOutTime = UserFunction.GetServerTime(); string str = "update 时间统计 set 离开='" + SignOutTime.ToString("T") + "',合计时间='" + UserFunction.TimeDiff(SignOutTime, SignInTime) + "' where ID=" + userinfo.Sign_Identity; DatabaseCmd database = new DatabaseCmd(); if (SignOutTime.Year == 1991 || !database.SqlExecuteNonQuery(str)) { MessageBox.Show("无法正常签退,可能是网络连接故障。\n" + "点击 确定 将强行退出,此次签到记录作废。\n" + "点击 取消 将不会退出,可修复网络连接后再尝试退出。", Main.SoftName, MessageBoxButtons.OKCancel); } } }
private void ButChange_Click(object sender, EventArgs e) { bool islegal = true; for (int i = 0; i < TextBPhone.Text.Length; ++i) { if (!Char.IsNumber(TextBPhone.Text, i)) { islegal = false; } } if (islegal) { ButChange.Enabled = false; ButChange.Text = "稍后...."; string str = @"update [member] set [电话]='" + TextBPhone.Text.Trim() + "',[座右铭]='" + TextBMotto.Text.Trim() + "' where [学号]='" + userinfo.StuNum + "'"; DatabaseCmd database = new DatabaseCmd(); if (!database.SqlExecuteNonQuery(str)) { MessageBox.Show("更新失败!请检查网络连接"); ButChange.Enabled = true; ButChange.Text = "应用设置"; ButChange.Focus(); } else { userinfo.Phone = TextBPhone.Text.Trim(); userinfo.HappyMotto = TextBMotto.Text.Trim(); ButChange.Text = "设置成功"; TextBMotto.Focus(); } } else { errorProvider1.SetError(TextBPhone, "只允许使用数字!"); TextBPhone.Focus(); } }
public void SignIn(ref UserInfo userinfo) { //检测上次是否正常退出(今天范围内),如果不是,将上次未签退的记录以0小时退掉,并将离开字段=登入字段(因为智能考核系统是以离开字段=0获取在线用户的) DatabaseCmd databasecmd = new DatabaseCmd(); string str = "update 时间统计 set 离开=登入 where 离开='0' and 日期='" + SignInTime.Year + "-" + SignInTime.Month + "-" + SignInTime.Day + "' and 学号='" + userinfo.StuNum + "'"; if (!databasecmd.SqlExecuteNonQuery(str)) { MessageBox.Show("出现致命错误!程序将强制退出!"); IsSignIn = false; Environment.Exit(0); } if (SignInTime.Year != 1991) { string str1 = string.Empty; str1 = "insert into 时间统计(学号,姓名,组别,日期,周次,登入,离开,合计时间,学期) values ('" + userinfo.StuNum + "','" + userinfo.user + "','" + userinfo.Team + "','" + SignInTime.Year + "-" + SignInTime.Month + "-" + SignInTime.Day + "','" + NowWeek + "','" + SignInTime.ToString("T") + "','" + "0" + "','" + "0" + "','" + Semester + "')" + " select scope_identity() as id"; try { object index; databasecmd.SqlExecuteScalar(str1, out index); Sign_Identity = index.ToString(); userinfo.Sign_Identity = Sign_Identity; IsSignIn = true; } catch (Exception ex) { MessageBox.Show(ex.ToString()); Environment.Exit(0); } } }