This commit is contained in:
Tonb73 2024-11-25 09:21:34 +03:00
parent 3fb820cd28
commit 546df058a6
6 changed files with 113 additions and 32 deletions

View File

@ -9,18 +9,20 @@ namespace ProjectTourAgency.Enities;
public class Client public class Client
{ {
public int Id { get;private set; } public int Id { get; private set; }
public string FullName { get; private set; } = string.Empty; public string FullName { get; private set; } = string.Empty;
public DateTime BirthDate { get; private set; } public DateTime BirthDate { get; private set; }
public string PhoneNumber { get; private set; } = string.Empty; public string PhoneNumber { get; private set; } = string.Empty;
public ClientStatus ClientStatus { get; private set; }
public int Money { get; private set; } public int Money { get; private set; }
public static Client CreateEntity(int id, string fullName, public static Client CreateEntity(int id, string fullName,
DateTime birthDate, string phoneNumber, int money) DateTime birthDate, string phoneNumber, int money, ClientStatus cs)
{ {
return new Client return new Client
{ {
Id = id, Id = id,
ClientStatus = cs,
FullName = fullName, FullName = fullName,
BirthDate = birthDate, BirthDate = birthDate,
PhoneNumber = phoneNumber, PhoneNumber = phoneNumber,

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTourAgency.Enities.Enums;
[Flags]
public enum ClientStatus
{
None = 0,
RegularCustomer = 1,
AgressiveCustomer = 2,
FriendlyCustomer = 3,
VIPCustomer = 4
}

View File

@ -38,77 +38,88 @@
textBoxMoney = new TextBox(); textBoxMoney = new TextBox();
buttonSave = new Button(); buttonSave = new Button();
buttonCancel = new Button(); buttonCancel = new Button();
label1 = new Label();
checkedListBoxClientStatus = new CheckedListBox();
SuspendLayout(); SuspendLayout();
// //
// labelName // labelName
// //
labelName.AutoSize = true; labelName.AutoSize = true;
labelName.Location = new Point(12, 9); labelName.Location = new Point(17, 15);
labelName.Margin = new Padding(4, 0, 4, 0);
labelName.Name = "labelName"; labelName.Name = "labelName";
labelName.Size = new Size(75, 15); labelName.Size = new Size(112, 25);
labelName.TabIndex = 0; labelName.TabIndex = 0;
labelName.Text = "Полное имя"; labelName.Text = "Полное имя";
// //
// labelDate // labelDate
// //
labelDate.AutoSize = true; labelDate.AutoSize = true;
labelDate.Location = new Point(12, 45); labelDate.Location = new Point(17, 75);
labelDate.Margin = new Padding(4, 0, 4, 0);
labelDate.Name = "labelDate"; labelDate.Name = "labelDate";
labelDate.Size = new Size(90, 15); labelDate.Size = new Size(137, 25);
labelDate.TabIndex = 1; labelDate.TabIndex = 1;
labelDate.Text = "Дата рождения"; labelDate.Text = "Дата рождения";
// //
// labelNumber // labelNumber
// //
labelNumber.AutoSize = true; labelNumber.AutoSize = true;
labelNumber.Location = new Point(12, 88); labelNumber.Location = new Point(17, 147);
labelNumber.Margin = new Padding(4, 0, 4, 0);
labelNumber.Name = "labelNumber"; labelNumber.Name = "labelNumber";
labelNumber.Size = new Size(101, 15); labelNumber.Size = new Size(150, 25);
labelNumber.TabIndex = 2; labelNumber.TabIndex = 2;
labelNumber.Text = "Номер телефона"; labelNumber.Text = "Номер телефона";
// //
// labelMoney // labelMoney
// //
labelMoney.AutoSize = true; labelMoney.AutoSize = true;
labelMoney.Location = new Point(12, 128); labelMoney.Location = new Point(17, 213);
labelMoney.Margin = new Padding(4, 0, 4, 0);
labelMoney.Name = "labelMoney"; labelMoney.Name = "labelMoney";
labelMoney.Size = new Size(46, 15); labelMoney.Size = new Size(67, 25);
labelMoney.TabIndex = 3; labelMoney.TabIndex = 3;
labelMoney.Text = "Баланс"; labelMoney.Text = "Баланс";
// //
// textBoxName // textBoxName
// //
textBoxName.Location = new Point(131, 9); textBoxName.Location = new Point(187, 15);
textBoxName.Margin = new Padding(4, 5, 4, 5);
textBoxName.Name = "textBoxName"; textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(100, 23); textBoxName.Size = new Size(231, 31);
textBoxName.TabIndex = 4; textBoxName.TabIndex = 4;
// //
// dateTimePickerDate // dateTimePickerDate
// //
dateTimePickerDate.Location = new Point(131, 45); dateTimePickerDate.Location = new Point(187, 75);
dateTimePickerDate.Margin = new Padding(4, 5, 4, 5);
dateTimePickerDate.Name = "dateTimePickerDate"; dateTimePickerDate.Name = "dateTimePickerDate";
dateTimePickerDate.Size = new Size(200, 23); dateTimePickerDate.Size = new Size(231, 31);
dateTimePickerDate.TabIndex = 5; dateTimePickerDate.TabIndex = 5;
// //
// textBoxNumber // textBoxNumber
// //
textBoxNumber.Location = new Point(131, 85); textBoxNumber.Location = new Point(187, 142);
textBoxNumber.Margin = new Padding(4, 5, 4, 5);
textBoxNumber.Name = "textBoxNumber"; textBoxNumber.Name = "textBoxNumber";
textBoxNumber.Size = new Size(100, 23); textBoxNumber.Size = new Size(231, 31);
textBoxNumber.TabIndex = 6; textBoxNumber.TabIndex = 6;
// //
// textBoxMoney // textBoxMoney
// //
textBoxMoney.Location = new Point(131, 125); textBoxMoney.Location = new Point(187, 208);
textBoxMoney.Margin = new Padding(4, 5, 4, 5);
textBoxMoney.Name = "textBoxMoney"; textBoxMoney.Name = "textBoxMoney";
textBoxMoney.Size = new Size(100, 23); textBoxMoney.Size = new Size(231, 31);
textBoxMoney.TabIndex = 7; textBoxMoney.TabIndex = 7;
// //
// buttonSave // buttonSave
// //
buttonSave.Location = new Point(49, 198); buttonSave.Location = new Point(60, 421);
buttonSave.Margin = new Padding(4, 5, 4, 5);
buttonSave.Name = "buttonSave"; buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(75, 23); buttonSave.Size = new Size(107, 38);
buttonSave.TabIndex = 8; buttonSave.TabIndex = 8;
buttonSave.Text = "Сохранить"; buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true; buttonSave.UseVisualStyleBackColor = true;
@ -116,19 +127,40 @@
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(173, 198); buttonCancel.Location = new Point(371, 421);
buttonCancel.Margin = new Padding(4, 5, 4, 5);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23); buttonCancel.Size = new Size(107, 38);
buttonCancel.TabIndex = 9; buttonCancel.TabIndex = 9;
buttonCancel.Text = "Отменить"; buttonCancel.Text = "Отменить";
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click; buttonCancel.Click += buttonCancel_Click;
// //
// label1
//
label1.AutoSize = true;
label1.Location = new Point(17, 295);
label1.Margin = new Padding(4, 0, 4, 0);
label1.Name = "label1";
label1.Size = new Size(135, 25);
label1.TabIndex = 10;
label1.Text = "Статус КЛиента";
//
// checkedListBoxClientStatus
//
checkedListBoxClientStatus.FormattingEnabled = true;
checkedListBoxClientStatus.Location = new Point(187, 280);
checkedListBoxClientStatus.Name = "checkedListBoxClientStatus";
checkedListBoxClientStatus.Size = new Size(231, 88);
checkedListBoxClientStatus.TabIndex = 11;
//
// FormClient // FormClient
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(389, 251); ClientSize = new Size(517, 479);
Controls.Add(checkedListBoxClientStatus);
Controls.Add(label1);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonSave); Controls.Add(buttonSave);
Controls.Add(textBoxMoney); Controls.Add(textBoxMoney);
@ -139,6 +171,7 @@
Controls.Add(labelNumber); Controls.Add(labelNumber);
Controls.Add(labelDate); Controls.Add(labelDate);
Controls.Add(labelName); Controls.Add(labelName);
Margin = new Padding(4, 5, 4, 5);
Name = "FormClient"; Name = "FormClient";
Text = "FormClient"; Text = "FormClient";
ResumeLayout(false); ResumeLayout(false);
@ -157,5 +190,7 @@
private TextBox textBoxMoney; private TextBox textBoxMoney;
private Button buttonSave; private Button buttonSave;
private Button buttonCancel; private Button buttonCancel;
private Label label1;
private CheckedListBox checkedListBoxClientStatus;
} }
} }

View File

@ -1,6 +1,7 @@
 
using ProjectRouteAgency.Repositories; using ProjectRouteAgency.Repositories;
using ProjectTourAgency.Enities; using ProjectTourAgency.Enities;
using ProjectTourAgency.Enities.Enums;
using ProjectTourAgency.Implementations; using ProjectTourAgency.Implementations;
using ProjectTourAgency.Repositories; using ProjectTourAgency.Repositories;
using System; using System;
@ -35,6 +36,17 @@ namespace ProjectTourAgency.Forms
textBoxNumber.Text = client.PhoneNumber; textBoxNumber.Text = client.PhoneNumber;
textBoxMoney.Text = client.Money.ToString(); textBoxMoney.Text = client.Money.ToString();
dateTimePickerDate.Value = client.BirthDate; dateTimePickerDate.Value = client.BirthDate;
foreach (ClientStatus elem in
Enum.GetValues(typeof(ClientStatus)))
{
if ((elem & client.ClientStatus) != 0)
{
checkedListBoxClientStatus.SetItemChecked(checkedListBoxClientStatus.Items.IndexOf(
elem), true);
}
}
_clientId = value; _clientId = value;
} }
catch (Exception ex) catch (Exception ex)
@ -50,7 +62,10 @@ namespace ProjectTourAgency.Forms
InitializeComponent(); InitializeComponent();
_clientRepository = clientRepository ?? _clientRepository = clientRepository ??
throw new ArgumentNullException(nameof(clientRepository)); throw new ArgumentNullException(nameof(clientRepository));
foreach (var elem in Enum.GetValues(typeof(ClientStatus)))
{
checkedListBoxClientStatus.Items.Add(elem);
}
} }
private void buttonSave_Click(object sender, EventArgs e) private void buttonSave_Click(object sender, EventArgs e)
@ -59,7 +74,8 @@ namespace ProjectTourAgency.Forms
{ {
if (string.IsNullOrWhiteSpace(textBoxName.Text) || if (string.IsNullOrWhiteSpace(textBoxName.Text) ||
string.IsNullOrWhiteSpace(textBoxNumber.Text) string.IsNullOrWhiteSpace(textBoxNumber.Text)
|| string.IsNullOrWhiteSpace(textBoxMoney.Text) || string.IsNullOrWhiteSpace(dateTimePickerDate.Text)) || string.IsNullOrWhiteSpace(textBoxMoney.Text) || string.IsNullOrWhiteSpace(dateTimePickerDate.Text)
|| checkedListBoxClientStatus.CheckedItems.Count == 0)
{ {
throw new Exception("Имеются незаполненные поля"); throw new Exception("Имеются незаполненные поля");
} }
@ -83,6 +99,15 @@ namespace ProjectTourAgency.Forms
private void buttonCancel_Click(object sender, EventArgs e) => Close(); private void buttonCancel_Click(object sender, EventArgs e) => Close();
private Client CreateClient(int id) => Client.CreateEntity(id, textBoxName.Text, dateTimePickerDate.Value,textBoxNumber.Text, Convert.ToInt32(textBoxMoney.Text)); private Client CreateClient(int id)
{
ClientStatus clientStatus = ClientStatus.None;
foreach (var elem in checkedListBoxClientStatus.CheckedItems)
{
clientStatus |= (ClientStatus)elem;
}
return Client.CreateEntity(id, textBoxName.Text, dateTimePickerDate.Value, textBoxNumber.Text,
int.Parse(textBoxMoney.Text), clientStatus);
}
} }
} }

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<root> <root>
<!-- <!--
Microsoft ResX Schema Microsoft ResX Schema
Version 2.0 Version 2.0
@ -48,7 +48,7 @@
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64 mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter : System.Runtime.Serialization.Formatters.Soap.SoapFormatter

View File

@ -30,8 +30,8 @@ public class ClientRepository : IClientRepository
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @" var queryInsert = @"
INSERT INTO Clients (FullName, BirthDate, PhoneNumber, Money) INSERT INTO Clients (FullName, BirthDate, PhoneNumber, Money, ClientStatus)
VALUES (@FullName, @BirthDate, @PhoneNumber, @Money)"; VALUES (@FullName, @BirthDate, @PhoneNumber, @Money, @ClientStatus)";
connection.Execute(queryInsert, client); connection.Execute(queryInsert, client);
} }
@ -117,7 +117,8 @@ SET
FullName = @FullName, FullName = @FullName,
BirthDate = @BirthDate, BirthDate = @BirthDate,
PhoneNumber = @PhoneNumber, PhoneNumber = @PhoneNumber,
Money = @Money Money = @Money,
CLientStatus = @CLientStatus
WHERE Id = @Id"; WHERE Id = @Id";
connection.Execute(queryUpdate, client); connection.Execute(queryUpdate, client);
} }