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

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_add_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.             this.SetEmpty();
  20.             if (Request.QueryString["main_id"] != null)
  21.             {
  22.                 this.SetTable(Request.QueryString["main_id"]);
  23.                 if (Request.QueryString["flow_id"] != null)
  24.                 {
  25.                     this.SetFlow(Request.QueryString["flow_id"]);
  26.                 }
  27.             }
  28.         }
  29.     }
  30.     protected void SetEmpty()
  31.     {
  32.         TxtName.Text = "";
  33.         DdlType.SelectedIndex = 2;
  34.         TxtNumber.Text = "";
  35.         TxtOperator.Text = "";
  36.         OperatorId.Value = "";
  37.         TxtLargerNext.Text = "";
  38.         TxtLargerThan.Text = "";
  39.         TxtNumber.Text = "";
  40.     }
  41.     protected void SetFlow(string flow_id)
  42.     {
  43.         SqlConnection conn = dbConnection.getConnection();
  44.         conn.Open();
  45.         SqlCommand cmd = new SqlCommand("select f.name, f.apply_type, f.operator_id, e.emp_name, "+
  46.             "f.number, f.next_number, f.larger_than, f.larger_next from OA_FLOW_DETAIL f "+
  47.             "inner join OA_EMPLOYEE e on f.operator_id=e.id where f.id=" + flow_id, conn);
  48.         SqlDataReader dr = cmd.ExecuteReader();
  49.         if(dr.Read())
  50.         {
  51.             TxtName.Text = dr["name"].ToString();
  52.             DdlType.SelectedValue = dr["apply_type"].ToString();
  53.             OperatorId.Value = dr["operator_id"].ToString();
  54.             TxtOperator.Text = dr["emp_name"].ToString();
  55.             TxtNumber.Text = dr["number"].ToString();
  56.             TxtNextNumber.Text = dr["next_number"].ToString();
  57.             if (dr["larger_than"].ToString().Equals("0"))
  58.             {
  59.                 TxtLargerThan.Text = "";
  60.             }
  61.             else
  62.             {
  63.                 TxtLargerThan.Text = dr["larger_than"].ToString();
  64.             }
  65.             TxtLargerNext.Text = dr["larger_next"].ToString();
  66.         }
  67.         dr.Close();
  68.         conn.Close();
  69.     }
  70.     protected void SetTable(string main_id)
  71.     {
  72.         SqlConnection conn = dbConnection.getConnection();
  73.         conn.Open();
  74.         SqlCommand cmd = new SqlCommand("select count(*) from OA_FLOW_DETAIL where main_id="+main_id, conn);
  75.         int count = Convert.ToInt32(cmd.ExecuteScalar().ToString());
  76.         if (count > 0)
  77.         {
  78.             TableHeaderRow th = new TableHeaderRow();
  79.             th.BackColor = System.Drawing.Color.LightGray;
  80.             TableHeaderCell thc = new TableHeaderCell();
  81.             thc.BorderWidth = Unit.Pixel(1);
  82.             thc.HorizontalAlign = HorizontalAlign.Center;
  83.             thc.Text = "流程名稱";
  84.             th.Cells.Add(thc);
  85.             thc = new TableHeaderCell();
  86.             thc.BorderWidth = Unit.Pixel(1);
  87.             thc.HorizontalAlign = HorizontalAlign.Center;
  88.             thc.Text = "類別";
  89.             th.Cells.Add(thc);
  90.             thc = new TableHeaderCell();
  91.             thc.BorderWidth = Unit.Pixel(1);
  92.             thc.HorizontalAlign = HorizontalAlign.Center;
  93.             thc.Text = "編號";
  94.             th.Cells.Add(thc);
  95.             thc = new TableHeaderCell();
  96.             thc.BorderWidth = Unit.Pixel(1);
  97.             thc.HorizontalAlign = HorizontalAlign.Center;
  98.             thc.Text = "辦理人";
  99.             th.Cells.Add(thc);
  100.             thc = new TableHeaderCell();
  101.             thc.BorderWidth = Unit.Pixel(1);
  102.             thc.HorizontalAlign = HorizontalAlign.Center;
  103.             thc.Text = "下一步編號";
  104.             th.Cells.Add(thc);
  105.             thc = new TableHeaderCell();
  106.             thc.BorderWidth = Unit.Pixel(1);
  107.             thc.HorizontalAlign = HorizontalAlign.Center;
  108.             thc.Text = "最大天數";
  109.             th.Cells.Add(thc);
  110.             thc = new TableHeaderCell();
  111.             thc.BorderWidth = Unit.Pixel(1);
  112.             thc.HorizontalAlign = HorizontalAlign.Center;
  113.             thc.Text = "超過最大天數跳轉編號";
  114.             th.Cells.Add(thc);
  115.             thc = new TableHeaderCell();
  116.             thc.BorderWidth = Unit.Pixel(1);
  117.             thc.HorizontalAlign = HorizontalAlign.Center;
  118.             thc.Text = " ";
  119.             th.Cells.Add(thc);
  120.             TblFlowList.Rows.Add(th);
  121.             cmd = new SqlCommand("select d.id, d.main_id, d.name, d.apply_type, e.emp_name, d.number, d.next_number, "+
  122.                 "d.larger_than, d.larger_next from OA_FLOW_DETAIL d inner join OA_EMPLOYEE e on "+
  123.                 "d.operator_id=e.id where main_id="+main_id, conn);
  124.             SqlDataReader dr = cmd.ExecuteReader();
  125.             while (dr.Read())
  126.             {
  127.                 TableRow tr = new TableRow();
  128.                 TableCell td = new TableCell();
  129.                 td.HorizontalAlign = HorizontalAlign.Center;
  130.                 td.BorderWidth = Unit.Pixel(1);
  131.                 td.Text = dr["name"].ToString();
  132.                 tr.Cells.Add(td); td = new TableCell();
  133.                 td.HorizontalAlign = HorizontalAlign.Center;
  134.                 td.BorderWidth = Unit.Pixel(1);
  135.                 if (dr["apply_type"].ToString().Equals("1"))
  136.                 {
  137.                     td.Text = "會簽";
  138.                 }
  139.                 else
  140.                 {
  141.                     td.Text = "審批";
  142.                 }
  143.                 tr.Cells.Add(td); 
  144.                 td = new TableCell();
  145.                 td.HorizontalAlign = HorizontalAlign.Center;
  146.                 td.BorderWidth = Unit.Pixel(1);
  147.                 td.Text = dr["number"].ToString();
  148.                 tr.Cells.Add(td); 
  149.                 td = new TableCell();
  150.                 td.HorizontalAlign = HorizontalAlign.Center;
  151.                 td.BorderWidth = Unit.Pixel(1);
  152.                 td.Text = dr["emp_name"].ToString();
  153.                 tr.Cells.Add(td); 
  154.                 td = new TableCell();
  155.                 td.HorizontalAlign = HorizontalAlign.Center;
  156.                 td.BorderWidth = Unit.Pixel(1);
  157.                 if (!dr["next_number"].ToString().Equals(""))
  158.                 {
  159.                     td.Text = dr["next_number"].ToString();
  160.                 }
  161.                 else
  162.                 {
  163.                     td.Text = "  ";
  164.                 }
  165.                 tr.Cells.Add(td); 
  166.                 td = new TableCell();
  167.                 td.HorizontalAlign = HorizontalAlign.Center;
  168.                 td.BorderWidth = Unit.Pixel(1);
  169.                 if (!dr["larger_than"].ToString().Equals("0"))
  170.                 {
  171.                     td.Text = dr["larger_than"].ToString();
  172.                 }
  173.                 else
  174.                 {
  175.                     td.Text = "  ";
  176.                 }
  177.                 tr.Cells.Add(td); 
  178.                 td = new TableCell();
  179.                 td.HorizontalAlign = HorizontalAlign.Center;
  180.                 td.BorderWidth = Unit.Pixel(1);
  181.                 if (!dr["larger_next"].ToString().Equals(""))
  182.                 {
  183.                     td.Text = dr["larger_next"].ToString();
  184.                 }
  185.                 else
  186.                 {
  187.                     td.Text = " ";
  188.                 }
  189.                 tr.Cells.Add(td);
  190.                 td = new TableCell();
  191.                 td.BorderWidth = Unit.Pixel(1);
  192.                 td.HorizontalAlign = HorizontalAlign.Center;
  193.                 HyperLink lb = new HyperLink();
  194.                 lb.Text = "編輯";
  195.                 lb.NavigateUrl = "add_flow.aspx?main_id=" + dr["main_id"].ToString() + "&flow_id=" + dr["id"].ToString();
  196.                 td.Controls.Add(lb);
  197.                 tr.Cells.Add(td);
  198.                 TblFlowList.Rows.Add(tr);
  199.             }
  200.             dr.Close();
  201.         }
  202.         conn.Close();
  203.     }
  204.     protected void BtnOk_Click(object sender, EventArgs e)
  205.     { 
  206.         int main_id = 0;
  207.         if (Request.QueryString["main_id"] != null)
  208.         {
  209.             main_id = Convert.ToInt32(Request.QueryString["main_id"]);
  210.         }
  211.         SqlConnection conn = dbConnection.getConnection();
  212.         conn.Open();
  213.         if (Request.QueryString["flow_id"] == null)
  214.         {
  215.             //新增
  216.             int flow_id = 1;
  217.             SqlCommand cmd = new SqlCommand("select max(id) from OA_FLOW_DETAIL", conn);
  218.             try
  219.             {
  220.                 flow_id = Convert.ToInt32(cmd.ExecuteScalar()) + 1;
  221.             }
  222.             catch { }
  223.             cmd = new SqlCommand("insert into OA_FLOW_DETAIL(id, main_id, name, apply_type, operator_id, " +
  224.                 "number, next_number, larger_than, larger_next) values (" + flow_id + "," + main_id + ",'" +
  225.                 TxtName.Text + "','" + DdlType.SelectedValue + "','" + OperatorId.Value + "','" + TxtNumber.Text + "','" +
  226.                 TxtNextNumber.Text + "','" + TxtLargerThan.Text + "','" + TxtLargerNext.Text + "')", conn);
  227.             cmd.ExecuteNonQuery();
  228.         }
  229.         else
  230.         { 
  231.             //編輯
  232.             int flow_id = Convert.ToInt32(Request.QueryString["flow_id"]);
  233.             SqlCommand cmd = new SqlCommand("update OA_FLOW_DETAIL set name='"+TxtName.Text+"', apply_type='"+
  234.                 DdlType.SelectedValue+"',  operator_id='"+OperatorId.Value+"',number='"+TxtNumber.Text+
  235.                 "', next_number='"+TxtNextNumber.Text+"', larger_than='"+TxtLargerThan.Text+
  236.                 "', larger_next='"+TxtLargerNext.Text+"' where id="+flow_id, conn);
  237.             cmd.ExecuteNonQuery();
  238.         }
  239.         conn.Close();
  240.         Response.Redirect("add_flow.aspx?main_id="+main_id);
  241.     }
  242.     protected void BtnCancel_Click(object sender, EventArgs e)
  243.     {
  244.         if (Request.QueryString["main_id"] != null)
  245.         {
  246.             Response.Redirect("add_flow.aspx?main_id="+Request.QueryString["main_id"]);
  247.         }
  248.     }
  249. }