ПИС Курсач (ВКЛЮЧАЕТ ВСЕ ЛР И ПР)
.pdf<div class="row mb-3">
<label for="passwp" class="col-sm-2 col-form-label">Пароль:</label> <div class="col-sm-4">
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox> </div>
</div> <br />
<asp:Button ID="Button1" runat="server" Text="Войти" OnClick="Button1_Click" /> </div>
<div class="row">
<p>Если у вас нет аккаута, можете <a href="Registration.aspx" class="linkprimary">зарегистрироваться</a></p>
</div>
</div>
</asp:Content>
Листинг 5 – Код файла Authorization.aspx.cs
using System;
using System.Collections.Generic; using System.Data;
using System.Data.OleDb; using System.Linq;
using System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
namespace PostSite
{
public partial class Authorization : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Login.Text == "" | Password.Text == "")
{
WarningText.Visible = true; return;
}
string mySelectQuery = "SELECT p.idПользователя as userid, p.АдминСтатус as adminStatus FROM Пользователь p WHERE p.Логин = '" + Login.Text.ToString() + "' AND p.Пароль = '" + Password.Text.ToString() + "'";
OleDbConnection myConnection = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Connection PostBD"].ConnectionString);
OleDbDataAdapter adapter = new OleDbDataAdapter(mySelectQuery, myConnection); DataTable dt = new DataTable();
myConnection.Open();
adapter.Fill(dt);
myConnection.Close();
if (dt.Rows.Count == 0)
{
WarningText.Visible = true; return;
}
Session["userID"] = dt.Rows[0]["userid"];
Session["adminStatus"] = dt.Rows[0]["adminStatus"];
Response.Redirect("PersonalArea.aspx");
//foreach (DataRow row in dt.Rows) //{
// Button1.Text = row[0].ToString(); //}
}
}
}
Листинг 6 – Код файла Registration.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Registration.aspx.cs" Inherits="PostSite.Registration" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <style type="text/css">
.auto-style1 { width: 150px; text-align: right
}
.auto-style5 { height: 32px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="container"> <div class="row">
<h1>Регистрация</h1>
<p>Если у вас уже есть аккаунт, можете <a href="Authorization.aspx" class="linkprimary">авторизоваться</a></p>
</div>
<table>
<tr>
<td class="auto-style1">Фамилия:</td> <td class="auto-style5">
<asp:TextBox ID="SecondName" runat="server" TextMode="SingleLine" Width="200px"></asp:TextBox>
</td>
<td>
<asp:Label ID="LablePasportWarning" runat="server" Text=""></asp:Label> <asp:RegularExpressionValidator ID="SecondNameValidator"
runat="server"
ControlToValidate="SecondName"
ErrorMessage="Некорректный ввод Фамилии!"
EnableClientScript="False"
ForeColor="Red"
SetFocusOnError="true"
ValidationExpression="^[а-яА-Я]+$">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style1">Имя:</td> <td class="auto-style5">
<asp:TextBox ID="FirstName" runat="server" TextMode="SingleLine" Width="200px"></asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator ID="FirstNameValidator" runat="server"
ControlToValidate="FirstName"
ErrorMessage="Некорректный ввод Имени!"
EnableClientScript="False"
ForeColor="Red"
SetFocusOnError="true"
ValidationExpression="^[а-яА-Я]+$">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style1">Отчество:</td> <td class="auto-style5">
<asp:TextBox ID="MiddleName" runat="server" TextMode="SingleLine" Width="200px"></asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator ID="MiddleNameValidator" runat="server"
ControlToValidate="MiddleName"
ErrorMessage="Некорректный ввод Отчества!"
EnableClientScript="False"
ForeColor="Red"
SetFocusOnError="true"
ValidationExpression="^[а-яА-Я]+$">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style1">Адрес:</td> <td class="auto-style5">
<asp:TextBox ID="Adress" runat="server" TextMode="SingleLine" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">Паспорт:</td> <td class="auto-style5">
<asp:TextBox ID="Pasport" runat="server" TextMode="SingleLine" Width="200px"></asp:TextBox>
</td>
<td class="auto-style5"> <asp:RegularExpressionValidator ID="PasportValidator"
runat="server"
ControlToValidate="Pasport"
ErrorMessage="Некорректный ввод Паспорта!"
EnableClientScript="False"
ForeColor="Red"
SetFocusOnError="true" ValidationExpression="^([0-9]{4}\s{1}[0-9]{6})?$">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style1">Логин (Почта):</td>
<td class="auto-style5">
<asp:TextBox ID="LoginRegister" runat="server" TextMode="SingleLine" Width="200px"></asp:TextBox>
</td>
<td class="auto-style5"> <asp:RegularExpressionValidator ID="LoginValidator"
runat="server"
ControlToValidate="LoginRegister"
ErrorMessage="Неккоректный E-Mail!"
EnableClientScript="False"
ForeColor="Red"
SetFocusOnError="true" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style1">Пароль:</td> <td class="auto-style5">
<asp:TextBox ID="PasswordRegister" runat="server" TextMode="Password" Width="200px"></asp:TextBox>
</td>
<td class="auto-style5">
<asp:RegularExpressionValidator ID="PasswordValidator" runat="server" ControlToValidate="PasswordRegister"
ErrorMessage="Неккоректный Пароль!"
EnableClientScript="False"
ForeColor="Red"
SetFocusOnError="true" ValidationExpression="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,15}$">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style1">Повторите пароль:</td> <td class="auto-style5">
<asp:TextBox ID="PasswordRepitReg" runat="server" TextMode="Password" Width="200px"></asp:TextBox>
</td>
<td>
<asp:CompareValidator ID="PasswordRepitValidator" runat="server" ControlToCompare="PasswordRegister" ControlToValidate="PasswordRepitReg" EnableClientScript="False"
ForeColor="Red"
SetFocusOnError="true"
ErrorMessage="Пароли не совпадают!">
</asp:CompareValidator>
</td>
</tr>
</table> <br />
<div class="container">
<asp:Button ID="ButtonRegister" runat="server" Text="Зарегистрироваться"
OnClick="ButtonRegister_Click" />
<asp:Label ID="WarningLabel" runat="server" ForeColor="Red" Text=""></asp:Label> </div>
</div>
</asp:Content>
Листинг 7 – Код файла Registration.aspx.cs
using System;
using System.Collections.Generic; using System.Data.OleDb;
using System.Data; using System.Linq; using System.Web; using System.Web.UI;
using System.Web.UI.WebControls; using System.Drawing.Drawing2D;
using System.Runtime.Remoting.Contexts; using System.Xml.Linq;
using static System.Net.Mime.MediaTypeNames;
namespace PostSite
{
public partial class Registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected DataTable Select(string SelectQuery)
{
OleDbConnection myConnection = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Connection PostBD"].ConnectionString);
OleDbDataAdapter adapter = new OleDbDataAdapter(SelectQuery, myConnection); DataTable dt = new DataTable();
myConnection.Open();
adapter.Fill(dt);
myConnection.Close();
return dt;
}
protected string TextToSqlParam(string str)
{
if (str.Length == 0)
{
return "NULL";
}
else
{
return "'" + str + "'";
}
}
protected void ButtonRegister_Click(object sender, EventArgs e)
{
if (SecondName.Text.Length == 0 | FirstName.Text.Length == 0 | LoginRegister.Text.Length == 0 | Pasport.Text.Length == 0 | PasswordRegister.Text.Length == 0 | PasswordRepitReg.Text.Length == 0)
{
WarningLabel.Text = "Заполненны не все поля!"; return;
}
string mySelectQueryFIO = "SELECT idПользователя FROM Пользователь " + "WHERE [Фамилия]&[Имя]&[Отчество] = '" + SecondName.Text + FirstName.Text +
MiddleName.Text + "'";
string mySelectQueryPassport = "SELECT idПользователя FROM Пользователь " + "WHERE Паспорт = '" + Pasport.Text + "'";
string mySelectQueryMail = "SELECT idПользователя FROM Пользователь " + "WHERE Логин = '" + LoginRegister.Text + "'";
DataTable dt = Select(mySelectQueryFIO); if (dt.Rows.Count != 0)
{
WarningLabel.Text = "Ползователь с таким именем уже есть!"; return;
}
dt = Select(mySelectQueryPassport); if (dt.Rows.Count != 0)
{
WarningLabel.Text = "Ползователь с таким паспортом уже есть!"; return;
}
dt = Select(mySelectQueryMail); if (dt.Rows.Count != 0)
{
WarningLabel.Text = "Ползователь с таким логином уже есть!"; return;
}
string InsertSqlQ = "INSERT INTO Пользователь(Фамилия, Имя, Отчество, Адрес, Паспорт, Логин, Пароль) " +
"VALUES(" + TextToSqlParam(SecondName.Text) + "," + TextToSqlParam(FirstName.Text) + "," +
TextToSqlParam(MiddleName.Text) + "," + TextToSqlParam(Adress.Text) + "," + TextToSqlParam(Pasport.Text) + "," + TextToSqlParam(LoginRegister.Text) + "," +
TextToSqlParam(PasswordRegister.Text) + ")";
var connect = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Egor\\source\\repos\\Post.mdb");
connect.Open();
var mycom = new OleDbCommand(); mycom.CommandText = InsertSqlQ; mycom.Connection = connect; mycom.ExecuteNonQuery(); connect.Close();
Response.Redirect("Authorization.aspx");
}
}
}
Листинг 8 – Код файла PersonalArea.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="PersonalArea.aspx.cs" Inherits="PostSite.PersonalArea" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <div class="container px-4">
<div class="text-center mb-4 "> <h1>Личный кабинет</h1>
</div>
<div class="text-center mb-4 "> <h3>Личные данные</h3> <p>
<asp:Label ID="Label1" runat="server" Text="ФИО:"></asp:Label>
<asp:Label ID="fio" runat="server" Text=""></asp:Label> </p>
<p>
<asp:Label ID="Label4" runat="server" Text="Паспорт:"></asp:Label>
<asp:Label ID="passport" runat="server" Text=""></asp:Label> </p>
<h3>Адрес</h3>
<p>
<asp:Label ID="Label2" runat="server" Text="Почтовый индекс:"></asp:Label>
<asp:Label ID="postindex" runat="server" Text=""></asp:Label> </p>
<p>
<asp:Label ID="adress" runat="server" Text=""></asp:Label> </p>
<p>
<asp:Button ID="LogoutButton" runat="server" Text="Выйти из аккаунта"
OnClick="LogoutButton_Click" /> </p>
</div>
</div>
</asp:Content>
Листинг 9 – Код файла PersonalArea.aspx.cs
using System;
using System.Collections.Generic; using System.Data.OleDb;
using System.Data; using System.Linq; using System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
namespace PostSite
{
public partial class PersonalArea : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["userID"] is null)
{
return;
}
string mySelectQuery = "SELECT [Фамилия]&' '&[Имя]&' '&[Отчество] as fio, [Паспорт] as passport, [ПочтовыйИндекс] as postindex, [Адрес] as address FROM Пользователь WHERE [idПользователя] = " + Session["userID"];
OleDbConnection myConnection = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Connection PostBD"].ConnectionString);
OleDbDataAdapter adapter = new OleDbDataAdapter(mySelectQuery, myConnection); DataTable dt = new DataTable();
myConnection.Open();
adapter.Fill(dt);
myConnection.Close();
fio.Text = dt.Rows[0]["fio"].ToString(); passport.Text = dt.Rows[0]["passport"].ToString(); postindex.Text = dt.Rows[0]["postindex"].ToString(); adress.Text = dt.Rows[0]["address"].ToString();
}
protected void LogoutButton_Click(object sender, EventArgs e)
{
Session.Abandon();
Response.Redirect("Authorization.aspx");
}
}
}
Листинг 10 – Код файла Delivery.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Delivery.aspx.cs" Inherits="PostSite.Delivery" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <div class="container px-4">
<div class="text-center mb-4 "> <h1>
Доставки
</h1>
<asp:Label ID="WarningText" Font-Bold="True" ForeColor="Red" Visible="false" runat="server" Text="Авторизуйтель чтобы посмотреть заказы"></asp:Label>
</div>
<div>
<asp:DropDownList ID="DropDownList1" runat="server" DataTextField="userFIO"
DataValueField="idПользователя"
DataSourceID="users"
>
</asp:DropDownList>
<asp:SqlDataSource runat="server" ID="users" ConnectionString="<%$ ConnectionStrings:ConnectionPostBD %>"
ProviderName="<%$ ConnectionStrings:ConnectionPostBD.ProviderName %>" SelectCommand="SELECT TOP 1 -1 as idПользователя, 'Все Пользователи' as userFIO
from Статус UNION ALL SELECT [idПользователя], [Фамилия]&' '&[Имя]&' '&[Отчество] as userFIO FROM [Пользователь]">
</asp:SqlDataSource>
<asp:DropDownList ID="DropDownList2" runat="server"
DataTextField="Название"
DataValueField="idСтатуса"
DataSourceID="status">
</asp:DropDownList>
<asp:SqlDataSource runat="server" ID="status" ConnectionString="<%$ ConnectionStrings:ConnectionPostBD %>"
ProviderName="<%$ ConnectionStrings:ConnectionPostBD.ProviderName %>" SelectCommand="SELECT TOP 1 'Все Статусы' as Название, -1 as idСтатуса from
Статус UNION ALL SELECT [Название], [idСтатуса] FROM [Статус]">
</asp:SqlDataSource>
<asp:DropDownList ID="DropDownList3" runat="server"
DataTextField="Название"