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

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.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. public partial class web_data_repair : System.Web.UI.Page
  13. {
  14.     SqlCommand sqlcom;
  15.     protected void Page_Load(object sender, EventArgs e)
  16.     {
  17.         if (!IsPostBack)
  18.         {
  19.             //LoginDAO.CheckLogin(Session, Response, "../", 2);
  20.         int id = -1;
  21.         try
  22.         {
  23.             id = Convert.ToInt32(DropDownList1.SelectedValue);
  24.         }
  25.         catch
  26.         {
  27.         }
  28.         MultiView1.ActiveViewIndex = id;
  29.         if (id == 0)
  30.         {
  31.             bind1();
  32.         }
  33.         else if (id == 1)
  34.         {
  35.             bind2();
  36.         }
  37.         else if (id == 2)
  38.         {
  39.             bind3();
  40.         }
  41.         else if (id == 3)
  42.         {
  43.             bind4();
  44.         }
  45.         else
  46.         {
  47.         }
  48.         }
  49.     }
  50.     public void bind1()
  51.     {
  52.         Panel1.Visible = false;
  53.         int id = 1;
  54.         SqlConnection conn = dbConnection.getConnection();
  55.         conn.Open();
  56.         DataSet ds = new DataSet();
  57.         DataTable dt = new DataTable();
  58.         dt.Columns.Add(new DataColumn("編號", typeof(int)));
  59.         dt.Columns.Add(new DataColumn("公司名稱", typeof(string)));
  60.         dt.Columns.Add(new DataColumn("聯絡人", typeof(string)));
  61.         dt.Columns.Add(new DataColumn("手機號碼", typeof(string)));
  62.         dt.Columns.Add(new DataColumn("固定電話", typeof(string)));
  63.         dt.Columns.Add(new DataColumn("fax", typeof(string)));
  64.         dt.Columns.Add(new DataColumn("ID", typeof(int)));
  65.         SqlCommand sqlcom = new SqlCommand("select * from oa_company order by id", conn);
  66.         SqlDataReader comm = sqlcom.ExecuteReader();
  67.         if (comm.HasRows)
  68.         {
  69.             while (comm.Read())
  70.             {
  71.                 DataRow row = dt.NewRow();
  72.                 row["編號"] = id;
  73.                 row["公司名稱"] = comm["company"].ToString();
  74.                 row["聯絡人"] = comm["contact_person"].ToString();
  75.                 row["手機號碼"] = comm["mobile_tel"].ToString();
  76.                 row["固定電話"] = comm["phone"].ToString();
  77.                 row["fax"] = comm["fax"].ToString();
  78.                 row["ID"] = comm["id"].ToString();
  79.                 id = id + 1;
  80.                 dt.Rows.Add(row);
  81.             }
  82.         }
  83.         else
  84.         {
  85.             Panel1.Visible = true;
  86.         }
  87.         ds.Tables.Add(dt);
  88.         GridView1.DataSource = ds;
  89.         GridView1.DataKeyNames = new string[] { "ID" };
  90.         GridView1.DataBind();
  91.         comm.Close();
  92.         conn.Close();
  93.         set1();
  94.     }   
  95.     public void set1()
  96.     {
  97.         DropDownList dll;
  98.         string str = "";
  99.         SqlConnection conn = dbConnection.getConnection();
  100.         conn.Open();
  101.         for (int i = 0; i < GridView1.Rows.Count; i++)
  102.         {
  103.             dll = (DropDownList)(GridView1.Rows[i].FindControl("dl"));
  104.             SqlCommand sqlcom = new SqlCommand("select equipment from OA_COMPANY where id='" + GridView1.DataKeys[i].Value.ToString() + "'", conn);
  105.             str = sqlcom.ExecuteScalar().ToString();
  106.             for (int j = 0; j < dll.Items.Count; j++)
  107.             {
  108.                 if (dll.Items[j].Text.ToString().Equals(str))
  109.                 {
  110.                     dll.SelectedIndex = j;
  111.                     break;
  112.                 }
  113.             }
  114.         }
  115.         conn.Close();
  116.     }
  117.     public void bind2()
  118.     {
  119.         Panel2.Visible = false;
  120.         int id = 1;
  121.         SqlConnection conn = dbConnection.getConnection();
  122.         conn.Open();
  123.         DataSet ds = new DataSet();
  124.         DataTable dt = new DataTable();
  125.         dt.Columns.Add(new DataColumn("no", typeof(int)));
  126.         dt.Columns.Add(new DataColumn("type", typeof(string)));
  127.         dt.Columns.Add(new DataColumn("ID", typeof(int)));
  128.         SqlCommand sqlcom = new SqlCommand("select id,type from OA_UNIT_TYPE", conn);
  129.         SqlDataReader dr = sqlcom.ExecuteReader();
  130.         if (dr.HasRows)
  131.         {
  132.             while (dr.Read())
  133.             {
  134.                 DataRow row = dt.NewRow();
  135.                 row["no"] = id;
  136.                 row["type"] = dr["type"].ToString();
  137.                 row["ID"] = dr["id"].ToString();
  138.                 dt.Rows.Add(row);
  139.                 id = id + 1;
  140.             }
  141.         }
  142.         else
  143.         {
  144.             Panel2.Visible = true;
  145.         }
  146.         ds.Tables.Add(dt);
  147.         GridView2.DataSource = ds;
  148.         GridView2.DataKeyNames = new string[] { "ID" };
  149.         GridView2.DataBind();
  150.         dr.Close();
  151.         conn.Close();
  152.     }
  153.     public void bind3()
  154.     {
  155.         Panel3.Visible = false;
  156.         SqlConnection conn = dbConnection.getConnection();
  157.         conn.Open();
  158.         DataSet ds = new DataSet();
  159.         DataTable dt = new DataTable();
  160.         dt.Columns.Add(new DataColumn("ID", typeof(int)));
  161.         dt.Columns.Add(new DataColumn("設備名稱", typeof(string)));
  162.         SqlCommand sqlcom = new SqlCommand("select * from OA_UNIT_DETAIL order by id", conn);
  163.         SqlDataReader dr = sqlcom.ExecuteReader();
  164.         if (dr.HasRows)
  165.         {
  166.             while (dr.Read())
  167.             {
  168.                 DataRow row = dt.NewRow();
  169.                 row["ID"] = dr["id"].ToString();
  170.                 row["設備名稱"] = dr["eq_name"].ToString();
  171.                 dt.Rows.Add(row);
  172.             }
  173.         }
  174.         else
  175.         {
  176.             Panel3.Visible = true;
  177.         }
  178.         ds.Tables.Add(dt);
  179.         GridView3.DataSource = ds;
  180.         GridView3.DataKeyNames = new string[] { "ID" };
  181.         GridView3.DataBind();
  182.         dr.Close();
  183.         conn.Close();
  184.         set2();
  185.     }
  186.     public void set2()
  187.     {
  188.         DropDownList dll;
  189.         string str = "";
  190.         SqlConnection conn = dbConnection.getConnection();
  191.         conn.Open();
  192.         for (int i = 0; i < GridView3.Rows.Count; i++)
  193.         {
  194.             dll = (DropDownList)(GridView3.Rows[i].FindControl("dl"));
  195.             SqlCommand sqlcom = new SqlCommand("select eq_type from OA_UNIT_DETAIL where id='" + GridView3.DataKeys[i].Value.ToString() + "'", conn);
  196.             str = sqlcom.ExecuteScalar().ToString();
  197.             for (int j = 0; j < dll.Items.Count; j++)
  198.             {
  199.                 if (dll.Items[j].Text.ToString().Equals(str))
  200.                 {
  201.                     dll.SelectedIndex = j;
  202.                     break;
  203.                 }
  204.             }
  205.         }
  206.         conn.Close();
  207.     }
  208.     public void bind4()
  209.     {
  210.         Panel4.Visible = false;
  211.         SqlConnection conn = dbConnection.getConnection();
  212.         conn.Open();
  213.         DataSet ds = new DataSet();
  214.         DataTable dt = new DataTable();
  215.         dt.Columns.Add(new DataColumn("ID", typeof(int)));
  216.         dt.Columns.Add(new DataColumn("question", typeof(string)));
  217.         SqlCommand sqlcom = new SqlCommand("select * from OA_UNIT_QUESTION order by id", conn);
  218.         SqlDataReader dr = sqlcom.ExecuteReader();
  219.         if (dr.HasRows)
  220.         {
  221.             while (dr.Read())
  222.             {
  223.                 DataRow row = dt.NewRow();
  224.                 row["ID"] = dr["id"].ToString();
  225.                 row["question"] = dr["question"].ToString();
  226.                 dt.Rows.Add(row);
  227.             }
  228.         }
  229.         else
  230.         {
  231.             Panel4.Visible = true;
  232.         }
  233.         ds.Tables.Add(dt);
  234.         GridView4.DataSource = ds;
  235.         GridView4.DataKeyNames = new string[] { "ID" };
  236.         GridView4.DataBind();
  237.         dr.Close();
  238.         conn.Close();
  239.         set3();
  240.     }
  241.     public void set3()
  242.     {
  243.         DropDownList dll;
  244.         string str = "";
  245.         SqlConnection conn = dbConnection.getConnection();
  246.         conn.Open();
  247.         for (int i = 0; i < GridView4.Rows.Count; i++)
  248.         {
  249.             dll = (DropDownList)(GridView4.Rows[i].FindControl("dl"));
  250.             SqlCommand sqlcom = new SqlCommand("select equipment from OA_UNIT_QUESTION where id='" + GridView4.DataKeys[i].Value.ToString() + "'", conn);
  251.             str = sqlcom.ExecuteScalar().ToString();
  252.             for (int j = 0; j < dll.Items.Count; j++)
  253.             {
  254.                 if (dll.Items[j].Text.ToString().Equals(str))
  255.                 {
  256.                     dll.SelectedIndex = j;
  257.                     break;
  258.                 }
  259.             }
  260.         }
  261.         conn.Close();
  262.     }
  263.     protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  264.     {
  265.         GridView1.EditIndex = e.NewEditIndex;
  266.         bind1();
  267.     }
  268.     protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
  269.     {
  270.         int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
  271.         string sqlstr = "delete from oa_company where id=" + id ;
  272.         SqlConnection sqlcon=dbConnection.getConnection();
  273.         sqlcon.Open();
  274.         sqlcom = new SqlCommand(sqlstr, sqlcon);
  275.         sqlcom.ExecuteNonQuery();
  276.         sqlcon.Close();
  277.         bind1();
  278.     }
  279.     protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  280.     {
  281.             int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
  282.             DropDownList dll = (DropDownList)(GridView1.Rows[e.RowIndex].FindControl("dl"));
  283.             SqlConnection conn = dbConnection.getConnection();
  284.             conn.Open();
  285.             SqlCommand comm = new SqlCommand("update oa_company set company='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString() + "',contact_person='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString() + "',mobile_tel='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString() + "',phone='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString() + "',fax='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString() + "',equipment='" + dll.SelectedItem.Text.ToString() + "'where id='" + id + "'", conn);
  286.             comm.ExecuteNonQuery();
  287.             conn.Close();
  288.             GridView1.EditIndex = -1;
  289.             bind1();
  290.     }
  291.     protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  292.     {
  293.         GridView1.EditIndex = -1;
  294.         bind1();
  295.     }
  296.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  297.     {
  298.         int i;
  299.         //执行循环,保证每条数据都可以更新
  300.         for (i = -1; i < GridView1.Rows.Count; i++)
  301.         {
  302.             //首先判断是否是数据行
  303.             if (e.Row.RowType == DataControlRowType.DataRow)
  304.             {
  305.                 //当鼠标停留时更改背景色
  306.                 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
  307.                 //当鼠标移开时还原背景色
  308.                 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
  309.             }
  310.         }
  311.     }
  312.     protected void ApprovelList1_RowCreated(object sender, GridViewRowEventArgs e)
  313.     {
  314.         LinkButton lbRevoke = (LinkButton)e.Row.FindControl("LbRevoke1");
  315.         if (e.Row.RowType == DataControlRowType.DataRow)
  316.         {
  317.             lbRevoke.CommandArgument = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
  318.             lbRevoke.Click += new EventHandler(lbRevoke1_Click);
  319.         }
  320.     }
  321.     public void lbRevoke1_Click(object sender, EventArgs e)
  322.     {
  323.         Panel1.Visible = true;
  324.     }
  325.     protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
  326.     {
  327.         GridView2.EditIndex = e.NewEditIndex;
  328.         bind2();
  329.     }
  330.     protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
  331.     {
  332.         int id = Convert.ToInt32(GridView2.DataKeys[e.RowIndex].Value);
  333.         string sqlstr = "delete from OA_UNIT_TYPE where id=" + id ;
  334.         SqlConnection sqlcon=dbConnection.getConnection();
  335.         sqlcon.Open();
  336.         sqlcom = new SqlCommand(sqlstr, sqlcon);
  337.         sqlcom.ExecuteNonQuery();
  338.         sqlcon.Close();
  339.         bind2();
  340.     }
  341.     protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
  342.     {
  343.         try
  344.         {
  345.             int id = Convert.ToInt32(GridView2.DataKeys[e.RowIndex].Value);
  346.             SqlConnection conn = dbConnection.getConnection();
  347.             conn.Open();
  348.             SqlCommand comm = new SqlCommand("update OA_UNIT_TYPE set type='" + ((TextBox)(GridView2.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString() + "'where id='" + id + "'", conn);
  349.             comm.ExecuteNonQuery();
  350.             conn.Close();
  351.             GridView2.EditIndex = -1;
  352.             bind2();
  353.         }
  354.         catch (Exception ex)
  355.         {
  356.             ShowMessageBox(ex.Message.ToString());
  357.             //Response.Write(ex.Message);
  358.         }
  359.     }
  360.     protected void GridView2_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  361.     {
  362.         GridView2.EditIndex = -1;
  363.         bind2();
  364.     }
  365.     protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
  366.     {
  367.         int i;
  368.         //执行循环,保证每条数据都可以更新
  369.         for (i = -1; i < GridView2.Rows.Count; i++)
  370.         {
  371.             //首先判断是否是数据行
  372.             if (e.Row.RowType == DataControlRowType.DataRow)
  373.             {
  374.                 //当鼠标停留时更改背景色
  375.                 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
  376.                 //当鼠标移开时还原背景色
  377.                 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
  378.             }
  379.         }
  380.     }
  381.     protected void ApprovelList2_RowCreated(object sender, GridViewRowEventArgs e)
  382.     {
  383.         LinkButton lbRevoke = (LinkButton)e.Row.FindControl("LbRevoke2");
  384.         if (e.Row.RowType == DataControlRowType.DataRow)
  385.         {
  386.             lbRevoke.CommandArgument = GridView2.DataKeys[e.Row.RowIndex].Value.ToString();
  387.             lbRevoke.Click += new EventHandler(lbRevoke2_Click);
  388.         }
  389.     }
  390.     public void lbRevoke2_Click(object sender, EventArgs e)
  391.     {
  392.         Panel2.Visible = true;
  393.     }
  394.     protected void GridView3_RowEditing(object sender, GridViewEditEventArgs e)
  395.     {
  396.         GridView3.EditIndex = e.NewEditIndex;
  397.         bind3();
  398.     }
  399.     protected void GridView3_RowDeleting(object sender, GridViewDeleteEventArgs e)
  400.     {
  401.         int id = Convert.ToInt32(GridView3.DataKeys[e.RowIndex].Value);
  402.         string sqlstr = "delete from OA_UNIT_DETAIL where id='" + id + "'";
  403.         SqlConnection sqlcon=dbConnection.getConnection();
  404.         sqlcon.Open();
  405.         sqlcom = new SqlCommand(sqlstr, sqlcon);
  406.         sqlcom.ExecuteNonQuery();
  407.         sqlcon.Close();
  408.         bind3();
  409.     }
  410.     protected void GridView3_RowUpdating(object sender, GridViewUpdateEventArgs e)
  411.     {
  412.         try
  413.         {
  414.             DropDownList dll = (DropDownList)(GridView3.Rows[e.RowIndex].FindControl("dl"));
  415.             int id = Convert.ToInt32(GridView3.DataKeys[e.RowIndex].Value);
  416.             SqlConnection conn = dbConnection.getConnection();
  417.             conn.Open();
  418.             SqlCommand comm = new SqlCommand("update OA_UNIT_DETAIL set eq_name='" + ((TextBox)(GridView3.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString() + "',eq_type='" + dll.SelectedValue.ToString() + "'where id='" + id + "'", conn);
  419.             comm.ExecuteNonQuery();
  420.             conn.Close();
  421.             GridView3.EditIndex = -1;
  422.             bind3();
  423.         }
  424.         catch (Exception ex)
  425.         {
  426.             ShowMessageBox(ex.Message.ToString());
  427.             //Response.Write(ex.Message);
  428.         }
  429.     }
  430.     protected void GridView3_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  431.     {
  432.         GridView3.EditIndex = -1;
  433.         bind3();
  434.     }
  435.     protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
  436.     {
  437.         int i;
  438.         //执行循环,保证每条数据都可以更新
  439.         for (i = -1; i < GridView3.Rows.Count; i++)
  440.         {
  441.             //首先判断是否是数据行
  442.             if (e.Row.RowType == DataControlRowType.DataRow)
  443.             {
  444.                 //当鼠标停留时更改背景色
  445.                 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
  446.                 //当鼠标移开时还原背景色
  447.                 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
  448.             }
  449.         }
  450.     }
  451.     protected void ApprovelList3_RowCreated(object sender, GridViewRowEventArgs e)
  452.     {
  453.         LinkButton lbRevoke = (LinkButton)e.Row.FindControl("LbRevoke3");
  454.         if (e.Row.RowType == DataControlRowType.DataRow)
  455.         {
  456.             lbRevoke.CommandArgument = GridView3.DataKeys[e.Row.RowIndex].Value.ToString();
  457.             lbRevoke.Click += new EventHandler(lbRevoke3_Click);
  458.         }
  459.     }
  460.     public void lbRevoke3_Click(object sender, EventArgs e)
  461.     {
  462.         Panel3.Visible = true;
  463.     }
  464.     protected void GridView4_RowEditing(object sender, GridViewEditEventArgs e)
  465.     {
  466.         GridView4.EditIndex = e.NewEditIndex;
  467.         bind4();
  468.     }
  469.     protected void GridView4_RowDeleting(object sender, GridViewDeleteEventArgs e)
  470.     {
  471.         int id = Convert.ToInt32(GridView4.DataKeys[e.RowIndex].Value);
  472.         string sqlstr = "delete from OA_UNIT_QUESTION where id='" + id + "'";
  473.         SqlConnection sqlcon = dbConnection.getConnection();
  474.         sqlcon.Open();
  475.         sqlcom = new SqlCommand(sqlstr, sqlcon);
  476.         sqlcom.ExecuteNonQuery();
  477.         sqlcon.Close();
  478.         bind4();
  479.     }
  480.     protected void GridView4_RowUpdating(object sender, GridViewUpdateEventArgs e)
  481.     {
  482.         try
  483.         {
  484.             DropDownList dll = (DropDownList)(GridView4.Rows[e.RowIndex].FindControl("dl"));
  485.             int id = Convert.ToInt32(GridView4.DataKeys[e.RowIndex].Value);
  486.             SqlConnection conn = dbConnection.getConnection();
  487.             conn.Open();
  488.             SqlCommand comm = new SqlCommand("update OA_UNIT_QUESTION set question='" + ((TextBox)(GridView4.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString() + "',equipment='" + dll.SelectedValue.ToString() + "'where id='" + id + "'", conn);
  489.             comm.ExecuteNonQuery();
  490.             conn.Close();
  491.             GridView4.EditIndex = -1;
  492.             bind4();
  493.         }
  494.         catch (Exception ex)
  495.         {
  496.             ShowMessageBox(ex.Message.ToString());
  497.         }
  498.     }
  499.     protected void GridView4_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  500.     {
  501.         GridView4.EditIndex = -1;
  502.         bind4();
  503.     }
  504.     protected void GridView4_RowDataBound(object sender, GridViewRowEventArgs e)
  505.     {
  506.         int i;
  507.         //执行循环,保证每条数据都可以更新
  508.         for (i = -1; i < GridView4.Rows.Count; i++)
  509.         {
  510.             //首先判断是否是数据行
  511.             if (e.Row.RowType == DataControlRowType.DataRow)
  512.             {
  513.                 //当鼠标停留时更改背景色
  514.                 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
  515.                 //当鼠标移开时还原背景色
  516.                 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
  517.             }
  518.         }
  519.     }
  520.     protected void ApprovelList4_RowCreated(object sender, GridViewRowEventArgs e)
  521.     {
  522.         LinkButton lbRevoke = (LinkButton)e.Row.FindControl("LbRevoke4");
  523.         if (e.Row.RowType == DataControlRowType.DataRow)
  524.         {
  525.             lbRevoke.CommandArgument = GridView4.DataKeys[e.Row.RowIndex].Value.ToString();
  526.             lbRevoke.Click += new EventHandler(lbRevoke4_Click);
  527.         }
  528.     }
  529.     public void lbRevoke4_Click(object sender, EventArgs e)
  530.     {
  531.         Panel4.Visible = true;
  532.     }
  533.     protected void Btview1_Click(object sender, EventArgs e)
  534.     {
  535.         int id = 1;
  536.         SqlConnection conn = dbConnection.getConnection();
  537.         conn.Open();
  538.         SqlCommand sqlcom = new SqlCommand("select max(id) from oa_company", conn);
  539.         try
  540.         {
  541.             id = Convert.ToInt32(sqlcom.ExecuteScalar()) + 1;
  542.         }
  543.         catch
  544.         {
  545.         }
  546.         if (!company.Text.Equals(""))
  547.         {
  548.             if (!equipment.SelectedItem.Text.ToString().Equals(""))
  549.             {
  550.                 SqlCommand comm = new SqlCommand("insert into oa_company(id,company,contact_person,mobile_tel,phone,fax,equipment)values('" + id + "','" + company.Text.ToString() + "','" + person.Text.ToString() + "','" + mobile.Text.ToString() + "','" + tel.Text.ToString() + "','" + fax.Text.ToString() + "','" + equipment.SelectedItem.Text.ToString() + "')", conn);
  551.                 comm.ExecuteNonQuery();
  552.                 conn.Close();
  553.             }
  554.             else
  555.             {
  556.                 ShowMessageBox("請選擇該公司所維修的設備類型");
  557.             }
  558.         }
  559.         else
  560.         {
  561.             ShowMessageBox("請輸入公司名稱");
  562.         }
  563.         bind1();
  564.     }
  565.     protected void Btview2_Click(object sender, EventArgs e)
  566.     {
  567.         int id = 1;
  568.         SqlConnection conn = dbConnection.getConnection();
  569.         conn.Open();
  570.         SqlCommand sqlcom = new SqlCommand("select max(id) from OA_UNIT_TYPE", conn);
  571.         try
  572.         {
  573.             id = Convert.ToInt32(sqlcom.ExecuteScalar()) + 1;
  574.         }
  575.         catch
  576.         {
  577.         }
  578.         if (!txttype.Text.Equals(""))
  579.         {
  580.             SqlCommand comm = new SqlCommand("insert into OA_UNIT_TYPE(id,type)values('" + id + "','" + txttype.Text.ToString() + "')", conn);
  581.             comm.ExecuteNonQuery();
  582.             conn.Close();
  583.         }
  584.         else
  585.         {
  586.             ShowMessageBox("請輸入設備名稱");
  587.         }
  588.         bind2();
  589.     }
  590.     protected void Btview3_Click(object sender, EventArgs e)
  591.     {
  592.         int id = 1;
  593.         SqlConnection conn = dbConnection.getConnection();
  594.         conn.Open();
  595.         SqlCommand sqlcom = new SqlCommand("select max(id) from OA_UNIT_DETAIL", conn);
  596.         try
  597.         {
  598.             id = Convert.ToInt32(sqlcom.ExecuteScalar()) + 1;
  599.         }
  600.         catch
  601.         {
  602.         }
  603.         if (!txt.Text.Equals(""))
  604.         {
  605.             SqlCommand comm = new SqlCommand("insert into OA_UNIT_DETAIL(id,eq_name,eq_type)values('" + id + "','" + txt.Text.ToString() + "','" + dltype.SelectedValue.ToString() + "')", conn);
  606.             comm.ExecuteNonQuery();
  607.             conn.Close();
  608.         }
  609.         else
  610.         {
  611.             ShowMessageBox("請輸入設備名稱");
  612.         }
  613.         bind3();
  614.     }
  615.     protected void Btview4_Click(object sender, EventArgs e)
  616.     {
  617.         int id = 1;
  618.         SqlConnection conn = dbConnection.getConnection();
  619.         conn.Open();
  620.         SqlCommand sqlcom = new SqlCommand("select max(id) from OA_UNIT_QUESTION", conn);
  621.         try
  622.         {
  623.             id = Convert.ToInt32(sqlcom.ExecuteScalar()) + 1;
  624.         }
  625.         catch
  626.         {
  627.         }
  628.         if (!txt1.Text.Equals(""))
  629.         {
  630.             SqlCommand comm = new SqlCommand("insert into OA_UNIT_QUESTION(id,question,equipment)values('" + id + "','" + txt1.Text.ToString() + "','" + type.SelectedValue.ToString() + "')", conn);
  631.             comm.ExecuteNonQuery();
  632.             conn.Close();
  633.         }
  634.         else
  635.         {
  636.             ShowMessageBox("請輸入設備名稱");
  637.         }
  638.         bind4();
  639.     }
  640.     protected void ShowMessageBox(string strMessage)
  641.     {
  642.         Response.Write(string.Format("<script>alert('{0}')</script>", strMessage));
  643.     }
  644.     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  645.     {
  646.         int id = -1;
  647.         try
  648.         {
  649.             id = Convert.ToInt32(DropDownList1.SelectedValue);
  650.         }
  651.         catch
  652.         {
  653.         }
  654.         MultiView1.ActiveViewIndex = id;
  655.         if (id == 0)
  656.         {
  657.             bind1();
  658.         }
  659.         else if (id == 1)
  660.         {
  661.             bind2();
  662.         }
  663.         else if (id == 2)
  664.         {
  665.             bind3();
  666.         }
  667.         else if (id == 3)
  668.         {
  669.             bind4();
  670.         }
  671.         else
  672.         {
  673.         }
  674.     }
  675. }