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 + " 07:50: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 + " 17:30: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 + " 07:50: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 + " 17:30: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 + ",3,'N','N','','',1)";
  296.                 cmd = new SqlCommand(sql, conn);
  297.                 
  298.                 cmd.Transaction = tx;
  299.                 cmd.ExecuteNonQuery();
  300.                 try { mail.mail_d(email_work, TxtDelegate.Text.Substring(7), TxtEmpName.Text); }
  301.                 catch { }
  302.                 
  303.                 if (state == 1)
  304.                 {//逐级签核
  305.                     flow_id++;
  306.                     ArrayList id1 = new ArrayList();//记录上层节点职级小于登陆者的ID
  307.                     ArrayList name1 = new ArrayList();//记录上层节点职级小于登陆者的name
  308.                     ArrayList mail1 = new ArrayList();//记录上层节点职级小于登陆者的mail
  309.                     ArrayList last_id = new ArrayList();//记录上层节点的ID
  310.                     ArrayList tmp_people = new ArrayList();//记录待签核人的ID
  311.                     ArrayList d_people = new ArrayList();
  312.                     ArrayList b_d_people = new ArrayList();
  313.                     ArrayList mail2 = new ArrayList();//记录代理人的MAIL
  314.                     ArrayList mail2_name = new ArrayList();//记录代理人姓名
  315.                     //判断是否为副董办公室
  316.                     if (DepartmentId.Value.ToString().Equals("50")) {                                              
  317.                                                     
  318.                           tx.Commit();
  319.                           Response.Redirect("my_list.aspx");
  320.                    
  321.                       } 
  322.                     //判断职级,大于8的是一个情况
  323.                     if (Convert.ToInt32(PositionId.Value) > 8) {
  324.                         int ceng = 0;
  325.                         cmd = new SqlCommand("select ceng from oa_department where id=" + DepartmentId.Value, conn);
  326.                         cmd.Transaction = tx;
  327.                         try
  328.                         {
  329.                             ceng = Convert.ToInt32(cmd.ExecuteScalar());
  330.                         }
  331.                         catch { }
  332.                         //找到上层节点部门的ID
  333.                         last_id.Add(DepartmentId.Value.ToString());
  334.                         for (int j = 1; j < ceng; j++)
  335.                         {
  336.                             cmd = new SqlCommand("select distinct last_id from oa_department where id=" + last_id[j - 1], conn);
  337.                             cmd.Transaction = tx;
  338.                             SqlDataReader dr2 = cmd.ExecuteReader();
  339.                             while (dr2.Read())
  340.                             {
  341.                                 last_id.Add(dr2["last_id"].ToString());
  342.                             }
  343.                             dr2.Close();
  344.                         }
  345.                         //找到上层节点人的ID
  346.                         for (int i = 0; i < last_id.Count; i++)
  347.                         {                            
  348.                             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" +
  349.                            " where  b.id=" + last_id[i] + " and q_manger=1 order by position desc", conn);
  350.                            cmd.Transaction = tx;
  351.                             SqlDataReader dr1 = cmd.ExecuteReader();
  352.                             while (dr1.Read())
  353.                             {
  354.                                 id1.Add(dr1["id"].ToString());
  355.                                 name1.Add(dr1["emp_name"].ToString());
  356.                                 mail1.Add(dr1["email_work"].ToString());
  357.                                 tmp_people.Add(dr1["id"].ToString());
  358.                             }
  359.                             dr1.Close();
  360.                         }
  361.                         //是本人,跳過
  362.                         for (int i = 0; i < id1.Count; i++)
  363.                         {
  364.                             if (id1[i].ToString().Equals(Session["user_id"].ToString())) { id1.RemoveAt(i); }
  365.                         }
  366.                         //
  367.                        
  368.                        
  369.                     }
  370.                        //职级小于8的是一个情况
  371.                     else if (Convert.ToInt32(PositionId.Value) <= 8)
  372.                     {
  373.                   
  374.                         //找到上层节点部门的ID
  375.                         last_id.Add(DepartmentId.Value.ToString());
  376.                         for (int j = 1; j < 5; j++)
  377.                         {
  378.                             
  379.                             cmd = new SqlCommand("select distinct last_id from oa_department where id="+last_id[j-1], conn);
  380.                             cmd.Transaction = tx;
  381.                             SqlDataReader dr2 = cmd.ExecuteReader();
  382.                             
  383.                             while (dr2.Read())
  384.                             {
  385.                                 last_id.Add(dr2["last_id"].ToString());
  386.                                 
  387.                             }
  388.                             dr2.Close();
  389.                         }
  390.                         //找到上层节点人的ID
  391.                         if (last_id.Count != 0)
  392.                         {
  393.                             for (int i = 1; i < last_id.Count; i++)
  394.                             {
  395.                                 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" +
  396.                                     " where  position<" + PositionId.Value + "and b.id=" + last_id[i] + " and q_manger=1 order by position desc", conn);
  397.                                 cmd.Transaction = tx;
  398.                                 SqlDataReader dr1 = cmd.ExecuteReader();
  399.                                 while (dr1.Read())
  400.                                 {
  401.                                     id1.Add(dr1["id"].ToString());
  402.                                     name1.Add(dr1["emp_name"].ToString());
  403.                                     mail1.Add(dr1["email_work"].ToString());
  404.                                  
  405.                                 } dr1.Close();
  406.                                 
  407.                             }
  408.                         }
  409.                     //  确定是否有代理人签核
  410.                         for (int k = 0; k < id1.Count; k++)
  411.                         {
  412.                             cmd = new SqlCommand("select d_people,b_d_people from oa_delegate where  s_date<=convert(varchar, getdate(), 120)" +
  413.                                   " and e_date>=convert(varchar, getdate(),120) and b_d_people='" + id1[k] + "'", conn);
  414.                             cmd.Transaction = tx;
  415.                             SqlDataReader dr3 = cmd.ExecuteReader();
  416.                             while (dr3.Read())
  417.                             {
  418.                                 d_people.Add(dr3["d_people"].ToString());
  419.                                 b_d_people.Add(dr3["b_d_people"].ToString());
  420.                                 id1.RemoveAt(k);
  421.                                 id1.Add(dr3["d_people"].ToString());
  422.                             }
  423.                             dr3.Close();
  424.                         }
  425.                         
  426.                      //                      
  427.                     }
  428.                     //是本人,跳過
  429.                     for (int i = 0; i < id1.Count; i++)
  430.                     {
  431.                         if (id1[i].ToString().Equals(Session["user_id"].ToString())) { id1.RemoveAt(i); }
  432.                     }  
  433.                    //
  434.                     if (id1.Count!= null)
  435.                     {
  436.                       
  437.                         for (int i = 0; i < id1.Count; i++)
  438.                         {
  439.                             cmd = new SqlCommand("insert into OA_TW_APPROVEL_FORM_FLOW(id,form_id, operator_id, " +
  440.                                 "apply_type, is_check, is_agree, comment, check_date, step)values(" +
  441.                                 flow_id + ", " + id + "," + id1[i] + ",2,'N','N','',''," + (i + 2) + ")", conn);
  442.                             cmd.Transaction = tx;
  443.                             cmd.ExecuteNonQuery();
  444.                             flow_id++;
  445.                     
  446.                            }                         
  447.                    
  448.                     for (int d = 0; d < id1.Count; d++)
  449.                         {
  450.                             cmd = new SqlCommand("insert into OA_DELEGATE(d_people,b_d_people,s_date,e_date)values('"
  451.                             +DelegateId.Value + "','" + Session["user_id"] + "','" + TxtVacationBegin.Text+"','"+TxtVacationEnd.Text+"')", conn);
  452.                             cmd.Transaction = tx;
  453.                             cmd.ExecuteNonQuery();
  454.                            
  455.                             flow_id++;
  456.                         }
  457.                         tx.Commit();
  458.                         Response.Redirect("my_list.aspx");
  459.                     }
  460.                     else
  461.                     {
  462.                         LblError.Text = "沒有找到相關處理流程, 請與管理員聯繫";
  463.                         tx.Rollback();
  464.                     }
  465.                 }
  466.                 else
  467.                 {
  468.                     tx.Commit();
  469.                     Response.Redirect("my_list.aspx");
  470.                 }
  471.                 #region
  472.               
  473.                 #endregion
  474.             }
  475.             catch (Exception ex)
  476.             {
  477.                 Response.Write(ex.Message);
  478.                 try
  479.                 {
  480.                     tx.Rollback();
  481.                 }
  482.                 catch { }
  483.             }
  484.             conn.Close();
  485.         }
  486.     }
  487.     //遞歸取出辦理人-- position:6-經理; 2-副董
  488.     protected void getEmployee(int department_id, int position)
  489.     {
  490.         int operator_id = 0;
  491.         int flag = 0;
  492.         SqlConnection conn = dbConnection.getConnection();
  493.         conn.Open();
  494.         string sql = "select id from OA_EMPLOYEE where department_id=" + department_id + " and position=" + position;
  495.         if (position == 2)
  496.         {
  497.             sql = "select id from OA_EMPLOYEE where position=" + position;
  498.         }
  499.         SqlCommand cmd = new SqlCommand(sql, conn);
  500.         SqlDataReader dr = cmd.ExecuteReader();
  501.         if (dr.Read())
  502.         {
  503.             operator_id = Convert.ToInt32(dr["id"].ToString());
  504.             OperatorId.Value = operator_id.ToString();
  505.         }
  506.         else
  507.         {
  508.             flag = 1;
  509.         }
  510.         dr.Close();
  511.         count = count + 1;
  512.         if (count == 6)
  513.         {
  514.             flag = 0;
  515.             OperatorId.Value = "0";
  516.         }
  517.         if (flag == 1)
  518.         {
  519.             cmd = new SqlCommand("select last_id from OA_DEPARTMENT where id=" + department_id, conn);
  520.             this.getEmployee(Convert.ToInt32(cmd.ExecuteScalar()), position);
  521.         }
  522.         conn.Close();
  523.     }
  524.     //遞歸取自由流程
  525.     protected void GetFlow(int main_id, int number, SqlConnection conn, SqlTransaction tx)
  526.     {
  527.         string sql = "select top 1 apply_type, operator_id, number, next_number, " +
  528.             "larger_than, larger_next from OA_FLOW_DETAIL where main_id=" + main_id + " order by number";
  529.         if (number != 0)
  530.         {
  531.             sql = "select top 1 apply_type, operator_id, number, next_number, " +
  532.              "larger_than, larger_next from OA_FLOW_DETAIL where main_id=" + main_id + " and number=" + number;
  533.         }
  534.         SqlCommand cmd = new SqlCommand(sql, conn);
  535.         cmd.Transaction = tx;
  536.         int next = 0;
  537.         int flag = 0;
  538.         SqlDataReader dr = cmd.ExecuteReader();
  539.         if (dr.Read())
  540.         {
  541.             apply_type.Add(dr["apply_type"].ToString());
  542.             operator_id.Add(dr["operator_id"].ToString());
  543.             if (!dr["larger_than"].ToString().Equals("0"))
  544.             {
  545.                 if (Convert.ToInt32(dr["larger_than"].ToString()) < Convert.ToInt32(TxtDays.Text))
  546.                 {
  547.                     if (!dr["larger_next"].Equals(""))
  548.                     {
  549.                         flag = 1;
  550.                         next = Convert.ToInt32(dr["larger_next"].ToString());
  551.                     }
  552.                 }
  553.                 else
  554.                 {
  555.                     if (!dr["next_number"].Equals(""))
  556.                     {
  557.                         flag = 1;
  558.                         next = Convert.ToInt32(dr["next_number"].ToString());
  559.                     }
  560.                 }
  561.             }
  562.             else
  563.             {
  564.                 if (!dr["next_number"].ToString().Equals(""))
  565.                 {
  566.                     flag = 1;
  567.                     next = Convert.ToInt32(dr["next_number"].ToString());
  568.                 }
  569.             }
  570.         }
  571.         dr.Close();
  572.         if (flag == 1)
  573.         {
  574.             this.GetFlow(main_id, next, conn, tx);
  575.         }
  576.     }
  577.     protected bool CheckValidate()
  578.     {
  579.         LblError.Text = "";
  580.         int flag = 0;
  581.         try
  582.         {
  583.             double day = Convert.ToDouble(TxtDays.Text);
  584.         }
  585.         catch
  586.         {
  587.             flag = 1;
  588.             Response.Write("<script>alert('格式有误')</script>");
  589.             LblError.Text = LblDays.Text+"格式有误";
  590.             TxtDays.Focus();
  591.         }
  592.         if (DelegateId.Value.Equals("") || DelegateId.Value.Equals("0"))
  593.         {
  594.             flag = 1;
  595.             Response.Write("<script>alert('請選擇代理人')</script>");
  596.             LblError.Text = "請選擇代理人";
  597.             TxtDelegate.Focus();
  598.         }
  599.         if (flag == 0)
  600.         {
  601.             return true;
  602.         }
  603.         else
  604.         {
  605.             return false;
  606.         }
  607.     }
  608.       protected bool checktime() {
  609.         LblError.Text = "";
  610.         int flag = 0;
  611.        
  612.         if (DdlOffType.SelectedItem.Text.Equals("出差"))
  613.         {
  614.             if (TxtBusinessBegin.Text == "" || TxtBusinessEnd.Text == "")
  615.             { flag = 2; }
  616.         }
  617.        else
  618.         {
  619.             if (TxtVacationBegin.Text == "" || TxtVacationEnd.Text == "")
  620.             { flag = 1; }
  621.         }
  622.         if (flag == 1)
  623.         {
  624.             Response.Write("<script>alert('休假日起止不能为空')</script>");
  625.             LblError.Text = "休假日起止不能为空";
  626.             TxtVacationBegin.Focus();
  627.             return false;
  628.         }
  629.         else if (flag == 2)
  630.         {
  631.             Response.Write("<script>alert('出差日起止不能为空')</script>");
  632.             LblError.Text = "出差日起止不能为空";
  633.             TxtBusinessBegin.Focus();
  634.             return false;
  635.         }
  636.         else
  637.         { 
  638.             return true; 
  639.         }
  640.     }
  641.     protected void DdlOffType_SelectedIndexChanged(object sender, EventArgs e)
  642.     {
  643.         if (DdlOffType.SelectedItem.Text.Equals("出差"))
  644.         {
  645.             TxtBusinessBegin.Enabled = true;
  646.             TxtBusinessEnd.Enabled = true;
  647.             ImageButton3.Enabled = true;
  648.             ImageButton4.Enabled = true;
  649.             LblBusinessBegin.ForeColor = System.Drawing.Color.Black;
  650.             LblBusinessEnd.ForeColor = System.Drawing.Color.Black;
  651.             LblBusinessPlace.ForeColor = System.Drawing.Color.Black;
  652.             DdlBusinessPlace.Enabled = true;
  653.             LblDays.Text = "工作日數";
  654.             DdlOffType.Focus();
  655.             
  656.             TxtVacationBegin.Enabled = false;
  657.             TxtVacationEnd.Enabled = false;
  658.             DdlVacationPlace.Enabled = false;
  659.             ImageButton1.Enabled = false;
  660.             ImageButton2.Enabled = false;
  661.             LblVacationBegin.ForeColor = System.Drawing.Color.SlateGray;
  662.             LblVacationEnd.ForeColor = System.Drawing.Color.SlateGray;
  663.             LblVacationPlace.ForeColor = System.Drawing.Color.SlateGray;
  664.         }
  665.         else
  666.         {
  667.             TxtBusinessBegin.Enabled = false;
  668.             TxtBusinessEnd.Enabled = false;
  669.             ImageButton3.Enabled = false;
  670.             ImageButton4.Enabled = false;
  671.             LblBusinessBegin.ForeColor = System.Drawing.Color.SlateGray;
  672.             LblBusinessEnd.ForeColor = System.Drawing.Color.SlateGray;
  673.             LblBusinessPlace.ForeColor = System.Drawing.Color.SlateGray;
  674.             DdlBusinessPlace.Enabled = false;
  675.             LblDays.Text = "休假日數";
  676.             DdlOffType.Focus();
  677.             TxtVacationBegin.Enabled = true;
  678.             TxtVacationEnd.Enabled = true;
  679.             DdlVacationPlace.Enabled = true;
  680.             ImageButton1.Enabled = true;
  681.             ImageButton2.Enabled = true;
  682.             LblVacationBegin.ForeColor = System.Drawing.Color.Black;
  683.             LblVacationEnd.ForeColor = System.Drawing.Color.Black;
  684.             LblVacationPlace.ForeColor = System.Drawing.Color.Black;
  685.             
  686.         }
  687.     }
  688. }