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

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.                         //mail
  351.                         ArrayList name1 = new ArrayList();
  352.                         ArrayList mail1 = new ArrayList();
  353.                         cmd = new SqlCommand("select top 1 a.email_work,a.emp_name from oa_employee as a inner join " +
  354.                            "oa_ch_approvel_form_flow as b on b.operator_id=a.id left join OA_ch_business_form as c " +
  355.                              "on b.form_id=c.id where b.step=c.step+1 and c.id=" + id + " order by position desc", conn);
  356.                         cmd.Transaction = tx;
  357.                         SqlDataReader dr3 = cmd.ExecuteReader();
  358.                         while (dr3.Read())
  359.                         {
  360.                             name1.Add(dr3["emp_name"].ToString());
  361.                             mail1.Add(dr3["email_work"].ToString());
  362.                             mail.mail_q(mail1[0], name1[0], TxtEmpName.Text, "中幹出差申請單");
  363.                         }
  364.                                          
  365.                         dr3.Close();
  366.                         tx.Commit(); 
  367.                       
  368.                 }
  369.                 catch (Exception ex)
  370.                 {
  371.                     Response.Write(ex.Message);
  372.                     tx.Rollback();
  373.                 }
  374.             }
  375.             else
  376.             {
  377.                 SqlCommand cmd = new SqlCommand("update OA_CH_BUSINESS_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  378.                 cmd.ExecuteNonQuery();
  379.             }
  380.             conn.Close();
  381.             Response.Redirect("my_list.aspx");
  382.         }
  383.     }
  384.     protected void BtnOk2_Click(object sender, EventArgs e)
  385.     {
  386.         if (Request.QueryString["o_id"] != null)
  387.         {
  388.             string id = Request.QueryString["o_id"];
  389.             SqlConnection conn = dbConnection.getConnection();
  390.             conn.Open();
  391.             if (State.Value.Equals("2"))
  392.             {
  393.                 SqlTransaction tx = conn.BeginTransaction();
  394.                 try
  395.                 {
  396.                     SqlCommand cmd = new SqlCommand("update OA_CH_OFF_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  397.                     cmd.Transaction = tx;
  398.                     cmd.ExecuteNonQuery();
  399.                     //mail
  400.                     ArrayList name1 = new ArrayList();
  401.                     ArrayList mail1 = new ArrayList();
  402.                     cmd = new SqlCommand("select top 1 a.email_work,a.emp_name from oa_employee as a inner join " +
  403.                        "oa_ch_approvel_form_flow as b on b.operator_id=a.id left join OA_ch_off_form as c " +
  404.                          "on b.form_id=c.id where b.step=c.step+1 and c.id=" + id + " order by position desc", conn);
  405.                     cmd.Transaction = tx;
  406.                     SqlDataReader dr3 = cmd.ExecuteReader();
  407.                     while (dr3.Read())
  408.                     {
  409.                         name1.Add(dr3["emp_name"].ToString());
  410.                         mail1.Add(dr3["email_work"].ToString());
  411.                         mail.mail_q(mail1[0], name1[0], TxtEmpName.Text, "中幹請假單");
  412.                     } dr3.Close();
  413.                     tx.Commit();
  414.                     //   
  415.                   
  416.                 }
  417.                 catch (Exception ex)
  418.                 {
  419.                     Response.Write(ex.Message);
  420.                     tx.Rollback();
  421.                 }
  422.             }
  423.             else
  424.             {
  425.                 SqlCommand cmd = new SqlCommand("update OA_CH_OFF_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  426.                 cmd.ExecuteNonQuery();
  427.                 Response.Redirect("my_list.aspx");
  428.             }
  429.             conn.Close();
  430.         }
  431.     }
  432. }