存储预订数据并显示

时间:2017-12-28 06:47:11

标签: c# asp.net sql-server-2012

这是我想要做的事情

  • 商店预订数据
  • 根据所选日期创建时间表
  • 填充时间表将保留所选日期。对于空插槽,显示一个插槽。

这是我到目前为止所尝试的

ERD enter image description here

插入预订数据并查询2017年11月11日的所有选定数据 enter image description here

显示日期的结果是asp.net

enter image description here

我想做什么

  • 让计划时间表从早上6点开始有时段,然后去 到晚上7点。按照下图提供的间隔时间。
  • 可以使用。
  • 为空插槽添加预订
  • 能够查看当前广告位的详细信息(仅限玩家名称)

我已经包含了我当前的aspx文件代码和下面的aspx.cs文件。任何帮助或指导将不胜感激。谢谢你的时间。

enter image description here

ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MakeReservation.aspx.cs" Inherits="ClubBAIST.CBS.UI.MakeReservation" %>

<%--<%@ Import Namespace="ClubBAIST.CBS.UI"%>--%>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Label ID="lblDate" runat="server" Text="Date: "></asp:Label>

        <asp:TextBox ID="tbxDate" runat="server"></asp:TextBox>

        <%-- Expand/Hide Calendar --%>
        <asp:Button ID="BtnCalendar" runat="server" OnClick="BtnCalendar_Click" Height="25px" Width="25px" Text="+" />

        <%-- Handle customer selection via calendar control --%>
        <asp:Calendar ID="calCalendar" runat="server" Visible="False" OnSelectionChanged="calCalendar_SelectionChanged" BackColor="White" BorderColor="White" BorderWidth="1px" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="190px" NextPrevFormat="FullMonth" Width="350px">
            <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
            <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" VerticalAlign="Bottom" />
            <OtherMonthDayStyle ForeColor="#999999" />
            <SelectedDayStyle BackColor="#333399" ForeColor="White" />
            <TitleStyle BackColor="White" BorderColor="Black" BorderWidth="4px" Font-Bold="True" Font-Size="12pt" ForeColor="#333399" />
            <TodayDayStyle BackColor="#CCCCCC" />
        </asp:Calendar>

        <%-- Drop down for days of the week --%>
        <asp:Label ID="lblDayOfWeek" runat="server" Text="Day Of Week: "></asp:Label>
        <asp:DropDownList ID="ddlDayOfWeek" runat="server">
            <asp:ListItem Text="Sunday" Value="Sunday"></asp:ListItem>
            <asp:ListItem Text="Monday" Value="Monday"></asp:ListItem>
            <asp:ListItem Text="Tuesday" Value="Tuesday"></asp:ListItem>
            <asp:ListItem Text="Wednesday" Value="Wednesday"></asp:ListItem>
            <asp:ListItem Text="Thursday" Value="Thursday"></asp:ListItem>
            <asp:ListItem Text="Friday" Value="Friday"></asp:ListItem>
        </asp:DropDownList>
        <asp:Button ID="GetTeeTimes" runat="server" Text="Find Tee Times" />
        <br />
        <asp:Table ID="TeeTimesTable" runat="server">
        </asp:Table>
        <asp:GridView ID="gvTeeTime" runat="server" OnSelectedIndexChanged="gvTeeTime_SelectedIndexChanged">
        </asp:GridView>
        <br />

        <div>
            <asp:Table ID="BookingTable" runat="server" Visible="false">
                <asp:TableRow>
                    <asp:TableHeaderCell>
                         <h3>Book Tee Time</h3>
                    </asp:TableHeaderCell>
                </asp:TableRow>
                <asp:TableRow>

                    <asp:TableCell>
                                Date:
                            </asp:TableCell>
                    <asp:TableCell>
                        <asp:TextBox ID="Date" TextMode="Date" runat="server"></asp:TextBox><br />
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell>
                                 Time: 
                            </asp:TableCell>
                    <asp:TableCell>
                        Hour:
                        <asp:DropDownList ID="Hour" runat="server">

                            <asp:ListItem>6</asp:ListItem>
                            <asp:ListItem>7</asp:ListItem>
                            <asp:ListItem>8</asp:ListItem>
                            <asp:ListItem>9</asp:ListItem>
                            <asp:ListItem>10</asp:ListItem>
                            <asp:ListItem>11</asp:ListItem>
                        </asp:DropDownList>
                        Minute:<asp:DropDownList ID="Minute" runat="server">
                            <asp:ListItem>00</asp:ListItem>
                            <asp:ListItem>07</asp:ListItem>
                            <asp:ListItem>15</asp:ListItem>
                            <asp:ListItem>22</asp:ListItem>
                            <asp:ListItem>30</asp:ListItem>
                            <asp:ListItem>37</asp:ListItem>
                            <asp:ListItem>45</asp:ListItem>
                            <asp:ListItem>52</asp:ListItem>
                        </asp:DropDownList>
                        AMorPM
                        <asp:DropDownList ID="AMorPM" AutoPostBack="true" OnSelectedIndexChanged="AMorPM_SelectedIndexChanged" runat="server">
                            <asp:ListItem>AM</asp:ListItem>
                            <asp:ListItem>PM</asp:ListItem>
                        </asp:DropDownList><br />
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell>
                                Number of Players: 
                            </asp:TableCell>
                    <asp:TableCell>
                        <asp:RadioButtonList OnSelectedIndexChanged="NumberOfPlayers_SelectedIndexChanged" ID="NumberOfPlayers" runat="server" RepeatDirection="Horizontal" AutoPostBack="True">
                            <asp:ListItem Selected="True">1</asp:ListItem>
                            <asp:ListItem>2</asp:ListItem>
                            <asp:ListItem>3</asp:ListItem>
                            <asp:ListItem>4</asp:ListItem>
                        </asp:RadioButtonList>
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell>
                        Member Type :
                    </asp:TableCell>
                    <asp:TableCell>
                        <asp:DropDownList 
                            ID="MemberTypeDDL" 
                            runat="server">
                            <asp:ListItem> </asp:ListItem>                           
                            <asp:ListItem Text="Gold" Value="1"> </asp:ListItem>
                            <asp:ListItem Text="Silver" Value="2"> </asp:ListItem>
                            <asp:ListItem Text="Bronze" Value="3"> </asp:ListItem>                            
                        </asp:DropDownList>
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell>
                                MemberNumber:
                            </asp:TableCell>
                    <asp:TableCell>
                        <asp:TextBox ID="MemberNumber" runat="server" Enabled="True"></asp:TextBox><br />
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell>
                                Player 1:
                            </asp:TableCell>
                    <asp:TableCell>
                        <asp:TextBox ID="MemberName1" runat="server" Enabled="true"></asp:TextBox><br />
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell>
                                Player 2:
                            </asp:TableCell>
                    <asp:TableCell>
                        <asp:TextBox ID="MemberName2" runat="server" Enabled="false"></asp:TextBox><br />
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell>
                                Player 3:
                            </asp:TableCell>
                    <asp:TableCell>
                        <asp:TextBox ID="MemberName3" runat="server" Enabled="false"></asp:TextBox><br />
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell>
                                Player 4:
                            </asp:TableCell>
                    <asp:TableCell>
                        <asp:TextBox ID="MemberName4" runat="server" Enabled="false"></asp:TextBox><br />
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell>
                                Number Of Carts:
                            </asp:TableCell>
                    <asp:TableCell>
                        <asp:DropDownList 
                            ID="NoOfCartsDDL" 
                            runat="server">
                            <asp:ListItem> </asp:ListItem>
                            <asp:ListItem Text="None" Value="0"> </asp:ListItem>
                            <asp:ListItem Text="One" Value="1"> </asp:ListItem>
                            <asp:ListItem Text="Two" Value="2"> </asp:ListItem>
                            <asp:ListItem Text="Three" Value="3"> </asp:ListItem>
                            <asp:ListItem Text="Four" Value="4"> </asp:ListItem>
                        </asp:DropDownList>
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableFooterRow>
                    <asp:TableCell>
                        <asp:Button ID="BookTeeTime" runat="server" OnClick="BookTeeTime_Click" Text="Book Tee Time" />
                    </asp:TableCell>
                </asp:TableFooterRow>
            </asp:Table>
        </div>
        <asp:Label ID="Message" runat="server" Text=""></asp:Label><br /><br />
    </form>
</body>
</html>

ASPX.CS

using ClubBAIST.CBS.Domain;
using ClubBAIST.CBS.TechnicalServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


/// <summary>
/// Namespace for all UI for Club BAIST
/// </summary>
namespace ClubBAIST.CBS.UI
{
    /// <summary>
    /// Interacts with the Controller class CBS to create a reservation
    /// </summary>
    public partial class MakeReservation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }//eom


        /// <summary>
        /// When user changes selection, whether via DDL or Calendar, update the Textbox field.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void calCalendar_SelectionChanged(object sender, EventArgs e)            
        {
            tbxDate.Text = calCalendar.SelectedDate.ToShortDateString();

            ddlDayOfWeek.Text = calCalendar.SelectedDate.DayOfWeek.ToString();
            BookingTable.Visible = true;

            Date.Text = calCalendar.SelectedDate.ToShortDateString();


            calCalendar.Visible = false;

            //ViewReservationSheet 

            //ClubBAISTController TeeTimeDirector = new ClubBAISTController();

            TeeTimes TeeTimesManager = new TeeTimes();
            DateTime ttDate = Convert.ToDateTime( tbxDate.Text);
            gvTeeTime.DataSource = TeeTimesManager.GetTeeTime(ttDate);
            gvTeeTime.DataBind();


            //TeeTime TeeTimeManager = new TeeTime();
        }//eom

        /// <summary>
        /// Makes the Calendar appear upon expanding
        /// </summary>
        protected void BtnCalendar_Click(object sender, EventArgs e)
        {
            calCalendar.Visible = true;
        }//eom

        protected void NumberOfPlayers_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (NumberOfPlayers.SelectedIndex == 0)
            {
                MemberName1.Enabled = true;
                MemberName2.Enabled = false;
                MemberName3.Enabled = false;
                MemberName4.Enabled = false;
                MemberName2.Text = "";
                MemberName3.Text = "";
                MemberName4.Text = "";
            }
            else if (NumberOfPlayers.SelectedIndex == 1)
            {
                MemberName1.Enabled = true;
                MemberName2.Enabled = true;
                MemberName3.Enabled = false;
                MemberName4.Enabled = false;
                MemberName3.Text = "";
                MemberName4.Text = "";
            }
            else if (NumberOfPlayers.SelectedIndex == 2)
            {
                MemberName1.Enabled = true;
                MemberName2.Enabled = true;
                MemberName3.Enabled = true;
                MemberName4.Enabled = false;
                MemberName4.Text = "";
            }
            else
            {
                MemberName1.Enabled = true;
                MemberName2.Enabled = true;
                MemberName3.Enabled = true;
                MemberName4.Enabled = true;
            }
        }

        protected void AMorPM_SelectedIndexChanged(object sender, EventArgs e)
        {
            Hour.Items.Clear();
            if (AMorPM.SelectedIndex == 0)
            {
                Hour.Items.Add("6");
                Hour.Items.Add("7");
                Hour.Items.Add("8");
                Hour.Items.Add("9");
                Hour.Items.Add("10");
                Hour.Items.Add("11");
            }
            else
            {
                Hour.Items.Add("12");
                Hour.Items.Add("1");
                Hour.Items.Add("2");
                Hour.Items.Add("3");
                Hour.Items.Add("4");
                Hour.Items.Add("5");
                Hour.Items.Add("6");
                Hour.Items.Add("7");
                Hour.Items.Add("8");
            }
        }

        protected void gvTeeTime_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void BookTeeTime_Click(object sender, EventArgs e)
        {
            int hours = int.Parse(Hour.SelectedItem.Text);
            int minutes = int.Parse(Minute.SelectedItem.Text);

            if (AMorPM.SelectedItem.Text == "PM" && hours != 12)
                hours += 12;

            string datetime = Date.Text;
            datetime += " " + hours.ToString() + ":" + minutes.ToString();
            TeeTime NewTeeTime;
            DateTime DateT = DateTime.Parse(datetime);
            try
            {
                NewTeeTime = new TeeTime(DateT, DateT, Convert.ToInt32(MemberNumber.Text), MemberName1.Text, MemberName2.Text, MemberName3.Text, MemberName4.Text, Convert.ToInt32(NumberOfPlayers.SelectedValue), Convert.ToInt32(NoOfCartsDDL.SelectedValue),Convert.ToInt32(MemberTypeDDL.SelectedValue));
            }
            catch (Exception)
            {
                Message.Text = "Some of your fields are incorrect";
                return;
            }

            ClubBAISTController RequestHandler = new ClubBAISTController();

            if (RequestHandler.ReserveTeeTime(NewTeeTime))
            {
                Message.Text = "Reservation was successfuly made.";

                //update teeTimes
                TeeTimes TeeTimesManager = new TeeTimes();
                DateTime ttDate = Convert.ToDateTime(tbxDate.Text);
                gvTeeTime.DataSource = TeeTimesManager.GetTeeTime(ttDate);
                gvTeeTime.DataBind();
            }
            else
            {
                Message.Text = "Reservation could not be made.";
            }

        }
    }//eoc
}//eon

0 个答案:

没有答案