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

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