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

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. using System.Net.Mail;
  13. using System.Net;
  14. using System.Net.Sockets;
  15. public partial class web_approvel_tw_deal_list : System.Web.UI.Page
  16. {
  17.     
  18.     ArrayList b_d_people = new ArrayList();
  19.     protected void Page_Load(object sender, EventArgs e)
  20.     {
  21.        
  22.         if (!IsPostBack)
  23.         {
  24.             flg.Value = "0";
  25.             LoginDAO.CheckLogin(Session, Response, "../../", 2);
  26.             this.SetTable();
  27.            
  28.            
  29.         }
  30.         if (Request.QueryString["f_id"] != null)
  31.         {
  32.             FlowList.DataKeyNames = new string[] { "id" };
  33.             PnlApprovel.Visible = true;
  34.             PnlDeal.Visible = true;
  35.             PnlFlow.Visible = true;
  36.             this.SetData(Request.QueryString["f_id"]);
  37.         }
  38.     }
  39.     
  40.     protected void SetTable()
  41.     {
  42.        
  43.         SqlConnection conn = dbConnection.getConnection();
  44.         conn.Open();
  45.         ArrayList d_people = new ArrayList();
  46.         
  47.         string user_id="0";
  48.         if (Session["user_id"] != null)
  49.         {
  50.             user_id = Session["user_id"].ToString();
  51.         }
  52.        /* //判断是否为代理人
  53.         SqlCommand cmd = new SqlCommand("select d_people,b_d_people from oa_delegate where  s_date<=convert(varchar, getdate(), 120)"+
  54.             " and e_date>=convert(varchar, getdate(), 120) and d_people="+Session["user_id"],conn);
  55.         SqlDataReader dr1 = cmd.ExecuteReader();
  56.         while (dr1.Read()) {
  57.            
  58.             d_people.Add(dr1["d_people"].ToString());
  59.             b_d_people.Add(dr1["b_d_people"].ToString());
  60.         }
  61.         //如果有代理,显示被代理人的表单给代理人看
  62.         if (dr1.HasRows) {
  63.             
  64.             
  65.             for (int i = 0; i < b_d_people.Count; i++)
  66.             {
  67.                 flg.Value = "1";
  68.                 cmd = new SqlCommand("SELECT f.id, f.step f_step, a.step a_step, t.name off_type, e.emp_name, a.apply_date " +
  69.                     "FROM dbo.OA_TW_APPROVEL_FORM_FLOW AS f INNER JOIN dbo.OA_TW_APPROVEL_FORM AS a ON f.form_id = a.id " +
  70.                     "INNER JOIN dbo.OA_EMPLOYEE AS e ON a.emp_id = e.id inner join OA_TW_OFF_TYPE t on a.off_type=t.id " +
  71.                     "WHERE (f.operator_id = " + user_id + ") AND (f.is_check = 'N') or (f.operator_id = " + b_d_people[i] + ") AND (f.is_check = 'N')" +
  72.                     " order by a.apply_date desc", conn);
  73.             }
  74.         }
  75.         //否则只显示自己的表单
  76.         else
  77.         {*/
  78.            SqlCommand cmd = new SqlCommand("SELECT f.id, f.step f_step,f.form_id, a.step a_step, t.name off_type, e.emp_name, a.apply_date " +
  79.             "FROM dbo.OA_TW_APPROVEL_FORM_FLOW AS f INNER JOIN dbo.OA_TW_APPROVEL_FORM AS a ON f.form_id = a.id " +
  80.             "INNER JOIN dbo.OA_EMPLOYEE AS e ON a.emp_id = e.id inner join OA_TW_OFF_TYPE t on a.off_type=t.id " +
  81.             "WHERE (f.operator_id = " + user_id + ") AND (f.is_check = 'N') and state=1 order by a.apply_date desc", conn);
  82.       //  }
  83.       //  dr1.Close();
  84.         SqlDataReader dr = cmd.ExecuteReader();
  85.         while (dr.Read())
  86.         {
  87.             int a_step = Convert.ToInt32(dr["a_step"].ToString()) + 1;
  88.             int f_step = Convert.ToInt32(dr["f_step"].ToString());
  89.             if (a_step == f_step)
  90.             {
  91.                 TblFlow.Visible = true;
  92.                 TableRow tr = new TableRow();
  93.                 TableCell td = new TableCell();
  94.                 td.BorderWidth = Unit.Pixel(1);
  95.                 td.Text = dr["emp_name"].ToString();
  96.                 tr.Cells.Add(td);
  97.                 td = new TableCell();
  98.                 td.BorderWidth = Unit.Pixel(1);
  99.                 td.Text = dr["emp_name"].ToString() + "的" + dr["off_type"].ToString() + "單";
  100.                 tr.Cells.Add(td);
  101.                 td = new TableCell();
  102.                 td.BorderWidth = Unit.Pixel(1);
  103.                 td.Text = dr["apply_date"].ToString();
  104.                 tr.Cells.Add(td);
  105.                
  106.                 td = new TableCell();
  107.                 td.BorderWidth = Unit.Pixel(1);
  108.                 HyperLink hl = new HyperLink();
  109.                 hl.Text = "查看";
  110.                 hl.NavigateUrl = "deal_list.aspx?f_id=" + dr["id"].ToString()+"&f_id1="+dr["form_id"].ToString();
  111.                 td.Controls.Add(hl);
  112.                 tr.Cells.Add(td);
  113.                 TblFlow.Rows.Add(tr);
  114.             }
  115.         }
  116.         dr.Close();
  117.        
  118.         conn.Close();
  119.     }
  120.   
  121.     protected void SetData(string id)
  122.     {
  123.         SqlConnection conn = dbConnection.getConnection();
  124.         conn.Open();
  125.         int form_id = 0;
  126.         SqlCommand cmd = new SqlCommand("select form_id from OA_TW_APPROVEL_FORM_FLOW where id="+id, conn);
  127.         form_id = Convert.ToInt32(cmd.ExecuteScalar().ToString());
  128.         cmd = new SqlCommand("select a.form_id, e.emp_name, e.emp_no, p.name position, " +
  129.             "d.name department, e1.emp_name delegate, t.name off_type, a.parenthesis, a.days, a.vacation_begin, " +
  130.             "a.vacation_end, vp.name vacation_place, fp1.name flight_go_depart, fp2.name flight_go_arrive, " +
  131.             "a.flight_go_time, a.flight_back_time, fp3.name flight_back_depart, fp4.name flight_back_arrive, " +
  132.             "a.business_begin, a.business_end, a.reason, a.apply_date, b.name business_place " +
  133.             "from OA_TW_APPROVEL_FORM a " +
  134.             "inner join OA_EMPLOYEE e on a.emp_id=e.id " +
  135.             "inner join OA_EMPLOYEE e1 on a.delegate_id=e1.id " +
  136.             "inner join OA_DEPARTMENT d on e.department_id=d.id " +
  137.             "inner join OA_EMPLOYEE_POSITION p on e.position=p.id " +
  138.             "inner join OA_TW_OFF_TYPE t on a.off_type=t.id " +
  139.             "inner join OA_VACATION_PLACE vp on a.vacation_place=vp.id " +
  140.             "inner join OA_FLIGHT_PLACE fp1 on a.flight_go_depart=fp1.id " +
  141.             "inner join OA_FLIGHT_PLACE fp2 on a.flight_go_arrive=fp2.id " +
  142.             "inner join OA_FLIGHT_PLACE fp3 on a.flight_back_depart=fp3.id " +
  143.             "inner join OA_FLIGHT_PLACE fp4 on a.flight_back_arrive=fp4.id " +
  144.             "inner join OA_BUSINESS_PLACE b on a.business_place=b.id where a.id=" + form_id, conn);
  145.         SqlDataReader dr = cmd.ExecuteReader();
  146.         if (dr.Read())
  147.         {
  148.             TxtFormNo.Text = dr["form_id"].ToString();
  149.             TxtEmpName.Text = dr["emp_name"].ToString();
  150.             TxtEmpNo.Text = dr["emp_no"].ToString();
  151.             TxtPosition.Text = dr["position"].ToString();
  152.             TxtDepartment.Text = dr["department"].ToString();
  153.             TxtDelegate.Text = dr["delegate"].ToString();
  154.             TxtOffType.Text = dr["off_type"].ToString();
  155.             TxtParenthesis.Text = dr["parenthesis"].ToString();
  156.             TxtDays.Text = dr["days"].ToString();
  157.             TxtVacationBegin.Text = dr["vacation_begin"].ToString();
  158.             TxtVacationEnd.Text = dr["vacation_end"].ToString();
  159.             TxtVacationPlace.Text = dr["vacation_place"].ToString();
  160.             TxtFlightGoDepart.Text = dr["flight_go_depart"].ToString();
  161.             TxtFlightGoArrive.Text = dr["flight_go_arrive"].ToString();
  162.             TxtFlightGoTime.Text = dr["flight_go_time"].ToString();
  163.             TxtFlightBackTime.Text = dr["flight_back_time"].ToString();
  164.             TxtFlightBackDepart.Text = dr["flight_back_depart"].ToString();
  165.             TxtFlightBackArrive.Text = dr["flight_back_arrive"].ToString();
  166.             TxtBusinessBegin.Text = dr["business_begin"].ToString();
  167.             TxtBusinessEnd.Text = dr["business_end"].ToString();
  168.             TxtReason.Text = dr["reason"].ToString();
  169.             TxtApplyDate.Text = dr["apply_date"].ToString();
  170.             TxtBusinessPlace.Text = dr["business_place"].ToString();
  171.         }
  172.         dr.Close();
  173.         conn.Close();
  174.     }
  175.   
  176.     protected void BtnOk_Click(object sender, EventArgs e)
  177.     {
  178.         SqlConnection conn = dbConnection.getConnection();
  179.         conn.Open();
  180.         SqlTransaction tx = conn.BeginTransaction();
  181.         try
  182.         {
  183.             DateMgr mgr = new DateMgr();
  184.             SqlCommand cmd = new SqlCommand("select * from oa_employee");
  185.             if (flg.Value.Equals("1"))
  186.             {
  187.                    cmd = new SqlCommand("update OA_TW_APPROVEL_FORM_FLOW set is_check='Y', is_agree='" +
  188.                        RbAgree.SelectedValue + "', comment='" + TxtComment.Text.Replace("n", "<br>") + 
  189.                        "', check_date='" + mgr.getDateTime() +"',operator_id='"+Session["user_id"]+
  190.                        "',apply_type='"+3+"' where id=" + Request.QueryString["f_id"], conn);
  191.             }
  192.             else 
  193.             {
  194.                 cmd = new SqlCommand("update OA_TW_APPROVEL_FORM_FLOW set is_check='Y', is_agree='" +
  195.                     RbAgree.SelectedValue + "', comment='" + TxtComment.Text.Replace("n", "<br>") + "', check_date='" + mgr.getDateTime() +
  196.                     "' where id=" + Request.QueryString["f_id"], conn);
  197.             }
  198.             cmd.Transaction = tx;
  199.             cmd.ExecuteNonQuery();
  200.             cmd = new SqlCommand("select form_id from OA_TW_APPROVEL_FORM_FLOW where id=" + Request.QueryString["f_id"], conn);
  201.             cmd.Transaction = tx;
  202.             int form_id = Convert.ToInt32(cmd.ExecuteScalar());
  203.             cmd = new SqlCommand("select max(step) from OA_TW_APPROVEL_FORM_FLOW where form_id=" + form_id, conn);
  204.             cmd.Transaction = tx;
  205.             int max_step = Convert.ToInt32(cmd.ExecuteScalar());
  206.             cmd = new SqlCommand("select step from OA_TW_APPROVEL_FORM where id=" + form_id, conn);
  207.             cmd.Transaction = tx;
  208.             int step = Convert.ToInt32(cmd.ExecuteScalar());
  209.             string total_result = "跑流程中";
  210.             string time = "";
  211.             if (max_step == step + 1)
  212.             {
  213.                 if (RbAgree.SelectedValue.Equals("N"))
  214.                 {
  215.                     total_result = "不同意";
  216.                 }
  217.                 else
  218.                 {
  219.                     total_result = "同意";
  220.                 }
  221.                 time = mgr.getDateTime();
  222.             }
  223.             else
  224.             {
  225.                 if (RbAgree.SelectedValue.Equals("N"))
  226.                 {
  227.                     total_result = "不同意";
  228.                     time = mgr.getDateTime();
  229.                 }
  230.             }
  231.             cmd = new SqlCommand("update OA_TW_APPROVEL_FORM set step=step+1, total_result='" +
  232.                 total_result + "', finish_date='" + time + "' where id=" + form_id, conn);
  233.             cmd.Transaction = tx;
  234.             cmd.ExecuteNonQuery();
  235.             
  236.            // tx.Commit();
  237.             //mail
  238.             ArrayList name1 = new ArrayList();
  239.             ArrayList mail1 = new ArrayList();
  240.             cmd = new SqlCommand("select top 1 a.email_work,a.emp_name from oa_employee as a inner join " +
  241.                "OA_TW_APPROVEL_FORM_flow as b on b.operator_id=a.id left join OA_TW_APPROVEL_FORM as c " +
  242.                  "on b.form_id=c.id where b.step=c.step+1 and c.id=" + form_id + " order by position desc", conn);
  243.             cmd.Transaction = tx;
  244.             SqlDataReader dr3 = cmd.ExecuteReader();
  245.             while (dr3.Read())
  246.             {
  247.                 name1.Add(dr3["emp_name"].ToString());
  248.                 mail1.Add(dr3["email_work"].ToString());
  249.                 mail.mail_q(mail1[0], name1[0], TxtEmpName.Text,"臺幹差假單");
  250.             } dr3.Close();
  251.             //   
  252.             tx.Commit();
  253.           
  254.         }
  255.         catch (Exception ex)
  256.         {
  257.             Response.Write(ex.ToString());
  258.          //   tx.Rollback();
  259.         }
  260.         conn.Close();
  261.         Response.Redirect("finish_list.aspx");
  262.     }
  263.     protected void FlowList_RowCreated(object sender, GridViewRowEventArgs e)
  264.     {    
  265.        
  266.         if (e.Row.RowType == DataControlRowType.DataRow)
  267.         {
  268.             SqlConnection conn = dbConnection.getConnection();
  269.             conn.Open();                   
  270.            
  271.                SqlCommand cmd = new SqlCommand("select apply_type, is_check, is_agree, comment from " +
  272.                    "OA_TW_APPROVEL_FORM_FLOW where  id=" + FlowList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  273.                 SqlDataReader dr = cmd.ExecuteReader();
  274.                 while (dr.Read())
  275.                 {
  276.                     Label label = (Label)e.Row.FindControl("LblApplyType");
  277.                     if (dr["apply_type"].ToString().Equals("1"))
  278.                     {
  279.                         label.Text = "會簽";
  280.                     }
  281.                     else if (dr["apply_type"].ToString().Equals("2"))
  282.                     {
  283.                         label.Text = "審批";
  284.                     }
  285.                     else if (dr["apply_type"].ToString().Equals("3"))
  286.                     {
  287.                         label.Text = "審批(代理)";
  288.                     }
  289.                     label = (Label)e.Row.FindControl("LblIsCheck");
  290.                     if (dr["is_check"].ToString().Equals("N"))
  291.                     {
  292.                         label.Text = "未處理";
  293.                     }
  294.                     else
  295.                     {
  296.                         label.Text = "已處理";
  297.                         label = (Label)e.Row.FindControl("LblIsAgree");
  298.                         if (dr["is_agree"].ToString().Equals("Y"))
  299.                         {
  300.                             label.Text = "已同意";
  301.                         }
  302.                         else
  303.                         {
  304.                             label.Text = "不同意";
  305.                         }
  306.                     }
  307.                     label = (Label)e.Row.FindControl("LblComment");
  308.                     label.Text = dr["comment"].ToString();
  309.                 }
  310.                 dr.Close();          
  311.             
  312.            
  313.             conn.Close();
  314.         }
  315.     }
  316.     protected void RbAgree_SelectedIndexChanged(object sender, EventArgs e)
  317.     {
  318.         if (TxtComment.Text.Equals("已同意") || TxtComment.Text.Equals("不同意"))
  319.         {
  320.             if (RbAgree.SelectedValue.Equals("Y"))
  321.             {
  322.                 TxtComment.Text = "已同意";
  323.             }
  324.             else
  325.             {
  326.                 TxtComment.Text = "不同意";
  327.             }
  328.         }
  329.     }
  330. }