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

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_deal_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.             this.SetMainTable();
  20.             if (Request.QueryString["f_id"] != null)
  21.             {
  22.                
  23.                 PnlApprovel.Visible = true;
  24.                 PnlDeal.Visible = true;
  25.                 this.SetValue(Request.QueryString["f_id"]);
  26.             }
  27.             if (Request.QueryString["o_id"] != null)
  28.             {
  29.               
  30.                 PnlOff.Visible = true;
  31.                 PnlDeal.Visible = true;
  32.                 this.SetOffValue(Request.QueryString["o_id"]);
  33.             }
  34.         }
  35.     }
  36.     protected void SetMainTable()
  37.     {
  38.         SqlConnection conn = dbConnection.getConnection();
  39.         conn.Open();
  40.         string user_id = "0";
  41.         if (Session["user_id"] != null)
  42.         {
  43.             user_id = Session["user_id"].ToString();
  44.         }
  45.         ArrayList ids = new ArrayList();
  46.         ArrayList form_ids = new ArrayList();
  47.         ArrayList is_businesses = new ArrayList();
  48.         ArrayList f_steps = new ArrayList();
  49.         SqlCommand cmd = new SqlCommand("SELECT f.id, f.form_id, f.is_business, f.step FROM dbo.OA_CH_APPROVEL_FORM_FLOW AS f " +
  50.             " left join oa_ch_business_form as b on f.form_id=b.id WHERE (f.operator_id = " + user_id + ") AND (f.is_check = 'N') and state=1", conn);
  51.         SqlDataReader dr = cmd.ExecuteReader();
  52.         while (dr.Read())
  53.         {
  54.             ids.Add(dr["id"].ToString());
  55.             form_ids.Add(dr["form_id"].ToString());
  56.             is_businesses.Add(dr["is_business"].ToString());
  57.             f_steps.Add(dr["step"].ToString());
  58.         }
  59.         dr.Close();
  60.         for (int i = ids.Count - 1; i >= 0; i--)
  61.         {
  62.             int f_step = Convert.ToInt32(f_steps[i]);
  63.             if (is_businesses[i].Equals("Y"))
  64.             {
  65.                 cmd = new SqlCommand("select e.emp_name, b.apply_date, b.step from OA_CH_BUSINESS_FORM b inner join " +
  66.                     "OA_EMPLOYEE e on b.emp_id=e.id where b.id=" + form_ids[i], conn);
  67.                 dr = cmd.ExecuteReader();
  68.                 if (dr.Read())
  69.                 {
  70.                     int b_step = Convert.ToInt32(dr["step"].ToString()) + 1;
  71.                     if (b_step == f_step)
  72.                     {
  73.                         TblFlow.Visible = true;
  74.                         TableRow tr = new TableRow();
  75.                         TableCell td = new TableCell();
  76.                         td.BorderWidth = Unit.Pixel(1);
  77.                         td.Text = dr["emp_name"].ToString();
  78.                         tr.Cells.Add(td);
  79.                         td = new TableCell();
  80.                         td.BorderWidth = Unit.Pixel(1);
  81.                         td.Text = dr["emp_name"].ToString() + "的出差單";
  82.                         tr.Cells.Add(td);
  83.                         td = new TableCell();
  84.                         td.BorderWidth = Unit.Pixel(1);
  85.                         td.Text = dr["apply_date"].ToString();
  86.                         tr.Cells.Add(td);
  87.                         td = new TableCell();
  88.                         td.BorderWidth = Unit.Pixel(1);
  89.                         HyperLink hl = new HyperLink();
  90.                         hl.Text = "查看";
  91.                         hl.NavigateUrl = "deal_list.aspx?f_id=" + ids[i].ToString();
  92.                         td.Controls.Add(hl);
  93.                         tr.Cells.Add(td);
  94.                         TblFlow.Rows.Add(tr);
  95.                     }
  96.                 }
  97.                 dr.Close();
  98.             }
  99.             else
  100.             {
  101.                 cmd = new SqlCommand("select e.emp_name, o.apply_date, t.name off_type, o.step from OA_CH_OFF_FORM o "+
  102.                     "inner join OA_EMPLOYEE e on o.emp_id=e.id inner join OA_CH_OFF_TYPE t on o.off_type=t.id "+
  103.                     "where o.id=" + form_ids[i] + " and state=1", conn);
  104.                 dr = cmd.ExecuteReader();
  105.                 if (dr.Read())
  106.                 {
  107.                     int b_step = Convert.ToInt32(dr["step"].ToString()) + 1;
  108.                     if (f_step == b_step)
  109.                     {
  110.                         TblFlow.Visible = true;
  111.                         TableRow tr = new TableRow();
  112.                         TableCell td = new TableCell();
  113.                         td.BorderWidth = Unit.Pixel(1);
  114.                         td.Text = dr["emp_name"].ToString();
  115.                         tr.Cells.Add(td);
  116.                         td = new TableCell();
  117.                         td.BorderWidth = Unit.Pixel(1);
  118.                         td.Text = dr["emp_name"].ToString() + "的" + dr["off_type"].ToString() + "單";
  119.                         tr.Cells.Add(td);
  120.                         td = new TableCell();
  121.                         td.BorderWidth = Unit.Pixel(1);
  122.                         td.Text = dr["apply_date"].ToString();
  123.                         tr.Cells.Add(td);
  124.                         td = new TableCell();
  125.                         td.BorderWidth = Unit.Pixel(1);
  126.                         HyperLink hl = new HyperLink();
  127.                         hl.Text = "查看";
  128.                         hl.NavigateUrl = "deal_list.aspx?o_id=" + ids[i].ToString();
  129.                         td.Controls.Add(hl);
  130.                         tr.Cells.Add(td);
  131.                         TblFlow.Rows.Add(tr);
  132.                     }
  133.                 }
  134.                 dr.Close();
  135.             }
  136.         }
  137.         conn.Close();
  138.     }
  139.     protected void SetValue(string id)
  140.     {
  141.         SqlConnection conn = dbConnection.getConnection();
  142.         conn.Open();
  143.         int form_id = 0;
  144.         string is_business = "";
  145.         SqlCommand cmd = new SqlCommand("select form_id, is_business from OA_CH_APPROVEL_FORM_FLOW where id="+id, conn);
  146.         SqlDataReader dr = cmd.ExecuteReader();
  147.         if (dr.Read())
  148.         {
  149.             form_id = Convert.ToInt32(dr["form_id"].ToString());
  150.             is_business = dr["is_business"].ToString();
  151.         }
  152.         dr.Close();
  153.         FormId.Value = form_id.ToString();
  154.         if (is_business.Equals("Y"))
  155.         {
  156.             PnlApprovel.Visible = true;
  157.             cmd = new SqlCommand("select a.form_id, e.emp_name, e.emp_no, p.name position, a.apply_date," +
  158.                 "d.name department, a.days, a.begin_time, a.end_time, f1.name depart_place, f2.name arrive_place, " +
  159.                 "a.depart_time, a.arrive_time from OA_CH_BUSINESS_FORM a inner join OA_EMPLOYEE e on a.emp_id=e.id " +
  160.                 "inner join OA_DEPARTMENT d on a.department_id=d.id inner join OA_EMPLOYEE_POSITION p on " +
  161.                 "e.position=p.id inner join OA_FLIGHT_PLACE f1 on a.depart_place=f1.id inner join " +
  162.                 "OA_FLIGHT_PLACE f2 on a.arrive_place=f2.id where a.id=" + form_id, conn);
  163.             dr = cmd.ExecuteReader();
  164.             if (dr.Read())
  165.             {
  166.                 TxtFormId.Text = dr["form_id"].ToString();
  167.                 TxtEmpName.Text = dr["emp_name"].ToString();
  168.                 TxtEmpNo.Text = dr["emp_no"].ToString();
  169.                 TxtPosition.Text = dr["position"].ToString();
  170.                 TxtApplyDate.Text = dr["apply_date"].ToString();
  171.                 TxtDepartment.Text = dr["department"].ToString();
  172.                 TxtDays.Text = dr["days"].ToString();
  173.                 TxtBeginTime.Text = dr["begin_time"].ToString();
  174.                 TxtEndTime.Text = dr["end_time"].ToString();
  175.                 TxtDepartPlace.Text = dr["depart_place"].ToString();
  176.                 TxtArrivePlace.Text = dr["arrive_place"].ToString();
  177.                 TxtDepartTime.Text = dr["depart_time"].ToString();
  178.                 TxtArriveTime.Text = dr["arrive_time"].ToString();
  179.             }
  180.             dr.Close();
  181.         }
  182.         conn.Close();
  183.         this.SetTable(form_id);
  184.     }
  185.     protected void SetOffValue(string id)
  186.     {
  187.         SqlConnection conn = dbConnection.getConnection();
  188.         conn.Open();
  189.         int form_id = 0;
  190.         SqlCommand cmd = new SqlCommand("select form_id from OA_CH_APPROVEL_FORM_FLOW where id="+id, conn);
  191.         form_id = Convert.ToInt32(cmd.ExecuteScalar().ToString());
  192.         cmd = new SqlCommand("select o.form_id, e.emp_no, e.emp_name, d.name department, " +
  193.             "e.emp_name delegate, e.position position, " +
  194.             "t.name off_type, o.begin_time, o.end_time, o.hours, o.apply_date, o.parenthesis, " +
  195.             "o.reason from OA_CH_OFF_FORM o inner join OA_EMPLOYEE e on o.emp_id=e.id inner join " +
  196.             "OA_DEPARTMENT d on o.department_id=d.id inner join OA_CH_OFF_TYPE t on " +
  197.             "o.off_type=t.id where o.id=" + form_id, conn);
  198.         SqlDataReader dr = cmd.ExecuteReader();
  199.         if (dr.Read())
  200.         {
  201.             TxtOffFormId.Text = dr["form_id"].ToString();
  202.             TxtOffEmpName.Text = dr["emp_no"].ToString() + dr["emp_name"].ToString();
  203.             TxtOffDepartment.Text = dr["department"].ToString();
  204.             TxtDelegate.Text = dr["delegate"].ToString();
  205.             TxtOffPosition.Text = dr["position"].ToString();
  206.             TxtOffType2.Text = dr["off_type"].ToString();
  207.             TxtOffBeginTime.Text = dr["begin_time"].ToString();
  208.             TxtOffEndTime.Text = dr["end_time"].ToString();
  209.             TxtHours.Text = dr["hours"].ToString();
  210.             TxtOffApplyDate.Text = dr["apply_date"].ToString();
  211.             TxtParenthesis.Text = dr["parenthesis"].ToString();
  212.             TxtReason.Text = dr["reason"].ToString();
  213.         }
  214.         dr.Close();
  215.         conn.Close();
  216.     }
  217.     protected void SetTable(int form_id)
  218.     {
  219.         SqlConnection conn = dbConnection.getConnection();
  220.         conn.Open();
  221.         int flag = 0;
  222.         SqlCommand cmd = new SqlCommand("select number, company, subject, linkman, tel, place, visa_begin, visa_end, " +
  223.             "flight_go_begin, flight_back_end, is_aboard, remark from OA_CH_BUSINESS_DETAIL where form_id=" + form_id +
  224.             " order by number", conn);
  225.         SqlDataReader dr = cmd.ExecuteReader();
  226.         while (dr.Read())
  227.         {
  228.             flag = 1;
  229.             //動態創建表格行
  230.             TableRow tr1 = new TableRow();
  231.             TableCell td1 = new TableCell();
  232.             td1.BorderWidth = Unit.Pixel(1);
  233.             Label label = new Label();
  234.             label.BorderStyle = BorderStyle.None;
  235.             label.Text = dr["number"].ToString();
  236.             td1.Controls.Add(label);
  237.             tr1.Cells.Add(td1);
  238.             TableCell td2 = new TableCell();
  239.             td2.BorderWidth = Unit.Pixel(1);
  240.             label = new Label();
  241.             label.BorderStyle = BorderStyle.None;
  242.             label.Text = dr["company"].ToString();
  243.             td2.Controls.Add(label);
  244.             tr1.Cells.Add(td2);
  245.             TableCell td3 = new TableCell();
  246.             td3.BorderWidth = Unit.Pixel(1);
  247.             label = new Label();
  248.             label.BorderStyle = BorderStyle.None;
  249.             label.Text = dr["subject"].ToString();
  250.             td3.Controls.Add(label);
  251.             tr1.Cells.Add(td3);
  252.             TableCell td4 = new TableCell();
  253.             td4.BorderWidth = Unit.Pixel(1);
  254.             label = new Label();
  255.             label.BorderStyle = BorderStyle.None;
  256.             label.Text = dr["linkman"].ToString();
  257.             td4.Controls.Add(label);
  258.             tr1.Cells.Add(td4);
  259.             TableCell td5 = new TableCell();
  260.             td5.BorderWidth = Unit.Pixel(1);
  261.             label = new Label();
  262.             label.BorderStyle = BorderStyle.None;
  263.             label.Text = dr["tel"].ToString();
  264.             td5.Controls.Add(label);
  265.             tr1.Cells.Add(td5);
  266.             TableCell td6 = new TableCell();
  267.             td6.BorderWidth = Unit.Pixel(1);
  268.             label = new Label();
  269.             label.BorderStyle = BorderStyle.None;
  270.             label.Text = dr["place"].ToString();
  271.             td6.Controls.Add(label);
  272.             tr1.Cells.Add(td6);
  273.             TableCell td7 = new TableCell();
  274.             td7.BorderWidth = Unit.Pixel(1);
  275.             label = new Label();
  276.             label.BorderStyle = BorderStyle.None;
  277.             label.Text = dr["visa_begin"].ToString();
  278.             td7.Controls.Add(label);
  279.             tr1.Cells.Add(td7);
  280.             TableCell td8 = new TableCell();
  281.             td8.BorderWidth = Unit.Pixel(1);
  282.             label = new Label();
  283.             label.BorderStyle = BorderStyle.None;
  284.             label.Text = dr["visa_end"].ToString();
  285.             td8.Controls.Add(label);
  286.             tr1.Cells.Add(td8);
  287.             TableCell td9 = new TableCell();
  288.             td9.BorderWidth = Unit.Pixel(1);
  289.             label = new Label();
  290.             label.BorderStyle = BorderStyle.None;
  291.             label.Text = dr["flight_go_begin"].ToString();
  292.             td9.Controls.Add(label);
  293.             tr1.Cells.Add(td9);
  294.             TableCell td10 = new TableCell();
  295.             td10.BorderWidth = Unit.Pixel(1);
  296.             label = new Label();
  297.             label.BorderStyle = BorderStyle.None;
  298.             label.Text = dr["flight_back_end"].ToString();
  299.             td10.Controls.Add(label);
  300.             tr1.Cells.Add(td10);
  301.             TableCell td11 = new TableCell();
  302.             td11.BorderWidth = Unit.Pixel(1);
  303.             CheckBox chk = new CheckBox();
  304.             chk.Text = "國外";
  305.             chk.Enabled = false;
  306.             if (dr["is_aboard"].ToString().Equals("Y"))
  307.             {
  308.                 chk.Checked = true;
  309.             }
  310.             else
  311.             {
  312.                 chk.Checked = false;
  313.             }
  314.             td11.Controls.Add(chk);
  315.             tr1.Cells.Add(td11);
  316.             TableCell td12 = new TableCell();
  317.             td12.BorderWidth = Unit.Pixel(1);
  318.             label = new Label();
  319.             label.BorderStyle = BorderStyle.None;
  320.             label.Text = dr["remark"].ToString();
  321.             td12.Controls.Add(label);
  322.             tr1.Cells.Add(td12);
  323.             TblDetail.Rows.Add(tr1);
  324.         }
  325.         dr.Close();
  326.         conn.Close();
  327.         if (flag == 0)
  328.         {
  329.             TblDetail.Visible = false;
  330.         }
  331.     }
  332.    
  333.     protected void RbAgree_SelectedIndexChanged(object sender, EventArgs e)
  334.     {
  335.         if (TxtComment.Text.Equals("已同意") || TxtComment.Text.Equals("不同意"))
  336.         {
  337.             if (RbAgree.SelectedValue.Equals("Y"))
  338.             {
  339.                 TxtComment.Text = "已同意";
  340.             }
  341.             else
  342.             {
  343.                 TxtComment.Text = "不同意";
  344.             }
  345.         }
  346.         this.SetTable(Convert.ToInt32(FormId.Value));
  347.     }
  348.     protected void BtnOk_Click(object sender, EventArgs e)
  349.     {
  350.         SqlConnection conn = dbConnection.getConnection();
  351.         conn.Open();
  352.         SqlTransaction tx = conn.BeginTransaction();
  353.         try
  354.         {
  355.             int flow_id = 0;
  356.             if (Request.QueryString["f_id"] != null)
  357.             {
  358.                 flow_id = Convert.ToInt32(Request.QueryString["f_id"]);
  359.             }
  360.             else if (Request.QueryString["o_id"] != null)
  361.             {
  362.                 flow_id = Convert.ToInt32(Request.QueryString["o_id"]);
  363.             }
  364.             string is_business = "";
  365.             DateMgr mgr = new DateMgr();
  366.             SqlCommand cmd = new SqlCommand("update OA_CH_APPROVEL_FORM_FLOW set is_check='Y', is_agree='" +
  367.                 RbAgree.SelectedValue + "', comment='" + TxtComment.Text.Replace("n", "<br>") + "', check_date='" + mgr.getDateTime() +
  368.                 "' where id=" + flow_id, conn);
  369.             cmd.Transaction = tx;
  370.             cmd.ExecuteNonQuery();
  371.             cmd = new SqlCommand("select form_id, is_business from OA_CH_APPROVEL_FORM_FLOW where id=" + flow_id, conn);
  372.             cmd.Transaction = tx;
  373.             SqlDataReader dr = cmd.ExecuteReader();
  374.             int form_id = 0;
  375.             if (dr.Read())
  376.             {
  377.                 form_id = Convert.ToInt32(dr["form_id"].ToString());
  378.                 is_business = dr["is_business"].ToString();                
  379.             }
  380.             dr.Close();
  381.             if (is_business.Equals("Y"))
  382.             {
  383.                 cmd = new SqlCommand("select max(step) from OA_CH_APPROVEL_FORM_FLOW where form_id=" + form_id + " and is_business='Y'", conn);
  384.                 cmd.Transaction = tx;
  385.                 int max_step = Convert.ToInt32(cmd.ExecuteScalar());
  386.                 cmd = new SqlCommand("select step from OA_CH_BUSINESS_FORM where id=" + form_id, conn);
  387.                 cmd.Transaction = tx;
  388.                 int step = Convert.ToInt32(cmd.ExecuteScalar());
  389.                 string total_result = "跑流程中";
  390.                 string time = "";
  391.                 if (max_step == step + 1)
  392.                 {
  393.                     if (RbAgree.SelectedValue.Equals("N"))
  394.                     {
  395.                         total_result = "不同意";
  396.                     }
  397.                     else
  398.                     {
  399.                         total_result = "同意";
  400.                     }
  401.                     time = mgr.getDateTime();
  402.                 }
  403.                 else
  404.                 {
  405.                     if (RbAgree.SelectedValue.Equals("N"))
  406.                     {
  407.                         total_result = "不同意";
  408.                         time = mgr.getDateTime();
  409.                     }
  410.                 }
  411.                 cmd = new SqlCommand("update OA_CH_BUSINESS_FORM set step=step+1, total_result='" +
  412.                     total_result + "', finish_date='" + time + "' where id=" + form_id, conn);
  413.                 cmd.Transaction = tx;
  414.                 cmd.ExecuteNonQuery();
  415.                 //mail
  416.                 ArrayList name1 = new ArrayList();
  417.                 ArrayList mail1 = new ArrayList();
  418.                 cmd = new SqlCommand("select top 1 a.email_work,a.emp_name from oa_employee as a inner join " +
  419.                    "OA_CH_APPROVEL_FORM_FLOW as b on b.operator_id=a.id left join OA_CH_BUSINESS_FORM as c " +
  420.                      "on b.form_id=c.id where b.step=c.step+1 and c.id=" + form_id + " order by position desc", conn);
  421.                 cmd.Transaction = tx;
  422.                 SqlDataReader dr3 = cmd.ExecuteReader();
  423.                 while (dr3.Read())
  424.                 {
  425.                     name1.Add(dr3["emp_name"].ToString());
  426.                     mail1.Add(dr3["email_work"].ToString());
  427.                     mail.mail_q(mail1[0], name1[0], TxtEmpName.Text, "中幹出差申請單");
  428.                 } dr3.Close();
  429.                 //   
  430.             }
  431.             else
  432.             {
  433.                 cmd = new SqlCommand("select max(step) from OA_CH_APPROVEL_FORM_FLOW where form_id=" + form_id + " and is_business='N'", conn);
  434.                 cmd.Transaction = tx;
  435.                 int max_step = Convert.ToInt32(cmd.ExecuteScalar());
  436.                 cmd = new SqlCommand("select step from OA_CH_OFF_FORM where id=" + form_id, conn);
  437.                 cmd.Transaction = tx;
  438.                 int step = Convert.ToInt32(cmd.ExecuteScalar());
  439.                 string total_result = "跑流程中";
  440.                 string time = "";
  441.                 if (max_step == step + 1)
  442.                 {
  443.                     if (RbAgree.SelectedValue.Equals("N"))
  444.                     {
  445.                         total_result = "不同意";
  446.                     }
  447.                     else
  448.                     {
  449.                         total_result = "同意";
  450.                     }
  451.                     time = mgr.getDateTime();
  452.                 }
  453.                 else
  454.                 {
  455.                     if (RbAgree.SelectedValue.Equals("N"))
  456.                     {
  457.                         total_result = "不同意";
  458.                         time = mgr.getDateTime();
  459.                     }
  460.                 }
  461.                 cmd = new SqlCommand("update OA_CH_OFF_FORM set step=step+1, total_result='" +
  462.                     total_result + "', finish_date='" + time + "' where id=" + form_id, conn);
  463.                 cmd.Transaction = tx;
  464.                 cmd.ExecuteNonQuery();
  465.                 //mail
  466.                 ArrayList name1 = new ArrayList();
  467.                 ArrayList mail1 = new ArrayList();
  468.                 cmd = new SqlCommand("select top 1 a.email_work,a.emp_name from oa_employee as a inner join " +
  469.                    "OA_CH_APPROVEL_FORM_FLOW as b on b.operator_id=a.id left join OA_CH_OFF_FORM as c " +
  470.                      "on b.form_id=c.id where b.step=c.step+1 and c.id=" + form_id + " order by position desc", conn);
  471.                 cmd.Transaction = tx;
  472.                 SqlDataReader dr3 = cmd.ExecuteReader();
  473.                 while (dr3.Read())
  474.                 {
  475.                     name1.Add(dr3["emp_name"].ToString());
  476.                     mail1.Add(dr3["email_work"].ToString());
  477.                     mail.mail_q(mail1[0], name1[0], TxtEmpName.Text, "中幹請假單");
  478.                 } dr3.Close();
  479.                 //   
  480.             }
  481.             tx.Commit();
  482.         }
  483.         catch (Exception ex)
  484.         {
  485.             Response.Write(ex.ToString());
  486.             tx.Rollback();
  487.         }
  488.         conn.Close();
  489.         try
  490.         {
  491.             Response.Redirect("finish_list.aspx");
  492.         }
  493.         catch (Exception ex)
  494.         {
  495.             Response.Write(ex.Message);
  496.         }
  497.     }
  498. }