Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.78 KB | None | 0 0
  1. <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="adminTourDates.aspx.cs" Inherits="adminTourDates" %>
  2.  
  3. <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
  4. </asp:Content>
  5. <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  6. <h3>Tour Date Admin Page</h3>
  7. <br />
  8. <p>Artist/Band</p>
  9. <asp:TextBox ID="artistText" runat="server"></asp:TextBox>
  10. <br />
  11. <p>Venue Playing</p>
  12. <asp:TextBox ID="venueText" runat="server"></asp:TextBox>
  13. <br />
  14. <br />
  15. <asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="White" BorderWidth="1px" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="190px" NextPrevFormat="FullMonth" Width="350px">
  16. <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
  17. <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" VerticalAlign="Bottom" />
  18. <OtherMonthDayStyle ForeColor="#999999" />
  19. <SelectedDayStyle BackColor="#333399" ForeColor="White" />
  20. <TitleStyle BackColor="White" BorderColor="Black" BorderWidth="4px" Font-Bold="True" Font-Size="12pt" ForeColor="#333399" />
  21. <TodayDayStyle BackColor="#CCCCCC" />
  22. </asp:Calendar>
  23.  
  24. <br />
  25. <asp:Label ID="calander_selected" runat="server" Text="" ForeColor="#CC00CC"></asp:Label>
  26. <asp:Label ID="errorLabel" runat="server" Text=""></asp:Label>
  27. <br />
  28.  
  29. <p>Time Playing</p>
  30. hours:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:TextBox ID="hoursText" runat="server" Width="50px"></asp:TextBox>
  31. <br />
  32. minutes:&nbsp;&nbsp;&nbsp;&nbsp; <asp:TextBox ID="minutesText" runat="server" Width="50px"></asp:TextBox>
  33. <br />
  34. <asp:Label ID="timeLabel" runat="server" Text="" ForeColor="#CC00CC"></asp:Label>
  35.  
  36. <br />
  37. <asp:Label ID="saveLabel" runat="server" Text=""></asp:Label>
  38. <br />
  39. <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" style="height: 48px" />
  40. <br />
  41. <br />
  42. <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="id" DataSourceID="SqlDataSource2" ForeColor="#333333" GridLines="None">
  43. <AlternatingRowStyle BackColor="White" />
  44. <Columns>
  45. <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" />
  46. <asp:BoundField DataField="artist" HeaderText="artist" SortExpression="artist" />
  47. <asp:BoundField DataField="venue" HeaderText="venue" SortExpression="venue" />
  48. <asp:BoundField DataField="date" HeaderText="date" SortExpression="date" />
  49. <asp:BoundField DataField="time" HeaderText="time" SortExpression="time" />
  50. <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
  51. </Columns>
  52. <EditRowStyle BackColor="#2461BF" />
  53. <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
  54. <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
  55. <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
  56. <RowStyle BackColor="#EFF3FB" />
  57. <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
  58. <SortedAscendingCellStyle BackColor="#F5F7FB" />
  59. <SortedAscendingHeaderStyle BackColor="#6D95E1" />
  60. <SortedDescendingCellStyle BackColor="#E9EBEF" />
  61. <SortedDescendingHeaderStyle BackColor="#4870BE" />
  62. </asp:GridView>
  63. <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [tblTour] WHERE [id] = @id" InsertCommand="INSERT INTO [tblTour] ([venue], [date], [time], [artist]) VALUES (@venue, @date, @time, @artist)" SelectCommand="SELECT * FROM [tblTour]" UpdateCommand="UPDATE [tblTour] SET [venue] = @venue, [date] = @date, [time] = @time, [artist] = @artist WHERE [id] = @id">
  64. <DeleteParameters>
  65. <asp:Parameter Name="id" Type="Int32" />
  66. </DeleteParameters>
  67. <InsertParameters>
  68. <asp:Parameter Name="venue" Type="String" />
  69. <asp:Parameter DbType="Date" Name="date" />
  70. <asp:Parameter Name="time" Type="DateTime" />
  71. <asp:Parameter Name="artist" Type="String" />
  72. </InsertParameters>
  73. <UpdateParameters>
  74. <asp:Parameter Name="venue" Type="String" />
  75. <asp:Parameter DbType="Date" Name="date" />
  76. <asp:Parameter Name="time" Type="DateTime" />
  77. <asp:Parameter Name="artist" Type="String" />
  78. <asp:Parameter Name="id" Type="Int32" />
  79. </UpdateParameters>
  80. </asp:SqlDataSource>
  81. </asp:Content>
  82.  
  83.  
  84. ######################################################################################################################################################################################################################################################################
  85.  
  86. using System;
  87. using System.Collections.Generic;
  88. using System.Linq;
  89. using System.Web;
  90. using System.Web.UI;
  91. using System.Web.UI.WebControls;
  92. using System.Data.SqlClient;
  93. using System.Configuration;
  94.  
  95. public partial class adminTourDates : System.Web.UI.Page
  96. {
  97. protected void Page_Load(object sender, EventArgs e)
  98. {
  99.  
  100.  
  101.  
  102. if (Page.IsPostBack == true)
  103. {
  104. errorLabel.Text = ("working");
  105. }
  106.  
  107.  
  108.  
  109. /*Labels*/
  110.  
  111. calander_selected.Text = Calendar1.SelectedDate.ToShortDateString();
  112. }
  113.  
  114.  
  115. protected void Button1_Click(object sender, EventArgs e)
  116. {
  117. SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  118.  
  119.  
  120.  
  121. var hours = int.Parse(hoursText.Text);
  122. var minutes = int.Parse(minutesText.Text);
  123. TimeSpan timeSpan = new TimeSpan(hours, minutes, 00);
  124.  
  125. saveLabel.Text = "details entered into db";
  126.  
  127. {
  128. //validation so cannot be attacked with SQL injection
  129. SqlCommand xp = new SqlCommand("Insert into tblTour(venue, artist, date, time) Values(@venue, @artist, @date, @time )", connect);
  130.  
  131.  
  132. xp.Parameters.AddWithValue("@venue", venueText.Text);
  133. xp.Parameters.AddWithValue("@artist", artistText.Text);
  134. xp.Parameters.AddWithValue("@date", Calendar1.SelectedDate.ToShortDateString());
  135. xp.Parameters.AddWithValue("@time", timeSpan);
  136.  
  137. connect.Open();
  138. xp.ExecuteNonQuery();
  139. connect.Close();
  140.  
  141. if (IsPostBack)
  142. {
  143. venueText.Text = "";
  144. artistText.Text = "";
  145.  
  146. }
  147. }
  148. }
  149.  
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement