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

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_my_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.             ApprovelList.DataKeyNames = new string[] { "id" };
  20.             if (Request.QueryString["a_id"] != null)
  21.             {
  22.                 PnlApprovel.Visible = true;
  23.                 FlowList.DataKeyNames = new string[] { "id" };
  24.                 this.SetData(Request.QueryString["a_id"]);
  25.                 this.CheckState(Request.QueryString["a_id"]);
  26.             }
  27.             if (Session["user"] != null)
  28.             {
  29.                 User user = (User)Session["user"];
  30.                 DepartmentId.Value = user.Department.Id.ToString();
  31.                 PositionId.Value = user.PositionId.ToString();
  32.             }
  33.         }
  34.     }
  35.     protected void CheckState(string id)
  36.     {
  37.         SqlConnection conn = dbConnection.getConnection();
  38.         conn.Open();
  39.         SqlCommand cmd = new SqlCommand("select state from OA_TW_APPROVEL_FORM where id=" + id, conn);
  40.         int state = Convert.ToInt32(cmd.ExecuteScalar().ToString());
  41.         State.Value = state.ToString();
  42.         if (state != 1)
  43.         {
  44.             FlowList.Visible = false;
  45.             Panel1.Visible = true;
  46.         }
  47.         conn.Close();
  48.     }
  49.     protected void SetData(string id)
  50.     {
  51.         SqlConnection conn = dbConnection.getConnection();
  52.         conn.Open();
  53.         SqlCommand cmd = new SqlCommand("select a.form_id, e.emp_name, e.emp_no, p.name position, " +
  54.             "d.name department, e1.emp_name delegate, t.name off_type, a.parenthesis, a.days, a.vacation_begin, " +
  55.             "a.vacation_end, vp.name vacation_place, fp1.name flight_go_depart, fp2.name flight_go_arrive, " +
  56.             "a.flight_go_time, a.flight_back_time, fp3.name flight_back_depart, fp4.name flight_back_arrive, " +
  57.             "a.business_begin, a.business_end, a.reason, a.apply_date, b.name business_place " +
  58.             "from OA_TW_APPROVEL_FORM a " +
  59.             "inner join OA_EMPLOYEE e on a.emp_id=e.id " +
  60.             "inner join OA_EMPLOYEE e1 on a.delegate_id=e1.id " +
  61.             "inner join OA_DEPARTMENT d on e.department_id=d.id " +
  62.             "inner join OA_EMPLOYEE_POSITION p on e.position=p.id " +
  63.             "inner join OA_TW_OFF_TYPE t on a.off_type=t.id " +
  64.             "inner join OA_VACATION_PLACE vp on a.vacation_place=vp.id " +
  65.             "inner join OA_FLIGHT_PLACE fp1 on a.flight_go_depart=fp1.id " +
  66.             "inner join OA_FLIGHT_PLACE fp2 on a.flight_go_arrive=fp2.id " +
  67.             "inner join OA_FLIGHT_PLACE fp3 on a.flight_back_depart=fp3.id " +
  68.             "inner join OA_FLIGHT_PLACE fp4 on a.flight_back_arrive=fp4.id " +
  69.             "inner join OA_BUSINESS_PLACE b on a.business_place=b.id where a.id=" + id, conn);
  70.         SqlDataReader dr = cmd.ExecuteReader();
  71.         if (dr.Read())
  72.         {
  73.             TxtFormNo.Text = dr["form_id"].ToString();
  74.             TxtEmpName.Text = dr["emp_name"].ToString();
  75.             TxtEmpNo.Text = dr["emp_no"].ToString();
  76.             TxtPosition.Text = dr["position"].ToString();
  77.             TxtDepartment.Text = dr["department"].ToString();
  78.             TxtDelegate.Text = dr["delegate"].ToString();
  79.             TxtOffType.Text = dr["off_type"].ToString();
  80.             TxtParenthesis.Text = dr["parenthesis"].ToString();
  81.             TxtDays.Text = dr["days"].ToString();
  82.             TxtVacationBegin.Text = dr["vacation_begin"].ToString();
  83.             TxtVacationEnd.Text = dr["vacation_end"].ToString();
  84.             TxtVacationPlace.Text = dr["vacation_place"].ToString();
  85.             TxtFlightGoDepart.Text = dr["flight_go_depart"].ToString();
  86.             TxtFlightGoArrive.Text = dr["flight_go_arrive"].ToString();
  87.             TxtFlightGoTime.Text = dr["flight_go_time"].ToString();
  88.             TxtFlightBackTime.Text = dr["flight_back_time"].ToString();
  89.             TxtFlightBackDepart.Text = dr["flight_back_depart"].ToString();
  90.             TxtFlightBackArrive.Text = dr["flight_back_arrive"].ToString();
  91.             TxtBusinessBegin.Text = dr["business_begin"].ToString();
  92.             TxtBusinessEnd.Text = dr["business_end"].ToString();
  93.             TxtReason.Text = dr["reason"].ToString();
  94.             TxtApplyDate.Text = dr["apply_date"].ToString();
  95.             TxtBusinessPlace.Text = dr["business_place"].ToString();
  96.         }
  97.         dr.Close();
  98.         conn.Close();
  99.     }
  100.     protected void ApprovelList_RowDataBound(object sender, GridViewRowEventArgs e)
  101.     {
  102.         //行高亮
  103.         if (e.Row.RowType == DataControlRowType.DataRow)
  104.         {
  105.             e.Row.Attributes.Add("onmouseover", "this.style.cursor='pointer';");
  106.             e.Row.Attributes.Add("onclick", "location.href='my_list.aspx?a_id=" + ApprovelList.DataKeys[e.Row.RowIndex].Value.ToString() + "'");
  107.         }
  108.     }
  109.     protected void FlowList_RowCreated(object sender, GridViewRowEventArgs e)
  110.     {
  111.         if (e.Row.RowType == DataControlRowType.DataRow)
  112.         {
  113.             SqlConnection conn = dbConnection.getConnection();
  114.             conn.Open();
  115.             SqlCommand cmd = new SqlCommand("select apply_type, is_check, is_agree, comment from "+
  116.                 "OA_TW_APPROVEL_FORM_FLOW where id="+FlowList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  117.             SqlDataReader dr = cmd.ExecuteReader();
  118.             if (dr.Read())
  119.             {
  120.                 Label label = (Label)e.Row.FindControl("LblApplyType");
  121.                 if (dr["apply_type"].ToString().Equals("1"))
  122.                 {
  123.                     label.Text = "會簽";
  124.                 }
  125.                 else if (dr["apply_type"].ToString().Equals("2"))
  126.                 {
  127.                     label.Text = "審批";
  128.                 }
  129.                 else if (dr["apply_type"].ToString().Equals("3"))
  130.                 {
  131.                     label.Text = "審批(代理)";
  132.                 }
  133.                 label = (Label)e.Row.FindControl("LblIsCheck");
  134.                 if (dr["is_check"].ToString().Equals("N"))
  135.                 {
  136.                     label.Text = "未處理";
  137.                 }
  138.                 else
  139.                 {
  140.                     label.Text = "已處理";
  141.                     label = (Label)e.Row.FindControl("LblIsAgree");
  142.                     if (dr["is_agree"].ToString().Equals("Y"))
  143.                     {
  144.                         label.Text = "已同意";
  145.                     }
  146.                     else
  147.                     {
  148.                         label.Text = "不同意";
  149.                     }
  150.                 }
  151.                 label = (Label)e.Row.FindControl("LblComment");
  152.                 label.Text = dr["comment"].ToString();
  153.             }
  154.             dr.Close();
  155.             conn.Close();
  156.         }
  157.     }
  158.     protected void BtnOk_Click(object sender, EventArgs e)
  159.     {
  160.         if (Request.QueryString["a_id"] != null)
  161.         {
  162.             string id = Request.QueryString["a_id"];
  163.             SqlConnection conn = dbConnection.getConnection();
  164.             conn.Open();
  165.             if (State.Value.Equals("2"))
  166.             {
  167.                 SqlTransaction tx = conn.BeginTransaction();
  168.                 try
  169.                 {
  170.                     SqlCommand cmd = new SqlCommand("update OA_TW_APPROVEL_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  171.                     cmd.Transaction = tx;
  172.                     cmd.ExecuteNonQuery();
  173.                     int flow_id = 1;
  174.                     cmd = new SqlCommand("select max(id) from OA_TW_APPROVEL_FORM_FLOW", conn);
  175.                     cmd.Transaction = tx;
  176.                     try
  177.                     {
  178.                         flow_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  179.                     }
  180.                     catch { }
  181.                     ArrayList main_ids = new ArrayList();
  182.                     cmd = new SqlCommand("select id from OA_FLOW_MAIN where department_id=" +
  183.                         DepartmentId.Value, conn);
  184.                     cmd.Transaction = tx;
  185.                     SqlDataReader dr = cmd.ExecuteReader();
  186.                     while (dr.Read())
  187.                     {
  188.                         main_ids.Add(dr["id"].ToString());
  189.                     }
  190.                     dr.Close();
  191.                     int flag = 0;
  192.                     int main_id = 0;
  193.                     for (int i = 0; i < main_ids.Count; i++)
  194.                     {
  195.                         cmd = new SqlCommand("select position_id from OA_FLOW_POSITION where main_id=" +
  196.                             main_ids[i], conn);
  197.                         cmd.Transaction = tx;
  198.                         dr = cmd.ExecuteReader();
  199.                         while (dr.Read())
  200.                         {
  201.                             if (dr["position_id"].ToString().Equals(PositionId.Value))
  202.                             {
  203.                                 flag = 1;
  204.                                 main_id = Convert.ToInt32(main_ids[i]);
  205.                             }
  206.                         }
  207.                         dr.Close();
  208.                         if (flag == 1)
  209.                         {
  210.                             break;
  211.                         }
  212.                     }
  213.                     if (main_id != 0)
  214.                     {
  215.                         ArrayList operator_ids = new ArrayList();
  216.                         cmd = new SqlCommand("select operator_id from OA_FLOW_DETAIL where main_id=" +
  217.                             main_id + " order by number", conn);
  218.                         cmd.Transaction = tx;
  219.                         dr = cmd.ExecuteReader();
  220.                         while (dr.Read())
  221.                         {
  222.                             operator_ids.Add(dr["operator_id"].ToString());
  223.                         }
  224.                         dr.Close();
  225.                         for (int i = 0; i < operator_ids.Count; i++)
  226.                         {
  227.                             cmd = new SqlCommand("insert into OA_TW_APPROVEL_FORM_FLOW(id, form_id, operator_id, " +
  228.                                 "apply_type, is_check, is_agree, comment, check_date, step)values(" +
  229.                                 flow_id + ", " + id + "," + operator_ids[i] + ",2,'N','N','',''," + (i + 2) + ")", conn);
  230.                             cmd.Transaction = tx;
  231.                             cmd.ExecuteNonQuery();
  232.                             flow_id++;
  233.                         }
  234.                         tx.Commit();
  235.                         Response.Redirect("my_list.aspx");
  236.                     }
  237.                     else
  238.                     {
  239.                         LblError.Text = "沒有找到相關處理流程, 請與管理員聯繫";
  240.                         tx.Rollback();
  241.                     }
  242.                 }
  243.                 catch (Exception ex)
  244.                 {
  245.                     Response.Write(ex.ToString());
  246.                     tx.Rollback();
  247.                 }
  248.             }
  249.             else
  250.             {
  251.                 SqlCommand cmd = new SqlCommand("update OA_TW_APPROVEL_FORM set state=1, total_result='跑流程中' where id=" + id, conn);
  252.                 cmd.ExecuteNonQuery();                
  253.             }
  254.             conn.Close();
  255.             ApprovelList.DataBind();
  256.             PnlApprovel.Visible = false;
  257.             PnlFlow.Visible = false;
  258.             Panel1.Visible = false;
  259.         }
  260.     }
  261.     protected void ApprovelList_RowCreated(object sender, GridViewRowEventArgs e)
  262.     {
  263.         if (e.Row.RowType == DataControlRowType.DataRow)
  264.         {
  265.             SqlConnection conn = dbConnection.getConnection();
  266.             conn.Open();
  267.             SqlCommand cmd = new SqlCommand("select total_result from OA_TW_APPROVEL_FORM where id=" +
  268.                 ApprovelList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  269.             LinkButton lbRevoke = (LinkButton)e.Row.FindControl("LbRevoke");
  270.             string total_result = cmd.ExecuteScalar().ToString();
  271.             if (total_result.Equals("跑流程中"))
  272.             {
  273.                 lbRevoke.Enabled = true;
  274.                 lbRevoke.CommandArgument = ApprovelList.DataKeys[e.Row.RowIndex].Value.ToString();
  275.                 lbRevoke.Click += new EventHandler(lbRevoke_Click);
  276.             }
  277.             else
  278.             {
  279.                 lbRevoke.OnClientClick = "";
  280.             }
  281.             conn.Close();
  282.         }
  283.     }
  284.     void lbRevoke_Click(object sender, EventArgs e)
  285.     {
  286.         LinkButton lbRevoke = (LinkButton)sender;
  287.         string id = lbRevoke.CommandArgument;
  288.         SqlConnection conn = dbConnection.getConnection();
  289.         conn.Open();
  290.         SqlTransaction tx = conn.BeginTransaction();
  291.         try
  292.         {
  293.             SqlCommand cmd = new SqlCommand("update OA_TW_APPROVEL_FORM set state=3, total_result='已撤銷' where id=" + id, conn);
  294.             cmd.Transaction = tx;
  295.             cmd.ExecuteNonQuery();
  296.             cmd = new SqlCommand("update OA_TW_APPROVEL_FORM_FLOW set is_check='N', is_agree='N', comment='', " +
  297.                 "check_date='' where form_id='" + id + "'", conn);
  298.             cmd.Transaction = tx;
  299.             cmd.ExecuteNonQuery();
  300.             tx.Commit();
  301.         }
  302.         catch (Exception ex)
  303.         {
  304.             Response.Write(ex.Message);
  305.             tx.Rollback();
  306.         }
  307.         conn.Close();
  308.         ApprovelList.DataBind();
  309.         PnlApprovel.Visible = false;
  310.         PnlFlow.Visible = false;
  311.         Panel1.Visible = false;
  312.     }
  313. }