Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,037

HOME > .NET Framework > Forum > สอบถามเกี่ยวกับการทำปฏิทินครับ คลิกดูว่าแต่ละวันมีกิจกรรมอะไรบ้าง



 

สอบถามเกี่ยวกับการทำปฏิทินครับ คลิกดูว่าแต่ละวันมีกิจกรรมอะไรบ้าง

 



Topic : 101405



โพสกระทู้ ( 312 )
บทความ ( 0 )



สถานะออฟไลน์




calendar

จะทำปฏิทินลักษณะตามภาพครับ
แล้วต้องการแบบว่าคลิกวันที่แล้วให้ดึงข้อมูลจาก DB มาโชว์ในช่องฝั่งขวามืออ่ะครับ

มีโค้ดหรือเครื่องมือตัวไหนที่พอจะทำได้บ้างครับ แล้วสร้างปฏิทินนี่ต้องใช้เครื่องมือตัวไหนทำ
รบกวนผู้รู้ด้วยครับ ขอบคุณครับ



Tag : .NET, Ms SQL Server 2008, VB.NET







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-10-07 15:37:25 By : Nr_Tom View : 1283 Reply : 21
 

 

No. 1

Guest


ใช้ datetime

หา days in month

หา first day of month

จะสร้างปฏิทิน ก็ mod 7

ตอนวนลูปก็ ckeck กับ database ว่าวันไหนมี activity ก็ให้เป็นสีๆ

ง่ายๆ ลองทำดู






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-07 16:35:31 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 2



โพสกระทู้ ( 312 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : ห้ามตอบเกินวันละ 2 กระทู้ เมื่อวันที่ 2013-10-07 16:35:31
รายละเอียดของการตอบ ::
พอจะมี code ตัวอย่างมั้ยครับ?

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-07 16:41:12 By : Nr_Tom
 

 

No. 3

Guest


ส่วน admin ไว้ป้อน activity

EventCalendar.aspx
<%@ Page Title="Manage Event Calendar" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="EventCalendar.aspx.cs" Inherits="Calendar_EventCalendar" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    <script src="../Scripts/jquery.balloon.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <h2>
        Event Calendar Management
    </h2>
    <p>
        To manage event calendar section of <a href="http://172.19.9.102" title="Intranet">intranet web application</a>.
    </p>
    <br />
    <ajaxToolkit:TabContainer ID="TabContainer1" CssClass="CustomTabStyle" runat="server" OnDemand="true">

    </ajaxToolkit:TabContainer>
</asp:Content>


EventCalendar.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Web.Security;
using AjaxControlToolkit;

public partial class Calendar_EventCalendar : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!RolesManage.IsUserInRoles(User.Identity.Name, RolesManage.GetRole(EnumRoleType.Calendar)))
        {
            Response.Redirect("~/");
        }
        else
        {
            Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

            var roles = from ur in Roles.GetRolesForUser(User.Identity.Name)
                        join r in intranet2012.RoleTable on ur.ToString() equals r.ID.ToString("00")
                        where r.TypeID == (int)EnumRoleType.Calendar
                        select r;

            foreach (var role in roles)
            {
                TabPanel newPanel = new TabPanel();
                newPanel.HeaderText = role.RoleName;

                switch (role.ID)
                {
                    case 11:
                        UserControl calendar = (UserControl)Page.LoadControl("~/Calendar/Calendar.ascx");
                        newPanel.Controls.Add(calendar);
                        break;
                    default:
                        newPanel.Controls.Add(new LiteralControl(role.ID.ToString()));
                        break;
                }

                TabContainer1.Tabs.Add(newPanel);
            }
        }
    }
}

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-08 08:17:12 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 4

Guest


Calendar.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Calendar.ascx.cs" Inherits="Calendar_Calendar" %>

<script type="text/javascript">
    function uploadError(sender, args) {
        document.getElementById("<%= LabelFileName.ClientID %>").innerHTML = "<span style='color:red;'>" + args.get_errorMessage() + "</span>";
    }

    function uploadComplete(sender, args) {
        if (args.get_length() > 1024 * 1024 * 10) {
            // it will raise the OnClientUploadError event
            sender._onError('File size should not be greater than 10MB.');

            return;
        }

        try {
            var fileExtension = args.get_fileName();

            if (fileExtension.indexOf('.xlsx') == -1) {
                sender._onError('File extension not supported. (Excel 2007 (.xlsx) only.)');

                return;
            }
        }
        catch (e) { 
            // alert(e.message);
        }
    }
</script>

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
        <div id="calendar">
            <div id="calendar_left">
                <asp:Table ID="Table1" CssClass="CalendarBody" runat="server">
                    <asp:TableRow>
                        <asp:TableCell CssClass="CalendarMonth" HorizontalAlign="Center" VerticalAlign="Middle">
                            <customControl:RollOverImageButton ID="RollOverImageButton1"
                                ImageUrl="~/images/arrow-left.png" RollOverImageUrl="~/images/arrow-left-over.png"
                                OnClick="RollOverImageButton1_Click" ToolTip="Back" runat="server" />
                        </asp:TableCell>
                        <asp:TableCell CssClass="CalendarMonth" ColumnSpan="5" HorizontalAlign="Center" VerticalAlign="Middle">
                            <asp:Label ID="LabelMonthName" runat="server" Text="Label"></asp:Label>
                        </asp:TableCell>
                        <asp:TableCell CssClass="CalendarMonth" HorizontalAlign="Center" VerticalAlign="Middle">
                            <customControl:RollOverImageButton ID="RollOverImageButton2"
                                ImageUrl="~/images/arrow-right.png" RollOverImageUrl="~/images/arrow-right-over.png"
                                OnClick="RollOverImageButton2_Click" ToolTip="Next" runat="server" />                            
                        </asp:TableCell>
                    </asp:TableRow>
                </asp:Table>

                <asp:Button ID="ButtonHidden1" runat="server" Text="Button" style="display: none;" />
                <ajaxToolkit:ModalPopupExtender runat="server" ID="ModalPopupExtender1"
                    TargetControlID="ButtonHidden1" PopupControlID="PanelPopup1" CancelControlID="ImageButtonClose1"
                    BackgroundCssClass="modalBackground" DropShadow="True"
                    RepositionMode="RepositionOnWindowScroll">
                </ajaxToolkit:ModalPopupExtender>
                <asp:Panel ID="PanelPopup1" CssClass="modalPopup" style="display: none;" runat="server">
                    <asp:Panel ID="PanelClose" CssClass="close" runat="server">
                        <asp:ImageButton ID="ImageButtonClose1" ImageUrl="~/images/close.png" ToolTip="Close" runat="server" CausesValidation="false" />
                    </asp:Panel>
                    <asp:Panel ID="PanelContent1" CssClass="importpublicholidays" runat="server">
                        <fieldset class="login">
                            <legend>
                                <table style="margin: 0 auto;">
                                    <tr>
                                        <td><asp:Panel ID="Panel10" runat="server" style="width: 10px; height: 10px; background-color: Red;"></asp:Panel></td>
                                        <td><asp:Label ID="Label4" runat="server" Text="Import Public Holidays"></asp:Label></td>
                                    </tr>
                                </table> 
                            </legend>
                            <p>
                                <asp:Label ID="LabelTemplate" runat="server" Text="Template:"></asp:Label><br />
                                <asp:Image ID="ImageTemplate" ImageUrl="~/images/excel16x16.png" ImageAlign="AbsMiddle" runat="server" />
                                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Template/PublicHolidays.xlsx">PublicHolidays.xlsx</asp:HyperLink>
                                <asp:Image ID="ImageFileExample" ImageUrl="~/images/excel16x16.png" ImageAlign="AbsMiddle" style="padding-left: 50px;" runat="server" />
                                <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/Template/ตัวอย่างการกรอกข้อมูลวันหยุดราชการ.xlsx">ตัวอย่างการกรอกข้อมูลวันหยุดราชการ.xlsx</asp:HyperLink>
                            </p>
                            <p>
                                <asp:Label ID="LabelExample" runat="server" Text="Example:"></asp:Label><br />
                                <asp:Image ID="ImageExample" ImageUrl="~/Template/template_example.png" style="padding-top: 5px;" runat="server" />
                            </p>
                            <p>
                                <asp:Label ID="LabelFile" runat="server" Text="Upload data:"></asp:Label><br />
                                <ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload1" runat="server" Style="padding-left: 10px;"
                                    UploadingBackColor="#CCFFFF" ThrobberID="myThrobber"
                                    OnClientUploadError="uploadError" OnClientUploadComplete="uploadComplete" />
                                <asp:Label ID="myThrobber" runat="server" Style="display: none;">
                                    <img style="vertical-align: middle;" alt="" src="uploading.gif" />
                                </asp:Label>
                                <asp:HiddenField ID="HiddenFieldFileName" runat="server" />
                                <asp:HiddenField ID="HiddenFieldContentType" runat="server" />
                                <asp:Label ID="LabelFileName" runat="server" Style="padding-left: 10px;"></asp:Label>
                                <asp:Label ID="LabelStatus" runat="server" Style="padding-left: 10px;"></asp:Label>
                            </p>
                        </fieldset>
                        <div style="overflow: auto; padding-right: 0px;">
                            <asp:Panel ID="PanelCommand1" CssClass="htmleditorButton" style="float: right;" runat="server">
                                <asp:Button ID="ButtonImport" runat="server" Text="Finish" OnClick="ButtonImport_Click" ValidationGroup="import" />
                            </asp:Panel>
                        </div>
                    </asp:Panel>
                </asp:Panel>

                <asp:Button ID="ButtonHidden2" runat="server" Text="Button" style="display: none;" />
                <ajaxToolkit:ModalPopupExtender runat="server" ID="ModalPopupExtender2"
                    TargetControlID="ButtonHidden2" PopupControlID="PanelPopup2" CancelControlID="ImageButtonClose2"
                    BackgroundCssClass="modalBackground" DropShadow="True"
                    RepositionMode="RepositionOnWindowScroll">
                </ajaxToolkit:ModalPopupExtender>
                <asp:HiddenField ID="HiddenFieldItemID" runat="server" />
                <asp:Panel ID="PanelPopup2" CssClass="modalPopup" style="display: none;" runat="server">
                    <asp:Panel ID="Panel8" CssClass="close" runat="server">
                        <asp:ImageButton ID="ImageButtonClose2" ImageUrl="~/images/close.png" ToolTip="Close" runat="server" CausesValidation="false" />
                    </asp:Panel>
                    <asp:Panel ID="PanelContent2" CssClass="addactivity" runat="server">
                        <fieldset class="login">
                            <legend>
                                <table style="margin: 0 auto;">
                                    <tr>
                                        <td><asp:Panel ID="PanelEvent" runat="server" style="width: 10px; height: 10px;"></asp:Panel></td>
                                        <td><asp:Label ID="LabelActivity" runat="server" Text="Label"></asp:Label></td>
                                    </tr>
                                </table> 
                            </legend>
                            <p>
                                <asp:HiddenField ID="HiddenFieldType" runat="server" />
                                <asp:Label ID="LabelSubject" runat="server" Text="Subject:"></asp:Label><br />
                                <asp:TextBox ID="TextBoxSubject" runat="server" ValidationGroup="activity" CssClass="textEntry"
                                    Style="width: 300px;" autocomplete="off"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBoxSubject"
                                    ValidationGroup="activity" ErrorMessage="Subject is required" CssClass="failureNotification"></asp:RequiredFieldValidator>
                            </p>
                            <p>
                                <table style="margin-left: 5px;">
                                    <tr>
                                        <td>
                                            <asp:Label ID="LabelStart" runat="server" Text="Start date:"></asp:Label><br />
                                            <asp:TextBox ID="TextBoxStart" runat="server" ValidationGroup="activity" CssClass="textEntry"
                                                Style="width: 100px;" autocomplete="off"></asp:TextBox>
                                            <asp:ImageButton runat="Server" ID="ImageCalendar1" ImageUrl="~/images/Calendar_scheduleHS.png"
                                                AlternateText="Click to show calendar" ImageAlign="AbsMiddle" /><br />
                                            <ajaxToolkit:CalendarExtender ID="CalendarExtender1" TargetControlID="TextBoxStart"
                                                PopupButtonID="ImageCalendar1" CssClass="calendarExtension" FirstDayOfWeek="Sunday" Format="dd/MM/yyyy" runat="server">
                                            </ajaxToolkit:CalendarExtender>   
                                        </td>
                                        <td style="padding-left: 30px;">
                                            <asp:Label ID="Label3" runat="server" Text="Time:"></asp:Label><br />
                                            <customControl:TimePicker ID="StartTime" runat="server" SelectedTimeFormat="TwentyFour" MinuteIncrement="30">
                                            </customControl:TimePicker>
                                        </td>
                                        <td style="vertical-align: bottom; padding-left: 30px;">
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBoxStart"
                                                ValidationGroup="activity" ErrorMessage="Start date is required" CssClass="failureNotification"></asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                </table>
                            </p>
                            <p>
                                <table style="margin-left: 5px;">
                                    <tr>
                                        <td>
                                            <asp:Label ID="LabelEnd" runat="server" Text="End date:"></asp:Label><br />
                                            <asp:TextBox ID="TextBoxEnd" runat="server" ValidationGroup="activity" CssClass="textEntry"
                                                Style="width: 100px;" autocomplete="off"></asp:TextBox>
                                            <asp:ImageButton runat="Server" ID="ImageCalendar2" ImageUrl="~/images/Calendar_scheduleHS.png"
                                                AlternateText="Click to show calendar" ImageAlign="AbsMiddle" /><br />
                                            <ajaxToolkit:CalendarExtender ID="CalendarExtender2" TargetControlID="TextBoxEnd"
                                                PopupButtonID="ImageCalendar2" CssClass="calendarExtension" FirstDayOfWeek="Sunday" Format="dd/MM/yyyy" runat="server">
                                            </ajaxToolkit:CalendarExtender>   
                                        </td>
                                        <td style="padding-left: 30px;">
                                            <asp:Label ID="Label5" runat="server" Text="Time:"></asp:Label><br />
                                            <customControl:TimePicker ID="EndTime" runat="server" SelectedTimeFormat="TwentyFour" MinuteIncrement="30">
                                            </customControl:TimePicker>
                                        </td>
                                        <td style="vertical-align: bottom; padding-left: 30px;">
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBoxEnd"
                                                ValidationGroup="activity" ErrorMessage="End date is required" CssClass="failureNotification"></asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                </table>
                            </p>
                            <p>
                                <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Start date is greater than end date." Type="Date"
                                    Operator="LessThanEqual" ControlToValidate="TextBoxStart" ControlToCompare="TextBoxEnd" ValidationGroup="activity" CssClass="failureNotification"></asp:CompareValidator>
                            </p>
                        </fieldset>
                        <div style="overflow: auto; padding-right: 0px;">
                            <asp:Panel ID="PanelCommand2" CssClass="htmleditorButton" style="float: right;" runat="server">
                                <asp:Button ID="ButtonSave" runat="server" Text="Save" OnClick="ButtonSave_Click" ValidationGroup="activity" />
                            </asp:Panel>
                        </div>
                    </asp:Panel>
                </asp:Panel>
            </div>
            <div id="calendar_right">
                <fieldset class="login" style="margin-top: 0px;">
                    <legend>Add Public Holidays</legend>
                    <div style="text-align: center;">
                        <table class="addevent">
                            <tr>
                                <td>
                                    <asp:Panel ID="Panel1" CssClass="newevent" runat="server">
                                        <asp:ImageButton ID="ImageButtonExcel" ImageUrl="~/images/excel_icon.png" 
                                            OnClick="ImageButtonExcel_Click" ToolTip="Import by Excel (.xlsx)" runat="server" />
                                    </asp:Panel>                        
                                </td>
                                <td>
                                    <asp:Panel ID="Panel2" CssClass="newevent" runat="server">
                                        <asp:ImageButton ID="ImageButtonManual" ImageUrl="~/images/manual_icon.png" 
                                            OnClick="ImageButtonManual_Click" ToolTip="Manual Add" runat="server" />
                                    </asp:Panel>                        
                        
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" style="padding: 0px;">
                                    <table style="margin: 0 auto;">
                                        <tr>
                                            <td><div id="pHolidays" style="width: 10px; height: 10px;"></div></td>
                                            <td><asp:Label ID="Label1" runat="server" Text="&nbsp;"></asp:Label></td>
                                        </tr>
                                    </table>                                       
                                </td>
                            </tr>
                        </table>
                    </div>
                </fieldset>


ยังมีต่อ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-08 08:20:24 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 5

Guest


ต่อ

Calendar.ascx
                <fieldset class="login">
                    <legend>Add Activity</legend>
                    <div style="text-align: center;">
                        <table class="addevent">
                            <tr>
                                <td>
                                    <asp:Panel ID="Panel3" CssClass="newevent" runat="server">
                                        <asp:ImageButton ID="ImageButtonEnergyEvent" ImageUrl="~/images/energy_icon.png" 
                                            OnClick="ImageButtonEnergyEvent_Click" ToolTip="Add MoEN Activity" runat="server" />
                                    </asp:Panel>
                                </td>
                                <td>
                                    <asp:Panel ID="Panel4" CssClass="newevent" runat="server">
                                        <asp:ImageButton ID="ImageButtonEvent" ImageUrl="~/images/activity_icon.png" 
                                            OnClick="ImageButtonEvent_Click" ToolTip="Add Activity" runat="server" />
                                    </asp:Panel>                        
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Panel ID="Panel5" CssClass="newevent" runat="server">
                                        <asp:ImageButton ID="ImageButtonMeeting" ImageUrl="~/images/meeting_icon.png" 
                                            OnClick="ImageButtonMeeting_Click" ToolTip="Add Meeting" runat="server" />
                                    </asp:Panel>  
                                </td>
                                <td>
                                    <asp:Panel ID="Panel6" CssClass="newevent" runat="server">
                                        <asp:ImageButton ID="ImageButtonTraining" ImageUrl="~/images/training_icon.png" 
                                            OnClick="ImageButtonTraining_Click" ToolTip="Add Training" runat="server" />
                                    </asp:Panel>  
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" style="padding: 0px;">
                                    <table style="margin: 0 auto;">
                                        <tr>
                                            <td><div id="activity" style="width: 10px; height: 10px;"></div></td>
                                            <td><asp:Label ID="Label2" runat="server" Text="&nbsp;"></asp:Label></td>
                                        </tr>
                                    </table>                                     
                                </td>
                            </tr>
                        </table>
                    </div>
                </fieldset>
            </div>
        </div>
        <br />

        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" 
            GridLines="None" AutoGenerateColumns="False" ShowHeaderWhenEmpty="True" 
            onrowdatabound="GridView1_RowDataBound" Width="100%" AllowPaging="True" PageSize="15"
            DataKeyNames="ID,TypeID" OnPageIndexChanging="GridView1_PageIndexChanging" 
            onrowcommand="GridView1_RowCommand">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:BoundField HeaderText="#">
                <HeaderStyle HorizontalAlign="Left" Width="5%" />
                <ItemStyle HorizontalAlign="Right" VerticalAlign="Top" />
                </asp:BoundField>
                <asp:BoundField DataField="ActivityName" HeaderText="Activity">
                <HeaderStyle HorizontalAlign="Left" Width="50%" />
                <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" />
                </asp:BoundField>
                <asp:BoundField DataField="StartDate" HeaderText="Start">
                <HeaderStyle HorizontalAlign="Left" Width="20%" />
                <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" />
                </asp:BoundField>
                <asp:BoundField DataField="EndDate" HeaderText="End">
                <HeaderStyle HorizontalAlign="Left" Width="20%" VerticalAlign="Top" />
                <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" />
                </asp:BoundField>
                <asp:TemplateField HeaderText=" ">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:ImageButton ID="ImageButtonEdit" runat="server" CommandName="EditItem"
                            ImageUrl="~/images/edit_icon.png" ToolTip="Edit" />
                    </ItemTemplate>
                    <HeaderStyle Width="3%" />
                    <ItemStyle VerticalAlign="Top" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText=" ">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:ImageButton ID="ImageButtonDelete" runat="server" CommandName="DeleteItem"
                            ImageUrl="~/images/delete_icon.gif" ToolTip="Delete" />
                    </ItemTemplate>
                    <HeaderStyle Width="2%" />
                    <ItemStyle VerticalAlign="Top" />
                </asp:TemplateField>
            </Columns>
            <EditRowStyle BackColor="#2461BF" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#507CD1" ForeColor="White"  HorizontalAlign="Left" CssClass="g_pagination" />
            <PagerSettings Mode="NumericFirstLast" PageButtonCount="8" FirstPageText="First" LastPageText="Last"/>
            <RowStyle BackColor="#EFF3FB" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#F5F7FB" />
            <SortedAscendingHeaderStyle BackColor="#6D95E1" />
            <SortedDescendingCellStyle BackColor="#E9EBEF" />
            <SortedDescendingHeaderStyle BackColor="#4870BE" />
        </asp:GridView>

    </ContentTemplate>
</asp:UpdatePanel>

<asp:UpdatePanel ID="UpdatePanel2" runat="server" OnLoad="UpdatePanel2_Load">
    <ContentTemplate>
        <asp:Button ID="ButtonHidden3" runat="server" Text="Button" style="display: none;" />
        <ajaxToolkit:ModalPopupExtender runat="server" ID="ModalPopupExtender3"
            TargetControlID="ButtonHidden3" PopupControlID="PanelPopup3" CancelControlID="ImageButtonClose3"
            BackgroundCssClass="modalBackground" DropShadow="True"
            RepositionMode="RepositionOnWindowScroll">
        </ajaxToolkit:ModalPopupExtender>
        <asp:Panel ID="PanelPopup3" CssClass="modalPopup" style="display: none;" runat="server">
            <asp:Panel ID="Panel9" CssClass="close" runat="server">
                <asp:ImageButton ID="ImageButtonClose3" ImageUrl="~/images/close.png" ToolTip="Close" runat="server" CausesValidation="false" />
            </asp:Panel>
            <asp:Panel ID="Panel7" CssClass="calendar_detail" runat="server">
                <asp:Panel ID="PanelEventHead" CssClass="event_head" runat="server">
                    <asp:Table ID="Table2" CssClass="table_name" runat="server">
                        <asp:TableRow ID="TableRow1" runat="server">
                            <asp:TableCell ID="CellTitle" CssClass="cell_name" runat="server">
                                <asp:Label ID="LabelTitle" runat="server" Text="Label"></asp:Label>
                            </asp:TableCell>
                        </asp:TableRow>
                    </asp:Table>
                </asp:Panel>
                <asp:Panel ID="PanelEventDetail" CssClass="event_detail" runat="server">
                    <asp:Table ID="TableDetail" CssClass="table_detail" BorderStyle="Solid" BorderWidth="1" runat="server">
                    </asp:Table>
                </asp:Panel>
            </asp:Panel>
        </asp:Panel>
    </ContentTemplate>
</asp:UpdatePanel>

<asp:UpdateProgress ID="UpdateProgress1" runat="server">
    <ProgressTemplate>
        <div class="loading"></div>        
    </ProgressTemplate>
</asp:UpdateProgress>  

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-08 08:21:09 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 6

Guest


Calendar.asmx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.IO;
using System.Text;
using AjaxControlToolkit;

public partial class Calendar_Calendar : System.Web.UI.UserControl
{
    private string savePath;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (ViewState["date"] == null)
        {
            ViewState["date"] = DateTime.Now;

            Calendar((DateTime)ViewState["date"]);
        }

        PrepareIcon();

        AsyncFileUpload1.UploadedComplete += new EventHandler<AsyncFileUploadEventArgs>(AsyncFileUpload1_UploadedComplete);
    }

    protected void AsyncFileUpload1_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
    {
        if (AsyncFileUpload1.FileBytes.Length <= 1024 * 1024 * 10)
        {
            if (Path.GetExtension(e.FileName).Contains(".xlsx"))
            {
                // Uncomment to save to AsyncFileUpload\Uploads folder.
                // ASP.NET must have the necessary permissions to write to the file system.

                savePath = Server.MapPath(string.Format("~/Template/[{0}]{1}", DateTime.Now.ToString("yyyyMMddHHmmss"), Path.GetFileName(e.FileName)));
                AsyncFileUpload1.SaveAs(savePath);

                ImportHolidays holidays = new ImportHolidays(savePath);

                if (holidays.HaveSheet())
                {
                    if (holidays.CheckFormat())
                    {
                        if (holidays.Import())
                        {
                            StringBuilder Sb = new StringBuilder();
                            Sb.AppendLine("top.$get(\"" + LabelStatus.ClientID + "\").innerHTML = '[Import Success]';");
                            Sb.AppendLine("top.$get(\"" + LabelFileName.ClientID + "\").innerHTML = 'Uploaded file name: <span style=\"color: blue;\">" + AsyncFileUpload1.FileName + "</span>';");
                            Sb.AppendLine("top.$get(\"" + HiddenFieldFileName.ClientID + "\").value = '" + AsyncFileUpload1.FileName + "';");
                            Sb.AppendLine("top.$get(\"" + HiddenFieldContentType.ClientID + "\").value = '" + AsyncFileUpload1.ContentType + "';");
                            Sb.AppendLine("top.$get(\"" + ButtonImport.ClientID + "\").disabled = false;");

                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", Sb.ToString(), true);
                        }
                        else
                        {
                            StringBuilder Sb = new StringBuilder();
                            Sb.AppendLine("top.$get(\"" + LabelStatus.ClientID + "\").innerHTML = '[Import Error]';");
                            Sb.AppendLine("var AsyncFileUpload = top.$get(\"" + AsyncFileUpload1.ClientID + "\");");
                            Sb.AppendLine("var txts = AsyncFileUpload.getElementsByTagName(\"input\");");
                            Sb.AppendLine("for (var i = 0; i < txts.length; i++) {");
                            Sb.AppendLine("if (txts[i].type == \"file\") {");
                            Sb.AppendLine("txts[i].value = \"\";");
                            Sb.AppendLine("}");
                            Sb.AppendLine("}");

                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "import", Sb.ToString(), true);                              
                        }
                    }
                    else
                    {
                        StringBuilder Sb = new StringBuilder();
                        Sb.AppendLine("top.$get(\"" + LabelStatus.ClientID + "\").innerHTML = '[Header Column Error]';");
                        Sb.AppendLine("var AsyncFileUpload = top.$get(\"" + AsyncFileUpload1.ClientID + "\");");
                        Sb.AppendLine("var txts = AsyncFileUpload.getElementsByTagName(\"input\");");
                        Sb.AppendLine("for (var i = 0; i < txts.length; i++) {");
                        Sb.AppendLine("if (txts[i].type == \"file\") {");
                        Sb.AppendLine("txts[i].value = \"\";");
                        Sb.AppendLine("}");
                        Sb.AppendLine("}");

                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "column", Sb.ToString(), true);                     
                    }
                }
                else
                {
                    StringBuilder Sb = new StringBuilder();
                    Sb.AppendLine("top.$get(\"" + LabelStatus.ClientID + "\").innerHTML = '[Sheet Name Error]';");
                    Sb.AppendLine("var AsyncFileUpload = top.$get(\"" + AsyncFileUpload1.ClientID + "\");");
                    Sb.AppendLine("var txts = AsyncFileUpload.getElementsByTagName(\"input\");");
                    Sb.AppendLine("for (var i = 0; i < txts.length; i++) {");
                    Sb.AppendLine("if (txts[i].type == \"file\") {");
                    Sb.AppendLine("txts[i].value = \"\";");
                    Sb.AppendLine("}");
                    Sb.AppendLine("}");

                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "sheet", Sb.ToString(), true);               
                }
            }
            else
            {
                StringBuilder Sb = new StringBuilder();
                Sb.AppendLine("var AsyncFileUpload = top.$get(\"" + AsyncFileUpload1.ClientID + "\");");
                Sb.AppendLine("var txts = AsyncFileUpload.getElementsByTagName(\"input\");");
                Sb.AppendLine("for (var i = 0; i < txts.length; i++) {");
                Sb.AppendLine("if (txts[i].type == \"file\") {");
                Sb.AppendLine("txts[i].value = \"\";");
                Sb.AppendLine("}");
                Sb.AppendLine("}");

                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "extension", Sb.ToString(), true);            
            }
        }
        else
        {
            StringBuilder Sb = new StringBuilder();
            Sb.AppendLine("var AsyncFileUpload = top.$get(\"" + AsyncFileUpload1.ClientID + "\");");
            Sb.AppendLine("var txts = AsyncFileUpload.getElementsByTagName(\"input\");");
            Sb.AppendLine("for (var i = 0; i < txts.length; i++) {");
            Sb.AppendLine("if (txts[i].type == \"file\") {");
            Sb.AppendLine("txts[i].value = \"\";");
            Sb.AppendLine("}");
            Sb.AppendLine("}");

            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "size", Sb.ToString(), true);
        }
    }

    protected void RollOverImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        DateTime currentDate = (DateTime)ViewState["date"];
        ViewState["date"] = currentDate.AddMonths(-1);

        Calendar((DateTime)ViewState["date"]);
    }

    protected void RollOverImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        DateTime currentDate = (DateTime)ViewState["date"];
        ViewState["date"] = currentDate.AddMonths(1);

        Calendar((DateTime)ViewState["date"]);
    }

    protected void Calendar(DateTime date)
    {
        LabelMonthName.Text = date.ToString("MMMM yyyy", new System.Globalization.CultureInfo("en-GB"));

        int daysInMonth = DateTime.DaysInMonth(date.Year, date.Month);
        int fristDayOfWeek = (int)DateTime.ParseExact(string.Format("1/{0}/{1}", date.Month.ToString(), date.Year.ToString()), "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture).DayOfWeek;
        int lastDayOfWeek = (int)DateTime.ParseExact(string.Format("{0}/{1}/{2}", daysInMonth.ToString(), date.Month.ToString(), date.Year.ToString()), "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture).DayOfWeek;
        int loopDays = daysInMonth + fristDayOfWeek + (7 - lastDayOfWeek);

        foreach (TableRow Tbr in Table1.Rows)
        {
            if (Table1.Rows.GetRowIndex(Tbr) != 0)
                Table1.Rows.Remove(Tbr);
        }

        TableRow Trh = new TableRow();
        Table1.Rows.Add(Trh);

        foreach (string str in new string[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" })
        {
            TableCell Tch = new TableCell();
            Trh.Cells.Add(Tch);
            Tch.CssClass = "CalendarHead";
            Tch.Text = str;
        }

        for (int i = 0; i < loopDays / 7; i++)
        {
            TableRow Tr = new TableRow();
            Table1.Rows.Add(Tr);

            for (int j = 0; j < 7; j++)
            {
                int printDay = j + (7 * i) - (fristDayOfWeek - 1);

                TableCell Tc = new TableCell();
                Tr.Cells.Add(Tc);

                if (printDay < 1 || printDay > daysInMonth)
                {
                    Tc.CssClass = "CalendarCell";
                }
                else
                {
                    DateTime aDate = DateTime.ParseExact(string.Format("{0}/{1}/{2}", (j + (7 * i) - (fristDayOfWeek - 1)).ToString(), date.Month.ToString(), date.Year.ToString()), "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture);

                    StringBuilder Sb = new StringBuilder();
                    Sb.AppendLine("<table style=\"width: 100%; height:100%; border-collapse: collapse;\">");
                    Sb.Append("<tr style=\"height: 20%;\">");
                    Sb.AppendLine("<td>");
                    Sb.AppendLine("<div>");
                    Sb.AppendFormat("<div class={0} style=\"float: left;\">{1}</div>", (DateTime.Now.ToShortDateString() == aDate.ToShortDateString()) ? "CalendarToday" : "CalendarDate", (j + (7 * i) - (fristDayOfWeek - 1)).ToString());

                    if (HaveHolidays(aDate))
                    {
                        Sb.AppendFormat("<div class=\"activitypanel1{0}\" style=\"width: 10px; height: 10px; float: right; margin-top: 5px; background-color: red;\"></div>", aDate.ToString("ddMMyy"));

                        AddBalloon(1, aDate);
                    }

                    Sb.AppendLine("</div>");
                    Sb.AppendLine("</td>");
                    Sb.AppendLine("</tr>");
                    Sb.AppendLine("<tr style=\"height: 40%;\">");
                    Sb.AppendLine("<td><div style=\"width: 10px; height: 10px;\"></div></td>");
                    Sb.AppendLine("</tr>");
                    Sb.AppendLine("<tr style=\"height: 20%;\">");
                    Sb.AppendLine("<td>");
                    Sb.AppendLine("<div>");

                    if (HaveMoENActivity(aDate))
                    {
                        Sb.AppendFormat("<div class=\"activitypanel2{0}\" style=\"width: 10px; height: 10px; float: left; margin-left: 6px; background-color: orange\"></div>", aDate.ToString("ddMMyy"));
                    
                        AddBalloon(2, aDate);
                    }

                    if (HaveActivity(aDate))
                    {
                        Sb.AppendFormat("<div class=\"activitypanel3{0}\" style=\"width: 10px; height: 10px; float: left; margin-left: 6px; background-color: green\"></div>", aDate.ToString("ddMMyy"));
                    
                        AddBalloon(3, aDate);
                    }

                    if (HaveMeeting(aDate))
                    {
                        Sb.AppendFormat("<div class=\"activitypanel4{0}\" style=\"width: 10px; height: 10px; float: left; margin-left: 6px; background-color: #0066cc\"></div>", aDate.ToString("ddMMyy"));
                    
                        AddBalloon(4, aDate);
                    }

                    if (HaveTraining(aDate))
                    {
                        Sb.AppendFormat("<div class=\"activitypanel5{0}\" style=\"width: 10px; height: 10px; float: left; margin-left: 6px; background-color: #f06eaa\"></div>", aDate.ToString("ddMMyy"));

                        AddBalloon(5, aDate);
                    }

                    Sb.AppendLine("</div>");
                    Sb.AppendLine("</td>");
                    Sb.AppendLine("</tr>");
                    Sb.AppendLine("</table>");

                    Panel CalendarDate = new Panel();
                    CalendarDate.CssClass = "daypanel";
                    CalendarDate.Controls.Add(new LiteralControl(Sb.ToString()));

                    Tc.CssClass = (j == 0 || j == 6) ? "CalendarCellHolliday" : "CalendarCellNormal";
                    Tc.Controls.Add(CalendarDate);

                    if (HaveHolidays(aDate) || HaveMoENActivity(aDate) || HaveActivity(aDate) || HaveMeeting(aDate) || HaveTraining(aDate))
                        Tc.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(UpdatePanel2, aDate.ToShortDateString()));
                }
            }
        }

        BindGridView(date);
    }


ยังมีต่อ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-08 08:24:20 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 7

Guest


ต่อ

Calendar.ascx.cs
    protected void UpdatePanel2_Load(object sender, EventArgs e)
    {
        string sEventArguments = this.Request.Params["__EVENTARGUMENT"];

        if (!String.IsNullOrEmpty(sEventArguments))
        {
            DateTime aDate;

            if (DateTime.TryParse(sEventArguments, out aDate))
            {
                if (aDate.CompareTo(DateTime.Now.Date) == 0)
                {
                    if (HaveHolidays(aDate))
                    {
                        string holidaysList = string.Empty;

                        foreach (DataRow Dr in GetHolidays(aDate).Rows)
                        {
                            holidaysList += string.Format("{0}, ", Dr["ActivityName"].ToString());
                        }

                        LabelTitle.Text = string.Format("Today is {0} - {1}", aDate.ToString("\tdddd MMMM, d yyyy\t", new System.Globalization.CultureInfo("en-GB")), holidaysList.Substring(0, holidaysList.Length - 2));
                    }
                    else
                    {
                        LabelTitle.Text = string.Format("Today is {0}", aDate.ToString("\tdddd MMMM, d yyyy\t", new System.Globalization.CultureInfo("en-GB")));
                    }
                }
                else
                {
                    if (HaveHolidays(aDate))
                    {
                        string holidaysList = string.Empty;

                        foreach (DataRow Dr in GetHolidays(aDate).Rows)
                        {
                            holidaysList += string.Format("{0}, ", Dr["ActivityName"].ToString());
                        }

                        LabelTitle.Text = string.Format("{0} - <span style=\"color: red;\">[{1}]</span>", aDate.ToString("dddd MMMM, d yyyy", new System.Globalization.CultureInfo("en-GB")), holidaysList.Substring(0, holidaysList.Length - 2));
                    }
                    else
                    {
                        LabelTitle.Text = aDate.ToString("dddd MMMM, d yyyy", new System.Globalization.CultureInfo("en-GB"));
                    }                
                }
            }

            foreach (string timeName in new string[] { "8.00", "9.00", "10.00", "11.00", "12.00", "13.00", "14.00", "15.00", "16.00" })
            {
                TableRow Tr1 = new TableRow();
                TableDetail.Rows.Add(Tr1);

                TableCell TcName = new TableCell();
                TcName.RowSpan = 2;
                TcName.CssClass = "row_head";
                Tr1.Cells.Add(TcName);

                Table TableName = new Table();
                TableName.Width = Unit.Parse("100%");
                TableName.Height = Unit.Parse(string.Format("{0}px", (600 / 12 - 1).ToString()));
                TableName.Style.Add(HtmlTextWriterStyle.BorderCollapse, "collapse");
                TcName.Controls.Add(TableName);

                TableRow TrName = new TableRow();
                TableName.Rows.Add(TrName);

                TableCell Name = new TableCell();
                Name.CssClass = "cell_name";
                Name.Text = timeName;
                TrName.Cells.Add(Name);

                TableCell Tc1 = new TableCell();
                Tc1.Width = Unit.Parse("90%");
                Tc1.CssClass = "row_alt";
                Tc1.Height = Unit.Parse(string.Format("{0}px", ((600 / 12 - 1) / 2).ToString()));
                Tr1.Cells.Add(Tc1);

                TableRow Tr2 = new TableRow();
                TableDetail.Rows.Add(Tr2);

                TableCell Tc2 = new TableCell();
                Tc2.Height = Unit.Parse(string.Format("{0}px", ((600 / 12 - 1) / 2).ToString()));
                Tr2.Cells.Add(Tc2);
            }

            Panel PanelActivity = new Panel();
            PanelActivity.CssClass = "panel_activity";
            PanelEventDetail.Controls.Add(PanelActivity);

            int i = 0;
            string[] color = new string[] { "red", "orange", "green", "#0066cc", "#f06eaa" };

            foreach (DataRow Dr in GetAllActivity(aDate).Rows)
            {
                int top = GetTop((DateTime)Dr["StartDate"], aDate);
                int height = GetHeight((DateTime)Dr["EndDate"], aDate, top);

                Panel aPanel = new Panel();
                aPanel.CssClass = "panel_detail";
                aPanel.Height = Unit.Parse(string.Format("{0}px", height.ToString()));
                aPanel.Style.Add(HtmlTextWriterStyle.Top, string.Format("{0}px", top.ToString()));
                aPanel.Style.Add(HtmlTextWriterStyle.Left, string.Format("{0}px", (i * 150 + (i + 1) * 2 + i + i).ToString()));
                aPanel.Style.Add(HtmlTextWriterStyle.BackgroundColor, color[(int)Dr["TypeID"] - 1]);
                aPanel.Controls.Add(new LiteralControl(string.Format("<span style=\"color: white; font-weight: bold;\" title=\"{0} [{1}]\">{0}</span><br /><span style=\"color: white;\">[{1}]</span>", Dr["ActivityName"].ToString(), GetTime(top, height).ToString())));
                PanelActivity.Controls.Add(aPanel);

                i++;
            }

            ModalPopupExtender3.Show();
        }
    }
    
    protected void AddBalloon(int ActivityType, DateTime date)
    {
        ClientScriptManager clientScript = Page.ClientScript;
        string scriptName = string.Format("activitypanel{0}{1}", ActivityType.ToString(), date.ToString("ddMMyy"));

        if (!clientScript.IsStartupScriptRegistered(this.GetType(), scriptName))
        {
            Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

            var activity = from a in intranet2012.Activity
                           where a.TypeID == ActivityType && (a.StartDate.Date.CompareTo(date) <= 0 && a.EndDate.Date.CompareTo(date) >= 0)
                           orderby a.StartDate, a.EndDate ascending
                           select a;

            string activityType = (from t in intranet2012.ActivityType
                                   where t.ID == ActivityType
                                   select t.TypeName).First();

            string[] color = new string[] { "red", "orange", "green", "#0066cc", "#f06eaa" };

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.AppendLine("$(function() {");
            stringBuilder.AppendFormat("$(\".activitypanel{0}{1}\").each(function()", ActivityType.ToString(), date.ToString("ddMMyy"));
            stringBuilder.Append("{ $(this).balloon({ contents: \"");
            stringBuilder.AppendFormat("<span style='margin: 10px 0px 0px 10px; font-weight: bold; color: {0}'>{1}</span><br />", color[ActivityType - 1], activityType);
            stringBuilder.Append("<ul class='activitylist'>");

            foreach (TableActivity a in activity)
            {
                string duration;

                if (a.StartDate.Date.CompareTo(a.EndDate.Date) == 0 && a.StartDate.TimeOfDay == new TimeSpan(8, 30, 0) && a.EndDate.TimeOfDay == new TimeSpan(16, 30, 0))
                {
                    duration = "[เต็มวัน]";                
                }
                else if (a.StartDate.Date.CompareTo(a.EndDate.Date) != 0)
                {
                    duration = string.Format("[{0} - {1}]", a.StartDate.ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH")), a.EndDate.ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH")));
                }
                else
                {
                    duration = string.Format("[{0}น. - {1}น.]", a.StartDate.ToString("HH:mm"), a.EndDate.ToString("HH:mm"));
                }

                stringBuilder.AppendFormat("<li>{0} {1}</li>", a.ActivityName, duration);              
            }

            stringBuilder.Append("</ul>\", position: \"bottom\" }); });");
            stringBuilder.AppendLine("});");

            ScriptManager.RegisterStartupScript(Page, this.GetType(), scriptName, stringBuilder.ToString(), true);
        }
    }

    protected void BindGridView(DateTime date)
    {
        GridView1.DataSource = GetActivity(date);
        GridView1.DataBind();
    }

    protected DataTable GetActivity(DateTime date)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        var activity = (from a in intranet2012.Activity
                        where (a.StartDate.Year == date.Year && a.StartDate.Month == date.Month) || (a.EndDate.Year == date.Year && a.EndDate.Month == date.Month)
                        orderby a.StartDate ascending
                        select a).ToList();

        return Intranet2012Datebase.LINQToDataTable(activity);
    }

    protected void ButtonImport_Click(object sender, EventArgs e)
    {
        Calendar((DateTime)ViewState["date"]);
    }

    protected void ButtonSave_Click(object sender, EventArgs e)
    {
        DateTime startDate;
        DateTime endDate;

        TimeSpan startTime;
        TimeSpan endTime;

        if (StartTime.Value.CompareTo(new TimeSpan(8, 30, 0)) < 0)
            startTime = new TimeSpan(8, 30, 0);
        else if (StartTime.Value.CompareTo(new TimeSpan(16, 30, 0)) > 0)
            startTime = new TimeSpan(16, 30, 0);
        else
            startTime = StartTime.Value;

        if (EndTime.Value.CompareTo(new TimeSpan(8, 30, 0)) < 0)
            endTime = new TimeSpan(8, 30, 0);
        else if (EndTime.Value.CompareTo(new TimeSpan(16, 30, 0)) > 0)
            endTime = new TimeSpan(16, 30, 0);
        else
            endTime = EndTime.Value;

        startDate = Convert.ToDateTime(TextBoxStart.Text, new System.Globalization.CultureInfo("en-GB")).Add(startTime);
        endDate = Convert.ToDateTime(TextBoxEnd.Text, new System.Globalization.CultureInfo("en-GB")).Add(endTime);

        if (startDate.CompareTo(endDate) < 0)
        {
            Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

            if (HiddenFieldItemID.Value == string.Empty)
            {
                TableActivity activity = new TableActivity();
                activity.TypeID = Convert.ToInt32(HiddenFieldType.Value);
                activity.ActivityName = TextBoxSubject.Text;
                activity.StartDate = startDate;
                activity.EndDate = endDate;

                if (!ItemExist(activity))
                {
                    intranet2012.Activity.InsertOnSubmit(activity);

                    TableModifyLog modify = new TableModifyLog();
                    modify.RoleID = 11;
                    modify.ItemID = GetNewItemID(Convert.ToInt32(HiddenFieldType.Value));
                    modify.ActionID = (int)EnumAction.AddNew;
                    modify.UserID = UserManage.GetUserID(HttpContext.Current.User.Identity.Name);
                    modify.ModifyDate = DateTime.Now;

                    intranet2012.ModifyLog.InsertOnSubmit(modify);
                    intranet2012.SubmitChanges();
                }
            }
            else
            {
                TableActivity aEdit = (from a in intranet2012.Activity
                                       where a.ID == Convert.ToInt32(HiddenFieldItemID.Value)
                                       select a).First();

                aEdit.ActivityName = TextBoxSubject.Text;
                aEdit.StartDate = startDate;
                aEdit.EndDate = endDate;

                TableModifyLog modify = new TableModifyLog();
                modify.RoleID = 11;
                modify.ItemID = aEdit.ID;
                modify.ActionID = (int)EnumAction.Update;
                modify.UserID = UserManage.GetUserID(HttpContext.Current.User.Identity.Name);
                modify.ModifyDate = DateTime.Now;

                intranet2012.ModifyLog.InsertOnSubmit(modify);
                intranet2012.SubmitChanges();
            }
        }

        Calendar((DateTime)ViewState["date"]);
        BindGridView((DateTime)ViewState["date"]);
    }


ยังมีต่อ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-08 08:25:39 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 8

Guest


ต่อ

Calendar.ascx.cs
    protected void ImageButtonExcel_Click(object sender, ImageClickEventArgs e)
    {
        Calendar((DateTime)ViewState["date"]);

        ButtonImport.Enabled = false;

        ModalPopupExtender1.Show();
    }

    protected void ImageButtonManual_Click(object sender, ImageClickEventArgs e)
    {
        Calendar((DateTime)ViewState["date"]);

        LabelActivity.Text = "Manual Add Public Holidays";
        HiddenFieldType.Value = "1";
        PanelEvent.Style.Add(HtmlTextWriterStyle.BackgroundColor, "red");
        ClearValue();

        ModalPopupExtender2.Show();   
    }

    protected void ImageButtonEnergyEvent_Click(object sender, ImageClickEventArgs e)
    {
        Calendar((DateTime)ViewState["date"]);

        LabelActivity.Text = "Add MoEN Activity";
        HiddenFieldType.Value = "2";
        PanelEvent.Style.Add(HtmlTextWriterStyle.BackgroundColor, "orange");
        ClearValue();

        ModalPopupExtender2.Show();
    }

    protected void ImageButtonEvent_Click(object sender, ImageClickEventArgs e)
    {
        Calendar((DateTime)ViewState["date"]);

        LabelActivity.Text = "Add Activity";
        HiddenFieldType.Value = "3";
        PanelEvent.Style.Add(HtmlTextWriterStyle.BackgroundColor, "green");
        ClearValue();

        ModalPopupExtender2.Show();
    }

    protected void ImageButtonMeeting_Click(object sender, ImageClickEventArgs e)
    {
        Calendar((DateTime)ViewState["date"]);

        LabelActivity.Text = "Add Meeting";
        HiddenFieldType.Value = "4";
        PanelEvent.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#0066cc");
        ClearValue();

        ModalPopupExtender2.Show();
    }

    protected void ImageButtonTraining_Click(object sender, ImageClickEventArgs e)
    {
        Calendar((DateTime)ViewState["date"]);

        LabelActivity.Text = "Add Training";
        HiddenFieldType.Value = "5";
        PanelEvent.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#f06eaa");
        ClearValue();

        ModalPopupExtender2.Show();
    }

    protected bool ItemExist(TableActivity activity)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        return ((from a in intranet2012.Activity
                 where a.TypeID == activity.TypeID && a.ActivityName == activity.ActivityName && a.StartDate == activity.StartDate && a.EndDate == activity.EndDate
                 select a).Count() > 0) ? true : false;
    }

    protected void PrepareIcon()
    {
        Panel1.Attributes.Add("onmouseover", string.Format("document.getElementById('{0}').innerHTML = 'Excel'; document.getElementById('pHolidays').style.backgroundColor = 'red';", Label1.ClientID));
        Panel1.Attributes.Add("onmouseout", string.Format("document.getElementById('{0}').innerHTML = '&nbsp;'; document.getElementById('pHolidays').style.backgroundColor = 'white';", Label1.ClientID));

        Panel2.Attributes.Add("onmouseover", string.Format("document.getElementById('{0}').innerHTML = 'Manual'; document.getElementById('pHolidays').style.backgroundColor = 'red';", Label1.ClientID));
        Panel2.Attributes.Add("onmouseout", string.Format("document.getElementById('{0}').innerHTML = '&nbsp;'; document.getElementById('pHolidays').style.backgroundColor = 'white';", Label1.ClientID));

        Panel3.Attributes.Add("onmouseover", string.Format("document.getElementById('{0}').innerHTML = 'MoEN Activity'; document.getElementById('activity').style.backgroundColor = 'orange';", Label2.ClientID));
        Panel3.Attributes.Add("onmouseout", string.Format("document.getElementById('{0}').innerHTML = '&nbsp;'; document.getElementById('activity').style.backgroundColor = 'white';", Label2.ClientID));

        Panel4.Attributes.Add("onmouseover", string.Format("document.getElementById('{0}').innerHTML = 'Activity'; document.getElementById('activity').style.backgroundColor = 'green';", Label2.ClientID));
        Panel4.Attributes.Add("onmouseout", string.Format("document.getElementById('{0}').innerHTML = '&nbsp;'; document.getElementById('activity').style.backgroundColor = 'white';", Label2.ClientID));

        Panel5.Attributes.Add("onmouseover", string.Format("document.getElementById('{0}').innerHTML = 'Meeting'; document.getElementById('activity').style.backgroundColor = '#0066cc';", Label2.ClientID));
        Panel5.Attributes.Add("onmouseout", string.Format("document.getElementById('{0}').innerHTML = '&nbsp;'; document.getElementById('activity').style.backgroundColor = 'white';", Label2.ClientID));

        Panel6.Attributes.Add("onmouseover", string.Format("document.getElementById('{0}').innerHTML = 'Training'; document.getElementById('activity').style.backgroundColor = '#f06eaa';", Label2.ClientID));
        Panel6.Attributes.Add("onmouseout", string.Format("document.getElementById('{0}').innerHTML = '&nbsp;'; document.getElementById('activity').style.backgroundColor = 'white';", Label2.ClientID));
    
    }

    protected void ClearValue()
    {
        HiddenFieldItemID.Value = string.Empty;
        TextBoxSubject.Text = string.Empty;
        TextBoxStart.Text = string.Empty;
        TextBoxEnd.Text = string.Empty;
        StartTime.Value = new TimeSpan(8, 30, 0);
        EndTime.Value = new TimeSpan(16, 30, 0);
    }

    protected void FillValue(TableActivity activity)
    {
        HiddenFieldItemID.Value = activity.ID.ToString();
        TextBoxSubject.Text = activity.ActivityName;
        TextBoxStart.Text = activity.StartDate.ToString("dd/MM/yyyy", new System.Globalization.CultureInfo("en-GB"));
        StartTime.Value = new TimeSpan(activity.StartDate.Hour, activity.StartDate.Minute, 0);
        TextBoxEnd.Text = activity.EndDate.ToString("dd/MM/yyyy", new System.Globalization.CultureInfo("en-GB"));
        EndTime.Value = new TimeSpan(activity.EndDate.Hour, activity.EndDate.Minute, 0);   
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        GridView gv = (GridView)sender;

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string color;

            switch ((int)GridView1.DataKeys[e.Row.RowIndex].Values[1])
            { 
                default:
                    color = "red";
                    break;
                case 2:
                    color = "orange";
                    break;
                case 3:
                    color = "green";
                    break;
                case 4:
                    color = "#0066cc";
                    break;
                case 5:
                    color = "#f06eaa";
                    break;
            }

            Table table1 = new Table();
            
            TableRow row1 = new TableRow();
            table1.Rows.Add(row1);

            TableCell cell1 = new TableCell();
            row1.Cells.Add(cell1);

            TableCell cell2 = new TableCell();
            cell2.Text = e.Row.Cells[1].Text;
            row1.Cells.Add(cell2);

            Panel panelType = new Panel();
            panelType.Width = Unit.Parse("10px");
            panelType.Height = Unit.Parse("10px");
            panelType.Style.Add(HtmlTextWriterStyle.BackgroundColor, color);
            cell1.Controls.Add(panelType);

            e.Row.Cells[0].Text = string.Format("{0}.", ((e.Row.RowIndex + 1) + (gv.PageIndex * gv.PageSize)).ToString());
            e.Row.Cells[1].Controls.Add(table1);
            e.Row.Cells[2].Text = Convert.ToDateTime(e.Row.Cells[2].Text).ToString("dd MMM yyyy เวลา HH:mm", new System.Globalization.CultureInfo("th-TH"));
            e.Row.Cells[3].Text = Convert.ToDateTime(e.Row.Cells[3].Text).ToString("dd MMM yyyy เวลา HH:mm", new System.Globalization.CultureInfo("th-TH"));
            
            ImageButton ImageButtonEdit = (ImageButton)e.Row.Cells[0].FindControl("ImageButtonEdit");
            ImageButtonEdit.CommandArgument = e.Row.RowIndex.ToString();

            ImageButton ImageButtonDelete = (ImageButton)e.Row.Cells[0].FindControl("ImageButtonDelete");
            ImageButtonDelete.CommandArgument = e.Row.RowIndex.ToString();
            ImageButtonDelete.OnClientClick = "javascript:return confirm('Do you want to delete this item?')";
        }
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.DataSource = GetActivity((DateTime)ViewState["date"]);
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();

        Calendar((DateTime)ViewState["date"]);
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "EditItem":
                EditItem(Convert.ToInt32(((GridView)sender).DataKeys[Convert.ToInt32(e.CommandArgument)].Value));
                break;
            case "DeleteItem":
                DeleteItem(Convert.ToInt32(((GridView)sender).DataKeys[Convert.ToInt32(e.CommandArgument)].Values[0]));
                break;
        }
    }

    protected void EditItem(int ItemID)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        TableActivity activity = (from a in intranet2012.Activity
                                  where a.ID == ItemID
                                  select a).First();

        switch (activity.TypeID)
        {
            default:
                Calendar((DateTime)ViewState["date"]);

                LabelActivity.Text = "Manual Add Public Holidays";
                HiddenFieldType.Value = "1";
                PanelEvent.Style.Add(HtmlTextWriterStyle.BackgroundColor, "red");
                FillValue(activity);

                ModalPopupExtender2.Show();  
                break;
            case 2:
                Calendar((DateTime)ViewState["date"]);

                LabelActivity.Text = "Add MoEN Activity";
                HiddenFieldType.Value = "2";
                PanelEvent.Style.Add(HtmlTextWriterStyle.BackgroundColor, "orange");
                FillValue(activity);

                ModalPopupExtender2.Show();
                break;
            case 3:
                Calendar((DateTime)ViewState["date"]);

                LabelActivity.Text = "Add Activity";
                HiddenFieldType.Value = "3";
                PanelEvent.Style.Add(HtmlTextWriterStyle.BackgroundColor, "green");
                FillValue(activity);

                ModalPopupExtender2.Show();
                break;
            case 4:
                Calendar((DateTime)ViewState["date"]);

                LabelActivity.Text = "Add Meeting";
                HiddenFieldType.Value = "4";
                PanelEvent.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#0066cc");
                FillValue(activity);

                ModalPopupExtender2.Show();
                break;
            case 5:
                Calendar((DateTime)ViewState["date"]);

                LabelActivity.Text = "Add Training";
                HiddenFieldType.Value = "5";
                PanelEvent.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#f06eaa");
                FillValue(activity);

                ModalPopupExtender2.Show();
                break;
        }
    }


ยังมีต่อ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-08 08:26:54 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 9

Guest


ต่อ

Calendar.ascx.cs
    protected void DeleteItem(int ItemID)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        TableActivity activity = (from a in intranet2012.Activity
                                  where a.ID == ItemID
                                  select a).First();

        intranet2012.Activity.DeleteOnSubmit(activity);

        TableModifyLog modify = new TableModifyLog();
        modify.RoleID = 11;
        modify.ItemID = activity.ID;
        modify.ActionID = (int)EnumAction.Delete;
        modify.UserID = UserManage.GetUserID(HttpContext.Current.User.Identity.Name);
        modify.ModifyDate = DateTime.Now;

        intranet2012.ModifyLog.InsertOnSubmit(modify);
        intranet2012.SubmitChanges();

        Calendar((DateTime)ViewState["date"]);
        BindGridView((DateTime)ViewState["date"]);
    }

    protected int GetNewItemID()
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        int index = (from a in intranet2012.Activity
                     where a.TypeID == 1
                     orderby a.ID descending
                     select a).Select(nt => nt.ID).First();

        return index;
    }

    protected int GetNewItemID(int typeID)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        int index = (from a in intranet2012.Activity
                     where a.TypeID == typeID
                     orderby a.ID descending
                     select a).Select(nt => nt.ID).First();

        return index;
    }

    protected bool HaveHolidays(DateTime aDate)
    { 
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        return (from a in intranet2012.Activity
                where a.TypeID == 1 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
                select a).Count() > 0 ? true : false;
    }

    protected bool HaveMoENActivity(DateTime aDate)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        return (from a in intranet2012.Activity
                where a.TypeID == 2 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
                select a).Count() > 0 ? true : false;
    }

    protected bool HaveActivity(DateTime aDate)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        return (from a in intranet2012.Activity
                where a.TypeID == 3 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
                select a).Count() > 0 ? true : false;
    }

    protected bool HaveMeeting(DateTime aDate)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        return (from a in intranet2012.Activity
                where a.TypeID == 4 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
                select a).Count() > 0 ? true : false;
    }

    protected bool HaveTraining(DateTime aDate)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        return (from a in intranet2012.Activity
                where a.TypeID == 5 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
                select a).Count() > 0 ? true : false;
    }

    protected DataTable GetHolidays(DateTime aDate)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        var holidays = from a in intranet2012.Activity
                       where a.TypeID == 1 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
                       select a;

        return Intranet2012Datebase.LINQToDataTable(holidays);
    }

    protected DataTable GetAllActivity(DateTime aDate)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        var activity = from a in intranet2012.Activity
                       where a.TypeID != 1 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
                       orderby a.StartDate ascending
                       select a;

        return Intranet2012Datebase.LINQToDataTable(activity);
    }

    protected int GetHeight(DateTime EndDate, DateTime CurrentDate, int top)
    {
        int height = 416;

        if (CurrentDate.CompareTo(EndDate.Date) > 0)
        {
            height = 416;
        }
        else if (CurrentDate.CompareTo(EndDate.Date) == 0)
        {
            switch (EndDate.ToString("HH:mm"))
            {
                case "09:00":
                    height = 26;
                    break;
                case "09:30":
                    height = 52;
                    break;
                case "10:00":
                    height = 78;
                    break;
                case "10:30":
                    height = 104;
                    break;
                case "11:00":
                    height = 130;
                    break;
                case "11:30":
                    height = 156;
                    break;
                case "12:00":
                    height = 182;
                    break;
                case "12:30":
                    height = 208;
                    break;
                case "13:00":
                    height = 234;
                    break;
                case "13:30":
                    height = 260;
                    break;
                case "14:00":
                    height = 286;
                    break;
                case "14:30":
                    height = 312;
                    break;
                case "15:00":
                    height = 338;
                    break;
                case "15:30":
                    height = 364;
                    break;
                case "16:00":
                    height = 390;
                    break;
                case "16:30":
                    height = 416;
                    break;
            }
        }

        return (height - top - 20 < 0) ? 416 - top - 20 : height - top - 20;
    }

    protected int GetTop(DateTime StartDate, DateTime CurrentDate)
    {
        int top = 0;

        if (CurrentDate.CompareTo(StartDate.Date) < 0)
        {
            top = 0;
        }
        else if (CurrentDate.CompareTo(StartDate.Date) == 0)
        {
            switch (StartDate.ToString("HH:mm"))
            {
                case "08:30":
                    top = 0;
                    break;
                case "09:00":
                    top = 26;
                    break;
                case "09:30":
                    top = 52;
                    break;
                case "10:00":
                    top = 78;
                    break;
                case "10:30":
                    top = 104;
                    break;
                case "11:00":
                    top = 130;
                    break;
                case "11:30":
                    top = 156;
                    break;
                case "12:00":
                    top = 182;
                    break;
                case "12:30":
                    top = 208;
                    break;
                case "13:00":
                    top = 234;
                    break;
                case "13:30":
                    top = 260;
                    break;
                case "14:00":
                    top = 286;
                    break;
                case "14:30":
                    top = 312;
                    break;
                case "15:00":
                    top = 338;
                    break;
                case "15:30":
                    top = 364;
                    break;
                case "16:00":
                    top = 390;
                    break;
            }
        }

        return top;
    }

    protected string GetTime(int Top, int Height)
    {
        string start = string.Empty;
        string end = string.Empty;

        switch (Top)
        {
            case 0:
                start = "08:30";
                break;
            case 26:
                start = "09:00";
                break;
            case 52:
                start = "09:30";
                break;
            case 78:
                start = "10:00";
                break;
            case 104:
                start = "10:30";
                break;
            case 130:
                start = "11:00";
                break;
            case 156:
                start = "11:30";
                break;
            case 182:
                start = "12:00";
                break;
            case 208:
                start = "12:20";
                break;
            case 234:
                start = "13:00";
                break;
            case 260:
                start = "13:30";
                break;
            case 286:
                start = "14:00";
                break;
            case 312:
                start = "14:30";
                break;
            case 338:
                start = "15:00";
                break;
            case 364:
                start = "15:30";
                break;
            case 390:
                start = "16:00";
                break;
        }

        switch (Height + Top + 20)
        {
            case 26:
                end = "09:00";
                break;
            case 52:
                end = "09:30";
                break;
            case 78:
                end = "10:00";
                break;
            case 104:
                end = "10:30";
                break;
            case 130:
                end = "11:00";
                break;
            case 156:
                end = "11:30";
                break;
            case 182:
                end = "12:00";
                break;
            case 208:
                end = "12:20";
                break;
            case 234:
                end = "13:00";
                break;
            case 260:
                end = "13:30";
                break;
            case 286:
                end = "14:00";
                break;
            case 312:
                end = "14:30";
                break;
            case 338:
                end = "15:00";
                break;
            case 364:
                end = "15:30";
                break;
            case 390:
                end = "16:00";
                break;
            case 416:
                end = "16:30";
                break;
        }

        return string.Format("{0}น. - {1}น.", start, end);
    }
}

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-08 08:27:44 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 10

Guest


ส่วนหน้า web

EventCalendar.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="EventCalendar.ascx.cs" Inherits="UserControls_EventCalendar" %>

<asp:UpdateProgress ID="UpdateProgress1" DynamicLayout="false" runat="server">
    <ProgressTemplate>
        <asp:Image ID="Image1" ImageUrl="~/images/loadingBar.gif" runat="server" />
    </ProgressTemplate>
</asp:UpdateProgress>

<div id="calendar">
    <div id="calendar_left">
        <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="RollOverImageButton1" EventName="Click" />
                <asp:AsyncPostBackTrigger ControlID="RollOverImageButton2" EventName="Click" />
            </Triggers>
            <ContentTemplate>
                <asp:Table ID="Table1" CssClass="CalendarBody" runat="server">
                    <asp:TableRow>
                        <asp:TableCell CssClass="CalendarMonth" HorizontalAlign="Center" VerticalAlign="Middle">
                            <customControl:RollOverImageButton ID="RollOverImageButton1" ImageUrl="~/images/arrow-left.png" RollOverImageUrl="~/images/arrow-left-over.png" ToolTip="Back" runat="server" />
                        </asp:TableCell>
                        <asp:TableCell CssClass="CalendarMonth" ColumnSpan="5" HorizontalAlign="Center" VerticalAlign="Middle">
                            <asp:Label ID="LabelMonthName" runat="server" Text="Label"></asp:Label>
                        </asp:TableCell>
                        <asp:TableCell CssClass="CalendarMonth" HorizontalAlign="Center" VerticalAlign="Middle">
                            <customControl:RollOverImageButton ID="RollOverImageButton2" ImageUrl="~/images/arrow-right.png" RollOverImageUrl="~/images/arrow-right-over.png" ToolTip="Next" runat="server" />                            
                        </asp:TableCell>
                    </asp:TableRow>
                </asp:Table>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>

    <asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="RollOverImageButton1" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="RollOverImageButton2" EventName="Click" />
        </Triggers>
        <ContentTemplate>
            <asp:Panel ID="PanelRight" CssClass="calendar_right" runat="server">
                <asp:Table ID="TableActivity" style="width: 100%;" runat="server">
                    <asp:TableRow>
                        <asp:TableCell CssClass="td_activity">
                            <asp:Label ID="Label1" runat="server" Text="Label" style="font-weight: bold;"></asp:Label>
                        </asp:TableCell>
                    </asp:TableRow>
                </asp:Table>
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>

<asp:UpdatePanel ID="UpdatePanel3" runat="server" OnLoad="UpdatePanel3_Load">
    <ContentTemplate>
        <asp:Button ID="ButtonHidden3" runat="server" Text="Button" style="display: none;" />
        <ajaxToolkit:ModalPopupExtender runat="server" ID="ModalPopupExtender3"
            TargetControlID="ButtonHidden3" PopupControlID="PanelActivity" CancelControlID="ImageButton1"
            BackgroundCssClass="modalBackground" DropShadow="True"
            RepositionMode="RepositionOnWindowScroll">
        </ajaxToolkit:ModalPopupExtender>
        <asp:Panel ID="PanelActivity" CssClass="modalPopup" runat="server">
            <asp:Panel ID="PanelClose" CssClass="close" runat="server">
                <asp:ImageButton ID="ImageButton1" CssClass="close" ImageUrl="~/images/close.png" ToolTip="Close" runat="server" />
            </asp:Panel>
            <asp:Panel ID="PanelEvent" CssClass="calendar_detail" runat="server">
                <asp:Panel ID="PanelEventHead" CssClass="event_head" runat="server">
                    <asp:Table ID="Table2" CssClass="table_name" runat="server">
                        <asp:TableRow runat="server">
                            <asp:TableCell ID="CellTitle" CssClass="cell_name" runat="server">
                                <asp:Label ID="LabelTitle" runat="server" Text="Label"></asp:Label>
                            </asp:TableCell>
                        </asp:TableRow>
                    </asp:Table>
                </asp:Panel>
                <asp:Panel ID="PanelEventDetail" CssClass="event_detail" runat="server">
                    <asp:Table ID="TableDetail" CssClass="table_detail" BorderStyle="Solid" BorderWidth="1" runat="server">
                    </asp:Table>
                </asp:Panel>
            </asp:Panel>
        </asp:Panel>
        <ajaxToolkit:DropShadowExtender ID="DropShadowExtender1" runat="server" TargetControlID="PanelActivity" Opacity=".8" Rounded="true" TrackPosition="true" />
        <ajaxToolkit:RoundedCornersExtender ID="RoundedCornersExtender1" runat="server" TargetControlID="PanelEvent" Radius="4" Corners="All" />
    </ContentTemplate>
</asp:UpdatePanel>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-08 08:30:20 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 11

Guest


EventCalendar.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Text;

public partial class UserControls_EventCalendar : System.Web.UI.UserControl
{
    private int rightHeight;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (ViewState["date"] == null)
        {
            ViewState["date"] = DateTime.Now;

            Calendar((DateTime)ViewState["date"]);

            EventDetail((DateTime)ViewState["date"]);
        }

        RollOverImageButton1.Click += new ImageClickEventHandler(RollOverImageButton1_Click);
        RollOverImageButton2.Click += new ImageClickEventHandler(RollOverImageButton2_Click);
    }

    protected void RollOverImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        DateTime currentDate = (DateTime)ViewState["date"];
        ViewState["date"] = currentDate.AddMonths(-1);

        Calendar((DateTime)ViewState["date"]);

        EventDetail((DateTime)ViewState["date"]);
    }

    protected void RollOverImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        DateTime currentDate = (DateTime)ViewState["date"];
        ViewState["date"] = currentDate.AddMonths(1);

        Calendar((DateTime)ViewState["date"]);

        EventDetail((DateTime)ViewState["date"]);
    }

    protected void EventDetail(DateTime date)
    {
        PanelRight.Height = Unit.Parse(string.Format("{0}px", (rightHeight * 74).ToString()));

        Label1.Text = string.Format("เดือน{0} {1}", date.ToString("MMMM", new System.Globalization.CultureInfo("th-TH")), date.ToString("yyyy", new System.Globalization.CultureInfo("th-TH")));

        foreach (DataRow Dr in GetMonthActivity(date).Rows)
        {
            TableRow row2 = new TableRow();
            TableActivity.Rows.Add(row2);

            TableCell cell2 = new TableCell();
            cell2.CssClass = "td_activity";
            row2.Cells.Add(cell2);

            string color;

            switch ((int)Dr["TypeID"])
            {
                default:
                    color = "red";
                    break;
                case 2:
                    color = "orange";
                    break;
                case 3:
                    color = "green";
                    break;
                case 4:
                    color = "#0066cc";
                    break;
                case 5:
                    color = "#f06eaa";
                    break;
            }

            Table table1 = new Table();
            cell2.Controls.Add(table1);

            TableRow row11 = new TableRow();
            table1.Rows.Add(row11);

            TableCell cell11 = new TableCell();
            row11.Cells.Add(cell11);

            Panel panelType = new Panel();
            panelType.Width = Unit.Parse("10px");
            panelType.Height = Unit.Parse("10px");
            panelType.Style.Add(HtmlTextWriterStyle.BackgroundColor, color);
            cell11.Controls.Add(panelType);

            TableCell cell12 = new TableCell();
            if (Dr["ActivityName"].ToString().Length > 20)
            {
                cell12.Text = string.Format("{0}...", Dr["ActivityName"].ToString().Substring(0, 20));
                cell12.ToolTip = Dr["ActivityName"].ToString();
            }
            else
            {
                cell12.Text = Dr["ActivityName"].ToString();
            }
            row11.Cells.Add(cell12);

            TableRow row1 = new TableRow();
            TableActivity.Rows.Add(row1);

            TableCell cell1 = new TableCell();
            cell1.CssClass = "td_activity";
            cell1.Style.Add(HtmlTextWriterStyle.TextAlign, "right");

            if (Convert.ToDateTime(Dr["StartDate"]).Date.CompareTo(Convert.ToDateTime(Dr["EndDate"]).Date) == 0)
            {
                if (Convert.ToDateTime(Dr["StartDate"]).ToString("HH:mm") == "08:30" && Convert.ToDateTime(Dr["EndDate"]).ToString("HH:mm") == "16:30")
                {
                    cell1.Text = Convert.ToDateTime(Dr["StartDate"]).ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH"));
                }
                else
                    cell1.Text = string.Format("{0} [{1}-{2}]", Convert.ToDateTime(Dr["StartDate"]).ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH")), Convert.ToDateTime(Dr["StartDate"]).ToString("HH:mm", new System.Globalization.CultureInfo("th-TH")), Convert.ToDateTime(Dr["EndDate"]).ToString("HH:mm", new System.Globalization.CultureInfo("th-TH")));
            }
            else
            {
                cell1.Text = string.Format("{0} - {1}", Convert.ToDateTime(Dr["StartDate"]).ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH")), Convert.ToDateTime(Dr["EndDate"]).ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH")));
            }

            row1.Cells.Add(cell1);
        }
    }

    protected void Calendar(DateTime date)
    {
        LabelMonthName.Text = date.ToString("เดือนMMMM พ.ศ. yyyy", new System.Globalization.CultureInfo("th-TH"));

        int daysInMonth = DateTime.DaysInMonth(date.Year, date.Month);
        int fristDayOfWeek = (int)DateTime.ParseExact(string.Format("1/{0}/{1}", date.Month.ToString(), date.Year.ToString()), "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture).DayOfWeek;
        int lastDayOfWeek = (int)DateTime.ParseExact(string.Format("{0}/{1}/{2}", daysInMonth.ToString(), date.Month.ToString(), date.Year.ToString()), "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture).DayOfWeek;
        int loopDays = daysInMonth + fristDayOfWeek + (7 - lastDayOfWeek);

        rightHeight = (loopDays / 7) + 1;

        foreach (TableRow Tbr in Table1.Rows)
        {
            if (Table1.Rows.GetRowIndex(Tbr) != 0)
                Table1.Rows.Remove(Tbr);
        }

        TableRow Trh = new TableRow();
        Table1.Rows.Add(Trh);

        foreach (string str in new string[] {"อาทิตย์", "จันทร์", "อังคาร", "พุธ", "พฤหัสบดี", "ศุกร์", "เสาร์"})
        {
            TableCell Tch = new TableCell();
            Trh.Cells.Add(Tch);
            Tch.CssClass = "CalendarHead";
            Tch.Text = str;
        }

        for (int i = 0; i < loopDays / 7; i++)
        {
            TableRow Tr = new TableRow();
            Table1.Rows.Add(Tr);

            for (int j = 0; j < 7; j++)
            {
                int printDay = j + (7 * i) - (fristDayOfWeek - 1);

                TableCell Tc = new TableCell();
                Tr.Cells.Add(Tc);

                if (printDay < 1 || printDay > daysInMonth)
                {
                    Tc.CssClass = "CalendarCell";
                }
                else
                {
                    DateTime aDate = DateTime.ParseExact(string.Format("{0}/{1}/{2}", (j + (7 * i) - (fristDayOfWeek - 1)).ToString(), date.Month.ToString(), date.Year.ToString()), "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture);

                    StringBuilder Sb = new StringBuilder();
                    Sb.AppendLine("<table style=\"width: 100%; height:100%; border-collapse: collapse;\">");
                    Sb.Append("<tr style=\"height: 20%;\">");
                    Sb.AppendLine("<td>");
                    Sb.AppendLine("<div>");
                    Sb.AppendFormat("<div class={0} style=\"float: left;\">{1}</div>", (DateTime.Now.ToShortDateString() == aDate.ToShortDateString()) ? "CalendarToday" : "CalendarDate", (j + (7 * i) - (fristDayOfWeek - 1)).ToString());

                    if (HaveHolidays(aDate))
                    {
                        Sb.AppendFormat("<div class=\"activitypanel1{0}\" style=\"width: 10px; height: 10px; float: right; margin-top: 5px; background-color: red;\"></div>", aDate.ToString("ddMMyy"));

                        AddBalloon(1, aDate);
                    }

                    Sb.AppendLine("</div>");
                    Sb.AppendLine("</td>");
                    Sb.AppendLine("</tr>");
                    Sb.AppendLine("<tr style=\"height: 40%;\">");
                    Sb.AppendLine("<td><div style=\"width: 10px; height: 10px;\"></div></td>");
                    Sb.AppendLine("</tr>");
                    Sb.AppendLine("<tr style=\"height: 20%;\">");
                    Sb.AppendLine("<td>");
                    Sb.AppendLine("<div>");

                    if (HaveMoENActivity(aDate))
                    {
                        Sb.AppendFormat("<div class=\"activitypanel2{0}\" style=\"width: 10px; height: 10px; float: left; margin-left: 6px; background-color: orange\"></div>", aDate.ToString("ddMMyy"));

                        AddBalloon(2, aDate);
                    }

                    if (HaveActivity(aDate))
                    {
                        Sb.AppendFormat("<div class=\"activitypanel3{0}\" style=\"width: 10px; height: 10px; float: left; margin-left: 6px; background-color: green\"></div>", aDate.ToString("ddMMyy"));

                        AddBalloon(3, aDate);
                    }

                    if (HaveMeeting(aDate))
                    {
                        Sb.AppendFormat("<div class=\"activitypanel4{0}\" style=\"width: 10px; height: 10px; float: left; margin-left: 6px; background-color: #0066cc\"></div>", aDate.ToString("ddMMyy"));

                        AddBalloon(4, aDate);
                    }

                    if (HaveTraining(aDate))
                    {
                        Sb.AppendFormat("<div class=\"activitypanel5{0}\" style=\"width: 10px; height: 10px; float: left; margin-left: 6px; background-color: #f06eaa\"></div>", aDate.ToString("ddMMyy"));

                        AddBalloon(5, aDate);
                    }

                    Sb.AppendLine("</div>");
                    Sb.AppendLine("</td>");
                    Sb.AppendLine("</tr>");
                    Sb.AppendLine("</table>");

                    Panel CalendarDate = new Panel();
                    CalendarDate.CssClass = "daypanel";
                    CalendarDate.Controls.Add(new LiteralControl(Sb.ToString()));

                    Tc.CssClass = (j == 0 || j == 6) ? "CalendarCellHolliday" : "CalendarCellNormal";
                    Tc.Controls.Add(CalendarDate);

                    if (HaveHolidays(aDate) || HaveMoENActivity(aDate) || HaveActivity(aDate) || HaveMeeting(aDate) || HaveTraining(aDate))
                        Tc.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(UpdatePanel3, aDate.ToShortDateString()));
                }
            }
        }
    }


ยังมีต่อ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-08 08:31:54 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 12

Guest


ต่อ

EventCalendar.ascx.cs
    protected void UpdatePanel3_Load(object sender, EventArgs e)
    {
        string sEventArguments = this.Request.Params["__EVENTARGUMENT"];

        if (!string.IsNullOrEmpty(sEventArguments))
        {
            if (IsNumeric(sEventArguments.Substring(0, 1)))
            {
                DateTime aDate;

                if (DateTime.TryParse(sEventArguments, out aDate))
                {
                    if (aDate.CompareTo(DateTime.Now.Date) == 0)
                    {
                        if (HaveHolidays(aDate))
                        {
                            string holidaysList = string.Empty;

                            foreach (DataRow Dr in GetHolidays(aDate).Rows)
                            {
                                holidaysList += string.Format("{0}, ", Dr["ActivityName"].ToString());
                            }

                            LabelTitle.Text = string.Format("<span style=\"color: blue;\">วันนี้</span> {0} - <span style=\"color: red;\">[{1}]</span>", aDate.ToString("\tวันddddที่ d MMMM พ.ศ. yyyy\t", new System.Globalization.CultureInfo("th-TH")), holidaysList.Substring(0, holidaysList.Length - 2));
                        }
                        else
                        {
                            LabelTitle.Text = string.Format("<span style=\"color: blue;\">วันนี้</span> {0}", aDate.ToString("\tวันddddที่ d MMMM พ.ศ. yyyy\t", new System.Globalization.CultureInfo("th-TH")));
                        }
                    }
                    else
                    {
                        if (HaveHolidays(aDate))
                        {
                            string holidaysList = string.Empty;

                            foreach (DataRow Dr in GetHolidays(aDate).Rows)
                            {
                                holidaysList += string.Format("{0}, ", Dr["ActivityName"].ToString());
                            }

                            LabelTitle.Text = string.Format("{0} - <span style=\"color: red;\">[{1}]</span>", aDate.ToString("วันddddที่ d MMMM พ.ศ. yyyy", new System.Globalization.CultureInfo("th-TH")), holidaysList.Substring(0, holidaysList.Length - 2));
                        }
                        else
                        {
                            LabelTitle.Text = aDate.ToString("วันddddที่ d MMMM พ.ศ. yyyy", new System.Globalization.CultureInfo("th-TH"));
                        }
                    }
                }

                foreach (string timeName in new string[] { "8.00", "9.00", "10.00", "11.00", "12.00", "13.00", "14.00", "15.00", "16.00" })
                {
                    TableRow Tr1 = new TableRow();
                    TableDetail.Rows.Add(Tr1);

                    TableCell TcName = new TableCell();
                    TcName.RowSpan = 2;
                    TcName.CssClass = "row_head";
                    Tr1.Cells.Add(TcName);

                    Table TableName = new Table();
                    TableName.Width = Unit.Parse("100%");
                    TableName.Height = Unit.Parse(string.Format("{0}px", (600 / 12 - 1).ToString()));
                    TableName.Style.Add(HtmlTextWriterStyle.BorderCollapse, "collapse");
                    TcName.Controls.Add(TableName);

                    TableRow TrName = new TableRow();
                    TableName.Rows.Add(TrName);

                    TableCell Name = new TableCell();
                    Name.CssClass = "cell_name";
                    Name.Text = timeName;
                    TrName.Cells.Add(Name);

                    TableCell Tc1 = new TableCell();
                    Tc1.Width = Unit.Parse("90%");
                    Tc1.CssClass = "row_alt";
                    Tc1.Height = Unit.Parse(string.Format("{0}px", ((600 / 12 - 1) / 2).ToString()));
                    Tr1.Cells.Add(Tc1);

                    TableRow Tr2 = new TableRow();
                    TableDetail.Rows.Add(Tr2);

                    TableCell Tc2 = new TableCell();
                    Tc2.Height = Unit.Parse(string.Format("{0}px", ((600 / 12 - 1) / 2).ToString()));
                    Tr2.Cells.Add(Tc2);
                }

                Panel PanelActivity = new Panel();
                PanelActivity.CssClass = "panel_activity";
                PanelEventDetail.Controls.Add(PanelActivity);

                int i = 0;
                string[] color = new string[] { "red", "orange", "green", "#0066cc", "#f06eaa" };

                foreach (DataRow Dr in GetAllActivity(aDate).Rows)
                {
                    int top = GetTop((DateTime)Dr["StartDate"], aDate);
                    int height = GetHeight((DateTime)Dr["EndDate"], aDate, top);

                    Panel aPanel = new Panel();
                    aPanel.CssClass = "panel_detail";
                    aPanel.Height = Unit.Parse(string.Format("{0}px", height.ToString()));
                    aPanel.Style.Add(HtmlTextWriterStyle.Top, string.Format("{0}px", top.ToString()));
                    aPanel.Style.Add(HtmlTextWriterStyle.Left, string.Format("{0}px", (i * 150 + (i + 1) * 2 + i + i).ToString()));
                    aPanel.Style.Add(HtmlTextWriterStyle.BackgroundColor, color[(int)Dr["TypeID"] - 1]);
                    aPanel.Controls.Add(new LiteralControl(string.Format("<span style=\"color: white; font-weight: bold;\" title=\"{0} [{1}]\">{0}</span><br /><span style=\"color: white;\">[{1}]</span>", Dr["ActivityName"].ToString(), GetTime(top, height).ToString())));
                    PanelActivity.Controls.Add(aPanel);

                    i++;
                }

                ModalPopupExtender3.Show();
            }
        }
    }

    protected bool HaveHolidays(DateTime aDate)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        return (from a in intranet2012.Activity
                where a.TypeID == 1 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
                select a).Count() > 0 ? true : false;
    }

    protected bool HaveMoENActivity(DateTime aDate)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        return (from a in intranet2012.Activity
                where a.TypeID == 2 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
                select a).Count() > 0 ? true : false;
    }

    protected bool HaveActivity(DateTime aDate)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        return (from a in intranet2012.Activity
                where a.TypeID == 3 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
                select a).Count() > 0 ? true : false;
    }

    protected bool HaveMeeting(DateTime aDate)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        return (from a in intranet2012.Activity
                where a.TypeID == 4 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
                select a).Count() > 0 ? true : false;
    }

    protected bool HaveTraining(DateTime aDate)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        return (from a in intranet2012.Activity
                where a.TypeID == 5 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
                select a).Count() > 0 ? true : false;
    }

    protected DataTable GetHolidays(DateTime aDate)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        var holidays = from a in intranet2012.Activity
                       where a.TypeID == 1 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
                       select a;

        return Intranet2012Datebase.LINQToDataTable(holidays);
    }

    protected DataTable GetAllActivity(DateTime aDate)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        var activity = from a in intranet2012.Activity
                       where a.TypeID != 1 && (a.StartDate.Date.CompareTo(aDate) <= 0 && a.EndDate.Date.CompareTo(aDate) >= 0)
                       orderby a.StartDate ascending
                       select a;

        return Intranet2012Datebase.LINQToDataTable(activity);
    }

    protected DataTable GetMonthActivity(DateTime aDate)
    {
        Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

        var activity = (from a in intranet2012.Activity
                        where (a.StartDate.Year == aDate.Year && a.StartDate.Month == aDate.Month) || (a.EndDate.Year == aDate.Year && a.EndDate.Month == aDate.Month)
                        orderby a.StartDate ascending
                        select a).ToList();

        return Intranet2012Datebase.LINQToDataTable(activity);       
    }

    protected void AddBalloon(int ActivityType, DateTime date)
    {
        ClientScriptManager clientScript = Page.ClientScript;
        string scriptName = string.Format("activitypanel{0}{1}", ActivityType.ToString(), date.ToString("ddMMyy"));

        if (!clientScript.IsStartupScriptRegistered(this.GetType(), scriptName))
        {
            Intranet2012DataContext intranet2012 = new Intranet2012DataContext();

            var activity = from a in intranet2012.Activity
                           where a.TypeID == ActivityType && (a.StartDate.Date.CompareTo(date) <= 0 && a.EndDate.Date.CompareTo(date) >= 0)
                           orderby a.StartDate, a.EndDate ascending
                           select a;

            string activityType = (from t in intranet2012.ActivityType
                                   where t.ID == ActivityType
                                   select t.TypeName).First();

            string[] color = new string[] { "red", "orange", "green", "#0066cc", "#f06eaa" };

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.AppendLine("$(function() {");
            stringBuilder.AppendFormat("$(\".activitypanel{0}{1}\").each(function()", ActivityType.ToString(), date.ToString("ddMMyy"));
            stringBuilder.Append("{ $(this).balloon({ contents: \"");
            stringBuilder.AppendFormat("<span style='margin: 10px 0px 0px 10px; font-weight: bold; color: {0}'>{1}</span><br />", color[ActivityType - 1], activityType);
            stringBuilder.Append("<ul class='activitylist'>");

            foreach (TableActivity a in activity)
            {
                string duration;

                if (a.StartDate.Date.CompareTo(a.EndDate.Date) == 0 && a.StartDate.TimeOfDay == new TimeSpan(8, 30, 0) && a.EndDate.TimeOfDay == new TimeSpan(16, 30, 0))
                {
                    duration = "[เต็มวัน]";
                }
                else if (a.StartDate.Date.CompareTo(a.EndDate.Date) != 0)
                {
                    duration = string.Format("[{0} - {1}]", a.StartDate.ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH")), a.EndDate.ToString("dd MMM yyyy", new System.Globalization.CultureInfo("th-TH")));
                }
                else
                {
                    duration = string.Format("[{0}น. - {1}น.]", a.StartDate.ToString("HH:mm"), a.EndDate.ToString("HH:mm"));
                }

                stringBuilder.AppendFormat("<li>{0} {1}</li>", a.ActivityName, duration);
            }

            stringBuilder.Append("</ul>\", position: \"bottom\" }); });");
            stringBuilder.AppendLine("});");

            ScriptManager.RegisterStartupScript(Page, this.GetType(), scriptName, stringBuilder.ToString(), true);
        }
    }


ยังมีต่อ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-08 08:33:17 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 13

Guest


ต่อ

EventCalendar.ascx.cs
    protected int GetHeight(DateTime EndDate, DateTime CurrentDate, int top)
    {
        int height = 416;

        if (CurrentDate.CompareTo(EndDate.Date) > 0)
        {
            height = 416;
        }
        else if (CurrentDate.CompareTo(EndDate.Date) == 0)
        {
            switch (EndDate.ToString("HH:mm"))
            {
                case "09:00":
                    height = 26;
                    break;
                case "09:30":
                    height = 52;
                    break;
                case "10:00":
                    height = 78;
                    break;
                case "10:30":
                    height = 104;
                    break;
                case "11:00":
                    height = 130;
                    break;
                case "11:30":
                    height = 156;
                    break;
                case "12:00":
                    height = 182;
                    break;
                case "12:30":
                    height = 208;
                    break;
                case "13:00":
                    height = 234;
                    break;
                case "13:30":
                    height = 260;
                    break;
                case "14:00":
                    height = 286;
                    break;
                case "14:30":
                    height = 312;
                    break;
                case "15:00":
                    height = 338;
                    break;
                case "15:30":
                    height = 364;
                    break;
                case "16:00":
                    height = 390;
                    break;
                case "16:30":
                    height = 416;
                    break;
            }
        }

        return (height - top - 20 < 0) ? 416 - top - 20 : height - top - 20;
    }

    protected int GetTop(DateTime StartDate, DateTime CurrentDate)
    {
        int top = 0;

        if (CurrentDate.CompareTo(StartDate.Date) < 0)
        {
            top = 0;
        }
        else if (CurrentDate.CompareTo(StartDate.Date) == 0)
        {
            switch (StartDate.ToString("HH:mm"))
            {
                case "08:30":
                    top = 0;
                    break;
                case "09:00":
                    top = 26;
                    break;
                case "09:30":
                    top = 52;
                    break;
                case "10:00":
                    top = 78;
                    break;
                case "10:30":
                    top = 104;
                    break;
                case "11:00":
                    top = 130;
                    break;
                case "11:30":
                    top = 156;
                    break;
                case "12:00":
                    top = 182;
                    break;
                case "12:30":
                    top = 208;
                    break;
                case "13:00":
                    top = 234;
                    break;
                case "13:30":
                    top = 260;
                    break;
                case "14:00":
                    top = 286;
                    break;
                case "14:30":
                    top = 312;
                    break;
                case "15:00":
                    top = 338;
                    break;
                case "15:30":
                    top = 364;
                    break;
                case "16:00":
                    top = 390;
                    break;
            }
        }

        return top;
    }

    protected string GetTime(int Top, int Height)
    {
        string start = string.Empty;
        string end = string.Empty;

        switch (Top)
        {
            case 0:
                start = "08:30";
                break;
            case 26:
                start = "09:00";
                break;
            case 52:
                start = "09:30";
                break;
            case 78:
                start = "10:00";
                break;
            case 104:
                start = "10:30";
                break;
            case 130:
                start = "11:00";
                break;
            case 156:
                start = "11:30";
                break;
            case 182:
                start = "12:00";
                break;
            case 208:
                start = "12:20";
                break;
            case 234:
                start = "13:00";
                break;
            case 260:
                start = "13:30";
                break;
            case 286:
                start = "14:00";
                break;
            case 312:
                start = "14:30";
                break;
            case 338:
                start = "15:00";
                break;
            case 364:
                start = "15:30";
                break;
            case 390:
                start = "16:00";
                break;
        }

        switch (Height + Top + 20)
        {
            case 26:
                end = "09:00";
                break;
            case 52:
                end = "09:30";
                break;
            case 78:
                end = "10:00";
                break;
            case 104:
                end = "10:30";
                break;
            case 130:
                end = "11:00";
                break;
            case 156:
                end = "11:30";
                break;
            case 182:
                end = "12:00";
                break;
            case 208:
                end = "12:20";
                break;
            case 234:
                end = "13:00";
                break;
            case 260:
                end = "13:30";
                break;
            case 286:
                end = "14:00";
                break;
            case 312:
                end = "14:30";
                break;
            case 338:
                end = "15:00";
                break;
            case 364:
                end = "15:30";
                break;
            case 390:
                end = "16:00";
                break;
            case 416:
                end = "16:30";
                break;
        }

        return string.Format("{0}น. - {1}น.", start, end);
    }

    public bool IsNumeric(string stringToTest)
    {
        int result;
        if (int.TryParse(stringToTest, out result))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-08 08:34:10 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 14



โพสกระทู้ ( 312 )
บทความ ( 0 )



สถานะออฟไลน์


ดูโค้ดแล้วงงมากเลยครับ แบบนี้คือสร้างปฏิทินเองใช่ป่ะ?

ถ้าเราใช้ เครื่องมือ calendar ใน visual Studio สร้างปฏิทินล่ะครับ
มีวิธีไหนที่จะเช็คได้บ้างว่าวันไหนมีกิจกรรมอะไรบ้าง ??
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-11 10:56:22 By : Nr_Tom
 


 

No. 15

Guest


ตอบความคิดเห็นที่ : 13 เขียนโดย : ห้ามตอบเกินวันละ 2 กระทู้ เมื่อวันที่ 2013-10-08 08:34:10
รายละเอียดของการตอบ ::


ผมขอดูผลลัพท์ Screen Design /Output หน่อยครับ
ขอบคุณครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-11 13:09:37 By : ผ่านมา
 


 

No. 16



โพสกระทู้ ( 312 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 15 เขียนโดย : ผ่านมา เมื่อวันที่ 2013-10-11 13:09:37
รายละเอียดของการตอบ ::
12324ddf

ตามนี้เลยครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-11 13:40:21 By : Nr_Tom
 


 

No. 17



โพสกระทู้ ( 312 )
บทความ ( 0 )



สถานะออฟไลน์


wqe123

นี่คือที่ผมทำได้ สามารถดึงค่าจาก DB มาเช็คได้แล้ว
นี่คือ code ที่ดึงค่ามาครับ

Code (VB.NET)
Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
        Dim adoDATA As New DataTable
        adoDATA = clsDB.GetDT("SELECT * FROM MST_Activity ")
        For i As Integer = 0 To adoDATA.Rows.Count - 1
            If e.Day.Date = Format(adoDATA.Rows(i).Item("ActDate"), "dd/MM/yyyy") Then
                e.Cell.BackColor = System.Drawing.Color.Red
                e.Cell.BorderColor = System.Drawing.Color.Gray
                e.Cell.BorderWidth = 1
            End If
        Next

        'If e.Day.Date = "11/10/2556" Or e.Day.Date = "10/10/2556" Then
        '    e.Cell.BackColor = System.Drawing.Color.Red
        'End If
    End Sub


ณ ตอนนี้ DB เก็บ ค่า ActDate แค่วันเดียว
ทีนี้ผมมีข้อสงสัยว่า
1. ถ้าเกิด DB เก็บค่าวันที่ของ Activity เป็นวันเริ่มต้นกับวันสิ้นสุด จะมีการเช็คค่าอย่างไรครับ?
2. อยากให้ตัวเลขตรงวันที่ไม่มีขีดเส้นใต้ทำยังไง? (ผมกำหนด underline เป็น false แล้วแต่ยังไม่หาย)
3. ปุ่ม Next & Prev สามารถกำหนดเป็นรูปได้มั้ยครับ?

รบกวนผู้รู้ด้วยครับ ผมมือใหม่ vb
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-11 13:56:03 By : Nr_Tom
 


 

No. 18

Guest


ตอบนายผ่านมา

admin (input data)

2

web (show data but it empty)

3
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-11 16:55:07 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 19

Guest


ตอบความคิดเห็นที่ : 18 เขียนโดย : ห้ามตอบเกินวันละ 2 กระทู้ เมื่อวันที่ 2013-10-11 16:55:07
รายละเอียดของการตอบ ::


สมมุติว่า ผมมีทางให้คุณเลือก

1. คุณมาเป็นหัวหน้าผม
2. คุณมาเป็นลูกน้องผม
3. ไปนรกด้วยกัน


คุณจะเลือกแบบไหน


[x] กระผมขอโทษครับ ทางแคบทางเลือกของผม
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-11 20:43:23 By : ผ่านมา
 


 

No. 20



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์



แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-12 02:41:53 By : PlaKriM
 


 

No. 21



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-12 08:09:15 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามเกี่ยวกับการทำปฏิทินครับ คลิกดูว่าแต่ละวันมีกิจกรรมอะไรบ้าง
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่