deal_d.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. public partial class web_approvel_tw_deal_d : System.Web.UI.Page
  13. {
  14.     string name = "";
  15.     string d_start = "";
  16.     string d_end = "";
  17.     string hour = "";
  18.     string type = "";
  19.     protected void Page_Load(object sender, EventArgs e)
  20.     {
  21.         if (!IsPostBack)
  22.         {
  23.            // flg.Value = "0";
  24.             LoginDAO.CheckLogin(Session, Response, "../../", 2);
  25.           
  26.         }
  27.         if (Request.QueryString["f_id"] != null)
  28.         {
  29.             FlowList.DataKeyNames = new string[] { "id" };
  30.             PnlApprovel.Visible = true;
  31.             PnlDeal.Visible = true;
  32.             PnlFlow.Visible = true;
  33.             this.SetData(Request.QueryString["f_id"]);
  34.         }
  35.     }
  36.     protected void SetData(string id)
  37.     {
  38.         SqlConnection conn = dbConnection.getConnection();
  39.         conn.Open();
  40.         int form_id = 0;
  41.         SqlCommand cmd = new SqlCommand("select form_id from OA_TW_APPROVEL_FORM_FLOW where id=" + id, conn);
  42.         form_id = Convert.ToInt32(cmd.ExecuteScalar().ToString());
  43.         cmd = new SqlCommand("select a.form_id, e.emp_name, e.emp_no, p.name position, " +
  44.             "d.name department, e1.emp_name delegate, t.name off_type,t.id type, a.parenthesis, a.days, a.vacation_begin, " +
  45.             "a.vacation_end,a.days, vp.name vacation_place, fp1.name flight_go_depart, fp2.name flight_go_arrive, " +
  46.             "a.flight_go_time, a.flight_back_time, fp3.name flight_back_depart, fp4.name flight_back_arrive, " +
  47.             "a.business_begin, a.business_end, a.reason, a.apply_date, b.name business_place " +
  48.             "from OA_TW_APPROVEL_FORM a " +
  49.             "inner join OA_EMPLOYEE e on a.emp_id=e.id " +
  50.             "inner join OA_EMPLOYEE e1 on a.delegate_id=e1.id " +
  51.             "inner join OA_DEPARTMENT d on e.department_id=d.id " +
  52.             "inner join OA_EMPLOYEE_POSITION p on e.position=p.id " +
  53.             "inner join OA_TW_OFF_TYPE t on a.off_type=t.id " +
  54.             "inner join OA_VACATION_PLACE vp on a.vacation_place=vp.id " +
  55.             "inner join OA_FLIGHT_PLACE fp1 on a.flight_go_depart=fp1.id " +
  56.             "inner join OA_FLIGHT_PLACE fp2 on a.flight_go_arrive=fp2.id " +
  57.             "inner join OA_FLIGHT_PLACE fp3 on a.flight_back_depart=fp3.id " +
  58.             "inner join OA_FLIGHT_PLACE fp4 on a.flight_back_arrive=fp4.id " +
  59.             "inner join OA_BUSINESS_PLACE b on a.business_place=b.id where a.id=" + form_id, conn);
  60.         SqlDataReader dr = cmd.ExecuteReader();
  61.         if (dr.Read())
  62.         {
  63.             TxtFormNo.Text = dr["form_id"].ToString();
  64.             TxtEmpName.Text = dr["emp_name"].ToString();
  65.             TxtEmpNo.Text = dr["emp_no"].ToString();
  66.             TxtPosition.Text = dr["position"].ToString();
  67.             TxtDepartment.Text = dr["department"].ToString();
  68.             TxtDelegate.Text = dr["delegate"].ToString();
  69.             TxtOffType.Text = dr["off_type"].ToString();
  70.             TxtParenthesis.Text = dr["parenthesis"].ToString();
  71.             TxtDays.Text = dr["days"].ToString();
  72.             TxtVacationBegin.Text = dr["vacation_begin"].ToString();
  73.             TxtVacationEnd.Text = dr["vacation_end"].ToString();
  74.             TxtVacationPlace.Text = dr["vacation_place"].ToString();
  75.             TxtFlightGoDepart.Text = dr["flight_go_depart"].ToString();
  76.             TxtFlightGoArrive.Text = dr["flight_go_arrive"].ToString();
  77.             TxtFlightGoTime.Text = dr["flight_go_time"].ToString();
  78.             TxtFlightBackTime.Text = dr["flight_back_time"].ToString();
  79.             TxtFlightBackDepart.Text = dr["flight_back_depart"].ToString();
  80.             TxtFlightBackArrive.Text = dr["flight_back_arrive"].ToString();
  81.             TxtBusinessBegin.Text = dr["business_begin"].ToString();
  82.             TxtBusinessEnd.Text = dr["business_end"].ToString();
  83.             TxtReason.Text = dr["reason"].ToString();
  84.             TxtApplyDate.Text = dr["apply_date"].ToString();
  85.             TxtBusinessPlace.Text = dr["business_place"].ToString();
  86.             name = dr["emp_name"].ToString();
  87.             if (dr["type"].ToString().Equals("1"))
  88.             {
  89.                 d_start = dr["business_begin"].ToString();
  90.                 d_end = dr["business_end"].ToString();
  91.                 hour = dr["days"].ToString();
  92.                 type = dr["off_type"].ToString();
  93.             }
  94.             else
  95.             {
  96.                 d_start = dr["vacation_begin"].ToString();
  97.                 d_end = dr["vacation_end"].ToString();
  98.                 hour = dr["days"].ToString();
  99.                 type = dr["off_type"].ToString();
  100.             }
  101.         }
  102.         dr.Close();
  103.         conn.Close();
  104.     }
  105.     protected void BtnOk_Click(object sender, EventArgs e)
  106.     {
  107.         SqlConnection conn = dbConnection.getConnection();
  108.         conn.Open();
  109.         SqlTransaction tx = conn.BeginTransaction();
  110.         try
  111.         {
  112.             DateMgr mgr = new DateMgr();
  113.             SqlCommand cmd = new SqlCommand("select * from oa_employee");
  114.             /*if (flg.Value.Equals("1"))
  115.             {
  116.                 cmd = new SqlCommand("update OA_TW_APPROVEL_FORM_FLOW set is_check='Y', is_agree='" +
  117.                     RbAgree.SelectedValue + "', comment='" + TxtComment.Text.Replace("n", "<br>") +
  118.                     "', check_date='" + mgr.getDateTime() + "',operator_id='" + Session["user_id"] +
  119.                     "',apply_type='" + 3 + "' where id=" + Request.QueryString["f_id"], conn);
  120.             }
  121.             else
  122.             {*/
  123.                 cmd = new SqlCommand("update OA_TW_APPROVEL_FORM_FLOW set is_check='Y', is_agree='" +
  124.                     RbAgree.SelectedValue + "', comment='" + TxtComment.Text.Replace("n", "<br>") + "', check_date='" + mgr.getDateTime() +
  125.                     "' where id=" + Request.QueryString["f_id"], conn);
  126.            // }
  127.             cmd.Transaction = tx;
  128.             cmd.ExecuteNonQuery();
  129.             cmd = new SqlCommand("select form_id from OA_TW_APPROVEL_FORM_FLOW where id=" + Request.QueryString["f_id"], conn);
  130.             cmd.Transaction = tx;
  131.             int form_id = Convert.ToInt32(cmd.ExecuteScalar());
  132.             cmd = new SqlCommand("select max(step) from OA_TW_APPROVEL_FORM_FLOW where form_id=" + form_id, conn);
  133.             cmd.Transaction = tx;
  134.             int max_step = Convert.ToInt32(cmd.ExecuteScalar());
  135.             cmd = new SqlCommand("select step from OA_TW_APPROVEL_FORM where id=" + form_id, conn);
  136.             cmd.Transaction = tx;
  137.             int step = Convert.ToInt32(cmd.ExecuteScalar());
  138.             string total_result = "跑流程中";
  139.             string time = "";
  140.             if (max_step == step + 1)
  141.             {
  142.                 if (RbAgree.SelectedValue.Equals("N"))
  143.                 {
  144.                     total_result = "不同意";
  145.                 }
  146.                 else
  147.                 {
  148.                     total_result = "同意";
  149.                     //mail.mail_tw(name, d_start, d_end, hour, type);
  150.                     // Response.Write(d_start);
  151.                 }
  152.                 time = mgr.getDateTime();
  153.             }
  154.             else
  155.             {
  156.                 if (RbAgree.SelectedValue.Equals("N"))
  157.                 {
  158.                     total_result = "不同意";
  159.                     time = mgr.getDateTime();
  160.                 }
  161.             }
  162.             cmd = new SqlCommand("update OA_TW_APPROVEL_FORM set step=step+1, total_result='" +
  163.                 total_result + "', finish_date='" + time + "' where id=" + form_id, conn);
  164.             cmd.Transaction = tx;
  165.             cmd.ExecuteNonQuery();
  166.             ArrayList name1 = new ArrayList();
  167.             ArrayList mail1 = new ArrayList();
  168.             cmd = new SqlCommand("select top 1 a.email_work,a.emp_name from oa_employee as a inner join " +
  169.                "OA_TW_APPROVEL_FORM_flow as b on b.operator_id=a.id left join OA_TW_APPROVEL_FORM as c " +
  170.                  "on b.form_id=c.id where b.step=c.step+1 and c.id=" + form_id + " order by position desc", conn);
  171.             cmd.Transaction = tx;
  172.             SqlDataReader dr3 = cmd.ExecuteReader();
  173.             while (dr3.Read())
  174.             {
  175.                 name1.Add(dr3["emp_name"].ToString());
  176.                 mail1.Add(dr3["email_work"].ToString());
  177.                 //mail.mail_q(mail1[0], name1[0], TxtEmpName.Text, "臺幹差假單");
  178.             } dr3.Close();
  179.             //   
  180.             tx.Commit();
  181.            // Response.Write("<script>window.href='deal_list.aspx'</script>");
  182.            //  Response.Write("<script>window.close();</script>");
  183.             
  184.         }
  185.         catch (Exception ex)
  186.         {
  187.             Response.Write(ex.ToString());
  188.             //   tx.Rollback();
  189.         }
  190.         conn.Close();
  191.       //  try
  192.       //  {
  193.       //      Response.Write("<script>mainFrame5.location.href='deal_list.aspx'</script>");
  194.            Response.Write("<script>window.close();</script>");
  195.      //   }
  196.      //   catch
  197.      //   {
  198.      //       Response.Write("wrong");
  199.      //   }   
  200.        
  201.         
  202.     }
  203.     
  204.     protected void FlowList_RowCreated(object sender, GridViewRowEventArgs e)
  205.     {
  206.         if (e.Row.RowType == DataControlRowType.DataRow)
  207.         {
  208.             SqlConnection conn = dbConnection.getConnection();
  209.             conn.Open();
  210.             SqlCommand cmd = new SqlCommand("select apply_type, is_check, is_agree, comment from " +
  211.                 "OA_TW_APPROVEL_FORM_FLOW where  id=" + FlowList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  212.             SqlDataReader dr = cmd.ExecuteReader();
  213.             while (dr.Read())
  214.             {
  215.                 Label label = (Label)e.Row.FindControl("LblApplyType");
  216.                 if (dr["apply_type"].ToString().Equals("1"))
  217.                 {
  218.                     label.Text = "會簽";
  219.                 }
  220.                 else if (dr["apply_type"].ToString().Equals("2"))
  221.                 {
  222.                     label.Text = "審批";
  223.                 }
  224.                 else if (dr["apply_type"].ToString().Equals("3"))
  225.                 {
  226.                     label.Text = "審批(代理)";
  227.                 }
  228.                 label = (Label)e.Row.FindControl("LblIsCheck");
  229.                 if (dr["is_check"].ToString().Equals("N"))
  230.                 {
  231.                     label.Text = "未處理";
  232.                 }
  233.                 else
  234.                 {
  235.                     label.Text = "已處理";
  236.                     label = (Label)e.Row.FindControl("LblIsAgree");
  237.                     if (dr["is_agree"].ToString().Equals("Y"))
  238.                     {
  239.                         label.Text = "已同意";
  240.                     }
  241.                     else
  242.                     {
  243.                         label.Text = "不同意";
  244.                     }
  245.                 }
  246.                 label = (Label)e.Row.FindControl("LblComment");
  247.                 label.Text = dr["comment"].ToString();
  248.             }
  249.             dr.Close();
  250.             conn.Close();
  251.         }
  252.     }
  253.     protected void RbAgree_SelectedIndexChanged(object sender, EventArgs e)
  254.     {
  255.         if (TxtComment.Text.Equals("已同意") || TxtComment.Text.Equals("不同意"))
  256.         {
  257.             if (RbAgree.SelectedValue.Equals("Y"))
  258.             {
  259.                 TxtComment.Text = "已同意";
  260.             }
  261.             else
  262.             {
  263.                 TxtComment.Text = "不同意";
  264.             }
  265.         }
  266.     }
  267. }