跳到主要內容

online meeting - with cisco webex xml

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="index" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<link rel="stylesheet" type="text/css" href="Content/mrr.css" />
   
<link rel="stylesheet" type="text/css" href="Content/jquery-ui.min.css" />
<link rel="stylesheet" type="text/css" href="Content/jquery-ui.structure.min.css" />
<link rel="stylesheet" type="text/css" href="Content/jquery-ui.theme.css" />
<link rel="stylesheet" type="text/css" href="Content/Site.css" />   
  
<script type="text/javascript" src="Scripts/jquery-1.10.2.min.js"></script>
<%--<script type="text/javascript" src="Scripts/jquery-1.10.2.intellisense.js"></script>--%>
<%--<script type="text/javascript" src="Scripts/jquery-1.10.2.min.map"></script>--%>
<script type="text/javascript" src="Scripts/jquery-ui.min.js"></script>       
<script type="text/javascript" src="Scripts/jquery.blockUI.js"></script>


<script type="text/javascript" >
    $(document).ready(function () {
        setup();           
    });
</script>

<script type="text/javascript" >
    function setup() {
                      
        $("#TextBox1").datepicker({
            dateFormat: "yy/mm/dd",
            dafaultDate: new Date(),
            minDate: new Date()               
        });
           
    }
</script>       

<script>
    window.onerror = function (msg, url, linenumber) {      
        return true;
    }
</script>


<style>
/*.tooltip {
    position: relative;
    display: inline-block;
    border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color:lightyellow;
    color: #000;
    text-align: center;
    border-radius: 6px;
    padding: 5px 0;  
    position: absolute ;
    left: 60px ;
    top : 50px;
    z-index: 1000;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
}*/
</style>

<style>
      .ui-widget-header,.ui-state-default, ui-button{
         background:#3366cc;
         border: 1px solid #b9cd6d;
         color: #FFFFFF;
         font-weight: bold;
      }
</style>


<style>
a.tooltip span{
 z-index: 10;
 display: none;
 border-radius:4px;
 -moz-border-radius: 4px;
 -webkit-border-radius: 4px;
 }
 a.tooltip:hover span{
 display: inline;
 position: absolute;
 border: 1px solid #8c8c8c;
 background: #f4f4f4;
 }
 a.tooltip > span{
 width: 150px;
 padding: 10px 12px;
 opacity: 0;
 visibility: hidden;
 z-index: 10;
 position: absolute;
 font-size: 12px;
 font-style: normal;
 -webkit-border-radius: 3px;
 -moz-border-radius: 3px; -o-border-radius: 3px;
 border-radius: 3px;
 -webkit-box-shadow: 4px 4px 4px #d9b3c3;
 -moz-box-shadow: 4px 4px 4px #d9b3c3;
 box-shadow: 4px 4px 4px #d9b3c3;
 }
 a.tooltip:hover > span{
 opacity: 1;
 text-decoration:none;
 visibility: visible;
 overflow: visible;
 margin-top: 40px;
 display: inline;
 margin-left: -200px;
 }
 a.tooltip span b{
 width: 15px;
 height: 15px;
 margin-left: 20px;
 margin-top: -19px;
 display: block;
 position: absolute;
 -webkit-transform: rotate(-45deg);
 -moz-transform: rotate(-45deg);
 -o-transform: rotate(-45deg);
 transform: rotate(-45deg);
 -webkit-box-shadow: inset -1px 1px 0 #fff;
 -moz-box-shadow: inset 0 1px 0 #fff; -o-box-shadow: inset 0 1px 0 #fff;
 box-shadow: inset 0 1px 0 #fff;
 display: none\0/; *display: none;
 background: #f4f4f4;
 border-top: 1px solid #8c8c8c;
 border-right: 1px solid #8c8c8c;
 }
 a.tooltip > span{
 color: #000000;
 background: #f4f4f4;
 background: -moz-linear-gradient(top, #FBF5E6 0%, #FFFFFF 100%);
 background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#FBF5E6), color-stop(100%,#FFFFFF));
 filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#FBF5E6', endColorstr='#FFFFFF',GradientType=0 );
 border: 1px solid #8c8c8c;
 }
 </style>


<script>
    function exeBlockui(t)
    {       
            $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
            setTimeout($.unblockUI, t);       
    }
</script>


<script>
    //$(document).ready(function () {
    //    $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
    //    setTimeout($.unblockUI, 000);
    //});

    $(document).ready(function () {
        $('#RadioButton1').change(function () {
            $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
            setTimeout($.unblockUI, 3000);
        });
    });
    $(document).ready(function () {
        $('#RadioButton2').change(function () {
            $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
            setTimeout($.unblockUI, 8000);
        });
    });
    $(document).ready(function () {
        $('.class2').click(function () {
            $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
            setTimeout($.unblockUI, 3000);
        });
    });
    $(document).ready(function () {
        $(".class1").click(function () {
            $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
            setTimeout($.unblockUI, 8000);
        });
    });

</script>

<script>
    function exeBlockui(t) {
        $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
        setTimeout($.unblockUI, t);
    }
</script>

<script>
    $(document).ready(function () {

        $("#TextBox1").change(function () {
            if ($("input:radio[name=rdo1]").is(":checked")) {
                $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
                setTimeout($.unblockUI, 3000);
            }
            else {
                $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
                setTimeout($.unblockUI, 8000);
            }           
        });
       
   });

</script>


</head>


<body class="" id="theBody" runat="server">
    <form id="form1" runat="server">
  
         <div class="divWrapper" id="mainContent" runat="server">

             <table class='indexBannerWrapperTable'>
                <tr>
                    <td>
                        <img width="190px" height="50px" src="images/logo_190x50.jpg" />
                    </td>
                    <td style="text-align: right">
                        <font style="font-size:14px">顯示 : </font>
                        <asp:RadioButton ID="RadioButton1"  name="rdo1"  runat="server"  Font-Size="14px"  Checked="True" Text="一日" AutoPostBack="True"    OnCheckedChanged="RadioButton1_CheckedChanged" />
                             &nbsp;<asp:RadioButton ID="RadioButton2"     name="rdo2"   Font-Size="14px"  runat="server" Text="一週" AutoPostBack="True" OnCheckedChanged="RadioButton2_CheckedChanged" />
                        <font>&nbsp;</font>
                        <asp:Button ID="Button1" runat="server" Text="前一天" OnClick="Button1_Click" />
&nbsp;<asp:TextBox   style="ime-mode: disabled;"    OnKeyDown="javascript: return false"   ID="TextBox1" runat="server" Width="103px" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
                        <span id="group" style="FONT-SIZE: 16px; BACKGROUND-COLOR: #d9ecff">
                        <asp:Button ID="Button2" runat="server" Text="今天" OnClick="Button2_Click" />
                        </span>
                        <asp:Button ID="Button3"  runat ="server" Text="後一天" OnClick="Button3_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </td>
                    <td>
                        <span id="group" style="FONT-SIZE: 16px; BORDER-TOP: gray 1px solid; BORDER-RIGHT: gray 1px solid; BORDER-BOTTOM: gray 1px solid; PADDING-BOTTOM: 3px; PADDING-LEFT: 5px; BORDER-LEFT: gray 1px solid; PADDING-RIGHT: 5px; BACKGROUND-COLOR: #d9ecff">美商科技</span>
                        <a href="docs/會議室預約系統-操作手冊V01R01.pdf">- 會議室使用狀況查詢
                            <img alt="help" border="0" title="help" height="15" width="15" src="images/help.gif">
                        </a>
                    </td>
                </tr>
            </table>
            

   <table id="time_schedule" cellSpacing="0" cellPadding="0" border="1" bordercolor="#A6D2FF"  width="1024px" align="left">
    <thead>
       <tr>
         <th id='todayColumn' class="todaySmallCon"> <asp:Label ID="Label1" runat="server" > </asp:Label> </th>
         <th class="topsmallCon"><div>09:00</div><div style='font-size:8px'>|</div><div>09:29</div></th>
         <th class="topsmallCon"><div>09:30</div><div style='font-size:8px'>|</div><div>09:59</div></th>
         <th class="topsmallCon"><div>10:00</div><div style='font-size:8px'>|</div><div>10:29</div></th>
         <th class="topsmallCon"><div>10:30</div><div style='font-size:8px'>|</div><div>10:59</div></th>
         <th class="topsmallCon"><div>11:00</div><div style='font-size:8px'>|</div><div>11:29</div></th>
         <th class="topsmallCon"><div>11:30</div><div style='font-size:8px'>|</div><div>11:59</div></th>
         <th class="topsmallCon"><div>12:00</div><div style='font-size:8px'>|</div><div>12:29</div></th>
         <th class="topsmallCon"><div>12:30</div><div style='font-size:8px'>|</div><div>12:59</div></th>
         <th class="topsmallCon"><div>13:00</div><div style='font-size:8px'>|</div><div>13:29</div></th>
         <th class="topsmallCon"><div>13:30</div><div style='font-size:8px'>|</div><div>13:59</div></th>
         <th class="topsmallCon"><div>14:00</div><div style='font-size:8px'>|</div><div>14:29</div></th>
         <th class="topsmallCon"><div>14:30</div><div style='font-size:8px'>|</div><div>14:59</div></th>
         <th class="topsmallCon"><div>15:00</div><div style='font-size:8px'>|</div><div>15:29</div></th>
         <th class="topsmallCon"><div>15:30</div><div style='font-size:8px'>|</div><div>15:59</div></th>
         <th class="topsmallCon"><div>16:00</div><div style='font-size:8px'>|</div><div>16:29</div></th>
         <th class="topsmallCon"><div>16:30</div><div style='font-size:8px'>|</div><div>16:59</div></th>
      <th class="topsmallCon"><div>17:00</div><div style='font-size:8px'>|</div><div>17:29</div></th>
      <th class="topsmallCon"><div>17:30</div><div style='font-size:8px'>|</div><div>17:59</div></th>
      </tr>
     </thead>
               
                   
    <tbody id="dataBody" >                    
                   
                    <asp:Literal ID="Literal1" runat="server"></asp:Literal>                

               </tbody>
                
                 <%--<tfoot>
                    <tr> <td colspan="19"> &nbsp; </td> </tr>
                 </tfoot>--%>

   </table>

         </div>


       
         <asp:Panel ID="Panel1" runat="server" Visible="false"   style="left:40%; top:40%; position: absolute;width:300px">
               <table border="1" style="width:300px">
                   <tr style="border-width:1px">
                       <td style="font-size:16px;background-color:darkblue;color:white"> 系統訊息 </td>
                   </tr>
                   <tr style="background-color:lightgray">
                      
                       <td style="font-size:16px; margin:auto">
                          <br />
                           提醒:您所指定預約之會議時間,出現在過去時間。
                          <br /><br />
                       </td>                      
                   </tr>
                   <tr style="border-width:1px">
                       <td style="text-align:center;background-color:lightgray">
                              <asp:Button ID="Button4" runat="server" Font-Size="Medium" Text="確定" OnClick="Button4_Click"></asp:Button>
                       </td>
                   </tr>
               </table>
         </asp:Panel>


        <asp:Literal ID="Literal2" runat="server"></asp:Literal>             
       

    </form>
</body>
</html>


------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Data.SqlClient;
using System.Data;
using System.Net.Mail;
using System.Xml;
using System.Net;
using System.IO;
using System.Text;


public partial class index : System.Web.UI.Page 
{
    SqlDataReader reader ;
    SqlCommand command ;
    SqlConnection conn;   
    CommonUtil.UserProfile ObjUserProfile = new CommonUtil.UserProfile();


    protected void Page_Load(object sender, EventArgs e)
    {       
        SetSession();
             

        //CommonUtil.UserProfile objUserProfile;       
        if ((Session["UserProfile"] == null))
        {
            //objUserProfile = new CommonUtil.UserProfile();
            //if (CommonUtil.CommonClass.getUserProfileErr(Request.ServerVariables["LOGON_USER"].ToString(), ref objUserProfile) == true)
            //{
            //    Response.Redirect(Request.Url.ToString());
            //}

            //if (Request.UrlReferrer != null)
            //{
                //string urlRef = Request.UrlReferrer.AbsoluteUri;
                //if (urlRef.IndexOf("NewSchedule", StringComparison.CurrentCultureIgnoreCase) > 0 || urlRef.IndexOf("NewScheduleView", StringComparison.CurrentCultureIgnoreCase) > 0)
                //{
                //    Response.Write("無操作權限!");
                //    Response.End();
                //}
                //else
                //{
                    SetSsoNullSesson();
                //}
            //}
        }
        else
        {
            //if(Session["USRID"]  != null)
            //{
            //    if (Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdmin"]) ==  Convert.ToString(Session["USRID"] )   )
            //    {
            //          Session["UserProfile"] = null;
            //          Session["USRID"] = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdmin"])  ;                
            //    }
            //}
        }

        //if (HttpContext.Current.Request.LogonUserIdentity.Name.Split(new char[] { '\\' })[1] == "000000")
        if (HttpContext.Current.Request.LogonUserIdentity.Name.Split(new char[] { '\\' })[1] == Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdmin"]))
        {
            Session["UserProfile"] = ObjUserProfile;
            Session["USRID"] = HttpContext.Current.Request.LogonUserIdentity.Name.Split(new char[] { '\\' })[1];
        }
       
        if(!Page.IsPostBack)
        { 
            if (Session["DisabledSet"] != null)
            {
                if (Session["DisabledSet"].ToString() == "true")
                {
                    //Panel1.Visible = true;
                    //mainContent.Disabled = true;
                    //Session["DisabledSet"] = null;

                    this.Literal2.Text = "<div  title='System Message' id='dialog-message'><p>";
                    this.Literal2.Text += "<span class='ui-icon ui-icon-circle-check' style='float: left; margin: 0 7px 50px 0;'></span>";
                    this.Literal2.Text += "提醒:您所指定預約之會議時間,出現在過去時間。 </p> <p>";
                    this.Literal2.Text += "  </p> </div>";
                    this.Literal2.Text += "";
                    Session["DisabledSet"] = null;

                    Page.ClientScript.RegisterStartupScript(this.GetType(), "openModel", GetJsModel(), true);
                }
            }
            else
            {
                WaitProcess();
            }
                       
           
            //第一次載入顯示當天資料
            if (Session["target"] == null)
            {
                this.TextBox1.Text = DateTime.Now.ToString("yyyy/MM/dd");
                Button1.Attributes.Remove("class");
                Button2.Attributes.Remove("class");
                Button3.Attributes.Remove("class");
                Button1.Attributes.Add("class", "class2"); 
                Button2.Attributes.Add("class", "class2");
                Button3.Attributes.Add("class", "class2");
            }
           

            if (Session["target"] != null)
            {
                this.TextBox1.Text = Convert.ToString(Session["target"]);
            }
            if (Session["targetType"] != null)
            {
                string Daytype = Convert.ToString(Session["targetType"]);
                if (Daytype == "DAY")
                {
                    RadioButton1.Checked = true;
                    RadioButton2.Checked = false;
                    RadioButton1_CheckedChanged(this,null);
                }
                else
                {
                    RadioButton1.Checked = false;
                    RadioButton2.Checked = true;
                    RadioButton2_CheckedChanged(this, null);
                }
            }

            Session["target"] = this.TextBox1.Text;
            if (RadioButton1.Checked)
            {
                Session["targetType"] = "DAY";
            }
            else
            {
                Session["targetType"] = "WEEK";
            }

            if (Session["target"] == null)
            {
                this.Label1.Text = this.TextBox1.Text + "<br/>" + ConvertWeek(ConvertDateTime(this.TextBox1.Text).DayOfWeek);
            }           

            SetDisableBtn();

            if (Session["target"] == null)
            {
                this.Literal1.Text = GenDataByDay(this.TextBox1.Text.Trim());
            }
            else
            {
                TextBox1_TextChanged(this, null);
            }


        }
    }


    private string GetJsModel()
    {
        string jsContent = "$(function () { ";
        jsContent += "$('#dialog-message').dialog({ ";
        jsContent += " modal: true, buttons: { ";
        jsContent += "  確定: function () { $(this).dialog('close');  ";
        jsContent += " } } }); });";
        jsContent += "";
       
        return jsContent;
    }

    private void WaitProcess()
    {
        if (Session["targetType"] != null)
        {
            string Daytype = Convert.ToString(Session["targetType"]);
            if (Daytype == "DAY")
            {
                //js += " exeBlockui(3000);  ";
                //Page.ClientScript.RegisterStartupScript(this.GetType(), "daywait", js, true);
            }
            else
            {
               //js += " exeBlockui(8000);  ";
               //Page.ClientScript.RegisterStartupScript(this.GetType(), "daywait", js, true);
            }
        }
        else
        {
           // js += " exeBlockui(3000);  ";
           // Page.ClientScript.RegisterStartupScript(this.GetType(), "daywait", js, true);
        }
    }


    private void SetSession()
    {
        if (Request.UrlReferrer != null)
        {
                string urlRef = Request.UrlReferrer.AbsoluteUri;
                if (urlRef.IndexOf("NewSchedule", StringComparison.CurrentCultureIgnoreCase) <= 0 && urlRef.IndexOf("NewScheduleView", StringComparison.CurrentCultureIgnoreCase) <= 0 && urlRef.IndexOf("Index", StringComparison.CurrentCultureIgnoreCase) <= 0)
                {
                    Session.Remove("targetType");
                    Session.Remove("target");
                    Session.Remove("DisabledSet");           
                }
        }
    }

    private string GenDataByDay(string date)
    {
        string data = "";

        string strConn2 = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["DBConn"]);
        SqlConnection myConn2 = new SqlConnection(strConn2);
        myConn2.Open();
        DataSet ds2 = new DataSet();
        string sqlcmd2 = "   ";
        sqlcmd2 += "   SELECT ROOM_ID , ROOM_NAME FROM MRR_MEETINGROOM_WebEx ORDER BY ROOM_ID    ";       
        SqlDataAdapter sda2 = new SqlDataAdapter(sqlcmd2, myConn2);
        sda2.Fill(ds2);
        myConn2.Close();
        foreach(DataRow dr in ds2.Tables[0].Rows)
        {
            data += GenDataByDayAndMeetRoom(date, dr["ROOM_ID"].ToString());
        }
        Session["ROOM"] = ds2;          
        return data;
    }


   
    private string GenDataByDayAndMeetRoom(string date,string room)
    {         
        StringBuilder data = new StringBuilder();
        conn = new SqlConnection(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["DBConn"])) ;
        data.Append("<tr>");
        data.Append("<td class='testsmallCon'  > " + room + " </td>");
        conn.Open();

        for (int i = 1; i <= 18;i++ )
        {
                       
            string checkMeeting = "SELECT SCHEDULE_ID ,EMPLOYEE_NAME, AGENDA , CHAIRMAN ,EMPLOYEE_ID  ";
            checkMeeting += " FROM MRR_MEETINGROOM_WebEx_SCHEDULE  ";
            checkMeeting += " WHERE ROOM_ID = '"+room+"' ";
            checkMeeting += " AND CONVERT(VARCHAR,MEETING_DATE,111) = '"+date+"' ";
            checkMeeting += " AND cast(START_TIME as int) <= " + i;
            checkMeeting += " AND cast(END_TIME as int) > " + i;
           

            command = new SqlCommand(checkMeeting, conn);
            reader = command.ExecuteReader();

            //DataSet ds = new DataSet();
            //ds = GetMeetDataSet(checkMeeting) ;
            //if (ds.Tables[0].Rows.Count > 0)
            //{
            //    string scheduleId =  ds.Tables[0].Rows[0]["SCHEDULE_ID"].ToString();
            //    string empName = ds.Tables[0].Rows[0]["EMPLOYEE_NAME"].ToString();
            //    string agenda = ds.Tables[0].Rows[0]["AGENDA"].ToString();
            //    string chairman = ds.Tables[0].Rows[0]["CHAIRMAN"].ToString();
            //    string empid = ds.Tables[0].Rows[0]["EMPLOYEE_ID"].ToString();               
            //    data.Append(CancelMeetingCell(HttpUtility.UrlEncode(Encrypt(scheduleId)), GetToolTip(empid,empName, agenda, chairman)));
            //}
            if(reader.HasRows)
            {
                while (reader.Read())
                {
                    string scheduleId = Convert.ToString(reader["SCHEDULE_ID"]) ;
                    string empName = Convert.ToString(reader["EMPLOYEE_NAME"]) ;
                    string agenda = Convert.ToString(reader["AGENDA"]) ;
                    string chairman = Convert.ToString(reader["CHAIRMAN"]);
                    string empid = Convert.ToString(reader["EMPLOYEE_ID"]) ;
                    data.Append(CancelMeetingCell(HttpUtility.UrlEncode(Encrypt(scheduleId)), GetToolTip(empid, empName, agenda, chairman)));
                }
            }
            else
            {
                data.Append(SetMeetingCell(HttpUtility.UrlEncode(Encrypt(date.Replace("/", "") + "_" + room + "_" + i.ToString()))));
            }
            reader.Close();
           
        }

        data.Append("</tr> ");       
        conn.Close();
        return data.ToString();
    }

   


    private string GenWeekDayTitle(DateTime date)
    {
        string week = ConvertWeek(date.DayOfWeek);
        string weekTitle = "";
        weekTitle += "<tr>";
        weekTitle += " <td align='center'  class='weekTitle' colspan='19' style='background-color:yellow'> " + date.ToString("yyyy/MM/dd") + "("+week+ ")" + " </td> ";
        weekTitle += "</tr>";
        return weekTitle;
    }


    private string ConvertWeek(DayOfWeek dow)
    {
        string result = "";
        if (dow == DayOfWeek.Monday)
        {
            result = "星期一";
        }
        else if (dow == DayOfWeek.Tuesday)
        {
            result = "星期二";
        }
        else if (dow == DayOfWeek.Wednesday)
        {
            result = "星期三";
        }
        else if (dow == DayOfWeek.Thursday)
        {
            result = "星期四";
        }
        else if (dow == DayOfWeek.Friday)
        {
            result = "星期五";
        }
        else if (dow == DayOfWeek.Saturday)
        {
            result = "星期六";
        }
        else if (dow == DayOfWeek.Sunday)
        {
            result = "星期日";
        }
        return result;
    }


    private string GetMeetData(string selectCmd)
    {
        DataSet ds = new DataSet();
        ds = GetMeetDataSet(selectCmd);
        return ds.Tables[0].Rows[0][0].ToString().Trim();

    }


    private DataSet GetMeetDataSet(string selectCmd)
    {
        DataSet ds = new DataSet();
        try
        {
            string strConn = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["DBConn"]);
            SqlConnection myConn = new SqlConnection(strConn);
            myConn.Open();           
            string sqlcmd = selectCmd;
            SqlDataAdapter sda = new SqlDataAdapter(sqlcmd, myConn);
            sda.Fill(ds);
            myConn.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return ds;
    }


    //privious   所有的都以TextBox1.Text為基準日
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (RadioButton1.Checked == true)  //day 前一天  今天-1
        {
            DateTime dt = ConvertDateTime(TextBox1.Text.Trim());
            TextBox1.Text = dt.AddDays(-1).ToString("yyyy/MM/dd");
            this.Label1.Text = this.TextBox1.Text + "<br/>" + ConvertWeek(ConvertDateTime(this.TextBox1.Text).DayOfWeek);
            this.Literal1.Text = GenDataByDay(TextBox1.Text);
            Session["target"] = this.TextBox1.Text;
            Session["targetType"] = "DAY";
           
        }
        else   //week  前一週  當周第一天-7 = 前一週的第一天
        {
            DateTime dt = ConvertDateTime(TextBox1.Text.Trim());
            TextBox1.Text = dt.AddDays(-7).ToString("yyyy/MM/dd");
            this.Label1.Text = ShowNonYearDate(this.TextBox1.Text + "-" + ConvertDateTime(this.TextBox1.Text).AddDays(7).ToString("yyyy/MM"));
            Session["target"] = this.TextBox1.Text;
            Session["targetType"] = "WEEK";

            DateTime dt2 = ConvertDateTime(TextBox1.Text.Trim());
            string d1 = dt2.ToString("yyyy/MM/dd");
            string d2 = dt2.AddDays(1).ToString("yyyy/MM/dd");
            string d3 = dt2.AddDays(2).ToString("yyyy/MM/dd");
            string d4 = dt2.AddDays(3).ToString("yyyy/MM/dd");
            string d5 = dt2.AddDays(4).ToString("yyyy/MM/dd");
            string d6 = dt2.AddDays(5).ToString("yyyy/MM/dd");
            string d7 = dt2.AddDays(6).ToString("yyyy/MM/dd");

            StringBuilder content = new StringBuilder();
            content.Append(GenWeekDayTitle(dt2));
            content.Append(GenDataByDay(d1));
            content.Append(GenWeekDayTitle(dt2.AddDays(1)));
            content.Append(GenDataByDay(d2));
            content.Append(GenWeekDayTitle(dt2.AddDays(2)));
            content.Append(GenDataByDay(d3));
            content.Append(GenWeekDayTitle(dt2.AddDays(3)));
            content.Append(GenDataByDay(d4));
            content.Append(GenWeekDayTitle(dt2.AddDays(4)));
            content.Append(GenDataByDay(d5));
            content.Append(GenWeekDayTitle(dt2.AddDays(5)));
            content.Append(GenDataByDay(d6));
            content.Append(GenWeekDayTitle(dt2.AddDays(6)));
            content.Append(GenDataByDay(d7));
            this.Literal1.Text = content.ToString();

        }
        SetDisableBtn();
    }
   

    //today
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (RadioButton1.Checked == true)  //day  今天
        {
            TextBox1.Text = DateTime.Now.ToString("yyyy/MM/dd");
            this.Label1.Text = this.TextBox1.Text + "<br/>" + ConvertWeek(ConvertDateTime(this.TextBox1.Text).DayOfWeek);
            this.Literal1.Text = GenDataByDay(TextBox1.Text.Trim());
            Session["target"] = this.TextBox1.Text;
            Session["targetType"] = "DAY";
           
        }
        else   //week  今天開始的連續七天
        {
            DateTime dt = DateTime.Now;   //ConvertDateTime(TextBox1.Text.Trim());
            TextBox1.Text = dt.ToString("yyyy/MM/dd");
            this.Label1.Text = ShowNonYearDate(this.TextBox1.Text + "-" + ConvertDateTime(this.TextBox1.Text).AddDays(7).ToString("MM/dd"));
            Session["target"] = this.TextBox1.Text;
            Session["targetType"] = "WEEK";

            string d1 = dt.ToString("yyyy/MM/dd");
            string d2 = dt.AddDays(1).ToString("yyyy/MM/dd");
            string d3 = dt.AddDays(2).ToString("yyyy/MM/dd");
            string d4 = dt.AddDays(3).ToString("yyyy/MM/dd");
            string d5 = dt.AddDays(4).ToString("yyyy/MM/dd");
            string d6 = dt.AddDays(5).ToString("yyyy/MM/dd");
            string d7 = dt.AddDays(6).ToString("yyyy/MM/dd");

            StringBuilder content = new StringBuilder();
            content.Append(GenWeekDayTitle(dt));
            content.Append(GenDataByDay(d1));
            content.Append(GenWeekDayTitle(dt.AddDays(1)));
            content.Append(GenDataByDay(d2));
            content.Append(GenWeekDayTitle(dt.AddDays(2)));
            content.Append(GenDataByDay(d3));
            content.Append(GenWeekDayTitle(dt.AddDays(3)));
            content.Append(GenDataByDay(d4));
            content.Append(GenWeekDayTitle(dt.AddDays(4)));
            content.Append(GenDataByDay(d5));
            content.Append(GenWeekDayTitle(dt.AddDays(5)));
            content.Append(GenDataByDay(d6));
            content.Append(GenWeekDayTitle(dt.AddDays(6)));
            content.Append(GenDataByDay(d7));
            this.Literal1.Text = content.ToString();
        }
        SetDisableBtn();
    }


    //next
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (RadioButton1.Checked == true)  //day  後一天   今日+1
        {
            DateTime dt = ConvertDateTime(TextBox1.Text.Trim());
            TextBox1.Text = dt.AddDays(1).ToString("yyyy/MM/dd");
            this.Label1.Text = this.TextBox1.Text + "<br/>" + ConvertWeek(ConvertDateTime(this.TextBox1.Text).DayOfWeek);
            this.Literal1.Text = GenDataByDay(TextBox1.Text);
            Session["target"] = this.TextBox1.Text;
            Session["targetType"] = "DAY";
           
        }
        else   //week  後一週  當週最後一日 + 1 = 後一週開始日,然後連續七天
        {
            DateTime dt = ConvertDateTime(TextBox1.Text.Trim());
            TextBox1.Text = dt.AddDays(7).ToString("yyyy/MM/dd");
            this.Label1.Text = ShowNonYearDate(this.TextBox1.Text + "-" + ConvertDateTime(this.TextBox1.Text).AddDays(7).ToString("MM/dd"));
            Session["target"] = this.TextBox1.Text;
            Session["targetType"] = "WEEK";

            DateTime dt2 = ConvertDateTime(TextBox1.Text.Trim());
            string d1 = dt2.ToString("yyyy/MM/dd");
            string d2 = dt2.AddDays(1).ToString("yyyy/MM/dd");
            string d3 = dt2.AddDays(2).ToString("yyyy/MM/dd");
            string d4 = dt2.AddDays(3).ToString("yyyy/MM/dd");
            string d5 = dt2.AddDays(4).ToString("yyyy/MM/dd");
            string d6 = dt2.AddDays(5).ToString("yyyy/MM/dd");
            string d7 = dt2.AddDays(6).ToString("yyyy/MM/dd");

            StringBuilder content = new StringBuilder();
            content.Append(GenWeekDayTitle(dt2));
            content.Append(GenDataByDay(d1));
            content.Append(GenWeekDayTitle(dt2.AddDays(1)));
            content.Append(GenDataByDay(d2));
            content.Append(GenWeekDayTitle(dt2.AddDays(2)));
            content.Append(GenDataByDay(d3));
            content.Append(GenWeekDayTitle(dt2.AddDays(3)));
            content.Append(GenDataByDay(d4));
            content.Append(GenWeekDayTitle(dt2.AddDays(4)));
            content.Append(GenDataByDay(d5));
            content.Append(GenWeekDayTitle(dt2.AddDays(5)));
            content.Append(GenDataByDay(d6));
            content.Append(GenWeekDayTitle(dt2.AddDays(6)));
            content.Append(GenDataByDay(d7));
            this.Literal1.Text = content.ToString();
        }
        SetDisableBtn();
    }


    //change textbox selected date
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        if (RadioButton1.Checked == true)  //day
        {
           
            DateTime dt = ConvertDateTime(TextBox1.Text.Trim());
            TextBox1.Text = dt.AddDays(0).ToString("yyyy/MM/dd");
            this.Label1.Text = this.TextBox1.Text + "<br/>" + ConvertWeek(ConvertDateTime(this.TextBox1.Text).DayOfWeek);
           
            this.Literal1.Text = GenDataByDay(TextBox1.Text);
            Session["target"] = this.TextBox1.Text;
            Session["targetType"] = "DAY";
        }
        else   //week 當日為起始的週
        {
            DateTime dt = ConvertDateTime(TextBox1.Text.Trim());
            TextBox1.Text = dt.AddDays(0).ToString("yyyy/MM/dd");
            this.Label1.Text = ShowNonYearDate(this.TextBox1.Text + "-" + ConvertDateTime(this.TextBox1.Text).AddDays(7).ToString("MM/dd"));                    

            Session["target"] = this.TextBox1.Text;
            Session["targetType"] = "WEEK";

            DateTime dt2 = ConvertDateTime(TextBox1.Text.Trim());
            string d1 = dt2.ToString("yyyy/MM/dd");
            string d2 = dt2.AddDays(1).ToString("yyyy/MM/dd");
            string d3 = dt2.AddDays(2).ToString("yyyy/MM/dd");
            string d4 = dt2.AddDays(3).ToString("yyyy/MM/dd");
            string d5 = dt2.AddDays(4).ToString("yyyy/MM/dd");
            string d6 = dt2.AddDays(5).ToString("yyyy/MM/dd");
            string d7 = dt2.AddDays(6).ToString("yyyy/MM/dd");

            StringBuilder content = new StringBuilder();
            content.Append(GenWeekDayTitle(dt2));
            content.Append(GenDataByDay(d1));
            content.Append(GenWeekDayTitle(dt2.AddDays(1)));
            content.Append(GenDataByDay(d2));
            content.Append(GenWeekDayTitle(dt2.AddDays(2)));
            content.Append(GenDataByDay(d3));
            content.Append(GenWeekDayTitle(dt2.AddDays(3)));
            content.Append(GenDataByDay(d4));
            content.Append(GenWeekDayTitle(dt2.AddDays(4)));
            content.Append(GenDataByDay(d5));
            content.Append(GenWeekDayTitle(dt2.AddDays(5)));
            content.Append(GenDataByDay(d6));
            content.Append(GenWeekDayTitle(dt2.AddDays(6)));
            content.Append(GenDataByDay(d7));
            this.Literal1.Text = content.ToString();

            //if (Page.IsPostBack)
            //{
            //    string execweek = " $(document).ready(function () {  exeBlockui(8000);  });  ";
            //    Page.ClientScript.RegisterStartupScript(this.GetType(), "execweek", execweek, true);
            //}
        }
        SetDisableBtn();
    }


    private string ShowNonYearDate(string date)
    {
        return date.Replace(DateTime.Now.Year + "/","");
    }


    private void SetDisableBtn()
    {
        if (ConvertDateTime(TextBox1.Text.Trim()) <= DateTime.Now)
        {
            Button1.Enabled = false;
        }
        else
        {
            Button1.Enabled = true;
        }
    }

    private DateTime ConvertDateTime(string datestring)
    {
        return new DateTime(Convert.ToInt32(datestring.Split(new char []{ '/' })[0]), Convert.ToInt32(datestring.Split(new char []{ '/' })[1]), Convert.ToInt32(datestring.Split(new char []{ '/' })[2]));
    }


    protected void RadioButton1_CheckedChanged(object sender, EventArgs e) 
    {
        Button1.Attributes.Remove("class");
        Button2.Attributes.Remove("class");
        Button3.Attributes.Remove("class");
        Button1.Attributes.Add("class", "class2");
        Button2.Attributes.Add("class", "class2");
        Button3.Attributes.Add("class", "class2");

        RadioButton1.Checked = true;
        RadioButton2.Checked = false;
        Button1.Text = "前一天";
        Button2.Text = "今天";
        Button3.Text = "後一天";

        if(e != null)
        {
           Button2_Click(this,null);
        }


        this.Label1.Text = this.TextBox1.Text + "<br/>" + ConvertWeek(ConvertDateTime(this.TextBox1.Text).DayOfWeek);
        SetDisableBtn();

        if (RadioButton1.Checked)
        {
            Session["targetType"] = "DAY";
        }
        else
        {
            Session["targetType"] = "WEEK";
        }
    }
   

    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        Button1.Attributes.Remove("class");
        Button2.Attributes.Remove("class");
        Button3.Attributes.Remove("class");
        Button1.Attributes.Add("class", "class1");
        Button2.Attributes.Add("class", "class1");
        Button3.Attributes.Add("class","class1");
       
        RadioButton1.Checked = false;
        RadioButton2.Checked = true;
        Button1.Text = "前一週";
        Button2.Text = "當週";
        Button3.Text = "下一週";

        if (e != null)
        {
            Button2_Click(this, null);
        }

        this.Label1.Text = ShowNonYearDate(this.TextBox1.Text + "-" + ConvertDateTime(this.TextBox1.Text).AddDays(7).ToString("MM/dd"));
        SetDisableBtn();

        if (RadioButton2.Checked)
        {
            Session["targetType"] = "WEEK";           
        }
        else
        {
            Session["targetType"] = "DAY";
        }
    }


    protected void Button4_Click(object sender, EventArgs e)
    {
        Panel1.Visible = false;
        mainContent.Disabled = false;
    }


    private string GetToolTip(string empid, string empName, string agenda, string chairman)
    {
        return "使用者: " + empid + "(" + empName + ")" + " <br/>會議名稱: " + agenda + "  <br/>主席: " + chairman;
    }

    private string CancelMeetingCell(string scheduleId, string tooltip)   //class='testtopsmallCon tooltip'
    {
           return "<td  title='" + tooltip.Replace("<br/>", "&#13;") + "' class='testtopsmallCon' style='background-color:red' id='" + scheduleId + "' onclick=location.href='NewScheduleView.aspx?" + GenCancelMeetingKey() + "='+this.id>     </td>";
           //return "<td  style='background-color:red'  id='" + scheduleId + "' onclick=location.href='NewScheduleView.aspx?" + GenCancelMeetingKey() + "='+this.id>   <a class='tooltip' href='#' style='color:red'> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <span style='text-align:left'> <b></b> " + tooltip + "  </span>  </a>  </td>";
    }

    private string SetMeetingCell(string id)
    {
        return "<td class='testtopsmallCon'  id='" + id + "' onclick=location.href='NewSchedule.aspx?"+ GenSetMeetingKey() +"='+this.id>    </td>";
    }


    private string Encrypt(string clearText)
    {
        string EncryptionKey = DateTime.Now.ToString("yyyyMMdd") + "WEBEXMT";

        byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);

        using (Aes encryptor = Aes.Create())
        {
            Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });

            encryptor.Key = pdb.GetBytes(32);
            encryptor.IV = pdb.GetBytes(16);

            using (MemoryStream ms = new MemoryStream())
            {

                using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(clearBytes, 0, clearBytes.Length);

                    cs.Close();
                }

                clearText = Convert.ToBase64String(ms.ToArray());
            }
        }
        return clearText;
    }


    private string GenCancelMeetingKey()
    {
        char[] charArray = DateTime.Now.AddYears(Convert.ToInt32(DateTime.Now.DayOfWeek)).AddMonths(-Convert.ToInt32(DateTime.Now.DayOfWeek)).AddDays(Convert.ToInt32(DateTime.Now.DayOfWeek))
            .ToString("yyyyMMdd").ToCharArray();
        Array.Reverse(charArray);
        return (Convert.ToInt32(new string(charArray)) * Convert.ToInt32(DateTime.Now.DayOfWeek)).ToString() ;
    }


    private string GenSetMeetingKey()
    {
        char[] charArray = DateTime.Now.AddYears(-Convert.ToInt32(DateTime.Now.DayOfWeek)).AddMonths(Convert.ToInt32(DateTime.Now.DayOfWeek)).AddDays(-Convert.ToInt32(DateTime.Now.DayOfWeek))
            .ToString("yyyyMMdd").ToCharArray();
        Array.Reverse(charArray);
        return (Convert.ToInt32(new string(charArray)) * Convert.ToInt32(DateTime.Now.DayOfWeek)).ToString();
    }


    private void  SetSsoNullSesson()
    {
      //Response.Write(HttpContext.Current.Request.LogonUserIdentity.Name);     

      //if (Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdmin"]) == HttpContext.Current.Request.LogonUserIdentity.Name.Split(new char[] { '\\' })[1])
      // {
      //     Session["UserProfile"] = null ;
      //     Session["USRID"] = HttpContext.Current.Request.LogonUserIdentity.Name.Split(new char[] { '\\' })[1] ;
      //     return;
      // }

        //if (ObjUserProfile.QueryUserProfile("09130") == false)

      //if (HttpContext.Current.Request.LogonUserIdentity.Name.Split(new char[] { '\\' })[1] == "000000")
      if (HttpContext.Current.Request.LogonUserIdentity.Name.Split(new char[] { '\\' })[1] == Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdmin"]))
      {
          Session["UserProfile"] = ObjUserProfile;
          Session["USRID"] = HttpContext.Current.Request.LogonUserIdentity.Name.Split(new char[] { '\\' })[1];
      }
      else
      {

          if (ObjUserProfile.QueryUserProfile(HttpContext.Current.Request.LogonUserIdentity.Name.Split(new char[] { '\\' })[1]) == false)
          {
              Response.Redirect(Request.Url.ToString());
          }
          else
          {
              Session["UserProfile"] = ObjUserProfile;
              Session["USRID"] = HttpContext.Current.Request.LogonUserIdentity.Name.Split(new char[] { '\\' })[1];
          }
      }
   

    }


}

================================================
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewSchedule.aspx.cs" Inherits="NewSchedule" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link rel="stylesheet" type="text/css" href="Content/mrr.css" />
   
    <link rel="stylesheet" type="text/css" href="Content/jquery-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="Content/jquery-ui.structure.min.css" />
    <link rel="stylesheet" type="text/css" href="Content/jquery-ui.theme.css" />
    <%--<link rel="stylesheet" type="text/css" href="Content/Site.css" />--%>
    <%--<link rel="stylesheet" type="text/css" href="Content/jquery.alerts.css" />--%>
    <%--<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" />--%>
    <%--<link href="https://cdn.rawgit.com/google/code-prettify/master/loader/prettify.css" rel="stylesheet" type="text/css" />--%>

    <script type="text/javascript" src="Scripts/jquery-1.10.2.min.js"></script>
    <%--<script type="text/javascript" src="Scripts/jquery-1.10.2.min.map"></script>--%>
    <script type="text/javascript" src="Scripts/jquery-ui.min.js"></script>
    <%--<script type="text/javascript" src="Scripts/jquery.alerts.js"></script>--%>
    <%--<script type="text/javascript" src="Scripts/jquery.confirm.min.js"></script>--%>
    <%--<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>--%>
    <%--<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>--%>
    <script type="text/javascript" src="Scripts/jquery.blockUI.js"></script>


    <script type="text/javascript" >
        $(document).ready(function () {
            setup();
           
        });

    </script>

    <script type="text/javascript" >
        function setup() {

            $("#TextBox5").datepicker({
                dateFormat: "yy/mm/dd",
                dafaultDate: new Date(),
                minDate: new Date()
            });
        }
   </script>

    <script>
         $(function () {
             $('#dialog-message').dialog({
                 autoOpen: false,
                 modal: true,
                 buttons: {
                     確定: function () {
                         $(this).dialog('close');
                         exeBlockui(8000);
                         location.href = 'Index.aspx';
                  }
               }
             });
         });       

    </script>

    <script>
    $(function() {
        $("#title1").tooltip({
            open: function (event, ui) {
                ui.tooltip.css("max-width", "430px").css("background-Color", "#f6f5cc").css("position","relative").css("left","270px").css("top","-100px");
            }
        });
     });
    </script>


    <%--<script>
        $(document).ready(function () {
            $("#simpleConfirm").confirm(
                ({
                    text: "Are you sure you want to delete that comment?",
                    title: "Confirmation required",
                    confirm: function(button) {
                       
                    },
                    //cancel: function(button) {
                    //    // nothing to do
                    //},
                    confirmButton: "Yes I am",
                    //cancelButton: "No",
                    cancelButton: false,
                    post: true,
                    confirmButtonClass: "btn-danger",
                    cancelButtonClass: "btn-default"
                    //dialogClass: "modal-dialog modal-lg" // Bootstrap classes for large modal
                }
                )
                );
        });
       
    </script>--%>


    <script>
        window.onerror = function (msg, url, linenumber) {
            return true;
        }
   </script>

    <style type="text/css">
        .auto-style1 {
            width: 216px;
        }
    </style>

    <style>
         .ui-widget-header,.ui-state-default, ui-button{
            background:#3366cc;
            border: 1px solid #b9cd6d;
            color: #FFFFFF;
            font-weight: bold;
         }
   </style>


   <script>
       $(document).ready(function () {
        $('.class4').click(function () {
            $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
            setTimeout($.unblockUI, 3000);
        });
       });
       $(document).ready(function () {
        $(".class3").click(function () {
            $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
            setTimeout($.unblockUI, 8000);
        });
       });
   </script>

    <script>
        function exeBlockui(t) {
            $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
            setTimeout($.unblockUI, t);
        }
</script>

</head>

<body>
    <form id="form1" runat="server">
       
       
        <table bordr="0" >

            <tr >
                <td style="width:20%"> </td>
                <td>

                     <table width="800px" border="1">

                <tr>
                    <td class="auto-style1">
                        <img width='190px' height='50px' src="images/logo_190x50.jpg"/>
                    </td>
                    <td style="text-align:right">
                       
                            <span id="group" style="FONT-SIZE: 16px; BORDER-TOP: gray 1px solid; BORDER-RIGHT: gray 1px solid; BORDER-BOTTOM: gray 1px solid; PADDING-BOTTOM: 3px; PADDING-LEFT: 5px; BORDER-LEFT: gray 1px solid; PADDING-RIGHT: 5px; BACKGROUND-COLOR: #d9ecff">美商科技</span>
                            -會議室預約
                    </td>                   
                </tr>


                <tr>
                    <td class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;申請者編號 : </font>
                    </td>
                    <td class="mmr_rightCon">
                                            <asp:Label ID="Label1" runat="server"></asp:Label>
                     </td>
                </tr>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;會議室名稱 : </font>
                    </td>
                    <td class="mmr_rightCon">     
                       
                        <asp:DropDownList ID="DropDownList1" runat="server" Width="200px" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Enabled="False">
                            <%--<asp:ListItem>A</asp:ListItem>
                            <asp:ListItem>B</asp:ListItem>
                            <asp:ListItem>C</asp:ListItem>--%>
                        </asp:DropDownList>
                       
                    </td>
                </tr>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;設備 : </font>
                    </td>
                    <td id="equipment" class="mmr_rightCon">
                        <asp:Label ID="Label2" runat="server" ForeColor="Red"></asp:Label>
                    </td>
                </tr>
               <%-- <tr>
                    <td class="mmr_leftCon">
                        <font>注意事項 : </font>
                    </td>
                    <td id="ps" class="mmr_rightCon">
                        <asp:Label ID="Label3" runat="server"></asp:Label>
                    </td>
                </tr>--%>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;會議名稱 : </font><font size="2" color="#FF0000">*</font>
                    </td>
                    <td class="mmr_rightCon">
                        <asp:TextBox ID="TextBox1" runat="server" Width="300px" MaxLength="100"></asp:TextBox>
                        <asp:Label ID="Label3" runat="server" ForeColor="Red" Visible="False"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;主席 : </font><font size="2" color="#FF0000">*</font>
                    </td>
                    <td class="mmr_rightCon">
                        <asp:TextBox ID="TextBox2" runat="server" Width="300px" MaxLength="25"></asp:TextBox>
                        <asp:Label ID="Label4" runat="server" ForeColor="Red" Visible="False"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;與會人數 : </font><font size="2" color="#FF0000">*</font>
                    </td>
                    <td class="mmr_rightCon">
                        <asp:TextBox ID="TextBox3" runat="server" Width="300px"></asp:TextBox>
                        <asp:Label ID="Label5" runat="server" ForeColor="Red" Visible="False"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;聯絡人電話 : </font><font size="2" color="#FF0000">*</font>
                    </td>
                    <td class="mmr_rightCon">
                        <asp:TextBox ID="TextBox4" runat="server" Width="300px" MaxLength="50"></asp:TextBox>
                        <asp:Label ID="Label6" runat="server" ForeColor="Red" Visible="False"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;預約日期 : </font><font size="2" color="#FF0000">*</font>
                    </td>
                    <td class="mmr_rightCon">
                        <asp:TextBox ID="TextBox5" runat="server" Width="300px" MaxLength="10"></asp:TextBox>
                        <asp:Label ID="Label7" runat="server" ForeColor="Red" Visible="False"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;起迄時間 : </font><font size="2" color="#FF0000">*</font>
                    </td>
                    <td class="mmr_rightCon">
                        <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
                             <asp:ListItem Value="1">09:00</asp:ListItem>
                             <asp:ListItem Value="2">09:30</asp:ListItem>
                             <asp:ListItem Value="3">10:00</asp:ListItem>
                             <asp:ListItem Value="4">10:30</asp:ListItem>
                             <asp:ListItem Value="5">11:00</asp:ListItem>
                             <asp:ListItem Value="6">11:30</asp:ListItem>
                             <asp:ListItem Value="7">12:00</asp:ListItem>
                             <asp:ListItem Value="8">12:30</asp:ListItem>
                             <asp:ListItem Value="9">13:00</asp:ListItem>
                             <asp:ListItem Value="10">13:30</asp:ListItem>
                             <asp:ListItem Value="11">14:00</asp:ListItem>
                             <asp:ListItem Value="12">14:30</asp:ListItem>
                             <asp:ListItem Value="13">15:00</asp:ListItem>
                             <asp:ListItem Value="14">15:30</asp:ListItem>
                             <asp:ListItem Value="15">16:00</asp:ListItem>
                             <asp:ListItem Value="16">16:30</asp:ListItem>
                             <asp:ListItem Value="17">17:00</asp:ListItem>
                             <asp:ListItem Value="18">17:30</asp:ListItem>
                           
                        </asp:DropDownList>
                        &nbsp; - &nbsp;
       <asp:DropDownList ID="DropDownList3" runat="server"></asp:DropDownList>
                    </td>
                </tr>

                         <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;實體會議室名稱 : </font><font size="2" color="#FF0000">*</font>
                    </td>
                    <td class="mmr_rightCon">
                        <asp:TextBox ID="TextBox7" runat="server" Width="300px" MaxLength="25"></asp:TextBox>
                        <asp:Label ID="Label9" runat="server" ForeColor="Red" Visible="False"></asp:Label>
                    </td>
                </tr>

                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin" id="title1" title="example1@com.tw;example2@com.tw">
                       <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;Mail CC :  (請用”;”分隔)</font>  <%--<font size="2" color="#FF0000">*</font>--%>
                       
                    </td>
                    <td >
                       
                          <%--<asp:TextBox ID="TextBox6" runat="server"  Width="500px" ></asp:TextBox>--%>
                          <textarea id="TextBox6" runat="server" rows="4" cols="70" maxlength="500"></textarea>
                          <br />
                        <asp:Label ID="Label8" runat="server" ForeColor="Red" Visible="False"></asp:Label>
                    </td>
                </tr>
                <%--<tr>
                    <td class="mmr_leftCon">
                        <font>是否預約未來每周同一<br>時段的會議室? </font>
                    </td>
                    <td class="mmr_rightCon">
                        <input id="fixedMonthRowSwitch" type="checkbox" />
                    </td>
                </tr>--%>


                <tr> <td colspan="2"  style="border-bottom-width:0px"> &nbsp; </td> </tr>
                <tr>
                    <td style="text-align:center; border-top-width:0px" colspan="2" >
                         <asp:Button ID="Button1" runat="server" Text="回首頁" OnClick="Button1_Click"></asp:Button>
                         &nbsp;&nbsp;   <asp:Button ID="Button2" runat="server" Text="確定預約" OnClick="Button2_Click"></asp:Button>
                         &nbsp;&nbsp;   <asp:Button ID="Button3" runat="server" Text="清除資料" OnClick="Button3_Click"></asp:Button>
                    </td>
                </tr>

            </table>

                </td>
                 <td style="width:20%"> </td>
            </tr>

        </table>
    

        <asp:Literal ID="Literal2" runat="server"></asp:Literal>

        <div  title='System Message' id='dialog-message'><p>
                <span class='ui-icon ui-icon-circle-check' style='float: left; margin: 0 7px 50px 0;'></span>
                         會議室預約成功,請記得自行預約台北會議室(實體會議室) </p> <p>
        </p> </div>
                       


    </form>
</body>

</html>


------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Net;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.OracleClient;
using System.Net.Mail;
using System.Security.Cryptography;
using System.ServiceModel;


public partial class NewSchedule : System.Web.UI.Page
{

    private CommonUtil.UserProfile objUserProfile;
    private OracleConnection connDB = new OracleConnection();
    private delegate void GetRoomLogin(string whichRoom);

    string result = "";
    string duringTime = "";
    string meetingStartDate = "";
    string meetingKey = "";
    string hostUrl = "";
    string attenUrl = "";
    string errMsg = "";

    string setDate = "";
    string setRoom = "";
    string setTime = "";
    string cc = "";
    string USERID = "";
    string USERNAME = "";
    string USERMAIL = "";
    string USEDEPT = "";
    string USREEPTNAME = "";
    string JoinMeetingPass = "";
    string MeetingID = "";
    string MeetingPass = "";
    string Daytype = "";
   

    protected void Page_Load(object sender, EventArgs e)
    {
              
        if (Session["UserProfile"] == null)           
        {
            //objUserProfile = new CommonUtil.UserProfile();
            //if (CommonUtil.CommonClass.getUserProfileErr(Request.ServerVariables["LOGON_USER"].ToString(), ref objUserProfile) == true)
            //{
            //    Response.Redirect(Request.Url.ToString());
            //}
            Response.Redirect("Index.aspx");
        }
        else
        {
            if (Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdmin"]) != Convert.ToString(Session["USRID"]))
            {
                objUserProfile = (CommonUtil.UserProfile)Session["UserProfile"];
                USERID = objUserProfile.GetUSR_ID;
                USERNAME = objUserProfile.GetUSR_NME;
                USERMAIL = objUserProfile.GetUSR_EMAIL;
                USEDEPT = objUserProfile.GetDEPT_ID;
                USREEPTNAME = objUserProfile.GetDEPT_NME;
            }
            else
            {
                objUserProfile =null ;
                USERID = Convert.ToString(Session["USRID"]);
                USERNAME = Convert.ToString(Session["USRID"]);
                USERMAIL =Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdminMail"] );        //2199
                USEDEPT = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdmin"]);
                USREEPTNAME = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdmin"]);
            }
        }
       
       
        if (!Page.IsPostBack)
        {
            if (Session["ROOM"] != null)
            {
                DataView dvRoom = ((DataSet)Session["ROOM"]).Tables[0].DefaultView ;
                //dvRoom.RowFilter = "ROOM_ID <> 'C'";
                DropDownList1.DataTextField = "ROOM_NAME";
                DropDownList1.DataValueField = "ROOM_ID";
                DropDownList1.DataSource = dvRoom;
                DropDownList1.DataBind();
            }
           
            string data = "";
            if (Request[AuthValidKey()] != null)
            {
                data = Decrypt(HttpUtility.UrlDecode(Request[AuthValidKey()].ToString().Trim()));
            }
            else
            {
                //data = "20170804_A_17";   
                Response.Redirect("Index.aspx");
            }
            int h = Convert.ToInt32(CheckEnableSet(data.Split(new char[] { '_' })[2].ToString().Trim()).Split(new char[] { ':' })[0]);
            int m = Convert.ToInt32(CheckEnableSet(data.Split(new char[] { '_' })[2].ToString().Trim()).Split(new char[] { ':' })[1]);
            if (DateTime.Now > new DateTime(Convert.ToInt32(data.Split(new char[] { '_' })[0].Substring(0, 4)), Convert.ToInt32(data.Split(new char[] { '_' })[0].Substring(4, 2)), Convert.ToInt32(data.Split(new char[] { '_' })[0].Substring(6, 2)), h, m, 0))
            {
                //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OVERTIME", "alert('指定之會議時間,不得為過去時間!');location='Index.aspx';", true);
                Session["DisabledSet"] = "true";
                Response.Redirect("Index.aspx");                
            }
           
            AddItems(0);
            ChangeRoomSetMemo();
            //if (Request["DATEROOMTIME"] != null)
            //{
            //string data = Request["DATEROOMTIME"].ToString().Trim();
            setDate = data.Split(new char[] { '_' })[0].Substring(0, 4) + "/" + data.Split(new char[] { '_' })[0].Substring(4, 2) + "/" + data.Split(new char[] { '_' })[0].Substring(6, 2);
            TextBox5.Text = setDate;
            setRoom = data.Split(new char[] { '_' })[1].ToString().Trim();
            DropDownList1.SelectedValue = setRoom;
            setTime = data.Split(new char[] { '_' })[2].ToString().Trim();
            SetStartEndTime(setTime);
            //}
            this.Label1.Text = USERID + "(" + USERNAME + ")";           
        }


        if (Session["targetType"] != null)
        {
            Daytype = Convert.ToString(Session["targetType"]);
            if (Daytype == "DAY")
            {
                //Button1.Attributes.Remove("class");
                //Button1.Attributes.Add("class", "class4");
                Button2.Attributes.Remove("class");
                Button2.Attributes.Add("class", "class4");
            }
            else
            {
                Button1.Attributes.Remove("class");
                Button1.Attributes.Add("class", "class3");
                //Button2.Attributes.Remove("class");          //改為dialog confirm執行
                //Button2.Attributes.Add("class", "class3");
            }
        }
               
        //DropDownList1.SelectedValue = "B";
        //string key = GetMeetingData(WebexXmlExeType.GetMeeting, "571153203");    //76312
        //string url = GetMeetingData(WebexXmlExeType.GetjoinurlMeeting, "571153203");
    }
   
   
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Index.aspx");       
    }


    private void UpdateAgendaConfName()
    {
        string strXMLServer = GetXmlServer();
       
        string strXML = "";
        strXML += "<?xml version='1.0' encoding='utf-8'?>";
        strXML += "<message xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
        strXML += "<header>";
        strXML += "<securityContext>";

        string meetroom = DropDownList1.SelectedValue.Trim();
        if (meetroom == "C")
        {
            strXML += "<siteName>MAIL</siteName>";
        }
        else
        {
            strXML += "<siteName>MAIL-1</siteName>";
        }

        //strXML += "<siteName>MAIL</siteName>";
        strXML += "<webExID>" + Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["Webexid"]) + "</webExID>";       //帳號
        strXML += "<password>" + Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["Webexpwd"]) + "</password>";      //密碼
        //strXML += "<email>DIKC@com.tw</email>";   //
        strXML += "</securityContext>";
        strXML += "</header>";

        strXML += "  <body> ";
        strXML += "  <bodyContent xsi:type='java:com.webex.service.binding.meeting.SetMeeting'>  ";
        strXML += " <metaData>  ";
        strXML += "  <agenda>" + TextBox1.Text.Trim() + "</agenda>  ";
        strXML += "  <confName>" + TextBox1.Text.Trim() + "</confName> ";
        strXML += "  </metaData> ";
        strXML += "  <meetingkey>" + meetingKey.Trim() + "</meetingkey> ";
        strXML += "  </bodyContent> ";
        strXML += " </body>   ";
        strXML += " </message>  ";            

        postXMLData(strXMLServer, GetRequestXml(strXML));
    }   


    //Create Meeting
    protected void Button2_Click(object sender, EventArgs e)
    {
        GetRoomLogin login = new GetRoomLogin(GetIdPass);
        string strConn2 = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["DBConn"]);
        SqlConnection myConn2 = new SqlConnection(strConn2);
        myConn2.Open();
        DataSet ds2 = new DataSet();
        string sqlcmd2 = "   ";
        sqlcmd2 += "   SELECT * FROM MRR_MEETINGROOM_WebEx_SCHEDULE WHERE ROOM_ID = '"+ DropDownList1.SelectedValue.Trim() +"'  ";
        sqlcmd2 += "    AND CONVERT(VARCHAR,MEETING_DATE,111) = '"+ TextBox5.Text.Trim() +"'  ";
        //sqlcmd2 += "   AND START_TIME >= '" + DropDownList2.SelectedValue.Trim() + "'  AND END_TIME <= '" + DropDownList3.SelectedValue.Trim() + "'  ";
        //sqlcmd2 += "   AND (( '" + DropDownList2.SelectedValue.Trim() + "' between START_TIME and  END_TIME) or ( " ;
        //sqlcmd2 += "   '" + DropDownList3.SelectedValue.Trim() + "' between START_TIME and  END_TIME )) " ;      
          
        sqlcmd2 += " AND ( " ; 
     sqlcmd2 += " " + DropDownList2.SelectedValue.Trim() + " >= START_TIME  AND " + DropDownList2.SelectedValue.Trim() + " < END_TIME " ; 
     sqlcmd2 += " OR " ; 
     sqlcmd2 += " " + DropDownList3.SelectedValue.Trim() + " > START_TIME  AND " + DropDownList3.SelectedValue.Trim() + " <= END_TIME " ; 
     sqlcmd2 += " OR " ; 
     sqlcmd2 += " " + DropDownList2.SelectedValue.Trim() + " <= START_TIME  AND " + DropDownList3.SelectedValue.Trim() + " >= END_TIME " ; 
     sqlcmd2 += " ) " ;    

        SqlDataAdapter sda2 = new SqlDataAdapter(sqlcmd2, myConn2);
        sda2.Fill(ds2);
        myConn2.Close();

        if(ds2.Tables[0].Rows.Count > 0)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "webex", "alert('重複預約,請選擇其他會議室及日期時間');", true);
            return;
        }
               
        //GetMeetingIDPass();
        login(DropDownList1.SelectedValue.Trim());
        if (InputCheck())
        {
            try
            {
                JoinMeetingPass = GetMeetingPass();
                string strXMLServer = GetXmlServer();
                //WebRequest request = WebRequest.Create(strXMLServer);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strXMLServer);

                //request.Method = "POST";
                // Set the ContentType property of the WebRequest.
                //request.ContentType = "application/x-www-form-urlencoded";              
                string strXML = "";
                strXML += "<?xml version='1.0' encoding='utf-8'?>";
                strXML += "<message xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
                strXML += "<header>";
                strXML += "<securityContext>";
                string meetroom = DropDownList1.SelectedValue.Trim();
                if (meetroom == "C")
                {
                    strXML += "<siteName>MAIL</siteName>";
                }
                else
                {
                    strXML += "<siteName>MAIL-1</siteName>";
                }
                //strXML += "<siteName>MAIL</siteName>";
                strXML += "<webExID>" + MeetingID + "</webExID>";       
                strXML += "<password>" + MeetingPass + "</password>";      
                //strXML += "<email>MAIL@Icom.tw</email>";   
                strXML += "</securityContext>";
                strXML += "</header>";
                strXML += "<body> ";
                strXML += "<bodyContent xsi:type='java:com.webex.service.binding.meeting.CreateMeeting'> ";
                strXML += "<accessControl> ";
                strXML += "<meetingPassword>" + JoinMeetingPass + "</meetingPassword> ";      //會議密碼 05072925
                strXML += "</accessControl> ";
                strXML += "<metaData> ";
                strXML += "<confName>" + TextBox1.Text.Trim().ReplaceXml() + "</confName> ";      //會議名稱
                strXML += "<agenda>" + TextBox1.Text.Trim().ReplaceXml() + "</agenda> ";         //會議議程
                strXML += "</metaData>";
                strXML += "<participants>";
                strXML += "<maxUserNumber>" + TextBox3.Text.Trim().ReplaceXml() + "</maxUserNumber>";      //與會人數
                strXML += "<attendees>";
                strXML += "<attendee>";
                //strXML += "<emailInvitations>true</emailInvitations>";     //電子郵件邀請
                strXML += "<person>";
                strXML += "<name>" + USERNAME + "</name>";      //邀請人名(登入的申請人名)?
                strXML += "<email>" + USERMAIL + "</email>";    //邀請電子郵件(登入的申請人電子郵件)?
                strXML += "</person>";
                strXML += "</attendee>";
                strXML += "</attendees>";
                strXML += "</participants>";
                strXML += "<enableOptions> ";
                strXML += "<chat>true</chat> ";     //聊天
                strXML += "<poll>true</poll> ";     //投票
                strXML += "<audioVideo>true</audioVideo> ";     //影音
                strXML += "</enableOptions> ";
                strXML += "<schedule> ";
                meetingStartDate = TextBox5.Text.Substring(5, 5) + "/" + TextBox5.Text.Substring(0, 4) + " " + DropDownList2.SelectedItem.Text + ":00";    //07/18/2017 15:00:00
                strXML += "<startDate>" + meetingStartDate + "</startDate> ";        //會議開始時間 MM/DD/YYYY HH:mm:ss
                strXML += "<openTime>900</openTime> ";
               
                DateTime end = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Convert.ToInt32(DropDownList3.SelectedItem.Text.Substring(0, 2)), Convert.ToInt32(DropDownList3.SelectedItem.Text.Substring(3, 2)), 00);
                DateTime start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Convert.ToInt32(DropDownList2.SelectedItem.Text.Substring(0, 2)), Convert.ToInt32(DropDownList2.SelectedItem.Text.Substring(3, 2)), 00);
                TimeSpan diff = end - start;
                double mins = diff.TotalMinutes;
                duringTime = mins.ToString();
                strXML += "<duration>" + duringTime + "</duration> ";      //會議花費時間
                strXML += "<timeZoneID>48</timeZoneID> ";
                strXML += " <allowAnyoneHostMeeting>true</allowAnyoneHostMeeting> ";
                strXML += "</schedule> ";
                strXML += "</bodyContent>";
                strXML += "</body> ";
                strXML += "</message>";
               
                //result = postXMLData(strXMLServer, GetRequestXml(strXML));
                                               
                /*
                byte[] byteArray = Encoding.UTF8.GetBytes(strXML);
                // Set the ContentLength property of the WebRequest.
                //request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = byteArray.Length;               
                request.Method = "POST";               

                // Get the request stream.
                Stream dataStream = request.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);
                // Close the Stream object.
                dataStream.Close();

                // Get the response.
                //WebResponse response = request.GetResponse();
                HttpWebResponse response =  (HttpWebResponse)request.GetResponse();

                // Get the stream containing content returned by the server.
                dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                string responseFromServer = reader.ReadToEnd();
               
                reader.Close();
                dataStream.Close();
                response.Close();
                */

                XmlDocument doc = new XmlDocument();
                //doc.LoadXml(responseFromServer);
                doc.LoadXml(ExecuteWebexXml( strXML ));

                // Display the content.
                //Console.WriteLine(responseFromServer);
                // Clean up the streams.
               
                if (GetExeResult(doc).ToUpper() == "SUCCESS")
                {
                    meetingKey = GetMeetingKEY(doc);
                    hostUrl = GetHostURL(doc);
                    attenUrl = GetAttURL(doc);
                }
            }
            catch (Exception ex)     
            {
                throw new Exception("XML交易失敗!" + ex.Message) ;              
            }
            if (meetingKey.Trim() != "")
            {                              
                try
                {
                    string strConn = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["DBConn"]);
                    SqlConnection myConn = new SqlConnection(strConn);
                    myConn.Open();   //EMPLOYEE_ID , EMPLOYEE_NAME single sign on 取得
                    string sqlCmd = " INSERT INTO MRR_MEETINGROOM_WebEx_SCHEDULE(EMPLOYEE_ID,EMPLOYEE_NAME,ROOM_ID";
                    sqlCmd += ",AGENDA,CHAIRMAN,PERSON_NUMBER,TELE_NUMBER,MEETING_DATE,START_TIME,END_TIME,UPDDT,MEETINGKEY,HOSTURL,ATTENDEEURL,MailCC,ENTITY_ROOM_ID)  ";
                    sqlCmd += " VALUES('" + USERID + "','" + USERNAME + "','" + DropDownList1.SelectedValue.Trim() + "','" + ReplaceStr(TextBox1.Text.Trim()) + "'";
                    sqlCmd += ",'" + ReplaceStr(TextBox2.Text.Trim()) + "','" + ReplaceStr(TextBox3.Text.Trim()) + "','" + ReplaceStr(TextBox4.Text.Trim()) + "','" + ReplaceStr(TextBox5.Text.Trim()) + "','" + DropDownList2.SelectedValue.Trim() + "','" + DropDownList3.SelectedValue.Trim() + "',GETDATE(),'" + meetingKey + "','" + hostUrl + "','" + attenUrl + "','" + TextBox6.Value.Trim().Replace("'","") + "' ,'"+ ReplaceStr(TextBox7.Text.Trim()) +"') ";

                    SqlCommand cmd = new SqlCommand(sqlCmd, myConn);
                    int effectRows = cmd.ExecuteNonQuery();
                    myConn.Close();
                    if (effectRows > 0)
                    {
                        string from = mailFormAddr();
                        string to = ClearString( Convert.ToString( System.Configuration.ConfigurationManager.AppSettings[ "EquipMgm" ] ) );         //ClearString(USERMAIL) + ";" +
                        string cc2199 = ClearString(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["SPCC"]));
                        string inputMailCC = ClearString(TextBox6.Value.Trim()); 
                        cc = cc2199 + ";" + inputMailCC ;
                        string subject = mailSuccessSubject();
                        string body = SendToOtherUserBody();
                        SendMail(ClearString(from), ClearString(to), subject, body);                                                 

                        from = mailFormAddr();
                        to = ClearString(USERMAIL);                      
                        subject = mailSuccessSubject() ;
                        body = SendToApplyUserBody();
                        SendMail(ClearString(from), ClearString(to), subject, body);    
                       

                        //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "dbex", "alert('會議室預約成功,請記得自行預約台北會議室(實體會議室)');location.href='Index.aspx'", true);
                        //string alertOK = " $(document).ready(function () { $('#simpleConfirm').click(); }); ";
                        //alertOK += "   ";

                        string addjs = "";
                        if (Daytype == "DAY")
                        {
                            addjs = "exeBlockui(3000);";
                        }
                        else
                        {
                            addjs = "exeBlockui(9000);";
                        }

                        string alertOK = " $(document).ready(function () {  $('#dialog-message').dialog('open');  });  "  ;
                        alertOK += "";

                        Page.ClientScript.RegisterStartupScript(this.GetType(), "open", alertOK, true);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("電子郵件發送失敗!" + ex.Message);
                }
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "webex", "alert('WebEx交易失敗:" + errMsg + "');", true);
            }
        }
    }

   
    private string SendToOtherUserBody()
    {
        return mailStart() + mailBolck1() + mailBlock2() + mailEnd();
    }

    private string SendToApplyUserBody()
    {
        cc = string.Empty;
        return mailStart()+ mailApplyUserBlock() +  mailBolck1() + mailBlock2() + mailEnd();
    }
   
     private string GetMeetingDataByGetMeeting()
     {
         return GetMeetingData( WebexXmlExeType.GetMeeting, meetingKey );      
     }

     private string GetMeetingDataByGetJoinurl()
    {
        return GetMeetingData(WebexXmlExeType.GetjoinurlMeeting, meetingKey);
    }
            

    private string ReplaceStr(string source)
    {       
        return source.Replace("'", "").Replace("--", "").Replace(";", "");    
    }

  
    private string ConvertMM(DateTime dt)
    {
        string mm;
        switch(dt.ToString("MM"))
        {
            case "01":
                mm = "January";
                break;
            case "02":
                mm = "February";
                break;
            case "03":
                mm = "March";
                break;
            case "04":
                mm = "April";
                break;
            case "05":
                mm = "May";
                break;
            case "06":
                mm = "June";
                break;
            case "07":
                mm = "July";
                break;
            case "08":
                mm = "August";
                break;
            case "09":
                mm = "Stepember";
                break;
            case "10":
                mm = "October";
                break;
            case "11":
                mm = "Novermber";
                break;
            case "12":
                mm = "December";
                break;
            default :
                mm = "";
                break;
        }
        return mm;
    }

   
    private string GetMeetingKEY(XmlDocument doc)
    {
        return GetTargetNode(doc, 1, 0, 0).InnerText;
    }

    private string GetHostURL(XmlDocument doc)
    {
        return GetTargetNode2(doc, 1, 0, 1, 0).InnerText;
    }

    private string GetAttURL(XmlDocument doc)
    {
        return GetTargetNode2(doc, 1, 0, 1, 1).InnerText;
    }

   
    private string GetHostKeyNodeText(XmlDocument doc)
    {
        return GetTargetNode(doc, 1, 0, 15).InnerText;
    }

    private string GetMeetUrlNodeText(XmlDocument doc)
    {
        return GetTargetNode(doc, 1, 0, 0).InnerText;
    }


    private string GetExeResult(XmlDocument doc)
    {
        return GetTargetNode(doc, 0, 0, 0).InnerText;
    }


    private bool InputCheck()
    {
        bool b = true;
        if (TextBox1.Text.Trim() == "")
        {
            this.Label3.Visible = true;
            this.Label3.Text = "會議名稱為必填";
            b = false;
        }
        else
        {
            this.Label3.Visible = false;
            this.Label3.Text = "";
            TextBox1.Text = TextBox1.Text.Trim();
        }
        if (TextBox2.Text.Trim() == "")
        {
            this.Label4.Visible = true;
            this.Label4.Text = "主席為必填";
            b = false;
        }
        else
        {
            this.Label4.Visible = false;
            this.Label4.Text = "";
            TextBox2.Text = TextBox2.Text.Trim();
        }
        if (TextBox3.Text.Trim() == "")
        {
            this.Label5.Visible = true;
            this.Label5.Text = "與會人數為必填";
            b = false;
        }
        else
        {
            this.Label5.Visible = false;
            this.Label5.Text = "";
            TextBox3.Text = TextBox3.Text.Trim();
        }
        if (!Regex.IsMatch(TextBox3.Text.Trim(), @"^(\d)+$"))
        {
            this.Label5.Visible = true;
            this.Label5.Text = "請輸入數字格式";
            b = false;
        }
        else
        {
            if (Convert.ToInt32( TextBox3.Text ) > 25)
            {
                this.Label5.Visible = true;
                this.Label5.Text = "與會人數須小於等於25";
                b = false;
            }
        }      
        if (TextBox4.Text.Trim() == "")
        {
            this.Label6.Visible = true;
            this.Label6.Text = "連絡電話為必填";
            b = false;
        }
        else
        {
            this.Label6.Visible = false;
            this.Label6.Text = "";
            TextBox4.Text = TextBox4.Text.Trim();
        }
        if (!Regex.IsMatch(TextBox4.Text.Trim(), @"^(\d)+$"))
        {
            this.Label6.Visible = true;
            this.Label6.Text = "請輸入數字格式";
            b = false;
        }

        if (TextBox5.Text.Trim() == "")
        {
            this.Label7.Visible = true;
            this.Label7.Text = "預約日期為必填";
            b = false;
        }
        else
        {
            this.Label7.Visible = false;
            this.Label7.Text = "";
            TextBox5.Text = TextBox5.Text.Trim();
        }
        if (!Regex.IsMatch(TextBox5.Text.Trim(), @"^([12]\d{3}/(0[1-9]|1[0-2])/(0[1-9]|[12]\d|3[01]))$"))
        {
            this.Label7.Visible = true;
            this.Label7.Text = "請輸入日期格式";
            b = false;
        }

        if (TextBox6.Value.Trim() != "")
        {
            if (TextBox6.Value.Trim().IndexOf(";") > 0)
            {
                string[] arry = TextBox6.Value.Trim().Split(new char[] { ';' });
                foreach(string mail in arry)
                {
                    if (mail.Trim().IndexOf("@") <= 0)
                    {
                        this.Label8.Visible = true;
                        this.Label8.Text = "電子郵件格式錯誤";
                        b = false;
                        break;
                    }
                }
            }
            else
            {
                if (TextBox6.Value.Trim().IndexOf("@") <=0)
                {
                    this.Label8.Visible = true;
                    this.Label8.Text = "電子郵件格式錯誤";
                    b = false;
                }
            }
        }

        if (TextBox7.Text.Trim() == "")
        {
            this.Label9.Visible = true;
            this.Label9.Text = "實體會議室名稱為必填";
            b = false;
        }
        else
        {
            this.Label9.Visible = false;
            this.Label9.Text = "";
            TextBox7.Text = TextBox7.Text.Trim();
        }
       
        return b;
    }
   

    protected void Button3_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        TextBox6.Value = "";
        TextBox7.Text = "";
    }
   

    private void AddItems(int i)
    {
        List<string> list = new List<string>();
        list.Add("09:30");
        list.Add("10:00");
        list.Add("10:30");
        list.Add("11:00");
        list.Add("11:30");
        list.Add("12:00");
        list.Add("12:30");
        list.Add("13:00");
        list.Add("13:30");
        list.Add("14:00");
        list.Add("14:30");
        list.Add("15:00");
        list.Add("15:30");
        list.Add("16:00");
        list.Add("16:30");
        list.Add("17:00");
        list.Add("17:30");
        list.Add("18:00");

        DropDownList3.Items.Clear();
        List<string> list2 = new List<string>();
        list2 = list.GetRange(i, list.Count - i);
        int j = i + 2;
        foreach (string item in list2)
        {
            DropDownList3.Items.Add(new ListItem(item, j.ToString()));
            j++;
        }
    }


    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        string startTime = DropDownList2.SelectedValue.Trim();
        if (startTime == "1")
        {
            AddItems(0);
        }
        else if (startTime == "2")
        {
            AddItems(1);
        }
        else if (startTime == "3")
        {
            AddItems(2);
        }
        else if (startTime == "4")
        {
            AddItems(3);
        }
        else if (startTime == "5")
        {
            AddItems(4);
        }
        else if (startTime == "6")
        {
            AddItems(5);
        }
        else if (startTime == "7")
        {
            AddItems(6);
        }
        else if (startTime == "8")
        {
            AddItems(7);
        }
        else if (startTime == "9")
        {
            AddItems(8);
        }
        else if (startTime == "10")
        {
            AddItems(9);
        }
        else if (startTime == "11")
        {
            AddItems(10);
        }
        else if (startTime == "12")
        {
            AddItems(11);
        }
        else if (startTime == "13")
        {
            AddItems(12);
        }
        else if (startTime == "14")
        {
            AddItems(13);
        }
        else if (startTime == "15")
        {
            AddItems(14);
        }
        else if (startTime == "16")
        {
            AddItems(15);
        }
        else if (startTime == "17")
        {
            AddItems(16);
        }
        else if (startTime == "18")
        {
            AddItems(17);
        }
    }


    private void ChangeRoomSetMemo()
    {
        try
        {
            string strConn = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["DBConn"]);
            SqlConnection myConn = new SqlConnection(strConn);
            myConn.Open();
            DataSet ds = new DataSet();
            string sqlcmd = " select MEMO from  MRR_MEETINGROOM_WebEx  WHERE ROOM_ID = '" + DropDownList1.SelectedValue.Trim() + "' ";
            SqlDataAdapter sda = new SqlDataAdapter(sqlcmd, myConn);
            sda.Fill(ds);
            myConn.Close();
            Label2.Text = ds.Tables[0].Rows[0][0].ToString();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }


    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        ChangeRoomSetMemo();
    }

    private void SetStartEndTime(string nm)
    {
        switch (nm)
        {
            case "1":
                DropDownList2.SelectedValue = "1";
                DropDownList3.SelectedValue = "2";
                break;
            case "2":
                DropDownList2.SelectedValue = "2";
                DropDownList3.SelectedValue = "3";
                break;
            case "3":
                DropDownList2.SelectedValue = "3";
                DropDownList3.SelectedValue = "4";
                break;
            case "4":
                DropDownList2.SelectedValue = "4";
                DropDownList3.SelectedValue = "5";
                break;
            case "5":
                DropDownList2.SelectedValue = "5";
                DropDownList3.SelectedValue = "6";
                break;
            case "6":
                DropDownList2.SelectedValue = "6";
                DropDownList3.SelectedValue = "7";
                break;
            case "7":
                DropDownList2.SelectedValue = "7";
                DropDownList3.SelectedValue = "8";
                break;
            case "8":
                DropDownList2.SelectedValue = "8";
                DropDownList3.SelectedValue = "9";
                break;
            case "9":
                DropDownList2.SelectedValue = "9";
                DropDownList3.SelectedValue = "10";
                break;
            case "10":
                DropDownList2.SelectedValue = "10";
                DropDownList3.SelectedValue = "11";
                break;
            case "11":
                DropDownList2.SelectedValue = "11";
                DropDownList3.SelectedValue = "12";
                break;
            case "12":
                DropDownList2.SelectedValue = "12";
                DropDownList3.SelectedValue = "13";
                break;
            case "13":
                DropDownList2.SelectedValue = "13";
                DropDownList3.SelectedValue = "14";
                break;
            case "14":
                DropDownList2.SelectedValue = "14";
                DropDownList3.SelectedValue = "15";
                break;
            case "15":
                DropDownList2.SelectedValue = "15";
                DropDownList3.SelectedValue = "16";
                break;
            case "16":
                DropDownList2.SelectedValue = "16";
                DropDownList3.SelectedValue = "17";
                break;
            case "17":
                DropDownList2.SelectedValue = "17";
                DropDownList3.SelectedValue = "18";
                break;
            case "18":
                DropDownList2.SelectedValue = "18";
                DropDownList3.SelectedValue = "19";
                break;

        }
    }


    private string CheckEnableSet(string nm)
    {
        string time = "";
        switch (nm)
        {
            case "1":
                time = "09:30";
                break;
            case "2":
                time = "10:00";
                break;
            case "3":
                time = "10:30";
                break;
            case "4":
                time = "11:00";
                break;
            case "5":
                time = "11:30";
                break;
            case "6":
                time = "12:00";
                break;
            case "7":
                time = "12:30";
                break;
            case "8":
                time = "13:00";
                break;
            case "9":
                time = "13:30";
                break;
            case "10":
                time = "14:00";
                break;
            case "11":
                time = "14:30";
                break;
            case "12":
                time = "15:00";
                break;
            case "13":
                time = "15:30";
                break;
            case "14":
                time = "16:00";
                break;
            case "15":
                time = "16:30";
                break;
            case "16":
                time = "17:00";
                break;
            case "17":
                time = "17:30";
                break;
            case "18":
                time = "18:00";
                break;
        }
        return time;
    }


    private string GetMeetingData(WebexXmlExeType xmlType, string meetingKey)
    {
        GetRoomLogin login = new GetRoomLogin(GetIdPass);
        string hostKey = "";
        string meetUrl = "";
        string strXML = "";
        string returnData = "";      
        login(DropDownList1.SelectedValue.Trim());
        try
        {
            //JoinMeetingPass = GetMeetingPass();
            strXML += "<?xml version='1.0' encoding='utf-8'?>";
            strXML += "<serv:message xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
            strXML += "<header>";
            strXML += "<securityContext>";
            string meetroom = DropDownList1.SelectedValue.Trim();
            if (meetroom == "C")
            {
                strXML += "<siteName>MAIL</siteName>";
            }
            else
            {
                strXML += "<siteName>MAIL-1</siteName>";
            }
            strXML += "<webExID>" + MeetingID + "</webExID>";
            strXML += "<password>" + MeetingPass + "</password>";
            strXML += "</securityContext>";
            strXML += "</header>";
            strXML += "<body> ";
            strXML += "  <bodyContent xsi:type='java:com.webex.service.binding.meeting." + xmlType.ToString() + "'> ";
            strXML += "  <meetingKey>" + meetingKey + "</meetingKey> ";
            strXML += "   </bodyContent>";
            strXML += "</body> ";
            strXML += "</serv:message>";
           
            XmlDocument doc = new XmlDocument();
            doc.LoadXml( ExecuteWebexXml( strXML ) );
            if (GetExeResult(doc).ToUpper() == "SUCCESS")
            {
                if (xmlType == WebexXmlExeType.GetMeeting)
                {
                    hostKey = GetHostKeyNodeText(doc);
                    returnData = hostKey;
                }
                else if (xmlType == WebexXmlExeType.GetjoinurlMeeting)
                {
                    meetUrl = GetMeetUrlNodeText(doc);
                    returnData = meetUrl;
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return returnData;
    }    


    private string mailFormAddr()
    {
        return "MAIL@com.tw";
    }

    private string mailSuccessSubject()
    {
        return "會議室預約成功";
    }

    private string mailStart()
    {
        return "<p style='line-height:24px;font-family:Arial,sans-serif'> ";
    }

    private string mailBolck1()
    {
        DateTime dt1 = new DateTime();
        dt1 = DateTime.ParseExact(meetingStartDate, "MM/dd/yyyy HH:mm:ss", null);
        string body = "";
        body += "<b> " + TextBox1.Text.Trim() + " </b> <br/>";
        body += "<font color='"+Color.Black+"'>" + dt1.DayOfWeek.ToString( ) + "," + ConvertMM( dt1 ) + " " + dt1.ToString( "dd" ) + ", " + dt1.Year + "<br/>";
        body += dt1.ToString("HH:mm") + " | " + " Taipei Time (Taipei, GMT+08:00) | " + (Convert.ToDouble(duringTime) / 60).ToString().Replace(".0", "") + "hr  </font><br/>";
        return body;
    }

    private string mailBlock2()
    {
        string body = "";
        body += "<font color='" + Color.Black + "'> Meeting number: " + meetingKey + " <br/>";
        body += "Meeting password: " + JoinMeetingPass + " <br/> ";
        body += "Webex會議室代碼: " + DropDownList1.SelectedValue + " <br/>";
        body += "實體會議室代碼: " + TextBox7.Text.Trim() + "</font> <br/><br/><br/>";
        return body;
    }

    private string mailEnd()
    {
        string body = "";
        body += "<a href='" + hostUrl + "' style='text-decoration:none'>";
        body += " <font style='background-color:#6de35b;font-size:25px;color:white'> &nbsp; <b>Add To Calendar</b> &nbsp </font>  ";
        body += " </a> &nbsp;&nbsp;  ";
        body += "When It's Time,";
        body += "<a href='" + GetMeetingDataByGetJoinurl() + "'> join the meeting </a>";
        body += "</p>";
        body += "";
        return body;
    }

    private string mailApplyUserBlock()
    {
        string body = "";
        body += "<font color='" + Color.Black + "'>Hi, " + USERNAME + "<br/>";
        body += "請在會議開始前登入WebEx會議室  <br/>";
        body += "並依以下步驟操作:  <br/>";
        body += "(1)點選會議室畫面上方的Participant -> Reclaim Host Role  <br/>";
        body += "(2)輸入 \"HostKey\"  <br/>";
        body += "您本次會議的HostKey:</font>" + "<font color='"+Color.Blue+" '><b>" + GetMeetingDataByGetMeeting( ) + "</b></font>" + "   <br/><br/>";
        return body;
    }       


    //MAIL
    private string strCCMailAddress = "";
    public bool SendMail(string MailFrom, string MailTo, string MailSubject, string MailBody)
    {
        strCCMailAddress = cc;
        bool blnReturn = true;

        string strServer = ConfigurationManager.AppSettings["MailServer"].ToString();
        string strID = ConfigurationManager.AppSettings["MailID"].ToString();
        string strPWD = ConfigurationManager.AppSettings["MailPwd"].ToString();
        string strSendMail = ConfigurationManager.AppSettings["SendMail"].ToString().ToUpper();
        string strCC = ConfigurationManager.AppSettings["CCMail"].ToString();
        string strTestMode = ConfigurationManager.AppSettings["TestMode"].ToString().ToUpper();

        string strUseMailPool = "";
        try
        {
            //Kevin(20090713) 是否要使用 Mail Pool 機制
            strUseMailPool = ConfigurationManager.AppSettings["UseMailPool"].ToString().ToUpper();
        }
        catch (Exception ex)
        {
            strUseMailPool = "N";
        }

        if (strSendMail.ToUpper() != "Y")
        {
            return true;
        }

        //若有自訂的[附件收件者]時,取代系統定義的[附件收件者]郵件位址
        if (!string.IsNullOrEmpty(strCCMailAddress))
        {
            strCC = strCCMailAddress;      //並CC給2199信箱及曹協理
        }

        if (strTestMode == "Y")
        {
            //MailBody = "原收件者:" + MailTo + "<BR>" + "副本收件者:" + strCC + "<BR><BR>" + MailBody;
            //strCC = ConfigurationManager.AppSettings["CCMail"].ToString();
            ////Kevin(20090206):若有設定 Test Mode 則以CC為收件者
            ////MailTo = "ABCD@com.tw;EDKX@com.tw"
            //MailTo = strCC;
            //strCC = "";
            //MailSubject = MailSubject + "...<TEST MODE>";
        }

        if (strUseMailPool == "Y")
        {
            //Kevin(20090713) 使用 Mail Pool 機制時,先將 Mail 資訊新增至 MAIL POOL
            InsertDataToMailQueue(MailFrom, MailTo, strCC, MailSubject, MailBody);
        }
        else
        {
            SmtpClient objSMTP = new SmtpClient(strServer);
            //your smtp server

            objSMTP.UseDefaultCredentials = false;
            objSMTP.Credentials = new NetworkCredential(strID, strPWD);
            //Your username and password to login
            objSMTP.DeliveryMethod = SmtpDeliveryMethod.Network;
            try
            {
                MailAddress MailAddressFrom = new MailAddress(MailFrom.Replace(";", "").Trim());
                MailMessage message = new MailMessage();
                message.Subject = MailSubject;
                message.Body = MailBody;
                message.IsBodyHtml = true;
                message.From = MailAddressFrom;

                string[] aylMailCC = null;
                if (!string.IsNullOrEmpty(strCC))
                {
                    aylMailCC = strCC.Split(new char[] { ';' });
                    for (int intCNT = 0; intCNT <= aylMailCC.Length - 1; intCNT++)
                    {
                        if (!string.IsNullOrEmpty(aylMailCC[intCNT].Trim()))
                        {
                            message.CC.Add(aylMailCC[intCNT]);
                        }
                    }
                }

                string[] aylMailTo = null;
                if (!string.IsNullOrEmpty(MailTo))
                {
                    aylMailTo = MailTo.Split(new char[] { ';' });
                    for (int intRow = 0; intRow <= aylMailTo.Length - 1; intRow++)
                    {
                        if (!string.IsNullOrEmpty(aylMailTo[intRow].Trim()))
                        {
                            message.To.Add(aylMailTo[intRow].Trim());
                        }
                    }
                }

                objSMTP.Send(message);
                blnReturn = true;
            }
            catch (Exception ex)
            {
                blnReturn = false;
                //Kevin(20090218) 顯示較易辨別的過誤訊息至前端
                //throw new ApplicationException("FlowSendMail Error:" + ex.Message);
            }
        }
        return blnReturn;
    }


    public void InsertDataToMailQueue(string MailFrom, string MailTo, string MailCC, string MailSubject, string MailBody)
    {
        string strSQL = "";
        OracleCommand cmdDB = new OracleCommand();
        string strSEQ = "";
        //IDbTransaction tx = null;
        OracleTransaction tx = null;

        try
        {
            this.OpenDB();
            tx = connDB.BeginTransaction();

            //取得 SEQUENCE
            strSQL = "SELECT SENDMAIL_SEQ.NEXTVAL FROM DUAL";
            cmdDB = new OracleCommand(strSQL, connDB, tx);
            strSEQ = Convert.ToString(cmdDB.ExecuteScalar());

            //新增 SENDMAIL_QUEUE
            strSQL = "INSERT INTO SENDMAIL_QUEUE ";
            strSQL += " (MODULE_NME, MAIL_ID, MAIL_FROM, MAIL_TO,MAIL_CC, MAIL_SUBJECT, MAIL_BODY, UPDDT)";
            strSQL += " VALUES";
            strSQL += " ('FLOW', " + strSEQ + ", '" + MailFrom + "', '" + MailTo + "', '" + MailCC + "', '" + MailSubject + "', EMPTY_CLOB(), SYSDATE)";
            cmdDB = new OracleCommand(strSQL, connDB, tx);
            cmdDB.ExecuteNonQuery();

            //更新 SENDMAIL_QUEUE CLOB 資料
            strSQL = "SELECT MAIL_BODY FROM SENDMAIL_QUEUE WHERE MAIL_ID = '" + strSEQ + "' FOR UPDATE ";
            cmdDB.CommandText = strSQL;
            cmdDB.Parameters.Clear();
            cmdDB.CommandTimeout = 300;
            OracleLob clob = default(OracleLob);
            using (OracleDataReader objReader = cmdDB.ExecuteReader())
            {
                while (objReader.Read())
                {
                    clob = objReader.GetOracleLob(0);
                    byte[] arrValue = System.Text.Encoding.Unicode.GetBytes(MailBody);
                    clob.Write(arrValue, 0, arrValue.Length);
                }
                objReader.Close();
                tx.Commit();
            }
        }
        catch (Exception ex)
        {
            tx.Rollback();
            throw new Exception( "InsertMailQueue失敗" + ex.Message );
        }
        finally
        {
            connDB.Close();
            connDB.Dispose();
        }
    }
   

    private bool OpenDB()
    {
        try
        {
            string connDBConnection = null;

            if ((connDB == null) | connDB.State == ConnectionState.Closed)
            {
                connDBConnection = System.Configuration.ConfigurationManager.ConnectionStrings["DBConn"].ConnectionString;
                connDB.ConnectionString = connDBConnection;
                connDB.Open();
            }
        }
        catch (Exception ex)
        {
            throw new Exception( "資料庫開啟失敗" + ex.Message );
        }
        return true;
    }


    private string GetMeetingPass( string hashCode = "yyyyMMddHHmmssff" )
    {
        MD5 md5 = MD5.Create();
        byte[] source = Encoding.Default.GetBytes(DateTime.Now.ToString(hashCode));
        byte[] crypto = md5.ComputeHash(source);
        return Convert.ToBase64String(crypto).Substring(0, 10);
    }


    private XmlNode GetRootXMLNode(XmlDocument doc)
    {
        return doc.SelectNodes("/")[0].ChildNodes[1];
    }

    private XmlNode GetTargetNode(XmlDocument doc, int node1, int node2, int node3)
    {
        return GetRootXMLNode(doc).ChildNodes[node1].ChildNodes[node2].ChildNodes[node3];
    }

    private XmlNode GetTargetNode2(XmlDocument doc, int node1, int node2, int node3, int node4)
    {
        return GetRootXMLNode(doc).ChildNodes[node1].ChildNodes[node2].ChildNodes[node3].ChildNodes[node4];
    }


    private string Decrypt(string cipherText)
    {
        string EncryptionKey = DateTime.Now.ToString("yyyyMMdd") + "WEBEXMT";
        cipherText = cipherText.Replace(" ", "+");

        byte[] cipherBytes = Convert.FromBase64String(cipherText);

        using (Aes encryptor = Aes.Create())
        {
            Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });

            encryptor.Key = pdb.GetBytes(32);
            encryptor.IV = pdb.GetBytes(16);

            using (MemoryStream ms = new MemoryStream())
            {
                using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(cipherBytes, 0, cipherBytes.Length);
                    cs.Close();
                }
                cipherText = Encoding.Unicode.GetString(ms.ToArray());
            }
        }
        return cipherText;
    }


    public string postXMLData(string destinationUrl, string requestXml)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(destinationUrl);
        byte[] bytes;
        bytes = System.Text.Encoding.UTF8.GetBytes(requestXml);
        request.ContentType = "application/x-www-form-urlencoded;";
        request.ContentLength = bytes.Length;
        request.Method = "POST";
        Stream requestStream = request.GetRequestStream();
        requestStream.Write(bytes, 0, bytes.Length);
        requestStream.Close();
        HttpWebResponse response;
        response = (HttpWebResponse)request.GetResponse();
        if (response.StatusCode == HttpStatusCode.OK)
        {
            Stream responseStream = response.GetResponseStream();
            string responseStr = new StreamReader(responseStream).ReadToEnd();
            return responseStr;
        }
        return null;
    }


    private string GetRequestXml(string strXML)
    {
        return "XML=" + HttpUtility.UrlEncode(strXML);
    }

    private string GetXmlServer()
    {
        return "https://webex.com/WBXService/xml8.0.0/XMLService";
    }


    private string AuthValidKey()
    {
        char[] charArray = DateTime.Now.AddYears(-Convert.ToInt32(DateTime.Now.DayOfWeek)).AddMonths(Convert.ToInt32(DateTime.Now.DayOfWeek)).AddDays(-Convert.ToInt32(DateTime.Now.DayOfWeek))
            .ToString("yyyyMMdd").ToCharArray();
        Array.Reverse(charArray);
        return (Convert.ToInt32(new string(charArray)) * Convert.ToInt32(DateTime.Now.DayOfWeek)).ToString();
    }


    private string ClearString(string source)
    {
        if (source.StartsWith(";"))
        {
            source = source.Substring(1);
        }
        if (source.EndsWith(";"))
        {
            source = source.Substring(0, source.Length - 1);
        }
        return source;
    }

    private void GetIdPass(string key)
    {
        MeetingID = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["Webexid" + key]);
        MeetingPass = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["Webexpwd" + key]);
    }


    private string ExecuteWebexXml( string strXML )
    {
        string result = "";
        ServiceReference1.Service1Client svc = new ServiceReference1.Service1Client( );
        try
        {
            svc.Open( );
            result = svc.CreateMeeting( strXML, DropDownList1.SelectedValue.Trim( ) );
            svc.Close( );
        }
        catch (Exception ex)
        {
            try
            {
                if (svc.State == CommunicationState.Faulted)
                    svc.Abort( );
                else
                    svc.Close( );
            }
            catch
            {
                svc.Abort( );
            }
        }
        return result;
    }


    private enum WebexXmlExeType
    {
        GetMeeting,
        GetjoinurlMeeting
    }
   
}

public static class XmlStringExtension
{
    public static string ReplaceXml(this string source)
    {
        return source.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace("'", "&apos;").Replace("\"", "&quot;");
    }
}

public static class Color
{
    public static string Blue
    {
        get
        {
            return "#3366cc";
        }
    }
    public static string Black
     {
         get
         {
             return "#666666";
         }
     }
}

================================================
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewScheduleView.aspx.cs" Inherits="NewScheduleView" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link rel="stylesheet" type="text/css" href="Content/mrr.css" />
   
    <link rel="stylesheet" type="text/css" href="Content/jquery-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="Content/jquery-ui.structure.min.css" />
    <link rel="stylesheet" type="text/css" href="Content/jquery-ui.theme.css" />
    <link rel="stylesheet" type="text/css" href="Content/Site.css" />
    <%--<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" />--%>
    <%--<link href="https://cdn.rawgit.com/google/code-prettify/master/loader/prettify.css" rel="stylesheet" type="text/css" />--%>

    <script type="text/javascript" src="Scripts/jquery-1.10.2.min.js"></script>
    <%--<script type="text/javascript" src="Scripts/jquery-1.10.2.intellisense.js"></script>--%>
    <%--<script type="text/javascript" src="Scripts/jquery-1.10.2.min.map"></script>--%>
    <script type="text/javascript" src="Scripts/jquery-ui.min.js"></script> 
    <%--<script type="text/javascript" src="Scripts/jquery.confirm.min.js"></script>--%>
    <%--<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>--%>
    <%--<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>--%>
    <script type="text/javascript" src="Scripts/jquery.blockUI.js"></script>


    <script type="text/javascript" >
        $(document).ready(function () {
            setup();
        });

    </script>

    <script type="text/javascript" >
        function setup() {
            $("#TextBox5").datepicker({
                dateFormat: "yy/mm/dd",
                dafaultDate: new Date(),
                minDate: new Date()
            });
        }
 </script>

   
    <script>
        $(function () {
            $('#dialog-message').dialog({
                autoOpen: false,
                modal: true,
                buttons: {
                    確定: function () {
                        $(this).dialog('close');
                        exeBlockui(8000);
                        location.href = 'Index.aspx';
                    }
                }
            });
        });

    </script>


    <script>
        window.onerror = function (msg, url, linenumber) {
            return true;
        }
   </script>


    <style type="text/css">
        .auto-style1 {
            width: 216px;
        }
    </style>

    <style>
         .ui-widget-header,.ui-state-default, ui-button{
            background:#3366cc;
            border: 1px solid #b9cd6d;
            color: #FFFFFF;
            font-weight: bold;
         }
   </style>


    <script>
        $(document).ready(function () {
            $('.class6').click(function () {
                $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
                setTimeout($.unblockUI, 3000);
            });
        });
        $(document).ready(function () {
            $(".class5").click(function () {
                $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
                setTimeout($.unblockUI, 8000);
            });
        });
   </script>

    <script>
        function exeBlockui(t) {
            $.blockUI({ message: '<div style="padding: 5px"><img src="images/waiting.gif" /> 取得會議室資料.. </div>' });
            setTimeout($.unblockUI, t);
        }
</script>


</head>


<body>
    <form id="form1" runat="server">
       
        <table bordr="0" >

            <tr >
                <td style="width:20%"> </td>
                <td>


      
            <table width="800px" border="1">

                <tr>
                    <td class="auto-style1">
                        <img width='190px' height='50px' src="images/logo_190x50.jpg"/>
                    </td>
                    <td style="text-align:right">
                       
                            <span id="group" style="FONT-SIZE: 16px; BORDER-TOP: gray 1px solid; BORDER-RIGHT: gray 1px solid; BORDER-BOTTOM: gray 1px solid; PADDING-BOTTOM: 3px; PADDING-LEFT: 5px; BORDER-LEFT: gray 1px solid; PADDING-RIGHT: 5px; BACKGROUND-COLOR: #d9ecff">美商科技</span>
                            -取消預約會議室
                    </td>                   
                </tr>


                <tr>
                    <td class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;申請者編號 : </font>
                    </td>
                    <td class="mmr_rightCon">

                                            <asp:Label ID="Label1" runat="server"></asp:Label>

                                            </td>
                </tr>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;會議室名稱 : </font>
                    </td>
                    <td class="mmr_rightCon">
                       
                       
                       
                                            <asp:Label ID="Label2" runat="server"></asp:Label>

                    </td>
                </tr>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;設備 : </font>
                    </td>
                    <td id="equipment" class="mmr_rightCon">

                                            <asp:Label ID="Label3" runat="server" ForeColor="Red"></asp:Label>
                    </td>
                </tr>
               <%-- <tr>
                    <td class="mmr_leftCon">
                        <font>注意事項 : </font>
                    </td>
                    <td id="ps" class="mmr_rightCon">
                        <asp:Label ID="Label3" runat="server"></asp:Label>
                    </td>
                </tr>--%>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;會議名稱 : </font><font size="2" color="#FF0000">*</font>
                    </td>
                    <td class="mmr_rightCon">

                                            <asp:Label ID="Label4" runat="server"></asp:Label>

                    </td>
                </tr>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;主席 : </font><font size="2" color="#FF0000">*</font>
                    </td>
                    <td class="mmr_rightCon">

                                            <asp:Label ID="Label5" runat="server"></asp:Label>

                    </td>
                </tr>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;與會人數 : </font><font size="2" color="#FF0000">*</font>
                    </td>
                    <td class="mmr_rightCon">

                                            <asp:Label ID="Label6" runat="server"></asp:Label>

                    </td>
                </tr>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;聯絡人電話 : </font><font size="2" color="#FF0000">*</font>
                    </td>
                    <td class="mmr_rightCon">

                                            <asp:Label ID="Label7" runat="server"></asp:Label>

                    </td>
                </tr>
                <tr>
                    <td  class='topsmallCon'  style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;預約日期 : </font><font size="2" color="#FF0000">*</font>
                    </td>
                    <td class="mmr_rightCon">

                                            <asp:Label ID="Label8" runat="server"></asp:Label>

                    </td>
                </tr>
                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;起迄時間 : </font><font size="2" color="#FF0000">*</font>
                    </td>
                    <td class="mmr_rightCon">
                        &nbsp;<asp:Label ID="Label9" runat="server"></asp:Label>

                    </td>
                </tr>

                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                        <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;實體會議室名稱 : </font><font size="2" color="#FF0000">*</font>
                    </td>
                    <td class="mmr_rightCon">
                        &nbsp;<asp:Label ID="Label11" runat="server"></asp:Label>
                    </td>
                </tr>

                <%--<tr>
                    <td class="mmr_leftCon">
                        <font>是否預約未來每周同一<br>時段的會議室? </font>
                    </td>
                    <td class="mmr_rightCon">
                        <input id="fixedMonthRowSwitch" type="checkbox" />
                    </td>
                </tr>--%>

                <tr>
                    <td  class='topsmallCon' style="border-left-width:thin">
                       <font style="font-size:12px; font-family: Arial, sans-serif">&nbsp;Mail CC : </font>                         
                    </td>
                    <td >
                        <%--<textarea id="TextBox6" runat="server" rows="4" cols="70" maxlength="500"></textarea>--%>
                        &nbsp;
                        <asp:Label ID="Label10" runat="server"></asp:Label>
                    </td>
                </tr>

                <tr>
                    <td style="text-align:center" colspan="2">
                         <asp:Button ID="Button1" runat="server" Text="回首頁" OnClick="Button1_Click"></asp:Button>
                         &nbsp;&nbsp;   <asp:Button ID="Button2" runat="server" Text="取消預約" OnClick="Button2_Click"></asp:Button>
                         &nbsp;&nbsp;  
                    </td>
                </tr>

            </table>



                     </td>
                 <td style="width:20%"> </td>
            </tr>

        </table>


        <div  title='System Message' id='dialog-message'><p>
                <span class='ui-icon ui-icon-circle-check' style='float: left; margin: 0 7px 50px 0;'></span>
                         會議室預約完成取消  <p>
        </p> </div>


    </form>
</body>


</html>

------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.Data;
using System.Net.Mail;
using System.Xml;
using System.Net;
using System.IO;
using System.Text;
using System.Configuration;
using System.Data.OracleClient;
using System.ServiceModel;


public partial class NewScheduleView : System.Web.UI.Page
{
    private OracleConnection connDB = new OracleConnection();
    delegate void GetRoomLogin(string whichRoom);
    string SCHID = "";
    string MTKEY = "";
    string cc = "";
    string id = "";
    string pwd = "";
    string Daytype = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        CommonUtil.UserProfile objUserProfile;
        if (Session["UserProfile"] == null) {
            //objUserProfile = new CommonUtil.UserProfile();
            //if (CommonUtil.CommonClass.getUserProfileErr(Request.ServerVariables["LOGON_USER"].ToString(), ref objUserProfile) == true)
            //{
            //    Response.Redirect(Request.Url.ToString());
            //}
            Response.Redirect("Index.aspx");
        }
       
        if (Request[AuthValidKey()] != null)
        {
            SCHID = Decrypt(HttpUtility.UrlDecode(Request[AuthValidKey()].Trim().ToString()));
        }
        else
        {
            Response.Redirect("Index.aspx");
        }

        string strConn = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["DBConn"]);
        SqlConnection myConn = new SqlConnection(strConn);
        myConn.Open();
        DataSet ds = new DataSet();
        string sqlcmd = " SELECT EMPLOYEE_NAME ,MRR_MEETINGROOM_WebEx_SCHEDULE.ROOM_ID,MEMO, ";
        sqlcmd += " AGENDA,CHAIRMAN,PERSON_NUMBER,TELE_NUMBER,MEETING_DATE,START_TIME,END_TIME , EMPLOYEE_ID, MailCC , ENTITY_ROOM_ID ";
        sqlcmd += " FROM MRR_MEETINGROOM_WebEx_SCHEDULE , MRR_MEETINGROOM_WebEx ";
        sqlcmd += " WHERE MRR_MEETINGROOM_WebEx_SCHEDULE.SCHEDULE_ID = " + SCHID;
        sqlcmd += " AND MRR_MEETINGROOM_WebEx_SCHEDULE.ROOM_ID = MRR_MEETINGROOM_WebEx.ROOM_ID  ";
        sqlcmd += "  ";
        SqlDataAdapter sda = new SqlDataAdapter(sqlcmd, myConn);
        sda.Fill(ds);
        myConn.Close();

        string dept = "";
        //if (Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdmin"]) != Convert.ToString(Session["USRID"]))
        //{
            CommonUtil.UserProfile ObjUserProfile2 = new CommonUtil.UserProfile();
            if (ObjUserProfile2.QueryUserProfile(ds.Tables[0].Rows[0]["EMPLOYEE_ID"].ToString()) == false)
            {
                dept = "";
            }
            else
            {
                dept = ObjUserProfile2.GetDEPT_NME + "\\";
            }          
        //}
        //else
        //{
            if (ds.Tables[0].Rows[0]["EMPLOYEE_ID"].ToString() == Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdmin"]))
            {
                objUserProfile = null;
                dept = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdmin"]) + "\\";
            }
        //}

        this.Label1.Text = dept +  ds.Tables[0].Rows[0]["EMPLOYEE_NAME"].ToString() + "(" + ds.Tables[0].Rows[0]["EMPLOYEE_ID"].ToString() + ")";
        this.Label2.Text = ds.Tables[0].Rows[0]["ROOM_ID"].ToString();
        this.Label3.Text = ds.Tables[0].Rows[0]["MEMO"].ToString();
        this.Label4.Text = ds.Tables[0].Rows[0]["AGENDA"].ToString();
        this.Label5.Text = ds.Tables[0].Rows[0]["CHAIRMAN"].ToString();
        this.Label6.Text = ds.Tables[0].Rows[0]["PERSON_NUMBER"].ToString();
        this.Label7.Text = ds.Tables[0].Rows[0]["TELE_NUMBER"].ToString();
        this.Label8.Text = ds.Tables[0].Rows[0]["MEETING_DATE"].ToString();
        string st = ConvertStime(ds.Tables[0].Rows[0]["START_TIME"].ToString());
        string et = ConvertEtime(ds.Tables[0].Rows[0]["END_TIME"].ToString());
        this.Label9.Text = st + "-" + et ;
        Label10.Text = ClearString(ds.Tables[0].Rows[0]["MailCC"].ToString().Replace(" ",""))  ;
        Label11.Text = ds.Tables[0].Rows[0]["ENTITY_ROOM_ID"].ToString();
               
        CommonUtil.UserProfile ObjUserProfile = new CommonUtil.UserProfile();
        string usrid = "";
        if (Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdmin"]) != Convert.ToString(Session["USRID"]))
        {
            ObjUserProfile = (CommonUtil.UserProfile)Session["UserProfile"];
            usrid = ObjUserProfile.GetUSR_ID.ToString() ;
        }
        else
        {
            ObjUserProfile = null;
            usrid =Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdmin"]) ;
        }

        if (ds.Tables[0].Rows[0]["EMPLOYEE_ID"].ToString() != usrid)
        {
            if (Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["WebexAdmin"]) == usrid)
            {
                Button2.Enabled = true;
            }
            else
            {
                Button2.Enabled = false;
            }
        }
        else
        {
            Button2.Enabled = true;
        }
       
        if (Session["targetType"] != null)
        {
            Daytype = Convert.ToString(Session["targetType"]);
            if (Daytype == "DAY")
            {
                //Button1.Attributes.Remove("class");
                //Button1.Attributes.Add("class", "class6");
                Button2.Attributes.Remove("class");
                Button2.Attributes.Add("class", "class6");
            }
            else
            {
                Button1.Attributes.Remove("class");
                Button1.Attributes.Add("class", "class5");
                //Button2.Attributes.Remove("class");      //改為dialog confirm執行
                //Button2.Attributes.Add("class", "class5");
            }
        }

        GetMeetingKey();
    }


    private void GetMeetingKey()
    {
        string strConn = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["DBConn"]);
        SqlConnection myConn = new SqlConnection(strConn);
        myConn.Open();
        DataSet ds = new DataSet();
        string sqlcmd = "  SELECT MEETINGKEY FROM MRR_MEETINGROOM_WebEx_SCHEDULE WHERE SCHEDULE_ID = " + SCHID ;       
        SqlDataAdapter sda = new SqlDataAdapter(sqlcmd, myConn);
        sda.Fill(ds);
        myConn.Close();
        MTKEY = ds.Tables[0].Rows[0]["MEETINGKEY"].ToString();
    }

    private string ConvertStime(string nm)
    {
        string result = "";
        switch(nm)
        {
            case "1":
                result = "09:00";
                break;
            case "2":
                result = "09:30";
                break;
            case "3":
                result = "10:00";
                break;
            case "4":
                result = "10:30";
                break;
            case "5":
                result = "11:00";
                break;
            case "6":
                result = "11:30";
                break;
            case "7":
                result = "12:00";
                break;
            case "8":
                result = "12:30";
                break;
            case "9":
                result = "13:00";
                break;
            case "10":
                result = "13:30";
                break;
            case "11":
                result = "14:00";
                break;
            case "12":
                result = "14:30";
                break;
            case "13":
                result = "15:00";
                break;
            case "14":
                result = "15:30";
                break;
            case "15":
                result = "16:00";
                break;
            case "16":
                result = "16:30";
                break;
            case "17":
                result = "17:00";
                break;
            case "18":
                result = "17:30";
                break;       
           
        }
        return result;
    }


    private string  ConvertEtime(string nm)
    {
        string result = "";
        switch (nm)
        {           
            case "2":
                result = "09:30";
                break;
            case "3":
                result = "10:00";
                break;
            case "4":
                result = "10:30";
                break;
            case "5":
                result = "11:00";
                break;
            case "6":
                result = "11:30";
                break;
            case "7":
                result = "12:00";
                break;
            case "8":
                result = "12:30";
                break;
            case "9":
                result = "13:00";
                break;
            case "10":
                result = "13:30";
                break;
            case "11":
                result = "14:00";
                break;
            case "12":
                result = "14:30";
                break;
            case "13":
                result = "15:00";
                break;
            case "14":
                result = "15:30";
                break;
            case "15":
                result = "16:00";
                break;
            case "16":
                result = "16:30";
                break;
            case "17":
                result = "17:00";
                break;
            case "18":
                result = "17:30";
                break;
            case "19":
                result = "18:00";
                break;
        }
        return result;
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Index.aspx");       
    }


    //cancel meeting
    protected void Button2_Click(object sender, EventArgs e)
    {
        GetRoomLogin login = new GetRoomLogin(GetIdPass);
        string meetingKey = MTKEY;
        //string meetingKey = "123456789";       
        //string id = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["Webexid"]);
        //string pwd = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["Webexpwd"]);
        //GetMeetingIDPass();
        login(this.Label2.Text.Trim());

        //string strXMLServer = GetXmlServer() ;
        //WebRequest request = WebRequest.Create(strXMLServer);
        //// Set the Method property of the request to POST.
        //request.Method = "POST";
        //// Set the ContentType property of the WebRequest.
        ////request.ContentType = "application/x-www-form-urlencoded";

        // Create POST data and convert it to a byte array.
        string strXML = "";
        strXML += "<?xml version='1.0' encoding='UTF-8'?> ";
        strXML += "<message xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> ";
        strXML += "<header> ";
        strXML += "<securityContext> ";

        string meetroom = this.Label2.Text;
        if (meetroom == "C")
        {
            strXML += "<siteName>MAIL</siteName>";
        }
        else
        {
            strXML += "<siteName>MAIL-1</siteName>";
        }
       
        //strXML += "<siteName>MAIL</siteName> ";
        strXML += "<webExID>" + id + "</webExID> ";    //帳號
        strXML += "<password>" + pwd + "</password> ";    //密碼
        strXML += "</securityContext> ";
        strXML += "</header> ";
        strXML += "<body>  ";
        strXML += "<bodyContent xsi:type='java:com.webex.service.binding.meeting.DelMeeting'>  ";
        strXML += "<meetingKey>"+ meetingKey +"</meetingKey>  ";      //會議ID
        strXML += "</bodyContent>  ";
        strXML += "</body>  ";
        strXML += "</message> ";

        //byte[] byteArray = Encoding.UTF8.GetBytes(strXML);

        //// Set the ContentLength property of the WebRequest.
        //request.ContentLength = byteArray.Length;

        //// Get the request stream.
        //Stream dataStream = request.GetRequestStream();
        //// Write the data to the request stream.
        //dataStream.Write(byteArray, 0, byteArray.Length);
        //// Close the Stream object.
        //dataStream.Close();
        //// Get the response.
        //WebResponse response = request.GetResponse();

        //// Get the stream containing content returned by the server.
        //dataStream = response.GetResponseStream();
        //// Open the stream using a StreamReader for easy access.
        //StreamReader reader = new StreamReader(dataStream);
        //// Read the content.
        //string responseFromServer = reader.ReadToEnd();

        string result = "";
        ServiceReference1.Service1Client svc = new ServiceReference1.Service1Client();
       
        try
        {
            svc.Open();
            result = svc.DelMeeting(strXML, this.Label2.Text);
            svc.Close();
        }
        catch (Exception ex)
        {
            try
            {
                if (svc.State == CommunicationState.Faulted)
                    svc.Abort();
                else
                    svc.Close();
            }
            catch
            {
                svc.Abort();
            }
        }               

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(result);

        //// Display the content.
        ////Console.WriteLine(responseFromServer);
        //// Clean up the streams.
        //reader.Close();
        //dataStream.Close();
        //response.Close();       

        if (GetExeResult(doc).ToUpper() == "SUCCESS")       
        {
            string strConn2 = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["DBConn"]);
            SqlConnection myConn2 = new SqlConnection(strConn2);
            myConn2.Open();
            DataSet ds2 = new DataSet();
            string sqlcmd2 = "  SELECT *, CONVERT(VARCHAR,MEETING_DATE,111)  as formdate FROM MRR_MEETINGROOM_WebEx_SCHEDULE WHERE SCHEDULE_ID = " + SCHID;
            SqlDataAdapter sda2 = new SqlDataAdapter(sqlcmd2, myConn2);
            sda2.Fill(ds2);
            myConn2.Close();
            string ROOM_ID = ds2.Tables[0].Rows[0]["ROOM_ID"].ToString()  ;
            string AGENDA = ds2.Tables[0].Rows[0]["AGENDA"].ToString();
            string CHAIRMAN = ds2.Tables[0].Rows[0]["CHAIRMAN"].ToString();
            string formdate = ds2.Tables[0].Rows[0]["formdate"].ToString();
            string START_TIME = ConvertStime(ds2.Tables[0].Rows[0]["START_TIME"].ToString());
            string END_TIME = ConvertEtime(ds2.Tables[0].Rows[0]["END_TIME"].ToString());
            string MEETINGKEY = ds2.Tables[0].Rows[0]["MEETINGKEY"].ToString();
            string MailCC = ds2.Tables[0].Rows[0]["MailCC"].ToString();
            string ENTITY_ROOM_ID = ds2.Tables[0].Rows[0]["ENTITY_ROOM_ID"].ToString();

            try
            {
                string strConn = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["DBConn"]);
                SqlConnection myConn = new SqlConnection(strConn);
                myConn.Open();
                string sqlCmd = "   DELETE FROM MRR_MEETINGROOM_WebEx_SCHEDULE   WHERE MEETINGKEY = '" + meetingKey + "'  ";               
                SqlCommand cmd = new SqlCommand(sqlCmd, myConn);
                int effectRows = cmd.ExecuteNonQuery();
                myConn.Close();

                if (effectRows > 0)
                {  
                    string from = "WebExMeeting@com.tw";
                    string to = ClearString(MailCC) + ";" + ClearString(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["EquipMgm"]));
                    string cc2199 = ClearString(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["SPCC"]));
                    cc = cc2199;
                    //string subject = "會議室預約取消 ( 會議名稱: "  + AGENDA +  "  地點: " +  ROOM_ID  +"會議室  日期: " + formdate + "  " + START_TIME + " - " +   END_TIME + ")";
                    string subject = "會議室預約取消";
                    string body = "    ";
                    body += " <b><font color='red'>  已取消此時段會議  </font> </b><br/>";
                    body += "會議名稱: " +  AGENDA   + "<br/>";
                    body += "WebEx會議室代碼: " + ROOM_ID + " <br/>";
                    body += "實體會議室代碼: " + ENTITY_ROOM_ID + "<br/>"; 
                    body += "主席: " +  CHAIRMAN   + "<br/>";
                    body += "日期: " +  formdate   + "<br/>";
                    body += "時間: " +  START_TIME    +" - " + END_TIME + "<br/>";                   
                    SendMail(ClearString(from), ClearString(to), subject, body);
                                       
                    string addjs = "";
                    if (Daytype == "DAY")
                    {
                        //addjs = "exeBlockui(3000);";
                    }
                    else
                    {
                        addjs = "exeBlockui(9000);";
                    }

                    //Page.ClientScript.RegisterStartupScript(this.GetType(), "addjs", addjs, true);
                   
                    //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "DBDEL", "alert('取消成功!');location.href='Index.aspx'", true);
                    string alertOK = " $(document).ready(function () {  $('#dialog-message').dialog('open');  }); " ;
                    alertOK += "";

                    Page.ClientScript.RegisterStartupScript(this.GetType(), "open", alertOK, true); 
                }
            }
            catch (Exception ex)
            {
                throw new Exception( "電子郵件發送失敗!" + ex.Message );
            }
        }
        else
        {
            Page.ClientScript.RegisterStartupScript( this.GetType( ), "err", "$('#dialog-message').hide();alert('WebEx預約不存在,取消預約失敗!');location.href='Index.aspx';", true ); 
        }
    }
   

    //MAIL
    private string strCCMailAddress = "";
    public bool SendMail(string MailFrom, string MailTo, string MailSubject, string MailBody)
    {
        strCCMailAddress = cc;
        bool blnReturn = true;

        string strServer = ConfigurationManager.AppSettings["MailServer"].ToString();
        string strID = ConfigurationManager.AppSettings["MailID"].ToString();
        string strPWD = ConfigurationManager.AppSettings["MailPwd"].ToString();
        string strSendMail = ConfigurationManager.AppSettings["SendMail"].ToString().ToUpper();
        string strCC = ConfigurationManager.AppSettings["CCMail"].ToString();
        string strTestMode = ConfigurationManager.AppSettings["TestMode"].ToString().ToUpper();

        string strUseMailPool = "";

        try
        {
            //Kevin(20090713) 是否要使用 Mail Pool 機制
            strUseMailPool = ConfigurationManager.AppSettings["UseMailPool"].ToString().ToUpper();
        }
        catch (Exception ex)
        {
            strUseMailPool = "N";
        }

        if (strSendMail.ToUpper() != "Y")
        {
            return true;
        }

        //若有自訂的[附件收件者]時,取代系統定義的[附件收件者]郵件位址
        if (!string.IsNullOrEmpty(strCCMailAddress))
        {
            strCC = strCCMailAddress;
        }

        if (strTestMode == "Y")
        {
            //MailBody = "原收件者:" + MailTo + "<BR>" + "副本收件者:" + strCC + "<BR><BR>" + MailBody;
            //strCC = ConfigurationManager.AppSettings["CCMail"].ToString();
            ////Kevin(20090206):若有設定 Test Mode 則以CC為收件者
            ////MailTo = "IDKX@com.tw;IDKR@com.tw"
            //MailTo = strCC;
            //strCC = "";
            //MailSubject = MailSubject + "...<TEST MODE>";
        }

        if (strUseMailPool == "Y")
        {
            //Kevin(20090713) 使用 Mail Pool 機制時,先將 Mail 資訊新增至 MAIL POOL
            InsertDataToMailQueue(MailFrom, MailTo, strCC, MailSubject, MailBody);
        }
        else
        {
            SmtpClient objSMTP = new SmtpClient(strServer);
            //your smtp server

            objSMTP.UseDefaultCredentials = false;
            objSMTP.Credentials = new NetworkCredential(strID, strPWD);
            //Your username and password to login
            objSMTP.DeliveryMethod = SmtpDeliveryMethod.Network;
            try
            {
                MailAddress MailAddressFrom = new MailAddress(MailFrom.Replace(";", "").Trim());
                MailMessage message = new MailMessage();
                message.Subject = MailSubject;
                message.Body = MailBody;
                message.IsBodyHtml = true;
                message.From = MailAddressFrom;

                string[] aylMailCC = null;
                if (!string.IsNullOrEmpty(strCC))
                {
                    aylMailCC = strCC.Split(new char[] { ';' });
                    for (int intCNT = 0; intCNT <= aylMailCC.Length - 1; intCNT++)
                    {
                        if (!string.IsNullOrEmpty(aylMailCC[intCNT].Trim()))
                        {
                            message.CC.Add(aylMailCC[intCNT]);
                        }
                    }
                }

                string[] aylMailTo = null;
                if (!string.IsNullOrEmpty(MailTo))
                {
                    aylMailTo = MailTo.Split(new char[] { ';' });
                    for (int intRow = 0; intRow <= aylMailTo.Length - 1; intRow++)
                    {
                        if (!string.IsNullOrEmpty(aylMailTo[intRow].Trim()))
                        {
                            message.To.Add(aylMailTo[intRow].Trim());
                        }
                    }
                }

                objSMTP.Send(message);
                blnReturn = true;
            }
            catch (Exception ex)
            {
                blnReturn = false;
                //Kevin(20090218) 顯示較易辨別的過誤訊息至前端
                throw new ApplicationException("FlowSendMail Error:" + ex.Message);
            }
        }
        return blnReturn;
    }


    public void InsertDataToMailQueue(string MailFrom, string MailTo, string MailCC, string MailSubject, string MailBody)
    {
        string strSQL = "";
        OracleCommand cmdDB = new OracleCommand();
        string strSEQ = "";
        //IDbTransaction tx = null;
        OracleTransaction tx = null;

        try
        {
            this.OpenDB();
            tx = connDB.BeginTransaction();

            //取得 SEQUENCE
            strSQL = "SELECT SENDMAIL_SEQ.NEXTVAL FROM DUAL";
            cmdDB = new OracleCommand(strSQL, connDB, tx);
            strSEQ = Convert.ToString(cmdDB.ExecuteScalar());

            //新增 SENDMAIL_QUEUE
            strSQL = "INSERT INTO SENDMAIL_QUEUE ";
            strSQL += " (MODULE_NME, MAIL_ID, MAIL_FROM, MAIL_TO,MAIL_CC, MAIL_SUBJECT, MAIL_BODY, UPDDT)";
            strSQL += " VALUES";
            strSQL += " ('FLOW', " + strSEQ + ", '" + MailFrom + "', '" + MailTo + "', '" + MailCC + "', '" + MailSubject + "', EMPTY_CLOB(), SYSDATE)";
            cmdDB = new OracleCommand(strSQL, connDB, tx);
            cmdDB.ExecuteNonQuery();

            //更新 SENDMAIL_QUEUE CLOB 資料
            strSQL = "SELECT MAIL_BODY FROM SENDMAIL_QUEUE WHERE MAIL_ID = '" + strSEQ + "' FOR UPDATE ";
            cmdDB.CommandText = strSQL;
            cmdDB.Parameters.Clear();
            cmdDB.CommandTimeout = 300;
            OracleLob clob = default(OracleLob);
            using (OracleDataReader objReader = cmdDB.ExecuteReader())
            {
                while (objReader.Read())
                {
                    clob = objReader.GetOracleLob(0);
                    byte[] arrValue = System.Text.Encoding.Unicode.GetBytes(MailBody);
                    clob.Write(arrValue, 0, arrValue.Length);
                }
                objReader.Close();
                tx.Commit();
            }
        }
        catch (Exception ex)
        {
            tx.Rollback();
            throw new Exception( "InsertMailQueue失敗" + ex.Message );
        }
        finally
        {
            connDB.Close();
            connDB.Dispose();
        }
    }
   
   
    private bool OpenDB()
    {
        try
        {
            string connDBConnection = null;

            if ((connDB == null) | connDB.State == ConnectionState.Closed)
            {
                connDBConnection = System.Configuration.ConfigurationManager.ConnectionStrings["DBConn"].ConnectionString;
                connDB.ConnectionString = connDBConnection;
                connDB.Open();
            }
        }
        catch (Exception ex)
        {
            throw new Exception( "資料庫開啟失敗" + ex.Message );
        }
        return true;
    }


    private XmlNode GetRootXMLNode(XmlDocument doc)
    {
        return doc.SelectNodes("/")[0].ChildNodes[1];
    }

    private XmlNode GetTargetNode(XmlDocument doc, int node1, int node2, int node3)
    {
        return GetRootXMLNode(doc).ChildNodes[node1].ChildNodes[node2].ChildNodes[node3];
    }


    private string GetExeResult(XmlDocument doc)
    {
        return GetTargetNode(doc, 0, 0, 0).InnerText;
    }

    private string GetRtnReason(XmlDocument doc)
    {
        return GetTargetNode(doc, 0, 0, 1).InnerText;
    }


    private string GetXmlServer()
    {
        return "https://webex.com/WBXService/xml8.0.0/XMLService";
    }


    private string Decrypt(string cipherText)
    {
        string EncryptionKey = DateTime.Now.ToString("yyyyMMdd") + "WEBEXMT";
        cipherText = cipherText.Replace(" ", "+");

        byte[] cipherBytes = Convert.FromBase64String(cipherText);

        using (Aes encryptor = Aes.Create())
        {
            Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });

            encryptor.Key = pdb.GetBytes(32);
            encryptor.IV = pdb.GetBytes(16);

            using (MemoryStream ms = new MemoryStream())
            {
                using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(cipherBytes, 0, cipherBytes.Length);
                    cs.Close();
                }
                cipherText = Encoding.Unicode.GetString(ms.ToArray());
            }
        }
        return cipherText;
    }


    private string AuthValidKey()
    {
        char[] charArray = DateTime.Now.AddYears(Convert.ToInt32(DateTime.Now.DayOfWeek)).AddMonths(-Convert.ToInt32(DateTime.Now.DayOfWeek)).AddDays(Convert.ToInt32(DateTime.Now.DayOfWeek))
            .ToString("yyyyMMdd").ToCharArray();
        Array.Reverse(charArray);
        return (Convert.ToInt32(new string(charArray)) * Convert.ToInt32(DateTime.Now.DayOfWeek)).ToString();
    }


    private string ClearString(string source)
    {
        if (source.StartsWith(";"))
        {
            source = source.Substring(1);
        }
        if (source.EndsWith(";"))
        {
            source = source.Substring(0, source.Length - 1);
        }
        return source;
    }

    private void GetIdPass(string key)
    {
        id = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["Webexid" + key]);
        pwd = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["Webexpwd" + key]);
    }

}