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

OA系统

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. public partial class web_approvel_ch_my_list : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)
  17.         {
  18.             LoginDAO.CheckLogin(Session, Response, "../../", 2);
  19.             ApprovelList.DataKeyNames = new string[] { "id" };
  20.             OffList.DataKeyNames = new string[] { "id" };
  21.             if (Request.QueryString["a_id"]!=null)
  22.             {
  23.                 PnlApprovel.Visible = true;
  24.                 PnlFlow.Visible = true;
  25.                 FlowList.DataKeyNames = new string[] { "id" };
  26.                 this.SetValue(Request.QueryString["a_id"]);
  27.             }
  28.             if (Request.QueryString["o_id"] != null)
  29.             {
  30.                 PnlOffFlow.Visible = true;
  31.                 PnlOffForm.Visible = true;
  32.                 OffFlowList.DataKeyNames = new string[] { "id" };
  33.                 this.SetOffValue(Request.QueryString["o_id"]);
  34.             }
  35.             if (Session["user"] != null)
  36.             {
  37.                 User user = (User)Session["user"];
  38.                 DepartmentId.Value = user.Department.Id.ToString();
  39.                 PositionId.Value = user.PositionId.ToString();
  40.             }
  41.         }
  42.     }
  43.     protected void SetValue(string id)
  44.     {
  45.         SqlConnection conn = dbConnection.getConnection();
  46.         conn.Open();
  47.         SqlCommand cmd = new SqlCommand("select a.form_id, e.emp_name, e.emp_no, p.name position, a.apply_date," +
  48.             "d.name department, a.days, a.begin_time, a.end_time, f1.name depart_place, f2.name arrive_place, " +
  49.             "a.depart_time, a.arrive_time, a.state from OA_CH_BUSINESS_FORM a inner join OA_EMPLOYEE e on a.emp_id=e.id " +
  50.             "inner join OA_DEPARTMENT d on a.department_id=d.id inner join OA_EMPLOYEE_POSITION p on " +
  51.             "e.position=p.id inner join OA_FLIGHT_PLACE f1 on a.depart_place=f1.id inner join " +
  52.             "OA_FLIGHT_PLACE f2 on a.arrive_place=f2.id where a.id=" + id, conn);
  53.         SqlDataReader dr = cmd.ExecuteReader();
  54.         int state = 0;
  55.         if (dr.Read())
  56.         {
  57.             TxtFormId.Text = dr["form_id"].ToString();
  58.             TxtEmpName.Text = dr["emp_name"].ToString();
  59.             TxtEmpNo.Text = dr["emp_no"].ToString();
  60.             TxtPosition.Text = dr["position"].ToString();
  61.             TxtApplyDate.Text = dr["apply_date"].ToString();
  62.             TxtDepartment.Text = dr["department"].ToString();
  63.             TxtDays.Text = dr["days"].ToString();
  64.             TxtBeginTime.Text = dr["begin_time"].ToString();
  65.             TxtEndTime.Text = dr["end_time"].ToString();
  66.             TxtDepartPlace.Text = dr["depart_place"].ToString();
  67.             TxtArrivePlace.Text = dr["arrive_place"].ToString();
  68.             TxtDepartTime.Text = dr["depart_time"].ToString();
  69.             TxtArriveTime.Text = dr["arrive_time"].ToString();
  70.             state = Convert.ToInt32(dr["state"].ToString());
  71.             State.Value = state.ToString();
  72.         }
  73.         dr.Close();
  74.         int flag = 0;
  75.         cmd = new SqlCommand("select number, company, subject, linkman, tel, place, visa_begin, visa_end, "+
  76.             "flight_go_begin, flight_back_end, is_aboard, remark from OA_CH_BUSINESS_DETAIL where form_id="+id+
  77.             " order by number", conn);
  78.         dr = cmd.ExecuteReader();
  79.         while (dr.Read())
  80.         {
  81.             flag = 1;
  82.             //動態創建表格行
  83.             TableRow tr1 = new TableRow();
  84.             TableCell td1 = new TableCell();
  85.             td1.BorderWidth = Unit.Pixel(1);
  86.             Label label = new Label();
  87.             label.BorderStyle = BorderStyle.None;
  88.             label.Text = dr["number"].ToString();
  89.             td1.Controls.Add(label);
  90.             tr1.Cells.Add(td1);
  91.             TableCell td2 = new TableCell();
  92.             td2.BorderWidth = Unit.Pixel(1);
  93.             label = new Label();
  94.             label.BorderStyle = BorderStyle.None;
  95.             label.Text = dr["company"].ToString();
  96.             td2.Controls.Add(label);
  97.             tr1.Cells.Add(td2);
  98.             TableCell td3 = new TableCell();
  99.             td3.BorderWidth = Unit.Pixel(1);
  100.             label = new Label();
  101.             label.BorderStyle = BorderStyle.None;
  102.             label.Text = dr["subject"].ToString();
  103.             td3.Controls.Add(label);
  104.             tr1.Cells.Add(td3);
  105.             TableCell td4 = new TableCell();
  106.             td4.BorderWidth = Unit.Pixel(1);
  107.             label = new Label();
  108.             label.BorderStyle = BorderStyle.None;
  109.             label.Text = dr["linkman"].ToString();
  110.             td4.Controls.Add(label);
  111.             tr1.Cells.Add(td4);
  112.             TableCell td5 = new TableCell();
  113.             td5.BorderWidth = Unit.Pixel(1);
  114.             label = new Label();
  115.             label.BorderStyle = BorderStyle.None;
  116.             label.Text = dr["tel"].ToString();
  117.             td5.Controls.Add(label);
  118.             tr1.Cells.Add(td5);
  119.             TableCell td6 = new TableCell();
  120.             td6.BorderWidth = Unit.Pixel(1);
  121.             label = new Label();
  122.             label.BorderStyle = BorderStyle.None;
  123.             label.Text = dr["place"].ToString();
  124.             td6.Controls.Add(label);
  125.             tr1.Cells.Add(td6);
  126.             TableCell td7 = new TableCell();
  127.             td7.BorderWidth = Unit.Pixel(1);
  128.             label = new Label();
  129.             label.BorderStyle = BorderStyle.None;
  130.             label.Text = dr["visa_begin"].ToString();
  131.             td7.Controls.Add(label);
  132.             tr1.Cells.Add(td7);
  133.             TableCell td8 = new TableCell();
  134.             td8.BorderWidth = Unit.Pixel(1);
  135.             label = new Label();
  136.             label.BorderStyle = BorderStyle.None;
  137.             label.Text = dr["visa_end"].ToString();
  138.             td8.Controls.Add(label);
  139.             tr1.Cells.Add(td8);
  140.             TableCell td9 = new TableCell();
  141.             td9.BorderWidth = Unit.Pixel(1);
  142.             label = new Label();
  143.             label.BorderStyle = BorderStyle.None;
  144.             label.Text = dr["flight_go_begin"].ToString();
  145.             td9.Controls.Add(label);
  146.             tr1.Cells.Add(td9);
  147.             TableCell td10 = new TableCell();
  148.             td10.BorderWidth = Unit.Pixel(1);
  149.             label = new Label();
  150.             label.BorderStyle = BorderStyle.None;
  151.             label.Text = dr["flight_back_end"].ToString();
  152.             td10.Controls.Add(label);
  153.             tr1.Cells.Add(td10);
  154.             TableCell td11 = new TableCell();
  155.             td11.BorderWidth = Unit.Pixel(1);
  156.             CheckBox chk = new CheckBox();
  157.             chk.Text = "國外";
  158.             chk.Enabled = false;
  159.             if (dr["is_aboard"].ToString().Equals("Y"))
  160.             {
  161.                 chk.Checked = true;
  162.             }
  163.             else
  164.             {
  165.                 chk.Checked = false;
  166.             }
  167.             td11.Controls.Add(chk);
  168.             tr1.Cells.Add(td11);
  169.             TableCell td12 = new TableCell();
  170.             td12.BorderWidth = Unit.Pixel(1);
  171.             label = new Label();
  172.             label.BorderStyle = BorderStyle.None;
  173.             label.Text = dr["remark"].ToString();
  174.             td12.Controls.Add(label);
  175.             tr1.Cells.Add(td12);
  176.             TblDetail.Rows.Add(tr1);
  177.         }
  178.         dr.Close();
  179.         conn.Close();
  180.         if (flag == 0)
  181.         {
  182.             TblDetail.Visible = false;
  183.         }
  184.         if (state != 1)
  185.         {
  186.             PnlFlow.Visible = false;
  187.             Panel1.Visible = true;
  188.         }
  189.     }
  190.     protected void SetOffValue(string id)
  191.     {
  192.         SqlConnection conn = dbConnection.getConnection();
  193.         conn.Open();
  194.         SqlCommand cmd = new SqlCommand("select o.form_id, e.emp_no, e.emp_name, d.name department, "+
  195.             "e.emp_name delegate, e.position position, o.state, "+
  196.             "t.name off_type, o.begin_time, o.end_time, o.hours, o.apply_date, o.parenthesis, "+
  197.             "o.reason from OA_CH_OFF_FORM o inner join OA_EMPLOYEE e on o.emp_id=e.id inner join "+
  198.             "OA_DEPARTMENT d on o.department_id=d.id inner join OA_CH_OFF_TYPE t on "+
  199.             "o.off_type=t.id where o.id="+id, conn);
  200.         SqlDataReader dr = cmd.ExecuteReader();
  201.         int state = 0;
  202.         if (dr.Read())
  203.         {
  204.             TxtOffFormId.Text = dr["form_id"].ToString();
  205.             TxtOffEmpName.Text = dr["emp_no"].ToString() + dr["emp_name"].ToString();
  206.             TxtOffDepartment.Text = dr["department"].ToString();
  207.             TxtDelegate.Text = dr["delegate"].ToString();
  208.             TxtOffPosition.Text = dr["position"].ToString();
  209.             TxtOffType2.Text = dr["off_type"].ToString();
  210.             TxtOffBeginTime.Text = dr["begin_time"].ToString();
  211.             TxtOffEndTime.Text = dr["end_time"].ToString();
  212.             TxtHours.Text = dr["hours"].ToString();
  213.             TxtOffApplyDate.Text = dr["apply_date"].ToString();
  214.             TxtParenthesis.Text = dr["parenthesis"].ToString();
  215.             TxtReason.Text = dr["reason"].ToString();
  216.             state = Convert.ToInt32(dr["state"].ToString());
  217.             State.Value = state.ToString();
  218.         }
  219.         dr.Close();
  220.         if (state != 1)
  221.         {
  222.             PnlOffFlow.Visible = false;
  223.             Panel2.Visible = true;
  224.         }
  225.         conn.Close();
  226.     }
  227.     protected void ApprovelList_RowDataBound(object sender, GridViewRowEventArgs e)
  228.     {
  229.         //行高亮
  230.         if (e.Row.RowType == DataControlRowType.DataRow)
  231.         {
  232.             e.Row.Attributes.Add("onmouseover", "this.style.cursor='pointer';");
  233.             e.Row.Attributes.Add("onclick", "location.href='my_list.aspx?a_id=" + ApprovelList.DataKeys[e.Row.RowIndex].Value.ToString() + "'");
  234.         }
  235.     }
  236.     protected void FlowList_RowCreated(object sender, GridViewRowEventArgs e)
  237.     {
  238.         if (e.Row.RowType == DataControlRowType.DataRow)
  239.         {
  240.             SqlConnection conn = dbConnection.getConnection();
  241.             conn.Open();
  242.             SqlCommand cmd = new SqlCommand("select apply_type, is_check, is_agree, comment from " +
  243.                 "OA_CH_APPROVEL_FORM_FLOW where id=" + FlowList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  244.             SqlDataReader dr = cmd.ExecuteReader();
  245.             if (dr.Read())
  246.             {
  247.                 Label label = (Label)e.Row.FindControl("LblApplyType");
  248.                 if (dr["apply_type"].ToString().Equals("1"))
  249.                 {
  250.                     label.Text = "會簽";
  251.                 }
  252.                 else
  253.                 {
  254.                     label.Text = "審批";
  255.                 }
  256.                 label = (Label)e.Row.FindControl("LblIsCheck");
  257.                 if (dr["is_check"].ToString().Equals("N"))
  258.                 {
  259.                     label.Text = "未處理";
  260.                 }
  261.                 else
  262.                 {
  263.                     label.Text = "已處理";
  264.                     label = (Label)e.Row.FindControl("LblIsAgree");
  265.                     if (dr["is_agree"].ToString().Equals("Y"))
  266.                     {
  267.                         label.Text = "已同意";
  268.                     }
  269.                     else
  270.                     {
  271.                         label.Text = "不同意";
  272.                     }
  273.                 }
  274.                 label = (Label)e.Row.FindControl("LblComment");
  275.                 label.Text = dr["comment"].ToString();
  276.             }
  277.             dr.Close();
  278.             conn.Close();
  279.         }
  280.     }
  281.     protected void OffList_RowDataBound(object sender, GridViewRowEventArgs e)
  282.     {
  283.         //行高亮
  284.         if (e.Row.RowType == DataControlRowType.DataRow)
  285.         {
  286.             e.Row.Attributes.Add("onmouseover", "this.style.cursor='pointer';");
  287.             e.Row.Attributes.Add("onclick", "location.href='my_list.aspx?o_id=" + OffList.DataKeys[e.Row.RowIndex].Value.ToString() + "'");
  288.         }
  289.     }
  290.     protected void OffFlowList_RowCreated(object sender, GridViewRowEventArgs e)
  291.     {
  292.         if (e.Row.RowType == DataControlRowType.DataRow)
  293.         {
  294.             SqlConnection conn = dbConnection.getConnection();
  295.             conn.Open();
  296.             SqlCommand cmd = new SqlCommand("select apply_type, is_check, is_agree, comment from " +
  297.                 "OA_CH_APPROVEL_FORM_FLOW where id=" + OffFlowList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  298.             SqlDataReader dr = cmd.ExecuteReader();
  299.             if (dr.Read())
  300.             {
  301.                 Label label = (Label)e.Row.FindControl("LblApplyType");
  302.                 if (dr["apply_type"].ToString().Equals("1"))
  303.                 {
  304.                     label.Text = "會簽";
  305.                 }
  306.                 else
  307.                 {
  308.                     label.Text = "審批";
  309.                 }
  310.                 label = (Label)e.Row.FindControl("LblIsCheck");
  311.                 if (dr["is_check"].ToString().Equals("N"))
  312.                 {
  313.                     label.Text = "未處理";
  314.                 }
  315.                 else
  316.                 {
  317.                     label.Text = "已處理";
  318.                     label = (Label)e.Row.FindControl("LblIsAgree");
  319.                     if (dr["is_agree"].ToString().Equals("Y"))
  320.                     {
  321.                         label.Text = "已同意";
  322.                     }
  323.                     else
  324.                     {
  325.                         label.Text = "不同意";
  326.                     }
  327.                 }
  328.                 label = (Label)e.Row.FindControl("LblComment");
  329.                 label.Text = dr["comment"].ToString();
  330.             }
  331.             dr.Close();
  332.             conn.Close();
  333.         }
  334.     }
  335.     protected void BtnOk_Click(object sender, EventArgs e)
  336.     {
  337.         if (Request.QueryString["a_id"] != null)
  338.         {
  339.             string id = Request.QueryString["a_id"];
  340.             SqlConnection conn = dbConnection.getConnection();
  341.             conn.Open();
  342.             if (State.Value.Equals("2"))
  343.             {
  344.                 SqlTransaction tx = conn.BeginTransaction();
  345.                 try
  346.                 {
  347.                     SqlCommand cmd = new SqlCommand("update OA_CH_BUSINESS_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  348.                     cmd.Transaction = tx;
  349.                     cmd.ExecuteNonQuery();
  350.                     //添加流程
  351.                     int flow_id = 1;
  352.                     cmd = new SqlCommand("select max(id) from OA_CH_APPROVEL_FORM_FLOW", conn);
  353.                     cmd.Transaction = tx;
  354.                     try
  355.                     {
  356.                         flow_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  357.                     }
  358.                     catch { }
  359.                     ArrayList main_ids = new ArrayList();
  360.                     cmd = new SqlCommand("select id from OA_FLOW_MAIN where department_id=" + DepartmentId.Value, conn);
  361.                     cmd.Transaction = tx;
  362.                     SqlDataReader dr = cmd.ExecuteReader();
  363.                     while (dr.Read())
  364.                     {
  365.                         main_ids.Add(dr["id"].ToString());
  366.                     }
  367.                     dr.Close();
  368.                     int flag = 0;
  369.                     int main_id = 0;
  370.                     for (int i = 0; i < main_ids.Count; i++)
  371.                     {
  372.                         cmd = new SqlCommand("select position_id from OA_FLOW_POSITION where main_id=" + main_ids[i], conn);
  373.                         cmd.Transaction = tx;
  374.                         dr = cmd.ExecuteReader();
  375.                         while (dr.Read())
  376.                         {
  377.                             if (dr["position_id"].ToString().Equals(PositionId.Value))
  378.                             {
  379.                                 flag = 1;
  380.                                 main_id = Convert.ToInt32(main_ids[i]);
  381.                             }
  382.                         }
  383.                         dr.Close();
  384.                         if (flag == 1)
  385.                         {
  386.                             break;
  387.                         }
  388.                     }
  389.                     if (main_id != 0)
  390.                     {
  391.                         ArrayList operator_ids = new ArrayList();
  392.                         cmd = new SqlCommand("select operator_id from OA_FLOW_DETAIL where main_id=" + main_id +
  393.                             " order by number", conn);
  394.                         cmd.Transaction = tx;
  395.                         dr = cmd.ExecuteReader();
  396.                         while (dr.Read())
  397.                         {
  398.                             operator_ids.Add(dr["operator_id"].ToString());
  399.                         }
  400.                         dr.Close();
  401.                         for (int i = 0; i < operator_ids.Count; i++)
  402.                         {
  403.                             cmd = new SqlCommand("insert into OA_CH_APPROVEL_FORM_FLOW(id, form_id, operator_id, " +
  404.                                 "apply_type, is_check, is_agree, comment, check_date, step, is_business)values(" +
  405.                                 flow_id + ", " + id + "," + operator_ids[i] + ",2,'N','N','',''," + (i + 1) + ",'Y')", conn);
  406.                             cmd.Transaction = tx;
  407.                             cmd.ExecuteNonQuery();
  408.                             flow_id++;
  409.                         }
  410.                         tx.Commit();
  411.                         Response.Redirect("my_list.aspx");
  412.                     }
  413.                     else
  414.                     {
  415.                         LblError.Text = "沒有找到相關處理流程, 請與管理員聯繫";
  416.                         tx.Rollback();
  417.                     }
  418.                 }
  419.                 catch (Exception ex)
  420.                 {
  421.                     Response.Write(ex.Message);
  422.                     tx.Rollback();
  423.                 }
  424.             }
  425.             else
  426.             {
  427.                 SqlCommand cmd = new SqlCommand("update OA_CH_BUSINESS_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  428.                 cmd.ExecuteNonQuery();
  429.             }
  430.             conn.Close();
  431.             Response.Redirect("my_list.aspx");
  432.         }
  433.     }
  434.     protected void BtnOk2_Click(object sender, EventArgs e)
  435.     {
  436.         if (Request.QueryString["o_id"] != null)
  437.         {
  438.             string id = Request.QueryString["o_id"];
  439.             SqlConnection conn = dbConnection.getConnection();
  440.             conn.Open();
  441.             if (State.Value.Equals("2"))
  442.             {
  443.                 SqlTransaction tx = conn.BeginTransaction();
  444.                 try
  445.                 {
  446.                     SqlCommand cmd = new SqlCommand("update OA_CH_OFF_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  447.                     cmd.Transaction = tx;
  448.                     cmd.ExecuteNonQuery();
  449.                     //添加流程
  450.                     int flow_id = 1;
  451.                     cmd = new SqlCommand("select max(id) from OA_CH_APPROVEL_FORM_FLOW", conn);
  452.                     cmd.Transaction = tx;
  453.                     try
  454.                     {
  455.                         flow_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  456.                     }
  457.                     catch { }
  458.                     ArrayList main_ids = new ArrayList();
  459.                     cmd = new SqlCommand("select id from OA_FLOW_MAIN where department_id=" + DepartmentId.Value, conn);
  460.                     cmd.Transaction = tx;
  461.                     SqlDataReader dr = cmd.ExecuteReader();
  462.                     while (dr.Read())
  463.                     {
  464.                         main_ids.Add(dr["id"].ToString());
  465.                     }
  466.                     dr.Close();
  467.                     int flag = 0;
  468.                     int main_id = 0;
  469.                     for (int i = 0; i < main_ids.Count; i++)
  470.                     {
  471.                         cmd = new SqlCommand("select position_id from OA_FLOW_POSITION where main_id=" + main_ids[i], conn);
  472.                         cmd.Transaction = tx;
  473.                         dr = cmd.ExecuteReader();
  474.                         while (dr.Read())
  475.                         {
  476.                             if (dr["position_id"].ToString().Equals(PositionId.Value))
  477.                             {
  478.                                 flag = 1;
  479.                                 main_id = Convert.ToInt32(main_ids[i]);
  480.                             }
  481.                         }
  482.                         dr.Close();
  483.                         if (flag == 1)
  484.                         {
  485.                             break;
  486.                         }
  487.                     }
  488.                     if (main_id != 0)
  489.                     {
  490.                         ArrayList operator_ids = new ArrayList();
  491.                         cmd = new SqlCommand("select operator_id from OA_FLOW_DETAIL where main_id=" + main_id +
  492.                             " order by number", conn);
  493.                         cmd.Transaction = tx;
  494.                         dr = cmd.ExecuteReader();
  495.                         while (dr.Read())
  496.                         {
  497.                             operator_ids.Add(dr["operator_id"].ToString());
  498.                         }
  499.                         dr.Close();
  500.                         for (int i = 0; i < operator_ids.Count; i++)
  501.                         {
  502.                             cmd = new SqlCommand("insert into OA_CH_APPROVEL_FORM_FLOW(id, form_id, operator_id, " +
  503.                                 "apply_type, is_check, is_agree, comment, check_date, step, is_business)values(" +
  504.                                 flow_id + ", " + id + "," + operator_ids[i] + ",2,'N','N','',''," + (i + 2) + ",'N')", conn);
  505.                             cmd.Transaction = tx;
  506.                             cmd.ExecuteNonQuery();
  507.                             flow_id++;
  508.                         }
  509.                         tx.Commit();
  510.                         Response.Redirect("my_list.aspx");
  511.                     }
  512.                     else
  513.                     {
  514.                         LblError.Text = "沒有找到相關處理流程, 請與管理員聯繫";
  515.                         tx.Rollback();
  516.                     }
  517.                 }
  518.                 catch (Exception ex)
  519.                 {
  520.                     Response.Write(ex.Message);
  521.                     tx.Rollback();
  522.                 }
  523.             }
  524.             else
  525.             {
  526.                 SqlCommand cmd = new SqlCommand("update OA_CH_OFF_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  527.                 cmd.ExecuteNonQuery();
  528.                 Response.Redirect("my_list.aspx");
  529.             }
  530.             conn.Close();
  531.         }
  532.     }
  533. }