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

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