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.     
  15.     protected void Page_Load(object sender, EventArgs e)
  16.     {
  17.         if (!IsPostBack)
  18.         {
  19.             LoginDAO.CheckLogin(Session, Response, "../../", 2);
  20.             ApprovelList.DataKeyNames = new string[] { "id" };
  21.             OffList.DataKeyNames = new string[] { "id" };
  22.             if (Request.QueryString["a_id"]!=null)
  23.             {
  24.                 PnlApprovel.Visible = true;
  25.                 PnlFlow.Visible = true;
  26.                 FlowList.DataKeyNames = new string[] { "id" };
  27.                 this.SetValue(Request.QueryString["a_id"]);
  28.                 this.SetAmtValue(Request.QueryString["a_id"]);
  29.             }
  30.             if (Request.QueryString["o_id"] != null)
  31.             {
  32.                 PnlOffFlow.Visible = true;
  33.                 PnlOffForm.Visible = true;
  34.                 OffFlowList.DataKeyNames = new string[] { "id" };
  35.                 this.SetOffValue(Request.QueryString["o_id"]);
  36.             }
  37.             if (Session["user"] != null)
  38.             {
  39.                 User user = (User)Session["user"];
  40.                 DepartmentId.Value = user.Department.Id.ToString();
  41.                 PositionId.Value = user.PositionId.ToString();
  42.             }
  43.         }
  44.     }
  45.     protected void SetValue(string id)
  46.     {
  47.         SqlConnection conn = dbConnection.getConnection();
  48.         conn.Open();
  49.         SqlCommand cmd = new SqlCommand("select a.form_id, e.emp_name, e.emp_no, p.name position, a.apply_date," +
  50.             "d.name department, a.days, a.begin_time, a.end_time,  depart_place, arrive_place, " +
  51.             "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 " +
  52.             "inner join OA_DEPARTMENT d on a.department_id=d.id inner join OA_EMPLOYEE_POSITION p on " +
  53.             "e.position=p.id  where a.id=" + id, conn);
  54.         SqlDataReader dr = cmd.ExecuteReader();
  55.         int state = 0;
  56.         if (dr.Read())
  57.         {
  58.             TxtFormId.Text = dr["form_id"].ToString();
  59.             TxtEmpName.Text = dr["emp_name"].ToString();
  60.             TxtEmpNo.Text = dr["emp_no"].ToString();
  61.             TxtPosition.Text = dr["position"].ToString();
  62.             TxtApplyDate.Text = dr["apply_date"].ToString();
  63.             TxtDepartment.Text = dr["department"].ToString();
  64.             TxtDays.Text = dr["days"].ToString();
  65.             TxtBeginTime.Text = dr["begin_time"].ToString();
  66.             TxtEndTime.Text = dr["end_time"].ToString();
  67.             TxtDepartPlace.Text = dr["depart_place"].ToString();
  68.             TxtArrivePlace.Text = dr["arrive_place"].ToString();
  69.             TxtDepartTime.Text = dr["depart_time"].ToString();
  70.             TxtArriveTime.Text = dr["arrive_time"].ToString();
  71.             state = Convert.ToInt32(dr["state"].ToString());
  72.             State.Value = state.ToString();
  73.             
  74.         }
  75.         dr.Close();
  76.         int flag = 0;
  77.         cmd = new SqlCommand("select * from OA_CH_BUSINESS_DETAIL where form_id="+id+
  78.             " order by number", conn);
  79.         dr = cmd.ExecuteReader();
  80.         while (dr.Read())
  81.         {
  82.             flag = 1;
  83.             //動態創建表格行
  84.             TableRow tr1 = new TableRow();
  85.             TableCell td1 = new TableCell();
  86.             td1.BorderWidth = Unit.Pixel(1);
  87.             Label label = new Label();
  88.             label.BorderStyle = BorderStyle.None;
  89.             label.Text = dr["number"].ToString();
  90.             td1.Controls.Add(label);
  91.             tr1.Cells.Add(td1);
  92.             TableCell td2 = new TableCell();
  93.             td2.BorderWidth = Unit.Pixel(1);
  94.             label = new Label();
  95.             label.BorderStyle = BorderStyle.None;
  96.             label.Text = dr["date"].ToString();
  97.             td2.Controls.Add(label);
  98.             tr1.Cells.Add(td2);
  99.             TableCell td3 = new TableCell();
  100.             td3.BorderWidth = Unit.Pixel(1);
  101.             label = new Label();
  102.             label.BorderStyle = BorderStyle.None;
  103.             label.Text = dr["d_start"].ToString();
  104.             td3.Controls.Add(label);
  105.             tr1.Cells.Add(td3);
  106.             TableCell td4 = new TableCell();
  107.             td4.BorderWidth = Unit.Pixel(1);
  108.             label = new Label();
  109.             label.BorderStyle = BorderStyle.None;
  110.             label.Text = dr["d_end"].ToString();
  111.             td4.Controls.Add(label);
  112.             tr1.Cells.Add(td4);
  113.             TableCell td5 = new TableCell();
  114.             td5.BorderWidth = Unit.Pixel(1);
  115.             label = new Label();
  116.             label.BorderStyle = BorderStyle.None;
  117.             label.Text = dr["tool"].ToString();
  118.             td5.Controls.Add(label);
  119.             tr1.Cells.Add(td5);
  120.             TableCell td6 = new TableCell();
  121.             td6.BorderWidth = Unit.Pixel(1);
  122.             label = new Label();
  123.             label.BorderStyle = BorderStyle.None;
  124.             label.Text = dr["content"].ToString();
  125.             td6.Controls.Add(label);
  126.             tr1.Cells.Add(td6);
  127.             TableCell td7 = new TableCell();
  128.             td7.BorderWidth = Unit.Pixel(1);
  129.             label = new Label();
  130.             label.BorderStyle = BorderStyle.None;
  131.             label.Text = dr["remark"].ToString();
  132.             td7.Controls.Add(label);
  133.             tr1.Cells.Add(td7);   
  134.           
  135.             TblDetail.Rows.Add(tr1);
  136.         }
  137.         dr.Close();
  138.      
  139.         conn.Close();
  140.         if (flag == 0)
  141.         {
  142.             TblDetail.Visible = false;
  143.         }
  144.         if (state != 1)
  145.         {
  146.             PnlFlow.Visible = false;
  147.             Panel1.Visible = true;
  148.         }
  149.     }
  150.     protected void SetAmtValue(string id) 
  151.     {
  152.         SqlConnection conn = dbConnection.getConnection();
  153.         conn.Open();
  154.         SqlCommand cmd = new SqlCommand("select * from OA_CH_BUSINESS_DETAIL1 where form_id="+id, conn);
  155.         SqlDataReader dr = cmd.ExecuteReader();
  156.         while (dr.Read()) 
  157.         {
  158.             TxtFAmt1.Text = dr["f_eat"].ToString();
  159.             TxtFRemark1.Text=dr["f_eat_remark"].ToString();
  160.             TxtFAmt2.Text = dr["f_house"].ToString();
  161.             TxtFRemark2.Text = dr["f_house_remark"].ToString();
  162.             TxtFAmt3.Text = dr["f_move"].ToString();
  163.             TxtFRemark3.Text = dr["f_move_remark"].ToString();
  164.             TxtFAmt4.Text = dr["f_other"].ToString();
  165.             TxtFRemark4.Text = dr["f_other_remark"].ToString();
  166.             TxtFAmt5.Text = dr["f_total"].ToString();
  167.             TxtFRemark5.Text = dr["f_total_remark"].ToString();
  168.         }
  169.         dr.Close();
  170.         conn.Close();
  171.     
  172.     }
  173.     protected void SetOffValue(string id)
  174.     {
  175.         SqlConnection conn = dbConnection.getConnection();
  176.         conn.Open();
  177.         SqlCommand cmd = new SqlCommand("select o.form_id, e.emp_no, e.emp_name, d.name department, "+
  178.             "e.emp_name delegate, e.position position, o.state, "+
  179.             "t.name off_type, o.begin_time, o.end_time, o.hours, o.apply_date, o.parenthesis, "+
  180.             "o.reason from OA_CH_OFF_FORM o inner join OA_EMPLOYEE e on o.emp_id=e.id inner join "+
  181.             "OA_DEPARTMENT d on o.department_id=d.id inner join OA_CH_OFF_TYPE t on "+
  182.             "o.off_type=t.id where o.id="+id, conn);
  183.         SqlDataReader dr = cmd.ExecuteReader();
  184.         int state = 0;
  185.         if (dr.Read())
  186.         {
  187.             TxtOffFormId.Text = dr["form_id"].ToString();
  188.             TxtOffEmpName.Text = dr["emp_no"].ToString() + dr["emp_name"].ToString();
  189.             TxtOffDepartment.Text = dr["department"].ToString();
  190.             TxtDelegate.Text = dr["delegate"].ToString();
  191.             TxtOffPosition.Text = dr["position"].ToString();
  192.             TxtOffType2.Text = dr["off_type"].ToString();
  193.             TxtOffBeginTime.Text = dr["begin_time"].ToString();
  194.             TxtOffEndTime.Text = dr["end_time"].ToString();
  195.             TxtHours.Text = dr["hours"].ToString();
  196.             TxtOffApplyDate.Text = dr["apply_date"].ToString();
  197.             TxtParenthesis.Text = dr["parenthesis"].ToString();
  198.             TxtReason.Text = dr["reason"].ToString();
  199.             state = Convert.ToInt32(dr["state"].ToString());
  200.             State.Value = state.ToString();
  201.            
  202.         }
  203.         dr.Close();
  204.         if (state != 1)
  205.         {
  206.             PnlOffFlow.Visible = false;
  207.             Panel2.Visible = true;
  208.         }
  209.         conn.Close();
  210.     }
  211.     protected void ApprovelList_RowDataBound(object sender, GridViewRowEventArgs e)
  212.     {
  213.         //行高亮
  214.         if (e.Row.RowType == DataControlRowType.DataRow)
  215.         {
  216.             e.Row.Attributes.Add("onmouseover", "this.style.cursor='pointer';");
  217.             e.Row.Attributes.Add("onclick", "javascript:void(window.open('my_list_d.aspx?a_id=" + ApprovelList.DataKeys[e.Row.RowIndex].Value.ToString() + "'))");
  218.         }
  219.     }
  220.     protected void FlowList_RowCreated(object sender, GridViewRowEventArgs e)
  221.     {
  222.         if (e.Row.RowType == DataControlRowType.DataRow)
  223.         {
  224.             SqlConnection conn = dbConnection.getConnection();
  225.             conn.Open();
  226.             SqlCommand cmd = new SqlCommand("select apply_type, is_check, is_agree, comment from " +
  227.                 "OA_CH_APPROVEL_FORM_FLOW where id=" + FlowList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  228.             SqlDataReader dr = cmd.ExecuteReader();
  229.             if (dr.Read())
  230.             {
  231.                 Label label = (Label)e.Row.FindControl("LblApplyType");
  232.                 if (dr["apply_type"].ToString().Equals("1"))
  233.                 {
  234.                     label.Text = "會簽";
  235.                 }
  236.                 else if (dr["apply_type"].ToString().Equals("3"))
  237.                 {
  238.                     label.Text = "代理";
  239.                 }
  240.                 else
  241.                 {
  242.                     label.Text = "審批";
  243.                 }
  244.                 label = (Label)e.Row.FindControl("LblIsCheck");
  245.                 if (dr["is_check"].ToString().Equals("N"))
  246.                 {
  247.                     label.Text = "未處理";
  248.                 }
  249.                 else
  250.                 {
  251.                     label.Text = "已處理";
  252.                     label = (Label)e.Row.FindControl("LblIsAgree");
  253.                     if (dr["is_agree"].ToString().Equals("Y"))
  254.                     {
  255.                         label.Text = "已同意";
  256.                     }
  257.                     else
  258.                     {
  259.                         label.Text = "不同意";
  260.                     }
  261.                 }
  262.                 label = (Label)e.Row.FindControl("LblComment");
  263.                 label.Text = dr["comment"].ToString();
  264.             }
  265.             dr.Close();
  266.             conn.Close();
  267.         }
  268.     }
  269.     protected void OffList_RowDataBound(object sender, GridViewRowEventArgs e)
  270.     {
  271.         //行高亮
  272.         if (e.Row.RowType == DataControlRowType.DataRow)
  273.         {
  274.             e.Row.Attributes.Add("onmouseover", "this.style.cursor='pointer';");
  275.             e.Row.Attributes.Add("onclick", "location.href='my_list.aspx?o_id=" + OffList.DataKeys[e.Row.RowIndex].Value.ToString() + "'");
  276.         }
  277.     }
  278.     protected void OffFlowList_RowCreated(object sender, GridViewRowEventArgs e)
  279.     {
  280.         if (e.Row.RowType == DataControlRowType.DataRow)
  281.         {
  282.             SqlConnection conn = dbConnection.getConnection();
  283.             conn.Open();
  284.             SqlCommand cmd = new SqlCommand("select apply_type, is_check, is_agree, comment from " +
  285.                 "OA_CH_APPROVEL_FORM_FLOW where id=" + OffFlowList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  286.             SqlDataReader dr = cmd.ExecuteReader();
  287.             if (dr.Read())
  288.             {
  289.                 Label label = (Label)e.Row.FindControl("LblApplyType");
  290.                 if (dr["apply_type"].ToString().Equals("1"))
  291.                 {
  292.                     label.Text = "會簽";
  293.                 }
  294.                 else if (dr["apply_type"].ToString().Equals("3"))
  295.                 {
  296.                     label.Text = "代理";
  297.                 }
  298.                 else
  299.                 {
  300.                     label.Text = "審批";
  301.                 }
  302.                 label = (Label)e.Row.FindControl("LblIsCheck");
  303.                 if (dr["is_check"].ToString().Equals("N"))
  304.                 {
  305.                     label.Text = "未處理";
  306.                 }
  307.                 else
  308.                 {
  309.                     label.Text = "已處理";
  310.                     label = (Label)e.Row.FindControl("LblIsAgree");
  311.                     if (dr["is_agree"].ToString().Equals("Y"))
  312.                     {
  313.                         label.Text = "已同意";
  314.                     }
  315.                     else
  316.                     {
  317.                         label.Text = "不同意";
  318.                     }
  319.                 }
  320.                 label = (Label)e.Row.FindControl("LblComment");
  321.                 label.Text = dr["comment"].ToString();
  322.             }
  323.             dr.Close();
  324.             conn.Close();
  325.         }
  326.     }
  327.     protected void BtnOk_Click(object sender, EventArgs e)
  328.     {
  329.         if (Request.QueryString["a_id"] != null)
  330.         {
  331.             string id = Request.QueryString["a_id"];
  332.             SqlConnection conn = dbConnection.getConnection();
  333.             conn.Open();
  334.             if (State.Value.Equals("2"))
  335.             {
  336.                 SqlTransaction tx = conn.BeginTransaction();
  337.                 try
  338.                 {
  339.                     SqlCommand cmd = new SqlCommand("update OA_CH_BUSINESS_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  340.                     cmd.Transaction = tx;
  341.                     cmd.ExecuteNonQuery();                      
  342.                         //mail
  343.                         ArrayList name1 = new ArrayList();
  344.                         ArrayList mail1 = new ArrayList();
  345.                         cmd = new SqlCommand("select top 1 a.email_work,a.emp_name from oa_employee as a inner join " +
  346.                            "oa_ch_approvel_form_flow as b on b.operator_id=a.id left join OA_ch_business_form as c " +
  347.                              "on b.form_id=c.id where b.step=c.step+1 and is_business='Y' and c.id=" + id + " order by position desc", conn);
  348.                         cmd.Transaction = tx;
  349.                         SqlDataReader dr3 = cmd.ExecuteReader();
  350.                         while (dr3.Read())
  351.                         {
  352.                             name1.Add(dr3["emp_name"].ToString());
  353.                             mail1.Add(dr3["email_work"].ToString());
  354.                             //mail.mail_q(mail1[0], name1[0], TxtEmpName.Text, "中幹出差申請單");
  355.                         }
  356.                                          
  357.                         dr3.Close();
  358.                         tx.Commit(); 
  359.                       
  360.                 }
  361.                 catch (Exception ex)
  362.                 {
  363.                     Response.Write(ex.Message);
  364.                     tx.Rollback();
  365.                 }
  366.             }
  367.             else
  368.             {
  369.                 SqlCommand cmd = new SqlCommand("update OA_CH_BUSINESS_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  370.                 cmd.ExecuteNonQuery();
  371.             }
  372.             conn.Close();
  373.             Response.Redirect("my_list.aspx");
  374.         }
  375.     }
  376.     protected void BtnOk2_Click(object sender, EventArgs e)
  377.     {
  378.         if (Request.QueryString["o_id"] != null)
  379.         {
  380.             string id = Request.QueryString["o_id"];
  381.             SqlConnection conn = dbConnection.getConnection();
  382.             conn.Open();
  383.             if (State.Value.Equals("2"))
  384.             {
  385.                 SqlTransaction tx = conn.BeginTransaction();
  386.                 try
  387.                 {
  388.                     SqlCommand cmd = new SqlCommand("update OA_CH_OFF_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  389.                     cmd.Transaction = tx;
  390.                     cmd.ExecuteNonQuery();
  391.                     //mail
  392.                     ArrayList name1 = new ArrayList();
  393.                     ArrayList mail1 = new ArrayList();
  394.                     cmd = new SqlCommand("select top 1 a.email_work,a.emp_name from oa_employee as a inner join " +
  395.                        "oa_ch_approvel_form_flow as b on b.operator_id=a.id left join OA_ch_off_form as c " +
  396.                          "on b.form_id=c.id where b.step=c.step+1 and is_business='n' and c.id=" + id + " order by position desc", conn);
  397.                     cmd.Transaction = tx;
  398.                     SqlDataReader dr3 = cmd.ExecuteReader();
  399.                     while (dr3.Read())
  400.                     {
  401.                         name1.Add(dr3["emp_name"].ToString());
  402.                         mail1.Add(dr3["email_work"].ToString());
  403.                         //mail.mail_d(mail1[0].ToString(), name1[0].ToString(), TxtOffEmpName.Text);
  404.                     } dr3.Close();
  405.                     tx.Commit();
  406.                     //   
  407.                     
  408.                   
  409.                 }
  410.                 catch (Exception ex)
  411.                 {
  412.                     Response.Write(ex.Message);
  413.                     tx.Rollback();
  414.                 }
  415.             }
  416.             else
  417.             {
  418.                 SqlCommand cmd = new SqlCommand("update OA_CH_OFF_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  419.                 cmd.ExecuteNonQuery();
  420.                 
  421.             }
  422.             conn.Close();
  423.             Response.Redirect("my_list.aspx");
  424.         }
  425.     }
  426.     protected void Button1_Click(object sender, EventArgs e)
  427.     {
  428.         Response.Clear();
  429.         Response.Buffer = true;
  430.         Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMdd") + ".xls");
  431.         Response.ContentEncoding = System.Text.Encoding.UTF8;
  432.         Response.ContentType = "application/vnd.ms-xls";
  433.         this.EnableViewState = false;
  434.     }
  435. }