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

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_flow_flow_show : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)
  17.         {
  18.             if (Request.QueryString["f_id"] != null)
  19.             {
  20.                 this.SetValue(Request.QueryString["f_id"]);
  21.             }
  22.             if (Request.QueryString["d_id"] != null)
  23.             {
  24.                 this.SetDetail(Request.QueryString["d_id"]);
  25.                 this.PnlDetail.Visible = true;
  26.             }
  27.             FlowList.DataKeyNames = new string[] { "id" };
  28.         }
  29.     }
  30.     protected void SetValue(string id)
  31.     {
  32.         SqlConnection conn = dbConnection.getConnection();
  33.         conn.Open();
  34.         SqlCommand cmd = new SqlCommand("select name, description, type from OA_FLOW_MAIN where id="+id, conn);
  35.         SqlDataReader dr = cmd.ExecuteReader();
  36.         if (dr.Read())
  37.         {
  38.             TxtName.Text = dr["name"].ToString();
  39.             TxtDescription.Text = dr["description"].ToString();
  40.             RbType.SelectedValue = dr["type"].ToString();
  41.         }
  42.         dr.Close();
  43.         cmd = new SqlCommand("select f.department_id, d.name from OA_FLOW_DEPARTMENT f "+
  44.             "inner join OA_DEPARTMENT d on f.department_id=d.id where f.main_id="+id, conn);
  45.         dr = cmd.ExecuteReader();
  46.         while (dr.Read())
  47.         {
  48.             DepartmentIds.Value = DepartmentIds.Value + dr["department_id"].ToString() + ";";
  49.             LblDepartments.Text = LblDepartments.Text + dr["name"].ToString() + ";";
  50.         }
  51.         dr.Close();
  52.         DepartmentIds.Value = DepartmentIds.Value.Substring(0, DepartmentIds.Value.Length - 1);
  53.         conn.Close();
  54.     }
  55.     protected void SetDetail(string id)
  56.     {
  57.         SqlConnection conn = dbConnection.getConnection();
  58.         conn.Open();
  59.         SqlCommand cmd = new SqlCommand("select f.name, f.apply_type, f.operator_id, e.emp_name, " +
  60.             "f.number, f.next_number, f.larger_than, f.larger_next from OA_FLOW_DETAIL f " +
  61.             "inner join OA_EMPLOYEE e on f.operator_id=e.id where f.id=" + id, conn);
  62.         SqlDataReader dr = cmd.ExecuteReader();
  63.         if (dr.Read())
  64.         {
  65.             TxtDetailName.Text = dr["name"].ToString();
  66.             DdlType.SelectedValue = dr["apply_type"].ToString();
  67.             OperatorId.Value = dr["operator_id"].ToString();
  68.             TxtOperator.Text = dr["emp_name"].ToString();
  69.             TxtNumber.Text = dr["number"].ToString();
  70.             TxtNextNumber.Text = dr["next_number"].ToString();
  71.             if (dr["larger_than"].ToString().Equals("0"))
  72.             {
  73.                 TxtLargerThan.Text = "";
  74.             }
  75.             else
  76.             {
  77.                 TxtLargerThan.Text = dr["larger_than"].ToString();
  78.             }
  79.             TxtLargerNext.Text = dr["larger_next"].ToString();
  80.         }
  81.         dr.Close();
  82.         conn.Close();
  83.     }
  84.     protected void BtnOk_Click(object sender, EventArgs e)
  85.     {
  86.         if (Request.QueryString["f_id"] != null)
  87.         {
  88.             string id = Request.QueryString["f_id"];
  89.             string upd_user = "";
  90.             if (Session["user"] != null)
  91.             {
  92.                 upd_user = ((User)Session["user"]).Emp_name;
  93.             }
  94.             SqlConnection conn = dbConnection.getConnection();
  95.             conn.Open();
  96.             SqlTransaction tx = conn.BeginTransaction();
  97.             try
  98.             {
  99.                 SqlCommand cmd = new SqlCommand("update OA_FLOW_MAIN set name='"+TxtName.Text+"', "+
  100.                     "description='"+TxtDescription.Text+"', type='"+RbType.SelectedValue+"' where id="+id, conn);
  101.                 cmd.Transaction = tx;
  102.                 cmd.ExecuteNonQuery();
  103.                 cmd = new SqlCommand("delete from OA_FLOW_DEPARTMENT where main_id="+id, conn);
  104.                 cmd.Transaction = tx;
  105.                 cmd.ExecuteNonQuery();
  106.                 string[] ids = DepartmentIds.Value.Split(new char[] { ',' });
  107.                 int department_id = 1;
  108.                 cmd = new SqlCommand("select max(id) from OA_FLOW_DEPARTMENT", conn);
  109.                 cmd.Transaction = tx;
  110.                 try
  111.                 {
  112.                     department_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  113.                 }
  114.                 catch { }
  115.                 for (int i = 0; i < ids.Length; i++)
  116.                 {
  117.                     cmd = new SqlCommand("insert into OA_FLOW_DEPARTMENT(id, main_id, department_id)" +
  118.                         "values(" + department_id + ",'" + id + "','" + ids[i] + "')", conn);
  119.                     cmd.Transaction = tx;
  120.                     cmd.ExecuteNonQuery();
  121.                     department_id++;
  122.                 }
  123.                 tx.Commit();
  124.                 LblDepartments.Text = "";
  125.                 DepartmentIds.Value = "";
  126.                 cmd = new SqlCommand("select f.department_id, d.name from OA_FLOW_DEPARTMENT f " +
  127.                     "inner join OA_DEPARTMENT d on f.department_id=d.id where f.main_id=" + id, conn);
  128.                 SqlDataReader dr = cmd.ExecuteReader();
  129.                 while (dr.Read())
  130.                 {
  131.                     DepartmentIds.Value = DepartmentIds.Value + dr["department_id"].ToString() + ";";
  132.                     LblDepartments.Text = LblDepartments.Text + dr["name"].ToString() + ";";
  133.                 }
  134.                 dr.Close();
  135.                 DepartmentIds.Value = DepartmentIds.Value.Substring(0, DepartmentIds.Value.Length - 1);
  136.             }
  137.             catch (Exception ex)
  138.             {
  139.                 Response.Write(ex.Message);
  140.                 tx.Rollback();
  141.             }
  142.             conn.Close();
  143.         }
  144.         BtnOk.Visible = false;
  145.         BtnEdit.Visible = true;
  146.         BtnSelect.Visible = false;
  147.         TxtDescription.Enabled = false;
  148.         TxtName.Enabled = false;
  149.         RbType.Enabled = false;
  150.     }
  151.     protected void BtnEdit_Click(object sender, EventArgs e)
  152.     {
  153.         BtnOk.Visible = true;
  154.         BtnEdit.Visible = false;
  155.         BtnSelect.Visible = true;
  156.         TxtDescription.Enabled = true;
  157.         TxtName.Enabled = true;
  158.         RbType.Enabled = true;
  159.     }
  160.     protected void FlowList_RowCreated(object sender, GridViewRowEventArgs e)
  161.     {
  162.         if (e.Row.RowType == DataControlRowType.DataRow)
  163.         {
  164.             LinkButton btnEdit = (LinkButton)e.Row.FindControl("BtnEdit");
  165.             btnEdit.CommandArgument = FlowList.DataKeys[e.Row.RowIndex].Value.ToString();
  166.             SqlConnection conn = dbConnection.getConnection();
  167.             conn.Open();
  168.             SqlCommand cmd = new SqlCommand("select apply_type, larger_than from OA_FLOW_DETAIL where id=" + FlowList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  169.             SqlDataReader dr = cmd.ExecuteReader();
  170.             if (dr.Read())
  171.             {
  172.                 Label label = (Label)e.Row.FindControl("LblApplyType");
  173.                 if (dr["apply_type"].ToString().Equals("1"))
  174.                 {
  175.                     label.Text = "會簽";
  176.                 }
  177.                 else
  178.                 {
  179.                     label.Text = "審批";
  180.                 }
  181.             }
  182.             dr.Close();
  183.             conn.Close();
  184.         }
  185.     }
  186.     protected void FlowList_RowDataBound(object sender, GridViewRowEventArgs e)
  187.     {
  188.     }
  189.     protected void FlowList_RowCommand(object sender, GridViewCommandEventArgs e)
  190.     {
  191.         if (e.CommandName.Equals("EditData"))
  192.         {
  193.             string id = e.CommandArgument.ToString();
  194.             try
  195.             {
  196.                 if (Request.QueryString["f_id"] != null)
  197.                 {
  198.                     Response.Redirect("flow_show.aspx?f_id="+Request.QueryString["f_id"]+"&d_id="+id);
  199.                 }
  200.             }
  201.             catch (Exception ex)
  202.             {
  203.                 Response.Write(ex.Message);
  204.             }
  205.         }
  206.     }
  207.     protected void BtnDetailOk_Click(object sender, EventArgs e)
  208.     {
  209.         if (Request.QueryString["d_id"] != null)
  210.         {
  211.             SqlConnection conn = dbConnection.getConnection();
  212.             conn.Open();
  213.             SqlCommand cmd = new SqlCommand("update OA_FLOW_DETAIL set apply_type='"+DdlType.SelectedValue+
  214.                 "', operator_id='"+OperatorId.Value+"', number='"+TxtNumber.Text+"', next_number='"+
  215.                 TxtNextNumber.Text+"', larger_than='"+TxtLargerThan.Text+"', larger_next='"+TxtLargerNext.Text+
  216.                 "', name='"+TxtDetailName.Text+"' where id="+Request.QueryString["d_id"], conn);
  217.             cmd.ExecuteNonQuery();
  218.             conn.Close();
  219.             FlowList.DataBind();
  220.             this.SetEmpty();
  221.             PnlDetail.Visible = false;
  222.         }
  223.     }
  224.     protected void BtnCancel_Click(object sender, EventArgs e)
  225.     {
  226.         this.SetEmpty();
  227.         PnlDetail.Visible = false;
  228.     }
  229.     protected void SetEmpty()
  230.     {
  231.         TxtDetailName.Text = "";
  232.         DdlType.SelectedIndex = 2;
  233.         TxtNumber.Text = "";
  234.         TxtOperator.Text = "";
  235.         OperatorId.Value = "";
  236.         TxtLargerNext.Text = "";
  237.         TxtLargerThan.Text = "";
  238.         TxtNumber.Text = "";
  239.     }
  240. }