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

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. using System.Net.Mail;
  13. using System.Net;
  14. using System.Net.Sockets;
  15. public partial class web_approvel_tw_form : System.Web.UI.Page
  16. {
  17.     ArrayList apply_type = new ArrayList();
  18.     ArrayList operator_id = new ArrayList();  
  19.      
  20.     private int count = 0;
  21.     protected void Page_Load(object sender, EventArgs e)
  22.     {
  23.         if (!IsPostBack)
  24.         {
  25.             LoginDAO.CheckLogin(Session, Response, "../../", 2);
  26.             if (Session["user"] != null)
  27.             {
  28.                 DateMgr mgr = new DateMgr();
  29.                 User user = (User)Session["user"];
  30.                 TxtApplyDate.Text = mgr.getDateTime();
  31.                 TxtFormNo.Text = mgr.getTime();
  32.                 TxtEmpName.Text = user.Emp_name;
  33.                 EmpId.Value = user.Id.ToString();
  34.                 TxtEmpNo.Text = user.Emp_no;
  35.                 TxtDepartment.Text = user.Department.Full_name;
  36.                 DepartmentId.Value = user.Department.Id.ToString();
  37.                 TxtPosition.Text = user.Position;
  38.                 PositionSequence.Value = user.PositionSequence.ToString();
  39.                 PositionId.Value = user.PositionId.ToString();
  40.                 Session["department_id"] = user.Department.Id.ToString();
  41.             }
  42.         }
  43.     }
  44.     protected void ImageButton1_Click(object sender, EventArgs e)
  45.     {
  46.         if (Calendar1.Visible == true)
  47.         {
  48.             Calendar1.Visible = false;
  49.             Calendar1.Focus();
  50.         }
  51.         else
  52.         {
  53.             Calendar1.Visible = true;
  54.             Calendar1.Focus();
  55.         }
  56.     }
  57.     protected void ImageButton2_Click(object sender, EventArgs e)
  58.     {
  59.         if (Calendar2.Visible == true)
  60.         {
  61.             Calendar2.Visible = false;
  62.             Calendar2.Focus();
  63.         }
  64.         else
  65.         {
  66.             Calendar2.Visible = true;
  67.             Calendar2.Focus();
  68.         }
  69.     }
  70.     protected void ImageButton3_Click(object sender, EventArgs e)
  71.     {
  72.         if (Calendar3.Visible == true)
  73.         {
  74.             Calendar3.Visible = false;
  75.             TxtBusinessEnd.Focus();
  76.         }
  77.         else
  78.         {
  79.             Calendar3.Visible = true;
  80.             TxtBusinessEnd.Focus();
  81.         }
  82.     }
  83.     protected void ImageButton4_Click(object sender, EventArgs e)
  84.     {
  85.         if (Calendar4.Visible == true)
  86.         {
  87.             Calendar4.Visible = false;
  88.             TxtReason.Focus();
  89.            
  90.         }
  91.         else
  92.         {
  93.             Calendar4.Visible = true;
  94.             TxtReason.Focus();
  95.             
  96.         }
  97.     }
  98.     protected void ImageButton5_Click(object sender, EventArgs e)
  99.     {
  100.         if (Calendar5.Visible == true)
  101.         {
  102.             Calendar5.Visible = false;
  103.             
  104.         }
  105.         else
  106.         {
  107.             Calendar5.Visible = true;
  108.             TxtFlightBackTime.Focus();
  109.         }
  110.     }
  111.     protected void ImageButton6_Click(object sender, EventArgs e)
  112.     {
  113.         if (Calendar6.Visible == true)
  114.         {
  115.             Calendar6.Visible = false;
  116.             
  117.         }
  118.         else
  119.         {
  120.             Calendar6.Visible = true;
  121.             DdlFlightBackDepart.Focus();
  122.         }
  123.     }
  124.     protected void Calendar1_SelectionChanged(object sender, EventArgs e)
  125.     {
  126.         Calendar1.Visible = false;
  127.         string year = Calendar1.SelectedDate.Year.ToString();
  128.         string month = Calendar1.SelectedDate.Month.ToString();
  129.         if (month.Length == 1)
  130.         {
  131.             month = "0" + month;
  132.         }
  133.         string day = Calendar1.SelectedDate.Day.ToString();
  134.         if (day.Length == 1)
  135.         {
  136.             day = "0" + day;
  137.         }
  138.         TxtVacationBegin.Text = year + "-" + month + "-" + day + " 00:00:00";
  139.         TxtVacationBegin.Focus();
  140.     }
  141.     protected void Calendar2_SelectionChanged(object sender, EventArgs e)
  142.     {
  143.         Calendar2.Visible = false;
  144.         string year = Calendar2.SelectedDate.Year.ToString();
  145.         string month = Calendar2.SelectedDate.Month.ToString();
  146.         if (month.Length == 1)
  147.         {
  148.             month = "0" + month;
  149.         }
  150.         string day = Calendar2.SelectedDate.Day.ToString();
  151.         if (day.Length == 1)
  152.         {
  153.             day = "0" + day;
  154.         }
  155.         TxtVacationEnd.Text = year + "-" + month + "-" + day + " 00:00:00";
  156.         TxtVacationEnd.Focus();
  157.     }
  158.     protected void Calendar3_SelectionChanged(object sender, EventArgs e)
  159.     {
  160.         Calendar3.Visible = false;
  161.         string year = Calendar3.SelectedDate.Year.ToString();
  162.         string month = Calendar3.SelectedDate.Month.ToString();
  163.         if (month.Length == 1)
  164.         {
  165.             month = "0" + month;
  166.         }
  167.         string day = Calendar3.SelectedDate.Day.ToString();
  168.         if (day.Length == 1)
  169.         {
  170.             day = "0" + day;
  171.         }
  172.         TxtBusinessBegin.Text = year + "-" + month + "-" + day + " 00:00:00";
  173.         TxtBusinessEnd.Focus();
  174.     }
  175.     protected void Calendar4_SelectionChanged(object sender, EventArgs e)
  176.     {
  177.         Calendar4.Visible = false;
  178.         string year = Calendar4.SelectedDate.Year.ToString();
  179.         string month = Calendar4.SelectedDate.Month.ToString();
  180.         if (month.Length == 1)
  181.         {
  182.             month = "0" + month;
  183.         }
  184.         string day = Calendar4.SelectedDate.Day.ToString();
  185.         if (day.Length == 1)
  186.         {
  187.             day = "0" + day;
  188.         }
  189.         TxtBusinessEnd.Text = year + "-" + month + "-" + day + " 00:00:00";
  190.         TxtReason.Focus();
  191.     }
  192.     protected void Calendar5_SelectionChanged(object sender, EventArgs e)
  193.     {
  194.         Calendar5.Visible = false;
  195.         string year = Calendar5.SelectedDate.Year.ToString();
  196.         string month = Calendar5.SelectedDate.Month.ToString();
  197.         if (month.Length == 1)
  198.         {
  199.             month = "0" + month;
  200.         }
  201.         string day = Calendar5.SelectedDate.Day.ToString();
  202.         if (day.Length == 1)
  203.         {
  204.             day = "0" + day;
  205.         }
  206.         TxtFlightGoTime.Text = year + "-" + month + "-" + day + " 00:00:00";
  207.         TxtFlightBackTime.Focus();
  208.     }
  209.     protected void Calendar6_SelectionChanged(object sender, EventArgs e)
  210.     {
  211.         Calendar6.Visible = false;
  212.         string year = Calendar6.SelectedDate.Year.ToString();
  213.         string month = Calendar6.SelectedDate.Month.ToString();
  214.         if (month.Length == 1)
  215.         {
  216.             month = "0" + month;
  217.         }
  218.         string day = Calendar6.SelectedDate.Day.ToString();
  219.         if (day.Length == 1)
  220.         {
  221.             day = "0" + day;
  222.         }
  223.         TxtFlightBackTime.Text = year + "-" + month + "-" + day + " 00:00:00";
  224.         DdlFlightBackDepart.Focus();
  225.     }
  226.   
  227.     protected void BtnSave_Click(object sender, EventArgs e)
  228.     {
  229.         this.save(2);
  230.     }
  231.     protected void BtnOk_Click(object sender, EventArgs e)
  232.     {
  233.         this.save(1);
  234.     }
  235.    
  236.     protected void save(int state)
  237.     {
  238.         if (this.CheckValidate()&&this.checktime())
  239.         {
  240.             SqlConnection conn = dbConnection.getConnection();
  241.             conn.Open();
  242.             SqlTransaction tx = conn.BeginTransaction();
  243.             string sql = "";
  244.             try
  245.             {
  246.                 int id = 1;
  247.                 SqlCommand cmd = new SqlCommand("select max(id) from OA_TW_APPROVEL_FORM", conn);
  248.                 cmd.Transaction = tx;
  249.                 try
  250.                 {
  251.                     id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  252.                 }
  253.                 catch { }
  254.                 string total_result = "跑流程中";
  255.                 if (state == 2)
  256.                 {
  257.                     total_result = "未送件";
  258.                 }
  259.                 sql = "insert into OA_TW_APPROVEL_FORM(id, form_id, emp_id, department_id, delegate_id, " +
  260.                     "off_type, parenthesis, days, vacation_begin, vacation_end, business_place," +
  261.                     "vacation_place, flight_go_depart, flight_go_arrive, flight_go_time, flight_back_time, " +
  262.                     "flight_back_depart, flight_back_arrive, business_begin, business_end, reason, " +
  263.                     "step, total_result, finish_date, is_del, apply_date, state) values (" +
  264.                     id + ", '" + TxtFormNo.Text + "','" + EmpId.Value + "', '" + DepartmentId.Value + "','" +
  265.                     DelegateId.Value + "','" + DdlOffType.SelectedValue + "','" + TxtParenthesis.Text + "','" +
  266.                     TxtDays.Text + "','" + TxtVacationBegin.Text + "','" + TxtVacationEnd.Text + "','" +
  267.                     DdlBusinessPlace.SelectedValue + "','" + DdlVacationPlace.SelectedValue + "','" +
  268.                     DdlFlightGoDepart.SelectedValue + "','" + DdlFlightGoArrive.SelectedValue + "','" +
  269.                     TxtFlightGoTime.Text + "','" + TxtFlightBackTime.Text + "','" +
  270.                     DdlFlightBackDepart.SelectedValue + "','" + DdlFlightBackArrive.SelectedValue + "','" +
  271.                     TxtBusinessBegin.Text + "','" + TxtBusinessEnd.Text + "','" + TxtReason.Text + "'," +
  272.                     "0,'" + total_result + "','','N','" + TxtApplyDate.Text + "','" + state + "')";
  273.                 cmd = new SqlCommand(sql, conn);
  274.                 cmd.Transaction = tx;
  275.                 cmd.ExecuteNonQuery();
  276.                 int flow_id = 1;
  277.                 cmd = new SqlCommand("select max(id) from OA_TW_APPROVEL_FORM_FLOW", conn);
  278.                 cmd.Transaction = tx;
  279.                 try
  280.                 {
  281.                     flow_id = Convert.ToInt32(cmd.ExecuteScalar().ToString()) + 1;
  282.                 }
  283.                 catch { }
  284.                 cmd = new SqlCommand("select max(id) from OA_delegate", conn);
  285.                 cmd.Transaction = tx;
  286.                 
  287.                 //跑代理人            
  288.                 cmd = new SqlCommand( "select email_work from oa_employee where id=" + DelegateId.Value, conn);
  289.                  cmd.Transaction = tx;                
  290.                 string email_work = cmd.ExecuteScalar().ToString();
  291.                
  292.                   
  293.                 sql = "insert into OA_TW_APPROVEL_FORM_FLOW(id, form_id, operator_id, " +
  294.                     "apply_type, is_check, is_agree, comment, check_date, step) values (" +
  295.                     flow_id + ", " + id + "," + DelegateId.Value + ",2,'N','N','','',1)";
  296.                 cmd = new SqlCommand(sql, conn);
  297.                 cmd.Transaction = tx;
  298.                 cmd.ExecuteNonQuery();
  299.                 mail.mail_d(email_work, TxtDelegate.Text.Substring(7), TxtEmpName.Text);
  300.                 
  301.                 if (state == 1)
  302.                 {//逐级签核
  303.                     flow_id++;
  304.                     ArrayList id1 = new ArrayList();//记录上层节点职级小于登陆者的ID
  305.                     ArrayList name1 = new ArrayList();//记录上层节点职级小于登陆者的name
  306.                     ArrayList mail1 = new ArrayList();//记录上层节点职级小于登陆者的mail
  307.                     ArrayList last_id = new ArrayList();//记录上层节点的ID
  308.                     ArrayList ceng = new ArrayList();//记录层的ID
  309.                     ArrayList tmp_people = new ArrayList();//记录待签核人的ID
  310.                     ArrayList d_people = new ArrayList();
  311.                     ArrayList b_d_people = new ArrayList();
  312.                     ArrayList mail2 = new ArrayList();//记录代理人的MAIL
  313.                     ArrayList mail2_name = new ArrayList();//记录代理人姓名
  314.                     //判断是否为副董办公室
  315.                     if (DepartmentId.Value.ToString().Equals("50")) {
  316.                                                
  317.                               cmd = new SqlCommand("insert into OA_TW_APPROVEL_FORM_FLOW(id,form_id, operator_id, " +
  318.                                   "apply_type, is_check, is_agree, comment, check_date, step)values(" +
  319.                                   flow_id + ", " + id + ",'128',2,'N','N','',''," + 2 + ")", conn);
  320.                               cmd.Transaction = tx;
  321.                               cmd.ExecuteNonQuery();
  322.                           
  323.                               flow_id++;
  324.                            cmd = new SqlCommand("update OA_TW_APPROVEL_FORM_FLOW set total_result='同意' where id=" + flow_id, conn);
  325.                         
  326.                           //代理人资料(OA_DELEGATE)
  327.                         
  328.                               cmd = new SqlCommand("insert into OA_DELEGATE(d_people,b_d_people,s_date,e_date)values('"
  329.                               + DelegateId.Value + "','" + Session["user_id"] + "','" + TxtVacationBegin.Text + "','" + TxtVacationEnd.Text + "')", conn);
  330.                               cmd.Transaction = tx;
  331.                               cmd.ExecuteNonQuery();
  332.                               flow_id++;
  333.                         
  334.                           tx.Commit();
  335.                           Response.Redirect("my_list.aspx");
  336.                    
  337.                       } 
  338.                     //判断职级,大于8的是一个情况
  339.                     if (Convert.ToInt32(PositionId.Value) > 8) {
  340.                        
  341.                   
  342.                         //找到上层节点部门的ID
  343.                         last_id.Add(DepartmentId.Value.ToString());
  344.                         for (int j = 1; j < 2; j++)
  345.                         {
  346.                             cmd = new SqlCommand("select distinct last_id from oa_department where id=" + last_id[j - 1], conn);
  347.                             cmd.Transaction = tx;
  348.                             SqlDataReader dr2 = cmd.ExecuteReader();
  349.                             while (dr2.Read())
  350.                             {
  351.                                 last_id.Add(dr2["last_id"].ToString());
  352.                             }
  353.                             dr2.Close();
  354.                         }
  355.                         //找到上层节点人的ID
  356.                         for (int i = 1; i < last_id.Count; i++)
  357.                         {                            
  358.                             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" +
  359.                            " where  position<" + PositionId.Value + "and b.id=" + last_id[i] + " and q_manger=1 order by position desc", conn);
  360.                            cmd.Transaction = tx;
  361.                             SqlDataReader dr1 = cmd.ExecuteReader();
  362.                             while (dr1.Read())
  363.                             {
  364.                                 id1.Add(dr1["id"].ToString());
  365.                                 name1.Add(dr1["emp_name"].ToString());
  366.                                 mail1.Add(dr1["email_work"].ToString());
  367.                                 tmp_people.Add(dr1["id"].ToString());
  368.                             }
  369.                             dr1.Close();
  370.                         }
  371.                        
  372.                     }
  373.                        //职级小于8的是一个情况
  374.                     else if (Convert.ToInt32(PositionId.Value) <= 8)
  375.                     {
  376.                   
  377.                         //找到上层节点部门的ID
  378.                         last_id.Add(DepartmentId.Value.ToString());
  379.                         for (int j = 1; j < 5; j++)
  380.                         {
  381.                             
  382.                             cmd = new SqlCommand("select distinct last_id from oa_department where id="+last_id[j-1], conn);
  383.                             cmd.Transaction = tx;
  384.                             SqlDataReader dr2 = cmd.ExecuteReader();
  385.                             
  386.                             while (dr2.Read())
  387.                             {
  388.                                 last_id.Add(dr2["last_id"].ToString());
  389.                                 
  390.                             }
  391.                             dr2.Close();
  392.                         }
  393.                         //找到上层节点人的ID
  394.                         if (last_id.Count != 0)
  395.                         {
  396.                             for (int i = 1; i < last_id.Count; i++)
  397.                             {
  398.                                 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" +
  399.                                     " where  position<" + PositionId.Value + "and b.id=" + last_id[i] + " and q_manger=1 order by position desc", conn);
  400.                                 cmd.Transaction = tx;
  401.                                 SqlDataReader dr1 = cmd.ExecuteReader();
  402.                                 while (dr1.Read())
  403.                                 {
  404.                                     id1.Add(dr1["id"].ToString());
  405.                                     name1.Add(dr1["emp_name"].ToString());
  406.                                     mail1.Add(dr1["email_work"].ToString());
  407.                                  
  408.                                 } dr1.Close();
  409.                                 
  410.                             }
  411.                         }
  412.                     //  确定是否有代理人签核
  413.                         for (int k = 0; k < id1.Count; k++)
  414.                         {
  415.                             cmd = new SqlCommand("select d_people,b_d_people from oa_delegate where  s_date<=convert(varchar, getdate(), 120)" +
  416.                                   " and e_date>=convert(varchar, getdate(),120) and b_d_people='" + id1[k] + "'", conn);
  417.                             cmd.Transaction = tx;
  418.                             SqlDataReader dr3 = cmd.ExecuteReader();
  419.                             while (dr3.Read())
  420.                             {
  421.                                 d_people.Add(dr3["d_people"].ToString());
  422.                                 b_d_people.Add(dr3["b_d_people"].ToString());
  423.                                 id1.RemoveAt(k);
  424.                                 id1.Add(dr3["d_people"].ToString());
  425.                             }
  426.                             dr3.Close();
  427.                         }
  428.                         
  429.                      //   
  430.                       
  431.                     }
  432.                    
  433.                     if (id1.Count!= null)
  434.                     {
  435.                       
  436.                         for (int i = 0; i < id1.Count; i++)
  437.                         {
  438.                             cmd = new SqlCommand("insert into OA_TW_APPROVEL_FORM_FLOW(id,form_id, operator_id, " +
  439.                                 "apply_type, is_check, is_agree, comment, check_date, step)values(" +
  440.                                 flow_id + ", " + id + "," + id1[i] + ",2,'N','N','',''," + (i + 2) + ")", conn);
  441.                             cmd.Transaction = tx;
  442.                             cmd.ExecuteNonQuery();
  443.                     
  444.                            }                         
  445.                    
  446.                     for (int d = 0; d < id1.Count; d++)
  447.                         {
  448.                             cmd = new SqlCommand("insert into OA_DELEGATE(d_people,b_d_people,s_date,e_date)values('"
  449.                             +DelegateId.Value + "','" + Session["user_id"] + "','" + TxtVacationBegin.Text+"','"+TxtVacationEnd.Text+"')", conn);
  450.                             cmd.Transaction = tx;
  451.                             cmd.ExecuteNonQuery();
  452.                            
  453.                             flow_id++;
  454.                         }
  455.                         tx.Commit();
  456.                         Response.Redirect("my_list.aspx");
  457.                     }
  458.                     else
  459.                     {
  460.                         LblError.Text = "沒有找到相關處理流程, 請與管理員聯繫";
  461.                         tx.Rollback();
  462.                     }
  463.                 }
  464.                 else
  465.                 {
  466.                     tx.Commit();
  467.                     Response.Redirect("my_list.aspx");
  468.                 }
  469.                 #region
  470.               
  471.                 #endregion
  472.             }
  473.             catch (Exception ex)
  474.             {
  475.                 Response.Write(ex.Message);
  476.                 try
  477.                 {
  478.                     tx.Rollback();
  479.                 }
  480.                 catch { }
  481.             }
  482.             conn.Close();
  483.         }
  484.     }
  485.     //遞歸取出辦理人-- position:6-經理; 2-副董
  486.     protected void getEmployee(int department_id, int position)
  487.     {
  488.         int operator_id = 0;
  489.         int flag = 0;
  490.         SqlConnection conn = dbConnection.getConnection();
  491.         conn.Open();
  492.         string sql = "select id from OA_EMPLOYEE where department_id=" + department_id + " and position=" + position;
  493.         if (position == 2)
  494.         {
  495.             sql = "select id from OA_EMPLOYEE where position=" + position;
  496.         }
  497.         SqlCommand cmd = new SqlCommand(sql, conn);
  498.         SqlDataReader dr = cmd.ExecuteReader();
  499.         if (dr.Read())
  500.         {
  501.             operator_id = Convert.ToInt32(dr["id"].ToString());
  502.             OperatorId.Value = operator_id.ToString();
  503.         }
  504.         else
  505.         {
  506.             flag = 1;
  507.         }
  508.         dr.Close();
  509.         count = count + 1;
  510.         if (count == 6)
  511.         {
  512.             flag = 0;
  513.             OperatorId.Value = "0";
  514.         }
  515.         if (flag == 1)
  516.         {
  517.             cmd = new SqlCommand("select last_id from OA_DEPARTMENT where id=" + department_id, conn);
  518.             this.getEmployee(Convert.ToInt32(cmd.ExecuteScalar()), position);
  519.         }
  520.         conn.Close();
  521.     }
  522.     //遞歸取自由流程
  523.     protected void GetFlow(int main_id, int number, SqlConnection conn, SqlTransaction tx)
  524.     {
  525.         string sql = "select top 1 apply_type, operator_id, number, next_number, " +
  526.             "larger_than, larger_next from OA_FLOW_DETAIL where main_id=" + main_id + " order by number";
  527.         if (number != 0)
  528.         {
  529.             sql = "select top 1 apply_type, operator_id, number, next_number, " +
  530.              "larger_than, larger_next from OA_FLOW_DETAIL where main_id=" + main_id + " and number=" + number;
  531.         }
  532.         SqlCommand cmd = new SqlCommand(sql, conn);
  533.         cmd.Transaction = tx;
  534.         int next = 0;
  535.         int flag = 0;
  536.         SqlDataReader dr = cmd.ExecuteReader();
  537.         if (dr.Read())
  538.         {
  539.             apply_type.Add(dr["apply_type"].ToString());
  540.             operator_id.Add(dr["operator_id"].ToString());
  541.             if (!dr["larger_than"].ToString().Equals("0"))
  542.             {
  543.                 if (Convert.ToInt32(dr["larger_than"].ToString()) < Convert.ToInt32(TxtDays.Text))
  544.                 {
  545.                     if (!dr["larger_next"].Equals(""))
  546.                     {
  547.                         flag = 1;
  548.                         next = Convert.ToInt32(dr["larger_next"].ToString());
  549.                     }
  550.                 }
  551.                 else
  552.                 {
  553.                     if (!dr["next_number"].Equals(""))
  554.                     {
  555.                         flag = 1;
  556.                         next = Convert.ToInt32(dr["next_number"].ToString());
  557.                     }
  558.                 }
  559.             }
  560.             else
  561.             {
  562.                 if (!dr["next_number"].ToString().Equals(""))
  563.                 {
  564.                     flag = 1;
  565.                     next = Convert.ToInt32(dr["next_number"].ToString());
  566.                 }
  567.             }
  568.         }
  569.         dr.Close();
  570.         if (flag == 1)
  571.         {
  572.             this.GetFlow(main_id, next, conn, tx);
  573.         }
  574.     }
  575.     protected bool CheckValidate()
  576.     {
  577.         LblError.Text = "";
  578.         int flag = 0;
  579.         try
  580.         {
  581.             double day = Convert.ToDouble(TxtDays.Text);
  582.         }
  583.         catch
  584.         {
  585.             flag = 1;
  586.             Response.Write("<script>alert('工作日数格式有误')</script>");
  587.             LblError.Text = "工作日数格式有误";
  588.             TxtDays.Focus();
  589.         }
  590.         if (DelegateId.Value.Equals("") || DelegateId.Value.Equals("0"))
  591.         {
  592.             flag = 1;
  593.             Response.Write("<script>alert('請選擇代理人')</script>");
  594.             LblError.Text = "請選擇代理人";
  595.             TxtDelegate.Focus();
  596.         }
  597.         if (flag == 0)
  598.         {
  599.             return true;
  600.         }
  601.         else
  602.         {
  603.             return false;
  604.         }
  605.     }
  606.       protected bool checktime() {
  607.         LblError.Text = "";
  608.         int flag = 0;
  609.        
  610.         if (DdlOffType.SelectedItem.Text.Equals("出差"))
  611.         {
  612.             if (TxtBusinessBegin.Text == "" || TxtBusinessEnd.Text == "")
  613.             { flag = 2; }
  614.         }
  615.        else
  616.         {
  617.             if (TxtVacationBegin.Text == "" || TxtVacationEnd.Text == "")
  618.             { flag = 1; }
  619.         }
  620.         if (flag == 1)
  621.         {
  622.             Response.Write("<script>alert('休假日起止不能为空')</script>");
  623.             LblError.Text = "休假日起止不能为空";
  624.             TxtVacationBegin.Focus();
  625.             return false;
  626.         }
  627.         else if (flag == 2)
  628.         {
  629.             Response.Write("<script>alert('出差日起止不能为空')</script>");
  630.             LblError.Text = "出差日起止不能为空";
  631.             TxtBusinessBegin.Focus();
  632.             return false;
  633.         }
  634.         else
  635.         { 
  636.             return true; 
  637.         }
  638.     }
  639.     protected void DdlOffType_SelectedIndexChanged(object sender, EventArgs e)
  640.     {
  641.         if (DdlOffType.SelectedItem.Text.Equals("出差"))
  642.         {
  643.             TxtBusinessBegin.Enabled = true;
  644.             TxtBusinessEnd.Enabled = true;
  645.             ImageButton3.Enabled = true;
  646.             ImageButton4.Enabled = true;
  647.             LblBusinessBegin.Enabled = true;
  648.             LblBusinessEnd.Enabled = true;
  649.             LblBusinessPlace.Enabled = true;
  650.             DdlBusinessPlace.Enabled = true;
  651.             LblDays.Text = "工作日數";
  652.             DdlOffType.Focus();
  653.             
  654.             TxtVacationBegin.Enabled = false;
  655.             TxtVacationEnd.Enabled = false;
  656.             DdlVacationPlace.Enabled = false;
  657.             ImageButton1.Enabled = false;
  658.             ImageButton2.Enabled = false;
  659.             LblVacationBegin.Enabled = false;
  660.             LblVacationEnd.Enabled = false;
  661.             LblVacationPlace.Enabled = false;
  662.         }
  663.         else
  664.         {
  665.             TxtBusinessBegin.Enabled = false;
  666.             TxtBusinessEnd.Enabled = false;
  667.             ImageButton3.Enabled = false;
  668.             ImageButton4.Enabled = false;
  669.             LblBusinessBegin.Enabled = false;
  670.             LblBusinessEnd.Enabled = false;
  671.             LblBusinessPlace.Enabled = false;
  672.             DdlBusinessPlace.Enabled = false;
  673.             LblDays.Text = "休假日數";
  674.             DdlOffType.Focus();
  675.             TxtVacationBegin.Enabled = true;
  676.             TxtVacationEnd.Enabled = true;
  677.             DdlVacationPlace.Enabled = true;
  678.             ImageButton1.Enabled = true;
  679.             ImageButton2.Enabled = true;
  680.             LblVacationBegin.Enabled = true;
  681.             LblVacationEnd.Enabled = true;
  682.             LblVacationPlace.Enabled = true;
  683.             
  684.         }
  685.     }
  686. }