private void XSTable() { str = new StringBuilder(); lblXS.Text = ""; //按日期排序,查找出当前状态为已完成的勤务流程各步骤的功能类型,功能记录的GUID string XSSql = "select PFunction,Number,NFunction from STelFlow where Tel_ID = '" + Tel_ID + "' AND OperateStep = '2' order by CreatedDate"; DataTable XSTable = db.GetDataTable(XSSql); str.Append("<table width=\"100%\">"); //定义表开始 for (int i = 0; i < XSTable.Rows.Count; i++) //表共有多少条记录 { if (XSTable.Rows[i][0].ToString() == "1") //电话登记 { XSDJ(XSTable.Rows[i][1].ToString()); } else if (XSTable.Rows[i][0].ToString() == "2") //办公室审阅 { XSSY(XSTable.Rows[i][1].ToString()); } else if (XSTable.Rows[i][0].ToString() == "3") //领导批示 { XSPS(XSTable.Rows[i][1].ToString()); } } str.Append("</table>"); //定义表结束 lblXS.Text = str.ToString(); }
protected void Page_Load(object sender, EventArgs e) { config.ProjectId = "00000001"; if (!IsPostBack) { //取得所有功能选项 DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable("select * from SSysFunction", out dt); cblFunctionSelect.DataSource = dt.DefaultView; cblFunctionSelect.DataTextField = "Name"; cblFunctionSelect.DataValueField = "Function_Id"; cblFunctionSelect.DataBind(); //添加关闭本页面的事件 btnSave.Attributes.Add("onclick", "closeWin();"); if (Request.QueryString["RoleId"] != null) { //保存角色信息 DataTable dtRole; //保存角色功能关系信息 DataTable dtRoleFunction; string strRole = Request.QueryString["RoleId"].ToString(); db = new MDataBase(config.DBConn); //取得角色信息 db.GetDataTable("select * from SSysRole where Role_Id='" + strRole + "'", out dtRole); //取得角色功能关系信息 db.GetDataTable("select * from SSysRoleFunction where Role_Id='" + strRole + "'", out dtRoleFunction); txtRoleName.Text = dtRole.Rows[0]["Name"].ToString(); for (int i = 0; i < cblFunctionSelect.Items.Count; i++) { if ((dtRoleFunction.Select("Function_Id='" + cblFunctionSelect.Items[i].Value + "'").Length) != 0) { cblFunctionSelect.Items[i].Selected = true; } } hfIsUpdate.Value = strRole; lblCaption.Text = "角色修改"; } else { hfIsUpdate.Value = "Insert"; lblCaption.Text = "角色添加"; } } }
private void XS() { str = new StringBuilder(); lblxs.Text = ""; str.Append("<table width=\"100%\">"); //定义表开始 string strSOrdNet = "select Order_ID,Title,Net,Type,Content,Unit,Man,Time,Adjunct,Personnel,Net_Guid from" + " SOrdNet where Order_ID = '" + ViewState["Order_ID"].ToString() + "'"; DataRow SOrdNetRow = db.GetDataRow(strSOrdNet); str.Append(" <tr> <td colspan=\"4\" align=\"center\"> 警卫局网站信息报送审批表 </td> </tr>" + "<tr> <td align=\"center\" style=\"width: 25%\"> 勤务编号</td> <td colspan=\"3\"> " + SOrdNetRow[0].ToString().Trim() + "</td></tr> " + "<tr><td align=\"center\" style=\"width: 25%\"> 信息标题</td><td colspan=\"3\"> " + SOrdNetRow[1].ToString().Trim() + "</td></tr> " + "<tr><td align=\"center\" style=\"width: 25%\">拟发网站</td><td align=\"center\" style=\"width: 25%\"> " + SOrdNetRow[2].ToString().Trim() + "</td> <td align=\"center\" style=\"width: 25%\">栏目</td>" + SOrdNetRow[3].ToString().Trim() + "</td> </tr>" + "<tr><td colspan=\"4\" align=\"center\">内容</td></tr>" + "<tr><td colspan=\"4\" align=\"center\"> " + SOrdNetRow[4].ToString().Trim() + "</td> </tr> " + "<tr> <td align=\"center\">附件:</td><td colspan=\"3\"> "); str.Append("<iframe style=\"overflow: auto; border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none; width: 550px; height: 120px;\" src = \"Abjunct.aspx?AttachmentBatch_Guid='" + SOrdNetRow[8].ToString().Trim() + "'\"></iframe>"); str.Append("</td></tr> " + "<tr> <td align=\"center\">承办单位</td>" + "<td>" + SOrdNetRow[5].ToString().Trim() + "</td>" + "<td>拟稿人</td> <td style=\"width: 189px\">" + SOrdNetRow[6].ToString().Trim() + "</td> </tr>" + "<tr> <td align=\"center\">拟稿时间</td>" + "<td>" + SOrdNetRow[7].ToString().Trim() + "</td> " + "<td> 部门拟稿</td> <td style=\"width: 189px\">" + SOrdNetRow[9].ToString().Trim() + "</td></tr> "); string strSOrdNetAuditing = "select OrderNotion,PerNumber from SOrdNetAuditing where Net_Guid = '" + SOrdNetRow[10].ToString().Trim() + "' and StatusId <> '1'"; DataTable SOrdNetAuditingtable = db.GetDataTable(strSOrdNetAuditing); for (int i = 0; i < SOrdNetAuditingtable.Rows.Count; i++) { str.Append(" <tr> <td align=\"center\" style=\"width=25%; height: 51px;\">领导意见</td> " + " <td align=\"left\" style=\"width=75%; height: 51px;\"> " + SOrdNetAuditingtable.Rows[i][0].ToString() + "</td></tr> " + "<tr> <td style=\"height: 4px\"></td> " + "<td align=\"right\" style=\"width=75%; height: 4px;\"> " + SOrdNetAuditingtable.Rows[i][1].ToString() + "</td> </tr>"); } str.Append("</table>"); lblxs.Text = str.ToString(); }
/// <summary> /// 绑定sql查询到的数据到数据表 /// </summary> /// <param name="sql"></param> private void BindData(string sql) { if (sql == "") { sql = "select * from SSysRole where StatusId=0"; } DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable(sql, out dt); if (dt != null) { ViewState["dataSource"] = dt; intCount = dt.Rows.Count; grvRole.DataSource = dt; grvRole.DataBind(); lblPageSum.Text = this.grvRole.PageCount.ToString(); lblRecordeSum.Text = dt.Rows.Count.ToString(); } else { lblPageSum.Text = "0"; Response.Write("<script type='text/javascript'>alert('没有您查找的角色!');</script>"); } }
/// <summary> /// 判断当前登录角色是否具有某个功能(参数中指定) /// </summary> /// <param name="FunctionId">要判断的功能ID</param> /// <param name="config">当前登录人的信息</param> /// <returns></returns> public static bool CheckRole(string FunctionId, Config config) { //根据登录角色得到功能 string strGetFunction = "Select Function_Id From SSysRoleFunction Where Role_Id ='" + config.LoginRole + "'"; bool isHave = false; try { MDataBase db = new MDataBase(config.DBConn); DataTable dt = new DataTable(); db.GetDataTable(strGetFunction, out dt); //判断登录角色的功能中是否有指定功能 if ((dt.Select("Function_Id='" + FunctionId + "'")).Length != 0) { isHave = true; } } catch (Exception exc) { throw exc; } return(isHave); }
/// <summary> /// 绑定sql查询到的数据到数据表 /// </summary> /// <param name="sql"></param> private void BindData(string sql) { try { if (sql == "") { sql = "select a.*,b.UserName As UserName,b.Name As Name,c.Name AS StatusName from SPsnWorkTime a INNER JOIN SC_WorkStatus c ON a.WorkStatusId = c.WorkStatusId Left Join SSysStaff b On a.Staff_Id=b.Staff_Id where a.StatusId=0 And a.Day Between '" + DateTime.Now.AddDays(-7) + "' And '" + DateTime.Now + "'"; } DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); bool isw = db.GetDataTable(sql, out dt); string strs = db.ErrMessage; if (dt != null) { ViewState["dataSource"] = dt; intCount = dt.Rows.Count; grvWorkStat.DataSource = dt; grvWorkStat.DataBind(); lblPageSum.Text = this.grvWorkStat.PageCount.ToString(); lblRecordeSum.Text = dt.Rows.Count.ToString(); } else { lblPageSum.Text = "0"; //Response.Write("<script type='text/javascript'>alert('没有找到!');</script>"); } } catch (Exception exc) { throw exc; } }
/// <summary> /// 绑定sql查询到的数据到数据表 /// </summary> /// <param name="sql"></param> private void BindData(string sql) { if (sql == "") { sql = "SELECT a.*, (CASE WHEN b.Name IS NULL THEN '无' ELSE b.Name END) AS parentName, 1 as [Index] FROM SSysDepartment a LEFT OUTER JOIN SSysDepartment b ON a.Parent_Id = b.Dept_Id where (a.StatusId=0) Order By a.Parent_Id, a.OrderIndex"; } try { DataTable dt; db = new MDataBase(config.DBConn); MDataBase db1 = new MDataBase(config.DBConn); bool a = db.GetDataTable(sql, out dt); string b = db.ErrMessage; ViewState["dataSource"] = dt; for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Index"] = (int)dt.Rows[i]["Index"] + i; } intCount = dt.Rows.Count; grvDepartment.DataSource = dt; grvDepartment.DataBind(); PageSum.Text = grvDepartment.PageCount.ToString(); RecordeSum.Text = dt.Rows.Count.ToString(); } catch (Exception exc) { throw exc; } }
/// <summary> /// 根据部门ID得到属于此部门的员工的集合,如果部门ID是0则返回全部员工 /// </summary> /// <param name="DeptId"></param> /// <param name="config"></param> /// <returns></returns> public static string GetStaffByDept(string DeptId, Config config) { try { string strReturn = "('"; MDataBase db = new MDataBase(config.DBConn); DataTable dtStaff = new DataTable(); string strStaff = ""; if (DeptId == "0") { strStaff = "Select * From SSysStaff"; } else { strStaff = "Select * From SSysStaff Where Dept_Id='" + DeptId + "'"; } db.GetDataTable(strStaff, out dtStaff); if (dtStaff.Rows.Count > 0) { for (int i = 0; i < dtStaff.Rows.Count; i++) { strReturn += dtStaff.Rows[i]["Staff_Id"].ToString() + "','"; } strReturn = strReturn.TrimEnd('\'').TrimEnd(',').TrimEnd('\''); } strReturn += "')"; return(strReturn); } catch (Exception exc) { throw exc; } }
public void GetWorkPlan(string sql) { try { if (sql == "") { sql = "select a.*,b.UserName As UserName,b.Name As Name from SPsnWorkTime a Left Join SSysStaff b On a.Staff_Id=b.Staff_Id where a.StatusId=0 And a.Day Between '" + DateTime.Now.AddDays(-7) + "' And '" + DateTime.Now + "'"; } DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); bool isw = db.GetDataTable(sql, out dt); string strs = db.ErrMessage; if (dt != null) { ViewState["dataSource"] = dt; } else { lblPageSum.Text = "0"; Response.Write("<script type='text/javascript'>alert('没有找到!');</script>"); } } catch (Exception exc) { throw exc; } }
/// <summary> /// 根据角色编号得到角色姓名 /// </summary> /// <param name="id"></param> /// <param name="config"></param> /// <returns></returns> public static string GetRoleNameById(string id, Config config) { try { string strReturnNames = ""; if (id != "undefined") { id = id.Replace(",", "','"); string strName = "Select Name From SSysRole Where Role_Id in ('" + id + "')"; MDataBase db = new MDataBase(config.DBConn); DataTable dtName = new DataTable(); db.GetDataTable(strName, out dtName); if (dtName.Rows.Count > 0) { for (int i = 0; i < dtName.Rows.Count; i++) { strReturnNames += dtName.Rows[i]["Name"].ToString() + ","; } strReturnNames = strReturnNames.TrimEnd(','); } } return(strReturnNames); } catch (Exception exc) { throw exc; } }
//查询考试进度 private void ExamProgress() { string sql = "select QuestionState from temp" + config.Staff.Username + " where QuestionState='0'"; DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable(sql, out dt); string Count = (dt.Rows.Count).ToString(); }
//查询未做题的数量 private void selectQuestionState() { string sql = "select QuestionState from temp" + config.Staff.Username + " where QuestionState='0'"; DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable(sql, out dt); this.lblTip.Text = "有" + (dt.Rows.Count).ToString() + "题标记未做题"; }
protected void Page_Load(object sender, EventArgs e) { ////////////// CSSysStaff staff = new CSSysStaff(config.DBConn); staff.Staff_Id = "00000001"; config.Staff = staff; ////////////// btnSelect.Attributes.Add("onclick", "PopWindow();"); btnSelectDepartment.Attributes.Add("onclick", "SelectDept();"); if (!IsPostBack) { if (Function.CheckStaff(config) == "Yes")//为系统管理员 { GetWorkPlan(""); BindData(); //可以选择员工和部门 btnSelect.Enabled = true; btnSelectDepartment.Enabled = true; } else if (Function.CheckStaff(config) == "No")//不是管理员 { GetWorkPlan("select a.*,b.UserName As UserName,b.Name As Name from SPsnWorkTime a Left Join SSysStaff b On a.Staff_Id=b.Staff_Id Where a.StatusId=0 And Staff_Id='" + config.Staff.Staff_Id + "' And a.Day Between '" + DateTime.Now.AddDays(-7) + "' And '" + DateTime.Now + "'"); BindData(); //不可以选择 btnSelect.Enabled = false; btnSelectDepartment.Enabled = false; } else//是部门的管理员 { //得到其所属的员工staff_Id db = new MDataBase(config.DBConn); string sqlStaff = "Select Staff_Id From SSysStaff Where Dept_Id='" + Function.CheckStaff(config) + "'"; DataTable dtStaff = new DataTable(); db.GetDataTable(sqlStaff, out dtStaff); string strStaffs = ""; for (int i = 0; i < dtStaff.Rows.Count; i++) { strStaffs += dtStaff.Rows[i][0].ToString() + "','"; } strStaffs = strStaffs.TrimEnd('\'').TrimEnd(','); GetWorkPlan("select a.*,b.UserName As UserName,b.Name As Name from SPsnWorkTime a Left Join SSysStaff b On a.Staff_Id=b.Staff_Id Where a.StatusId=0 And a.Staff_Id in('" + strStaffs + ") And a.Day Between '" + DateTime.Now.AddDays(-7) + "' And '" + DateTime.Now + "'"); BindData(); //可以选择其所属部门员工 btnSelect.Enabled = true; btnSelectDepartment.Enabled = false; } } txtSelect.Text = Function.GetStaffNameById(hfStaffId.Value.TrimEnd(','), config); txtDepartment.Text = Function.GetDeptNameById(hfDeptId.Value.TrimEnd(','), config); }
protected void Page_Load(object sender, EventArgs e) { Config Config = (Config)Session["Config"]; if (!this.IsPostBack) { //判断用户的角色 // string staff_Id = Config.Staff.Staff_Id; //得到登录的用户名 // string Role = Config.LoginRole.ToString(); //得到登录角色 // string selectRole = db.GetDataScalar("SELECT Name FROM SSysRole WHERE (Role_Id = '" + Role + "')"); //根据传来的角色ID得到角色的名称 string staff_Id = "00000001"; string selectRole = ""; //!!!!! 先写死办公室值班室 ViewState["staff_Id"] = staff_Id; //用户名 ViewState["Role"] = selectRole; //角色 ControlDataBind drp = new ControlDataBind(ConfigurationManager.ConnectionStrings["OA"].ToString()); if (selectRole == "值班室") { drp.DropDownListBind(dropOrder, "STelEnrol", "Tel_ID", "Tel_ID", 4, "StatusId in ('1','2','4')", staff_Id); } else //如果不等于值班室,只能查看和自己相关的勤务 { //查找该用户名做的所有勤务 //在流程表中查找下部执行人有该登录名的 DataTable OrderTable = new DataTable(); string staffOne = "select distinct Tel_ID from STelFlow where PExecute = '" + staff_Id + "'" + " UNION " + "select distinct Tel_ID from STelFlow left join SOrdArrangeMan on STelFlow.NExecute = SOrdArrangeMan.Guid where Man = '" + staff_Id + "'"; OrderTable = db.GetDataTable(staffOne); DataRow dr = OrderTable.NewRow(); dr["Tel_ID"] = "0"; OrderTable.Rows.InsertAt(dr, 0); dropOrder.DataSource = OrderTable; dropOrder.DataValueField = "Tel_ID"; dropOrder.DataTextField = "Tel_ID"; dropOrder.DataBind(); } } }
private string GetMan(string GUIDMan) { string strMan = "select Man from SOrdArrangeMan where Guid = '" + GUIDMan + "'"; //找到该GUID对应的用户名称 DataTable ManTable = db.GetDataTable(strMan); string Man = ""; for (int i = 0; i < ManTable.Rows.Count; i++) { if (i != ManTable.Rows.Count - 1) { Man = Man + ManTable.Rows[i][0].ToString() + ","; } else { Man = Man + ManTable.Rows[i][0].ToString(); } } return(Man); }
//插入平均分到考试表 private void AverageAdd() { string sql = "select avg(score) from SExmScore where Exam_Id='" + Session["Guid"].ToString() + "'"; DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable(sql, out dt); float Average = Convert.ToInt32(dt.Rows[0]); string sqlin = "UPDATE SExmExam set Average='" + Average + "')"; db = new MDataBase(config.DBConn); db.executeUpdate(sqlin); }
//插入名次到成绩表的方法 private void Gradation() { string sql = "select 1 as index,Score from SExmScore where Exam_Id='" + Session["Guid"].ToString() + "' order by Score"; DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable(sql, out dt); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["index"] = Convert.ToInt32(dt.Rows[i]["index"].ToString()) + i; } }
/// <summary> /// 绑定sql查询到的数据到数据表 /// </summary> /// <param name="sql"></param> private void BindData(string sql) { if (sql == "") { if (hfPower.Value == "Yes") { sql = "Select a.*,b.Name as StaffName,c.Name AS StatusName from SPsnWorkTime a INNER JOIN SC_WorkStatus c ON a.WorkStatusId = c.WorkStatusId Left Join SSysStaff b On a.Staff_Id=b.Staff_Id Where a.StatusId=0"; } else if (hfPower.Value == "No") { sql = "Select a.*,b.Name as StaffName,c.Name AS StatusName from SPsnWorkTime a INNER JOIN SC_WorkStatus c ON a.WorkStatusId = c.WorkStatusId Left Join SSysStaff b On a.Staff_Id=b.Staff_Id Where a.StatusId=0 And a.Staff_Id='" + config.Staff.Staff_Id + "'"; } else { sql = "Select a.*,b.Name as StaffName,c.Name AS StatusName from SPsnWorkTime a INNER JOIN SC_WorkStatus c ON a.WorkStatusId = c.WorkStatusId Left Join SSysStaff b On a.Staff_Id=b.Staff_Id Where a.StatusId=0 And a.Staff_Id in('" + Function.GetStaffByDept(config.Staff.Staff_Id, config) + "')"; } } try { DataTable dt; db = new MDataBase(config.DBConn); bool a = db.GetDataTable(sql, out dt); if (dt != null) { if (dt.Rows.Count == 0) { Response.Write("<script type='text/javascript'>alert('没有相应记录!');window.location.href=window.location.href;</script>"); } else { ViewState["dataSource"] = dt; intCount = dt.Rows.Count; grvWorkPlan.DataSource = dt; grvWorkPlan.DataBind(); PageSum.Text = grvWorkPlan.PageCount.ToString(); RecordeSum.Text = dt.Rows.Count.ToString(); } } else { grvWorkPlan.DataSource = null; grvWorkPlan.DataBind(); PageSum.Text = "0"; RecordeSum.Text = "0"; lblCurrentPage.Text = "0"; } } catch (Exception exc) { throw exc; } }
/// <summary> /// 绑定sql查询到的数据到数据表 /// </summary> /// <param name="sql"></param> //双空查询,显示全部信息 private void BindDataGv() { string sql = "select a.Question_Guid,a.Question,substring(Question,1,15),a.QuestionType_Id,b.QuestionTypeName,a.CreatedBy from SExmQuestion a,SC_QuestionType b where a.QuestionType_Id=b.QuestionType_Id"; DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable(sql, out dt); ViewState["dataSource"] = dt; if (dt.Rows.Count == 0) { btnFirstPage.Visible = false; btnForwardPage.Visible = false; btnNextPage.Visible = false; btnLastPage.Visible = false; this.lblCount.Visible = false; lblPage.ForeColor = Color.Red; lblPage.Text = "对不起,没有查询到相关信息!"; gvQuestion.Visible = false; btnChange.Visible = false; btnDelete.Visible = false; this.lblCurrentPage.Visible = false; } else { this.lblCount.Visible = true; this.lblCurrentPage.Visible = true; btnFirstPage.Visible = true; btnForwardPage.Visible = true; btnNextPage.Visible = true; btnLastPage.Visible = true; gvQuestion.Visible = true; btnChange.Visible = true; btnDelete.Visible = true; gvQuestion.PageSize = 50; gvQuestion.DataSource = dt; gvQuestion.DataBind(); //如果GV就一页,翻页按钮不显示 if (gvQuestion.PageCount == 1) { btnFirstPage.Visible = false; btnForwardPage.Visible = false; btnNextPage.Visible = false; btnLastPage.Visible = false; } //显示搜索到的全部条数 this.lblCount.Text = "共有" + (dt.Rows.Count).ToString() + "条记录"; //显示GridView的页数 lblPage.ForeColor = Color.Black; lblPage.Text = "/共" + (gvQuestion.PageCount).ToString() + "页"; //显示GV是第几页 lblCurrentPage.Text = "第" + (gvQuestion.PageIndex + 1).ToString() + "页"; } }
//下拉菜单数据绑定 protected void QuestionTypeDataBind() { string sql = "select QuestionTypeName,QuestionType_Id from SC_QuestionType"; DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable(sql, out dt); sltQuestionTypeId.DataSource = dt.DefaultView; sltQuestionTypeId.DataValueField = "QuestionType_Id"; sltQuestionTypeId.DataTextField = "QuestionTypeName"; sltQuestionTypeId.DataBind(); }
/// <summary> /// SC_QuestionType对象GetDataTable方法 /// </summary> private DataTable executeGetDataTableLike() { bool blnFirstField = true; string sql = "select * from SC_QuestionType"; // (QuestionType_Id)字段 if (_blnQuestionType_IdChanged == true) { if (blnFirstField == true) { blnFirstField = false; sql += " WHERE "; } else { sql += " AND "; } sql += "QuestionType_Id like '%" + _QuestionType_Id + "%'"; } // (QuestionTypeName)字段 if (_blnQuestionTypeNameChanged == true) { if (blnFirstField == true) { blnFirstField = false; sql += " WHERE "; } else { sql += " AND "; } sql += "QuestionTypeName like '%" + _QuestionTypeName + "%'"; } try { MDataBase db = new MDataBase(_DBConn); DataTable dt; bool blnReturnCode = db.GetDataTable(sql, out dt); if (blnReturnCode == false || dt == null) { return(null); } return(dt); } catch (Exception err) { throw; return(null); } }
//插入分数到成绩表的方法,正确数/总题数 private void ScoreAdd() { string sql = "select RightCount from SExmScore where Exam_Id='" + Session["Guid"].ToString() + "'"; DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable(sql, out dt); //取得正确题数 int RightCount = dt.Rows.Count; //取得平均分的方法(正确数/总题数) float Score = RightCount / Convert.ToInt32(Session["Count"]); string sqlin = "UPDATE SExmScore set Score='" + Score + "'"; db = new MDataBase(config.DBConn); db.executeUpdate(sqlin); }
public void DataGridSqlBind(DataGrid DGrid, string sql, string SessionID, Label Message, string MsgStr) { try { DataTable dt = db.GetDataTable(sql); if (dt.Rows.Count > 0) { DGrid.DataSource = dt; DGrid.DataBind(); DGrid.Visible = true; } else { Message.Text = MsgStr; DGrid.Visible = false; } } catch (Exception Err) { ErrorLog.LogInsert(Err.Message, "CS/ControlDataBind", SessionID); Message.Text = MsgStr; } }
//检索数据库题目总数的方法 private void selectQuestionCount() { string sql = "select Question_Guid from SExmQuestion"; DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable(sql, out dt); if (dt.Rows.Count < int.Parse(txtQuestionCount.Text)) { lblError.Visible = true; lblError.Text = "题库内题目数量不足"; return; } }
//判断类型六题目数量是否足够 private void selectQuestionSix() { string sql = "select b.QuestionTypeName from SExmQuestion a,SC_QuestionType b where a.QuestionType_Id = b.QuestionType_Id and b.QuestionTypeName = '" + sltQuestionTypeIdSix.Text + "'"; DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable(sql, out dt); if (dt.Rows.Count < int.Parse(txtPercentageSix.Text)) { lblError.Visible = true; lblError.Text = "题库内" + sltQuestionTypeIdSix.Text + "题目数量不足"; return; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { config.ProjectId = "00000001"; //取得所有部门,作为新部门的父部门 DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable("select * from SSysDepartment", out dt); ddlSupDepartment.Items.Clear(); //当新部门没有父部门时的选项 ddlSupDepartment.Items.Add(new ListItem("无", "0")); ddlSupDepartment.AppendDataBoundItems = true; //绑定新部门的父部门 ddlSupDepartment.DataSource = dt.DefaultView; ddlSupDepartment.DataTextField = "Name"; ddlSupDepartment.DataValueField = "Dept_Id"; ddlSupDepartment.DataBind(); //添加关闭本页面的事件 btnSave.Attributes.Add("onclick", "closeWin();"); if (Request.QueryString["Department"] != null) { DataTable dtDept; string strDept = Request.QueryString["Department"].ToString(); db = new MDataBase(config.DBConn); db.GetDataTable("select * from SSysDepartment where Dept_Id='" + strDept + "' Order By Parent_Id,OrderIndex", out dtDept); txtDepartmentName.Text = dtDept.Rows[0]["Name"].ToString(); for (int i = 0; i < ddlSupDepartment.Items.Count; i++) { if (ddlSupDepartment.Items[i].Value == dtDept.Rows[0]["Parent_Id"].ToString()) { ddlSupDepartment.SelectedIndex = i; } } hfIsUpdate.Value = strDept; lblCaption.Text = "部门修改"; } else { hfIsUpdate.Value = "Insert"; lblCaption.Text = "部门添加"; } } }
//下拉菜单数据绑定 protected void QuestionTypeDataBind() { string sql = "select QuestionTypeName,QuestionType_Id from SC_QuestionType"; DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable(sql, out dt); //默认项为空 sltQuestionTypeId.Items.Add(new ListItem("", "")); sltQuestionTypeId.AppendDataBoundItems = true; sltQuestionTypeId.DataSource = dt.DefaultView; sltQuestionTypeId.DataValueField = "QuestionType_Id"; sltQuestionTypeId.DataTextField = "QuestionTypeName"; sltQuestionTypeId.DataBind(); }
//下拉菜单数据绑定 private void QuestionTypeDataBind() { string sql = "select QuestionTypeName from SC_QuestionType"; DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable(sql, out dt); //添加一个Item项 sltQuestionTypeName.Items.Add(new ListItem("全部", "全部")); // sltQuestionTypeName.DataSource = dt.DefaultView; sltQuestionTypeName.DataValueField = "QuestionTypeName"; sltQuestionTypeName.DataTextField = "QuestionTypeName"; sltQuestionTypeName.DataBind(); }
//下拉菜单数据绑定方法 private void sltDataBind(DropDownList slt) { string sql = "select QuestionTypeName from SC_QuestionType"; DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable(sql, out dt); //给各DropDownList添加一个空白Item项 slt.AppendDataBoundItems = true; slt.Items.Add(new ListItem("", "")); slt.DataSource = dt.DefaultView; slt.DataValueField = "QuestionTypeName"; slt.DataTextField = "QuestionTypeName"; slt.DataBind(); }
//gvScore绑值事件 private void DataBindGvScore() { string sql = "select b.Staff_Id,b.Score,a.Average b.Gradation from SExmExam a,SExmScore b where a.Exam_Id = b.Exam_Id and b.Exam_Id = '" + hfdGv.Value + "'"; DataTable dt = new DataTable(); db = new MDataBase(config.DBConn); db.GetDataTable(sql, out dt); ViewState["dataSourceScore"] = dt; if (dt.Rows.Count == 0) { this.btnScoreDetail.Visible = false; this.btnFirstPageScore.Visible = false; this.btnForwardPageScore.Visible = false; this.btnNextPageScore.Visible = false; this.btnLastPageScore.Visible = false; this.lblCountScore.Visible = false; this.lblCountPageScore.Visible = false; this.lblPageScore.Visible = true; this.lblPageScore.ForeColor = Color.Red; this.lblPageScore.Text = "对不起,没有查询到相关信息!"; this.gvScore.Visible = false; } else { this.btnScoreDetail.Visible = true; this.lblCountScore.Visible = true; this.lblCountPageScore.Visible = true; this.btnFirstPageScore.Visible = true; this.btnForwardPageScore.Visible = true; this.btnNextPageScore.Visible = true; this.btnLastPageScore.Visible = true; this.gvScore.Visible = true; gvExam.PageSize = 50; gvExam.DataSource = dt; gvExam.DataBind(); //显示搜索到的全部条数 this.lblCountScore.Text = "共有" + (dt.Rows.Count).ToString() + "条记录"; //显示GridView的页数 this.lblPageScore.Visible = true; this.lblPageScore.ForeColor = Color.Black; this.lblPageScore.Text = "/共" + (gvExam.PageCount).ToString() + "页"; //显示GV是第几页 this.lblCountPageScore.Text = "第" + (gvExam.PageIndex + 1).ToString() + "页"; //GV中的radiobutton默认选定第一条 RadioButton rbn = ((RadioButton)(gvScore.Rows[0].Cells[0].FindControl("rbnScore"))); rbn.Checked = true; } }