public DataTable getUserTree() { sqlHelper sh = new sqlHelper(); sysLoginInCls si = public_method.getLoginInObject(); string sql = "select * from vw_tree_all " + " where userId in (select userId from sys_dataRole_user where roleId = " + si.dataRoleId + ")" + " union all select* from vw_tree_all" + " where id in (select distinct parentId from vw_tree_all" + " where userId in (select userId from sys_dataRole_user where roleId = " + si.dataRoleId + "))" + " union all select* from vw_tree_all" + " where id in (select distinct parentId from vw_tree_all" + " where id in (select distinct parentId from vw_tree_all" + " where userId in (select userId from sys_dataRole_user where roleId = " + si.dataRoleId + ")))" + " union all select* from vw_tree_all" + " where id in (select distinct parentId from vw_tree_all" + " where id in (select distinct parentId from vw_tree_all" + " where id in (select distinct parentId from vw_tree_all" + " where userId in (select userId from sys_dataRole_user where roleId = " + si.dataRoleId + "))))"; DataTable dt = new DataTable(); try { dt = sh.dbClient().SqlQueryable <object>(sql).ToDataTable(); } catch { } return(dt); }
public DataTable getSelectItem2(string tableName, string fieldValue) { sysLoginInCls si = public_method.getLoginInObject(); DataTable dt = new DataTable(); //这里执行 try { sqlHelper sh = new sqlHelper(); ISqlSugarClient db = sh.dbClient(); string sql = "select * from " + tableName + " where (flag=1"; if (!string.IsNullOrEmpty(fieldValue) && fieldValue != "null") { sql += " and projectId= " + si.projectId + " and carId is null ) or (flag=1 and projectId= " + si.projectId + " and guanYouId=" + fieldValue + ")"; } else { sql += " and projectId= " + si.projectId + " and carId is null )"; } dt = db.SqlQueryable <object>(sql).ToDataTable(); } catch (Exception ex) { } return(dt); }
public DataTable get_times_user_softTop5(JObject passJson) { sqlHelper sh = new sqlHelper(); string timeQujian = passJson["timeQujian"].ToString(); string[] TimerArray = new string[2]; if (timeQujian != "") { TimerArray = timeQujian.Split('~'); } string userIdList = passJson["userIdList"].ToString(); string sql = "select * from (select *,ROW_NUMBER() over(partition by userId,day order by usedSeconds desc ) num from ("; sql += " select userId,userName,(userName+'-'+appName) appName,postName,convert(varchar(10),createDate,120) day,sum(usedSeconds) usedSeconds"; sql += " from vw_tb_mouse_user where createDate between '" + TimerArray[0] + " ' and dateadd(day,1,'" + TimerArray[1] + "') "; if (!string.IsNullOrEmpty(userIdList)) { sql += "and userId in(" + userIdList + ")"; } sql += " group by userId,userName,appName,postName,convert(varchar(10),createDate,120) ) t1 ) t0 where num<=" + System.Configuration.ConfigurationManager.AppSettings["softComparmCount"]; DataTable dt = new DataTable(); try { dt = sh.dbClient().SqlQueryable <object>(sql).OrderBy("userId desc").ToDataTable(); } catch (Exception ex) { } return(dt); }
public DataTable getSelectItem(string tableName, int belongsId, int checkDataRole = 0) { sysLoginInCls si = public_method.getLoginInObject(); DataTable dt = new DataTable(); //这里执行 try { sqlHelper sh = new sqlHelper(); ISqlSugarClient db = sh.dbClient(); string whereSql = ""; string sql = "select * from " + tableName + " where flag=1 " + whereSql; if (checkDataRole == 1) { #region sql += " and belongsId = " + belongsId; #endregion } dt = db.SqlQueryable <object>(sql).ToDataTable(); } catch (Exception ex) { } return(dt); }
public DataTable getSelectItem(string tableName , string fieldKey , string fieldValue , int checkDataRole = 0) { DataTable dt = new DataTable(); //这里执行 try { sqlHelper sh = new sqlHelper(); ISqlSugarClient db = sh.dbClient(); string sql = "select * from " + tableName + " where flag=1"; if (!string.IsNullOrEmpty(fieldKey) && !string.IsNullOrEmpty(fieldValue)) { sql += " and " + fieldKey + "='" + fieldValue + "'"; } if (checkDataRole == 1) { #region #endregion } dt = db.SqlQueryable <object>(sql).ToDataTable(); } catch (Exception ex) { } return(dt); }
private void btnSave_Click(object sender, EventArgs e) { string connectionString = string.Format("server = {0}", txtIp.Text); SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString); // Supply the additional values. builder.UserID = "sa"; builder.InitialCatalog = "SchoolManagment2017"; builder.Password = "******"; sqlHelper help = new sqlHelper(builder.ToString()); try { if (help.IsConnection) { AppSettings setting = new AppSettings(); setting.SaveConnectionString("partialConnectString", connectionString); MessageBox.Show("تم حفظ قاعدة البيانات بنجاح", "إشعار", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "إشعار", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public DataTable get_mouse_keyboard_union(JObject passJson) { sqlHelper sh = new sqlHelper(); string timeQujian = passJson["timeQujian"].ToString(); string[] TimerArray = new string[2]; if (timeQujian != "") { TimerArray = timeQujian.Split('~'); } string userIdList = passJson["userIdList"].ToString(); string sql = "select userId,userName,convert(varchar(10),createDate,120) day,sum(Count) count from vw_mouse_keyboard_union_user"; sql += " where createDate between '" + TimerArray[0] + "' and dateadd(day,1,'" + TimerArray[1] + "')"; if (!string.IsNullOrEmpty(userIdList)) { sql += "and userId in(" + userIdList + ")"; } sql += " group by userId,userName,convert(varchar(10),createDate,120) "; DataTable dt = new DataTable(); try { dt = sh.dbClient().SqlQueryable <object>(sql).OrderBy("day,userId asc").ToDataTable(); } catch (Exception ex) { } return(dt); }
public object search() { sqlHelper sh = new sqlHelper(); var list = sh.dbClient().Queryable <sys_user>().ToList();//查询所有 return(list); }
public returnR machineUserDel(JObject passObj) { returnR rr = new returnR(); string idList = passObj["idList"].ToString(); string sql = "delete tb_Machine_user where userid in(" + idList + ")"; sqlHelper sh = new sqlHelper(); int iLen = 0; try { iLen = sh.dbClient().Ado.ExecuteCommand(sql); if (iLen > 0) { rr.code = 100; rr.msg = "删除成功!"; } else { rr.code = 0; rr.msg = "删除失败!"; } } catch (Exception ex) { rr.code = -5; rr.msg = ex.Message; } return(rr); }
public string updateListenCount(string count) { if (string.IsNullOrEmpty(count)) { return("错误,输入的count为空"); } ISqlSugarClient db = null; try { sqlHelper sh = new sqlHelper(); db = sh.dbClient(); sys_listen listen = new sys_listen(); listen.listen_count = DES_En_De.DesEncrypt(count); var countList = db.SqlQueryable <sys_listen>("select listen_count from sys_listen").ToList(); if (countList.Count > 0) { db.Updateable(listen).ExecuteCommand(); } else { db.Insertable(listen).ExecuteCommand(); } } catch (Exception ex) { return(ex.Message); } return("操作成功"); }
public List <object> getMachineUserDate(JObject passJson, String mac) { try { sqlHelper sh = new sqlHelper(); ISqlSugarClient db = sh.dbClient(); string sql = ""; sql += " select u.*,t.teamName from tb_Machine_user u" + " inner join public_team t on t.teamId = u.belongsId and t.flag = 1 " + " where u.flag = 1 and cpuid = '" + mac + "'"; //这里把查询的语句记录到内存中 sysSearchSql sss = new sysSearchSql(); sss.loginInIp = public_method.GetIPAddress(); sss.gridkey = "getMachineUserDate";//这里记录一下 sss.sql = sql; MvcApplication.setsysSearchSql(sss); var list = db.SqlQueryable <object>(sql).ToList(); return(list); } catch (Exception ex) { return(new List <object>()); } }
protected void Button1_Click(object sender, EventArgs e) { sqlHelper sh = new sqlHelper(); string sql = "select STUDENT_NO,STUDENT_NAME,TEACHER,STUDENT_REA,STUDENT_PHONE,CREATETIME,LENGTH from STUDENTAPPLY where FLAG=0 and STUDENT_NO='" + TextBox1.Text + "'and TEACHER='" + Session["name"] + "'"; prolist.DataSource = pr.GetList(sql); prolist.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { sqlHelper hlp = new sqlHelper(); string strSql = "Select categoryID, categoryName from Categories"; gvExecuteSql.DataSource = hlp.executeSQL(strSql); gvExecuteSql.DataBind(); }
public DataTable get_common(string tableName, string userIdList, string groupByModel) { sqlHelper sh = new sqlHelper(); string sql = ""; string sqlUserList = ""; if (!string.IsNullOrEmpty(userIdList)) { sqlUserList = " where userId in (" + userIdList + ") "; } if (groupByModel == "person") { sql = "select top 5 * from " + tableName; sql += sqlUserList; } else if (groupByModel == "team") { sql = " select teamName as userName, sum(Count) as Count from " + tableName; sql += sqlUserList; sql += "group by teamName"; } else if (groupByModel == "department") { sql = " select departmentName as userName, sum(Count) as Count from " + tableName; sql += sqlUserList; sql += "group by departmentName"; } else if (groupByModel == "fgs") { sql = " select fgsName as userName, sum(Count) as Count from " + tableName; sql += sqlUserList; sql += "group by fgsName"; } else if (groupByModel == "zgs") { sql = " select zgsName as userName, sum(Count) as Count from " + tableName; sql += sqlUserList; sql += "group by zgsName"; } DataTable dt = new DataTable(); try { dt = sh.dbClient().SqlQueryable <object>(sql).ToDataTable(); } catch { } return(dt); }
private void BtnCnx_Click(object sender, EventArgs e) { Regex rgx = new Regex(@"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"); if (rgx.IsMatch(txtIP.Text)) { Regex rg = new Regex(@"^\d{4}$"); if (rg.IsMatch(txtPort.Text)) { if (txtIP.Text != "" && txtNom.Text != "" && txtPass.Text != "" && txtPort.Text != "") { var s = txtIP.Text + "," + txtPort.Text; string connectionString = string.Format(" Server = {0}; User ID ={1};Password ={2}" , s, txtNom.Text, txtPass.Text); SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString); // Supply the additional values. builder.InitialCatalog = "VegaCableProd"; sqlHelper help = new sqlHelper(builder.ToString()); try { if (help.IsConnection) { MessageBox.Show("La connection est etablie avec Succes", "Connection Valide", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Connection Echoue", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Veillez verifier que vous avez remplit tous les case ", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { txtPort.Text = ""; MessageBox.Show("veuillez respecter le notation de la port"); } } else { txtIP.Text = ""; MessageBox.Show("veuillez respecter le notation de l'adress IP"); } }
public DataTable get_user_soft_list(string tableName, string userIdList, string groupByModel) { sqlHelper sh = new sqlHelper(); string sql = ""; string sqlUserList = ""; if (!string.IsNullOrEmpty(userIdList)) { sqlUserList = " where userId in (" + userIdList + ") "; } if (groupByModel == "person") { sql = "select top 10 * from " + tableName; sql += sqlUserList; } else if (groupByModel == "team") { sql = " select top 10 teamName as userName,partDate,appName,left(windowTitle,50)as windowTitle from " + tableName; sql += sqlUserList; } else if (groupByModel == "department") { sql = " select top 10 departmentName as userName,partDate,appName,left(windowTitle,50)as windowTitle from " + tableName; sql += sqlUserList; } else if (groupByModel == "fgs") { sql = " select top 10 fgsName as userName,partDate,appName,left(windowTitle,50)as windowTitle from " + tableName; sql += sqlUserList; } else if (groupByModel == "zgs") { sql = " select top 10 zgsName as userName,partDate,appName,left(windowTitle,50)as windowTitle from " + tableName; sql += sqlUserList; } DataTable dt = new DataTable(); try { dt = sh.dbClient().SqlQueryable <object>(sql).ToDataTable(); } catch { } return(dt); }
public DataTable get_user_hours_keyword(string userIdList, string groupByModel) { sqlHelper sh = new sqlHelper(); string sql = ""; string sqlUserList = ""; if (!string.IsNullOrEmpty(userIdList)) { sqlUserList += " where userId in (" + userIdList + ") "; } if (groupByModel == "person") { sql = "select * from vw_当日_人员时刻繁忙度对比 "; sql += sqlUserList; } else if (groupByModel == "team") { sql = "select teamName as userName,sum(Count)as Count,hour from vw_当日_人员时刻繁忙度对比 " + sqlUserList; sql += " group by teamName,hour"; } else if (groupByModel == "department") { sql = "select departmentName as userName,sum(Count)as Count,hour from vw_当日_人员时刻繁忙度对比 " + sqlUserList; sql += " group by departmentName,hour"; } else if (groupByModel == "fgs") { sql = "select fgsName as userName,sum(Count)as Count,hour from vw_当日_人员时刻繁忙度对比 " + sqlUserList; sql += " group by fgsName,hour"; } else if (groupByModel == "zgs") { sql = "select zgsName as userName,sum(Count)as Count,hour from vw_当日_人员时刻繁忙度对比 " + sqlUserList; sql += " group by zgsName,hour"; } DataTable dt = new DataTable(); try { dt = sh.dbClient().SqlQueryable <object>(sql).OrderBy("hour asc,userName asc").ToDataTable(); } catch (Exception ex) { } return(dt); }
public DataTable commonSql(string tableName) { DataTable dt = new DataTable(); string sql = "select * from " + tableName; try { sqlHelper sh = new sqlHelper(); dt = sh.dbClient().Ado.GetDataTable(sql); } catch { } return(dt); }
protected void btnAdd_Click(object sender, EventArgs e) { sqlHelper sh = new sqlHelper(); string sno = Labelno.Text.Trim(); string sname = Labelsname.Text.Trim(); string teacher = Labeltname.Text.Trim(); string stuRea = txtRea.Text.Trim(); string stuPhone = txtPhone.Text.Trim(); string Length = txtLength.Text.Trim(); //string stuSex if (stuRea.Equals("")) { Tool.Alert("理由不能为空", Page); } else if (stuPhone.Equals("")) { Tool.Alert("电话号码不能为空", Page); } else if (Length.Equals("")) { Tool.Alert("请假天数不能为空", Page); } else { string sqlAddAPPLY = "insert into STUDENTAPPLY(STUDENT_NO,STUDENT_NAME,TEACHER,STUDENT_REA,STUDENT_PHONE,CREATETIME,LENGTH,FLAG) values('" + sno + "','" + sname + "','" + teacher + "','" + stuRea + "','" + stuPhone + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + Length + "','" + 1 + "')"; if (sh.excuteNonQuery(sqlAddAPPLY)) { Tool.Alert("申请成功,请等待回复!", Page); Labelno.Text = ""; Labelsname.Text = ""; Labeltname.Text = ""; txtRea.Text = ""; txtPhone.Text = ""; txtLength.Text = ""; } else { Tool.Alert("申请失败,请重试!", Page); } } }
public returnR machineUserModify(JObject passObj) { returnR rr = new returnR(); string userId = passObj["userId"].ToString(); string belongsId = passObj["belongsId"].ToString(); string cpuId = passObj["cpuId"].ToString(); string userName = passObj["userName"].ToString(); string sex = passObj["sex"].ToString(); string psw = passObj["psw"].ToString(); string machineName = passObj["machineName"].ToString(); string account = passObj["account"].ToString(); string remarks = ""; if (passObj["remarks"] != null) { remarks = passObj["remarks"].ToString(); } psw = DES_En_De.UserMd5(psw); string sql = "update tb_Machine_user set account='" + account + "',cpuId='" + cpuId + "',machineName='" + machineName + "',userName='******',sex='" + sex + "',belongsId='" + belongsId + "',remarks='" + remarks + "',updateDate=GETDATE() where userId='" + userId + "'"; sqlHelper sh = new sqlHelper(); int iLen = 0; try { iLen = sh.dbClient().Ado.ExecuteCommand(sql); if (iLen > 0) { rr.code = 100; rr.msg = "修改成功!"; } else { rr.code = 0; rr.msg = "修改失败!"; } } catch (Exception ex) { rr.code = -5; rr.msg = ex.Message; } return(rr); }
public List <sys_data_role> get_sys_data_role() { List <sys_data_role> l_role = new List <sys_data_role>(); //这里执行 try { sqlHelper sh = new sqlHelper(); ISqlSugarClient db = sh.dbClient(); l_role = db.Queryable <sys_data_role>().Where(it => it.flag == 1).OrderBy("orderNo").ToList(); } catch (Exception ex) { } return(l_role); }
public DataTable getSysLog(JObject passJson) { DataTable dt = new DataTable(); try { sqlHelper sh = new sqlHelper(); ISqlSugarClient db = sh.dbClient(); string sql = ""; sql = " select s.*,u.userName createUserName from sys_log s left join sys_user u on s.createUserId=u.userId where 1=1 "; if (passJson != null) { JArray passSearchJarry = JArray.Parse(passJson["centerSearchArray"].ToString()); for (var i = 0; i < passSearchJarry.Count; i++) { string key = passSearchJarry[i]["fieldName"].ToString(); string op = passSearchJarry[i]["op"].ToString(); string value = passSearchJarry[i]["fieldValue"].ToString();; if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(op) && !string.IsNullOrEmpty(value)) { sql += " and " + key + public_method.get_opTimeReset_sql(op, value); } } } // sql += " order by s.createDate desc "; //这里把查询的语句记录到内存中 sysSearchSql sss = new sysSearchSql(); sss.loginInIp = public_method.GetIPAddress(); sss.gridkey = "getSysLog";//这里记录一下 sss.sql = sql; MvcApplication.setsysSearchSql(sss); dt = db.SqlQueryable <object>(sql).OrderBy("createDate desc").ToDataTable(); return(dt); } catch (Exception ex) { return(dt); } }
public DataTable getDataRoleUserIdList() { sqlHelper sh = new sqlHelper(); sysLoginInCls si = public_method.getLoginInObject(); string sql = "select userId from sys_dataRole_user where roleId = " + si.dataRoleId; DataTable dt = new DataTable(); try { dt = sh.dbClient().SqlQueryable <object>(sql).ToDataTable(); } catch { } return(dt); }
public DataTable commonMethod(string tableName) { sqlHelper sh = new sqlHelper(); string sql = "select * from " + tableName; DataTable dt = new DataTable(); try { dt = sh.dbClient().SqlQueryable <object>(sql).ToDataTable(); } catch { } return(dt); }
private DataTable getMySubordinateList(string departmentId) { ISqlSugarClient db = null; try { sqlHelper sh = new sqlHelper(); db = sh.dbClient(); var depId = new SugarParameter("@departmentId", departmentId); //var manager = new SugarParameter("@managerFlag", managerFlag); SugarParameter[] para = new SugarParameter[1]; para[0] = depId; //para[1] = manager; DataTable MySubordinateList = db.Ado.UseStoredProcedure().GetDataTable("sp_getMySubordinateList", para); //string sql = ""; //sql += " ;WITH rec AS( " + // " SELECT departmentId,departmentName,belongsId FROM public_department where departmentId = " + departmentId + // " UNION ALL " + // " SELECT a.departmentId,a.departmentName,a.belongsId FROM public_department as a ,rec AS b WHERE a.belongsId = b.departmentId " + // " ) " + // " select userId from tb_Machine_user " + // " where belongsId in " + // " ( " + // " SELECT departmentId FROM rec " + // " ) " ; return(MySubordinateList); } catch (Exception ex) { //return new List<object>(); return(new DataTable()); } finally { db.Close(); } }
public List <object> getUserManger(JObject passJson) { try { sqlHelper sh = new sqlHelper(); ISqlSugarClient db = sh.dbClient(); string sql = ""; sql += " select * from vw_userManger where 1=1"; if (passJson != null) { JArray passSearchJarry = JArray.Parse(passJson["centerSearchArray"].ToString()); for (var i = 0; i < passSearchJarry.Count; i++) { string key = passSearchJarry[i]["fieldName"].ToString(); string op = passSearchJarry[i]["op"].ToString(); string value = passSearchJarry[i]["fieldValue"].ToString();; if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(op) && !string.IsNullOrEmpty(value)) { sql += " and " + key + public_method.get_opTimeReset_sql(op, value); } } } //这里把查询的语句记录到内存中 sysSearchSql sss = new sysSearchSql(); sss.loginInIp = public_method.GetIPAddress(); sss.gridkey = "getUserManger";//这里记录一下 sss.sql = sql; MvcApplication.setsysSearchSql(sss); var list = db.SqlQueryable <object>(sql).OrderBy("orderNum").ToList(); return(list); } catch (Exception ex) { return(new List <object>()); } }
protected void btnLogin_Click(object sender, EventArgs e) { sqlHelper sh = new sqlHelper(); string strCmd = "select * from userslogin where username='******' and password='******'"; bool flag = sh.excuteReader(strCmd); if (flag) { DataTable dt = sh.GetList(strCmd).Tables[0]; if (txtPassword1.Text != "" && txtPassword1.Text != "") { if (int.Parse(txtPassword1.Text) == int.Parse(txtPassword.Text)) { Response.Write("<script>alert('和原密码相同,修改失败!')</script>"); } else if (int.Parse(txtPassword1.Text) != int.Parse(txtPassword2.Text)) { Response.Write("<script>alert('密码不一致!')</script>"); } else { string sql = "update userslogin set password='******'where username ='******'"; if (sh.excuteNonQuery(sql)) { Response.Write("<script>alert('修改成功');window.location='login.aspx';</script>"); } } } else { Response.Write("<script>alert('修改值不能为空!')</script>"); } } else { Response.Write("<script>alert('用户名或密码错误!')</script>"); } }
public returnR submitUserInfo(JObject passObj) { returnR rr = new returnR(); rr.code = 0; string cpuId = passObj["cpuId"].ToString(); string userName = passObj["userName"].ToString(); string belongsId = passObj["belongsId"].ToString(); sqlHelper sh = new sqlHelper(); string sql = "select * from tb_Machine_user with(nolock) where flag=1 and cpuId='" + cpuId + "'"; try { SqlSugarClient db = sh.dbClient(); DataTable dt = db.Ado.GetDataTable(sql); if (dt.Rows.Count > 0) { sql = "update tb_Machine_user set userName='******' ,belongsId='" + belongsId + "',updateDate=GETDATE() where flag=1 and cpuId='" + cpuId + "'"; } else { sql = "insert into tb_Machine_user(cpuId,userName,belongsId,createDate) values('" + cpuId + "','" + userName + "','" + belongsId + "',getdate())"; } int iReturn = db.Ado.ExecuteCommand(sql); if (iReturn > 0) { rr.code = 100; } else { rr.code = 0; } } catch { } return(rr); }
public returnR getSystemMenu(string role_id) { returnR r = new returnR(); r.code = (int)sysEnum.还没有执行; if (string.IsNullOrEmpty(role_id)) { r.code = (int)sysEnum.参数必填; return(r); } //这里执行 try { sqlHelper sh = new sqlHelper(); } catch (Exception ex) { r.code = (int)sysEnum.发生异常; r.msg = ex.Message; } return(r); }
public DataTable get_ruanjianFenbu(string userIdList, string groupByModel) { sqlHelper sh = new sqlHelper(); string sql = "select * from vw_当日_软件类别时间分布图 where mins>10 "; if (!string.IsNullOrEmpty(userIdList)) { sql += " and userId in (" + userIdList + ")"; } DataTable dt = new DataTable(); try { dt = sh.dbClient().SqlQueryable <object>(sql).OrderBy("mins desc").ToDataTable(); } catch { } return(dt); }
protected void btnLogin_Click(object sender, EventArgs e) { sqlHelper sh = new sqlHelper(); string strCmd = "select * from userslogin where username='******' and password='******'"; bool flag = sh.excuteReader(strCmd); if (flag) { //使用数据访问类中的GetList方法获取数据表,并返回给dt对象 DataTable dt = sh.GetList(strCmd).Tables[0]; //Session对象保存用户登录名、用户类型 Session["name"] = dt.Rows[0]["username"]; Session["type"] = dt.Rows[0]["type"]; Response.Redirect("default.aspx"); } else { Response.Write("<script>alert('用户名或密码错误!')</script>"); } }