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

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_probation_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.         }
  34.     }
  35.     protected void FlowWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
  36.     {
  37.         if (FlowWizard.ActiveStepIndex == 0)
  38.         {
  39.             int flag = 0;
  40.             ArrayList position_ids = new ArrayList();
  41.             for (int i = 0; i < ChkPosition.Items.Count; i++)
  42.             {
  43.                 if (ChkPosition.Items[i].Selected)
  44.                 {
  45.                     flag = 1;
  46.                     position_ids.Add(ChkPosition.Items[i].Value.ToString());
  47.                 }
  48.             }
  49.             if (flag == 0)
  50.             {
  51.                 Response.Write("<script language='javascript'>alert('請選擇職位');</script>");
  52.                 e.Cancel = true;
  53.             }
  54.             else
  55.             {
  56.                 SqlConnection conn = dbConnection.getConnection();
  57.                 conn.Open();
  58.                 SqlTransaction tx = conn.BeginTransaction();
  59.                 try
  60.                 {
  61.                     if (MainId.Value.Equals("0"))
  62.                     {
  63.                         //新增
  64.                         int main_id = 1;
  65.                         SqlCommand cmd = new SqlCommand("select max(id) from OA_PROBATION_FLOW_MAIN", conn);
  66.                         cmd.Transaction = tx;
  67.                         try
  68.                         {
  69.                             main_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  70.                         }
  71.                         catch { }
  72.                         cmd = new SqlCommand("insert into OA_PROBATION_FLOW_MAIN(id, department_id)values(" + main_id
  73.                             + "," + DepartmentId.Value + ")", conn);
  74.                         cmd.Transaction = tx;
  75.                         cmd.ExecuteNonQuery();
  76.                         for (int i = 0; i < position_ids.Count; i++)
  77.                         {
  78.                             cmd = new SqlCommand("insert into OA_PROBATION_FLOW_POSITION(main_id, position_id)values(" +
  79.                                 main_id + "," + position_ids[i] + ")", conn);
  80.                             cmd.Transaction = tx;
  81.                             cmd.ExecuteNonQuery();
  82.                         }
  83.                         tx.Commit();
  84.                         MainId.Value = main_id.ToString();
  85.                     }
  86.                     else
  87.                     {
  88.                         //编辑
  89.                         SqlCommand cmd = new SqlCommand("delete from OA_PROBATION_FLOW_POSITION where main_id=" + MainId.Value, conn);
  90.                         cmd.Transaction = tx;
  91.                         cmd.ExecuteNonQuery();
  92.                         for (int i = 0; i < position_ids.Count; i++)
  93.                         {
  94.                             cmd = new SqlCommand("insert into OA_PROBATION_FLOW_POSITION(main_id, position_id)values(" +
  95.                                 MainId.Value + "," + position_ids[i] + ")", conn);
  96.                             cmd.Transaction = tx;
  97.                             cmd.ExecuteNonQuery();
  98.                         }
  99.                         tx.Commit();
  100.                     }
  101.                 }
  102.                 catch (Exception ex)
  103.                 {
  104.                     tx.Rollback();
  105.                     Response.Write(ex.Message);
  106.                 }
  107.                 conn.Close();
  108.                 this.SetEmpty();
  109.             }
  110.         }
  111.     }
  112.     protected void BtnSaveDetail_Click(object sender, EventArgs e)
  113.     {
  114.         if (this.CheckValidate() && !MainId.Value.Equals("0"))
  115.         {
  116.             SqlConnection conn = dbConnection.getConnection();
  117.             conn.Open();
  118.             //if (DetailId.Value.Equals("0"))
  119.             //{
  120.             //    int detail_id = 1;
  121.             //    SqlCommand cmd = new SqlCommand("select max(id) from OA_PROBATION_FLOW_DETAIL", conn);
  122.             //    try
  123.             //    {
  124.             //        detail_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  125.             //    }
  126.             //    catch { }
  127.             //    cmd = new SqlCommand("insert into OA_PROBATION_FLOW_DETAIL(id, main_id, operator_id, number) values (" +
  128.             //        detail_id + "," + MainId.Value + ",'" + OperatorId.Value + "','" + TxtNumber.Text + "')", conn);
  129.             //    cmd.ExecuteNonQuery();
  130.             //}
  131.             //else
  132.             //{
  133.             //    SqlCommand cmd = new SqlCommand("update OA_PROBATION_FLOW_DETAIL set operator_id='" + OperatorId.Value + "', " +
  134.             //        "number='" + TxtNumber.Text + "' where id=" + DetailId.Value, conn);
  135.             //    cmd.ExecuteNonQuery();
  136.             //}
  137.             conn.Close();
  138.             this.SetEmpty();
  139.             MainList.DataBind();
  140.         }
  141.     }
  142.     protected void SetEmpty()
  143.     {
  144.         LblError.Text = "";
  145.     }
  146.     protected bool CheckValidate()
  147.     {
  148.         if (OperatorId1.Value.Equals("0") || OperatorId2.Value.Equals("0"))
  149.         {
  150.             LblError.Text = "辦理人不能為空";
  151.             return false;
  152.         }
  153.         return true;
  154.     }
  155.     protected void SetValue(string id)
  156.     {
  157.         SqlConnection conn = dbConnection.getConnection();
  158.         conn.Open();
  159.         //SqlCommand cmd = new SqlCommand("select d.number, d.operator_id, e.emp_name, e.emp_no, p.name position " +
  160.         //    "from OA_PROBATION_FLOW_DETAIL d inner join OA_EMPLOYEE e on d.operator_id=e.id inner join " +
  161.         //    "OA_EMPLOYEE_POSITION p on e.position=p.id where d.id=" + id, conn);
  162.         //SqlDataReader dr = cmd.ExecuteReader();
  163.         //if (dr.Read())
  164.         //{
  165.         //    TxtNumber.Text = dr["number"].ToString();
  166.         //    OperatorId.Value = dr["operator_id"].ToString();
  167.         //    TxtOperator.Text = dr["emp_no"].ToString() + " " + dr["emp_name"].ToString() + dr["position"].ToString();
  168.         //    DetailId.Value = id;
  169.         //}
  170.         //dr.Close();
  171.         conn.Close();
  172.     }
  173.     protected void FlowWizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
  174.     {
  175.         if (this.CheckValidate() && !MainId.Value.Equals("0"))
  176.         {
  177.             SqlConnection conn = dbConnection.getConnection();
  178.             conn.Open();
  179.             
  180.             conn.Close();
  181.             this.SetEmpty();
  182.             MainList.DataBind();
  183.         }
  184.     }
  185.     protected void MainList_RowCreated(object sender, GridViewRowEventArgs e)
  186.     {
  187.         if (e.Row.RowType == DataControlRowType.DataRow)
  188.         {
  189.             string id = MainList.DataKeys[e.Row.RowIndex].Value.ToString();
  190.             SqlConnection conn = dbConnection.getConnection();
  191.             conn.Open();
  192.             string position = "";
  193.             string position_ids = "";
  194.             SqlCommand cmd = new SqlCommand("select f.position_id, p.name position from OA_PROBATION_FLOW_POSITION f inner join " +
  195.                 "OA_EMPLOYEE_POSITION p on f.position_id=p.id where f.main_id=" + id, conn);
  196.             SqlDataReader dr = cmd.ExecuteReader();
  197.             while (dr.Read())
  198.             {
  199.                 position_ids = position_ids + dr["position_id"].ToString() + ",";
  200.                 position = position + dr["position"].ToString() + ";";
  201.             }
  202.             dr.Close();
  203.             if (position.Length > 0)
  204.             {
  205.                 LinkButton btn = (LinkButton)e.Row.FindControl("LbPosition");
  206.                 btn.Text = position.Substring(0, position.Length - 1);
  207.                 btn.CommandArgument = MainList.DataKeys[e.Row.RowIndex].Value.ToString();
  208.             }
  209.             PositionIds.Value = position_ids;
  210.             conn.Close();
  211.         }
  212.     }
  213.     protected void MainList_RowCommand(object sender, GridViewCommandEventArgs e)
  214.     {
  215.         if (e.CommandName.Equals("EditData"))
  216.         {
  217.             for (int i = 0; i < ChkPosition.Items.Count; i++)
  218.             {
  219.                 ChkPosition.Items[i].Selected = false;
  220.             }
  221.             string id = e.CommandArgument.ToString();
  222.             MainId.Value = id;
  223.             SqlConnection conn = dbConnection.getConnection();
  224.             conn.Open();
  225.             SqlCommand cmd = new SqlCommand("select position_id from OA_PROBATION_FLOW_POSITION where main_id=" + id, conn);
  226.             SqlDataReader dr = cmd.ExecuteReader();
  227.             while (dr.Read())
  228.             {
  229.                 string position_id = dr["position_id"].ToString();
  230.                 for (int i = 0; i < ChkPosition.Items.Count; i++)
  231.                 {
  232.                     if (ChkPosition.Items[i].Value.Equals(position_id))
  233.                     {
  234.                         ChkPosition.Items[i].Selected = true;
  235.                     }
  236.                 }
  237.             }
  238.             dr.Close();
  239.             conn.Close();
  240.             FlowWizard.ActiveStepIndex = 0;
  241.             FlowWizard.Visible = true;
  242.         }
  243.     }
  244.     protected void MainList_RowDataBound(object sender, GridViewRowEventArgs e)
  245.     {
  246.         if (e.Row.RowType == DataControlRowType.DataRow)
  247.         {
  248.             e.Row.Cells[e.Row.Cells.Count - 1].Attributes.Add("onclick", "return confirm('確定删除嗎?')");
  249.         }
  250.     }
  251.     protected void BtnAdd_Click(object sender, EventArgs e)
  252.     {
  253.         this.SetEmpty();
  254.     }
  255.     protected void BtnAddMain_Click(object sender, EventArgs e)
  256.     {
  257.         this.SetEmpty();
  258.         FlowWizard.Visible = true;
  259.         FlowWizard.ActiveStepIndex = 0;
  260.         MainId.Value = "0";
  261.         for (int i = 0; i < ChkPosition.Items.Count; i++)
  262.         {
  263.             ChkPosition.Items[i].Selected = false;
  264.         }
  265.     }
  266. }