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

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.             " WHERE (f.operator_id = " + user_id + ") AND (f.is_check = 'N')", 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], 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.     protected void RbAgree_SelectedIndexChanged(object sender, EventArgs e)
  333.     {
  334.         if (TxtComment.Text.Equals("已同意") || TxtComment.Text.Equals("不同意"))
  335.         {
  336.             if (RbAgree.SelectedValue.Equals("Y"))
  337.             {
  338.                 TxtComment.Text = "已同意";
  339.             }
  340.             else
  341.             {
  342.                 TxtComment.Text = "不同意";
  343.             }
  344.         }
  345.         this.SetTable(Convert.ToInt32(FormId.Value));
  346.     }
  347.     protected void BtnOk_Click(object sender, EventArgs e)
  348.     {
  349.         SqlConnection conn = dbConnection.getConnection();
  350.         conn.Open();
  351.         SqlTransaction tx = conn.BeginTransaction();
  352.         try
  353.         {
  354.             int flow_id = 0;
  355.             if (Request.QueryString["f_id"] != null)
  356.             {
  357.                 flow_id = Convert.ToInt32(Request.QueryString["f_id"]);
  358.             }
  359.             else if (Request.QueryString["o_id"] != null)
  360.             {
  361.                 flow_id = Convert.ToInt32(Request.QueryString["o_id"]);
  362.             }
  363.             string is_business = "";
  364.             DateMgr mgr = new DateMgr();
  365.             SqlCommand cmd = new SqlCommand("update OA_CH_APPROVEL_FORM_FLOW set is_check='Y', is_agree='" +
  366.                 RbAgree.SelectedValue + "', comment='" + TxtComment.Text.Replace("n", "<br>") + "', check_date='" + mgr.getDateTime() +
  367.                 "' where id=" + flow_id, conn);
  368.             cmd.Transaction = tx;
  369.             cmd.ExecuteNonQuery();
  370.             cmd = new SqlCommand("select form_id, is_business from OA_CH_APPROVEL_FORM_FLOW where id=" + flow_id, conn);
  371.             cmd.Transaction = tx;
  372.             SqlDataReader dr = cmd.ExecuteReader();
  373.             int form_id = 0;
  374.             if (dr.Read())
  375.             {
  376.                 form_id = Convert.ToInt32(dr["form_id"].ToString());
  377.                 is_business = dr["is_business"].ToString();                
  378.             }
  379.             dr.Close();
  380.             if (is_business.Equals("Y"))
  381.             {
  382.                 cmd = new SqlCommand("select max(step) from OA_CH_APPROVEL_FORM_FLOW where form_id=" + form_id + " and is_business='Y'", conn);
  383.                 cmd.Transaction = tx;
  384.                 int max_step = Convert.ToInt32(cmd.ExecuteScalar());
  385.                 cmd = new SqlCommand("select step from OA_CH_BUSINESS_FORM where id=" + form_id, conn);
  386.                 cmd.Transaction = tx;
  387.                 int step = Convert.ToInt32(cmd.ExecuteScalar());
  388.                 string total_result = "跑流程中";
  389.                 string time = "";
  390.                 if (max_step == step + 1)
  391.                 {
  392.                     if (RbAgree.SelectedValue.Equals("N"))
  393.                     {
  394.                         total_result = "不同意";
  395.                     }
  396.                     else
  397.                     {
  398.                         total_result = "同意";
  399.                     }
  400.                     time = mgr.getDateTime();
  401.                 }
  402.                 else
  403.                 {
  404.                     if (RbAgree.SelectedValue.Equals("N"))
  405.                     {
  406.                         total_result = "不同意";
  407.                         time = mgr.getDateTime();
  408.                     }
  409.                 }
  410.                 cmd = new SqlCommand("update OA_CH_BUSINESS_FORM set step=step+1, total_result='" +
  411.                     total_result + "', finish_date='" + time + "' where id=" + form_id, conn);
  412.                 cmd.Transaction = tx;
  413.                 cmd.ExecuteNonQuery();
  414.             }
  415.             else
  416.             {
  417.                 cmd = new SqlCommand("select max(step) from OA_CH_APPROVEL_FORM_FLOW where form_id=" + form_id + " and is_business='N'", conn);
  418.                 cmd.Transaction = tx;
  419.                 int max_step = Convert.ToInt32(cmd.ExecuteScalar());
  420.                 cmd = new SqlCommand("select step from OA_CH_OFF_FORM where id=" + form_id, conn);
  421.                 cmd.Transaction = tx;
  422.                 int step = Convert.ToInt32(cmd.ExecuteScalar());
  423.                 string total_result = "跑流程中";
  424.                 string time = "";
  425.                 if (max_step == step + 1)
  426.                 {
  427.                     if (RbAgree.SelectedValue.Equals("N"))
  428.                     {
  429.                         total_result = "不同意";
  430.                     }
  431.                     else
  432.                     {
  433.                         total_result = "同意";
  434.                     }
  435.                     time = mgr.getDateTime();
  436.                 }
  437.                 else
  438.                 {
  439.                     if (RbAgree.SelectedValue.Equals("N"))
  440.                     {
  441.                         total_result = "不同意";
  442.                         time = mgr.getDateTime();
  443.                     }
  444.                 }
  445.                 cmd = new SqlCommand("update OA_CH_OFF_FORM set step=step+1, total_result='" +
  446.                     total_result + "', finish_date='" + time + "' where id=" + form_id, conn);
  447.                 cmd.Transaction = tx;
  448.                 cmd.ExecuteNonQuery();
  449.             }
  450.             tx.Commit();
  451.         }
  452.         catch (Exception ex)
  453.         {
  454.             Response.Write(ex.ToString());
  455.             tx.Rollback();
  456.         }
  457.         conn.Close();
  458.         try
  459.         {
  460.             Response.Redirect("finish_list.aspx");
  461.         }
  462.         catch (Exception ex)
  463.         {
  464.             Response.Write(ex.Message);
  465.         }
  466.     }
  467. }