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

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_Company_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("company", typeof(string));
  21.             dt.Columns.Add("num", typeof(Int32));
  22.             SqlConnection conn = dbConnection.getConnection();
  23.             conn.Open();
  24.             SqlCommand sqlcom = new SqlCommand("SELECT id, company,equipment FROM OA_COMPANY order by id", 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["company"] = dr["company"].ToString();
  33.                     SqlConnection conn1 = dbConnection.getConnection();
  34.                     conn1.Open();
  35.                     SqlCommand sqlcom1 = new SqlCommand("select count(*) as num from OA_REPAIR_FORM_DETAIL where company='" + dr["company"].ToString() + "'", 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.                     dt.Rows.Add(row);
  45.                     dr1.Close();
  46.                     conn1.Close();
  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.             GridView oGridView = (GridView)e.Row.FindControl("DetailGridView");
  62.             if (oGridView != null)
  63.             {
  64.                 int step = 1;
  65.                 string str="";
  66.                 DataSet ds = new DataSet();
  67.                 DataTable dt = new DataTable();
  68.                 dt.Columns.Add(new DataColumn("department", typeof(string)));
  69.                 dt.Columns.Add(new DataColumn("form_id", typeof(string)));
  70.                 dt.Columns.Add(new DataColumn("apply_time", typeof(string)));
  71.                 dt.Columns.Add(new DataColumn("emp_name", typeof(string)));
  72.                 dt.Columns.Add(new DataColumn("eq_type", typeof(string)));
  73.                 dt.Columns.Add(new DataColumn("eq_detail", 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.                     str = "select a.department_id as department_id, 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,OA_COMPANY as d where b.form_id=a.form_id and b.emp_id=c.id and a.company=d.company and d.id='" + MasterGridView.DataKeys[e.Row.RowIndex].Value.ToString() + "'"; 
  82.                 SqlCommand sqlcom = new SqlCommand(str, conn);
  83.                 SqlDataReader dr1 = sqlcom.ExecuteReader();
  84.                 if (dr1.HasRows)
  85.                 {
  86.                     while (dr1.Read())
  87.                     {
  88.                         DataRow row = dt.NewRow();
  89.                         row["form_id"] = dr1["form_id"].ToString();
  90.                         row["emp_name"] = dr1["emp_name"].ToString();
  91.                         row["eq_type"] = dr1["eq_type"].ToString();
  92.                         row["eq_detail"] = dr1["eq_detail"].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.                         SqlCommand sqlcom4 = new SqlCommand("select name from OA_DEPARTMENT where id='" + dr1["department_id"].ToString() + "'", conn1);
  155.                         SqlDataReader dr5 = sqlcom4.ExecuteReader();
  156.                         if (dr5.HasRows)
  157.                         {
  158.                             while (dr5.Read())
  159.                             {
  160.                                 row["department"] = dr5["name"].ToString();
  161.                             }
  162.                         }
  163.                         conn1.Close();
  164.                         dt.Rows.Add(row);
  165.                     }
  166.                 }
  167.                 dr1.Close();
  168.                 ds.Tables.Add(dt);
  169.                 oGridView.DataSource = ds;
  170.                 oGridView.DataBind();
  171.                 dr1.Close();
  172.                 conn.Close();
  173.             }
  174.         }
  175.     }
  176.     public string SetTime(string s)
  177.     {
  178.         string year = "";
  179.         string month = "";
  180.         string day = "";
  181.         string hour = "";
  182.         string minite = "";
  183.         string second = "";
  184.         if (s.Length == 14)
  185.         {
  186.             year = s.Substring(0, 4).ToString();
  187.             month = s.Substring(4, 2).ToString();
  188.             day = s.Substring(6, 2).ToString();
  189.             hour = s.Substring(8, 2).ToString();
  190.             minite = s.Substring(10, 2).ToString();
  191.             second = s.Substring(12, 2).ToString();
  192.             return year + "-" + month + "-" + day + " " + hour + ":" + minite + ":" + second;
  193.         }
  194.         else
  195.         {
  196.             return s;
  197.         }
  198.     }
  199.     protected void ShowMessageBox(string strMessage)
  200.     {
  201.         Response.Write(string.Format("<script>alert('{0}')</script>", strMessage));
  202.     }
  203.     protected void CalEnddate_SelectionChanged(object sender, EventArgs e)
  204.     {
  205.         CalEnddate.Visible = false;
  206.         string year = CalEnddate.SelectedDate.Year.ToString();
  207.         string month = CalEnddate.SelectedDate.Month.ToString();
  208.         if (month.Length == 1)
  209.         {
  210.             month = "0" + month;
  211.         }
  212.         string day = CalEnddate.SelectedDate.Day.ToString();
  213.         if (day.Length == 1)
  214.         {
  215.             day = "0" + day;
  216.         }
  217.         e_time.Text = year + month + day + "000000";
  218.         e_time.Focus();
  219.     }
  220.     protected void CalBegindate_SelectionChanged(object sender, EventArgs e)
  221.     {
  222.         CalBegindate.Visible = false;
  223.         string year = CalBegindate.SelectedDate.Year.ToString();
  224.         string month = CalBegindate.SelectedDate.Month.ToString();
  225.         if (month.Length == 1)
  226.         {
  227.             month = "0" + month;
  228.         }
  229.         string day = CalBegindate.SelectedDate.Day.ToString();
  230.         if (day.Length == 1)
  231.         {
  232.             day = "0" + day;
  233.         }
  234.         b_time.Text = year + month + day + "000000";
  235.         b_time.Focus();
  236.     }
  237.     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  238.     {
  239.         if (CalEnddate.Visible == true)
  240.         {
  241.             CalEnddate.Visible = false;
  242.             CalEnddate.Focus();
  243.         }
  244.         else
  245.         {
  246.             CalEnddate.Visible = true;
  247.             CalEnddate.Focus();
  248.         }
  249.     }
  250.     protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
  251.     {
  252.         if (CalBegindate.Visible == true)
  253.         {
  254.             CalBegindate.Visible = false;
  255.             CalBegindate.Focus();
  256.         }
  257.         else
  258.         {
  259.             CalBegindate.Visible = true;
  260.             CalBegindate.Focus();
  261.         }
  262.     }
  263.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  264.     {
  265.         if (e.Row.RowType == DataControlRowType.DataRow)
  266.         {
  267.             GridView oGridView = (GridView)e.Row.FindControl("DetailGridView");
  268.             if (oGridView != null)
  269.             {
  270.                 int step = 1;
  271.                 string str = "";
  272.                 DataSet ds = new DataSet();
  273.                 DataTable dt = new DataTable();
  274.                 dt.Columns.Add(new DataColumn("department", typeof(string)));
  275.                 dt.Columns.Add(new DataColumn("form_id", typeof(string)));
  276.                 dt.Columns.Add(new DataColumn("apply_time", typeof(string)));
  277.                 dt.Columns.Add(new DataColumn("emp_name", typeof(string)));
  278.                 dt.Columns.Add(new DataColumn("eq_type", typeof(string)));
  279.                 dt.Columns.Add(new DataColumn("eq_detail", typeof(string)));
  280.                 dt.Columns.Add(new DataColumn("content", typeof(string)));
  281.                 dt.Columns.Add(new DataColumn("check_md", typeof(string)));
  282.                 dt.Columns.Add(new DataColumn("check_company", typeof(string)));
  283.                 dt.Columns.Add(new DataColumn("comment", typeof(string)));
  284.                 dt.Columns.Add(new DataColumn("check_time", typeof(string)));
  285.                 SqlConnection conn = dbConnection.getConnection();
  286.                 conn.Open();
  287.                 str = "select a.department_id as department_id, 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.company='" + 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() + "'";
  288.                 SqlCommand sqlcom = new SqlCommand(str, conn);
  289.                 SqlDataReader dr1 = sqlcom.ExecuteReader();
  290.                 if (dr1.HasRows)
  291.                 {
  292.                     while (dr1.Read())
  293.                     {
  294.                         DataRow row = dt.NewRow();
  295.                         row["form_id"] = dr1["form_id"].ToString();
  296.                         row["emp_name"] = dr1["emp_name"].ToString();
  297.                         row["eq_type"] = dr1["eq_type"].ToString();
  298.                         row["eq_detail"] = dr1["eq_detail"].ToString();
  299.                         row["content"] = dr1["content"].ToString();
  300.                         row["apply_time"] = SetTime(dr1["form_id"].ToString());
  301.                         SqlConnection conn1 = dbConnection.getConnection();
  302.                         conn1.Open();
  303.                         SqlCommand sqlcom1 = new SqlCommand("select max(step) as step from OA_REPAIR_FLOW where form_id='" + dr1["form_id"].ToString() + "'", conn1);
  304.                         SqlDataReader dr4 = sqlcom1.ExecuteReader();
  305.                         if (dr4.HasRows)
  306.                         {
  307.                             while (dr4.Read())
  308.                             {
  309.                                 if (!(dr4["step"].ToString().Equals("")))
  310.                                 {
  311.                                     step = Convert.ToInt32(dr4["step"]);
  312.                                 }
  313.                             }
  314.                         }
  315.                         dr4.Close();
  316.                         SqlCommand sqlcom2 = new SqlCommand("select is_agree from OA_REPAIR_FLOW where form_id='" + dr1["form_id"].ToString() + "'and step=" + step, conn1);
  317.                         SqlDataReader dr2 = sqlcom2.ExecuteReader();
  318.                         if (dr2.HasRows)
  319.                         {
  320.                             while (dr2.Read())
  321.                             {
  322.                                 if (dr2["is_agree"].ToString().Equals("Y"))
  323.                                 {
  324.                                     row["check_md"] = "已完工";
  325.                                 }
  326.                                 else if (dr2["is_agree"].ToString().Equals("N"))
  327.                                 {
  328.                                     row["check_md"] = "未处理";
  329.                                 }
  330.                                 else
  331.                                 {
  332.                                     row["check_md"] = "";
  333.                                 }
  334.                             }
  335.                         }
  336.                         dr2.Close();
  337.                         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);
  338.                         SqlDataReader dr3 = sqlcom3.ExecuteReader();
  339.                         if (dr3.HasRows)
  340.                         {
  341.                             while (dr3.Read())
  342.                             {
  343.                                 if (dr3["is_agree"].ToString().Equals("Y"))
  344.                                 {
  345.                                     row["check_company"] = "已完工";
  346.                                 }
  347.                                 else if (dr3["is_agree"].ToString().Equals("N"))
  348.                                 {
  349.                                     row["check_company"] = "未处理";
  350.                                 }
  351.                                 else
  352.                                 {
  353.                                     row["check_company"] = "";
  354.                                 }
  355.                                 row["comment"] = dr3["comment"].ToString().Replace("/n", "<br>").ToString();
  356.                                 row["check_time"] = SetTime(dr3["check_time"].ToString());
  357.                             }
  358.                         }
  359.                         dr3.Close();
  360.                         SqlCommand sqlcom4 = new SqlCommand("select name from OA_DEPARTMENT where id='" + dr1["department_id"].ToString() + "'", conn1);
  361.                         SqlDataReader dr5 = sqlcom4.ExecuteReader();
  362.                         if (dr5.HasRows)
  363.                         {
  364.                             while (dr5.Read())
  365.                             {
  366.                                 row["department"] = dr5["name"].ToString();
  367.                             }
  368.                         }
  369.                         conn1.Close();
  370.                         dt.Rows.Add(row);
  371.                     }
  372.                 }
  373.                 dr1.Close();
  374.                 ds.Tables.Add(dt);
  375.                 oGridView.DataSource = ds;
  376.                 oGridView.DataBind();
  377.                 dr1.Close();
  378.                 conn.Close();
  379.             }
  380.         }
  381.     }
  382.     protected void btn_ok_Click(object sender, EventArgs e)
  383.     {
  384.             MultiView1.ActiveViewIndex = 1;
  385.             DataSet ds = new DataSet();
  386.             DataTable dt = new DataTable();
  387.             dt.Columns.Add("id", typeof(Int32));
  388.             dt.Columns.Add("company", typeof(string));
  389.             dt.Columns.Add("num", typeof(Int32));
  390.             SqlConnection conn = dbConnection.getConnection();
  391.             conn.Open();
  392.             DataRow row = dt.NewRow();
  393.             SqlCommand sqlcom1 = new SqlCommand("select id from OA_COMPANY where company='" + dl_company.SelectedValue.ToString() + "'", conn);
  394.             SqlDataReader dr1 = sqlcom1.ExecuteReader();
  395.             if (dr1.HasRows)
  396.             {
  397.                 while (dr1.Read())
  398.                 {
  399.                     row["id"] = Convert.ToInt32(dr1["id"]);
  400.                 }
  401.             }
  402.             dr1.Close();
  403.             row["company"] = dl_company.SelectedValue.ToString();
  404.             string str = str = "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.company='" + dl_company.SelectedValue.ToString() + "' and (a.form_id between '" + b_time.Text + "' and '" + e_time.Text + "') and a.eq_detail='" + dl_name.SelectedValue.ToString() + "'";
  405.             SqlCommand sqlcom = new SqlCommand(str, conn);
  406.             SqlDataReader dr = sqlcom.ExecuteReader();
  407.             if (dr.HasRows)
  408.             {
  409.                 while (dr.Read())
  410.                 {
  411.                     row["num"] = Convert.ToInt32(dr["num"]);
  412.                 }
  413.             }
  414.             dt.Rows.Add(row);
  415.             ds.Tables.Add(dt);
  416.             GridView1.DataSource = ds;
  417.             GridView1.DataBind();
  418.             GridView1.DataKeyNames = new string[] { "company" };
  419.             dr.Close();
  420.             conn.Close();
  421.     }
  422. }