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

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