Exam_GridViewNested.aspx.cs
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:18k
源码类别:

OA系统

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Configuration;
  5. using System.Collections;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11. public partial class web_data_repair_select_Exam_GridViewNested : System.Web.UI.Page
  12. {
  13.     protected void Page_Load(object sender, EventArgs e)
  14.     {
  15.     if (!Page.IsPostBack)
  16.     {
  17.         DataSet ds = new DataSet();
  18.         DataTable dt = new DataTable();
  19.         dt.Columns.Add("id", typeof(Int32));
  20.         dt.Columns.Add("name", typeof(string));
  21.         dt.Columns.Add("num", typeof(Int32));
  22.         SqlConnection conn = dbConnection.getConnection();
  23.         conn.Open();
  24.         SqlCommand sqlcom = new SqlCommand("SELECT id, name FROM OA_DEPARTMENT WHERE (CHARINDEX('店', name) > 0)", conn);
  25.         SqlDataReader dr = sqlcom.ExecuteReader();
  26.         if (dr.HasRows)
  27.         {
  28.             while (dr.Read())
  29.             {
  30.                 DataRow row = dt.NewRow();
  31.                 row["id"] = Convert.ToInt32(dr["id"]);
  32.                 row["name"] = Convert.ToString(dr["name"]);
  33.                 SqlConnection conn1 = dbConnection.getConnection();
  34.                 conn1.Open();
  35.                 SqlCommand sqlcom1 = new SqlCommand("select count(*) as num from OA_REPAIR_FORM_DETAIL where department_id="+Convert.ToInt32(dr["id"]),conn1);
  36.                 SqlDataReader dr1 = sqlcom1.ExecuteReader();
  37.                 if (dr1.HasRows)
  38.                 {
  39.                     while (dr1.Read())
  40.                     {
  41.                         row["num"] = Convert.ToInt32(dr1["num"]);
  42.                     }
  43.                 }
  44.                 dr1.Close();
  45.                 conn1.Close();
  46.                 dt.Rows.Add(row);
  47.             }
  48.         }
  49.         ds.Tables.Add(dt);
  50.       MasterGridView.DataSource = ds;
  51.       MasterGridView.DataBind();
  52.       MasterGridView.DataKeyNames = new string[] { "id" };
  53.       dr.Close();
  54.       conn.Close();
  55.     }
  56.   }
  57.   protected void MasterGridView_RowDataBound(object sender, GridViewRowEventArgs e)
  58.   {
  59.     if (e.Row.RowType == DataControlRowType.DataRow)
  60.     { 
  61.      
  62.      GridView oGridView = (GridView)e.Row.FindControl("DetailGridView");
  63.      if (oGridView != null)
  64.      {
  65.          int step = 1;
  66.          DataSet ds = new DataSet();
  67.          DataTable dt = new DataTable();
  68.          dt.Columns.Add(new DataColumn("form_id", typeof(string)));
  69.          dt.Columns.Add(new DataColumn("apply_time", typeof(string)));
  70.          dt.Columns.Add(new DataColumn("emp_name", typeof(string)));
  71.          dt.Columns.Add(new DataColumn("eq_type", typeof(string)));
  72.          dt.Columns.Add(new DataColumn("eq_detail", typeof(string)));
  73.          dt.Columns.Add(new DataColumn("company", typeof(string)));
  74.          dt.Columns.Add(new DataColumn("content", typeof(string)));
  75.          dt.Columns.Add(new DataColumn("check_md", typeof(string)));
  76.          dt.Columns.Add(new DataColumn("check_company", typeof(string)));
  77.          dt.Columns.Add(new DataColumn("comment", typeof(string)));
  78.          dt.Columns.Add(new DataColumn("check_time", typeof(string)));
  79.          SqlConnection conn = dbConnection.getConnection();
  80.          conn.Open();
  81.          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);
  82.          SqlDataReader dr1 = sqlcom.ExecuteReader();
  83.          if (dr1.HasRows)
  84.          {
  85.              while (dr1.Read())
  86.              {
  87.                  DataRow row = dt.NewRow();
  88.                  row["form_id"] = dr1["form_id"].ToString();
  89.                  row["emp_name"] = dr1["emp_name"].ToString();
  90.                  row["eq_type"] = dr1["eq_type"].ToString();
  91.                  row["eq_detail"] = dr1["eq_detail"].ToString();
  92.                  row["company"] = dr1["company"].ToString();
  93.                  row["content"] = dr1["content"].ToString();
  94.                  row["apply_time"] = SetTime(dr1["form_id"].ToString());
  95.                  SqlConnection conn1 = dbConnection.getConnection();
  96.                  conn1.Open();
  97.                  SqlCommand sqlcom1 = new SqlCommand("select max(step) as step from OA_REPAIR_FLOW where form_id='" + dr1["form_id"].ToString() + "'", conn1);
  98.                  SqlDataReader dr4 = sqlcom1.ExecuteReader();
  99.                  if (dr4.HasRows)
  100.                  {
  101.                      while (dr4.Read())
  102.                      {
  103.                          if (!(dr4["step"].ToString().Equals("")))
  104.                          {
  105.                              step = Convert.ToInt32(dr4["step"]);
  106.                          }
  107.                      }
  108.                  }
  109.                  dr4.Close();
  110.                  SqlCommand sqlcom2 = new SqlCommand("select is_agree from OA_REPAIR_FLOW where form_id='" + dr1["form_id"].ToString() + "'and step=" + step, conn1);
  111.                  SqlDataReader dr2 = sqlcom2.ExecuteReader();
  112.                  if (dr2.HasRows)
  113.                  {
  114.                      while (dr2.Read())
  115.                      {
  116.                          if (dr2["is_agree"].ToString().Equals("Y"))
  117.                          {
  118.                              row["check_md"] = "已完工";
  119.                          }
  120.                          else if (dr2["is_agree"].ToString().Equals("N"))
  121.                          {
  122.                              row["check_md"] = "未处理";
  123.                          }
  124.                          else
  125.                          {
  126.                              row["check_md"] = "";
  127.                          }
  128.                      }
  129.                  }
  130.                  dr2.Close();
  131.                  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);
  132.                  SqlDataReader dr3 = sqlcom3.ExecuteReader();
  133.                  if (dr3.HasRows)
  134.                  {
  135.                      while (dr3.Read())
  136.                      {
  137.                          if (dr3["is_agree"].ToString().Equals("Y"))
  138.                          {
  139.                              row["check_company"] = "已完工";
  140.                          }
  141.                          else if (dr3["is_agree"].ToString().Equals("N"))
  142.                          {
  143.                              row["check_company"] = "未处理";
  144.                          }
  145.                          else
  146.                          {
  147.                              row["check_company"] = "";
  148.                          }
  149.                          row["comment"] = dr3["comment"].ToString().Replace("/n", "<br>").ToString();
  150.                          row["check_time"] = SetTime(dr3["check_time"].ToString());
  151.                      }
  152.                  }
  153.                  dr3.Close();
  154.                  conn1.Close();
  155.                  dt.Rows.Add(row);
  156.              }
  157.          }
  158.          dr1.Close();
  159.          ds.Tables.Add(dt);
  160.        oGridView.DataSource = ds;
  161.        oGridView.DataBind();
  162.        dr1.Close();
  163.        conn.Close();
  164.      }
  165.     }
  166.   }
  167.     public string SetTime(string s)
  168.     {
  169.         string year = "";
  170.         string month = "";
  171.         string day = "";
  172.         string hour = "";
  173.         string minite = "";
  174.         string second = "";
  175.         if (s.Length == 14)
  176.         {
  177.             year = s.Substring(0, 4).ToString();
  178.             month = s.Substring(4, 2).ToString();
  179.             day = s.Substring(6, 2).ToString();
  180.             hour = s.Substring(8, 2).ToString();
  181.             minite = s.Substring(10, 2).ToString();
  182.             second = s.Substring(12, 2).ToString();
  183.             return year + "-" + month + "-" + day + " " + hour + ":" + minite + ":" + second;
  184.         }
  185.         else
  186.         {
  187.             return s;
  188.         }
  189.     }
  190.     protected void btn_ok_Click(object sender, EventArgs e)
  191.     {
  192.             MultiView1.ActiveViewIndex = 1;
  193.             DataSet ds = new DataSet();
  194.             DataTable dt = new DataTable();
  195.             dt.Columns.Add("id",typeof(Int32));
  196.             dt.Columns.Add("name", typeof(string));
  197.             dt.Columns.Add("num", typeof(Int32));
  198.             SqlConnection conn = dbConnection.getConnection();
  199.             conn.Open();
  200.             DataRow row = dt.NewRow();
  201.             row["id"] = dl_company.SelectedValue.ToString();
  202.             row["name"] = dl_company.SelectedItem.ToString();
  203.             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);
  204.             SqlDataReader dr = sqlcom.ExecuteReader();
  205.             if (dr.HasRows)
  206.             {
  207.                 while (dr.Read())
  208.                 {
  209.                     row["num"] = Convert.ToInt32(dr["num"]);
  210.                 }
  211.             }
  212.             dt.Rows.Add(row);
  213.             ds.Tables.Add(dt);
  214.             GridView1.DataSource = ds;
  215.             GridView1.DataBind();
  216.             GridView1.DataKeyNames = new string[] { "id" };
  217.             dr.Close();
  218.             conn.Close();
  219.     }
  220.     protected void ShowMessageBox(string strMessage)
  221.     {
  222.         Response.Write(string.Format("<script>alert('{0}')</script>", strMessage));
  223.     }
  224.     protected void CalEnddate_SelectionChanged(object sender, EventArgs e)
  225.     {
  226.         CalEnddate.Visible = false;
  227.         string year = CalEnddate.SelectedDate.Year.ToString();
  228.         string month = CalEnddate.SelectedDate.Month.ToString();
  229.         if (month.Length == 1)
  230.         {
  231.             month = "0" + month;
  232.         }
  233.         string day = CalEnddate.SelectedDate.Day.ToString();
  234.         if (day.Length == 1)
  235.         {
  236.             day = "0" + day;
  237.         }
  238.         e_time.Text = year + month + day + "000000";
  239.         e_time.Focus();
  240.     }
  241.     protected void CalBegindate_SelectionChanged(object sender, EventArgs e)
  242.     {
  243.         CalBegindate.Visible = false;
  244.         string year = CalBegindate.SelectedDate.Year.ToString();
  245.         string month = CalBegindate.SelectedDate.Month.ToString();
  246.         if (month.Length == 1)
  247.         {
  248.             month = "0" + month;
  249.         }
  250.         string day = CalBegindate.SelectedDate.Day.ToString();
  251.         if (day.Length == 1)
  252.         {
  253.             day = "0" + day;
  254.         }
  255.         b_time.Text = year + month + day + "000000";
  256.         b_time.Focus();
  257.     }
  258.     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  259.     {
  260.         if (CalEnddate.Visible == true)
  261.         {
  262.             CalEnddate.Visible = false;
  263.             CalEnddate.Focus();
  264.         }
  265.         else
  266.         {
  267.             CalEnddate.Visible = true;
  268.             CalEnddate.Focus();
  269.         }
  270.     }
  271.     protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
  272.     {
  273.         if (CalBegindate.Visible == true)
  274.         {
  275.             CalBegindate.Visible = false;
  276.             CalBegindate.Focus();
  277.         }
  278.         else
  279.         {
  280.             CalBegindate.Visible = true;
  281.             CalBegindate.Focus();
  282.         }
  283.     }
  284.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  285.     {
  286.         if (e.Row.RowType == DataControlRowType.DataRow)
  287.         {
  288.             GridView oGridView = (GridView)e.Row.FindControl("DetailGridView");
  289.             if (oGridView != null)
  290.             {
  291.                 int step = 1;
  292.                 DataSet ds = new DataSet();
  293.                 DataTable dt = new DataTable();
  294.                 dt.Columns.Add(new DataColumn("form_id", typeof(string)));
  295.                 dt.Columns.Add(new DataColumn("apply_time", typeof(string)));
  296.                 dt.Columns.Add(new DataColumn("emp_name", typeof(string)));
  297.                 dt.Columns.Add(new DataColumn("eq_type", typeof(string)));
  298.                 dt.Columns.Add(new DataColumn("eq_detail", typeof(string)));
  299.                 dt.Columns.Add(new DataColumn("company", typeof(string)));
  300.                 dt.Columns.Add(new DataColumn("content", typeof(string)));
  301.                 dt.Columns.Add(new DataColumn("check_md", typeof(string)));
  302.                 dt.Columns.Add(new DataColumn("check_company", typeof(string)));
  303.                 dt.Columns.Add(new DataColumn("comment", typeof(string)));
  304.                 dt.Columns.Add(new DataColumn("check_time", typeof(string)));
  305.                 SqlConnection conn = dbConnection.getConnection();
  306.                 conn.Open();
  307.                 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);
  308.                 SqlDataReader dr1 = sqlcom.ExecuteReader();
  309.                 if (dr1.HasRows)
  310.                 {
  311.                     while (dr1.Read())
  312.                     {
  313.                         DataRow row = dt.NewRow();
  314.                         row["form_id"] = dr1["form_id"].ToString();
  315.                         row["emp_name"] = dr1["emp_name"].ToString();
  316.                         row["eq_type"] = dr1["eq_type"].ToString();
  317.                         row["eq_detail"] = dr1["eq_detail"].ToString();
  318.                         row["company"] = dr1["company"].ToString();
  319.                         row["content"] = dr1["content"].ToString();
  320.                         row["apply_time"] = SetTime(dr1["form_id"].ToString());
  321.                         SqlConnection conn1 = dbConnection.getConnection();
  322.                         conn1.Open();
  323.                         SqlCommand sqlcom1 = new SqlCommand("select max(step) as step from OA_REPAIR_FLOW where form_id='" + dr1["form_id"].ToString() + "'", conn1);
  324.                         SqlDataReader dr4 = sqlcom1.ExecuteReader();
  325.                         if (dr4.HasRows)
  326.                         {
  327.                             while (dr4.Read())
  328.                             {
  329.                                 if (!(dr4["step"].ToString().Equals("")))
  330.                                 {
  331.                                     step = Convert.ToInt32(dr4["step"]);
  332.                                 }
  333.                             }
  334.                         }
  335.                         dr4.Close();
  336.                         SqlCommand sqlcom2 = new SqlCommand("select is_agree from OA_REPAIR_FLOW where form_id='" + dr1["form_id"].ToString() + "'and step=" + step, conn1);
  337.                         SqlDataReader dr2 = sqlcom2.ExecuteReader();
  338.                         if (dr2.HasRows)
  339.                         {
  340.                             while (dr2.Read())
  341.                             {
  342.                                 if (dr2["is_agree"].ToString().Equals("Y"))
  343.                                 {
  344.                                     row["check_md"] = "已完工";
  345.                                 }
  346.                                 else if (dr2["is_agree"].ToString().Equals("N"))
  347.                                 {
  348.                                     row["check_md"] = "未处理";
  349.                                 }
  350.                                 else
  351.                                 {
  352.                                     row["check_md"] = "";
  353.                                 }
  354.                             }
  355.                         }
  356.                         dr2.Close();
  357.                         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);
  358.                         SqlDataReader dr3 = sqlcom3.ExecuteReader();
  359.                         if (dr3.HasRows)
  360.                         {
  361.                             while (dr3.Read())
  362.                             {
  363.                                 if (dr3["is_agree"].ToString().Equals("Y"))
  364.                                 {
  365.                                     row["check_company"] = "已完工";
  366.                                 }
  367.                                 else if (dr3["is_agree"].ToString().Equals("N"))
  368.                                 {
  369.                                     row["check_company"] = "未处理";
  370.                                 }
  371.                                 else
  372.                                 {
  373.                                     row["check_company"] = "";
  374.                                 }
  375.                                 row["comment"] = dr3["comment"].ToString().Replace("/n", "<br>").ToString();
  376.                                 row["check_time"] = SetTime(dr3["check_time"].ToString());
  377.                             }
  378.                         }
  379.                         dr3.Close();
  380.                         conn1.Close();
  381.                         dt.Rows.Add(row);
  382.                     }
  383.                 }
  384.                 dr1.Close();
  385.                 ds.Tables.Add(dt);
  386.                 oGridView.DataSource = ds;
  387.                 oGridView.DataBind();
  388.                 dr1.Close();
  389.                 conn.Close();
  390.             }
  391.         }
  392.     }
  393. }