diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/AbstractManagmentDatabase.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/AbstractManagmentDatabase.cs new file mode 100644 index 0000000..a1f41a5 --- /dev/null +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/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/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/CreateAdsForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/CreateAdsForm.cs index 6c3f1b0..73e971e 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/CreateAdsForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/CreateAdsForm.cs @@ -4,11 +4,11 @@ namespace WebsiteForPlacingAds { public partial class CreateAdsForm : Form { - IDatabaseLogic databaseLogic; - public CreateAdsForm(IDatabaseLogic databaseLogic) + AbstractManagmentDatabase managmentDatabase; + public CreateAdsForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; LoadData(); } @@ -28,7 +28,7 @@ namespace WebsiteForPlacingAds try { - databaseLogic.insertInto("ads", $"'{heading}'", price, $"'{date}'", $"'{status}'", client_id, category_id, subcategory_id); + managmentDatabase.insertInto("ads", $"'{heading}'", price, $"'{date}'", $"'{status}'", client_id, category_id, subcategory_id); MessageBox.Show("!"); LoadData(); } @@ -43,25 +43,25 @@ namespace WebsiteForPlacingAds comboBoxCategory.Items.Clear(); comboBoxSubcategory.Items.Clear(); comboBoxClient.Items.Clear(); - DataTable result = databaseLogic.getAllEntry("CATEGORIES"); + 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] = databaseLogic.getRowTableById(result, "categories_id", i).ToString() + ". " + databaseLogic.getRowTableById(result, "name", i).ToString(); + id_names[i] = managmentDatabase.getRowTableById(result, "categories_id", i).ToString() + ". " + managmentDatabase.getRowTableById(result, "name", i).ToString(); comboBoxCategory.Items.Add(id_names[i]); } - result = databaseLogic.getAllEntry("SUBCATEGORIES"); + result = managmentDatabase.getAllEntry("SUBCATEGORIES"); id_names = new string[result.Rows.Count]; for (int i = 0; i < result.Rows.Count; i++) { - id_names[i] = databaseLogic.getRowTableById(result, "subcategories_id", i).ToString() + ". " + databaseLogic.getRowTableById(result, "name", i).ToString(); + id_names[i] = managmentDatabase.getRowTableById(result, "subcategories_id", i).ToString() + ". " + managmentDatabase.getRowTableById(result, "name", i).ToString(); comboBoxSubcategory.Items.Add(id_names[i]); } - result = databaseLogic.getAllEntry("CLIENTS"); + 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] = databaseLogic.getRowTableById(result, "clients_id", i).ToString().Trim() + ". " + databaseLogic.getRowTableById(result, "name", i).ToString().Trim() + " " + databaseLogic.getRowTableById(result, "surname", i).ToString().Trim(); + 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]); } } diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/DeleteAdsForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/DeleteAdsForm.cs index d9f349d..5942355 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/DeleteAdsForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/DeleteAdsForm.cs @@ -12,12 +12,12 @@ namespace WebsiteForPlacingAds { public partial class DeleteAdsForm : Form { - IDatabaseLogic databaseLogic; + AbstractManagmentDatabase managmentDatabase; private int setval_seq; - public DeleteAdsForm(IDatabaseLogic databaseLogic) + public DeleteAdsForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; LoadData(); } @@ -29,8 +29,8 @@ namespace WebsiteForPlacingAds string query_seq_reduction = $"SELECT setval('seq_ads', {setval_seq - 1});"; try { - databaseLogic.deleteEntry("ads", int.Parse(ad_id)); - databaseLogic.reduceSeq("seq_ads", setval_seq); + managmentDatabase.deleteEntry("ads", int.Parse(ad_id)); + if (setval_seq > 0) managmentDatabase.reduceSeq("seq_ads", setval_seq); MessageBox.Show("Удалено!"); LoadData(); } @@ -42,20 +42,20 @@ namespace WebsiteForPlacingAds public void LoadData() { comboBoxDeleteAds.Items.Clear(); - DataTable result = databaseLogic.getAllEntry("ADS"); + DataTable result = managmentDatabase.getAllEntry("ADS"); setval_seq = result.Rows.Count; string Ads = ""; for (int i = 0; i < result.Rows.Count; i++) { - if (i == result.Rows.Count - 1) setval_seq = Convert.ToInt32(databaseLogic.getRowTableById(result, "ads_id", i)); - Ads = databaseLogic.getRowTableById(result, "ads_id", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "heading", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "price", i).ToString() + " | " + - ((DateTime)databaseLogic.getRowTableById(result, "date_of_placement", i)).ToString("dd.MM.yyy") + " | " + - databaseLogic.getRowTableById(result, "status", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "id_client", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "id_category", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "id_subcategory", i).ToString() + "\n"; + 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, "id_client", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "id_category", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "id_subcategory", i).ToString() + "\n"; comboBoxDeleteAds.Items.Add(Ads); } } diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/ListAdsForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/ListAdsForm.cs index 76e0ea3..467f0a5 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/ListAdsForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/ListAdsForm.cs @@ -13,28 +13,28 @@ namespace WebsiteForPlacingAds { public partial class ListAdsForm : Form { - IDatabaseLogic databaseLogic; - public ListAdsForm(IDatabaseLogic databaseLogic) + AbstractManagmentDatabase managmentDatabase; + public ListAdsForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; LoadData(); } private void LoadData() { - DataTable result = databaseLogic.getAllEntry("ADS"); + DataTable result = managmentDatabase.getAllEntry("ADS"); string listAds = ""; for (int i = 0; i < result.Rows.Count; i++) { - listAds += databaseLogic.getRowTableById(result, "ads_id", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "heading", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "price", i).ToString() + " | " + - ((DateTime)databaseLogic.getRowTableById(result, "date_of_placement", i)).ToString("dd.MM.yyy") + " | " + - databaseLogic.getRowTableById(result, "status", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "id_client", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "id_category", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "id_subcategory", i).ToString() + "\n"; + 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, "id_client", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "id_category", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "id_subcategory", i).ToString() + "\n"; } labelListAds.Text = listAds; } diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/UpdateAdsForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/UpdateAdsForm.cs index cc1aabf..b295493 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/UpdateAdsForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/AdsForm/UpdateAdsForm.cs @@ -13,11 +13,11 @@ namespace WebsiteForPlacingAds public partial class UpdateAdsForm : Form { //PostgreSqlDatabase psd; - IDatabaseLogic databaseLogic; - public UpdateAdsForm(IDatabaseLogic databaseLogic) + AbstractManagmentDatabase managmentDatabase; + public UpdateAdsForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; LoadData(); } @@ -30,13 +30,13 @@ namespace WebsiteForPlacingAds int len = query.Length; - string oldHeading = databaseLogic.getRowTableById("ads", "heading", ads_id).ToString(); - string oldPrice = databaseLogic.getRowTableById("ads", "heading", ads_id).ToString(); - string oldDate = ((DateTime)databaseLogic.getRowTableById("ads", "date_of_placement", ads_id)).ToString("dd.MM.yyyy"); - string oldStatus = databaseLogic.getRowTableById("ads", "status", ads_id).ToString(); - string[] oldClient = databaseLogic.getRowTableById("ads", "id_client", ads_id).ToString().Split(" "); - string[] oldCategory = databaseLogic.getRowTableById("ads", "id_category", ads_id).ToString().Split(" "); - string[] oldSubcategory = databaseLogic.getRowTableById("ads", "id_subcategory", ads_id).ToString().Split(" "); + 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", "id_client", ads_id).ToString().Split(" "); + string[] oldCategory = managmentDatabase.getRowTableById("ads", "id_category", ads_id).ToString().Split(" "); + string[] oldSubcategory = managmentDatabase.getRowTableById("ads", "id_subcategory", ads_id).ToString().Split(" "); string newHeading = textBoxHeading.Text; string newPrice = textBoxPrice.Text; @@ -63,7 +63,7 @@ namespace WebsiteForPlacingAds } try { - databaseLogic.ExecuteNonQuery(query); + managmentDatabase.ExecuteNonQuery(query); MessageBox.Show("Данные успешно обновлены!"); } catch (Exception) @@ -76,7 +76,7 @@ namespace WebsiteForPlacingAds public void LoadData() { comboBoxUpdateAd.Items.Clear(); - DataTable result = databaseLogic.getAllEntry("Ads"); + DataTable result = managmentDatabase.getAllEntry("Ads"); string Ads = ""; for (int i = 0; i < result.Rows.Count; i++) { @@ -93,21 +93,21 @@ namespace WebsiteForPlacingAds comboBoxCategory.Items.Clear(); comboBoxSubcategory.Items.Clear(); comboBoxClient.Items.Clear(); - result = databaseLogic.getAllEntry("Categories"); + 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 = databaseLogic.getAllEntry("Subcategories"); + 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 = databaseLogic.getAllEntry("Clients"); + result = managmentDatabase.getAllEntry("Clients"); string[] id_names_surnames = new string[result.Rows.Count]; for (int i = 0; i < result.Rows.Count; i++) { @@ -117,19 +117,19 @@ namespace WebsiteForPlacingAds } public void LoadDataSelectedItem(int ads_id) { - DataTable result = databaseLogic.getEntryById("ads", 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]["id_category"].ToString() + ". " + databaseLogic.getRowTableById("categories", "name", Convert.ToInt32(result.Rows[0]["id_category"])).ToString(); + comboBoxCategory.SelectedItem = result.Rows[0]["id_category"].ToString() + ". " + managmentDatabase.getRowTableById("categories", "name", Convert.ToInt32(result.Rows[0]["id_category"])).ToString(); - comboBoxSubcategory.SelectedItem = result.Rows[0]["id_subcategory"].ToString() + ". " + databaseLogic.getRowTableById("subcategories", "name", Convert.ToInt32(result.Rows[0]["id_subcategory"])).ToString(); + comboBoxSubcategory.SelectedItem = result.Rows[0]["id_subcategory"].ToString() + ". " + managmentDatabase.getRowTableById("subcategories", "name", Convert.ToInt32(result.Rows[0]["id_subcategory"])).ToString(); comboBoxClient.SelectedItem = result.Rows[0]["id_client"].ToString().Trim() + ". " + - databaseLogic.getRowTableById("clients", "name", Convert.ToInt32(result.Rows[0]["id_client"])).ToString().Trim() + " " + - databaseLogic.getRowTableById("clients", "surname", Convert.ToInt32(result.Rows[0]["id_client"])).ToString().Trim(); + managmentDatabase.getRowTableById("clients", "name", Convert.ToInt32(result.Rows[0]["id_client"])).ToString().Trim() + " " + + managmentDatabase.getRowTableById("clients", "surname", Convert.ToInt32(result.Rows[0]["id_client"])).ToString().Trim(); } diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/CreateCategoriesForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/CreateCategoriesForm.cs index 45d9b9a..4a8041f 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/CreateCategoriesForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/CreateCategoriesForm.cs @@ -4,11 +4,11 @@ namespace WebsiteForPlacingAds { public partial class CreateCategoriesForm : Form { - IDatabaseLogic databaseLogic; - public CreateCategoriesForm(IDatabaseLogic databaseLogic) + AbstractManagmentDatabase managmentDatabase; + public CreateCategoriesForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; } private void buttonCreateCategory_Click(object sender, EventArgs e) @@ -17,7 +17,7 @@ namespace WebsiteForPlacingAds try { - databaseLogic.insertInto("categories", $"'{name}'"); + managmentDatabase.insertInto("categories", $"'{name}'"); MessageBox.Show("!"); } catch (Exception ex) diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/DeleteCategoriesForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/DeleteCategoriesForm.cs index 0b31b36..e949e71 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/DeleteCategoriesForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/DeleteCategoriesForm.cs @@ -12,12 +12,12 @@ namespace WebsiteForPlacingAds { public partial class DeleteCategoriesForm : Form { - IDatabaseLogic databaseLogic; + AbstractManagmentDatabase managmentDatabase; private int setval_seq; - public DeleteCategoriesForm(IDatabaseLogic databaseLogic) + public DeleteCategoriesForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; LoadData(); } @@ -27,9 +27,9 @@ namespace WebsiteForPlacingAds string category_id = categories[0].Trim(); try { - databaseLogic.deleteEntry("categories", int.Parse(category_id)); + managmentDatabase.deleteEntry("categories", int.Parse(category_id)); LoadData(); - databaseLogic.reduceSeq("seq_categories", setval_seq); + if (setval_seq > 0) managmentDatabase.reduceSeq("seq_categories", setval_seq); MessageBox.Show("Удалено!"); } catch (Exception ex) @@ -40,14 +40,14 @@ namespace WebsiteForPlacingAds public void LoadData() { comboBoxDeleteCategories.Items.Clear(); - DataTable result = databaseLogic.getAllEntry("Categories"); + DataTable result = managmentDatabase.getAllEntry("Categories"); setval_seq = result.Rows.Count; string Categories = ""; for (int i = 0; i < result.Rows.Count; i++) { - if (i == result.Rows.Count - 1) setval_seq = Convert.ToInt32(databaseLogic.getRowTableById(result, "categories_id", i)); - Categories = databaseLogic.getRowTableById(result, "categories_id", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "name", i).ToString() + "\n"; + 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/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/ListCategoriesForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/ListCategoriesForm.cs index 254d088..2a48837 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/ListCategoriesForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/ListCategoriesForm.cs @@ -13,22 +13,22 @@ namespace WebsiteForPlacingAds { public partial class ListCategoriesForm : Form { - IDatabaseLogic databaseLogic; - public ListCategoriesForm(IDatabaseLogic databaseLogic) + AbstractManagmentDatabase managmentDatabase; + public ListCategoriesForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; LoadData(); } private void LoadData() { - DataTable result = databaseLogic.getAllEntry("Categories"); + DataTable result = managmentDatabase.getAllEntry("Categories"); string listCategories = ""; for (int i = 0; i < result.Rows.Count; i++) { - listCategories += databaseLogic.getRowTableById(result, "categories_id", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "name", i).ToString() + "\n"; + listCategories += managmentDatabase.getRowTableById(result, "categories_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "name", i).ToString() + "\n"; } labelListCategories.Text = listCategories; } diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/UpdateCategoriesForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/UpdateCategoriesForm.cs index 0813379..0409131 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/UpdateCategoriesForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/CategoriesForm/UpdateCategoriesForm.cs @@ -12,17 +12,17 @@ namespace WebsiteForPlacingAds { public partial class UpdateCategoriesForm : Form { - IDatabaseLogic databaseLogic; - public UpdateCategoriesForm(IDatabaseLogic databaseLogic) + AbstractManagmentDatabase managmentDatabase; + public UpdateCategoriesForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; LoadData(); } public void LoadData() { comboBoxUpdateCategory.Items.Clear(); - DataTable result = databaseLogic.getAllEntry("Categories"); + DataTable result = managmentDatabase.getAllEntry("Categories"); string Categories = ""; for (int i = 0; i < result.Rows.Count; i++) { @@ -33,8 +33,8 @@ namespace WebsiteForPlacingAds } public void LoadDataSelectedItem(int categories_id) { - DataTable result = databaseLogic.getEntryById("categories", categories_id); - textBoxName.Text = databaseLogic.getRowTableById(result, "name", 0).ToString(); + DataTable result = managmentDatabase.getEntryById("categories", categories_id); + textBoxName.Text = managmentDatabase.getRowTableById(result, "name", 0).ToString(); } private void comboBoxUpdateCategory_SelectedIndexChanged(object sender, EventArgs e) @@ -53,7 +53,7 @@ namespace WebsiteForPlacingAds int len = query.Length; - string oldName = databaseLogic.getRowTableById("categories", "name", category_id).ToString(); + string oldName = managmentDatabase.getRowTableById("categories", "name", category_id).ToString(); string newName = textBoxName.Text; @@ -67,7 +67,7 @@ namespace WebsiteForPlacingAds } try { - databaseLogic.ExecuteNonQuery(query); + managmentDatabase.ExecuteNonQuery(query); MessageBox.Show("Данные успешно обновлены!"); } catch (Exception) diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/CreateClientsForm.Designer.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/CreateClientsForm.Designer.cs index c4aded6..1199232 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/CreateClientsForm.Designer.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/CreateClientsForm.Designer.cs @@ -35,14 +35,12 @@ this.labelSurname = new System.Windows.Forms.Label(); this.textBoxPatronymic = new System.Windows.Forms.TextBox(); this.labelPatronymic = new System.Windows.Forms.Label(); - this.labelRating = 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.textBoxRating = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // buttonCreateClient @@ -107,15 +105,6 @@ this.labelPatronymic.TabIndex = 5; this.labelPatronymic.Text = "Отчество"; // - // labelRating - // - this.labelRating.AutoSize = true; - this.labelRating.Location = new System.Drawing.Point(43, 291); - this.labelRating.Name = "labelRating"; - this.labelRating.Size = new System.Drawing.Size(51, 15); - this.labelRating.TabIndex = 11; - this.labelRating.Text = "Рейтинг"; - // // labelDate // this.labelDate.AutoSize = true; @@ -167,24 +156,14 @@ this.textBoxDate.Size = new System.Drawing.Size(239, 23); this.textBoxDate.TabIndex = 15; // - // textBoxRating - // - this.textBoxRating.Location = new System.Drawing.Point(43, 308); - this.textBoxRating.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.textBoxRating.Name = "textBoxRating"; - this.textBoxRating.Size = new System.Drawing.Size(239, 23); - this.textBoxRating.TabIndex = 16; - // // 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.textBoxRating); this.Controls.Add(this.textBoxDate); this.Controls.Add(this.textBoxPhoneNumber); this.Controls.Add(this.labelPhoneNumber); - this.Controls.Add(this.labelRating); this.Controls.Add(this.labelDate); this.Controls.Add(this.textBoxEmail); this.Controls.Add(this.labelEmail); @@ -212,13 +191,11 @@ private Label labelSurname; private TextBox textBoxPatronymic; private Label labelPatronymic; - private Label labelRating; private Label labelDate; private TextBox textBoxEmail; private Label labelEmail; private Label labelPhoneNumber; private TextBox textBoxPhoneNumber; private TextBox textBoxDate; - private TextBox textBoxRating; } } \ No newline at end of file diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/CreateClientsForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/CreateClientsForm.cs index 31bb9f0..2d61f31 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/CreateClientsForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/CreateClientsForm.cs @@ -5,11 +5,11 @@ namespace WebsiteForPlacingAds public partial class CreateClientsForm : Form { //PostgreSqlDatabase psd; - IDatabaseLogic databaseLogic; - public CreateClientsForm(IDatabaseLogic databaseLogic) + AbstractManagmentDatabase managmentDatabase; + public CreateClientsForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; } private void buttonCreateClient_Click(object sender, EventArgs e) @@ -20,13 +20,17 @@ namespace WebsiteForPlacingAds string email = textBoxEmail.Text; string phoneNumber = textBoxPhoneNumber.Text; string date = textBoxDate.Text; - string rating = textBoxRating.Text; try { - if (patronymic != null) databaseLogic.insertInto("clients", $"'{name}'", $"'{surname}'", $"'{patronymic}'", $"'{email}'", $"{phoneNumber}", $"'{date}'", $"{rating}"); - else databaseLogic.insertInto("clients", $"'{name}'", $"'{surname}'", $"{patronymic}", $"'{email}'", $"{phoneNumber}", $"'{date}'", $"{rating}"); - MessageBox.Show("!"); + 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} "); } catch (Exception ex) { diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/DeleteClientsForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/DeleteClientsForm.cs index d4df5d6..7df3e91 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/DeleteClientsForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/DeleteClientsForm.cs @@ -12,12 +12,12 @@ namespace WebsiteForPlacingAds { public partial class DeleteClientsForm : Form { - IDatabaseLogic databaseLogic; + AbstractManagmentDatabase managmentDatabase; private int setval_seq; - public DeleteClientsForm(IDatabaseLogic databaseLogic) + public DeleteClientsForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; LoadData(); } @@ -29,10 +29,16 @@ namespace WebsiteForPlacingAds //string query_seq_reduction = $"SELECT setval('seq_ads', {setval_seq - 1});"; try { - databaseLogic.deleteEntry("clients", int.Parse(client_id)); + DateTime start = DateTime.Now; + + managmentDatabase.deleteEntry("clients", int.Parse(client_id)); LoadData(); - databaseLogic.reduceSeq("seq_clients", setval_seq); - MessageBox.Show("Удалено!"); + 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) { @@ -42,20 +48,19 @@ namespace WebsiteForPlacingAds public void LoadData() { comboBoxDeleteClients.Items.Clear(); - DataTable result = databaseLogic.getAllEntry("Clients"); + DataTable result = managmentDatabase.getAllEntry("Clients"); setval_seq = result.Rows.Count; string Clients = ""; for (int i = 0; i < result.Rows.Count; i++) { - if (i == result.Rows.Count - 1) setval_seq = Convert.ToInt32(databaseLogic.getRowTableById(result, "clients_id", i)); - Clients = databaseLogic.getRowTableById(result, "clients_id", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "name", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "surname", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "patronymic", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "email", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "phone_number", i).ToString() + " | " + - ((DateTime)databaseLogic.getRowTableById(result, "registration_date", i)).ToString("dd.MM.yyy") + " | " + - databaseLogic.getRowTableById(result, "rating", i).ToString() + "\n"; + 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/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/ListClientsForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/ListClientsForm.cs index 53086d5..ea4b8aa 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/ListClientsForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/ListClientsForm.cs @@ -13,30 +13,36 @@ namespace WebsiteForPlacingAds { public partial class ListClientsForm : Form { - IDatabaseLogic databaseLogic; - public ListClientsForm(IDatabaseLogic databaseLogic) + AbstractManagmentDatabase managmentDatabase; + public ListClientsForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; LoadData(); } private void LoadData() { - DataTable result = databaseLogic.getAllEntry("clients"); + DateTime start = DateTime.Now; + + DataTable result = managmentDatabase.getAllEntry("clients"); string listClients = ""; for (int i = 0; i < result.Rows.Count; i++) { - listClients += databaseLogic.getRowTableById(result, "clients_id", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "name", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "surname", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "patronymic", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "email", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "phone_number", i).ToString() + " | " + - ((DateTime)databaseLogic.getRowTableById(result, "registration_date", i)).ToString("dd.MM.yyy") + " | " + - databaseLogic.getRowTableById(result, "rating", i).ToString() + "\n"; + 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/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/UpdateClientsForm.Designer.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/UpdateClientsForm.Designer.cs index b63508a..8093d9f 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/UpdateClientsForm.Designer.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/UpdateClientsForm.Designer.cs @@ -31,11 +31,9 @@ this.buttonUpdateClient = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.comboBoxUpdateClient = new System.Windows.Forms.ComboBox(); - this.textBoxRating = new System.Windows.Forms.TextBox(); this.textBoxDate = new System.Windows.Forms.TextBox(); this.textBoxPhoneNumber = new System.Windows.Forms.TextBox(); this.labelPhoneNumber = new System.Windows.Forms.Label(); - this.labelRating = 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(); @@ -67,24 +65,16 @@ this.label1.TabIndex = 33; this.label1.Text = "Выберите клиента, которого хотите обновить"; // - // comboBoxUpdateAd + // 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 = "comboBoxUpdateAd"; + 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); // - // textBoxRating - // - this.textBoxRating.Location = new System.Drawing.Point(79, 371); - this.textBoxRating.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.textBoxRating.Name = "textBoxRating"; - this.textBoxRating.Size = new System.Drawing.Size(239, 23); - this.textBoxRating.TabIndex = 48; - // // textBoxDate // this.textBoxDate.Location = new System.Drawing.Point(79, 326); @@ -110,15 +100,6 @@ this.labelPhoneNumber.TabIndex = 45; this.labelPhoneNumber.Text = "Номер телефона"; // - // labelRating - // - this.labelRating.AutoSize = true; - this.labelRating.Location = new System.Drawing.Point(79, 354); - this.labelRating.Name = "labelRating"; - this.labelRating.Size = new System.Drawing.Size(51, 15); - this.labelRating.TabIndex = 44; - this.labelRating.Text = "Рейтинг"; - // // labelDate // this.labelDate.AutoSize = true; @@ -201,11 +182,9 @@ 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.textBoxRating); this.Controls.Add(this.textBoxDate); this.Controls.Add(this.textBoxPhoneNumber); this.Controls.Add(this.labelPhoneNumber); - this.Controls.Add(this.labelRating); this.Controls.Add(this.labelDate); this.Controls.Add(this.textBoxEmail); this.Controls.Add(this.labelEmail); @@ -230,11 +209,9 @@ private Button buttonUpdateClient; private Label label1; private ComboBox comboBoxUpdateClient; - private TextBox textBoxRating; private TextBox textBoxDate; private TextBox textBoxPhoneNumber; private Label labelPhoneNumber; - private Label labelRating; private Label labelDate; private TextBox textBoxEmail; private Label labelEmail; diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/UpdateClientsForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/UpdateClientsForm.cs index 7bffade..a6673c1 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/UpdateClientsForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/ClientsForm/UpdateClientsForm.cs @@ -12,17 +12,17 @@ namespace WebsiteForPlacingAds { public partial class UpdateClientsForm : Form { - IDatabaseLogic databaseLogic; - public UpdateClientsForm(IDatabaseLogic databaseLogic) + AbstractManagmentDatabase managmentDatabase; + public UpdateClientsForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; LoadData(); } public void LoadData() { comboBoxUpdateClient.Items.Clear(); - DataTable result = databaseLogic.getAllEntry("Clients"); + DataTable result = managmentDatabase.getAllEntry("Clients"); string Clients = ""; for (int i = 0; i < result.Rows.Count; i++) { @@ -32,8 +32,7 @@ namespace WebsiteForPlacingAds (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") + " | " + - result.Rows[i]["rating"].ToString() + "\n"; + ((DateTime)result.Rows[i]["registration_date"]).ToString("dd.MM.yyyy") + "\n"; comboBoxUpdateClient.Items.Add(Clients); } } @@ -46,13 +45,12 @@ namespace WebsiteForPlacingAds int len = query.Length; - string oldName = databaseLogic.getRowTableById("clients", "name", clients_id).ToString(); - string oldSurname = databaseLogic.getRowTableById("clients", "surname", clients_id).ToString(); - string oldPatronymic = databaseLogic.getRowTableById("clients", "patronymic", clients_id).ToString(); - string oldEmail = databaseLogic.getRowTableById("clients", "email", clients_id).ToString(); - string oldPhoneNumber = databaseLogic.getRowTableById("clients", "phone_number", clients_id).ToString(); - string oldDate = ((DateTime)databaseLogic.getRowTableById("clients", "registration_date", clients_id)).ToString("dd.MM.yyyy"); - string oldRating = databaseLogic.getRowTableById("clients", "rating", clients_id).ToString(); + 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; @@ -60,7 +58,6 @@ namespace WebsiteForPlacingAds string newEmail = textBoxEmail.Text; string newPhoneNumber = textBoxPhoneNumber.Text; string newDate = textBoxDate.Text; - string newRating = textBoxRating.Text; query = oldName == newName ? query : query + $"name = '{newName}', "; @@ -69,7 +66,6 @@ namespace WebsiteForPlacingAds query = oldEmail == newEmail ? query : query + $"email = '{newEmail}', "; query = oldPhoneNumber == newPhoneNumber ? query : query + $"phone_number = {newPhoneNumber}, "; query = oldDate == newDate ? query : query + $"registration_date = '{newDate}', "; - query = oldRating == newRating ? query : query + $"rating = {newRating}, "; if (len != query.Length) { @@ -79,8 +75,13 @@ namespace WebsiteForPlacingAds } try { - databaseLogic.ExecuteNonQuery(query); - MessageBox.Show("Данные успешно обновлены!"); + DateTime start = DateTime.Now; + + managmentDatabase.ExecuteNonQuery(query); + + DateTime end = DateTime.Now; + TimeSpan duration = end - start; + MessageBox.Show($"Данные успешно обновлены! Время выполнения: {duration.TotalMilliseconds} мс"); } catch (Exception) { @@ -90,14 +91,13 @@ namespace WebsiteForPlacingAds } public void LoadDataSelectedItem(int clients_id) { - DataTable result = databaseLogic.getEntryById("clients", clients_id); - textBoxName.Text = databaseLogic.getRowTableById(result, "name", 0).ToString(); - textBoxSurname.Text = databaseLogic.getRowTableById(result, "surname", 0).ToString(); - textBoxPatronymic.Text = databaseLogic.getRowTableById(result, "patronymic", 0).ToString(); - textBoxEmail.Text = databaseLogic.getRowTableById(result, "email", 0).ToString(); - textBoxPhoneNumber.Text = databaseLogic.getRowTableById(result, "phone_number", 0).ToString(); - textBoxDate.Text = ((DateTime)databaseLogic.getRowTableById(result, "registration_date", 0)).ToString("dd.MM.yyyy"); - textBoxRating.Text = databaseLogic.getRowTableById(result, "rating", 0).ToString(); + 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) diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/DatabaseLogic.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/DatabaseLogic.cs deleted file mode 100644 index f48af26..0000000 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/DatabaseLogic.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WebsiteForPlacingAds -{ - public class DatabaseLogic : IDatabaseLogic - { - private IDatabase database; - - public DatabaseLogic(IDatabase database) - { - this.database = database; - } - public Object getRowTableById(string tableName, string columnName, int id) - { - return database.ExecuteQuery($"SELECT {columnName} FROM {tableName} WHERE {tableName}_id = {id}").Rows[0][$"{columnName}"]; - } - public Object getRowTableById(DataTable table, string columnName, int i) - { - return table.Rows[i][columnName]; - } - public DataTable getEntryById(string tableName, int id) - { - return database.ExecuteQuery($"SELECT * FROM {tableName} WHERE {tableName}_id = {id}"); - } - public void ExecuteNonQuery(string query) - { - database.ExecuteNonQuery(query); - } - public DataTable ExecuteQuery(string query) - { - return database.ExecuteQuery(query); - } - public DataTable getAllEntry(string tableName) - { - return database.ExecuteQuery($"SELECT * FROM {tableName}"); - } - public void insertInto(string tableName, params string[] values) - { - string query = $"INSERT INTO {tableName} VALUES (nextval('seq_{tableName.ToLower()}'), "; - for (int i = 0; i < values.Length; i++) - { - if (i < values.Length - 1) query += $"{values[i]}, "; - else query += $"{values[i]})"; - } - database.ExecuteNonQuery(query); - } - public void deleteEntry(string tableName, int id) - { - database.ExecuteNonQuery($"DELETE FROM {tableName} WHERE {tableName}_id = {id}"); - } - public void reduceSeq(string seq, int currval) - { - database.ExecuteNonQuery($"SELECT setval('{seq}', {currval});"); - } - } -} diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/IDatabase.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/IDatabase.cs deleted file mode 100644 index c51b57d..0000000 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/IDatabase.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Npgsql; -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WebsiteForPlacingAds -{ - public interface IDatabase - { - - public DataTable ExecuteQuery(string query); - - public void ExecuteNonQuery(string query); - } -} diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/IDatabaseLogic.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/IDatabaseLogic.cs deleted file mode 100644 index ca300a2..0000000 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/IDatabaseLogic.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WebsiteForPlacingAds -{ - public interface IDatabaseLogic - { - public DataTable getEntryById(string tableName, int id); - public Object getRowTableById(string tableName, string columnName, int id); - public Object getRowTableById(DataTable table, string columnName, int i); - public DataTable ExecuteQuery(string query); - public void ExecuteNonQuery(string query); - DataTable getAllEntry(string tableName); - public void insertInto(string tableName, params string[] values); - public void deleteEntry(string tableName, int id); - public void reduceSeq(string seq, int currval); - } -} diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/MainForm.Designer.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/MainForm.Designer.cs index f7946d6..7ee640f 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/MainForm.Designer.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/MainForm.Designer.cs @@ -49,7 +49,19 @@ this.удалитьПодкатегориюToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изменитьПодкатегориюToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокПодкатегоийToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.label1 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.panel1 = new System.Windows.Forms.Panel(); + this.panel2 = new System.Windows.Forms.Panel(); + this.button2 = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.panel3 = new System.Windows.Forms.Panel(); + this.button3 = new System.Windows.Forms.Button(); + this.label3 = new System.Windows.Forms.Label(); this.menuStrip1.SuspendLayout(); + this.panel1.SuspendLayout(); + this.panel2.SuspendLayout(); + this.panel3.SuspendLayout(); this.SuspendLayout(); // // menuStrip1 @@ -223,11 +235,97 @@ this.списокПодкатегоийToolStripMenuItem.Text = "Список подкатегорий"; this.списокПодкатегоийToolStripMenuItem.Click += new System.EventHandler(this.списокПодкатегоийToolStripMenuItem_Click); // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(3, 11); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(225, 15); + this.label1.TabIndex = 1; + this.label1.Text = "Сценарий 1: Добавление 1000 клиентов"; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(63, 66); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(95, 33); + this.button1.TabIndex = 2; + this.button1.Text = "Старт"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // panel1 + // + this.panel1.Controls.Add(this.button1); + this.panel1.Controls.Add(this.label1); + this.panel1.Location = new System.Drawing.Point(12, 83); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(222, 102); + this.panel1.TabIndex = 3; + // + // panel2 + // + this.panel2.Controls.Add(this.button2); + this.panel2.Controls.Add(this.label2); + this.panel2.Location = new System.Drawing.Point(240, 83); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(222, 102); + this.panel2.TabIndex = 4; + // + // button2 + // + this.button2.Location = new System.Drawing.Point(63, 66); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(95, 33); + this.button2.TabIndex = 2; + this.button2.Text = "Старт"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(3, 11); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(210, 15); + this.label2.TabIndex = 1; + this.label2.Text = "Сценарий 2: Удаление 1000 клиентов"; + // + // panel3 + // + this.panel3.Controls.Add(this.button3); + this.panel3.Controls.Add(this.label3); + this.panel3.Location = new System.Drawing.Point(468, 83); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(222, 102); + this.panel3.TabIndex = 5; + // + // button3 + // + this.button3.Location = new System.Drawing.Point(63, 66); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(95, 33); + this.button3.TabIndex = 2; + this.button3.Text = "Старт"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // label3 + // + this.label3.Location = new System.Drawing.Point(7, 11); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(213, 44); + this.label3.TabIndex = 1; + this.label3.Text = "Сценарий 3: Изменение фамилий 1000 клиентов на \"surname2\""; + // // MainForm // 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.panel3); + this.Controls.Add(this.panel2); + this.Controls.Add(this.panel1); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); @@ -235,6 +333,11 @@ this.Text = "MainForm"; this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + this.panel2.ResumeLayout(false); + this.panel2.PerformLayout(); + this.panel3.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -263,5 +366,14 @@ 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; } } \ No newline at end of file diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/MainForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/MainForm.cs index 4a263c8..8fe9aaa 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/MainForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/MainForm.cs @@ -12,109 +12,146 @@ namespace WebsiteForPlacingAds { public partial class MainForm : Form { - IDatabase psd; - IDatabaseLogic databaseLogic; + AbstractManagmentDatabase managmentDatabase; + public MainForm() { InitializeComponent(); - psd = new PostgreSqlDatabase("Server=localhost;Port=5432;User Id=postgres;Password=12345678;Database=AlinaDatabase1;"); - databaseLogic = new DatabaseLogic(psd); + managmentDatabase = new ManagmentDatabase("Server=localhost;Port=5432;User Id=postgres;Password=aswdqq;Database=alinadb;"); } private void создатьКатегориюToolStripMenuItem_Click(object sender, EventArgs e) { - CreateCategoriesForm ccf = new CreateCategoriesForm(databaseLogic); + CreateCategoriesForm ccf = new CreateCategoriesForm(managmentDatabase); ccf.Show(); } private void удалитьКатегориюToolStripMenuItem_Click(object sender, EventArgs e) { - DeleteCategoriesForm dcf = new DeleteCategoriesForm(databaseLogic); + DeleteCategoriesForm dcf = new DeleteCategoriesForm(managmentDatabase); dcf.Show(); } private void создатьОбъявлениеToolStripMenuItem_Click(object sender, EventArgs e) { - CreateAdsForm caf = new CreateAdsForm(databaseLogic); + CreateAdsForm caf = new CreateAdsForm(managmentDatabase); caf.Show(); } private void удалитьОбъявлениеToolStripMenuItem_Click(object sender, EventArgs e) { - DeleteAdsForm uaf = new DeleteAdsForm(databaseLogic); + DeleteAdsForm uaf = new DeleteAdsForm(managmentDatabase); uaf.Show(); } private void изменитьОбъявлениеэToolStripMenuItem_Click(object sender, EventArgs e) { - UpdateAdsForm daf = new UpdateAdsForm(databaseLogic); + UpdateAdsForm daf = new UpdateAdsForm(managmentDatabase); daf.Show(); } private void списокОбъявленийToolStripMenuItem_Click(object sender, EventArgs e) { - ListAdsForm laf = new ListAdsForm(databaseLogic); + ListAdsForm laf = new ListAdsForm(managmentDatabase); laf.Show(); } private void создатьКлиентаToolStripMenuItem_Click(object sender, EventArgs e) { - CreateClientsForm ccf = new CreateClientsForm(databaseLogic); + CreateClientsForm ccf = new CreateClientsForm(managmentDatabase); ccf.Show(); } private void удалитьКлиентаToolStripMenuItem_Click(object sender, EventArgs e) { - DeleteClientsForm dcf = new DeleteClientsForm(databaseLogic); + DeleteClientsForm dcf = new DeleteClientsForm(managmentDatabase); dcf.Show(); } private void изменитьДанныеКлиентаToolStripMenuItem_Click(object sender, EventArgs e) { - UpdateClientsForm ucf = new UpdateClientsForm(databaseLogic); + UpdateClientsForm ucf = new UpdateClientsForm(managmentDatabase); ucf.Show(); } private void списокКлиентвToolStripMenuItem_Click(object sender, EventArgs e) { - ListClientsForm lcf = new ListClientsForm(databaseLogic); + ListClientsForm lcf = new ListClientsForm(managmentDatabase); lcf.Show(); } private void изменитьКатегориюToolStripMenuItem_Click(object sender, EventArgs e) { - UpdateCategoriesForm ucf = new UpdateCategoriesForm(databaseLogic); + UpdateCategoriesForm ucf = new UpdateCategoriesForm(managmentDatabase); ucf.Show(); } private void списокКатегорийToolStripMenuItem_Click(object sender, EventArgs e) { - ListCategoriesForm lcf = new ListCategoriesForm(databaseLogic); + ListCategoriesForm lcf = new ListCategoriesForm(managmentDatabase); lcf.Show(); } private void создатьПодкатеориюToolStripMenuItem_Click(object sender, EventArgs e) { - CreateSubcategoriesForm csf = new CreateSubcategoriesForm(databaseLogic); + CreateSubcategoriesForm csf = new CreateSubcategoriesForm(managmentDatabase); csf.Show(); } private void удалитьПодкатегориюToolStripMenuItem_Click(object sender, EventArgs e) { - DeleteSubcategoriesForm dsf = new DeleteSubcategoriesForm(databaseLogic); + DeleteSubcategoriesForm dsf = new DeleteSubcategoriesForm(managmentDatabase); dsf.Show(); } private void изменитьПодкатегориюToolStripMenuItem_Click(object sender, EventArgs e) { - UpdateSubcategoriesForm usf = new UpdateSubcategoriesForm(databaseLogic); + UpdateSubcategoriesForm usf = new UpdateSubcategoriesForm(managmentDatabase); usf.Show(); } private void списокПодкатегоийToolStripMenuItem_Click(object sender, EventArgs e) { - ListSubcategoriesForm lsf = new ListSubcategoriesForm(databaseLogic); + 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/WebsiteForPlacingAds/WebsiteForPlacingAds/ManagmentDatabase.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/ManagmentDatabase.cs new file mode 100644 index 0000000..2809584 --- /dev/null +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/ManagmentDatabase.cs @@ -0,0 +1,74 @@ +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()}'), "; + 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/WebsiteForPlacingAds/WebsiteForPlacingAds/PostgreSqlDatabase.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/PostgreSqlDatabase.cs deleted file mode 100644 index 5f5cbf6..0000000 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/PostgreSqlDatabase.cs +++ /dev/null @@ -1,105 +0,0 @@ -using Npgsql; -using System; -using System.Collections.Generic; -using System.Data; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static System.Windows.Forms.VisualStyles.VisualStyleElement; - -namespace WebsiteForPlacingAds -{ - public class PostgreSqlDatabase : IDatabase - { - protected NpgsqlConnection connection; - public PostgreSqlDatabase(string connectionString) - { - connection = new NpgsqlConnection(connectionString); - } - - public 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; - } - - public void ExecuteNonQuery(string query) - { - connection.Open(); - NpgsqlCommand command = new NpgsqlCommand(query, connection); - command.ExecuteNonQuery(); - connection.Close(); - } - - public void addAd(string heading, int price, string date, string status, int id_client, int id_category, int id_subcategory) - { - string query = String.Format("INSERT INTO ads VALUES (nextval('seq_ads'), '{0}', {1}, '{2}', '{3}', {4}, {5}, {6})", heading, price, date, status, id_client, id_category, id_subcategory); - ExecuteNonQuery(query); - } - public void addClient(string name, string surname, string patronymic, string email, string phone_number, string registration_date, int client_rating) - { - string query = String.Format($"INSERT INTO clients VALUES (nextval('seq_clients'), {name}', '{surname}', '{patronymic}', '{email}', '{phone_number}', '{registration_date}', '{client_rating}')"); - ExecuteNonQuery(query); - } - public void addClientsRating(int number_of_reviews, int number_of_sales, int number_of_subscribers, float average_rating) - { - string query = String.Format($"INSERT INTO clients_rating VALUES (nextval('seq_user_rating'), {number_of_reviews}', '{number_of_sales}', '{number_of_subscribers}', '{average_rating}')"); - ExecuteNonQuery(query); - } - public void addSubcategory(string name) - { - string query = String.Format($"INSERT INTO subcategories VALUES (nextval('seq_subcategory'), {name}')"); - ExecuteNonQuery(query); - } - public void addCategory(string name) - { - string query = String.Format($"INSERT INTO categories VALUES (nextval('seq_category'), {name}')"); - ExecuteNonQuery(query); - } - public DataTable getAllCategories() - { - string query = "SELECT category_id, name FROM categories"; - return ExecuteQuery(query); - } - public DataTable getAllSubcategories() - { - string query = "SELECT subcategory_id, name FROM subcategories"; - return ExecuteQuery(query); - } - public DataTable getAllClients() - { - string query = "SELECT client_id, name, surname FROM clients"; - return ExecuteQuery(query); - } - public DataTable getClient(int id_client) - { - string query = $"SELECT * FROM clients where id = {id_client}"; - return ExecuteQuery(query); - } - - public DataTable getFullList() - { - throw new NotImplementedException(); - } - public void Create(string query) - { - ExecuteNonQuery(query); - } - - public void Update() - { - throw new NotImplementedException(); - } - - public void Delete() - { - throw new NotImplementedException(); - } - } -} diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/CreateSubcategoriesForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/CreateSubcategoriesForm.cs index cac9997..8859540 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/CreateSubcategoriesForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/CreateSubcategoriesForm.cs @@ -4,11 +4,11 @@ namespace WebsiteForPlacingAds { public partial class CreateSubcategoriesForm : Form { - IDatabaseLogic databaseLogic; - public CreateSubcategoriesForm(IDatabaseLogic databaseLogic) + AbstractManagmentDatabase managmentDatabase; + public CreateSubcategoriesForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; } private void buttonCreateSubcategory_Click_1(object sender, EventArgs e) @@ -17,7 +17,7 @@ namespace WebsiteForPlacingAds try { - databaseLogic.insertInto("subcategories", $"'{name}'"); + managmentDatabase.insertInto("subcategories", $"'{name}'"); MessageBox.Show("!"); } catch (Exception ex) diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/DeleteSubcategoriesForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/DeleteSubcategoriesForm.cs index f2d6cc2..f240ae7 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/DeleteSubcategoriesForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/DeleteSubcategoriesForm.cs @@ -12,25 +12,25 @@ namespace WebsiteForPlacingAds { public partial class DeleteSubcategoriesForm : Form { - IDatabaseLogic databaseLogic; + AbstractManagmentDatabase managmentDatabase; private int setval_seq; - public DeleteSubcategoriesForm(IDatabaseLogic databaseLogic) + public DeleteSubcategoriesForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; LoadData(); } public void LoadData() { comboBoxDeleteSubcategories.Items.Clear(); - DataTable result = databaseLogic.getAllEntry("Subcategories"); + DataTable result = managmentDatabase.getAllEntry("Subcategories"); setval_seq = result.Rows.Count; string Subcategories = ""; for (int i = 0; i < result.Rows.Count; i++) { - if (i == result.Rows.Count - 1) setval_seq = Convert.ToInt32(databaseLogic.getRowTableById(result, "subcategories_id", i)); - Subcategories = databaseLogic.getRowTableById(result, "subcategories_id", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "name", i).ToString() + "\n"; + 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); } } @@ -41,9 +41,9 @@ namespace WebsiteForPlacingAds string subcategory_id = subcategories[0].Trim(); try { - databaseLogic.deleteEntry("subcategories", int.Parse(subcategory_id)); + managmentDatabase.deleteEntry("subcategories", int.Parse(subcategory_id)); LoadData(); - databaseLogic.reduceSeq("seq_subcategories", setval_seq); + if (setval_seq > 0) managmentDatabase.reduceSeq("seq_subcategories", setval_seq); MessageBox.Show("Удалено!"); } catch (Exception ex) diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/ListSubcategoriesForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/ListSubcategoriesForm.cs index 17df9a0..7cacc80 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/ListSubcategoriesForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/ListSubcategoriesForm.cs @@ -13,22 +13,22 @@ namespace WebsiteForPlacingAds { public partial class ListSubcategoriesForm : Form { - IDatabaseLogic databaseLogic; - public ListSubcategoriesForm(IDatabaseLogic databaseLogic) + AbstractManagmentDatabase managmentDatabase; + public ListSubcategoriesForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; LoadData(); } private void LoadData() { - DataTable result = databaseLogic.getAllEntry("Subcategories"); + DataTable result = managmentDatabase.getAllEntry("Subcategories"); string listSubcategories = ""; for (int i = 0; i < result.Rows.Count; i++) { - listSubcategories += databaseLogic.getRowTableById(result, "subcategories_id", i).ToString() + " | " + - databaseLogic.getRowTableById(result, "name", i).ToString() + "\n"; + listSubcategories += managmentDatabase.getRowTableById(result, "subcategories_id", i).ToString() + " | " + + managmentDatabase.getRowTableById(result, "name", i).ToString() + "\n"; } labelListSubcategories.Text = listSubcategories; } diff --git a/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/UpdateSubcategoriesForm.cs b/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/UpdateSubcategoriesForm.cs index 4c41d0f..aaaf4d2 100644 --- a/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/UpdateSubcategoriesForm.cs +++ b/WebsiteForPlacingAds/WebsiteForPlacingAds/SubcategoriesForm/UpdateSubcategoriesForm.cs @@ -12,17 +12,17 @@ namespace WebsiteForPlacingAds { public partial class UpdateSubcategoriesForm : Form { - IDatabaseLogic databaseLogic; - public UpdateSubcategoriesForm(IDatabaseLogic databaseLogic) + AbstractManagmentDatabase managmentDatabase; + public UpdateSubcategoriesForm(AbstractManagmentDatabase managmentDatabase) { InitializeComponent(); - this.databaseLogic = databaseLogic; + this.managmentDatabase = managmentDatabase; LoadData(); } public void LoadData() { comboBoxUpdateSubcategory.Items.Clear(); - DataTable result = databaseLogic.getAllEntry("Subcategories"); + DataTable result = managmentDatabase.getAllEntry("Subcategories"); string Subcategories = ""; for (int i = 0; i < result.Rows.Count; i++) { @@ -33,8 +33,8 @@ namespace WebsiteForPlacingAds } public void LoadDataSelectedItem(int subcategories_id) { - DataTable result = databaseLogic.getEntryById("subcategories", subcategories_id); - textBoxName.Text = databaseLogic.getRowTableById(result, "name", 0).ToString(); + DataTable result = managmentDatabase.getEntryById("subcategories", subcategories_id); + textBoxName.Text = managmentDatabase.getRowTableById(result, "name", 0).ToString(); } @@ -48,7 +48,7 @@ namespace WebsiteForPlacingAds int len = query.Length; - string oldName = databaseLogic.getRowTableById("subcategories", "name", subcategory_id).ToString(); + string oldName = managmentDatabase.getRowTableById("subcategories", "name", subcategory_id).ToString(); string newName = textBoxName.Text; @@ -62,7 +62,7 @@ namespace WebsiteForPlacingAds } try { - databaseLogic.ExecuteNonQuery(query); + managmentDatabase.ExecuteNonQuery(query); MessageBox.Show("Данные успешно обновлены!"); } catch (Exception)