From ed5ef49236a65e5b2f7495d2918614dfbae35aa1 Mon Sep 17 00:00:00 2001 From: MisterMLiL Date: Tue, 8 Oct 2024 15:14:10 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B5=D0=BA=D1=81=D1=82?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=BC=D0=B5=D0=BD=D1=8E=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tem.Designer.cs => CarControl.Designer.cs} | 2 +- Controls/{CarItem.cs => CarControl.cs} | 5 +- Controls/{CarItem.resx => CarControl.resx} | 0 Controls/CarItemMenuStrip.cs | 4 +- Controls/ParameterControl.cs | 6 + Controls/ParameterItemMenuStrip.Designer.cs | 74 +++++++++++ Controls/ParameterItemMenuStrip.cs | 35 +++++ Controls/ParameterItemMenuStrip.resx | 123 ++++++++++++++++++ Controls/ParameterPanelMenuStrip.Designer.cs | 65 +++++++++ Controls/ParameterPanelMenuStrip.cs | 27 ++++ Controls/ParameterPanelMenuStrip.resx | 123 ++++++++++++++++++ GtaVUsersInfo.csproj | 28 +++- Helpers/ErrorsShow.cs | 5 + MainForm.cs | 62 +++++++-- 14 files changed, 540 insertions(+), 19 deletions(-) rename Controls/{CarItem.Designer.cs => CarControl.Designer.cs} (99%) rename Controls/{CarItem.cs => CarControl.cs} (97%) rename Controls/{CarItem.resx => CarControl.resx} (100%) create mode 100644 Controls/ParameterItemMenuStrip.Designer.cs create mode 100644 Controls/ParameterItemMenuStrip.cs create mode 100644 Controls/ParameterItemMenuStrip.resx create mode 100644 Controls/ParameterPanelMenuStrip.Designer.cs create mode 100644 Controls/ParameterPanelMenuStrip.cs create mode 100644 Controls/ParameterPanelMenuStrip.resx diff --git a/Controls/CarItem.Designer.cs b/Controls/CarControl.Designer.cs similarity index 99% rename from Controls/CarItem.Designer.cs rename to Controls/CarControl.Designer.cs index 3ee2289..7eb43ce 100644 --- a/Controls/CarItem.Designer.cs +++ b/Controls/CarControl.Designer.cs @@ -1,6 +1,6 @@ namespace GtaVUsersInfo.Controls { - partial class CarItem + partial class CarControl { /// /// Обязательная переменная конструктора. diff --git a/Controls/CarItem.cs b/Controls/CarControl.cs similarity index 97% rename from Controls/CarItem.cs rename to Controls/CarControl.cs index 07add4f..5f3295e 100644 --- a/Controls/CarItem.cs +++ b/Controls/CarControl.cs @@ -8,7 +8,7 @@ using GtaVUsersInfo.Helpers; namespace GtaVUsersInfo.Controls { - public partial class CarItem : UserControl + public partial class CarControl : UserControl { private static readonly HttpClient httpClient = new HttpClient(); private Car car; @@ -24,8 +24,7 @@ namespace GtaVUsersInfo.Controls set { ContextMenuStrip = value; } } - - public CarItem(Car carItem) + public CarControl(Car carItem) { InitializeComponent(); diff --git a/Controls/CarItem.resx b/Controls/CarControl.resx similarity index 100% rename from Controls/CarItem.resx rename to Controls/CarControl.resx diff --git a/Controls/CarItemMenuStrip.cs b/Controls/CarItemMenuStrip.cs index 585423a..395f94e 100644 --- a/Controls/CarItemMenuStrip.cs +++ b/Controls/CarItemMenuStrip.cs @@ -17,9 +17,9 @@ namespace GtaVUsersInfo.Controls get { return myMenuStrip; } } - public CarItem Car; + public CarControl Car; - public CarItemMenuStrip(EventHandler add, EventHandler edit, EventHandler delete, CarItem car) + public CarItemMenuStrip(EventHandler add, EventHandler edit, EventHandler delete, CarControl car) { InitializeComponent(); diff --git a/Controls/ParameterControl.cs b/Controls/ParameterControl.cs index 6f57ebf..b5f2f8c 100644 --- a/Controls/ParameterControl.cs +++ b/Controls/ParameterControl.cs @@ -24,6 +24,12 @@ namespace GtaVUsersInfo.Controls set { Textbox.Text = value.ToString(); } } + public ContextMenuStrip MenuStrip + { + get { return ContextMenuStrip; } + set { ContextMenuStrip = value; } + } + public ParameterControl(string name, string text = "") { InitializeComponent(); diff --git a/Controls/ParameterItemMenuStrip.Designer.cs b/Controls/ParameterItemMenuStrip.Designer.cs new file mode 100644 index 0000000..342ae7a --- /dev/null +++ b/Controls/ParameterItemMenuStrip.Designer.cs @@ -0,0 +1,74 @@ +namespace GtaVUsersInfo.Controls +{ + partial class ParameterItemMenuStrip + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.myMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); + this.addNewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.myMenuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // myMenuStrip + // + this.myMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.addNewToolStripMenuItem, + this.deleteToolStripMenuItem}); + this.myMenuStrip.Name = "contextMenuStrip"; + this.myMenuStrip.Size = new System.Drawing.Size(181, 70); + // + // addNewToolStripMenuItem + // + this.addNewToolStripMenuItem.Name = "addNewToolStripMenuItem"; + this.addNewToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.addNewToolStripMenuItem.Text = "Создать"; + // + // deleteToolStripMenuItem + // + this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem"; + this.deleteToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.deleteToolStripMenuItem.Text = "Удалить"; + // + // ParameterPanelMenuStrip + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Name = "ParameterPanelMenuStrip"; + this.myMenuStrip.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ContextMenuStrip myMenuStrip; + private System.Windows.Forms.ToolStripMenuItem addNewToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem; + } +} diff --git a/Controls/ParameterItemMenuStrip.cs b/Controls/ParameterItemMenuStrip.cs new file mode 100644 index 0000000..b371ba6 --- /dev/null +++ b/Controls/ParameterItemMenuStrip.cs @@ -0,0 +1,35 @@ +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 GtaVUsersInfo.Controls +{ + public partial class ParameterItemMenuStrip : UserControl + { + public ContextMenuStrip Menu + { + get { return myMenuStrip; } + } + + public ParameterControl Parameter; + + public ParameterItemMenuStrip(EventHandler add, EventHandler delete, ParameterControl parameter) + { + InitializeComponent(); + + addNewToolStripMenuItem.Click += add; + deleteToolStripMenuItem.Click += delete; + + Parameter = parameter; + + addNewToolStripMenuItem.Tag = this; + deleteToolStripMenuItem.Tag = this; + } + } +} diff --git a/Controls/ParameterItemMenuStrip.resx b/Controls/ParameterItemMenuStrip.resx new file mode 100644 index 0000000..72c1c54 --- /dev/null +++ b/Controls/ParameterItemMenuStrip.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/Controls/ParameterPanelMenuStrip.Designer.cs b/Controls/ParameterPanelMenuStrip.Designer.cs new file mode 100644 index 0000000..ab52b28 --- /dev/null +++ b/Controls/ParameterPanelMenuStrip.Designer.cs @@ -0,0 +1,65 @@ +namespace GtaVUsersInfo.Controls +{ + partial class ParameterPanelMenuStrip + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.myMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); + this.addNewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.myMenuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // myMenuStrip + // + this.myMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.addNewToolStripMenuItem}); + this.myMenuStrip.Name = "contextMenuStrip"; + this.myMenuStrip.Size = new System.Drawing.Size(181, 48); + // + // addNewToolStripMenuItem + // + this.addNewToolStripMenuItem.Name = "addNewToolStripMenuItem"; + this.addNewToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.addNewToolStripMenuItem.Text = "Создать"; + // + // ParameterItemMenuStrip + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Name = "ParameterItemMenuStrip"; + this.myMenuStrip.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ContextMenuStrip myMenuStrip; + private System.Windows.Forms.ToolStripMenuItem addNewToolStripMenuItem; + } +} diff --git a/Controls/ParameterPanelMenuStrip.cs b/Controls/ParameterPanelMenuStrip.cs new file mode 100644 index 0000000..c3f55b0 --- /dev/null +++ b/Controls/ParameterPanelMenuStrip.cs @@ -0,0 +1,27 @@ +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 GtaVUsersInfo.Controls +{ + public partial class ParameterPanelMenuStrip : UserControl + { + public ContextMenuStrip Menu + { + get { return myMenuStrip; } + } + + public ParameterPanelMenuStrip(EventHandler add) + { + InitializeComponent(); + + addNewToolStripMenuItem.Click += add; + } + } +} diff --git a/Controls/ParameterPanelMenuStrip.resx b/Controls/ParameterPanelMenuStrip.resx new file mode 100644 index 0000000..72c1c54 --- /dev/null +++ b/Controls/ParameterPanelMenuStrip.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/GtaVUsersInfo.csproj b/GtaVUsersInfo.csproj index 8c12c80..b2d27be 100644 --- a/GtaVUsersInfo.csproj +++ b/GtaVUsersInfo.csproj @@ -97,6 +97,18 @@ CarPanelMenuStrip.cs + + UserControl + + + ParameterPanelMenuStrip.cs + + + UserControl + + + ParameterItemMenuStrip.cs + Form @@ -105,11 +117,11 @@ - + UserControl - - CarItem.cs + + CarControl.cs Form @@ -144,11 +156,17 @@ CarPanelMenuStrip.cs + + ParameterPanelMenuStrip.cs + + + ParameterItemMenuStrip.cs + AddCars.cs - - CarItem.cs + + CarControl.cs AddParameter.cs diff --git a/Helpers/ErrorsShow.cs b/Helpers/ErrorsShow.cs index f1636ea..d4a3a12 100644 --- a/Helpers/ErrorsShow.cs +++ b/Helpers/ErrorsShow.cs @@ -20,5 +20,10 @@ namespace GtaVUsersInfo.Helpers MessageBox.Show(message, "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); Console.WriteLine(message); } + + public static DialogResult ShowQuestMessage(string message) + { + return MessageBox.Show(message, "Информация", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + } } } diff --git a/MainForm.cs b/MainForm.cs index 454c4b1..69234ff 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -25,7 +25,7 @@ namespace GtaVUsersInfo private List carList; private List parameters; - private List cars; + private List cars; public MainForm() { @@ -38,9 +38,10 @@ namespace GtaVUsersInfo carList = LoadCarsFromJson(Resources.carJsonPath); parameters = new List { new ParameterControl("Имя"), new ParameterControl("Деньги") }; - cars = new List(); + cars = new List(); carsItems.ContextMenuStrip = new CarPanelMenuStrip(addNewCar).Menu; + parametersPanel.ContextMenuStrip = new ParameterPanelMenuStrip(addNewParameter).Menu; } private void MainForm_Load(object sender, EventArgs e) @@ -61,6 +62,7 @@ namespace GtaVUsersInfo foreach (Control param in parameters) { param.Dock = DockStyle.Top; + (param as ParameterControl).MenuStrip = new ParameterItemMenuStrip(addNewParameter, deleteParameter, param as ParameterControl).Menu; parametersPanel.Controls.Add(param); parametersPanel.Controls.SetChildIndex(param, 0); } @@ -70,7 +72,7 @@ namespace GtaVUsersInfo { carsItems.Controls.Clear(); - foreach (CarItem car in cars) + foreach (CarControl car in cars) { carsItems.Controls.Add(car); } @@ -152,7 +154,7 @@ namespace GtaVUsersInfo if (car.Name != null) { - CarItem item = new CarItem(car); + CarControl item = new CarControl(car); item.MenuStrip = new CarItemMenuStrip(addNewCar, editCar, deleteCar, item).Menu; cars.Add(item); CarPanelCreate(); @@ -180,7 +182,7 @@ namespace GtaVUsersInfo if (menu == null) return; - CarItem carItem = menu.Car as CarItem; + CarControl carItem = menu.Car; if (carItem == null) return; @@ -213,14 +215,20 @@ namespace GtaVUsersInfo if (menu == null) return; - CarItem carItem = menu.Car; + CarControl carItem = menu.Car; if (carItem == null) return; if (cars.Contains(carItem)) { - cars.Remove(carItem); - CarPanelCreate(); + if ( + ErrorsShow.ShowQuestMessage( + $"Вы точно хотите удалить автомобиль: {carItem.Car.Name} - {carItem.Car.Price}?" + ) == DialogResult.Yes) + { + cars.Remove(carItem); + CarPanelCreate(); + } } } @@ -240,5 +248,43 @@ namespace GtaVUsersInfo ParameterPanelCreate(); } } + + private void addNewParameter(object sender, EventArgs e) + { + addParameter_Click(sender, e); + } + + private void deleteParameter(object sender, EventArgs e) + { + if (parameters.Count <= 0) + { + ErrorsShow.ShowErrorMessage($"Список параметров пуст"); + return; + } + + ToolStripMenuItem clickedMenuItem = sender as ToolStripMenuItem; + if (clickedMenuItem == null) + return; + + ParameterItemMenuStrip menu = clickedMenuItem.Tag as ParameterItemMenuStrip; + if (menu == null) + return; + + ParameterControl parameterControl = menu.Parameter; + if (parameterControl == null) + return; + + if (parameters.Contains(parameterControl)) + { + if ( + ErrorsShow.ShowQuestMessage( + $"Вы точно хотите удалить элемент: {parameterControl.ParamName}?" + ) == DialogResult.Yes) + { + parameters.Remove(parameterControl); + ParameterPanelCreate(); + } + } + } } }