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

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. //System.Web.HttpUtility.UrlPathEncode 
  13. using Microsoft.Office.Interop.Excel;
  14. using Microsoft.Office.Interop;
  15. using System.Reflection;
  16. using System.Runtime.InteropServices;
  17. using ExcelApplication = Microsoft.Office.Interop.Excel.Application;
  18. using Label = System.Web.UI.WebControls.Label;
  19. public partial class web_approvel_ch_my_list_d : System.Web.UI.Page
  20. {
  21.     protected void Page_Load(object sender, EventArgs e)
  22.     {
  23.         if (!IsPostBack)
  24.         {
  25.             LoginDAO.CheckLogin(Session, Response, "../../", 2);
  26.            
  27.           
  28.             if (Request.QueryString["a_id"] != null)
  29.             {
  30.                 PnlApprovel.Visible = true;
  31.                 PnlFlow.Visible = true;
  32.                 FlowList.DataKeyNames = new string[] { "id" };
  33.                 this.SetValue(Request.QueryString["a_id"]);
  34.                 this.SetAmtValue(Request.QueryString["a_id"]);
  35.             }
  36.             if (Session["user"] != null)
  37.             {
  38.                 User user = (User)Session["user"];
  39.                 DepartmentId.Value = user.Department.Id.ToString();
  40.                 PositionId.Value = user.PositionId.ToString();
  41.             }
  42.         }
  43.     }
  44.     protected void FlowList_RowCreated(object sender, GridViewRowEventArgs e)
  45.     {
  46.         if (e.Row.RowType == DataControlRowType.DataRow)
  47.         {
  48.             SqlConnection conn = dbConnection.getConnection();
  49.             conn.Open();
  50.             SqlCommand cmd = new SqlCommand("select apply_type, is_check, is_agree, comment from " +
  51.                 "OA_CH_APPROVEL_FORM_FLOW where id=" + FlowList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  52.             SqlDataReader dr = cmd.ExecuteReader();
  53.             if (dr.Read())
  54.             {
  55.                 Label label = (Label)e.Row.FindControl("LblApplyType");
  56.                 if (dr["apply_type"].ToString().Equals("1"))
  57.                 {
  58.                     label.Text = "會簽";
  59.                 }
  60.                 else if (dr["apply_type"].ToString().Equals("3"))
  61.                 {
  62.                     label.Text = "代理";
  63.                 }
  64.                 else
  65.                 {
  66.                     label.Text = "審批";
  67.                 }
  68.                 label = (Label)e.Row.FindControl("LblIsCheck");
  69.                 if (dr["is_check"].ToString().Equals("N"))
  70.                 {
  71.                     label.Text = "未處理";
  72.                 }
  73.                 else
  74.                 {
  75.                     label.Text = "已處理";
  76.                     label = (Label)e.Row.FindControl("LblIsAgree");
  77.                     if (dr["is_agree"].ToString().Equals("Y"))
  78.                     {
  79.                         label.Text = "已同意";
  80.                     }
  81.                     else
  82.                     {
  83.                         label.Text = "不同意";
  84.                     }
  85.                 }
  86.                 label = (Label)e.Row.FindControl("LblComment");
  87.                 label.Text = dr["comment"].ToString();
  88.             }
  89.             dr.Close();
  90.             conn.Close();
  91.         }
  92.     }
  93.   
  94.     protected void BtnOk_Click(object sender, EventArgs e)
  95.     {
  96.         if (Request.QueryString["a_id"] != null)
  97.         {
  98.             string id = Request.QueryString["a_id"];
  99.             SqlConnection conn = dbConnection.getConnection();
  100.             conn.Open();
  101.             if (State.Value.Equals("2"))
  102.             {
  103.                 SqlTransaction tx = conn.BeginTransaction();
  104.                 try
  105.                 {
  106.                     SqlCommand cmd = new SqlCommand("update OA_CH_BUSINESS_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  107.                     cmd.Transaction = tx;
  108.                     cmd.ExecuteNonQuery();
  109.                     //mail
  110.                     ArrayList name1 = new ArrayList();
  111.                     ArrayList mail1 = new ArrayList();
  112.                     cmd = new SqlCommand("select top 1 a.email_work,a.emp_name from oa_employee as a inner join " +
  113.                        "oa_ch_approvel_form_flow as b on b.operator_id=a.id left join OA_ch_business_form as c " +
  114.                          "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);
  115.                     cmd.Transaction = tx;
  116.                     SqlDataReader dr3 = cmd.ExecuteReader();
  117.                     while (dr3.Read())
  118.                     {
  119.                         name1.Add(dr3["emp_name"].ToString());
  120.                         mail1.Add(dr3["email_work"].ToString());
  121.                         //mail.mail_q(mail1[0], name1[0], TxtEmpName.Text, "中幹出差申請單");
  122.                     }
  123.                     dr3.Close();
  124.                     tx.Commit();
  125.                 }
  126.                 catch (Exception ex)
  127.                 {
  128.                     Response.Write(ex.Message);
  129.                     tx.Rollback();
  130.                 }
  131.             }
  132.             else
  133.             {
  134.                 SqlCommand cmd = new SqlCommand("update OA_CH_BUSINESS_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  135.                 cmd.ExecuteNonQuery();
  136.             }
  137.             conn.Close();
  138.             Response.Redirect("my_list.aspx");
  139.         }
  140.     }
  141.  
  142.     protected void SetValue(string id)
  143.     {
  144.         SqlConnection conn = dbConnection.getConnection();
  145.         conn.Open();
  146.         SqlCommand cmd = new SqlCommand("select a.form_id, e.emp_name, e.emp_no, p.name position, a.apply_date," +
  147.             "d.name department, a.days, a.begin_time, a.end_time,  depart_place, arrive_place, " +
  148.             "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 " +
  149.             "inner join OA_DEPARTMENT d on a.department_id=d.id inner join OA_EMPLOYEE_POSITION p on " +
  150.             "e.position=p.id  where a.id=" + id, conn);
  151.         SqlDataReader dr = cmd.ExecuteReader();
  152.         int state = 0;
  153.         if (dr.Read())
  154.         {
  155.             TxtFormId.Text = dr["form_id"].ToString();
  156.             TxtEmpName.Text = dr["emp_name"].ToString();
  157.             TxtEmpNo.Text = dr["emp_no"].ToString();
  158.             TxtPosition.Text = dr["position"].ToString();
  159.             TxtApplyDate.Text = dr["apply_date"].ToString();
  160.             TxtDepartment.Text = dr["department"].ToString();
  161.             TxtDays.Text = dr["days"].ToString();
  162.             TxtBeginTime.Text = dr["begin_time"].ToString();
  163.             TxtEndTime.Text = dr["end_time"].ToString();
  164.             TxtDepartPlace.Text = dr["depart_place"].ToString();
  165.             TxtArrivePlace.Text = dr["arrive_place"].ToString();
  166.             TxtDepartTime.Text = dr["depart_time"].ToString();
  167.             TxtArriveTime.Text = dr["arrive_time"].ToString();
  168.             state = Convert.ToInt32(dr["state"].ToString());
  169.             State.Value = state.ToString();
  170.         }
  171.         dr.Close();
  172.         int flag = 0;
  173.         cmd = new SqlCommand("select * from OA_CH_BUSINESS_DETAIL where form_id=" + id +
  174.             " order by number", conn);
  175.         dr = cmd.ExecuteReader();
  176.         while (dr.Read())
  177.         {
  178.             flag = 1;
  179.             //動態創建表格行
  180.             TableRow tr1 = new TableRow();
  181.             TableCell td1 = new TableCell();
  182.             td1.BorderWidth = Unit.Pixel(1);
  183.             Label label = new Label();
  184.             label.BorderStyle = BorderStyle.None;
  185.             label.Text = dr["number"].ToString();
  186.             td1.Controls.Add(label);
  187.             tr1.Cells.Add(td1);
  188.             TableCell td2 = new TableCell();
  189.             td2.BorderWidth = Unit.Pixel(1);
  190.             label = new Label();
  191.             label.BorderStyle = BorderStyle.None;
  192.             label.Text = dr["date"].ToString();
  193.             td2.Controls.Add(label);
  194.             tr1.Cells.Add(td2);
  195.             TableCell td3 = new TableCell();
  196.             td3.BorderWidth = Unit.Pixel(1);
  197.             label = new Label();
  198.             label.BorderStyle = BorderStyle.None;
  199.             label.Text = dr["d_start"].ToString();
  200.             td3.Controls.Add(label);
  201.             tr1.Cells.Add(td3);
  202.             TableCell td4 = new TableCell();
  203.             td4.BorderWidth = Unit.Pixel(1);
  204.             label = new Label();
  205.             label.BorderStyle = BorderStyle.None;
  206.             label.Text = dr["d_end"].ToString();
  207.             td4.Controls.Add(label);
  208.             tr1.Cells.Add(td4);
  209.             TableCell td5 = new TableCell();
  210.             td5.BorderWidth = Unit.Pixel(1);
  211.             label = new Label();
  212.             label.BorderStyle = BorderStyle.None;
  213.             label.Text = dr["tool"].ToString();
  214.             td5.Controls.Add(label);
  215.             tr1.Cells.Add(td5);
  216.             TableCell td6 = new TableCell();
  217.             td6.BorderWidth = Unit.Pixel(1);
  218.             label = new Label();
  219.             label.BorderStyle = BorderStyle.None;
  220.             label.Text = dr["content"].ToString();
  221.             td6.Controls.Add(label);
  222.             tr1.Cells.Add(td6);
  223.             TableCell td7 = new TableCell();
  224.             td7.BorderWidth = Unit.Pixel(1);
  225.             label = new Label();
  226.             label.BorderStyle = BorderStyle.None;
  227.             label.Text = dr["remark"].ToString();
  228.             td7.Controls.Add(label);
  229.             tr1.Cells.Add(td7);
  230.             TblDetail.Rows.Add(tr1);
  231.         }
  232.         dr.Close();
  233.         conn.Close();
  234.         if (flag == 0)
  235.         {
  236.             TblDetail.Visible = false;
  237.         }
  238.         if (state != 1)
  239.         {
  240.             PnlFlow.Visible = false;
  241.             Panel1.Visible = true;
  242.         }
  243.     }
  244.     protected void SetAmtValue(string id)
  245.     {
  246.         SqlConnection conn = dbConnection.getConnection();
  247.         conn.Open();
  248.         SqlCommand cmd = new SqlCommand("select * from OA_CH_BUSINESS_DETAIL where form_id=" + id, conn);
  249.         SqlDataReader dr = cmd.ExecuteReader();
  250.         while (dr.Read())
  251.         {
  252.             TxtFAmt1.Text = dr["f_eat"].ToString();
  253.             TxtFRemark1.Text = dr["f_eat_remark"].ToString();
  254.             TxtFAmt2.Text = dr["f_house"].ToString();
  255.             TxtFRemark2.Text = dr["f_house_remark"].ToString();
  256.             TxtFAmt3.Text = dr["f_move"].ToString();
  257.             TxtFRemark3.Text = dr["f_move_remark"].ToString();
  258.             TxtFAmt4.Text = dr["f_other"].ToString();
  259.             TxtFRemark4.Text = dr["f_other_remark"].ToString();
  260.             TxtFAmt5.Text = dr["f_total"].ToString();
  261.             TxtFRemark5.Text = dr["f_total_remark"].ToString();
  262.         }
  263.         dr.Close();
  264.         conn.Close();
  265.     }
  266.     protected void Button1_Click(object sender, EventArgs e)
  267.     {
  268.         Response.Clear();
  269.         Response.Buffer = true;
  270.         Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMdd") + ".doc");
  271.       //   Response.ContentEncoding = System.Text.Encoding.UTF8;
  272.        //  Response.ContentEncoding = Encoding.UTF7;
  273.         Response.HeaderEncoding = System.Text.Encoding.UTF8;
  274.         Response.ContentType = "vnd.ms-excel/msword";
  275.         this.EnableViewState = false;
  276.         Response.ContentEncoding = System.Text.Encoding.UTF8; 
  277.        
  278.     }
  279.    
  280. }