Exam_GridViewNested.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:18k
源码类别:
OA系统
开发平台:
ASP/ASPX
- using System;
- using System.Data;
- using System.Data.SqlClient;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- public partial class web_data_repair_select_Exam_GridViewNested : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- DataSet ds = new DataSet();
- DataTable dt = new DataTable();
- dt.Columns.Add("id", typeof(Int32));
- dt.Columns.Add("name", typeof(string));
- dt.Columns.Add("num", typeof(Int32));
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand sqlcom = new SqlCommand("SELECT id, name FROM OA_DEPARTMENT WHERE (CHARINDEX('店', name) > 0)", conn);
- SqlDataReader dr = sqlcom.ExecuteReader();
- if (dr.HasRows)
- {
- while (dr.Read())
- {
- DataRow row = dt.NewRow();
- row["id"] = Convert.ToInt32(dr["id"]);
- row["name"] = Convert.ToString(dr["name"]);
- SqlConnection conn1 = dbConnection.getConnection();
- conn1.Open();
- SqlCommand sqlcom1 = new SqlCommand("select count(*) as num from OA_REPAIR_FORM_DETAIL where department_id="+Convert.ToInt32(dr["id"]),conn1);
- SqlDataReader dr1 = sqlcom1.ExecuteReader();
- if (dr1.HasRows)
- {
- while (dr1.Read())
- {
- row["num"] = Convert.ToInt32(dr1["num"]);
- }
- }
- dr1.Close();
- conn1.Close();
- dt.Rows.Add(row);
- }
- }
- ds.Tables.Add(dt);
- MasterGridView.DataSource = ds;
- MasterGridView.DataBind();
- MasterGridView.DataKeyNames = new string[] { "id" };
- dr.Close();
- conn.Close();
- }
- }
- protected void MasterGridView_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- GridView oGridView = (GridView)e.Row.FindControl("DetailGridView");
- if (oGridView != null)
- {
- int step = 1;
- DataSet ds = new DataSet();
- DataTable dt = new DataTable();
- dt.Columns.Add(new DataColumn("form_id", typeof(string)));
- dt.Columns.Add(new DataColumn("apply_time", typeof(string)));
- dt.Columns.Add(new DataColumn("emp_name", typeof(string)));
- dt.Columns.Add(new DataColumn("eq_type", typeof(string)));
- dt.Columns.Add(new DataColumn("eq_detail", typeof(string)));
- dt.Columns.Add(new DataColumn("company", typeof(string)));
- dt.Columns.Add(new DataColumn("content", typeof(string)));
- dt.Columns.Add(new DataColumn("check_md", typeof(string)));
- dt.Columns.Add(new DataColumn("check_company", typeof(string)));
- dt.Columns.Add(new DataColumn("comment", typeof(string)));
- dt.Columns.Add(new DataColumn("check_time", typeof(string)));
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand sqlcom = new SqlCommand("select a.form_id as form_id,c.emp_name as emp_name,a.eq_type as eq_type,a.eq_detail as eq_detail,a.company as company,a.content as content from OA_REPAIR_FORM_DETAIL as a,OA_REPAIR_FORM as b,OA_EMPLOYEE as c where b.form_id=a.form_id and b.emp_id=c.id and a.department_id='" + MasterGridView.DataKeys[e.Row.RowIndex].Value.ToString()+"'", conn);
- SqlDataReader dr1 = sqlcom.ExecuteReader();
- if (dr1.HasRows)
- {
- while (dr1.Read())
- {
- DataRow row = dt.NewRow();
- row["form_id"] = dr1["form_id"].ToString();
- row["emp_name"] = dr1["emp_name"].ToString();
- row["eq_type"] = dr1["eq_type"].ToString();
- row["eq_detail"] = dr1["eq_detail"].ToString();
- row["company"] = dr1["company"].ToString();
- row["content"] = dr1["content"].ToString();
- row["apply_time"] = SetTime(dr1["form_id"].ToString());
- SqlConnection conn1 = dbConnection.getConnection();
- conn1.Open();
- SqlCommand sqlcom1 = new SqlCommand("select max(step) as step from OA_REPAIR_FLOW where form_id='" + dr1["form_id"].ToString() + "'", conn1);
- SqlDataReader dr4 = sqlcom1.ExecuteReader();
- if (dr4.HasRows)
- {
- while (dr4.Read())
- {
- if (!(dr4["step"].ToString().Equals("")))
- {
- step = Convert.ToInt32(dr4["step"]);
- }
- }
- }
- dr4.Close();
- SqlCommand sqlcom2 = new SqlCommand("select is_agree from OA_REPAIR_FLOW where form_id='" + dr1["form_id"].ToString() + "'and step=" + step, conn1);
- SqlDataReader dr2 = sqlcom2.ExecuteReader();
- if (dr2.HasRows)
- {
- while (dr2.Read())
- {
- if (dr2["is_agree"].ToString().Equals("Y"))
- {
- row["check_md"] = "已完工";
- }
- else if (dr2["is_agree"].ToString().Equals("N"))
- {
- row["check_md"] = "未处理";
- }
- else
- {
- row["check_md"] = "";
- }
- }
- }
- dr2.Close();
- SqlCommand sqlcom3 = new SqlCommand("select is_agree,comment,check_time from OA_COMPANY_CHECK where form_id='" + dr1["form_id"].ToString() + "' and company='" + dr1["company"].ToString() + "'", conn1);
- SqlDataReader dr3 = sqlcom3.ExecuteReader();
- if (dr3.HasRows)
- {
- while (dr3.Read())
- {
- if (dr3["is_agree"].ToString().Equals("Y"))
- {
- row["check_company"] = "已完工";
- }
- else if (dr3["is_agree"].ToString().Equals("N"))
- {
- row["check_company"] = "未处理";
- }
- else
- {
- row["check_company"] = "";
- }
- row["comment"] = dr3["comment"].ToString().Replace("/n", "<br>").ToString();
- row["check_time"] = SetTime(dr3["check_time"].ToString());
- }
- }
- dr3.Close();
- conn1.Close();
- dt.Rows.Add(row);
- }
- }
- dr1.Close();
- ds.Tables.Add(dt);
- oGridView.DataSource = ds;
- oGridView.DataBind();
- dr1.Close();
- conn.Close();
- }
- }
- }
- public string SetTime(string s)
- {
- string year = "";
- string month = "";
- string day = "";
- string hour = "";
- string minite = "";
- string second = "";
- if (s.Length == 14)
- {
- year = s.Substring(0, 4).ToString();
- month = s.Substring(4, 2).ToString();
- day = s.Substring(6, 2).ToString();
- hour = s.Substring(8, 2).ToString();
- minite = s.Substring(10, 2).ToString();
- second = s.Substring(12, 2).ToString();
- return year + "-" + month + "-" + day + " " + hour + ":" + minite + ":" + second;
- }
- else
- {
- return s;
- }
- }
- protected void btn_ok_Click(object sender, EventArgs e)
- {
- MultiView1.ActiveViewIndex = 1;
- DataSet ds = new DataSet();
- DataTable dt = new DataTable();
- dt.Columns.Add("id",typeof(Int32));
- dt.Columns.Add("name", typeof(string));
- dt.Columns.Add("num", typeof(Int32));
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- DataRow row = dt.NewRow();
- row["id"] = dl_company.SelectedValue.ToString();
- row["name"] = dl_company.SelectedItem.ToString();
- SqlCommand sqlcom = new SqlCommand("select count(*) as num from OA_REPAIR_FORM_DETAIL as a,OA_REPAIR_FORM as b,OA_EMPLOYEE as c where b.form_id=a.form_id and b.emp_id=c.id and a.department_id='" +dl_company.SelectedValue.ToString() + "' and (a.form_id between '" + b_time.Text + "' and '" + e_time.Text + "') and a.eq_detail='" + dl_name.SelectedValue.ToString() + "'", conn);
- SqlDataReader dr = sqlcom.ExecuteReader();
- if (dr.HasRows)
- {
- while (dr.Read())
- {
- row["num"] = Convert.ToInt32(dr["num"]);
- }
- }
- dt.Rows.Add(row);
- ds.Tables.Add(dt);
- GridView1.DataSource = ds;
- GridView1.DataBind();
- GridView1.DataKeyNames = new string[] { "id" };
- dr.Close();
- conn.Close();
- }
- protected void ShowMessageBox(string strMessage)
- {
- Response.Write(string.Format("<script>alert('{0}')</script>", strMessage));
- }
- protected void CalEnddate_SelectionChanged(object sender, EventArgs e)
- {
- CalEnddate.Visible = false;
- string year = CalEnddate.SelectedDate.Year.ToString();
- string month = CalEnddate.SelectedDate.Month.ToString();
- if (month.Length == 1)
- {
- month = "0" + month;
- }
- string day = CalEnddate.SelectedDate.Day.ToString();
- if (day.Length == 1)
- {
- day = "0" + day;
- }
- e_time.Text = year + month + day + "000000";
- e_time.Focus();
- }
- protected void CalBegindate_SelectionChanged(object sender, EventArgs e)
- {
- CalBegindate.Visible = false;
- string year = CalBegindate.SelectedDate.Year.ToString();
- string month = CalBegindate.SelectedDate.Month.ToString();
- if (month.Length == 1)
- {
- month = "0" + month;
- }
- string day = CalBegindate.SelectedDate.Day.ToString();
- if (day.Length == 1)
- {
- day = "0" + day;
- }
- b_time.Text = year + month + day + "000000";
- b_time.Focus();
- }
- protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
- {
- if (CalEnddate.Visible == true)
- {
- CalEnddate.Visible = false;
- CalEnddate.Focus();
- }
- else
- {
- CalEnddate.Visible = true;
- CalEnddate.Focus();
- }
- }
- protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
- {
- if (CalBegindate.Visible == true)
- {
- CalBegindate.Visible = false;
- CalBegindate.Focus();
- }
- else
- {
- CalBegindate.Visible = true;
- CalBegindate.Focus();
- }
- }
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- GridView oGridView = (GridView)e.Row.FindControl("DetailGridView");
- if (oGridView != null)
- {
- int step = 1;
- DataSet ds = new DataSet();
- DataTable dt = new DataTable();
- dt.Columns.Add(new DataColumn("form_id", typeof(string)));
- dt.Columns.Add(new DataColumn("apply_time", typeof(string)));
- dt.Columns.Add(new DataColumn("emp_name", typeof(string)));
- dt.Columns.Add(new DataColumn("eq_type", typeof(string)));
- dt.Columns.Add(new DataColumn("eq_detail", typeof(string)));
- dt.Columns.Add(new DataColumn("company", typeof(string)));
- dt.Columns.Add(new DataColumn("content", typeof(string)));
- dt.Columns.Add(new DataColumn("check_md", typeof(string)));
- dt.Columns.Add(new DataColumn("check_company", typeof(string)));
- dt.Columns.Add(new DataColumn("comment", typeof(string)));
- dt.Columns.Add(new DataColumn("check_time", typeof(string)));
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand sqlcom = new SqlCommand("select a.form_id as form_id,c.emp_name as emp_name,a.eq_type as eq_type,a.eq_detail as eq_detail,a.company as company,a.content as content from OA_REPAIR_FORM_DETAIL as a,OA_REPAIR_FORM as b,OA_EMPLOYEE as c where b.form_id=a.form_id and b.emp_id=c.id and a.department_id='" + GridView1.DataKeys[e.Row.RowIndex].Value.ToString() + "' and (a.form_id between '" + b_time.Text + "' and '" + e_time.Text + "') and a.eq_detail='" + dl_name.SelectedValue.ToString() + "'", conn);
- SqlDataReader dr1 = sqlcom.ExecuteReader();
- if (dr1.HasRows)
- {
- while (dr1.Read())
- {
- DataRow row = dt.NewRow();
- row["form_id"] = dr1["form_id"].ToString();
- row["emp_name"] = dr1["emp_name"].ToString();
- row["eq_type"] = dr1["eq_type"].ToString();
- row["eq_detail"] = dr1["eq_detail"].ToString();
- row["company"] = dr1["company"].ToString();
- row["content"] = dr1["content"].ToString();
- row["apply_time"] = SetTime(dr1["form_id"].ToString());
- SqlConnection conn1 = dbConnection.getConnection();
- conn1.Open();
- SqlCommand sqlcom1 = new SqlCommand("select max(step) as step from OA_REPAIR_FLOW where form_id='" + dr1["form_id"].ToString() + "'", conn1);
- SqlDataReader dr4 = sqlcom1.ExecuteReader();
- if (dr4.HasRows)
- {
- while (dr4.Read())
- {
- if (!(dr4["step"].ToString().Equals("")))
- {
- step = Convert.ToInt32(dr4["step"]);
- }
- }
- }
- dr4.Close();
- SqlCommand sqlcom2 = new SqlCommand("select is_agree from OA_REPAIR_FLOW where form_id='" + dr1["form_id"].ToString() + "'and step=" + step, conn1);
- SqlDataReader dr2 = sqlcom2.ExecuteReader();
- if (dr2.HasRows)
- {
- while (dr2.Read())
- {
- if (dr2["is_agree"].ToString().Equals("Y"))
- {
- row["check_md"] = "已完工";
- }
- else if (dr2["is_agree"].ToString().Equals("N"))
- {
- row["check_md"] = "未处理";
- }
- else
- {
- row["check_md"] = "";
- }
- }
- }
- dr2.Close();
- SqlCommand sqlcom3 = new SqlCommand("select is_agree,comment,check_time from OA_COMPANY_CHECK where form_id='" + dr1["form_id"].ToString() + "' and company='" + dr1["company"].ToString() + "'", conn1);
- SqlDataReader dr3 = sqlcom3.ExecuteReader();
- if (dr3.HasRows)
- {
- while (dr3.Read())
- {
- if (dr3["is_agree"].ToString().Equals("Y"))
- {
- row["check_company"] = "已完工";
- }
- else if (dr3["is_agree"].ToString().Equals("N"))
- {
- row["check_company"] = "未处理";
- }
- else
- {
- row["check_company"] = "";
- }
- row["comment"] = dr3["comment"].ToString().Replace("/n", "<br>").ToString();
- row["check_time"] = SetTime(dr3["check_time"].ToString());
- }
- }
- dr3.Close();
- conn1.Close();
- dt.Rows.Add(row);
- }
- }
- dr1.Close();
- ds.Tables.Add(dt);
- oGridView.DataSource = ds;
- oGridView.DataBind();
- dr1.Close();
- conn.Close();
- }
- }
- }
- }