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

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_personnel_curricula_vitae_approvel_flow : 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.             FlowWizard.ActiveStepIndex = 0;
  20.             if (Session["p_department_id"] != null)
  21.             {
  22.                 DepartmentId.Value = Session["p_department_id"].ToString();
  23.                 SqlConnection conn = dbConnection.getConnection();
  24.                 conn.Open();
  25.                 SqlCommand cmd = new SqlCommand("select name from OA_DEPARTMENT where id="+DepartmentId.Value, conn);
  26.                 try
  27.                 {
  28.                     TxtDepartment.Text = cmd.ExecuteScalar().ToString();
  29.                 }
  30.                 catch { }
  31.                 conn.Close();
  32.             }
  33.             DetailList.DataKeyNames = new string[] { "id" };
  34.         }
  35.     }
  36.     protected void FlowWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
  37.     {
  38.         if (FlowWizard.ActiveStepIndex == 0)
  39.         {
  40.             int flag = 0;
  41.             ArrayList position_ids = new ArrayList();
  42.             for (int i = 0; i < ChkPosition.Items.Count; i++)
  43.             {
  44.                 if (ChkPosition.Items[i].Selected)
  45.                 {
  46.                     flag = 1;
  47.                     position_ids.Add(ChkPosition.Items[i].Value.ToString());
  48.                 }
  49.             }
  50.             if (flag == 0)
  51.             {
  52.                 Response.Write("<script language='javascript'>alert('請選擇職位');</script>");
  53.                 e.Cancel = true;
  54.             }
  55.             else
  56.             {
  57.                 SqlConnection conn = dbConnection.getConnection();
  58.                 conn.Open();
  59.                 SqlTransaction tx = conn.BeginTransaction();
  60.                 try
  61.                 {
  62.                     if (MainId.Value.Equals("0"))
  63.                     {
  64.                         //新增
  65.                         int main_id = 1;
  66.                         SqlCommand cmd = new SqlCommand("select max(id) from OA_FLOW_MAIN", conn);
  67.                         cmd.Transaction = tx;
  68.                         try
  69.                         {
  70.                             main_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  71.                         }
  72.                         catch { }
  73.                         cmd = new SqlCommand("insert into OA_FLOW_MAIN(id, department_id)values(" + main_id
  74.                             + "," + DepartmentId.Value + ")", conn);
  75.                         cmd.Transaction = tx;
  76.                         cmd.ExecuteNonQuery();
  77.                         for (int i = 0; i < position_ids.Count; i++)
  78.                         {
  79.                             cmd = new SqlCommand("insert into OA_FLOW_POSITION(main_id, position_id)values(" +
  80.                                 main_id + "," + position_ids[i] + ")", conn);
  81.                             cmd.Transaction = tx;
  82.                             cmd.ExecuteNonQuery();
  83.                         }
  84.                         tx.Commit();
  85.                         MainId.Value = main_id.ToString();
  86.                     }
  87.                     else
  88.                     { 
  89.                         //编辑
  90.                         SqlCommand cmd = new SqlCommand("delete from OA_FLOW_POSITION where main_id=" + MainId.Value, conn);
  91.                         cmd.Transaction = tx;
  92.                         cmd.ExecuteNonQuery();
  93.                         for (int i = 0; i < position_ids.Count; i++)
  94.                         {
  95.                             cmd = new SqlCommand("insert into OA_FLOW_POSITION(main_id, position_id)values(" +
  96.                                 MainId.Value + "," + position_ids[i] + ")", conn);
  97.                             cmd.Transaction = tx;
  98.                             cmd.ExecuteNonQuery();
  99.                         }
  100.                         tx.Commit();
  101.                     }
  102.                 }
  103.                 catch (Exception ex)
  104.                 {
  105.                     tx.Rollback();
  106.                     Response.Write(ex.Message);
  107.                 }
  108.                 conn.Close();
  109.                 DetailList.DataKeyNames = new string[] { "id" };
  110.                 DetailList.DataBind();
  111.                 this.SetEmpty();
  112.             }
  113.         }
  114.     }
  115.     protected void BtnSaveDetail_Click(object sender, EventArgs e)
  116.     {
  117.         if (this.CheckValidate() && !MainId.Value.Equals("0"))
  118.         {
  119.             SqlConnection conn = dbConnection.getConnection();
  120.             conn.Open();
  121.             if (DetailId.Value.Equals("0"))
  122.             {
  123.                 int detail_id = 1;
  124.                 SqlCommand cmd = new SqlCommand("select max(id) from OA_FLOW_DETAIL", conn);
  125.                 try
  126.                 {
  127.                     detail_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  128.                 }
  129.                 catch { }
  130.                 cmd = new SqlCommand("insert into OA_FLOW_DETAIL(id, main_id, operator_id, number) values (" +
  131.                     detail_id + "," + MainId.Value + ",'" + OperatorId.Value + "','" + TxtNumber.Text + "')", conn);
  132.                 cmd.ExecuteNonQuery();
  133.             }
  134.             else
  135.             {
  136.                 SqlCommand cmd = new SqlCommand("update OA_FLOW_DETAIL set operator_id='" + OperatorId.Value + "', " +
  137.                     "number='" + TxtNumber.Text + "' where id=" + DetailId.Value, conn);
  138.                 cmd.ExecuteNonQuery();
  139.             }
  140.             conn.Close();
  141.             this.SetEmpty();
  142.             DetailList.DataBind();
  143.             MainList.DataBind();
  144.         }
  145.     }
  146.     protected void SetEmpty()
  147.     {
  148.         TxtNumber.Text = "";
  149.         OperatorId.Value = "0";
  150.         TxtOperator.Text = "";
  151.         DetailId.Value = "0";
  152.         LblError.Text = "";
  153.     }
  154.     protected bool CheckValidate()
  155.     {
  156.         if (TxtNumber.Text.Trim().Equals(""))
  157.         {
  158.             LblError.Text = "編號不能為空";
  159.             return false;
  160.         }
  161.         else
  162.         {
  163.             try
  164.             {
  165.                 int number = Convert.ToInt32(TxtNumber.Text.Trim());
  166.             }
  167.             catch
  168.             {
  169.                 LblError.Text = "編號必須為數字";
  170.                 return false;
  171.             }
  172.         }
  173.         if (OperatorId.Value.Equals("0"))
  174.         {
  175.             LblError.Text = "辦理人不能為空";
  176.             return false;
  177.         }
  178.         return true;
  179.     }
  180.     protected void DetailList_RowDataBound(object sender, GridViewRowEventArgs e)
  181.     {
  182.         //
  183.         if (e.Row.RowType == DataControlRowType.DataRow)
  184.         {
  185.             e.Row.Cells[e.Row.Cells.Count - 1].Attributes.Add("onclick", "return confirm('確定删除嗎?')");
  186.         }
  187.     }
  188.     protected void DetailList_RowCreated(object sender, GridViewRowEventArgs e)
  189.     {
  190.         if (e.Row.RowType == DataControlRowType.DataRow)
  191.         {
  192.             try
  193.             {
  194.                 LinkButton btn = (LinkButton)e.Row.FindControl("LbEdit");
  195.                 btn.CommandArgument = DetailList.DataKeys[e.Row.RowIndex].Value.ToString();
  196.             }
  197.             catch
  198.             {
  199.             }
  200.         }
  201.     }
  202.     protected void DetailList_RowCommand(object sender, GridViewCommandEventArgs e)
  203.     {
  204.         if (e.CommandName.Equals("EditData"))
  205.         {
  206.             string id = e.CommandArgument.ToString();
  207.             this.SetValue(id);
  208.         }
  209.     }
  210.     protected void SetValue(string id)
  211.     {
  212.         SqlConnection conn = dbConnection.getConnection();
  213.         conn.Open();
  214.         SqlCommand cmd = new SqlCommand("select d.number, d.operator_id, e.emp_name, e.emp_no, p.name position "+
  215.             "from OA_FLOW_DETAIL d inner join OA_EMPLOYEE e on d.operator_id=e.id inner join "+
  216.             "OA_EMPLOYEE_POSITION p on e.position=p.id where d.id=" + id, conn);
  217.         SqlDataReader dr = cmd.ExecuteReader();
  218.         if (dr.Read())
  219.         {
  220.             TxtNumber.Text = dr["number"].ToString();
  221.             OperatorId.Value = dr["operator_id"].ToString();
  222.             TxtOperator.Text = dr["emp_no"].ToString() + " " + dr["emp_name"].ToString() + dr["position"].ToString();
  223.             DetailId.Value = id;
  224.         }
  225.         dr.Close();
  226.         conn.Close();
  227.     }
  228.     protected void FlowWizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
  229.     {
  230.         SqlConnection conn = dbConnection.getConnection();
  231.         conn.Open();
  232.         if (!MainId.Value.Equals("0"))
  233.         {
  234.             SqlCommand cmd = new SqlCommand("select count(id) from OA_FLOW_DETAIL where main_id=" + MainId.Value, conn);
  235.             int count = Convert.ToInt32(cmd.ExecuteScalar().ToString());
  236.             if (count == 0)
  237.             {
  238.                 Response.Write("<script language='javascript'>alert('請至少添加一個流程')</script>");
  239.                 e.Cancel = true;
  240.             }
  241.             else
  242.             {
  243.                 MainList.DataBind();
  244.                 FlowWizard.Visible = false;
  245.             }
  246.         } 
  247.         else
  248.         {
  249.             MainList.DataBind();
  250.             FlowWizard.Visible = false;
  251.         }
  252.         conn.Close();
  253.     }
  254.     protected void MainList_RowCreated(object sender, GridViewRowEventArgs e)
  255.     {
  256.         if (e.Row.RowType == DataControlRowType.DataRow)
  257.         {
  258.             string id = MainList.DataKeys[e.Row.RowIndex].Value.ToString();
  259.             SqlConnection conn = dbConnection.getConnection();
  260.             conn.Open();
  261.             string position = "";
  262.             string position_ids = "";
  263.             SqlCommand cmd = new SqlCommand("select f.position_id, p.name position from OA_FLOW_POSITION f inner join " +
  264.                 "OA_EMPLOYEE_POSITION p on f.position_id=p.id where f.main_id=" + id, conn);
  265.             SqlDataReader dr = cmd.ExecuteReader();
  266.             while (dr.Read())
  267.             {
  268.                 position_ids = position_ids + dr["position_id"].ToString() + ",";
  269.                 position = position + dr["position"].ToString() + ";";
  270.             }
  271.             dr.Close();
  272.             if (position.Length > 0)
  273.             {
  274.                 LinkButton btn = (LinkButton)e.Row.FindControl("LbPosition");
  275.                 btn.Text = position.Substring(0, position.Length - 1);
  276.                 btn.CommandArgument = MainList.DataKeys[e.Row.RowIndex].Value.ToString();
  277.             }
  278.             PositionIds.Value = position_ids;
  279.             conn.Close();
  280.         }
  281.     }
  282.     protected void MainList_RowCommand(object sender, GridViewCommandEventArgs e)
  283.     {
  284.         if (e.CommandName.Equals("EditData"))
  285.         {
  286.             for (int i = 0; i < ChkPosition.Items.Count; i++)
  287.             {
  288.                 ChkPosition.Items[i].Selected = false;
  289.             }
  290.             string id = e.CommandArgument.ToString();
  291.             MainId.Value = id;
  292.             SqlConnection conn = dbConnection.getConnection();
  293.             conn.Open();
  294.             SqlCommand cmd = new SqlCommand("select position_id from OA_FLOW_POSITION where main_id=" + id, conn);
  295.             SqlDataReader dr = cmd.ExecuteReader();
  296.             while (dr.Read())
  297.             {
  298.                 string position_id = dr["position_id"].ToString();
  299.                 for (int i = 0; i < ChkPosition.Items.Count; i++)
  300.                 {
  301.                     if (ChkPosition.Items[i].Value.Equals(position_id))
  302.                     {
  303.                         ChkPosition.Items[i].Selected = true;
  304.                     }
  305.                 }
  306.             }
  307.             dr.Close();
  308.             conn.Close();
  309.             FlowWizard.ActiveStepIndex = 0;
  310.             FlowWizard.Visible = true;
  311.         }
  312.     }
  313.     protected void MainList_RowDataBound(object sender, GridViewRowEventArgs e)
  314.     {
  315.         if (e.Row.RowType == DataControlRowType.DataRow)
  316.         {
  317.             e.Row.Cells[e.Row.Cells.Count - 1].Attributes.Add("onclick", "return confirm('確定删除嗎?')");
  318.         }
  319.     }
  320.     protected void BtnAdd_Click(object sender, EventArgs e)
  321.     {
  322.         this.SetEmpty();
  323.     }
  324.     protected void BtnAddMain_Click(object sender, EventArgs e)
  325.     {
  326.         this.SetEmpty();
  327.         FlowWizard.Visible = true;
  328.         FlowWizard.ActiveStepIndex = 0;
  329.         MainId.Value = "0";
  330.         for (int i = 0; i < ChkPosition.Items.Count; i++)
  331.         {
  332.             ChkPosition.Items[i].Selected = false;
  333.         }
  334.     }
  335. }