From a27716ccedf11c033fcd1140fd0e15b2cf8230a1 Mon Sep 17 00:00:00 2001 From: "nikbel2004@outlook.com" Date: Wed, 27 Mar 2024 10:03:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=204=20=D0=BF=D0=BE=20=D0=A1=D0=A3=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BulletinBoard/BulletinBoard.sln | 25 + .../AbstractManagmentDatabase.cs | 23 + .../AdsForm/CreateAdsForm.Designer.cs | 274 +++++++++++ .../BulletinBoard/AdsForm/CreateAdsForm.cs | 103 ++++ .../BulletinBoard/AdsForm/CreateAdsForm.resx | 120 +++++ .../AdsForm/DeleteAdsForm.Designer.cs | 84 ++++ .../BulletinBoard/AdsForm/DeleteAdsForm.cs | 71 +++ .../BulletinBoard/AdsForm/DeleteAdsForm.resx | 60 +++ .../AdsForm/ListAdsForm.Designer.cs | 74 +++ .../BulletinBoard/AdsForm/ListAdsForm.cs | 50 ++ .../BulletinBoard/AdsForm/ListAdsForm.resx | 60 +++ .../AdsForm/UpdateAdsForm.Designer.cs | 251 ++++++++++ .../BulletinBoard/AdsForm/UpdateAdsForm.cs | 154 ++++++ .../BulletinBoard/AdsForm/UpdateAdsForm.resx | 120 +++++ .../BulletinBoard/BulletinBoard.csproj | 21 + .../CreateCategoriesForm.Designer.cs | 86 ++++ .../CategoriesForm/CreateCategoriesForm.cs | 35 ++ .../CategoriesForm/CreateCategoriesForm.resx | 60 +++ .../DeleteCategoriesForm.Designer.cs | 87 ++++ .../CategoriesForm/DeleteCategoriesForm.cs | 61 +++ .../CategoriesForm/DeleteCategoriesForm.resx | 60 +++ .../ListCategoriesForm.Designer.cs | 75 +++ .../CategoriesForm/ListCategoriesForm.cs | 42 ++ .../CategoriesForm/ListCategoriesForm.resx | 60 +++ .../UpdateCategoriesForm.Designer.cs | 110 +++++ .../CategoriesForm/UpdateCategoriesForm.cs | 86 ++++ .../CategoriesForm/UpdateCategoriesForm.resx | 60 +++ .../CitiesForm/CreateCitiesForm.Designer.cs | 109 +++++ .../CitiesForm/CreateCitiesForm.cs | 56 +++ .../CitiesForm/CreateCitiesForm.resx | 120 +++++ .../CitiesForm/DeleteCitiesForm.Designer.cs | 86 ++++ .../CitiesForm/DeleteCitiesForm.cs | 61 +++ .../CitiesForm/DeleteCitiesForm.resx | 120 +++++ .../CitiesForm/ListCitiesForm.Designer.cs | 74 +++ .../CitiesForm/ListCitiesForm.cs | 42 ++ .../CitiesForm/ListCitiesForm.resx | 120 +++++ .../CitiesForm/UpdateCitiesForm.Designer.cs | 111 +++++ .../CitiesForm/UpdateCitiesForm.cs | 86 ++++ .../CitiesForm/UpdateCitiesForm.resx | 120 +++++ .../ClientsForm/CreateClientsForm.Designer.cs | 201 ++++++++ .../ClientsForm/CreateClientsForm.cs | 45 ++ .../ClientsForm/CreateClientsForm.resx | 60 +++ .../ClientsForm/DeleteClientsForm.Designer.cs | 87 ++++ .../ClientsForm/DeleteClientsForm.cs | 68 +++ .../ClientsForm/DeleteClientsForm.resx | 60 +++ .../ClientsForm/ListClientsForm.Designer.cs | 75 +++ .../ClientsForm/ListClientsForm.cs | 48 ++ .../ClientsForm/ListClientsForm.resx | 60 +++ .../ClientsForm/UpdateClientsForm.Designer.cs | 225 +++++++++ .../ClientsForm/UpdateClientsForm.cs | 110 +++++ .../ClientsForm/UpdateClientsForm.resx | 60 +++ .../BulletinBoard/MainForm.Designer.cs | 448 ++++++++++++++++++ BulletinBoard/BulletinBoard/MainForm.cs | 205 ++++++++ BulletinBoard/BulletinBoard/MainForm.resx | 123 +++++ .../BulletinBoard/ManagmentDatabase.cs | 85 ++++ BulletinBoard/BulletinBoard/Program.cs | 17 + .../RegionsForm/CreateRegionsForm.Designer.cs | 82 ++++ .../RegionsForm/CreateRegionsForm.cs | 40 ++ .../RegionsForm/CreateRegionsForm.resx | 120 +++++ .../RegionsForm/DeleteRegionsForm.Designer.cs | 86 ++++ .../RegionsForm/DeleteRegionsForm.cs | 61 +++ .../RegionsForm/DeleteRegionsForm.resx | 120 +++++ .../RegionsForm/ListRegionsForm.Designer.cs | 74 +++ .../RegionsForm/ListRegionsForm.cs | 42 ++ .../RegionsForm/ListRegionsForm.resx | 120 +++++ .../RegionsForm/UpdateRegionsForm.Designer.cs | 109 +++++ .../RegionsForm/UpdateRegionsForm.cs | 86 ++++ .../RegionsForm/UpdateRegionsForm.resx | 120 +++++ .../CreateSubcategoriesForm.Designer.cs | 109 +++++ .../CreateSubcategoriesForm.cs | 56 +++ .../CreateSubcategoriesForm.resx | 120 +++++ .../DeleteSubcategoriesForm.Designer.cs | 87 ++++ .../DeleteSubcategoriesForm.cs | 61 +++ .../DeleteSubcategoriesForm.resx | 60 +++ .../ListSubcategoriesForm.Designer.cs | 75 +++ .../ListSubcategoriesForm.cs | 42 ++ .../ListSubcategoriesForm.resx | 60 +++ .../UpdateSubcategoriesForm.Designer.cs | 111 +++++ .../UpdateSubcategoriesForm.cs | 88 ++++ .../UpdateSubcategoriesForm.resx | 60 +++ 80 files changed, 7383 insertions(+) create mode 100644 BulletinBoard/BulletinBoard.sln create mode 100644 BulletinBoard/BulletinBoard/AbstractManagmentDatabase.cs create mode 100644 BulletinBoard/BulletinBoard/AdsForm/CreateAdsForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/AdsForm/CreateAdsForm.cs create mode 100644 BulletinBoard/BulletinBoard/AdsForm/CreateAdsForm.resx create mode 100644 BulletinBoard/BulletinBoard/AdsForm/DeleteAdsForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/AdsForm/DeleteAdsForm.cs create mode 100644 BulletinBoard/BulletinBoard/AdsForm/DeleteAdsForm.resx create mode 100644 BulletinBoard/BulletinBoard/AdsForm/ListAdsForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/AdsForm/ListAdsForm.cs create mode 100644 BulletinBoard/BulletinBoard/AdsForm/ListAdsForm.resx create mode 100644 BulletinBoard/BulletinBoard/AdsForm/UpdateAdsForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/AdsForm/UpdateAdsForm.cs create mode 100644 BulletinBoard/BulletinBoard/AdsForm/UpdateAdsForm.resx create mode 100644 BulletinBoard/BulletinBoard/BulletinBoard.csproj create mode 100644 BulletinBoard/BulletinBoard/CategoriesForm/CreateCategoriesForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/CategoriesForm/CreateCategoriesForm.cs create mode 100644 BulletinBoard/BulletinBoard/CategoriesForm/CreateCategoriesForm.resx create mode 100644 BulletinBoard/BulletinBoard/CategoriesForm/DeleteCategoriesForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/CategoriesForm/DeleteCategoriesForm.cs create mode 100644 BulletinBoard/BulletinBoard/CategoriesForm/DeleteCategoriesForm.resx create mode 100644 BulletinBoard/BulletinBoard/CategoriesForm/ListCategoriesForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/CategoriesForm/ListCategoriesForm.cs create mode 100644 BulletinBoard/BulletinBoard/CategoriesForm/ListCategoriesForm.resx create mode 100644 BulletinBoard/BulletinBoard/CategoriesForm/UpdateCategoriesForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/CategoriesForm/UpdateCategoriesForm.cs create mode 100644 BulletinBoard/BulletinBoard/CategoriesForm/UpdateCategoriesForm.resx create mode 100644 BulletinBoard/BulletinBoard/CitiesForm/CreateCitiesForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/CitiesForm/CreateCitiesForm.cs create mode 100644 BulletinBoard/BulletinBoard/CitiesForm/CreateCitiesForm.resx create mode 100644 BulletinBoard/BulletinBoard/CitiesForm/DeleteCitiesForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/CitiesForm/DeleteCitiesForm.cs create mode 100644 BulletinBoard/BulletinBoard/CitiesForm/DeleteCitiesForm.resx create mode 100644 BulletinBoard/BulletinBoard/CitiesForm/ListCitiesForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/CitiesForm/ListCitiesForm.cs create mode 100644 BulletinBoard/BulletinBoard/CitiesForm/ListCitiesForm.resx create mode 100644 BulletinBoard/BulletinBoard/CitiesForm/UpdateCitiesForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/CitiesForm/UpdateCitiesForm.cs create mode 100644 BulletinBoard/BulletinBoard/CitiesForm/UpdateCitiesForm.resx create mode 100644 BulletinBoard/BulletinBoard/ClientsForm/CreateClientsForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/ClientsForm/CreateClientsForm.cs create mode 100644 BulletinBoard/BulletinBoard/ClientsForm/CreateClientsForm.resx create mode 100644 BulletinBoard/BulletinBoard/ClientsForm/DeleteClientsForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/ClientsForm/DeleteClientsForm.cs create mode 100644 BulletinBoard/BulletinBoard/ClientsForm/DeleteClientsForm.resx create mode 100644 BulletinBoard/BulletinBoard/ClientsForm/ListClientsForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/ClientsForm/ListClientsForm.cs create mode 100644 BulletinBoard/BulletinBoard/ClientsForm/ListClientsForm.resx create mode 100644 BulletinBoard/BulletinBoard/ClientsForm/UpdateClientsForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/ClientsForm/UpdateClientsForm.cs create mode 100644 BulletinBoard/BulletinBoard/ClientsForm/UpdateClientsForm.resx create mode 100644 BulletinBoard/BulletinBoard/MainForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/MainForm.cs create mode 100644 BulletinBoard/BulletinBoard/MainForm.resx create mode 100644 BulletinBoard/BulletinBoard/ManagmentDatabase.cs create mode 100644 BulletinBoard/BulletinBoard/Program.cs create mode 100644 BulletinBoard/BulletinBoard/RegionsForm/CreateRegionsForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/RegionsForm/CreateRegionsForm.cs create mode 100644 BulletinBoard/BulletinBoard/RegionsForm/CreateRegionsForm.resx create mode 100644 BulletinBoard/BulletinBoard/RegionsForm/DeleteRegionsForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/RegionsForm/DeleteRegionsForm.cs create mode 100644 BulletinBoard/BulletinBoard/RegionsForm/DeleteRegionsForm.resx create mode 100644 BulletinBoard/BulletinBoard/RegionsForm/ListRegionsForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/RegionsForm/ListRegionsForm.cs create mode 100644 BulletinBoard/BulletinBoard/RegionsForm/ListRegionsForm.resx create mode 100644 BulletinBoard/BulletinBoard/RegionsForm/UpdateRegionsForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/RegionsForm/UpdateRegionsForm.cs create mode 100644 BulletinBoard/BulletinBoard/RegionsForm/UpdateRegionsForm.resx create mode 100644 BulletinBoard/BulletinBoard/SubcategoriesForm/CreateSubcategoriesForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/SubcategoriesForm/CreateSubcategoriesForm.cs create mode 100644 BulletinBoard/BulletinBoard/SubcategoriesForm/CreateSubcategoriesForm.resx create mode 100644 BulletinBoard/BulletinBoard/SubcategoriesForm/DeleteSubcategoriesForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/SubcategoriesForm/DeleteSubcategoriesForm.cs create mode 100644 BulletinBoard/BulletinBoard/SubcategoriesForm/DeleteSubcategoriesForm.resx create mode 100644 BulletinBoard/BulletinBoard/SubcategoriesForm/ListSubcategoriesForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/SubcategoriesForm/ListSubcategoriesForm.cs create mode 100644 BulletinBoard/BulletinBoard/SubcategoriesForm/ListSubcategoriesForm.resx create mode 100644 BulletinBoard/BulletinBoard/SubcategoriesForm/UpdateSubcategoriesForm.Designer.cs create mode 100644 BulletinBoard/BulletinBoard/SubcategoriesForm/UpdateSubcategoriesForm.cs create mode 100644 BulletinBoard/BulletinBoard/SubcategoriesForm/UpdateSubcategoriesForm.resx diff --git a/BulletinBoard/BulletinBoard.sln b/BulletinBoard/BulletinBoard.sln new file mode 100644 index 0000000..bfb0582 --- /dev/null +++ b/BulletinBoard/BulletinBoard.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34622.214 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BulletinBoard", "BulletinBoard\BulletinBoard.csproj", "{262F1FD4-C5DD-42F3-B47A-8CB10414C3DE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {262F1FD4-C5DD-42F3-B47A-8CB10414C3DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {262F1FD4-C5DD-42F3-B47A-8CB10414C3DE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {262F1FD4-C5DD-42F3-B47A-8CB10414C3DE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {262F1FD4-C5DD-42F3-B47A-8CB10414C3DE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {66435ADB-84E8-4E5D-9E06-34B5125842AE} + EndGlobalSection +EndGlobal diff --git a/BulletinBoard/BulletinBoard/AbstractManagmentDatabase.cs b/BulletinBoard/BulletinBoard/AbstractManagmentDatabase.cs new file mode 100644 index 0000000..a1f41a5 --- /dev/null +++ b/BulletinBoard/BulletinBoard/AbstractManagmentDatabase.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WebsiteForPlacingAds +{ + public abstract class AbstractManagmentDatabase + { + public abstract DataTable getEntryById(string tableName, int id); + public abstract Object getRowTableById(string tableName, string columnName, int id); + public abstract Object getRowTableById(DataTable table, string columnName, int i); + public abstract void ExecuteNonQuery(string query); + public abstract DataTable ExecuteQuery(string query); + public abstract DataTable getAllEntry(string tableName); + public abstract void insertInto(string tableName, params string[] values); + public abstract void deleteEntry(string tableName, int id); + public abstract void deleteEntry(string tableName, string name); + public abstract void reduceSeq(string seq, int currval); + } +} diff --git a/BulletinBoard/BulletinBoard/AdsForm/CreateAdsForm.Designer.cs b/BulletinBoard/BulletinBoard/AdsForm/CreateAdsForm.Designer.cs new file mode 100644 index 0000000..4e213b5 --- /dev/null +++ b/BulletinBoard/BulletinBoard/AdsForm/CreateAdsForm.Designer.cs @@ -0,0 +1,274 @@ +namespace WebsiteForPlacingAds +{ + partial class CreateAdsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonCreateAd = new Button(); + labelHeading = new Label(); + textBoxHeading = new TextBox(); + textBoxPrice = new TextBox(); + labelPrice = new Label(); + textBoxDate = new TextBox(); + labelDate = new Label(); + labelSubcategory = new Label(); + labelCategory = new Label(); + textBoxStatus = new TextBox(); + labelStatus = new Label(); + labelClient = new Label(); + comboBoxSubcategory = new ComboBox(); + comboBoxCategory = new ComboBox(); + comboBoxClient = new ComboBox(); + label1 = new Label(); + comboBoxCity = new ComboBox(); + label2 = new Label(); + comboBoxRegion = new ComboBox(); + SuspendLayout(); + // + // buttonCreateAd + // + buttonCreateAd.Location = new Point(43, 443); + buttonCreateAd.Margin = new Padding(3, 2, 3, 2); + buttonCreateAd.Name = "buttonCreateAd"; + buttonCreateAd.Size = new Size(239, 29); + buttonCreateAd.TabIndex = 0; + buttonCreateAd.Text = "Разместить объявление"; + buttonCreateAd.UseVisualStyleBackColor = true; + buttonCreateAd.Click += buttonCreateAd_Click; + // + // labelHeading + // + labelHeading.AutoSize = true; + labelHeading.Location = new Point(43, 8); + labelHeading.Name = "labelHeading"; + labelHeading.Size = new Size(65, 15); + labelHeading.TabIndex = 1; + labelHeading.Text = "Заголовок"; + // + // textBoxHeading + // + textBoxHeading.Location = new Point(43, 26); + textBoxHeading.Margin = new Padding(3, 2, 3, 2); + textBoxHeading.Name = "textBoxHeading"; + textBoxHeading.Size = new Size(239, 23); + textBoxHeading.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(43, 72); + textBoxPrice.Margin = new Padding(3, 2, 3, 2); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(239, 23); + textBoxPrice.TabIndex = 4; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(43, 55); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(35, 15); + labelPrice.TabIndex = 3; + labelPrice.Text = "Цена"; + // + // textBoxDate + // + textBoxDate.Location = new Point(43, 118); + textBoxDate.Margin = new Padding(3, 2, 3, 2); + textBoxDate.Name = "textBoxDate"; + textBoxDate.Size = new Size(239, 23); + textBoxDate.TabIndex = 6; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(43, 101); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(105, 15); + labelDate.TabIndex = 5; + labelDate.Text = "Дата размещения"; + // + // labelSubcategory + // + labelSubcategory.AutoSize = true; + labelSubcategory.Location = new Point(43, 292); + labelSubcategory.Name = "labelSubcategory"; + labelSubcategory.Size = new Size(84, 15); + labelSubcategory.TabIndex = 11; + labelSubcategory.Text = "Подкатегория"; + // + // labelCategory + // + labelCategory.AutoSize = true; + labelCategory.Location = new Point(43, 246); + labelCategory.Name = "labelCategory"; + labelCategory.Size = new Size(63, 15); + labelCategory.TabIndex = 9; + labelCategory.Text = "Категория"; + // + // textBoxStatus + // + textBoxStatus.Location = new Point(43, 166); + textBoxStatus.Margin = new Padding(3, 2, 3, 2); + textBoxStatus.Name = "textBoxStatus"; + textBoxStatus.Size = new Size(239, 23); + textBoxStatus.TabIndex = 8; + // + // labelStatus + // + labelStatus.AutoSize = true; + labelStatus.Location = new Point(43, 148); + labelStatus.Name = "labelStatus"; + labelStatus.Size = new Size(43, 15); + labelStatus.TabIndex = 7; + labelStatus.Text = "Статус"; + // + // labelClient + // + labelClient.AutoSize = true; + labelClient.Location = new Point(43, 196); + labelClient.Name = "labelClient"; + labelClient.Size = new Size(46, 15); + labelClient.TabIndex = 13; + labelClient.Text = "Клиент"; + // + // comboBoxSubcategory + // + comboBoxSubcategory.FormattingEnabled = true; + comboBoxSubcategory.Location = new Point(43, 310); + comboBoxSubcategory.Margin = new Padding(3, 2, 3, 2); + comboBoxSubcategory.Name = "comboBoxSubcategory"; + comboBoxSubcategory.Size = new Size(239, 23); + comboBoxSubcategory.TabIndex = 15; + // + // comboBoxCategory + // + comboBoxCategory.FormattingEnabled = true; + comboBoxCategory.Location = new Point(43, 263); + comboBoxCategory.Margin = new Padding(3, 2, 3, 2); + comboBoxCategory.Name = "comboBoxCategory"; + comboBoxCategory.Size = new Size(239, 23); + comboBoxCategory.TabIndex = 16; + // + // comboBoxClient + // + comboBoxClient.FormattingEnabled = true; + comboBoxClient.Location = new Point(43, 213); + comboBoxClient.Margin = new Padding(3, 2, 3, 2); + comboBoxClient.Name = "comboBoxClient"; + comboBoxClient.Size = new Size(239, 23); + comboBoxClient.TabIndex = 17; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(43, 341); + label1.Name = "label1"; + label1.Size = new Size(46, 15); + label1.TabIndex = 22; + label1.Text = "Регион"; + // + // comboBoxCity + // + comboBoxCity.FormattingEnabled = true; + comboBoxCity.Location = new Point(43, 400); + comboBoxCity.Margin = new Padding(3, 2, 3, 2); + comboBoxCity.Name = "comboBoxCity"; + comboBoxCity.Size = new Size(239, 23); + comboBoxCity.TabIndex = 23; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(43, 384); + label2.Name = "label2"; + label2.Size = new Size(40, 15); + label2.TabIndex = 24; + label2.Text = "Город"; + // + // comboBoxRegion + // + comboBoxRegion.FormattingEnabled = true; + comboBoxRegion.Location = new Point(43, 359); + comboBoxRegion.Margin = new Padding(3, 2, 3, 2); + comboBoxRegion.Name = "comboBoxRegion"; + comboBoxRegion.Size = new Size(239, 23); + comboBoxRegion.TabIndex = 25; + // + // CreateAdsForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(324, 483); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(comboBoxRegion); + Controls.Add(comboBoxCity); + Controls.Add(comboBoxClient); + Controls.Add(comboBoxCategory); + Controls.Add(comboBoxSubcategory); + Controls.Add(labelClient); + Controls.Add(labelSubcategory); + Controls.Add(labelCategory); + Controls.Add(textBoxStatus); + Controls.Add(labelStatus); + Controls.Add(textBoxDate); + Controls.Add(labelDate); + Controls.Add(textBoxPrice); + Controls.Add(labelPrice); + Controls.Add(textBoxHeading); + Controls.Add(labelHeading); + Controls.Add(buttonCreateAd); + Margin = new Padding(3, 2, 3, 2); + Name = "CreateAdsForm"; + Text = "Объявления"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCreateAd; + private Label labelHeading; + private TextBox textBoxHeading; + private TextBox textBoxPrice; + private Label labelPrice; + private TextBox textBoxDate; + private Label labelDate; + private Label labelSubcategory; + private Label labelCategory; + private TextBox textBoxStatus; + private Label labelStatus; + private Label labelClient; + private ComboBox comboBoxSubcategory; + private ComboBox comboBoxCategory; + private ComboBox comboBoxClient; + private Label label1; + private ComboBox comboBoxRegion; + private Label label2; + private ComboBox comboBoxCity; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/AdsForm/CreateAdsForm.cs b/BulletinBoard/BulletinBoard/AdsForm/CreateAdsForm.cs new file mode 100644 index 0000000..15ed31c --- /dev/null +++ b/BulletinBoard/BulletinBoard/AdsForm/CreateAdsForm.cs @@ -0,0 +1,103 @@ +using System.Data; + +namespace WebsiteForPlacingAds +{ + public partial class CreateAdsForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public CreateAdsForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void buttonCreateAd_Click(object sender, EventArgs e) + { + string[] client = comboBoxClient.SelectedItem.ToString().Split(" "); + string[] category = comboBoxCategory.SelectedItem.ToString().Split(" "); + string[] subcategory = comboBoxSubcategory.SelectedItem.ToString().Split(" "); + string[] region = comboBoxCategory.SelectedItem.ToString().Split(" "); + string[] city = comboBoxSubcategory.SelectedItem.ToString().Split(" "); + + string heading = textBoxHeading.Text; + string price = textBoxPrice.Text; + string date = textBoxDate.Text; + string status = textBoxStatus.Text; + string client_id = client[0]; + string category_id = category[0]; + string subcategory_id = subcategory[0]; + string region_id = region[0]; + string city_id = city[0]; + + try + { + DateTime start = DateTime.Now; + + managmentDatabase.insertInto("ads", $"'{heading}'", price, $"'{date}'", $"'{status}'", client_id, category_id, subcategory_id, region_id, city_id); + MessageBox.Show("!"); + LoadData(); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"! : {duration.TotalMilliseconds} "); + + // + this.Close(); + } + catch (Exception ex) + { + MessageBox.Show(" "); + } + } + + private void LoadData() + { + comboBoxCategory.Items.Clear(); + comboBoxSubcategory.Items.Clear(); + comboBoxClient.Items.Clear(); + comboBoxRegion.Items.Clear(); + comboBoxCity.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("CATEGORIES"); + string[] id_names = new string[result.Rows.Count]; + for (int i = 0; i < result.Rows.Count; i++) + { + id_names[i] = managmentDatabase.getRowTableById(result, "categories_id", i).ToString() + ". " + managmentDatabase.getRowTableById(result, "name", i).ToString(); + comboBoxCategory.Items.Add(id_names[i]); + } + + result = managmentDatabase.getAllEntry("SUBCATEGORIES"); + id_names = new string[result.Rows.Count]; + for (int i = 0; i < result.Rows.Count; i++) + { + id_names[i] = managmentDatabase.getRowTableById(result, "subcategories_id", i).ToString() + ". " + managmentDatabase.getRowTableById(result, "name", i).ToString(); + comboBoxSubcategory.Items.Add(id_names[i]); + } + + result = managmentDatabase.getAllEntry("CLIENTS"); + string[] id_names_surnames = new string[result.Rows.Count]; + for (int i = 0; i < result.Rows.Count; i++) + { + id_names_surnames[i] = managmentDatabase.getRowTableById(result, "clients_id", i).ToString().Trim() + ". " + managmentDatabase.getRowTableById(result, "name", i).ToString().Trim() + " " + managmentDatabase.getRowTableById(result, "surname", i).ToString().Trim(); + comboBoxClient.Items.Add(id_names_surnames[i]); + } + + result = managmentDatabase.getAllEntry("REGIONS"); + id_names = new string[result.Rows.Count]; + for (int i = 0; i < result.Rows.Count; i++) + { + id_names[i] = managmentDatabase.getRowTableById(result, "regions_id", i).ToString() + ". " + managmentDatabase.getRowTableById(result, "name", i).ToString(); + comboBoxRegion.Items.Add(id_names[i]); + } + + + result = managmentDatabase.getAllEntry("CITIES"); + id_names = new string[result.Rows.Count]; + for (int i = 0; i < result.Rows.Count; i++) + { + id_names[i] = managmentDatabase.getRowTableById(result, "cities_id", i).ToString() + ". " + managmentDatabase.getRowTableById(result, "name", i).ToString(); + comboBoxCity.Items.Add(id_names[i]); + } + } + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/AdsForm/CreateAdsForm.resx b/BulletinBoard/BulletinBoard/AdsForm/CreateAdsForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BulletinBoard/BulletinBoard/AdsForm/CreateAdsForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/AdsForm/DeleteAdsForm.Designer.cs b/BulletinBoard/BulletinBoard/AdsForm/DeleteAdsForm.Designer.cs new file mode 100644 index 0000000..ccc1e13 --- /dev/null +++ b/BulletinBoard/BulletinBoard/AdsForm/DeleteAdsForm.Designer.cs @@ -0,0 +1,84 @@ +namespace WebsiteForPlacingAds +{ + partial class DeleteAdsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.buttonDeleteAd = new System.Windows.Forms.Button(); + this.comboBoxDeleteAds = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(80, 22); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(338, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Выберите объявление, которое хотите удалить"; + // + // buttonDeleteAd + // + this.buttonDeleteAd.Location = new System.Drawing.Point(151, 113); + this.buttonDeleteAd.Name = "buttonDeleteAd"; + this.buttonDeleteAd.Size = new System.Drawing.Size(186, 37); + this.buttonDeleteAd.TabIndex = 1; + this.buttonDeleteAd.Text = "Удалить"; + this.buttonDeleteAd.UseVisualStyleBackColor = true; + this.buttonDeleteAd.Click += new System.EventHandler(this.buttonDeleteAd_Click); + // + // comboBoxDeleteAds + // + this.comboBoxDeleteAds.FormattingEnabled = true; + this.comboBoxDeleteAds.Location = new System.Drawing.Point(40, 64); + this.comboBoxDeleteAds.Name = "comboBoxDeleteAds"; + this.comboBoxDeleteAds.Size = new System.Drawing.Size(419, 28); + this.comboBoxDeleteAds.TabIndex = 2; + // + // DeleteAdsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(505, 175); + this.Controls.Add(this.comboBoxDeleteAds); + this.Controls.Add(this.buttonDeleteAd); + this.Controls.Add(this.label1); + this.Name = "DeleteAdsForm"; + this.Text = "Удалить объявление"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Button buttonDeleteAd; + private ComboBox comboBoxDeleteAds; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/AdsForm/DeleteAdsForm.cs b/BulletinBoard/BulletinBoard/AdsForm/DeleteAdsForm.cs new file mode 100644 index 0000000..a70301c --- /dev/null +++ b/BulletinBoard/BulletinBoard/AdsForm/DeleteAdsForm.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WebsiteForPlacingAds +{ + public partial class DeleteAdsForm : Form + { + AbstractManagmentDatabase managmentDatabase; + private int setval_seq; + public DeleteAdsForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void buttonDeleteAd_Click(object sender, EventArgs e) + { + string[] ads = comboBoxDeleteAds.SelectedItem.ToString().Split("|"); + string ad_id = ads[0].Trim(); + string query = $"DELETE FROM ADS WHERE ads_id = {ad_id}"; + string query_seq_reduction = $"SELECT setval('seq_ads', {setval_seq - 1});"; + try + { + DateTime start = DateTime.Now; + + managmentDatabase.deleteEntry("ads", int.Parse(ad_id)); + if (setval_seq > 0) managmentDatabase.reduceSeq("seq_ads", setval_seq); + MessageBox.Show("Удалено!"); + LoadData(); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Добавлено! Время выполнения: {duration.TotalMilliseconds} мс"); + } + catch (Exception ex) + { + MessageBox.Show("Не удалось удалить"); + } + } + public void LoadData() + { + comboBoxDeleteAds.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("ADS"); + setval_seq = result.Rows.Count; + string Ads = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + setval_seq = Math.Max(Convert.ToInt32(managmentDatabase.getRowTableById(result, "ads_id", i)), setval_seq); + Ads = managmentDatabase.getRowTableById(result, "ads_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "heading", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "price", i).ToString() + " | " + + ((DateTime)managmentDatabase.getRowTableById(result, "date_of_placement", i)).ToString("dd.MM.yyy") + " | " + + managmentDatabase.getRowTableById(result, "status", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "client_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "category_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "subcategory_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "region_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "city_id", i).ToString() + "\n"; + comboBoxDeleteAds.Items.Add(Ads); + } + } + } +} diff --git a/BulletinBoard/BulletinBoard/AdsForm/DeleteAdsForm.resx b/BulletinBoard/BulletinBoard/AdsForm/DeleteAdsForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BulletinBoard/BulletinBoard/AdsForm/DeleteAdsForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/AdsForm/ListAdsForm.Designer.cs b/BulletinBoard/BulletinBoard/AdsForm/ListAdsForm.Designer.cs new file mode 100644 index 0000000..babe88f --- /dev/null +++ b/BulletinBoard/BulletinBoard/AdsForm/ListAdsForm.Designer.cs @@ -0,0 +1,74 @@ +namespace WebsiteForPlacingAds +{ + partial class ListAdsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.labelListAds = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.BackColor = System.Drawing.SystemColors.Control; + this.label1.Font = new System.Drawing.Font("Segoe UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(186, 25); + this.label1.TabIndex = 0; + this.label1.Text = "Список объявлений"; + // + // labelListAds + // + this.labelListAds.AutoSize = true; + this.labelListAds.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.labelListAds.Location = new System.Drawing.Point(12, 47); + this.labelListAds.Name = "labelListAds"; + this.labelListAds.Size = new System.Drawing.Size(0, 23); + this.labelListAds.TabIndex = 1; + // + // ListAdsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.labelListAds); + this.Controls.Add(this.label1); + this.Name = "ListAdsForm"; + this.Text = "ListAdsForm"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label labelListAds; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/AdsForm/ListAdsForm.cs b/BulletinBoard/BulletinBoard/AdsForm/ListAdsForm.cs new file mode 100644 index 0000000..15df69f --- /dev/null +++ b/BulletinBoard/BulletinBoard/AdsForm/ListAdsForm.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Windows.Forms.VisualStyles; + +namespace WebsiteForPlacingAds +{ + public partial class ListAdsForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public ListAdsForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void LoadData() + { + DateTime start = DateTime.Now; + + DataTable result = managmentDatabase.getAllEntry("ADS"); + string listAds = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + listAds += managmentDatabase.getRowTableById(result, "ads_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "heading", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "price", i).ToString() + " | " + + ((DateTime)managmentDatabase.getRowTableById(result, "date_of_placement", i)).ToString("dd.MM.yyy") + " | " + + managmentDatabase.getRowTableById(result, "status", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "client_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "category_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "subcategory_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "region_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "city_id", i).ToString() + "\n"; + } + labelListAds.Text = listAds; + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Список загружен! Время выполнения: {duration.TotalMilliseconds} мс"); + } + } +} diff --git a/BulletinBoard/BulletinBoard/AdsForm/ListAdsForm.resx b/BulletinBoard/BulletinBoard/AdsForm/ListAdsForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BulletinBoard/BulletinBoard/AdsForm/ListAdsForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/AdsForm/UpdateAdsForm.Designer.cs b/BulletinBoard/BulletinBoard/AdsForm/UpdateAdsForm.Designer.cs new file mode 100644 index 0000000..05c5e8d --- /dev/null +++ b/BulletinBoard/BulletinBoard/AdsForm/UpdateAdsForm.Designer.cs @@ -0,0 +1,251 @@ +namespace WebsiteForPlacingAds +{ + partial class UpdateAdsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + comboBoxClient = new ComboBox(); + comboBoxCategory = new ComboBox(); + comboBoxSubcategory = new ComboBox(); + labelClient = new Label(); + labelSubcategory = new Label(); + labelCategory = new Label(); + textBoxStatus = new TextBox(); + labelStatus = new Label(); + textBoxDate = new TextBox(); + labelDate = new Label(); + textBoxPrice = new TextBox(); + labelPrice = new Label(); + textBoxHeading = new TextBox(); + labelHeading = new Label(); + buttonUpdateAd = new Button(); + label1 = new Label(); + comboBoxUpdateAd = new ComboBox(); + SuspendLayout(); + // + // comboBoxClient + // + comboBoxClient.FormattingEnabled = true; + comboBoxClient.Location = new Point(81, 278); + comboBoxClient.Margin = new Padding(3, 2, 3, 2); + comboBoxClient.Name = "comboBoxClient"; + comboBoxClient.Size = new Size(239, 23); + comboBoxClient.TabIndex = 32; + // + // comboBoxCategory + // + comboBoxCategory.FormattingEnabled = true; + comboBoxCategory.Location = new Point(81, 328); + comboBoxCategory.Margin = new Padding(3, 2, 3, 2); + comboBoxCategory.Name = "comboBoxCategory"; + comboBoxCategory.Size = new Size(239, 23); + comboBoxCategory.TabIndex = 31; + // + // comboBoxSubcategory + // + comboBoxSubcategory.FormattingEnabled = true; + comboBoxSubcategory.Location = new Point(81, 375); + comboBoxSubcategory.Margin = new Padding(3, 2, 3, 2); + comboBoxSubcategory.Name = "comboBoxSubcategory"; + comboBoxSubcategory.Size = new Size(239, 23); + comboBoxSubcategory.TabIndex = 30; + // + // labelClient + // + labelClient.AutoSize = true; + labelClient.Location = new Point(81, 261); + labelClient.Name = "labelClient"; + labelClient.Size = new Size(46, 15); + labelClient.TabIndex = 29; + labelClient.Text = "Клиент"; + // + // labelSubcategory + // + labelSubcategory.AutoSize = true; + labelSubcategory.Location = new Point(81, 358); + labelSubcategory.Name = "labelSubcategory"; + labelSubcategory.Size = new Size(84, 15); + labelSubcategory.TabIndex = 28; + labelSubcategory.Text = "Подкатегория"; + // + // labelCategory + // + labelCategory.AutoSize = true; + labelCategory.Location = new Point(81, 311); + labelCategory.Name = "labelCategory"; + labelCategory.Size = new Size(63, 15); + labelCategory.TabIndex = 27; + labelCategory.Text = "Категория"; + // + // textBoxStatus + // + textBoxStatus.Location = new Point(81, 231); + textBoxStatus.Margin = new Padding(3, 2, 3, 2); + textBoxStatus.Name = "textBoxStatus"; + textBoxStatus.Size = new Size(239, 23); + textBoxStatus.TabIndex = 26; + // + // labelStatus + // + labelStatus.AutoSize = true; + labelStatus.Location = new Point(81, 214); + labelStatus.Name = "labelStatus"; + labelStatus.Size = new Size(43, 15); + labelStatus.TabIndex = 25; + labelStatus.Text = "Статус"; + // + // textBoxDate + // + textBoxDate.Location = new Point(81, 184); + textBoxDate.Margin = new Padding(3, 2, 3, 2); + textBoxDate.Name = "textBoxDate"; + textBoxDate.Size = new Size(239, 23); + textBoxDate.TabIndex = 24; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(81, 166); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(105, 15); + labelDate.TabIndex = 23; + labelDate.Text = "Дата размещения"; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(81, 137); + textBoxPrice.Margin = new Padding(3, 2, 3, 2); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(239, 23); + textBoxPrice.TabIndex = 22; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(81, 120); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(35, 15); + labelPrice.TabIndex = 21; + labelPrice.Text = "Цена"; + // + // textBoxHeading + // + textBoxHeading.Location = new Point(81, 91); + textBoxHeading.Margin = new Padding(3, 2, 3, 2); + textBoxHeading.Name = "textBoxHeading"; + textBoxHeading.Size = new Size(239, 23); + textBoxHeading.TabIndex = 20; + // + // labelHeading + // + labelHeading.AutoSize = true; + labelHeading.Location = new Point(81, 74); + labelHeading.Name = "labelHeading"; + labelHeading.Size = new Size(65, 15); + labelHeading.TabIndex = 19; + labelHeading.Text = "Заголовок"; + // + // buttonUpdateAd + // + buttonUpdateAd.Location = new Point(81, 425); + buttonUpdateAd.Margin = new Padding(3, 2, 3, 2); + buttonUpdateAd.Name = "buttonUpdateAd"; + buttonUpdateAd.Size = new Size(239, 29); + buttonUpdateAd.TabIndex = 18; + buttonUpdateAd.Text = "Изменить объявление"; + buttonUpdateAd.UseVisualStyleBackColor = true; + buttonUpdateAd.Click += buttonUpdateAd_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(51, 15); + label1.Name = "label1"; + label1.Size = new Size(275, 15); + label1.TabIndex = 33; + label1.Text = "Выберите объявление, которое хотите обновить"; + // + // comboBoxUpdateAd + // + comboBoxUpdateAd.FormattingEnabled = true; + comboBoxUpdateAd.Location = new Point(10, 39); + comboBoxUpdateAd.Margin = new Padding(3, 2, 3, 2); + comboBoxUpdateAd.Name = "comboBoxUpdateAd"; + comboBoxUpdateAd.Size = new Size(377, 23); + comboBoxUpdateAd.TabIndex = 34; + comboBoxUpdateAd.SelectedIndexChanged += comboBoxUpdateAd_SelectedIndexChanged; + // + // UpdateAdsForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(397, 473); + Controls.Add(comboBoxUpdateAd); + Controls.Add(label1); + Controls.Add(comboBoxClient); + Controls.Add(comboBoxCategory); + Controls.Add(comboBoxSubcategory); + Controls.Add(labelClient); + Controls.Add(labelSubcategory); + Controls.Add(labelCategory); + Controls.Add(textBoxStatus); + Controls.Add(labelStatus); + Controls.Add(textBoxDate); + Controls.Add(labelDate); + Controls.Add(textBoxPrice); + Controls.Add(labelPrice); + Controls.Add(textBoxHeading); + Controls.Add(labelHeading); + Controls.Add(buttonUpdateAd); + Margin = new Padding(3, 2, 3, 2); + Name = "UpdateAdsForm"; + Text = "Обновить объявление"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxClient; + private ComboBox comboBoxCategory; + private ComboBox comboBoxSubcategory; + private Label labelClient; + private Label labelSubcategory; + private Label labelCategory; + private TextBox textBoxStatus; + private Label labelStatus; + private TextBox textBoxDate; + private Label labelDate; + private TextBox textBoxPrice; + private Label labelPrice; + private TextBox textBoxHeading; + private Label labelHeading; + private Button buttonUpdateAd; + private Label label1; + private ComboBox comboBoxUpdateAd; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/AdsForm/UpdateAdsForm.cs b/BulletinBoard/BulletinBoard/AdsForm/UpdateAdsForm.cs new file mode 100644 index 0000000..cd440ea --- /dev/null +++ b/BulletinBoard/BulletinBoard/AdsForm/UpdateAdsForm.cs @@ -0,0 +1,154 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WebsiteForPlacingAds +{ + public partial class UpdateAdsForm : Form + { + //PostgreSqlDatabase psd; + AbstractManagmentDatabase managmentDatabase; + public UpdateAdsForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void buttonUpdateAd_Click(object sender, EventArgs e) + { + string[] selectedAds = comboBoxUpdateAd.SelectedItem.ToString().Split("|"); + int ads_id = int.Parse(selectedAds[0].Trim()); + + string query = $"UPDATE ads SET "; + int len = query.Length; + + + string oldHeading = managmentDatabase.getRowTableById("ads", "heading", ads_id).ToString(); + string oldPrice = managmentDatabase.getRowTableById("ads", "heading", ads_id).ToString(); + string oldDate = ((DateTime)managmentDatabase.getRowTableById("ads", "date_of_placement", ads_id)).ToString("dd.MM.yyyy"); + string oldStatus = managmentDatabase.getRowTableById("ads", "status", ads_id).ToString(); + string[] oldClient = managmentDatabase.getRowTableById("ads", "client_id", ads_id).ToString().Split(" "); + string[] oldCategory = managmentDatabase.getRowTableById("ads", "category_id", ads_id).ToString().Split(" "); + string[] oldSubcategory = managmentDatabase.getRowTableById("ads", "subcategory_id", ads_id).ToString().Split(" "); + + + string newHeading = textBoxHeading.Text; + string newPrice = textBoxPrice.Text; + string newDate = textBoxDate.Text; + string newStatus = textBoxStatus.Text; + string[] newClient = comboBoxClient.SelectedItem.ToString().Split(" "); + string[] newCategory = comboBoxCategory.SelectedItem.ToString().Split(" "); + string[] newSubcategory = comboBoxSubcategory.SelectedItem.ToString().Split(" "); + + + + query = oldHeading == newHeading ? query : query + $"heading = '{newHeading}', "; + query = oldPrice == newPrice ? query : query + $"price = {newPrice}, "; + query = oldDate == newDate ? query : query + $"date_of_placement = '{newDate}', "; + query = oldStatus == newStatus ? query : query + $"status = '{newStatus}', "; + query = oldClient[0].Trim() == newClient[0].Trim() ? query : query + $"client_id = '{newClient[0].Substring(0, newClient[0].IndexOf("."))}', "; + query = oldCategory[0].Trim() == newCategory[0].Trim() ? query : query + $"category_id = '{newCategory[0].Substring(0, newCategory[0].IndexOf("."))}', "; + query = oldSubcategory[0].Trim() == newSubcategory[0].Trim() ? query : query + $"subcategory_id = '{newSubcategory[0].Substring(0, newSubcategory[0].IndexOf("."))}', "; + + + if (len != query.Length) + { + query = query.TrimEnd(' '); + query = query.TrimEnd(','); + query += $" WHERE ADS_ID = {ads_id};"; + } + try + { + DateTime start = DateTime.Now; + + managmentDatabase.ExecuteNonQuery(query); + MessageBox.Show("Данные успешно обновлены!"); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Добавлено! Время выполнения: {duration.TotalMilliseconds} мс"); + } + catch (Exception) + { + + MessageBox.Show("Данные не обновились"); + } + + } + public void LoadData() + { + comboBoxUpdateAd.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("Ads"); + string Ads = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + Ads = result.Rows[i]["ads_id"].ToString() + " | " + + (string)result.Rows[i]["heading"] + " | " + + result.Rows[i]["price"].ToString() + " | " + + ((DateTime)result.Rows[i]["date_of_placement"]).ToString("dd.MM.yyyy") + " | " + + (string)result.Rows[i]["status"] + " | " + + result.Rows[i]["client_id"].ToString() + " | " + + result.Rows[i]["category_id"].ToString() + " | " + + result.Rows[i]["subcategory_id"].ToString() + "\n"; + comboBoxUpdateAd.Items.Add(Ads); + } + comboBoxCategory.Items.Clear(); + comboBoxSubcategory.Items.Clear(); + comboBoxClient.Items.Clear(); + + result = managmentDatabase.getAllEntry("Categories"); + string[] id_names = new string[result.Rows.Count]; + for (int i = 0; i < result.Rows.Count; i++) + { + id_names[i] = result.Rows[i]["categories_id"].ToString() + ". " + (string)result.Rows[i]["name"]; + comboBoxCategory.Items.Add(id_names[i]); + } + result = managmentDatabase.getAllEntry("Subcategories"); + id_names = new string[result.Rows.Count]; + for (int i = 0; i < result.Rows.Count; i++) + { + id_names[i] = result.Rows[i]["subcategories_id"].ToString() + ". " + (string)result.Rows[i]["name"]; + comboBoxSubcategory.Items.Add(id_names[i]); + } + result = managmentDatabase.getAllEntry("Clients"); + string[] id_names_surnames = new string[result.Rows.Count]; + for (int i = 0; i < result.Rows.Count; i++) + { + id_names_surnames[i] = result.Rows[i]["clients_id"].ToString().Trim() + ". " + ((string)result.Rows[i]["name"]).Trim() + " " + ((string)result.Rows[i]["surname"]).Trim(); + comboBoxClient.Items.Add(id_names_surnames[i]); + } + + } + public void LoadDataSelectedItem(int ads_id) + { + DataTable result = managmentDatabase.getEntryById("ads", ads_id); + textBoxHeading.Text = (string)result.Rows[0]["heading"]; + textBoxPrice.Text = result.Rows[0]["price"].ToString(); + textBoxDate.Text = ((DateTime)result.Rows[0]["date_of_placement"]).ToString("dd.MM.yyyy"); + textBoxStatus.Text = (string)result.Rows[0]["status"]; + + comboBoxCategory.SelectedItem = result.Rows[0]["category_id"].ToString() + ". " + managmentDatabase.getRowTableById("categories", "name", Convert.ToInt32(result.Rows[0]["id_category"])).ToString(); + + comboBoxSubcategory.SelectedItem = result.Rows[0]["subcategory_id"].ToString() + ". " + managmentDatabase.getRowTableById("subcategories", "name", Convert.ToInt32(result.Rows[0]["id_subcategory"])).ToString(); + + comboBoxClient.SelectedItem = result.Rows[0]["id_client"].ToString().Trim() + ". " + + managmentDatabase.getRowTableById("clients", "name", Convert.ToInt32(result.Rows[0]["client_id"])).ToString().Trim() + " " + + managmentDatabase.getRowTableById("clients", "surname", Convert.ToInt32(result.Rows[0]["client_id"])).ToString().Trim(); + + } + + private void comboBoxUpdateAd_SelectedIndexChanged(object sender, EventArgs e) + { + string[] selectedItems = comboBoxUpdateAd.SelectedItem.ToString().Split("|"); + int ads_id = int.Parse(selectedItems[0].Trim()); + LoadDataSelectedItem(ads_id); + } + } +} diff --git a/BulletinBoard/BulletinBoard/AdsForm/UpdateAdsForm.resx b/BulletinBoard/BulletinBoard/AdsForm/UpdateAdsForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BulletinBoard/BulletinBoard/AdsForm/UpdateAdsForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/BulletinBoard.csproj b/BulletinBoard/BulletinBoard/BulletinBoard.csproj new file mode 100644 index 0000000..1a1eec4 --- /dev/null +++ b/BulletinBoard/BulletinBoard/BulletinBoard.csproj @@ -0,0 +1,21 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + Form + + + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CategoriesForm/CreateCategoriesForm.Designer.cs b/BulletinBoard/BulletinBoard/CategoriesForm/CreateCategoriesForm.Designer.cs new file mode 100644 index 0000000..d75018b --- /dev/null +++ b/BulletinBoard/BulletinBoard/CategoriesForm/CreateCategoriesForm.Designer.cs @@ -0,0 +1,86 @@ +namespace WebsiteForPlacingAds +{ + partial class CreateCategoriesForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonCreateCategory = new System.Windows.Forms.Button(); + this.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // buttonCreateCategory + // + this.buttonCreateCategory.Location = new System.Drawing.Point(43, 70); + this.buttonCreateCategory.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCreateCategory.Name = "buttonCreateCategory"; + this.buttonCreateCategory.Size = new System.Drawing.Size(239, 29); + this.buttonCreateCategory.TabIndex = 0; + this.buttonCreateCategory.Text = "Добавить категорию"; + this.buttonCreateCategory.UseVisualStyleBackColor = true; + this.buttonCreateCategory.Click += new System.EventHandler(this.buttonCreateCategory_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(43, 8); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(59, 15); + this.labelName.TabIndex = 1; + this.labelName.Text = "Название"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(43, 26); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(239, 23); + this.textBoxName.TabIndex = 2; + // + // CreateCategoriesForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(324, 127); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCreateCategory); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "CreateCategoriesForm"; + this.Text = "Категория"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCreateCategory; + private Label labelName; + private TextBox textBoxName; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CategoriesForm/CreateCategoriesForm.cs b/BulletinBoard/BulletinBoard/CategoriesForm/CreateCategoriesForm.cs new file mode 100644 index 0000000..ca03d93 --- /dev/null +++ b/BulletinBoard/BulletinBoard/CategoriesForm/CreateCategoriesForm.cs @@ -0,0 +1,35 @@ +using System.Data; + +namespace WebsiteForPlacingAds +{ + public partial class CreateCategoriesForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public CreateCategoriesForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + } + + private void buttonCreateCategory_Click(object sender, EventArgs e) + { + string name = textBoxName.Text; + + try + { + DateTime start = DateTime.Now; + + managmentDatabase.insertInto("categories", $"'{name}'"); + MessageBox.Show("!"); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"! : {duration.TotalMilliseconds} "); + } + catch (Exception ex) + { + MessageBox.Show(" "); + } + } + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CategoriesForm/CreateCategoriesForm.resx b/BulletinBoard/BulletinBoard/CategoriesForm/CreateCategoriesForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BulletinBoard/BulletinBoard/CategoriesForm/CreateCategoriesForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CategoriesForm/DeleteCategoriesForm.Designer.cs b/BulletinBoard/BulletinBoard/CategoriesForm/DeleteCategoriesForm.Designer.cs new file mode 100644 index 0000000..344c0b8 --- /dev/null +++ b/BulletinBoard/BulletinBoard/CategoriesForm/DeleteCategoriesForm.Designer.cs @@ -0,0 +1,87 @@ +namespace WebsiteForPlacingAds +{ + partial class DeleteCategoriesForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.buttonDeleteCategory = new System.Windows.Forms.Button(); + this.comboBoxDeleteCategories = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(70, 16); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(262, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Выберите категорию, которую хотите удалить"; + // + // buttonDeleteCategory + // + this.buttonDeleteCategory.Location = new System.Drawing.Point(132, 85); + this.buttonDeleteCategory.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDeleteCategory.Name = "buttonDeleteCategory"; + this.buttonDeleteCategory.Size = new System.Drawing.Size(163, 28); + this.buttonDeleteCategory.TabIndex = 1; + this.buttonDeleteCategory.Text = "Удалить"; + this.buttonDeleteCategory.UseVisualStyleBackColor = true; + this.buttonDeleteCategory.Click += new System.EventHandler(this.buttonDeleteCategory_Click); + // + // comboBoxDeleteCategories + // + this.comboBoxDeleteCategories.FormattingEnabled = true; + this.comboBoxDeleteCategories.Location = new System.Drawing.Point(35, 48); + this.comboBoxDeleteCategories.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxDeleteCategories.Name = "comboBoxDeleteCategories"; + this.comboBoxDeleteCategories.Size = new System.Drawing.Size(367, 23); + this.comboBoxDeleteCategories.TabIndex = 2; + // + // DeleteCategoriesForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(442, 131); + this.Controls.Add(this.comboBoxDeleteCategories); + this.Controls.Add(this.buttonDeleteCategory); + this.Controls.Add(this.label1); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "DeleteCategoriesForm"; + this.Text = "Удалить категорию"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Button buttonDeleteCategory; + private ComboBox comboBoxDeleteCategories; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CategoriesForm/DeleteCategoriesForm.cs b/BulletinBoard/BulletinBoard/CategoriesForm/DeleteCategoriesForm.cs new file mode 100644 index 0000000..b591b6d --- /dev/null +++ b/BulletinBoard/BulletinBoard/CategoriesForm/DeleteCategoriesForm.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WebsiteForPlacingAds +{ + public partial class DeleteCategoriesForm : Form + { + AbstractManagmentDatabase managmentDatabase; + private int setval_seq; + public DeleteCategoriesForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void buttonDeleteCategory_Click(object sender, EventArgs e) + { + string[] categories = comboBoxDeleteCategories.SelectedItem.ToString().Split("|"); + string category_id = categories[0].Trim(); + try + { + DateTime start = DateTime.Now; + + managmentDatabase.deleteEntry("categories", int.Parse(category_id)); + LoadData(); + if (setval_seq > 0) managmentDatabase.reduceSeq("seq_categories", setval_seq); + MessageBox.Show("Удалено!"); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Добавлено! Время выполнения: {duration.TotalMilliseconds} мс"); + } + catch (Exception ex) + { + MessageBox.Show("Не удалось удалить"); + } + } + public void LoadData() + { + comboBoxDeleteCategories.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("Categories"); + setval_seq = result.Rows.Count; + string Categories = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + setval_seq = Math.Max(Convert.ToInt32(managmentDatabase.getRowTableById(result, "categories_id", i)), setval_seq); + Categories = managmentDatabase.getRowTableById(result, "categories_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "name", i).ToString() + "\n"; + comboBoxDeleteCategories.Items.Add(Categories); + } + } + } +} diff --git a/BulletinBoard/BulletinBoard/CategoriesForm/DeleteCategoriesForm.resx b/BulletinBoard/BulletinBoard/CategoriesForm/DeleteCategoriesForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BulletinBoard/BulletinBoard/CategoriesForm/DeleteCategoriesForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CategoriesForm/ListCategoriesForm.Designer.cs b/BulletinBoard/BulletinBoard/CategoriesForm/ListCategoriesForm.Designer.cs new file mode 100644 index 0000000..589ddeb --- /dev/null +++ b/BulletinBoard/BulletinBoard/CategoriesForm/ListCategoriesForm.Designer.cs @@ -0,0 +1,75 @@ +namespace WebsiteForPlacingAds +{ + partial class ListCategoriesForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.labelListCategories = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.BackColor = System.Drawing.SystemColors.Control; + this.label1.Font = new System.Drawing.Font("Segoe UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label1.Location = new System.Drawing.Point(10, 7); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(134, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Список категорий"; + // + // labelListCategories + // + this.labelListCategories.AutoSize = true; + this.labelListCategories.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.labelListCategories.Location = new System.Drawing.Point(10, 35); + this.labelListCategories.Name = "labelListCategories"; + this.labelListCategories.Size = new System.Drawing.Size(0, 19); + this.labelListCategories.TabIndex = 1; + // + // ListCategoriesForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.labelListCategories); + this.Controls.Add(this.label1); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "ListCategoriesForm"; + this.Text = "Список категорий"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label labelListCategories; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CategoriesForm/ListCategoriesForm.cs b/BulletinBoard/BulletinBoard/CategoriesForm/ListCategoriesForm.cs new file mode 100644 index 0000000..434af6d --- /dev/null +++ b/BulletinBoard/BulletinBoard/CategoriesForm/ListCategoriesForm.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Windows.Forms.VisualStyles; + +namespace WebsiteForPlacingAds +{ + public partial class ListCategoriesForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public ListCategoriesForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void LoadData() + { + DateTime start = DateTime.Now; + + DataTable result = managmentDatabase.getAllEntry("Categories"); + string listCategories = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + listCategories += managmentDatabase.getRowTableById(result, "categories_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "name", i).ToString() + "\n"; + } + labelListCategories.Text = listCategories; + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Список загружен! Время выполнения: {duration.TotalMilliseconds} мс"); + } + } +} diff --git a/BulletinBoard/BulletinBoard/CategoriesForm/ListCategoriesForm.resx b/BulletinBoard/BulletinBoard/CategoriesForm/ListCategoriesForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BulletinBoard/BulletinBoard/CategoriesForm/ListCategoriesForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CategoriesForm/UpdateCategoriesForm.Designer.cs b/BulletinBoard/BulletinBoard/CategoriesForm/UpdateCategoriesForm.Designer.cs new file mode 100644 index 0000000..6d9452e --- /dev/null +++ b/BulletinBoard/BulletinBoard/CategoriesForm/UpdateCategoriesForm.Designer.cs @@ -0,0 +1,110 @@ +namespace WebsiteForPlacingAds +{ + partial class UpdateCategoriesForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.comboBoxUpdateCategory = new System.Windows.Forms.ComboBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.buttonUpdateCategory = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(51, 15); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(271, 15); + this.label1.TabIndex = 33; + this.label1.Text = "Выберите категорию, которую хотите обновить"; + // + // comboBoxUpdateCategory + // + this.comboBoxUpdateCategory.FormattingEnabled = true; + this.comboBoxUpdateCategory.Location = new System.Drawing.Point(10, 39); + this.comboBoxUpdateCategory.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxUpdateCategory.Name = "comboBoxUpdateCategory"; + this.comboBoxUpdateCategory.Size = new System.Drawing.Size(377, 23); + this.comboBoxUpdateCategory.TabIndex = 34; + this.comboBoxUpdateCategory.SelectedIndexChanged += new System.EventHandler(this.comboBoxUpdateCategory_SelectedIndexChanged); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(78, 96); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(239, 23); + this.textBoxName.TabIndex = 37; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(78, 78); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(59, 15); + this.labelName.TabIndex = 36; + this.labelName.Text = "Название"; + // + // buttonUpdateCategory + // + this.buttonUpdateCategory.Location = new System.Drawing.Point(78, 140); + this.buttonUpdateCategory.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdateCategory.Name = "buttonUpdateCategory"; + this.buttonUpdateCategory.Size = new System.Drawing.Size(239, 29); + this.buttonUpdateCategory.TabIndex = 35; + this.buttonUpdateCategory.Text = "Обновить категорию"; + this.buttonUpdateCategory.UseVisualStyleBackColor = true; + this.buttonUpdateCategory.Click += new System.EventHandler(this.buttonUpdateCategory_Click_1); + // + // UpdateCategoriesForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(397, 190); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonUpdateCategory); + this.Controls.Add(this.comboBoxUpdateCategory); + this.Controls.Add(this.label1); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "UpdateCategoriesForm"; + this.Text = "Обновить категорию"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private Label label1; + private ComboBox comboBoxUpdateCategory; + private TextBox textBoxName; + private Label labelName; + private Button buttonUpdateCategory; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CategoriesForm/UpdateCategoriesForm.cs b/BulletinBoard/BulletinBoard/CategoriesForm/UpdateCategoriesForm.cs new file mode 100644 index 0000000..4cebba7 --- /dev/null +++ b/BulletinBoard/BulletinBoard/CategoriesForm/UpdateCategoriesForm.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WebsiteForPlacingAds +{ + public partial class UpdateCategoriesForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public UpdateCategoriesForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + public void LoadData() + { + comboBoxUpdateCategory.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("Categories"); + string Categories = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + Categories = result.Rows[i]["categories_id"].ToString() + " | " + + (string)result.Rows[i]["name"] + "\n"; + comboBoxUpdateCategory.Items.Add(Categories); + } + } + public void LoadDataSelectedItem(int categories_id) + { + DataTable result = managmentDatabase.getEntryById("categories", categories_id); + textBoxName.Text = managmentDatabase.getRowTableById(result, "name", 0).ToString(); + } + + private void comboBoxUpdateCategory_SelectedIndexChanged(object sender, EventArgs e) + { + string[] selectedItems = comboBoxUpdateCategory.SelectedItem.ToString().Split("|"); + int category_id = int.Parse(selectedItems[0].Trim()); + LoadDataSelectedItem(category_id); + } + + private void buttonUpdateCategory_Click_1(object sender, EventArgs e) + { + string[] selectedCategory = comboBoxUpdateCategory.SelectedItem.ToString().Split("|"); + int category_id = int.Parse(selectedCategory[0].Trim()); + + string query = $"UPDATE Categories SET "; + int len = query.Length; + + + string oldName = managmentDatabase.getRowTableById("categories", "name", category_id).ToString(); + + string newName = textBoxName.Text; + + + query = oldName == newName ? query : query + $"name = '{newName}', "; + if (len != query.Length) + { + query = query.TrimEnd(' '); + query = query.TrimEnd(','); + query += $" WHERE Categories_ID = {category_id};"; + } + try + { + DateTime start = DateTime.Now; + + managmentDatabase.ExecuteNonQuery(query); + MessageBox.Show("Данные успешно обновлены!"); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Добавлено! Время выполнения: {duration.TotalMilliseconds} мс"); + } + catch (Exception) + { + + MessageBox.Show("Данные не обновились"); + } + } + } +} diff --git a/BulletinBoard/BulletinBoard/CategoriesForm/UpdateCategoriesForm.resx b/BulletinBoard/BulletinBoard/CategoriesForm/UpdateCategoriesForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BulletinBoard/BulletinBoard/CategoriesForm/UpdateCategoriesForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CitiesForm/CreateCitiesForm.Designer.cs b/BulletinBoard/BulletinBoard/CitiesForm/CreateCitiesForm.Designer.cs new file mode 100644 index 0000000..8ce6b3a --- /dev/null +++ b/BulletinBoard/BulletinBoard/CitiesForm/CreateCitiesForm.Designer.cs @@ -0,0 +1,109 @@ +namespace WebsiteForPlacingAds +{ + partial class CreateCitiesForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonCreateCity = new Button(); + labelName = new Label(); + textBoxName = new TextBox(); + labelCategory = new Label(); + comboBoxRegion = new ComboBox(); + SuspendLayout(); + // + // buttonCreateCity + // + buttonCreateCity.Location = new Point(43, 111); + buttonCreateCity.Margin = new Padding(3, 2, 3, 2); + buttonCreateCity.Name = "buttonCreateCity"; + buttonCreateCity.Size = new Size(239, 29); + buttonCreateCity.TabIndex = 0; + buttonCreateCity.Text = "Добавить город"; + buttonCreateCity.UseVisualStyleBackColor = true; + buttonCreateCity.Click += buttonCreateCity_Click; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(43, 8); + labelName.Name = "labelName"; + labelName.Size = new Size(59, 15); + labelName.TabIndex = 1; + labelName.Text = "Название"; + // + // textBoxName + // + textBoxName.Location = new Point(43, 26); + textBoxName.Margin = new Padding(3, 2, 3, 2); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(239, 23); + textBoxName.TabIndex = 2; + // + // labelCategory + // + labelCategory.AutoSize = true; + labelCategory.Location = new Point(43, 62); + labelCategory.Name = "labelCategory"; + labelCategory.Size = new Size(46, 15); + labelCategory.TabIndex = 20; + labelCategory.Text = "Регион"; + // + // comboBoxRegion + // + comboBoxRegion.FormattingEnabled = true; + comboBoxRegion.Location = new Point(43, 78); + comboBoxRegion.Margin = new Padding(3, 2, 3, 2); + comboBoxRegion.Name = "comboBoxRegion"; + comboBoxRegion.Size = new Size(239, 23); + comboBoxRegion.TabIndex = 19; + // + // CreateCitiesForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(324, 163); + Controls.Add(labelCategory); + Controls.Add(comboBoxRegion); + Controls.Add(textBoxName); + Controls.Add(labelName); + Controls.Add(buttonCreateCity); + Margin = new Padding(3, 2, 3, 2); + Name = "CreateCitiesForm"; + Text = "Добавить Город"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCreateCity; + private Label labelName; + private TextBox textBoxName; + private Label labelCategory; + private ComboBox comboBoxRegion; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CitiesForm/CreateCitiesForm.cs b/BulletinBoard/BulletinBoard/CitiesForm/CreateCitiesForm.cs new file mode 100644 index 0000000..1438b1f --- /dev/null +++ b/BulletinBoard/BulletinBoard/CitiesForm/CreateCitiesForm.cs @@ -0,0 +1,56 @@ +using System.Data; + +namespace WebsiteForPlacingAds +{ + public partial class CreateCitiesForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public CreateCitiesForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void buttonCreateCity_Click(object sender, EventArgs e) + { + string name = textBoxName.Text; + + string[] region = comboBoxRegion.SelectedItem.ToString().Split(" "); + + string regions_id = region[0]; + + try + { + DateTime start = DateTime.Now; + + managmentDatabase.insertInto("cities", $"'{name}'", regions_id); + MessageBox.Show("!"); + LoadData(); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"! : {duration.TotalMilliseconds} "); + + // + this.Close(); + } + catch (Exception ex) + { + MessageBox.Show(" "); + } + } + + private void LoadData() + { + comboBoxRegion.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("REGIONS"); + string[] id_names = new string[result.Rows.Count]; + for (int i = 0; i < result.Rows.Count; i++) + { + id_names[i] = managmentDatabase.getRowTableById(result, "regions_id", i).ToString() + ". " + managmentDatabase.getRowTableById(result, "name", i).ToString(); + comboBoxRegion.Items.Add(id_names[i]); + } + } + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CitiesForm/CreateCitiesForm.resx b/BulletinBoard/BulletinBoard/CitiesForm/CreateCitiesForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BulletinBoard/BulletinBoard/CitiesForm/CreateCitiesForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CitiesForm/DeleteCitiesForm.Designer.cs b/BulletinBoard/BulletinBoard/CitiesForm/DeleteCitiesForm.Designer.cs new file mode 100644 index 0000000..65dc51c --- /dev/null +++ b/BulletinBoard/BulletinBoard/CitiesForm/DeleteCitiesForm.Designer.cs @@ -0,0 +1,86 @@ +namespace WebsiteForPlacingAds +{ + partial class DeleteCitiesForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + buttonDeleteCity = new Button(); + comboBoxDeleteCities = new ComboBox(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(70, 16); + label1.Name = "label1"; + label1.Size = new Size(235, 15); + label1.TabIndex = 0; + label1.Text = "Выберите город, которую хотите удалить"; + // + // buttonDeleteCity + // + buttonDeleteCity.Location = new Point(132, 85); + buttonDeleteCity.Margin = new Padding(3, 2, 3, 2); + buttonDeleteCity.Name = "buttonDeleteCity"; + buttonDeleteCity.Size = new Size(163, 28); + buttonDeleteCity.TabIndex = 1; + buttonDeleteCity.Text = "Удалить"; + buttonDeleteCity.UseVisualStyleBackColor = true; + buttonDeleteCity.Click += buttonDeleteCity_Click; + // + // comboBoxDeleteCities + // + comboBoxDeleteCities.FormattingEnabled = true; + comboBoxDeleteCities.Location = new Point(35, 48); + comboBoxDeleteCities.Margin = new Padding(3, 2, 3, 2); + comboBoxDeleteCities.Name = "comboBoxDeleteCities"; + comboBoxDeleteCities.Size = new Size(367, 23); + comboBoxDeleteCities.TabIndex = 2; + // + // DeleteCitiesForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(442, 131); + Controls.Add(comboBoxDeleteCities); + Controls.Add(buttonDeleteCity); + Controls.Add(label1); + Margin = new Padding(3, 2, 3, 2); + Name = "DeleteCitiesForm"; + Text = "Удалить город"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Button buttonDeleteCity; + private ComboBox comboBoxDeleteCities; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CitiesForm/DeleteCitiesForm.cs b/BulletinBoard/BulletinBoard/CitiesForm/DeleteCitiesForm.cs new file mode 100644 index 0000000..cbaaac5 --- /dev/null +++ b/BulletinBoard/BulletinBoard/CitiesForm/DeleteCitiesForm.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WebsiteForPlacingAds +{ + public partial class DeleteCitiesForm : Form + { + AbstractManagmentDatabase managmentDatabase; + private int setval_seq; + public DeleteCitiesForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void buttonDeleteCity_Click(object sender, EventArgs e) + { + string[] categories = comboBoxDeleteCities.SelectedItem.ToString().Split("|"); + string category_id = categories[0].Trim(); + try + { + DateTime start = DateTime.Now; + + managmentDatabase.deleteEntry("cities", int.Parse(category_id)); + LoadData(); + if (setval_seq > 0) managmentDatabase.reduceSeq("seq_cities", setval_seq); + MessageBox.Show("Удалено!"); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Добавлено! Время выполнения: {duration.TotalMilliseconds} мс"); + } + catch (Exception ex) + { + MessageBox.Show("Не удалось удалить"); + } + } + public void LoadData() + { + comboBoxDeleteCities.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("Cities"); + setval_seq = result.Rows.Count; + string Regions = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + setval_seq = Math.Max(Convert.ToInt32(managmentDatabase.getRowTableById(result, "cities_id", i)), setval_seq); + Regions = managmentDatabase.getRowTableById(result, "cities_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "name", i).ToString() + "\n"; + comboBoxDeleteCities.Items.Add(Regions); + } + } + } +} diff --git a/BulletinBoard/BulletinBoard/CitiesForm/DeleteCitiesForm.resx b/BulletinBoard/BulletinBoard/CitiesForm/DeleteCitiesForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BulletinBoard/BulletinBoard/CitiesForm/DeleteCitiesForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CitiesForm/ListCitiesForm.Designer.cs b/BulletinBoard/BulletinBoard/CitiesForm/ListCitiesForm.Designer.cs new file mode 100644 index 0000000..d08dcdb --- /dev/null +++ b/BulletinBoard/BulletinBoard/CitiesForm/ListCitiesForm.Designer.cs @@ -0,0 +1,74 @@ +namespace WebsiteForPlacingAds +{ + partial class ListCitiesForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + labelListCities = new Label(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.BackColor = SystemColors.Control; + label1.Font = new Font("Segoe UI", 11F, FontStyle.Regular, GraphicsUnit.Point); + label1.Location = new Point(10, 7); + label1.Name = "label1"; + label1.Size = new Size(121, 20); + label1.TabIndex = 0; + label1.Text = "Список городов"; + // + // labelListCities + // + labelListCities.AutoSize = true; + labelListCities.Font = new Font("Segoe UI", 10F, FontStyle.Regular, GraphicsUnit.Point); + labelListCities.Location = new Point(10, 35); + labelListCities.Name = "labelListCities"; + labelListCities.Size = new Size(0, 19); + labelListCities.TabIndex = 1; + // + // ListCitiesForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(700, 338); + Controls.Add(labelListCities); + Controls.Add(label1); + Margin = new Padding(3, 2, 3, 2); + Name = "ListCitiesForm"; + Text = "Список городов"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label labelListCities; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CitiesForm/ListCitiesForm.cs b/BulletinBoard/BulletinBoard/CitiesForm/ListCitiesForm.cs new file mode 100644 index 0000000..0bdbd97 --- /dev/null +++ b/BulletinBoard/BulletinBoard/CitiesForm/ListCitiesForm.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Windows.Forms.VisualStyles; + +namespace WebsiteForPlacingAds +{ + public partial class ListCitiesForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public ListCitiesForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void LoadData() + { + DateTime start = DateTime.Now; + + DataTable result = managmentDatabase.getAllEntry("Cities"); + string listCities = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + listCities += managmentDatabase.getRowTableById(result, "cities_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "name", i).ToString() + "\n"; + } + labelListCities.Text = listCities; + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Добавлено! Время выполнения: {duration.TotalMilliseconds} мс"); + } + } +} diff --git a/BulletinBoard/BulletinBoard/CitiesForm/ListCitiesForm.resx b/BulletinBoard/BulletinBoard/CitiesForm/ListCitiesForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BulletinBoard/BulletinBoard/CitiesForm/ListCitiesForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CitiesForm/UpdateCitiesForm.Designer.cs b/BulletinBoard/BulletinBoard/CitiesForm/UpdateCitiesForm.Designer.cs new file mode 100644 index 0000000..f995a6f --- /dev/null +++ b/BulletinBoard/BulletinBoard/CitiesForm/UpdateCitiesForm.Designer.cs @@ -0,0 +1,111 @@ +namespace WebsiteForPlacingAds +{ + partial class UpdateCitiesForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + comboBoxUpdateCity = new ComboBox(); + textBoxName = new TextBox(); + labelName = new Label(); + buttonUpdateCity = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(51, 15); + label1.Name = "label1"; + label1.Size = new Size(244, 15); + label1.TabIndex = 33; + label1.Text = "Выберите город, который хотите обновить"; + // + // comboBoxUpdateCity + // + comboBoxUpdateCity.FormattingEnabled = true; + comboBoxUpdateCity.Location = new Point(10, 39); + comboBoxUpdateCity.Margin = new Padding(3, 2, 3, 2); + comboBoxUpdateCity.Name = "comboBoxUpdateCity"; + comboBoxUpdateCity.Size = new Size(377, 23); + comboBoxUpdateCity.TabIndex = 34; + comboBoxUpdateCity.SelectedIndexChanged += comboBoxUpdateCity_SelectedIndexChanged; + // + // textBoxName + // + textBoxName.Location = new Point(78, 96); + textBoxName.Margin = new Padding(3, 2, 3, 2); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(239, 23); + textBoxName.TabIndex = 37; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(78, 78); + labelName.Name = "labelName"; + labelName.Size = new Size(59, 15); + labelName.TabIndex = 36; + labelName.Text = "Название"; + // + // buttonUpdateCity + // + buttonUpdateCity.Location = new Point(78, 140); + buttonUpdateCity.Margin = new Padding(3, 2, 3, 2); + buttonUpdateCity.Name = "buttonUpdateCity"; + buttonUpdateCity.Size = new Size(239, 29); + buttonUpdateCity.TabIndex = 35; + buttonUpdateCity.Text = "Обновить город"; + buttonUpdateCity.UseVisualStyleBackColor = true; + buttonUpdateCity.Click += buttonUpdateCity_Click_1; + // + // UpdateCitiesForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(397, 190); + Controls.Add(textBoxName); + Controls.Add(labelName); + Controls.Add(buttonUpdateCity); + Controls.Add(comboBoxUpdateCity); + Controls.Add(label1); + Margin = new Padding(3, 2, 3, 2); + Name = "UpdateCitiesForm"; + Text = "Обновить город"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + + private Label label1; + private ComboBox comboBoxUpdateCity; + private TextBox textBoxName; + private Label labelName; + private Button buttonUpdateCity; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/CitiesForm/UpdateCitiesForm.cs b/BulletinBoard/BulletinBoard/CitiesForm/UpdateCitiesForm.cs new file mode 100644 index 0000000..2845d29 --- /dev/null +++ b/BulletinBoard/BulletinBoard/CitiesForm/UpdateCitiesForm.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WebsiteForPlacingAds +{ + public partial class UpdateCitiesForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public UpdateCitiesForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + public void LoadData() + { + DateTime start = DateTime.Now; + + comboBoxUpdateCity.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("Cities"); + string Cities = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + Cities = result.Rows[i]["cities_id"].ToString() + " | " + + (string)result.Rows[i]["name"] + "\n"; + comboBoxUpdateCity.Items.Add(Cities); + } + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Добавлено! Время выполнения: {duration.TotalMilliseconds} мс"); + } + public void LoadDataSelectedItem(int cities_id) + { + DataTable result = managmentDatabase.getEntryById("regions", cities_id); + textBoxName.Text = managmentDatabase.getRowTableById(result, "name", 0).ToString(); + } + + private void comboBoxUpdateCity_SelectedIndexChanged(object sender, EventArgs e) + { + string[] selectedItems = comboBoxUpdateCity.SelectedItem.ToString().Split("|"); + int city_id = int.Parse(selectedItems[0].Trim()); + LoadDataSelectedItem(city_id); + } + + private void buttonUpdateCity_Click_1(object sender, EventArgs e) + { + string[] selectedCategory = comboBoxUpdateCity.SelectedItem.ToString().Split("|"); + int city_id = int.Parse(selectedCategory[0].Trim()); + + string query = $"UPDATE Cities SET "; + int len = query.Length; + + + string oldName = managmentDatabase.getRowTableById("cities", "name", city_id).ToString(); + + string newName = textBoxName.Text; + + + query = oldName == newName ? query : query + $"name = '{newName}', "; + if (len != query.Length) + { + query = query.TrimEnd(' '); + query = query.TrimEnd(','); + query += $" WHERE Cities_ID = {city_id};"; + } + try + { + managmentDatabase.ExecuteNonQuery(query); + MessageBox.Show("Данные успешно обновлены!"); + } + catch (Exception) + { + + MessageBox.Show("Данные не обновились"); + } + } + } +} diff --git a/BulletinBoard/BulletinBoard/CitiesForm/UpdateCitiesForm.resx b/BulletinBoard/BulletinBoard/CitiesForm/UpdateCitiesForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BulletinBoard/BulletinBoard/CitiesForm/UpdateCitiesForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/ClientsForm/CreateClientsForm.Designer.cs b/BulletinBoard/BulletinBoard/ClientsForm/CreateClientsForm.Designer.cs new file mode 100644 index 0000000..1199232 --- /dev/null +++ b/BulletinBoard/BulletinBoard/ClientsForm/CreateClientsForm.Designer.cs @@ -0,0 +1,201 @@ +namespace WebsiteForPlacingAds +{ + partial class CreateClientsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonCreateClient = new System.Windows.Forms.Button(); + this.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxSurname = new System.Windows.Forms.TextBox(); + this.labelSurname = new System.Windows.Forms.Label(); + this.textBoxPatronymic = new System.Windows.Forms.TextBox(); + this.labelPatronymic = new System.Windows.Forms.Label(); + this.labelDate = new System.Windows.Forms.Label(); + this.textBoxEmail = new System.Windows.Forms.TextBox(); + this.labelEmail = new System.Windows.Forms.Label(); + this.labelPhoneNumber = new System.Windows.Forms.Label(); + this.textBoxPhoneNumber = new System.Windows.Forms.TextBox(); + this.textBoxDate = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // buttonCreateClient + // + this.buttonCreateClient.Location = new System.Drawing.Point(43, 346); + this.buttonCreateClient.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCreateClient.Name = "buttonCreateClient"; + this.buttonCreateClient.Size = new System.Drawing.Size(239, 29); + this.buttonCreateClient.TabIndex = 0; + this.buttonCreateClient.Text = "Создать клиента"; + this.buttonCreateClient.UseVisualStyleBackColor = true; + this.buttonCreateClient.Click += new System.EventHandler(this.buttonCreateClient_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(43, 8); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(31, 15); + this.labelName.TabIndex = 1; + this.labelName.Text = "Имя"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(43, 26); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(239, 23); + this.textBoxName.TabIndex = 2; + // + // textBoxSurname + // + this.textBoxSurname.Location = new System.Drawing.Point(43, 72); + this.textBoxSurname.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxSurname.Name = "textBoxSurname"; + this.textBoxSurname.Size = new System.Drawing.Size(239, 23); + this.textBoxSurname.TabIndex = 4; + // + // labelSurname + // + this.labelSurname.AutoSize = true; + this.labelSurname.Location = new System.Drawing.Point(43, 55); + this.labelSurname.Name = "labelSurname"; + this.labelSurname.Size = new System.Drawing.Size(58, 15); + this.labelSurname.TabIndex = 3; + this.labelSurname.Text = "Фамилия"; + // + // textBoxPatronymic + // + this.textBoxPatronymic.Location = new System.Drawing.Point(43, 118); + this.textBoxPatronymic.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxPatronymic.Name = "textBoxPatronymic"; + this.textBoxPatronymic.Size = new System.Drawing.Size(239, 23); + this.textBoxPatronymic.TabIndex = 6; + // + // labelPatronymic + // + this.labelPatronymic.AutoSize = true; + this.labelPatronymic.Location = new System.Drawing.Point(43, 101); + this.labelPatronymic.Name = "labelPatronymic"; + this.labelPatronymic.Size = new System.Drawing.Size(58, 15); + this.labelPatronymic.TabIndex = 5; + this.labelPatronymic.Text = "Отчество"; + // + // labelDate + // + this.labelDate.AutoSize = true; + this.labelDate.Location = new System.Drawing.Point(43, 246); + this.labelDate.Name = "labelDate"; + this.labelDate.Size = new System.Drawing.Size(105, 15); + this.labelDate.TabIndex = 9; + this.labelDate.Text = "Дата регистрации"; + // + // textBoxEmail + // + this.textBoxEmail.Location = new System.Drawing.Point(43, 166); + this.textBoxEmail.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxEmail.Name = "textBoxEmail"; + this.textBoxEmail.Size = new System.Drawing.Size(239, 23); + this.textBoxEmail.TabIndex = 8; + // + // labelEmail + // + this.labelEmail.AutoSize = true; + this.labelEmail.Location = new System.Drawing.Point(43, 148); + this.labelEmail.Name = "labelEmail"; + this.labelEmail.Size = new System.Drawing.Size(41, 15); + this.labelEmail.TabIndex = 7; + this.labelEmail.Text = "Почта"; + // + // labelPhoneNumber + // + this.labelPhoneNumber.AutoSize = true; + this.labelPhoneNumber.Location = new System.Drawing.Point(43, 196); + this.labelPhoneNumber.Name = "labelPhoneNumber"; + this.labelPhoneNumber.Size = new System.Drawing.Size(101, 15); + this.labelPhoneNumber.TabIndex = 13; + this.labelPhoneNumber.Text = "Номер телефона"; + // + // textBoxPhoneNumber + // + this.textBoxPhoneNumber.Location = new System.Drawing.Point(43, 213); + this.textBoxPhoneNumber.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxPhoneNumber.Name = "textBoxPhoneNumber"; + this.textBoxPhoneNumber.Size = new System.Drawing.Size(239, 23); + this.textBoxPhoneNumber.TabIndex = 14; + // + // textBoxDate + // + this.textBoxDate.Location = new System.Drawing.Point(43, 263); + this.textBoxDate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxDate.Name = "textBoxDate"; + this.textBoxDate.Size = new System.Drawing.Size(239, 23); + this.textBoxDate.TabIndex = 15; + // + // CreateClientsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(324, 398); + this.Controls.Add(this.textBoxDate); + this.Controls.Add(this.textBoxPhoneNumber); + this.Controls.Add(this.labelPhoneNumber); + this.Controls.Add(this.labelDate); + this.Controls.Add(this.textBoxEmail); + this.Controls.Add(this.labelEmail); + this.Controls.Add(this.textBoxPatronymic); + this.Controls.Add(this.labelPatronymic); + this.Controls.Add(this.textBoxSurname); + this.Controls.Add(this.labelSurname); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCreateClient); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "CreateClientsForm"; + this.Text = "Клиенты"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCreateClient; + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxSurname; + private Label labelSurname; + private TextBox textBoxPatronymic; + private Label labelPatronymic; + private Label labelDate; + private TextBox textBoxEmail; + private Label labelEmail; + private Label labelPhoneNumber; + private TextBox textBoxPhoneNumber; + private TextBox textBoxDate; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/ClientsForm/CreateClientsForm.cs b/BulletinBoard/BulletinBoard/ClientsForm/CreateClientsForm.cs new file mode 100644 index 0000000..77ea23e --- /dev/null +++ b/BulletinBoard/BulletinBoard/ClientsForm/CreateClientsForm.cs @@ -0,0 +1,45 @@ +using System.Data; + +namespace WebsiteForPlacingAds +{ + public partial class CreateClientsForm : Form + { + //PostgreSqlDatabase psd; + AbstractManagmentDatabase managmentDatabase; + public CreateClientsForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + } + + private void buttonCreateClient_Click(object sender, EventArgs e) + { + string name = textBoxName.Text; + string surname = textBoxSurname.Text; + string patronymic = textBoxPatronymic.Text; + string email = textBoxEmail.Text; + string phoneNumber = textBoxPhoneNumber.Text; + string date = textBoxDate.Text; + + try + { + DateTime start = DateTime.Now; + + if (patronymic != null) + managmentDatabase.insertInto("clients", $"'{name}'", $"'{surname}'", $"'{patronymic}'", $"'{email}'", $"{phoneNumber}", $"'{date}'"); + else managmentDatabase.insertInto("clients", $"'{name}'", $"'{surname}'", $"{patronymic}", $"'{email}'", $"{phoneNumber}", $"'{date}'"); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"! : {duration.TotalMilliseconds} "); + + // + this.Close(); + } + catch (Exception ex) + { + MessageBox.Show(" "); + } + } + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/ClientsForm/CreateClientsForm.resx b/BulletinBoard/BulletinBoard/ClientsForm/CreateClientsForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BulletinBoard/BulletinBoard/ClientsForm/CreateClientsForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/ClientsForm/DeleteClientsForm.Designer.cs b/BulletinBoard/BulletinBoard/ClientsForm/DeleteClientsForm.Designer.cs new file mode 100644 index 0000000..dcacef2 --- /dev/null +++ b/BulletinBoard/BulletinBoard/ClientsForm/DeleteClientsForm.Designer.cs @@ -0,0 +1,87 @@ +namespace WebsiteForPlacingAds +{ + partial class DeleteClientsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.buttonDeleteClient = new System.Windows.Forms.Button(); + this.comboBoxDeleteClients = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(70, 16); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(266, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Выберите объявление, которое хотите удалить"; + // + // buttonDeleteClient + // + this.buttonDeleteClient.Location = new System.Drawing.Point(132, 85); + this.buttonDeleteClient.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDeleteClient.Name = "buttonDeleteClient"; + this.buttonDeleteClient.Size = new System.Drawing.Size(163, 28); + this.buttonDeleteClient.TabIndex = 1; + this.buttonDeleteClient.Text = "Удалить"; + this.buttonDeleteClient.UseVisualStyleBackColor = true; + this.buttonDeleteClient.Click += new System.EventHandler(this.buttonDeleteAd_Click); + // + // comboBoxDeleteClients + // + this.comboBoxDeleteClients.FormattingEnabled = true; + this.comboBoxDeleteClients.Location = new System.Drawing.Point(35, 48); + this.comboBoxDeleteClients.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxDeleteClients.Name = "comboBoxDeleteClients"; + this.comboBoxDeleteClients.Size = new System.Drawing.Size(367, 23); + this.comboBoxDeleteClients.TabIndex = 2; + // + // DeleteClientsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(442, 131); + this.Controls.Add(this.comboBoxDeleteClients); + this.Controls.Add(this.buttonDeleteClient); + this.Controls.Add(this.label1); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "DeleteClientsForm"; + this.Text = "Удалить объявление"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Button buttonDeleteClient; + private ComboBox comboBoxDeleteClients; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/ClientsForm/DeleteClientsForm.cs b/BulletinBoard/BulletinBoard/ClientsForm/DeleteClientsForm.cs new file mode 100644 index 0000000..7df3e91 --- /dev/null +++ b/BulletinBoard/BulletinBoard/ClientsForm/DeleteClientsForm.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WebsiteForPlacingAds +{ + public partial class DeleteClientsForm : Form + { + AbstractManagmentDatabase managmentDatabase; + private int setval_seq; + public DeleteClientsForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void buttonDeleteAd_Click(object sender, EventArgs e) + { + string[] clients = comboBoxDeleteClients.SelectedItem.ToString().Split("|"); + string client_id = clients[0].Trim(); + //string query = $"DELETE FROM ADS WHERE ads_id = {ad_id}"; + //string query_seq_reduction = $"SELECT setval('seq_ads', {setval_seq - 1});"; + try + { + DateTime start = DateTime.Now; + + managmentDatabase.deleteEntry("clients", int.Parse(client_id)); + LoadData(); + if (setval_seq > 0) managmentDatabase.reduceSeq("seq_clients", setval_seq); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + + MessageBox.Show($"Удалено! Время выполнения: {duration.TotalMilliseconds} мс"); + } + catch (Exception ex) + { + MessageBox.Show("Не удалось удалить"); + } + } + public void LoadData() + { + comboBoxDeleteClients.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("Clients"); + setval_seq = result.Rows.Count; + string Clients = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + setval_seq = Math.Max(Convert.ToInt32(managmentDatabase.getRowTableById(result, "clients_id", i)), setval_seq); + Clients = managmentDatabase.getRowTableById(result, "clients_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "name", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "surname", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "patronymic", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "email", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "phone_number", i).ToString() + " | " + + ((DateTime)managmentDatabase.getRowTableById(result, "registration_date", i)).ToString("dd.MM.yyy") + "\n"; + comboBoxDeleteClients.Items.Add(Clients); + } + } + } +} diff --git a/BulletinBoard/BulletinBoard/ClientsForm/DeleteClientsForm.resx b/BulletinBoard/BulletinBoard/ClientsForm/DeleteClientsForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BulletinBoard/BulletinBoard/ClientsForm/DeleteClientsForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/ClientsForm/ListClientsForm.Designer.cs b/BulletinBoard/BulletinBoard/ClientsForm/ListClientsForm.Designer.cs new file mode 100644 index 0000000..48c2e6f --- /dev/null +++ b/BulletinBoard/BulletinBoard/ClientsForm/ListClientsForm.Designer.cs @@ -0,0 +1,75 @@ +namespace WebsiteForPlacingAds +{ + partial class ListClientsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.labelListClients = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.BackColor = System.Drawing.SystemColors.Control; + this.label1.Font = new System.Drawing.Font("Segoe UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label1.Location = new System.Drawing.Point(10, 7); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(127, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Список клиентов"; + // + // labelListClients + // + this.labelListClients.AutoSize = true; + this.labelListClients.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.labelListClients.Location = new System.Drawing.Point(10, 35); + this.labelListClients.Name = "labelListClients"; + this.labelListClients.Size = new System.Drawing.Size(0, 19); + this.labelListClients.TabIndex = 1; + // + // ListClientsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.labelListClients); + this.Controls.Add(this.label1); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "ListClientsForm"; + this.Text = "Список клиентов"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label labelListClients; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/ClientsForm/ListClientsForm.cs b/BulletinBoard/BulletinBoard/ClientsForm/ListClientsForm.cs new file mode 100644 index 0000000..ea4b8aa --- /dev/null +++ b/BulletinBoard/BulletinBoard/ClientsForm/ListClientsForm.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Windows.Forms.VisualStyles; + +namespace WebsiteForPlacingAds +{ + public partial class ListClientsForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public ListClientsForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void LoadData() + { + DateTime start = DateTime.Now; + + DataTable result = managmentDatabase.getAllEntry("clients"); + string listClients = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + listClients += managmentDatabase.getRowTableById(result, "clients_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "name", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "surname", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "patronymic", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "email", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "phone_number", i).ToString() + " | " + + ((DateTime)managmentDatabase.getRowTableById(result, "registration_date", i)).ToString("dd.MM.yyy") + "\n"; + } + labelListClients.Text = listClients; + + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Список загружен! Время выполнения: {duration.TotalMilliseconds} мс"); + } + } +} diff --git a/BulletinBoard/BulletinBoard/ClientsForm/ListClientsForm.resx b/BulletinBoard/BulletinBoard/ClientsForm/ListClientsForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BulletinBoard/BulletinBoard/ClientsForm/ListClientsForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/ClientsForm/UpdateClientsForm.Designer.cs b/BulletinBoard/BulletinBoard/ClientsForm/UpdateClientsForm.Designer.cs new file mode 100644 index 0000000..8093d9f --- /dev/null +++ b/BulletinBoard/BulletinBoard/ClientsForm/UpdateClientsForm.Designer.cs @@ -0,0 +1,225 @@ +namespace WebsiteForPlacingAds +{ + partial class UpdateClientsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonUpdateClient = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.comboBoxUpdateClient = new System.Windows.Forms.ComboBox(); + this.textBoxDate = new System.Windows.Forms.TextBox(); + this.textBoxPhoneNumber = new System.Windows.Forms.TextBox(); + this.labelPhoneNumber = new System.Windows.Forms.Label(); + this.labelDate = new System.Windows.Forms.Label(); + this.textBoxEmail = new System.Windows.Forms.TextBox(); + this.labelEmail = new System.Windows.Forms.Label(); + this.textBoxPatronymic = new System.Windows.Forms.TextBox(); + this.labelPatronymic = new System.Windows.Forms.Label(); + this.textBoxSurname = new System.Windows.Forms.TextBox(); + this.labelSurname = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonUpdateClient + // + this.buttonUpdateClient.Location = new System.Drawing.Point(81, 407); + this.buttonUpdateClient.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdateClient.Name = "buttonUpdateClient"; + this.buttonUpdateClient.Size = new System.Drawing.Size(239, 29); + this.buttonUpdateClient.TabIndex = 18; + this.buttonUpdateClient.Text = "Обновить клиента"; + this.buttonUpdateClient.UseVisualStyleBackColor = true; + this.buttonUpdateClient.Click += new System.EventHandler(this.buttonUpdateClient_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(51, 15); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(259, 15); + this.label1.TabIndex = 33; + this.label1.Text = "Выберите клиента, которого хотите обновить"; + // + // comboBoxUpdateClient + // + this.comboBoxUpdateClient.FormattingEnabled = true; + this.comboBoxUpdateClient.Location = new System.Drawing.Point(10, 39); + this.comboBoxUpdateClient.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxUpdateClient.Name = "comboBoxUpdateClient"; + this.comboBoxUpdateClient.Size = new System.Drawing.Size(377, 23); + this.comboBoxUpdateClient.TabIndex = 34; + this.comboBoxUpdateClient.SelectedIndexChanged += new System.EventHandler(this.comboBoxUpdateClient_SelectedIndexChanged); + // + // textBoxDate + // + this.textBoxDate.Location = new System.Drawing.Point(79, 326); + this.textBoxDate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxDate.Name = "textBoxDate"; + this.textBoxDate.Size = new System.Drawing.Size(239, 23); + this.textBoxDate.TabIndex = 47; + // + // textBoxPhoneNumber + // + this.textBoxPhoneNumber.Location = new System.Drawing.Point(79, 276); + this.textBoxPhoneNumber.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxPhoneNumber.Name = "textBoxPhoneNumber"; + this.textBoxPhoneNumber.Size = new System.Drawing.Size(239, 23); + this.textBoxPhoneNumber.TabIndex = 46; + // + // labelPhoneNumber + // + this.labelPhoneNumber.AutoSize = true; + this.labelPhoneNumber.Location = new System.Drawing.Point(79, 259); + this.labelPhoneNumber.Name = "labelPhoneNumber"; + this.labelPhoneNumber.Size = new System.Drawing.Size(101, 15); + this.labelPhoneNumber.TabIndex = 45; + this.labelPhoneNumber.Text = "Номер телефона"; + // + // labelDate + // + this.labelDate.AutoSize = true; + this.labelDate.Location = new System.Drawing.Point(79, 309); + this.labelDate.Name = "labelDate"; + this.labelDate.Size = new System.Drawing.Size(105, 15); + this.labelDate.TabIndex = 43; + this.labelDate.Text = "Дата регистрации"; + // + // textBoxEmail + // + this.textBoxEmail.Location = new System.Drawing.Point(79, 229); + this.textBoxEmail.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxEmail.Name = "textBoxEmail"; + this.textBoxEmail.Size = new System.Drawing.Size(239, 23); + this.textBoxEmail.TabIndex = 42; + // + // labelEmail + // + this.labelEmail.AutoSize = true; + this.labelEmail.Location = new System.Drawing.Point(79, 211); + this.labelEmail.Name = "labelEmail"; + this.labelEmail.Size = new System.Drawing.Size(41, 15); + this.labelEmail.TabIndex = 41; + this.labelEmail.Text = "Почта"; + // + // textBoxPatronymic + // + this.textBoxPatronymic.Location = new System.Drawing.Point(79, 181); + this.textBoxPatronymic.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxPatronymic.Name = "textBoxPatronymic"; + this.textBoxPatronymic.Size = new System.Drawing.Size(239, 23); + this.textBoxPatronymic.TabIndex = 40; + // + // labelPatronymic + // + this.labelPatronymic.AutoSize = true; + this.labelPatronymic.Location = new System.Drawing.Point(79, 164); + this.labelPatronymic.Name = "labelPatronymic"; + this.labelPatronymic.Size = new System.Drawing.Size(58, 15); + this.labelPatronymic.TabIndex = 39; + this.labelPatronymic.Text = "Отчество"; + // + // textBoxSurname + // + this.textBoxSurname.Location = new System.Drawing.Point(79, 135); + this.textBoxSurname.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxSurname.Name = "textBoxSurname"; + this.textBoxSurname.Size = new System.Drawing.Size(239, 23); + this.textBoxSurname.TabIndex = 38; + // + // labelSurname + // + this.labelSurname.AutoSize = true; + this.labelSurname.Location = new System.Drawing.Point(79, 118); + this.labelSurname.Name = "labelSurname"; + this.labelSurname.Size = new System.Drawing.Size(58, 15); + this.labelSurname.TabIndex = 37; + this.labelSurname.Text = "Фамилия"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(79, 89); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(239, 23); + this.textBoxName.TabIndex = 36; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(79, 71); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(31, 15); + this.labelName.TabIndex = 35; + this.labelName.Text = "Имя"; + // + // UpdateClientsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(397, 464); + this.Controls.Add(this.textBoxDate); + this.Controls.Add(this.textBoxPhoneNumber); + this.Controls.Add(this.labelPhoneNumber); + this.Controls.Add(this.labelDate); + this.Controls.Add(this.textBoxEmail); + this.Controls.Add(this.labelEmail); + this.Controls.Add(this.textBoxPatronymic); + this.Controls.Add(this.labelPatronymic); + this.Controls.Add(this.textBoxSurname); + this.Controls.Add(this.labelSurname); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Controls.Add(this.comboBoxUpdateClient); + this.Controls.Add(this.label1); + this.Controls.Add(this.buttonUpdateClient); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "UpdateClientsForm"; + this.Text = "Обновить клиента"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private Button buttonUpdateClient; + private Label label1; + private ComboBox comboBoxUpdateClient; + private TextBox textBoxDate; + private TextBox textBoxPhoneNumber; + private Label labelPhoneNumber; + private Label labelDate; + private TextBox textBoxEmail; + private Label labelEmail; + private TextBox textBoxPatronymic; + private Label labelPatronymic; + private TextBox textBoxSurname; + private Label labelSurname; + private TextBox textBoxName; + private Label labelName; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/ClientsForm/UpdateClientsForm.cs b/BulletinBoard/BulletinBoard/ClientsForm/UpdateClientsForm.cs new file mode 100644 index 0000000..a6673c1 --- /dev/null +++ b/BulletinBoard/BulletinBoard/ClientsForm/UpdateClientsForm.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WebsiteForPlacingAds +{ + public partial class UpdateClientsForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public UpdateClientsForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + public void LoadData() + { + comboBoxUpdateClient.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("Clients"); + string Clients = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + Clients = result.Rows[i]["clients_id"].ToString() + " | " + + (string)result.Rows[i]["name"] + " | " + + result.Rows[i]["surname"].ToString() + " | " + + (string)result.Rows[i]["patronymic"] + " | " + + result.Rows[i]["email"].ToString() + " | " + + result.Rows[i]["phone_number"].ToString() + " | " + + ((DateTime)result.Rows[i]["registration_date"]).ToString("dd.MM.yyyy") + "\n"; + comboBoxUpdateClient.Items.Add(Clients); + } + } + private void buttonUpdateClient_Click(object sender, EventArgs e) + { + string[] selectedClients = comboBoxUpdateClient.SelectedItem.ToString().Split("|"); + int clients_id = int.Parse(selectedClients[0].Trim()); + + string query = $"UPDATE clients SET "; + int len = query.Length; + + + string oldName = managmentDatabase.getRowTableById("clients", "name", clients_id).ToString(); + string oldSurname = managmentDatabase.getRowTableById("clients", "surname", clients_id).ToString(); + string oldPatronymic = managmentDatabase.getRowTableById("clients", "patronymic", clients_id).ToString(); + string oldEmail = managmentDatabase.getRowTableById("clients", "email", clients_id).ToString(); + string oldPhoneNumber = managmentDatabase.getRowTableById("clients", "phone_number", clients_id).ToString(); + string oldDate = ((DateTime)managmentDatabase.getRowTableById("clients", "registration_date", clients_id)).ToString("dd.MM.yyyy"); + + string newName = textBoxName.Text; + string newSurname = textBoxSurname.Text; + string newPatronymic = textBoxPatronymic.Text; + string newEmail = textBoxEmail.Text; + string newPhoneNumber = textBoxPhoneNumber.Text; + string newDate = textBoxDate.Text; + + + query = oldName == newName ? query : query + $"name = '{newName}', "; + query = oldSurname == newSurname ? query : query + $"surname = '{newSurname}', "; + query = oldPatronymic == newPatronymic ? query : query + $"patronymic = '{newPatronymic}', "; + query = oldEmail == newEmail ? query : query + $"email = '{newEmail}', "; + query = oldPhoneNumber == newPhoneNumber ? query : query + $"phone_number = {newPhoneNumber}, "; + query = oldDate == newDate ? query : query + $"registration_date = '{newDate}', "; + + if (len != query.Length) + { + query = query.TrimEnd(' '); + query = query.TrimEnd(','); + query += $" WHERE Clients_ID = {clients_id};"; + } + try + { + DateTime start = DateTime.Now; + + managmentDatabase.ExecuteNonQuery(query); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Данные успешно обновлены! Время выполнения: {duration.TotalMilliseconds} мс"); + } + catch (Exception) + { + + MessageBox.Show("Данные не обновились"); + } + } + public void LoadDataSelectedItem(int clients_id) + { + DataTable result = managmentDatabase.getEntryById("clients", clients_id); + textBoxName.Text = managmentDatabase.getRowTableById(result, "name", 0).ToString(); + textBoxSurname.Text = managmentDatabase.getRowTableById(result, "surname", 0).ToString(); + textBoxPatronymic.Text = managmentDatabase.getRowTableById(result, "patronymic", 0).ToString(); + textBoxEmail.Text = managmentDatabase.getRowTableById(result, "email", 0).ToString(); + textBoxPhoneNumber.Text = managmentDatabase.getRowTableById(result, "phone_number", 0).ToString(); + textBoxDate.Text = ((DateTime)managmentDatabase.getRowTableById(result, "registration_date", 0)).ToString("dd.MM.yyyy"); + } + + private void comboBoxUpdateClient_SelectedIndexChanged(object sender, EventArgs e) + { + string[] selectedItems = comboBoxUpdateClient.SelectedItem.ToString().Split("|"); + int clients_id = int.Parse(selectedItems[0].Trim()); + LoadDataSelectedItem(clients_id); + } + } +} diff --git a/BulletinBoard/BulletinBoard/ClientsForm/UpdateClientsForm.resx b/BulletinBoard/BulletinBoard/ClientsForm/UpdateClientsForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BulletinBoard/BulletinBoard/ClientsForm/UpdateClientsForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/MainForm.Designer.cs b/BulletinBoard/BulletinBoard/MainForm.Designer.cs new file mode 100644 index 0000000..0bf975f --- /dev/null +++ b/BulletinBoard/BulletinBoard/MainForm.Designer.cs @@ -0,0 +1,448 @@ +namespace WebsiteForPlacingAds +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip1 = new MenuStrip(); + клиентыToolStripMenuItem = new ToolStripMenuItem(); + создатьКлиентаToolStripMenuItem = new ToolStripMenuItem(); + удалитьКлиентаToolStripMenuItem = new ToolStripMenuItem(); + изменитьДанныеКлиентаToolStripMenuItem = new ToolStripMenuItem(); + списокКлиентвToolStripMenuItem = new ToolStripMenuItem(); + объявленияToolStripMenuItem = new ToolStripMenuItem(); + создатьОбъявлениеToolStripMenuItem = new ToolStripMenuItem(); + удалитьОбъявлениеToolStripMenuItem = new ToolStripMenuItem(); + изменитьОбъявлениеэToolStripMenuItem = new ToolStripMenuItem(); + списокОбъявленийToolStripMenuItem = new ToolStripMenuItem(); + категорииToolStripMenuItem = new ToolStripMenuItem(); + создатьКатегориюToolStripMenuItem = new ToolStripMenuItem(); + удалитьКатегориюToolStripMenuItem = new ToolStripMenuItem(); + изменитьКатегориюToolStripMenuItem = new ToolStripMenuItem(); + списокКатегорийToolStripMenuItem = new ToolStripMenuItem(); + подкатегорииToolStripMenuItem = new ToolStripMenuItem(); + создатьПодкатеориюToolStripMenuItem = new ToolStripMenuItem(); + удалитьПодкатегориюToolStripMenuItem = new ToolStripMenuItem(); + изменитьПодкатегориюToolStripMenuItem = new ToolStripMenuItem(); + списокПодкатегоийToolStripMenuItem = new ToolStripMenuItem(); + toolStripMenuItem1 = new ToolStripMenuItem(); + toolStripMenuItem2 = new ToolStripMenuItem(); + toolStripMenuItem3 = new ToolStripMenuItem(); + toolStripMenuItem4 = new ToolStripMenuItem(); + toolStripMenuItem5 = new ToolStripMenuItem(); + label1 = new Label(); + button1 = new Button(); + panel1 = new Panel(); + panel2 = new Panel(); + button2 = new Button(); + label2 = new Label(); + panel3 = new Panel(); + button3 = new Button(); + label3 = new Label(); + toolStripMenuItem6 = new ToolStripMenuItem(); + toolStripMenuItem7 = new ToolStripMenuItem(); + toolStripMenuItem8 = new ToolStripMenuItem(); + toolStripMenuItem9 = new ToolStripMenuItem(); + toolStripMenuItem10 = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + panel1.SuspendLayout(); + panel2.SuspendLayout(); + panel3.SuspendLayout(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { клиентыToolStripMenuItem, объявленияToolStripMenuItem, категорииToolStripMenuItem, подкатегорииToolStripMenuItem, toolStripMenuItem1, toolStripMenuItem6 }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Padding = new Padding(5, 2, 0, 2); + menuStrip1.Size = new Size(700, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // клиентыToolStripMenuItem + // + клиентыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { создатьКлиентаToolStripMenuItem, удалитьКлиентаToolStripMenuItem, изменитьДанныеКлиентаToolStripMenuItem, списокКлиентвToolStripMenuItem }); + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(67, 20); + клиентыToolStripMenuItem.Text = "Клиенты"; + // + // создатьКлиентаToolStripMenuItem + // + создатьКлиентаToolStripMenuItem.Name = "создатьКлиентаToolStripMenuItem"; + создатьКлиентаToolStripMenuItem.Size = new Size(219, 22); + создатьКлиентаToolStripMenuItem.Text = "Создать клиента"; + создатьКлиентаToolStripMenuItem.Click += создатьКлиентаToolStripMenuItem_Click; + // + // удалитьКлиентаToolStripMenuItem + // + удалитьКлиентаToolStripMenuItem.Name = "удалитьКлиентаToolStripMenuItem"; + удалитьКлиентаToolStripMenuItem.Size = new Size(219, 22); + удалитьКлиентаToolStripMenuItem.Text = "Удалить клиента"; + удалитьКлиентаToolStripMenuItem.Click += удалитьКлиентаToolStripMenuItem_Click; + // + // изменитьДанныеКлиентаToolStripMenuItem + // + изменитьДанныеКлиентаToolStripMenuItem.Name = "изменитьДанныеКлиентаToolStripMenuItem"; + изменитьДанныеКлиентаToolStripMenuItem.Size = new Size(219, 22); + изменитьДанныеКлиентаToolStripMenuItem.Text = "Изменить данные клиента"; + изменитьДанныеКлиентаToolStripMenuItem.Click += изменитьДанныеКлиентаToolStripMenuItem_Click; + // + // списокКлиентвToolStripMenuItem + // + списокКлиентвToolStripMenuItem.Name = "списокКлиентвToolStripMenuItem"; + списокКлиентвToolStripMenuItem.Size = new Size(219, 22); + списокКлиентвToolStripMenuItem.Text = "Список клиентов"; + списокКлиентвToolStripMenuItem.Click += списокКлиентвToolStripMenuItem_Click; + // + // объявленияToolStripMenuItem + // + объявленияToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { создатьОбъявлениеToolStripMenuItem, удалитьОбъявлениеToolStripMenuItem, изменитьОбъявлениеэToolStripMenuItem, списокОбъявленийToolStripMenuItem }); + объявленияToolStripMenuItem.Name = "объявленияToolStripMenuItem"; + объявленияToolStripMenuItem.Size = new Size(87, 20); + объявленияToolStripMenuItem.Text = "Объявления"; + // + // создатьОбъявлениеToolStripMenuItem + // + создатьОбъявлениеToolStripMenuItem.Name = "создатьОбъявлениеToolStripMenuItem"; + создатьОбъявлениеToolStripMenuItem.Size = new Size(197, 22); + создатьОбъявлениеToolStripMenuItem.Text = "Создать объявление"; + создатьОбъявлениеToolStripMenuItem.Click += создатьОбъявлениеToolStripMenuItem_Click; + // + // удалитьОбъявлениеToolStripMenuItem + // + удалитьОбъявлениеToolStripMenuItem.Name = "удалитьОбъявлениеToolStripMenuItem"; + удалитьОбъявлениеToolStripMenuItem.Size = new Size(197, 22); + удалитьОбъявлениеToolStripMenuItem.Text = "Удалить объявление"; + удалитьОбъявлениеToolStripMenuItem.Click += удалитьОбъявлениеToolStripMenuItem_Click; + // + // изменитьОбъявлениеэToolStripMenuItem + // + изменитьОбъявлениеэToolStripMenuItem.Name = "изменитьОбъявлениеэToolStripMenuItem"; + изменитьОбъявлениеэToolStripMenuItem.Size = new Size(197, 22); + изменитьОбъявлениеэToolStripMenuItem.Text = "Изменить объявление"; + изменитьОбъявлениеэToolStripMenuItem.Click += изменитьОбъявлениеэToolStripMenuItem_Click; + // + // списокОбъявленийToolStripMenuItem + // + списокОбъявленийToolStripMenuItem.Name = "списокОбъявленийToolStripMenuItem"; + списокОбъявленийToolStripMenuItem.Size = new Size(197, 22); + списокОбъявленийToolStripMenuItem.Text = "Список объявлений"; + списокОбъявленийToolStripMenuItem.Click += списокОбъявленийToolStripMenuItem_Click; + // + // категорииToolStripMenuItem + // + категорииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { создатьКатегориюToolStripMenuItem, удалитьКатегориюToolStripMenuItem, изменитьКатегориюToolStripMenuItem, списокКатегорийToolStripMenuItem }); + категорииToolStripMenuItem.Name = "категорииToolStripMenuItem"; + категорииToolStripMenuItem.Size = new Size(76, 20); + категорииToolStripMenuItem.Text = "Категории"; + // + // создатьКатегориюToolStripMenuItem + // + создатьКатегориюToolStripMenuItem.Name = "создатьКатегориюToolStripMenuItem"; + создатьКатегориюToolStripMenuItem.Size = new Size(190, 22); + создатьКатегориюToolStripMenuItem.Text = "Создать категорию"; + создатьКатегориюToolStripMenuItem.Click += создатьКатегориюToolStripMenuItem_Click; + // + // удалитьКатегориюToolStripMenuItem + // + удалитьКатегориюToolStripMenuItem.Name = "удалитьКатегориюToolStripMenuItem"; + удалитьКатегориюToolStripMenuItem.Size = new Size(190, 22); + удалитьКатегориюToolStripMenuItem.Text = "Удалить категорию"; + удалитьКатегориюToolStripMenuItem.Click += удалитьКатегориюToolStripMenuItem_Click; + // + // изменитьКатегориюToolStripMenuItem + // + изменитьКатегориюToolStripMenuItem.Name = "изменитьКатегориюToolStripMenuItem"; + изменитьКатегориюToolStripMenuItem.Size = new Size(190, 22); + изменитьКатегориюToolStripMenuItem.Text = "Изменить категорию"; + изменитьКатегориюToolStripMenuItem.Click += изменитьКатегориюToolStripMenuItem_Click; + // + // списокКатегорийToolStripMenuItem + // + списокКатегорийToolStripMenuItem.Name = "списокКатегорийToolStripMenuItem"; + списокКатегорийToolStripMenuItem.Size = new Size(190, 22); + списокКатегорийToolStripMenuItem.Text = "Список категорий"; + списокКатегорийToolStripMenuItem.Click += списокКатегорийToolStripMenuItem_Click; + // + // подкатегорииToolStripMenuItem + // + подкатегорииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { создатьПодкатеориюToolStripMenuItem, удалитьПодкатегориюToolStripMenuItem, изменитьПодкатегориюToolStripMenuItem, списокПодкатегоийToolStripMenuItem }); + подкатегорииToolStripMenuItem.Name = "подкатегорииToolStripMenuItem"; + подкатегорииToolStripMenuItem.Size = new Size(97, 20); + подкатегорииToolStripMenuItem.Text = "Подкатегории"; + // + // создатьПодкатеориюToolStripMenuItem + // + создатьПодкатеориюToolStripMenuItem.Name = "создатьПодкатеориюToolStripMenuItem"; + создатьПодкатеориюToolStripMenuItem.Size = new Size(210, 22); + создатьПодкатеориюToolStripMenuItem.Text = "Создать подкатегорию"; + создатьПодкатеориюToolStripMenuItem.Click += создатьПодкатеориюToolStripMenuItem_Click; + // + // удалитьПодкатегориюToolStripMenuItem + // + удалитьПодкатегориюToolStripMenuItem.Name = "удалитьПодкатегориюToolStripMenuItem"; + удалитьПодкатегориюToolStripMenuItem.Size = new Size(210, 22); + удалитьПодкатегориюToolStripMenuItem.Text = "Удалить подкатегорию"; + удалитьПодкатегориюToolStripMenuItem.Click += удалитьПодкатегориюToolStripMenuItem_Click; + // + // изменитьПодкатегориюToolStripMenuItem + // + изменитьПодкатегориюToolStripMenuItem.Name = "изменитьПодкатегориюToolStripMenuItem"; + изменитьПодкатегориюToolStripMenuItem.Size = new Size(210, 22); + изменитьПодкатегориюToolStripMenuItem.Text = "Изменить подкатегорию"; + изменитьПодкатегориюToolStripMenuItem.Click += изменитьПодкатегориюToolStripMenuItem_Click; + // + // списокПодкатегоийToolStripMenuItem + // + списокПодкатегоийToolStripMenuItem.Name = "списокПодкатегоийToolStripMenuItem"; + списокПодкатегоийToolStripMenuItem.Size = new Size(210, 22); + списокПодкатегоийToolStripMenuItem.Text = "Список подкатегорий"; + списокПодкатегоийToolStripMenuItem.Click += списокПодкатегоийToolStripMenuItem_Click; + // + // toolStripMenuItem1 + // + toolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItem2, toolStripMenuItem3, toolStripMenuItem4, toolStripMenuItem5 }); + toolStripMenuItem1.Name = "toolStripMenuItem1"; + toolStripMenuItem1.Size = new Size(67, 20); + toolStripMenuItem1.Text = "Регионы"; + // + // toolStripMenuItem2 + // + toolStripMenuItem2.Name = "toolStripMenuItem2"; + toolStripMenuItem2.Size = new Size(180, 22); + toolStripMenuItem2.Text = "Создать регион"; + toolStripMenuItem2.Click += создатьРегионToolStripMenuItem_Click; + // + // toolStripMenuItem3 + // + toolStripMenuItem3.Name = "toolStripMenuItem3"; + toolStripMenuItem3.Size = new Size(180, 22); + toolStripMenuItem3.Text = "Удалить регион"; + toolStripMenuItem3.Click += удалитьРегионToolStripMenuItem_Click; + // + // toolStripMenuItem4 + // + toolStripMenuItem4.Name = "toolStripMenuItem4"; + toolStripMenuItem4.Size = new Size(180, 22); + toolStripMenuItem4.Text = "Изменить регион"; + toolStripMenuItem4.Click += изменитьРегионToolStripMenuItem_Click; + // + // toolStripMenuItem5 + // + toolStripMenuItem5.Name = "toolStripMenuItem5"; + toolStripMenuItem5.Size = new Size(180, 22); + toolStripMenuItem5.Text = "Список регион"; + toolStripMenuItem5.Click += списокРегионToolStripMenuItem_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(3, 11); + label1.Name = "label1"; + label1.Size = new Size(225, 15); + label1.TabIndex = 1; + label1.Text = "Сценарий 1: Добавление 1000 клиентов"; + // + // button1 + // + button1.Location = new Point(63, 66); + button1.Name = "button1"; + button1.Size = new Size(95, 33); + button1.TabIndex = 2; + button1.Text = "Старт"; + button1.UseVisualStyleBackColor = true; + button1.Click += button1_Click; + // + // panel1 + // + panel1.Controls.Add(button1); + panel1.Controls.Add(label1); + panel1.Location = new Point(12, 83); + panel1.Name = "panel1"; + panel1.Size = new Size(222, 102); + panel1.TabIndex = 3; + // + // panel2 + // + panel2.Controls.Add(button2); + panel2.Controls.Add(label2); + panel2.Location = new Point(240, 83); + panel2.Name = "panel2"; + panel2.Size = new Size(222, 102); + panel2.TabIndex = 4; + // + // button2 + // + button2.Location = new Point(63, 66); + button2.Name = "button2"; + button2.Size = new Size(95, 33); + button2.TabIndex = 2; + button2.Text = "Старт"; + button2.UseVisualStyleBackColor = true; + button2.Click += button2_Click; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(3, 11); + label2.Name = "label2"; + label2.Size = new Size(210, 15); + label2.TabIndex = 1; + label2.Text = "Сценарий 2: Удаление 1000 клиентов"; + // + // panel3 + // + panel3.Controls.Add(button3); + panel3.Controls.Add(label3); + panel3.Location = new Point(468, 83); + panel3.Name = "panel3"; + panel3.Size = new Size(222, 102); + panel3.TabIndex = 5; + // + // button3 + // + button3.Location = new Point(63, 66); + button3.Name = "button3"; + button3.Size = new Size(95, 33); + button3.TabIndex = 2; + button3.Text = "Старт"; + button3.UseVisualStyleBackColor = true; + button3.Click += button3_Click; + // + // label3 + // + label3.Location = new Point(7, 11); + label3.Name = "label3"; + label3.Size = new Size(213, 44); + label3.TabIndex = 1; + label3.Text = "Сценарий 3: Изменение фамилий 1000 клиентов на \"surname2\""; + // + // toolStripMenuItem6 + // + toolStripMenuItem6.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItem7, toolStripMenuItem8, toolStripMenuItem9, toolStripMenuItem10 }); + toolStripMenuItem6.Name = "toolStripMenuItem6"; + toolStripMenuItem6.Size = new Size(58, 20); + toolStripMenuItem6.Text = "Города"; + // + // toolStripMenuItem7 + // + toolStripMenuItem7.Name = "toolStripMenuItem7"; + toolStripMenuItem7.Size = new Size(180, 22); + toolStripMenuItem7.Text = "Создать город"; + toolStripMenuItem7.Click += создатьГородToolStripMenuItem_Click; + // + // toolStripMenuItem8 + // + toolStripMenuItem8.Name = "toolStripMenuItem8"; + toolStripMenuItem8.Size = new Size(180, 22); + toolStripMenuItem8.Text = "Удалить город"; + toolStripMenuItem8.Click += удалитьГородToolStripMenuItem_Click; + // + // toolStripMenuItem9 + // + toolStripMenuItem9.Name = "toolStripMenuItem9"; + toolStripMenuItem9.Size = new Size(180, 22); + toolStripMenuItem9.Text = "Изменить город"; + toolStripMenuItem9.Click += изменитьГородToolStripMenuItem_Click; + // + // toolStripMenuItem10 + // + toolStripMenuItem10.Name = "toolStripMenuItem10"; + toolStripMenuItem10.Size = new Size(180, 22); + toolStripMenuItem10.Text = "Список город"; + toolStripMenuItem10.Click += списокГородToolStripMenuItem_Click; + // + // MainForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(700, 338); + Controls.Add(panel3); + Controls.Add(panel2); + Controls.Add(panel1); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Margin = new Padding(3, 2, 3, 2); + Name = "MainForm"; + Text = "MainForm"; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + panel1.ResumeLayout(false); + panel1.PerformLayout(); + panel2.ResumeLayout(false); + panel2.PerformLayout(); + panel3.ResumeLayout(false); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem создатьКлиентаToolStripMenuItem; + private ToolStripMenuItem удалитьКлиентаToolStripMenuItem; + private ToolStripMenuItem изменитьДанныеКлиентаToolStripMenuItem; + private ToolStripMenuItem списокКлиентвToolStripMenuItem; + private ToolStripMenuItem объявленияToolStripMenuItem; + private ToolStripMenuItem создатьОбъявлениеToolStripMenuItem; + private ToolStripMenuItem категорииToolStripMenuItem; + private ToolStripMenuItem подкатегорииToolStripMenuItem; + private ToolStripMenuItem удалитьОбъявлениеToolStripMenuItem; + private ToolStripMenuItem изменитьОбъявлениеэToolStripMenuItem; + private ToolStripMenuItem списокОбъявленийToolStripMenuItem; + private ToolStripMenuItem создатьКатегориюToolStripMenuItem; + private ToolStripMenuItem удалитьКатегориюToolStripMenuItem; + private ToolStripMenuItem изменитьКатегориюToolStripMenuItem; + private ToolStripMenuItem списокКатегорийToolStripMenuItem; + private ToolStripMenuItem создатьПодкатеориюToolStripMenuItem; + private ToolStripMenuItem удалитьПодкатегориюToolStripMenuItem; + private ToolStripMenuItem изменитьПодкатегориюToolStripMenuItem; + private ToolStripMenuItem списокПодкатегоийToolStripMenuItem; + private Label label1; + private Button button1; + private Panel panel1; + private Panel panel2; + private Button button2; + private Label label2; + private Panel panel3; + private Button button3; + private Label label3; + private ToolStripMenuItem toolStripMenuItem1; + private ToolStripMenuItem toolStripMenuItem2; + private ToolStripMenuItem toolStripMenuItem3; + private ToolStripMenuItem toolStripMenuItem4; + private ToolStripMenuItem toolStripMenuItem5; + private ToolStripMenuItem toolStripMenuItem6; + private ToolStripMenuItem toolStripMenuItem7; + private ToolStripMenuItem toolStripMenuItem8; + private ToolStripMenuItem toolStripMenuItem9; + private ToolStripMenuItem toolStripMenuItem10; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/MainForm.cs b/BulletinBoard/BulletinBoard/MainForm.cs new file mode 100644 index 0000000..6f7a749 --- /dev/null +++ b/BulletinBoard/BulletinBoard/MainForm.cs @@ -0,0 +1,205 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WebsiteForPlacingAds +{ + public partial class MainForm : Form + { + AbstractManagmentDatabase managmentDatabase; + + + public MainForm() + { + InitializeComponent(); + managmentDatabase = new ManagmentDatabase("Server=192.168.56.101;Port=5432;User Id=postgres;Password=postgres;Database=lab4;"); + } + + private void создатьКатегориюToolStripMenuItem_Click(object sender, EventArgs e) + { + CreateCategoriesForm ccf = new CreateCategoriesForm(managmentDatabase); + ccf.Show(); + } + + private void удалитьКатегориюToolStripMenuItem_Click(object sender, EventArgs e) + { + DeleteCategoriesForm dcf = new DeleteCategoriesForm(managmentDatabase); + dcf.Show(); + } + + private void изменитьКатегориюToolStripMenuItem_Click(object sender, EventArgs e) + { + UpdateCategoriesForm ucf = new UpdateCategoriesForm(managmentDatabase); + ucf.Show(); + } + + private void списокКатегорийToolStripMenuItem_Click(object sender, EventArgs e) + { + ListCategoriesForm lcf = new ListCategoriesForm(managmentDatabase); + lcf.Show(); + } + + private void создатьРегионToolStripMenuItem_Click(object sender, EventArgs e) + { + CreateRegionsForm crf = new CreateRegionsForm(managmentDatabase); + crf.Show(); + } + + private void удалитьРегионToolStripMenuItem_Click(object sender, EventArgs e) + { + DeleteRegionsForm drf = new DeleteRegionsForm(managmentDatabase); + drf.Show(); + } + + private void изменитьРегионToolStripMenuItem_Click(object sender, EventArgs e) + { + UpdateRegionsForm urf = new UpdateRegionsForm(managmentDatabase); + urf.Show(); + } + + private void списокРегионToolStripMenuItem_Click(object sender, EventArgs e) + { + ListRegionsForm lrf = new ListRegionsForm(managmentDatabase); + lrf.Show(); + } + + private void создатьГородToolStripMenuItem_Click(object sender, EventArgs e) + { + CreateCitiesForm crf = new CreateCitiesForm(managmentDatabase); + crf.Show(); + } + + private void удалитьГородToolStripMenuItem_Click(object sender, EventArgs e) + { + DeleteCitiesForm drf = new DeleteCitiesForm(managmentDatabase); + drf.Show(); + } + + private void изменитьГородToolStripMenuItem_Click(object sender, EventArgs e) + { + UpdateCitiesForm urf = new UpdateCitiesForm(managmentDatabase); + urf.Show(); + } + + private void списокГородToolStripMenuItem_Click(object sender, EventArgs e) + { + ListCitiesForm lrf = new ListCitiesForm(managmentDatabase); + lrf.Show(); + } + + private void создатьОбъявлениеToolStripMenuItem_Click(object sender, EventArgs e) + { + CreateAdsForm caf = new CreateAdsForm(managmentDatabase); + caf.Show(); + } + + private void удалитьОбъявлениеToolStripMenuItem_Click(object sender, EventArgs e) + { + DeleteAdsForm uaf = new DeleteAdsForm(managmentDatabase); + uaf.Show(); + } + + private void изменитьОбъявлениеэToolStripMenuItem_Click(object sender, EventArgs e) + { + UpdateAdsForm daf = new UpdateAdsForm(managmentDatabase); + daf.Show(); + } + + private void списокОбъявленийToolStripMenuItem_Click(object sender, EventArgs e) + { + ListAdsForm laf = new ListAdsForm(managmentDatabase); + laf.Show(); + } + + private void создатьКлиентаToolStripMenuItem_Click(object sender, EventArgs e) + { + CreateClientsForm ccf = new CreateClientsForm(managmentDatabase); + ccf.Show(); + } + + private void удалитьКлиентаToolStripMenuItem_Click(object sender, EventArgs e) + { + DeleteClientsForm dcf = new DeleteClientsForm(managmentDatabase); + dcf.Show(); + } + + private void изменитьДанныеКлиентаToolStripMenuItem_Click(object sender, EventArgs e) + { + UpdateClientsForm ucf = new UpdateClientsForm(managmentDatabase); + ucf.Show(); + } + private void списокКлиентвToolStripMenuItem_Click(object sender, EventArgs e) + { + ListClientsForm lcf = new ListClientsForm(managmentDatabase); + lcf.Show(); + } + + private void создатьПодкатеориюToolStripMenuItem_Click(object sender, EventArgs e) + { + CreateSubcategoriesForm csf = new CreateSubcategoriesForm(managmentDatabase); + csf.Show(); + } + + private void удалитьПодкатегориюToolStripMenuItem_Click(object sender, EventArgs e) + { + DeleteSubcategoriesForm dsf = new DeleteSubcategoriesForm(managmentDatabase); + dsf.Show(); + } + + private void изменитьПодкатегориюToolStripMenuItem_Click(object sender, EventArgs e) + { + UpdateSubcategoriesForm usf = new UpdateSubcategoriesForm(managmentDatabase); + usf.Show(); + } + + private void списокПодкатегоийToolStripMenuItem_Click(object sender, EventArgs e) + { + ListSubcategoriesForm lsf = new ListSubcategoriesForm(managmentDatabase); + lsf.Show(); + } + private void button1_Click(object sender, EventArgs e) + { + DateTime start = DateTime.Now; + + for (int i = 0; i < 1000; i++) + { + managmentDatabase.insertInto("clients", "'name'", "'surname'", "'patronymic'", "'email@mail.ru'", $"{89372511129}", "'20.01.2022'"); + } + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Сценарий 1 завершен! Время выполнения: {duration.TotalMilliseconds} мс"); + } + + private void button2_Click(object sender, EventArgs e) + { + DateTime start = DateTime.Now; + + for (int i = 0; i < 1000; i++) + { + managmentDatabase.deleteEntry("clients", "name"); + } + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Сценарий 2 завершен! Время выполнения: {duration.TotalMilliseconds} мс"); + } + + private void button3_Click(object sender, EventArgs e) + { + DateTime start = DateTime.Now; + + managmentDatabase.ExecuteNonQuery("Update clients Set surname = 'surname2' where surname = 'surname'"); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Сценарий 3 завершен! Время выполнения: {duration.TotalMilliseconds} мс"); + } + } +} diff --git a/BulletinBoard/BulletinBoard/MainForm.resx b/BulletinBoard/BulletinBoard/MainForm.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/BulletinBoard/BulletinBoard/MainForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/ManagmentDatabase.cs b/BulletinBoard/BulletinBoard/ManagmentDatabase.cs new file mode 100644 index 0000000..0554314 --- /dev/null +++ b/BulletinBoard/BulletinBoard/ManagmentDatabase.cs @@ -0,0 +1,85 @@ +using Npgsql; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WebsiteForPlacingAds +{ + public class ManagmentDatabase : AbstractManagmentDatabase + { + protected NpgsqlConnection connection; + + public ManagmentDatabase(String connectionString) + { + connection = new NpgsqlConnection(connectionString); + } + + public override Object getRowTableById(string tableName, string columnName, int id) + { + return ExecuteQuery($"SELECT {columnName} FROM {tableName} WHERE {tableName}_id = {id}").Rows[0][$"{columnName}"]; + } + + public override Object getRowTableById(DataTable table, string columnName, int i) + { + return table.Rows[i][columnName]; + } + + public override DataTable getEntryById(string tableName, int id) + { + return ExecuteQuery($"SELECT * FROM {tableName} WHERE {tableName}_id = {id}"); + } + + public override DataTable getAllEntry(string tableName) + { + return ExecuteQuery($"SELECT * FROM {tableName}"); + } + + public override void insertInto(string tableName, params string[] values) + { + string query = $"INSERT INTO {tableName} VALUES (nextval('seq_{tableName.ToLower()}'), "; // seq_{tableName.} + for (int i = 0; i < values.Length; i++) + { + if (i < values.Length - 1) query += $"{values[i]}, "; + else query += $"{values[i]})"; + } + ExecuteNonQuery(query); + } + + public override void deleteEntry(string tableName, int id) + { + ExecuteNonQuery($"DELETE FROM {tableName} WHERE {tableName}_id = {id}"); + } + + public override void deleteEntry(string tableName, string name) + { + ExecuteNonQuery($"DELETE FROM {tableName} WHERE name = '{name}'"); + } + + public override void reduceSeq(string seq, int currval) + { + ExecuteNonQuery($"SELECT setval('{seq}', {currval});"); + } + + public override void ExecuteNonQuery(string query) + { + connection.Open(); + NpgsqlCommand command = new NpgsqlCommand(query, connection); + command.ExecuteNonQuery(); + connection.Close(); + } + + public override DataTable ExecuteQuery(string query) + { + connection.Open(); + NpgsqlCommand command = new NpgsqlCommand(query, connection); + NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(command); + DataTable result = new DataTable(); + adapter.Fill(result); + connection.Close(); + return result; + } + } +} diff --git a/BulletinBoard/BulletinBoard/Program.cs b/BulletinBoard/BulletinBoard/Program.cs new file mode 100644 index 0000000..4a9f366 --- /dev/null +++ b/BulletinBoard/BulletinBoard/Program.cs @@ -0,0 +1,17 @@ +namespace WebsiteForPlacingAds +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new MainForm()); + } + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/RegionsForm/CreateRegionsForm.Designer.cs b/BulletinBoard/BulletinBoard/RegionsForm/CreateRegionsForm.Designer.cs new file mode 100644 index 0000000..69288c6 --- /dev/null +++ b/BulletinBoard/BulletinBoard/RegionsForm/CreateRegionsForm.Designer.cs @@ -0,0 +1,82 @@ +namespace WebsiteForPlacingAds +{ + partial class CreateRegionsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonCreateCity = new Button(); + labelName = new Label(); + textBoxName = new TextBox(); + SuspendLayout(); + // + // buttonCreateCity + // + buttonCreateCity.Location = new Point(49, 93); + buttonCreateCity.Name = "buttonCreateCity"; + buttonCreateCity.Size = new Size(273, 39); + buttonCreateCity.TabIndex = 0; + buttonCreateCity.Text = "Добавить город"; + buttonCreateCity.UseVisualStyleBackColor = true; + buttonCreateCity.Click += buttonCreateCity_Click; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(49, 11); + labelName.Name = "labelName"; + labelName.Size = new Size(77, 20); + labelName.TabIndex = 1; + labelName.Text = "Название"; + // + // textBoxName + // + textBoxName.Location = new Point(49, 35); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(273, 27); + textBoxName.TabIndex = 2; + // + // CreateRegionsForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(370, 157); + Controls.Add(textBoxName); + Controls.Add(labelName); + Controls.Add(buttonCreateCity); + Name = "CreateRegionsForm"; + Text = "Добавить Город"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCreateCity; + private Label labelName; + private TextBox textBoxName; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/RegionsForm/CreateRegionsForm.cs b/BulletinBoard/BulletinBoard/RegionsForm/CreateRegionsForm.cs new file mode 100644 index 0000000..98c1b23 --- /dev/null +++ b/BulletinBoard/BulletinBoard/RegionsForm/CreateRegionsForm.cs @@ -0,0 +1,40 @@ +using System.Data; + +namespace WebsiteForPlacingAds +{ + public partial class CreateRegionsForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public CreateRegionsForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + } + + private void buttonCreateCity_Click(object sender, EventArgs e) + { + string name = textBoxName.Text; + + + try + { + DateTime start = DateTime.Now; + + managmentDatabase.insertInto("regions", $"'{name}'"); + MessageBox.Show("!"); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"! : {duration.TotalMilliseconds} "); + + // + this.Close(); + } + catch (Exception ex) + { + MessageBox.Show(" "); + } + } + + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/RegionsForm/CreateRegionsForm.resx b/BulletinBoard/BulletinBoard/RegionsForm/CreateRegionsForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BulletinBoard/BulletinBoard/RegionsForm/CreateRegionsForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/RegionsForm/DeleteRegionsForm.Designer.cs b/BulletinBoard/BulletinBoard/RegionsForm/DeleteRegionsForm.Designer.cs new file mode 100644 index 0000000..963fa3a --- /dev/null +++ b/BulletinBoard/BulletinBoard/RegionsForm/DeleteRegionsForm.Designer.cs @@ -0,0 +1,86 @@ +namespace WebsiteForPlacingAds +{ + partial class DeleteRegionsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + buttonDeleteRegion = new Button(); + comboBoxDeleteRegions = new ComboBox(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(70, 16); + label1.Name = "label1"; + label1.Size = new Size(242, 15); + label1.TabIndex = 0; + label1.Text = "Выберите регион, которую хотите удалить"; + // + // buttonDeleteRegion + // + buttonDeleteRegion.Location = new Point(132, 85); + buttonDeleteRegion.Margin = new Padding(3, 2, 3, 2); + buttonDeleteRegion.Name = "buttonDeleteRegion"; + buttonDeleteRegion.Size = new Size(163, 28); + buttonDeleteRegion.TabIndex = 1; + buttonDeleteRegion.Text = "Удалить"; + buttonDeleteRegion.UseVisualStyleBackColor = true; + buttonDeleteRegion.Click += buttonDeleteRegion_Click; + // + // comboBoxDeleteRegions + // + comboBoxDeleteRegions.FormattingEnabled = true; + comboBoxDeleteRegions.Location = new Point(35, 48); + comboBoxDeleteRegions.Margin = new Padding(3, 2, 3, 2); + comboBoxDeleteRegions.Name = "comboBoxDeleteRegions"; + comboBoxDeleteRegions.Size = new Size(367, 23); + comboBoxDeleteRegions.TabIndex = 2; + // + // DeleteRegionsForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(442, 131); + Controls.Add(comboBoxDeleteRegions); + Controls.Add(buttonDeleteRegion); + Controls.Add(label1); + Margin = new Padding(3, 2, 3, 2); + Name = "DeleteRegionsForm"; + Text = "Удалить регион"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Button buttonDeleteRegion; + private ComboBox comboBoxDeleteRegions; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/RegionsForm/DeleteRegionsForm.cs b/BulletinBoard/BulletinBoard/RegionsForm/DeleteRegionsForm.cs new file mode 100644 index 0000000..90f4fe8 --- /dev/null +++ b/BulletinBoard/BulletinBoard/RegionsForm/DeleteRegionsForm.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WebsiteForPlacingAds +{ + public partial class DeleteRegionsForm : Form + { + AbstractManagmentDatabase managmentDatabase; + private int setval_seq; + public DeleteRegionsForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void buttonDeleteRegion_Click(object sender, EventArgs e) + { + string[] categories = comboBoxDeleteRegions.SelectedItem.ToString().Split("|"); + string category_id = categories[0].Trim(); + try + { + DateTime start = DateTime.Now; + + managmentDatabase.deleteEntry("regions", int.Parse(category_id)); + LoadData(); + if (setval_seq > 0) managmentDatabase.reduceSeq("seq_regions", setval_seq); + MessageBox.Show("Удалено!"); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Добавлено! Время выполнения: {duration.TotalMilliseconds} мс"); + } + catch (Exception ex) + { + MessageBox.Show("Не удалось удалить"); + } + } + public void LoadData() + { + comboBoxDeleteRegions.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("Regions"); + setval_seq = result.Rows.Count; + string Regions = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + setval_seq = Math.Max(Convert.ToInt32(managmentDatabase.getRowTableById(result, "regions_id", i)), setval_seq); + Regions = managmentDatabase.getRowTableById(result, "regions_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "name", i).ToString() + "\n"; + comboBoxDeleteRegions.Items.Add(Regions); + } + } + } +} diff --git a/BulletinBoard/BulletinBoard/RegionsForm/DeleteRegionsForm.resx b/BulletinBoard/BulletinBoard/RegionsForm/DeleteRegionsForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BulletinBoard/BulletinBoard/RegionsForm/DeleteRegionsForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/RegionsForm/ListRegionsForm.Designer.cs b/BulletinBoard/BulletinBoard/RegionsForm/ListRegionsForm.Designer.cs new file mode 100644 index 0000000..359eda0 --- /dev/null +++ b/BulletinBoard/BulletinBoard/RegionsForm/ListRegionsForm.Designer.cs @@ -0,0 +1,74 @@ +namespace WebsiteForPlacingAds +{ + partial class ListRegionsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + labelListRegions = new Label(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.BackColor = SystemColors.Control; + label1.Font = new Font("Segoe UI", 11F, FontStyle.Regular, GraphicsUnit.Point); + label1.Location = new Point(10, 7); + label1.Name = "label1"; + label1.Size = new Size(130, 20); + label1.TabIndex = 0; + label1.Text = "Список регионов"; + // + // labelListRegions + // + labelListRegions.AutoSize = true; + labelListRegions.Font = new Font("Segoe UI", 10F, FontStyle.Regular, GraphicsUnit.Point); + labelListRegions.Location = new Point(10, 35); + labelListRegions.Name = "labelListRegions"; + labelListRegions.Size = new Size(0, 19); + labelListRegions.TabIndex = 1; + // + // ListRegionsForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(700, 338); + Controls.Add(labelListRegions); + Controls.Add(label1); + Margin = new Padding(3, 2, 3, 2); + Name = "ListRegionsForm"; + Text = "Список регионов"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label labelListRegions; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/RegionsForm/ListRegionsForm.cs b/BulletinBoard/BulletinBoard/RegionsForm/ListRegionsForm.cs new file mode 100644 index 0000000..d0b3ff5 --- /dev/null +++ b/BulletinBoard/BulletinBoard/RegionsForm/ListRegionsForm.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Windows.Forms.VisualStyles; + +namespace WebsiteForPlacingAds +{ + public partial class ListRegionsForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public ListRegionsForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void LoadData() + { + DateTime start = DateTime.Now; + + DataTable result = managmentDatabase.getAllEntry("Regions"); + string listRegions = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + listRegions += managmentDatabase.getRowTableById(result, "regions_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "name", i).ToString() + "\n"; + } + labelListRegions.Text = listRegions; + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Добавлено! Время выполнения: {duration.TotalMilliseconds} мс"); + } + } +} diff --git a/BulletinBoard/BulletinBoard/RegionsForm/ListRegionsForm.resx b/BulletinBoard/BulletinBoard/RegionsForm/ListRegionsForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BulletinBoard/BulletinBoard/RegionsForm/ListRegionsForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/RegionsForm/UpdateRegionsForm.Designer.cs b/BulletinBoard/BulletinBoard/RegionsForm/UpdateRegionsForm.Designer.cs new file mode 100644 index 0000000..aacaf54 --- /dev/null +++ b/BulletinBoard/BulletinBoard/RegionsForm/UpdateRegionsForm.Designer.cs @@ -0,0 +1,109 @@ +namespace WebsiteForPlacingAds +{ + partial class UpdateRegionsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + comboBoxUpdateRegion = new ComboBox(); + textBoxName = new TextBox(); + labelName = new Label(); + buttonUpdateRegion = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(51, 15); + label1.Name = "label1"; + label1.Size = new Size(251, 15); + label1.TabIndex = 33; + label1.Text = "Выберите регион, которую хотите обновить"; + // + // comboBoxUpdateRegion + // + comboBoxUpdateRegion.FormattingEnabled = true; + comboBoxUpdateRegion.Location = new Point(10, 39); + comboBoxUpdateRegion.Margin = new Padding(3, 2, 3, 2); + comboBoxUpdateRegion.Name = "comboBoxUpdateRegion"; + comboBoxUpdateRegion.Size = new Size(377, 23); + comboBoxUpdateRegion.TabIndex = 34; + comboBoxUpdateRegion.SelectedIndexChanged += comboBoxUpdateRegion_SelectedIndexChanged; + // + // textBoxName + // + textBoxName.Location = new Point(78, 96); + textBoxName.Margin = new Padding(3, 2, 3, 2); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(239, 23); + textBoxName.TabIndex = 37; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(78, 78); + labelName.Name = "labelName"; + labelName.Size = new Size(59, 15); + labelName.TabIndex = 36; + labelName.Text = "Название"; + // + // buttonUpdateRegion + // + buttonUpdateRegion.Location = new Point(78, 140); + buttonUpdateRegion.Margin = new Padding(3, 2, 3, 2); + buttonUpdateRegion.Name = "buttonUpdateRegion"; + buttonUpdateRegion.Size = new Size(239, 29); + buttonUpdateRegion.TabIndex = 35; + buttonUpdateRegion.Text = "Обновить регион"; + buttonUpdateRegion.UseVisualStyleBackColor = true; + buttonUpdateRegion.Click += buttonUpdateRegion_Click_1; + // + // UpdateRegionsForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(397, 190); + Controls.Add(textBoxName); + Controls.Add(labelName); + Controls.Add(buttonUpdateRegion); + Controls.Add(comboBoxUpdateRegion); + Controls.Add(label1); + Margin = new Padding(3, 2, 3, 2); + Name = "UpdateRegionsForm"; + Text = "Обновить регион"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Label label1; + private ComboBox comboBoxUpdateRegion; + private TextBox textBoxName; + private Label labelName; + private Button buttonUpdateRegion; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/RegionsForm/UpdateRegionsForm.cs b/BulletinBoard/BulletinBoard/RegionsForm/UpdateRegionsForm.cs new file mode 100644 index 0000000..9b13744 --- /dev/null +++ b/BulletinBoard/BulletinBoard/RegionsForm/UpdateRegionsForm.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WebsiteForPlacingAds +{ + public partial class UpdateRegionsForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public UpdateRegionsForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + public void LoadData() + { + comboBoxUpdateRegion.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("Regions"); + string Regions = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + Regions = result.Rows[i]["regions_id"].ToString() + " | " + + (string)result.Rows[i]["name"] + "\n"; + comboBoxUpdateRegion.Items.Add(Regions); + } + } + public void LoadDataSelectedItem(int regions_id) + { + DataTable result = managmentDatabase.getEntryById("regions", regions_id); + textBoxName.Text = managmentDatabase.getRowTableById(result, "name", 0).ToString(); + } + + private void comboBoxUpdateRegion_SelectedIndexChanged(object sender, EventArgs e) + { + string[] selectedItems = comboBoxUpdateRegion.SelectedItem.ToString().Split("|"); + int region_id = int.Parse(selectedItems[0].Trim()); + LoadDataSelectedItem(region_id); + } + + private void buttonUpdateRegion_Click_1(object sender, EventArgs e) + { + string[] selectedCategory = comboBoxUpdateRegion.SelectedItem.ToString().Split("|"); + int region_id = int.Parse(selectedCategory[0].Trim()); + + string query = $"UPDATE Regions SET "; + int len = query.Length; + + + string oldName = managmentDatabase.getRowTableById("regions", "name", region_id).ToString(); + + string newName = textBoxName.Text; + + + query = oldName == newName ? query : query + $"name = '{newName}', "; + if (len != query.Length) + { + query = query.TrimEnd(' '); + query = query.TrimEnd(','); + query += $" WHERE Regions_ID = {region_id};"; + } + try + { + DateTime start = DateTime.Now; + + managmentDatabase.ExecuteNonQuery(query); + MessageBox.Show("Данные успешно обновлены!"); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Добавлено! Время выполнения: {duration.TotalMilliseconds} мс"); + } + catch (Exception) + { + + MessageBox.Show("Данные не обновились"); + } + } + } +} diff --git a/BulletinBoard/BulletinBoard/RegionsForm/UpdateRegionsForm.resx b/BulletinBoard/BulletinBoard/RegionsForm/UpdateRegionsForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BulletinBoard/BulletinBoard/RegionsForm/UpdateRegionsForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/SubcategoriesForm/CreateSubcategoriesForm.Designer.cs b/BulletinBoard/BulletinBoard/SubcategoriesForm/CreateSubcategoriesForm.Designer.cs new file mode 100644 index 0000000..17c634b --- /dev/null +++ b/BulletinBoard/BulletinBoard/SubcategoriesForm/CreateSubcategoriesForm.Designer.cs @@ -0,0 +1,109 @@ +namespace WebsiteForPlacingAds +{ + partial class CreateSubcategoriesForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + textBoxName = new TextBox(); + labelName = new Label(); + buttonCreateSubcategory = new Button(); + comboBoxCategory = new ComboBox(); + labelCategory = new Label(); + SuspendLayout(); + // + // textBoxName + // + textBoxName.Location = new Point(37, 35); + textBoxName.Margin = new Padding(3, 2, 3, 2); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(239, 23); + textBoxName.TabIndex = 5; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(37, 17); + labelName.Name = "labelName"; + labelName.Size = new Size(59, 15); + labelName.TabIndex = 4; + labelName.Text = "Название"; + // + // buttonCreateSubcategory + // + buttonCreateSubcategory.Location = new Point(37, 118); + buttonCreateSubcategory.Margin = new Padding(3, 2, 3, 2); + buttonCreateSubcategory.Name = "buttonCreateSubcategory"; + buttonCreateSubcategory.Size = new Size(239, 29); + buttonCreateSubcategory.TabIndex = 3; + buttonCreateSubcategory.Text = "Добавить подкатегорию"; + buttonCreateSubcategory.UseVisualStyleBackColor = true; + buttonCreateSubcategory.Click += buttonCreateSubcategory_Click_1; + // + // comboBoxCategory + // + comboBoxCategory.FormattingEnabled = true; + comboBoxCategory.Location = new Point(37, 83); + comboBoxCategory.Margin = new Padding(3, 2, 3, 2); + comboBoxCategory.Name = "comboBoxCategory"; + comboBoxCategory.Size = new Size(239, 23); + comboBoxCategory.TabIndex = 17; + // + // labelCategory + // + labelCategory.AutoSize = true; + labelCategory.Location = new Point(37, 67); + labelCategory.Name = "labelCategory"; + labelCategory.Size = new Size(63, 15); + labelCategory.TabIndex = 18; + labelCategory.Text = "Категория"; + // + // CreateSubcategoriesForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(324, 158); + Controls.Add(labelCategory); + Controls.Add(comboBoxCategory); + Controls.Add(textBoxName); + Controls.Add(labelName); + Controls.Add(buttonCreateSubcategory); + Margin = new Padding(3, 2, 3, 2); + Name = "CreateSubcategoriesForm"; + Text = "Подкатегория"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxName; + private Label labelName; + private Button buttonCreateSubcategory; + private ComboBox comboBoxCategory; + private Label labelCategory; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/SubcategoriesForm/CreateSubcategoriesForm.cs b/BulletinBoard/BulletinBoard/SubcategoriesForm/CreateSubcategoriesForm.cs new file mode 100644 index 0000000..7422322 --- /dev/null +++ b/BulletinBoard/BulletinBoard/SubcategoriesForm/CreateSubcategoriesForm.cs @@ -0,0 +1,56 @@ +using System.Data; + +namespace WebsiteForPlacingAds +{ + public partial class CreateSubcategoriesForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public CreateSubcategoriesForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void buttonCreateSubcategory_Click_1(object sender, EventArgs e) + { + string name = textBoxName.Text; + string[] category = comboBoxCategory.SelectedItem.ToString().Split(" "); + + string category_id = category[0]; + + + try + { + DateTime start = DateTime.Now; + + managmentDatabase.insertInto("subcategories", $"'{name}'", category_id); + MessageBox.Show("!"); + LoadData(); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"! : {duration.TotalMilliseconds} "); + + // + this.Close(); + } + catch (Exception ex) + { + MessageBox.Show(" "); + } + } + + private void LoadData() + { + comboBoxCategory.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("CATEGORIES"); + string[] id_names = new string[result.Rows.Count]; + for (int i = 0; i < result.Rows.Count; i++) + { + id_names[i] = managmentDatabase.getRowTableById(result, "categories_id", i).ToString() + ". " + managmentDatabase.getRowTableById(result, "name", i).ToString(); + comboBoxCategory.Items.Add(id_names[i]); + } + } + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/SubcategoriesForm/CreateSubcategoriesForm.resx b/BulletinBoard/BulletinBoard/SubcategoriesForm/CreateSubcategoriesForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BulletinBoard/BulletinBoard/SubcategoriesForm/CreateSubcategoriesForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/SubcategoriesForm/DeleteSubcategoriesForm.Designer.cs b/BulletinBoard/BulletinBoard/SubcategoriesForm/DeleteSubcategoriesForm.Designer.cs new file mode 100644 index 0000000..85c4b69 --- /dev/null +++ b/BulletinBoard/BulletinBoard/SubcategoriesForm/DeleteSubcategoriesForm.Designer.cs @@ -0,0 +1,87 @@ +namespace WebsiteForPlacingAds +{ + partial class DeleteSubcategoriesForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.comboBoxDeleteSubcategories = new System.Windows.Forms.ComboBox(); + this.buttonDeleteSubcategory = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // comboBoxDeleteSubcategories + // + this.comboBoxDeleteSubcategories.FormattingEnabled = true; + this.comboBoxDeleteSubcategories.Location = new System.Drawing.Point(38, 49); + this.comboBoxDeleteSubcategories.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxDeleteSubcategories.Name = "comboBoxDeleteSubcategories"; + this.comboBoxDeleteSubcategories.Size = new System.Drawing.Size(367, 23); + this.comboBoxDeleteSubcategories.TabIndex = 5; + // + // buttonDeleteSubcategory + // + this.buttonDeleteSubcategory.Location = new System.Drawing.Point(135, 86); + this.buttonDeleteSubcategory.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDeleteSubcategory.Name = "buttonDeleteSubcategory"; + this.buttonDeleteSubcategory.Size = new System.Drawing.Size(163, 28); + this.buttonDeleteSubcategory.TabIndex = 4; + this.buttonDeleteSubcategory.Text = "Удалить"; + this.buttonDeleteSubcategory.UseVisualStyleBackColor = true; + this.buttonDeleteSubcategory.Click += new System.EventHandler(this.buttonDeleteSubcategory_Click_1); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(73, 17); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(282, 15); + this.label1.TabIndex = 3; + this.label1.Text = "Выберите подкатегорию, которую хотите удалить"; + // + // DeleteSubcategoriesForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(442, 131); + this.Controls.Add(this.comboBoxDeleteSubcategories); + this.Controls.Add(this.buttonDeleteSubcategory); + this.Controls.Add(this.label1); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "DeleteSubcategoriesForm"; + this.Text = "Удалить подкатегорию"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxDeleteSubcategories; + private Button buttonDeleteSubcategory; + private Label label1; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/SubcategoriesForm/DeleteSubcategoriesForm.cs b/BulletinBoard/BulletinBoard/SubcategoriesForm/DeleteSubcategoriesForm.cs new file mode 100644 index 0000000..9a22894 --- /dev/null +++ b/BulletinBoard/BulletinBoard/SubcategoriesForm/DeleteSubcategoriesForm.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WebsiteForPlacingAds +{ + public partial class DeleteSubcategoriesForm : Form + { + AbstractManagmentDatabase managmentDatabase; + private int setval_seq; + public DeleteSubcategoriesForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + public void LoadData() + { + comboBoxDeleteSubcategories.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("Subcategories"); + setval_seq = result.Rows.Count; + string Subcategories = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + setval_seq = Math.Max(Convert.ToInt32(managmentDatabase.getRowTableById(result, "subcategories_id", i)), setval_seq); + Subcategories = managmentDatabase.getRowTableById(result, "subcategories_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "name", i).ToString() + "\n"; + comboBoxDeleteSubcategories.Items.Add(Subcategories); + } + } + + private void buttonDeleteSubcategory_Click_1(object sender, EventArgs e) + { + string[] subcategories = comboBoxDeleteSubcategories.SelectedItem.ToString().Split("|"); + string subcategory_id = subcategories[0].Trim(); + try + { + DateTime start = DateTime.Now; + + managmentDatabase.deleteEntry("subcategories", int.Parse(subcategory_id)); + LoadData(); + if (setval_seq > 0) managmentDatabase.reduceSeq("seq_subcategories", setval_seq); + MessageBox.Show("Удалено!"); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Добавлено! Время выполнения: {duration.TotalMilliseconds} мс"); + } + catch (Exception ex) + { + MessageBox.Show("Не удалось удалить"); + } + } + } +} diff --git a/BulletinBoard/BulletinBoard/SubcategoriesForm/DeleteSubcategoriesForm.resx b/BulletinBoard/BulletinBoard/SubcategoriesForm/DeleteSubcategoriesForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BulletinBoard/BulletinBoard/SubcategoriesForm/DeleteSubcategoriesForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/SubcategoriesForm/ListSubcategoriesForm.Designer.cs b/BulletinBoard/BulletinBoard/SubcategoriesForm/ListSubcategoriesForm.Designer.cs new file mode 100644 index 0000000..cbd1b5f --- /dev/null +++ b/BulletinBoard/BulletinBoard/SubcategoriesForm/ListSubcategoriesForm.Designer.cs @@ -0,0 +1,75 @@ +namespace WebsiteForPlacingAds +{ + partial class ListSubcategoriesForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.labelListSubcategories = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.BackColor = System.Drawing.SystemColors.Control; + this.label1.Font = new System.Drawing.Font("Segoe UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label1.Location = new System.Drawing.Point(10, 7); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(160, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Список подкатегорий"; + // + // labelListSubcategories + // + this.labelListSubcategories.AutoSize = true; + this.labelListSubcategories.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.labelListSubcategories.Location = new System.Drawing.Point(10, 35); + this.labelListSubcategories.Name = "labelListSubcategories"; + this.labelListSubcategories.Size = new System.Drawing.Size(0, 19); + this.labelListSubcategories.TabIndex = 1; + // + // ListSubcategoriesForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.labelListSubcategories); + this.Controls.Add(this.label1); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "ListSubcategoriesForm"; + this.Text = "Список подкатегорий"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label labelListSubcategories; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/SubcategoriesForm/ListSubcategoriesForm.cs b/BulletinBoard/BulletinBoard/SubcategoriesForm/ListSubcategoriesForm.cs new file mode 100644 index 0000000..c85b719 --- /dev/null +++ b/BulletinBoard/BulletinBoard/SubcategoriesForm/ListSubcategoriesForm.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Windows.Forms.VisualStyles; + +namespace WebsiteForPlacingAds +{ + public partial class ListSubcategoriesForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public ListSubcategoriesForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + + private void LoadData() + { + DateTime start = DateTime.Now; + + DataTable result = managmentDatabase.getAllEntry("Subcategories"); + string listSubcategories = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + listSubcategories += managmentDatabase.getRowTableById(result, "subcategories_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "name", i).ToString() + "\n"; + } + labelListSubcategories.Text = listSubcategories; + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Добавлено! Время выполнения: {duration.TotalMilliseconds} мс"); + } + } +} diff --git a/BulletinBoard/BulletinBoard/SubcategoriesForm/ListSubcategoriesForm.resx b/BulletinBoard/BulletinBoard/SubcategoriesForm/ListSubcategoriesForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BulletinBoard/BulletinBoard/SubcategoriesForm/ListSubcategoriesForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/SubcategoriesForm/UpdateSubcategoriesForm.Designer.cs b/BulletinBoard/BulletinBoard/SubcategoriesForm/UpdateSubcategoriesForm.Designer.cs new file mode 100644 index 0000000..67ea25d --- /dev/null +++ b/BulletinBoard/BulletinBoard/SubcategoriesForm/UpdateSubcategoriesForm.Designer.cs @@ -0,0 +1,111 @@ +namespace WebsiteForPlacingAds +{ + partial class UpdateSubcategoriesForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.buttonUpdateSubcategory = new System.Windows.Forms.Button(); + this.comboBoxUpdateSubcategory = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(80, 104); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(239, 23); + this.textBoxName.TabIndex = 42; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(80, 86); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(59, 15); + this.labelName.TabIndex = 41; + this.labelName.Text = "Название"; + // + // buttonUpdateSubcategory + // + this.buttonUpdateSubcategory.Location = new System.Drawing.Point(80, 148); + this.buttonUpdateSubcategory.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdateSubcategory.Name = "buttonUpdateSubcategory"; + this.buttonUpdateSubcategory.Size = new System.Drawing.Size(239, 29); + this.buttonUpdateSubcategory.TabIndex = 40; + this.buttonUpdateSubcategory.Text = "Обновить категорию"; + this.buttonUpdateSubcategory.UseVisualStyleBackColor = true; + this.buttonUpdateSubcategory.Click += new System.EventHandler(this.buttonUpdateSubcategory_Click); + // + // comboBoxUpdateSubcategory + // + this.comboBoxUpdateSubcategory.FormattingEnabled = true; + this.comboBoxUpdateSubcategory.Location = new System.Drawing.Point(12, 47); + this.comboBoxUpdateSubcategory.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxUpdateSubcategory.Name = "comboBoxUpdateSubcategory"; + this.comboBoxUpdateSubcategory.Size = new System.Drawing.Size(377, 23); + this.comboBoxUpdateSubcategory.TabIndex = 39; + this.comboBoxUpdateSubcategory.SelectedIndexChanged += new System.EventHandler(this.comboBoxUpdateSubcategory_SelectedIndexChanged_1); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(53, 23); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(291, 15); + this.label1.TabIndex = 38; + this.label1.Text = "Выберите подкатегорию, которую хотите обновить"; + // + // UpdateSubcategoriesForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(397, 195); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonUpdateSubcategory); + this.Controls.Add(this.comboBoxUpdateSubcategory); + this.Controls.Add(this.label1); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "UpdateSubcategoriesForm"; + this.Text = "Обновить подкатегорию"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxName; + private Label labelName; + private Button buttonUpdateSubcategory; + private ComboBox comboBoxUpdateSubcategory; + private Label label1; + } +} \ No newline at end of file diff --git a/BulletinBoard/BulletinBoard/SubcategoriesForm/UpdateSubcategoriesForm.cs b/BulletinBoard/BulletinBoard/SubcategoriesForm/UpdateSubcategoriesForm.cs new file mode 100644 index 0000000..68b26b5 --- /dev/null +++ b/BulletinBoard/BulletinBoard/SubcategoriesForm/UpdateSubcategoriesForm.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WebsiteForPlacingAds +{ + public partial class UpdateSubcategoriesForm : Form + { + AbstractManagmentDatabase managmentDatabase; + public UpdateSubcategoriesForm(AbstractManagmentDatabase managmentDatabase) + { + InitializeComponent(); + this.managmentDatabase = managmentDatabase; + LoadData(); + } + public void LoadData() + { + comboBoxUpdateSubcategory.Items.Clear(); + DataTable result = managmentDatabase.getAllEntry("Subcategories"); + string Subcategories = ""; + for (int i = 0; i < result.Rows.Count; i++) + { + Subcategories = result.Rows[i]["subcategories_id"].ToString() + " | " + + (string)result.Rows[i]["name"] + "\n"; + comboBoxUpdateSubcategory.Items.Add(Subcategories); + } + } + public void LoadDataSelectedItem(int subcategories_id) + { + DataTable result = managmentDatabase.getEntryById("subcategories", subcategories_id); + textBoxName.Text = managmentDatabase.getRowTableById(result, "name", 0).ToString(); + } + + + + private void buttonUpdateSubcategory_Click(object sender, EventArgs e) + { + string[] selectedSubcategory = comboBoxUpdateSubcategory.SelectedItem.ToString().Split("|"); + int subcategory_id = int.Parse(selectedSubcategory[0].Trim()); + + string query = $"UPDATE Subcategories SET "; + int len = query.Length; + + + string oldName = managmentDatabase.getRowTableById("subcategories", "name", subcategory_id).ToString(); + + string newName = textBoxName.Text; + + + query = oldName == newName ? query : query + $"name = '{newName}', "; + if (len != query.Length) + { + query = query.TrimEnd(' '); + query = query.TrimEnd(','); + query += $" WHERE Subcategories_ID = {subcategory_id};"; + } + try + { + DateTime start = DateTime.Now; + + managmentDatabase.ExecuteNonQuery(query); + MessageBox.Show("Данные успешно обновлены!"); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Добавлено! Время выполнения: {duration.TotalMilliseconds} мс"); + } + catch (Exception) + { + + MessageBox.Show("Данные не обновились"); + } + } + + private void comboBoxUpdateSubcategory_SelectedIndexChanged_1(object sender, EventArgs e) + { + string[] selectedItems = comboBoxUpdateSubcategory.SelectedItem.ToString().Split("|"); + int subcategory_id = int.Parse(selectedItems[0].Trim()); + LoadDataSelectedItem(subcategory_id); + } + } +} diff --git a/BulletinBoard/BulletinBoard/SubcategoriesForm/UpdateSubcategoriesForm.resx b/BulletinBoard/BulletinBoard/SubcategoriesForm/UpdateSubcategoriesForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BulletinBoard/BulletinBoard/SubcategoriesForm/UpdateSubcategoriesForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file