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

OA系统

开发平台:

ASP/ASPX

  1. 
  2. using System;
  3. using System.Data;
  4. using System.Configuration;
  5. using System.Collections;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. using System.Data.SqlClient;
  13. using System.Net.Mail;
  14. using System.Net;
  15. using System.Net.Sockets;
  16. public partial class web_approvel_b_form : System.Web.UI.Page
  17. {
  18.     ArrayList apply_type = new ArrayList();
  19.     ArrayList operator_id = new ArrayList();
  20.     private int count = 0;
  21.     protected void Page_Load(object sender, EventArgs e)
  22.     {
  23.         if (!IsPostBack)
  24.         {
  25.             this.SetValue();
  26.             LoginDAO.CheckLogin(Session, Response, "../../", 2);
  27.         }
  28.     }
  29.     protected void SetValue()
  30.     {
  31.         if (Session["user"] != null)
  32.         { 
  33.             DateMgr mgr = new DateMgr();
  34.             User user = (User)Session["user"];
  35.             TxtEmpName.Text = user.Emp_name;
  36.             TxtEmpNo.Text = user.Emp_no;
  37.             TxtDepartment.Text = user.Department.Full_name;
  38.             TxtPosition.Text = user.Position;
  39.             PositionSequence.Value = user.PositionSequence.ToString();
  40.             TxtFormId.Text = mgr.getTime();
  41.             TxtApplyDate.Text = mgr.getDateTime();
  42.             EmployeeId.Value = user.Id.ToString();
  43.             DepartmentId.Value = user.Department.Id.ToString();
  44.             PositionId.Value = user.PositionId.ToString();
  45.             UserGroup.Value = user.UserGroup.ToString();
  46.         }
  47.     }
  48.    
  49.     protected void ImageButton1_Click(object sender, EventArgs e)
  50.     {
  51.         if (Calendar1.Visible == true)
  52.         {
  53.             Calendar1.Visible = false;
  54.         }
  55.         else
  56.         {
  57.             Calendar1.Visible = true;
  58.         }
  59.     }
  60.     protected void ImageButton2_Click(object sender, EventArgs e)
  61.     {
  62.         if (Calendar2.Visible == true)
  63.         {
  64.             Calendar2.Visible = false;
  65.         }
  66.         else
  67.         {
  68.             Calendar2.Visible = true;
  69.         }
  70.     }
  71.     protected void ImageButton3_Click(object sender, EventArgs e)
  72.     {
  73.         if (Calendar3.Visible == true)
  74.         {
  75.             Calendar3.Visible = false;
  76.         }
  77.         else
  78.         {
  79.             Calendar3.Visible = true;
  80.         }
  81.     }
  82.     protected void ImageButton4_Click(object sender, EventArgs e)
  83.     {
  84.         if (Calendar4.Visible == true)
  85.         {
  86.             Calendar4.Visible = false;
  87.         }
  88.         else
  89.         {
  90.             Calendar4.Visible = true;
  91.         }
  92.     }
  93.     protected void Calendar1_SelectionChanged(object sender, EventArgs e)
  94.     {
  95.         Calendar1.Visible = false;
  96.         string year = Calendar1.SelectedDate.Year.ToString();
  97.         string month = Calendar1.SelectedDate.Month.ToString();
  98.         if (month.Length == 1)
  99.         {
  100.             month = "0" + month;
  101.         }
  102.         string day = Calendar1.SelectedDate.Day.ToString();
  103.         if (day.Length == 1)
  104.         {
  105.             day = "0" + day;
  106.         }
  107.         TxtBeginTime.Text = year + "-" + month + "-" + day + " 07:50:00";
  108.     }
  109.     protected void Calendar2_SelectionChanged(object sender, EventArgs e)
  110.     {
  111.         Calendar2.Visible = false;
  112.         string year = Calendar2.SelectedDate.Year.ToString();
  113.         string month = Calendar2.SelectedDate.Month.ToString();
  114.         if (month.Length == 1)
  115.         {
  116.             month = "0" + month;
  117.         }
  118.         string day = Calendar2.SelectedDate.Day.ToString();
  119.         if (day.Length == 1)
  120.         {
  121.             day = "0" + day;
  122.         }
  123.         TxtEndTime.Text = year + "-" + month + "-" + day + " 17:30:00";
  124.     }
  125.     protected void Calendar3_SelectionChanged(object sender, EventArgs e)
  126.     {
  127.         Calendar3.Visible = false;
  128.         string year = Calendar3.SelectedDate.Year.ToString();
  129.         string month = Calendar3.SelectedDate.Month.ToString();
  130.         if (month.Length == 1)
  131.         {
  132.             month = "0" + month;
  133.         }
  134.         string day = Calendar3.SelectedDate.Day.ToString();
  135.         if (day.Length == 1)
  136.         {
  137.             day = "0" + day;
  138.         }
  139.         TxtDepartTime.Text = year + "-" + month + "-" + day + " 00:00:00";
  140.     }
  141.     protected void Calendar4_SelectionChanged(object sender, EventArgs e)
  142.     {
  143.         Calendar4.Visible = false;
  144.         string year = Calendar4.SelectedDate.Year.ToString();
  145.         string month = Calendar4.SelectedDate.Month.ToString();
  146.         if (month.Length == 1)
  147.         {
  148.             month = "0" + month;
  149.         }
  150.         string day = Calendar4.SelectedDate.Day.ToString();
  151.         if (day.Length == 1)
  152.         {
  153.             day = "0" + day;
  154.         }
  155.         TxtArriveTime.Text = year + "-" + month + "-" + day + " 00:00:00";
  156.     }
  157.     protected void BtnOk_Click(object sender, EventArgs e)
  158.     {
  159.         if (this.checktime()&&this.CheckValidate())
  160.         {
  161.             this.Save(1);
  162.         }
  163.     }
  164.     protected bool checktime()
  165.     {
  166.         LblError.Text = "";
  167.         int flag = 0;
  168.         if (TxtBeginTime.Text == "" || TxtEndTime.Text == "") 
  169.         {
  170.             flag = 1;
  171.            
  172.         }
  173.         if (TxtDays.Text == "") { flag = 2; }
  174.         if (flag == 1) 
  175.         {
  176.             LblError.Text = "出差日期起止不能为空";
  177.             Response.Write("<script>alert('出差日起止不能为空')</script>");
  178.             TxtBeginTime.Focus();
  179.             return false; 
  180.         }
  181.         else if (flag == 2) {
  182.             LblError.Text = "出差天数不能为空";
  183.             Response.Write("<script>alert('出差天数不能为空')</script>");
  184.             TxtDays.Focus();
  185.             return false;
  186.         }
  187.         else
  188.         { return true; }
  189.     
  190.     }
  191.     protected void Save(int state)
  192.     {
  193.         SqlConnection conn = dbConnection.getConnection();
  194.         conn.Open();
  195.         SqlTransaction tx = conn.BeginTransaction();
  196.         try
  197.         {
  198.             int id = 1;
  199.             SqlCommand cmd = new SqlCommand("select max(id) from OA_CH_BUSINESS_FORM", conn);
  200.             cmd.Transaction = tx;
  201.             try
  202.             {
  203.                 id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  204.             }
  205.             catch { }
  206.             
  207.             string total_result = "跑流程中";
  208.             
  209.             if (state == 2)
  210.             {
  211.                 total_result = "未送件";
  212.               
  213.             }
  214.             //添加表單
  215.             cmd = new SqlCommand("insert into OA_CH_BUSINESS_FORM(id, form_id, emp_id, apply_date, " +
  216.                 "department_id, days, begin_time, end_time, depart_place, arrive_place, depart_time, " +
  217.                 "arrive_time, step, total_result, finish_date, state) values (" + id + ",'" + TxtFormId.Text + "','" +
  218.                 EmployeeId.Value + "','" + TxtApplyDate.Text + "','" + DepartmentId.Value + "','" + TxtDays.Text +
  219.                 "','" + TxtBeginTime.Text + "','" + TxtEndTime.Text + "','" + DdlDepartPlace.Text + "','" +
  220.                 DdlArrivePlace.Text + "','" + TxtDepartTime.Text + "','" + TxtArriveTime.Text + "',0,'" +
  221.                 total_result + "',''," + state + ")", conn);
  222.             cmd.Transaction = tx;
  223.             cmd.ExecuteNonQuery();
  224.             //添加表身
  225.             int detail_id = 1;
  226.             cmd = new SqlCommand("select max(id) from OA_CH_BUSINESS_DETAIL", conn);
  227.             cmd.Transaction = tx;
  228.             try
  229.             {
  230.                 detail_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  231.             }
  232.             catch { }
  233.             #region
  234.             int index = 1;
  235.             //
  236.             if (!TxtDate1.Text.Trim().Equals("") || !TxtDate1.Text.Trim().Equals(""))
  237.             {
  238.                
  239.                 cmd = new SqlCommand("insert into OA_CH_BUSINESS_DETAIL(id, form_id, number, date, " +
  240.                     "d_start,d_end,tool,content,remark) values (" + detail_id + "," + id + ",'" + index + "','" +
  241.                     TxtDate1.Text + "','" + TxtD_start1.Text + "','" + TxtD_end1.Text + "','" + TxtTool1.Text +
  242.                     "','" + TxtContent1.Text + "','" + TxtRemark1.Text+ "')", conn);
  243.                 cmd.Transaction = tx;
  244.                 cmd.ExecuteNonQuery();
  245.                 detail_id++;
  246.                 index++;
  247.             }
  248.             if (!TxtDate2.Text.Trim().Equals("") || !TxtDate2.Text.Trim().Equals(""))
  249.             {
  250.                 cmd = new SqlCommand("insert into OA_CH_BUSINESS_DETAIL(id, form_id, number, date, " +
  251.                     "d_start,d_end,tool,content,remark) values (" + detail_id + "," + id + ",'" + index + "','" +
  252.                     TxtDate2.Text + "','" + TxtD_start2.Text + "','" + TxtD_end2.Text + "','" + TxtTool2.Text +
  253.                     "','" + TxtContent2.Text + "','" + TxtRemark2.Text + "')", conn);
  254.                 cmd.Transaction = tx;
  255.                 cmd.ExecuteNonQuery();
  256.                 detail_id++;
  257.                 index++;
  258.             }
  259.             if (!TxtDate3.Text.Trim().Equals("") || !TxtDate3.Text.Trim().Equals(""))
  260.             {
  261.                 cmd = new SqlCommand("insert into OA_CH_BUSINESS_DETAIL(id, form_id, number, date, " +
  262.                     "d_start,d_end,tool,content,remark) values (" + detail_id + "," + id + ",'" + index + "','" +
  263.                     TxtDate3.Text + "','" + TxtD_start3.Text + "','" + TxtD_end3.Text + "','" + TxtTool3.Text +
  264.                     "','" + TxtContent3.Text + "','" + TxtRemark3.Text + "')", conn);
  265.                 cmd.Transaction = tx;
  266.                 cmd.ExecuteNonQuery();
  267.                 detail_id++;
  268.                 index++;
  269.             }
  270.             if (!TxtDate4.Text.Trim().Equals("") || !TxtDate4.Text.Trim().Equals(""))
  271.             {
  272.                 cmd = new SqlCommand("insert into OA_CH_BUSINESS_DETAIL(id, form_id, number, date, " +
  273.                     "d_start,d_end,tool,content,remark) values (" + detail_id + "," + id + ",'" + index + "','" +
  274.                     TxtDate4.Text + "','" + TxtD_start4.Text + "','" + TxtD_end4.Text + "','" + TxtTool4.Text +
  275.                     "','" + TxtContent4.Text + "','" + TxtRemark4.Text + "')", conn);
  276.                 cmd.Transaction = tx;
  277.                 cmd.ExecuteNonQuery();
  278.                 detail_id++;
  279.                 index++;
  280.             }
  281.             if (!TxtDate5.Text.Trim().Equals("") || !TxtDate5.Text.Trim().Equals(""))
  282.             {
  283.                 cmd = new SqlCommand("insert into OA_CH_BUSINESS_DETAIL(id, form_id, number, date, " +
  284.                     "d_start,d_end,tool,content,remark) values (" + detail_id + "," + id + ",'" + index + "','" +
  285.                     TxtDate5.Text + "','" + TxtD_start5.Text + "','" + TxtD_end5.Text + "','" + TxtTool5.Text +
  286.                     "','" + TxtContent5.Text + "','" + TxtRemark5.Text + "')", conn);
  287.                 cmd.Transaction = tx;
  288.                 cmd.ExecuteNonQuery();
  289.                 detail_id++;
  290.                 index++;
  291.             }
  292.             //金额
  293.            // if (!TxtDate1.Text.Trim().Equals("") || !TxtDate1.Text.Trim().Equals(""))
  294.             // { 
  295.           int detail_id1 = 1;
  296.             cmd = new SqlCommand("select max(id) from OA_CH_BUSINESS_DETAIL1", conn);
  297.             cmd.Transaction = tx;
  298.             try
  299.             {
  300.                 detail_id1 = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  301.             }
  302.             catch { }
  303.            
  304.                 cmd = new SqlCommand("insert into OA_CH_BUSINESS_DETAIL1(id, form_id, f_eat, f_eat_remark, " +
  305.                        "f_house,f_house_remark,f_move,f_move_remark,f_other,f_other_remark,f_total,f_total_remark)" +
  306.                        " values ('" + detail_id1 + "','" + id + "','" +  TxtFAmt1.Text+ "','" +
  307.                       TxtFRemark1.Text + "','" + TxtFAmt2.Text + "','" +
  308.                       TxtFRemark2.Text + "','" + TxtFAmt3.Text+ "','" +
  309.                       TxtFRemark3.Text + "','" + TxtFAmt4.Text + "','" +
  310.                       TxtFRemark4.Text + "','" + TxtFAmt5.Text + "','" +
  311.                       TxtFRemark5.Text + "')", conn);
  312.                 cmd.Transaction = tx;
  313.                 cmd.ExecuteNonQuery();
  314.             
  315.           //  catch (Exception e1) { Response.Write(e1.Message); }
  316.                 
  317.             //}
  318.           //
  319.            
  320.             #endregion
  321.            //逐级签核
  322.                 
  323.                 ArrayList operator_id = new ArrayList();//记录上层节点职级小于登陆者的ID
  324.                 ArrayList name1 = new ArrayList();//记录上层节点职级小于登陆者的name
  325.                 ArrayList mail1 = new ArrayList();//记录上层节点职级小于登陆者的mail
  326.                 ArrayList last_id = new ArrayList();//记录上层节点的ID                
  327.                 ArrayList tmp_people = new ArrayList();//记录待签核人的ID
  328.                 ArrayList d_people = new ArrayList();
  329.                 ArrayList b_d_people = new ArrayList();
  330.                 ArrayList mail2 = new ArrayList();//记录代理人的MAIL
  331.                 ArrayList mail2_name = new ArrayList();//记录代理人姓名
  332.                 
  333.              
  334.                 int ceng = 0;
  335.                 cmd = new SqlCommand("select ceng from oa_department where id="+DepartmentId.Value,conn);
  336.                 cmd.Transaction = tx;
  337.                 
  338.                 try
  339.                 {
  340.                      ceng = Convert.ToInt32(cmd.ExecuteScalar());
  341.                 }
  342.                 catch { }
  343.                     last_id.Add(DepartmentId.Value.ToString());
  344.                    
  345.                     for (int j = 1; j < ceng; j++)
  346.                     {
  347.                         cmd = new SqlCommand("select distinct last_id from oa_department where id=" + last_id[j - 1], conn);
  348.                         cmd.Transaction = tx;
  349.                         SqlDataReader dr2 = cmd.ExecuteReader();
  350.                         while (dr2.Read())
  351.                         {
  352.                             last_id.Add(dr2["last_id"].ToString());
  353.                         }
  354.                       
  355.                         dr2.Close();
  356.                     }
  357.                     //找到上层节点人的ID
  358.                     for (int i = 0; i < last_id.Count; i++)
  359.                     {
  360.                         cmd = new SqlCommand("select a.id as id,a.email_work,a.emp_name from oa_employee as a left join oa_department as b on a.department_id=b.id" +
  361.                        " where  b.id=" + last_id[i] + " and q_manger=1 order by position desc", conn);
  362.                         cmd.Transaction = tx;
  363.                         SqlDataReader dr1 = cmd.ExecuteReader();
  364.                         while (dr1.Read())
  365.                         {   
  366.                             
  367.                             operator_id.Add(dr1["id"].ToString());
  368.                             name1.Add(dr1["emp_name"].ToString());
  369.                             mail1.Add(dr1["email_work"].ToString());
  370.                         }
  371.                       
  372.                         dr1.Close();
  373.                     }
  374.                    
  375.                
  376.                //是副董,跳過
  377.                     for (int p = 0; p < operator_id.Count; p++)
  378.                     {
  379.                         if (Convert.ToInt32(operator_id[p]) == 128)
  380.                         {
  381.                             if (TxtFAmt5.Text.ToString().Equals("0"))
  382.                             { 
  383.                                 operator_id.RemoveAt(p);
  384.                             }
  385.                         }
  386.                     }
  387.                     
  388.                 /*    for (int i = 0; i < 1; i++)
  389.                     {
  390.                         if (UserGroup.Value.Equals("1"))
  391.                         {
  392.                             cmd = new SqlCommand("select a.id as id from oa_employee as a left join oa_department as b on a.department_id=b.id" +
  393.                          " where  b.id=56 and q_manger=1 order by position desc", conn);
  394.                         }
  395.                         else if (UserGroup.Value.Equals("2"))
  396.                         {
  397.                             cmd = new SqlCommand("select a.id as id from oa_employee as a left join oa_department as b on a.department_id=b.id" +
  398.                          " where  b.id=90 and q_manger=1 order by position desc", conn);
  399.                         }
  400.                         cmd.Transaction = tx;
  401.                         SqlDataReader dr1 = cmd.ExecuteReader();
  402.                         while (dr1.Read())
  403.                         {
  404.                             operator_id.Add(dr1["id"].ToString());
  405.                             
  406.                         }
  407.                         dr1.Close();
  408.                     }*/
  409.                   //  operator_id.Add("128");
  410.                         //  确定是否有代理人签核
  411.                         for (int k = 0; k < operator_id.Count; k++)
  412.                         {
  413.                             cmd = new SqlCommand("select d_people,b_d_people from oa_delegate where  s_date<=convert(varchar, getdate(), 120)" +
  414.                                   " and e_date>=convert(varchar, getdate(),120) and b_d_people='" + operator_id[k] + "'", conn);
  415.                             cmd.Transaction = tx;
  416.                             SqlDataReader dr3 = cmd.ExecuteReader();
  417.                             while (dr3.Read())
  418.                             {
  419.                                 d_people.Add(dr3["d_people"].ToString());
  420.                                 b_d_people.Add(dr3["b_d_people"].ToString());
  421.                                 operator_id.RemoveAt(k);
  422.                                 operator_id.Add(dr3["d_people"].ToString());
  423.                             }
  424.                             dr3.Close();
  425.                         }
  426.                         //   是本人,跳過
  427.                         for (int i = 0; i < operator_id.Count; i++)
  428.                         {
  429.                             if (operator_id[i].ToString().Equals(Session["user_id"].ToString())) { operator_id.RemoveAt(i); }
  430.                         }  
  431.                     //添加流程
  432.                     int flow_id = 1;
  433.               
  434.                     cmd = new SqlCommand("select max(id) from OA_CH_APPROVEL_FORM_FLOW", conn);
  435.                     cmd.Transaction = tx;
  436.                     try
  437.                     {
  438.                         flow_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  439.                     }
  440.                     catch { }
  441.                 
  442.                     for (int i = 0; i < operator_id.Count; i++)
  443.                     {
  444.                         cmd = new SqlCommand("insert into OA_CH_APPROVEL_FORM_FLOW(id, form_id, operator_id, " +
  445.                             "apply_type, is_check, is_agree, comment, check_date, step, is_business)values(" +
  446.                             flow_id + ", " + id + "," + operator_id[i] + ",2,'N','N','',''," + (i + 1) + ",'Y')", conn);
  447.                         cmd.Transaction = tx;
  448.                         cmd.ExecuteNonQuery();
  449.                         flow_id++;
  450.                     }
  451.                   
  452.                     if (state == 1)
  453.                     {
  454.                        // mail.mail_q(mail1[0], name1[0], TxtEmpName.Text, "中幹出差申請單");
  455.                     }
  456.                  
  457.                    
  458.                     tx.Commit();
  459.                     Response.Redirect("my_list.aspx");
  460.                 }
  461.                
  462.                  
  463.      
  464.         catch (Exception ex)
  465.         {
  466.             Response.Write(ex.Message);
  467.             Response.Write("没找到相應主管簽核,請聯繫管理員");
  468.            // try
  469.           //  {
  470.            //     tx.Rollback();
  471.            // }
  472.          //   catch { }
  473.         }
  474.         conn.Close();  
  475.     }
  476.     protected void BtnSave_Click(object sender, EventArgs e)
  477.     {
  478.         this.Save(2);
  479.     }
  480.   /*  protected void total()
  481.     {
  482.         if (TxtFAmt5.Focus)
  483.         {
  484.             int total = 0;
  485.             total = Convert.ToInt32(TxtFAmt1.Text) + Convert.ToInt32(TxtFAmt2.Text)
  486.                  + Convert.ToInt32(TxtFAmt3.Text) + Convert.ToInt32(TxtFAmt4.Text) + Convert.ToInt32(TxtFAmt5.Text);
  487.               TxtFAmt3.Text = total.ToString();
  488.             return total;
  489.         }
  490.     }*/
  491.     protected bool CheckValidate()
  492.     {
  493.        LblError.Text = "";
  494.         int flag = 0;
  495.         try
  496.         {
  497.             if (!(TxtFAmt1.Text == null || TxtFAmt1.Text == ""))
  498.             { double day = Convert.ToDouble(TxtFAmt1.Text); }
  499.         }
  500.         catch
  501.         {
  502.             flag = 1;
  503.             Response.Write("<script>alert('格式有误')</script>");
  504.             LblError.Text = "膳食費用" + "格式有误";
  505.             TxtFAmt1.Focus();
  506.         }
  507.         try
  508.         {
  509.             if (!(TxtFAmt2.Text == null || TxtFAmt2.Text == ""))
  510.             {
  511.                 double day = Convert.ToDouble(TxtFAmt2.Text);
  512.             }
  513.         }
  514.         catch
  515.         {
  516.             flag = 1;
  517.             Response.Write("<script>alert('格式有误')</script>");
  518.             LblError.Text = "住宿費用" + "格式有误";
  519.             TxtFAmt2.Focus();
  520.         }
  521.         try
  522.         {
  523.             if (!(TxtFAmt3.Text == null || TxtFAmt3.Text == ""))
  524.             {
  525.                 double day = Convert.ToDouble(TxtFAmt3.Text);
  526.             }
  527.         }
  528.         catch
  529.         {
  530.             flag = 1;
  531.             Response.Write("<script>alert('格式有误')</script>");
  532.             LblError.Text = "交通費用" + "格式有误";
  533.             TxtFAmt3.Focus();
  534.         }
  535.         try
  536.         {
  537.             if (!(TxtFAmt4.Text == null || TxtFAmt4.Text == ""))
  538.             {
  539.                 double day = Convert.ToDouble(TxtFAmt4.Text);
  540.             }
  541.         }
  542.         catch
  543.         {
  544.             flag = 1;
  545.             Response.Write("<script>alert('格式有误')</script>");
  546.             LblError.Text = "其他費用" + "格式有误";
  547.             TxtFAmt4.Focus();
  548.         }
  549.         try
  550.         {
  551.            
  552.                 double day = Convert.ToDouble(TxtFAmt5.Text);
  553.             
  554.         }
  555.         catch
  556.         {
  557.             flag = 1;
  558.             Response.Write("<script>alert('格式有误')</script>");
  559.             LblError.Text = "合計" + "格式有误";
  560.             TxtFAmt5.Focus();
  561.         }
  562.           if (flag == 0)
  563.         {
  564.             return true;
  565.         }
  566.         else
  567.         {
  568.             return false;
  569.         }
  570.     }
  571.     //遞歸取出辦理人-- position:7-副理; 2-副董
  572.     protected void getEmployee(int department_id, int position)
  573.     {
  574.         int operator_id = 0;
  575.         int flag = 0;
  576.         SqlConnection conn = dbConnection.getConnection();
  577.         conn.Open();
  578.         string sql = "select id from OA_EMPLOYEE where department_id=" + department_id + " and position=" + position;
  579.         if (position == 2)
  580.         {
  581.             sql = "select id from OA_EMPLOYEE where position=" + position;
  582.         }
  583.         SqlCommand cmd = new SqlCommand(sql, conn);
  584.         SqlDataReader dr = cmd.ExecuteReader();
  585.         if (dr.Read())
  586.         {
  587.             operator_id = Convert.ToInt32(dr["id"].ToString());
  588.             OperatorId.Value = operator_id.ToString();
  589.         }
  590.         else
  591.         {
  592.             flag = 1;
  593.         }
  594.         dr.Close();
  595.         count = count + 1;
  596.         if (count == 6)
  597.         {
  598.             flag = 0;
  599.             OperatorId.Value = "0";
  600.         }
  601.         if (flag == 1)
  602.         {
  603.             cmd = new SqlCommand("select last_id from OA_DEPARTMENT where id=" + department_id, conn);
  604.             this.getEmployee(Convert.ToInt32(cmd.ExecuteScalar()), position);
  605.         }
  606.         conn.Close();
  607.     }
  608.     //遞歸取自由流程
  609.     protected void GetFlow(int main_id, int number, SqlConnection conn, SqlTransaction tx)
  610.     {
  611.         string sql = "select top 1 apply_type, operator_id, number, next_number, " +
  612.             "larger_than, larger_next from OA_FLOW_DETAIL where main_id=" + main_id + " order by number";
  613.         if (number != 0)
  614.         {
  615.             sql = "select top 1 apply_type, operator_id, number, next_number, " +
  616.              "larger_than, larger_next from OA_FLOW_DETAIL where main_id=" + main_id + " and number=" + number;
  617.         }
  618.         SqlCommand cmd = new SqlCommand(sql, conn);
  619.         cmd.Transaction = tx;
  620.         int next = 0;
  621.         int flag = 0;
  622.         SqlDataReader dr = cmd.ExecuteReader();
  623.         if (dr.Read())
  624.         {
  625.             apply_type.Add(dr["apply_type"].ToString());
  626.             operator_id.Add(dr["operator_id"].ToString());
  627.             if (!dr["larger_than"].ToString().Equals("0"))
  628.             {
  629.                 if (Convert.ToInt32(dr["larger_than"].ToString()) < Convert.ToInt32(TxtDays.Text))
  630.                 {
  631.                     if (!dr["larger_next"].Equals(""))
  632.                     {
  633.                         flag = 1;
  634.                         next = Convert.ToInt32(dr["larger_next"].ToString());
  635.                     }
  636.                 }
  637.                 else
  638.                 {
  639.                     if (!dr["next_number"].Equals(""))
  640.                     {
  641.                         flag = 1;
  642.                         next = Convert.ToInt32(dr["next_number"].ToString());
  643.                     }
  644.                 }
  645.             }
  646.             else
  647.             {
  648.                 if (!dr["next_number"].ToString().Equals(""))
  649.                 {
  650.                     flag = 1;
  651.                     next = Convert.ToInt32(dr["next_number"].ToString());
  652.                 }
  653.             }
  654.         }
  655.         dr.Close();
  656.         if (flag == 1)
  657.         {
  658.             this.GetFlow(main_id, next, conn, tx);
  659.         }
  660.     }
  661. }