diff --git a/DoubleDeckerBus/Drawing/DrawingBus.cs b/DoubleDeckerBus/Drawing/DrawingBus.cs index 4257c8c..e70186f 100644 --- a/DoubleDeckerBus/Drawing/DrawingBus.cs +++ b/DoubleDeckerBus/Drawing/DrawingBus.cs @@ -90,26 +90,39 @@ namespace DoubleDeckerbus.Drawing } public virtual void DrawTransport(Graphics g) { + // + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(EntityBus.BodyColor); - g.FillRectangle(additionalBrush, _startPosX + 147, _startPosY + 52, 21, 20); - g.FillRectangle(additionalBrush, _startPosX + 147, _startPosY + 71, 30, 27); - g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY + 52, 137, 46); + + g.FillRectangle(additionalBrush, _startPosX + 147, _startPosY + 52, 21, 20); + g.FillRectangle(additionalBrush, _startPosX + 147, _startPosY + 71, 30, 27); + g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY + 52, 137, 46); + Brush brBlue = new SolidBrush(Color.LightBlue); + g.FillRectangle(brBlue, _startPosX + 150, _startPosY + 55, 15, 15); + g.FillRectangle(brBlue, _startPosX + 42, _startPosY + 55, 15, 15); g.FillRectangle(brBlue, _startPosX + 69, _startPosY + 55, 15, 15); g.FillRectangle(brBlue, _startPosX + 96, _startPosY + 55, 15, 15); g.FillRectangle(brBlue, _startPosX + 123, _startPosY + 55, 15, 15); + + g.DrawLine(pen, _startPosX + 30, _startPosY + 52, _startPosX + 30, _startPosY + 98); g.DrawLine(pen, _startPosX + 35, _startPosY + 52, _startPosX + 35, _startPosY + 98); + Brush gr = new SolidBrush(Color.Gray); + g.FillEllipse(additionalBrush, _startPosX + 23, _startPosY + 88, 25, 25); g.FillEllipse(additionalBrush, _startPosX + 123, _startPosY + 88, 25, 25); + g.FillEllipse(gr, _startPosX + 25, _startPosY + 90, 21, 21); g.FillEllipse(gr, _startPosX + 125, _startPosY + 90, 21, 21); } + public bool CanMove(DirectionType direction) { if (EntityBus == null) @@ -125,6 +138,7 @@ namespace DoubleDeckerbus.Drawing _ => false, }; } + public void ChangeBordersPicture(int width, int height) { _pictureWidth = width; diff --git a/DoubleDeckerBus/Drawing/DrawingDoubleDeckerbus.cs b/DoubleDeckerBus/Drawing/DrawingDoubleDeckerbus.cs index 827ecc1..2513eba 100644 --- a/DoubleDeckerBus/Drawing/DrawingDoubleDeckerbus.cs +++ b/DoubleDeckerBus/Drawing/DrawingDoubleDeckerbus.cs @@ -16,6 +16,7 @@ namespace DoubleDeckerbus.Drawing { EntityBus = new EntityDoubleDeckerbus(speed, weight, bodyColor, additionalColor, secondfloor, stairs); } + } public override void DrawTransport(Graphics g) { @@ -23,17 +24,20 @@ namespace DoubleDeckerbus.Drawing { return; } - Pen pen = new(Color.Black); - Pen additionalPen = new(doubleDeckerBus.Body); - Brush additionalBrush = new SolidBrush(doubleDeckerBus.Body); + Pen pen = new(Color.Black); + Pen additionalPen = new(doubleDeckerBus.AddColor); + Brush additionalBrush = new SolidBrush(doubleDeckerBus.AddColor); base.DrawTransport(g); - if (doubleDeckerBus.Secondfloor) + if (doubleDeckerBus.IsSecondFloor) { - Brush additionalBrush2 = new SolidBrush(doubleDeckerBus.Body); + Brush additionalBrush2 = new SolidBrush(doubleDeckerBus.AddColor); Brush brBlue = new SolidBrush(Color.LightBlue); + g.FillRectangle(additionalBrush2, _startPosX + 7, _startPosY + 12, 172, 40); + g.DrawLine(pen, _startPosX + 7, _startPosY + 36, _startPosX + 178, _startPosY + 36); + g.FillRectangle(brBlue, _startPosX + 15, _startPosY + 15, 15, 15); g.FillRectangle(brBlue, _startPosX + 42, _startPosY + 15, 15, 15); g.FillRectangle(brBlue, _startPosX + 69, _startPosY + 15, 15, 15); @@ -42,7 +46,7 @@ namespace DoubleDeckerbus.Drawing g.FillRectangle(brBlue, _startPosX + 150, _startPosY + 15, 15, 15); } - if (doubleDeckerBus.Stairs) + if (doubleDeckerBus.IsStairs) { g.DrawLine(pen, _startPosX + 10, _startPosY + 55, _startPosX + 34, _startPosY + 55); g.DrawLine(pen, _startPosX + 10, _startPosY + 58, _startPosX + 34, _startPosY + 58); diff --git a/DoubleDeckerBus/Drawing/ExtentionDrawingBus.cs b/DoubleDeckerBus/Drawing/ExtentionDrawingBus.cs new file mode 100644 index 0000000..e0ee0c7 --- /dev/null +++ b/DoubleDeckerBus/Drawing/ExtentionDrawingBus.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DoubleDeckerbus.Entities; + +namespace DoubleDeckerbus.Drawing +{ + public static class ExtentionDrawingBus + { + public static DrawingBus? CreateDrawingBus(this string info, char separatorForObject, int width, int height) + { + string[] strs = info.Split(separatorForObject); + if (strs.Length == 3) + { + return new DrawingBus( + Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), + Color.FromName(strs[2]), width, height); + } + if (strs.Length == 6) + { + return new DrawingDoubleDeckerbus( + Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), + Color.FromName(strs[2]), Color.FromName(strs[3]), + Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5]), + width, height); + } + return null; + } + + public static string GetDataForSave(this DrawingBus DrawingBus, char separatorForObject) + { + var truck = DrawingBus.EntityBus; + if (truck == null) + { + return string.Empty; + } + var str = $"{truck.Speed}{separatorForObject}{truck.Weight}{separatorForObject}{truck.BodyColor.Name}"; + if (truck is not EntityDoubleDeckerbus DoubleDeckerBus) + { + return str; + } + return $"{str}{separatorForObject}{DoubleDeckerBus.AddColor.Name}{separatorForObject}{DoubleDeckerBus.IsSecondFloor}{separatorForObject}{DoubleDeckerBus.IsStairs}"; + } + } +} + diff --git a/DoubleDeckerBus/Entities/DirectionType.cs b/DoubleDeckerBus/Entities/DirectionType.cs index e635c45..ae174c9 100644 --- a/DoubleDeckerBus/Entities/DirectionType.cs +++ b/DoubleDeckerBus/Entities/DirectionType.cs @@ -12,5 +12,6 @@ namespace DoubleDeckerbus.Entities Down = 2, Left = 3, Right = 4 + } } \ No newline at end of file diff --git a/DoubleDeckerBus/Entities/EntityBus.cs b/DoubleDeckerBus/Entities/EntityBus.cs index 977fd31..bcb71c4 100644 --- a/DoubleDeckerBus/Entities/EntityBus.cs +++ b/DoubleDeckerBus/Entities/EntityBus.cs @@ -18,6 +18,7 @@ namespace DoubleDeckerbus.Entities Weight = weight; BodyColor = bodyColor; } + public void ChangeBodyColor(Color color) { BodyColor = color; diff --git a/DoubleDeckerBus/Entities/EntityDoubleDeckerbus.cs b/DoubleDeckerBus/Entities/EntityDoubleDeckerbus.cs index c8fd7c5..76b2e96 100644 --- a/DoubleDeckerBus/Entities/EntityDoubleDeckerbus.cs +++ b/DoubleDeckerBus/Entities/EntityDoubleDeckerbus.cs @@ -10,14 +10,16 @@ namespace DoubleDeckerbus.Entities public class EntityDoubleDeckerbus : EntityBus { public Color AddColor { get; private set; } - public bool Secondfloor { get; private set; } - public bool Stairs { get; private set; } + public bool IsSecondFloor { get; private set; } + public bool IsStairs { get; private set; } + public EntityDoubleDeckerbus(int speed, double weight, Color bodyColor, Color additionalColor, bool secondfloor, bool stairs) : base(speed, weight, bodyColor) { AddColor = additionalColor; - Secondfloor = secondfloor; - Stairs = stairs; + IsSecondFloor = secondfloor; + IsStairs = stairs; } + public void ChangeAdditionalColor(Color additionalColor) { AddColor = additionalColor; diff --git a/DoubleDeckerBus/FormBusConfig.cs b/DoubleDeckerBus/FormBusConfig.cs index 54c39a3..d1ed09d 100644 --- a/DoubleDeckerBus/FormBusConfig.cs +++ b/DoubleDeckerBus/FormBusConfig.cs @@ -13,7 +13,8 @@ using DoubleDeckerbus.Entities; namespace DoubleDeckerbus { public partial class FormBusConfig : Form - { + { + DrawingBus? _bus = null; private event Action? EventAddBus; public FormBusConfig() @@ -48,11 +49,13 @@ namespace DoubleDeckerbus EventAddBus += ev; } } + private void LabelObject_MouseDown(object sender, MouseEventArgs e) { (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); } + private void PanelObject_DragEnter(object sender, DragEventArgs e) { if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) @@ -87,11 +90,13 @@ namespace DoubleDeckerbus } DrawBus(); } + private void PanelColor_MouseDown(object sender, MouseEventArgs e) { (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); } + private void LabelMainColor_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(Color)) && _bus != null) @@ -103,12 +108,14 @@ namespace DoubleDeckerbus e.Effect = DragDropEffects.None; } } + private void LabelMainColor_DragDrop(object sender, DragEventArgs e) { var color = (Color)e.Data.GetData(typeof(Color)); _bus.EntityBus.ChangeBodyColor(color); DrawBus(); } + private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(Color)) && _bus != null && _bus is DrawingDoubleDeckerbus) @@ -128,6 +135,7 @@ namespace DoubleDeckerbus _doubledeckerbus.ChangeAdditionalColor(color); DrawBus(); } + private void ButtonAdd_Click(object sender, EventArgs e) { EventAddBus?.Invoke(_bus); diff --git a/DoubleDeckerBus/FormBusConfig.resx b/DoubleDeckerBus/FormBusConfig.resx index f298a7b..af32865 100644 --- a/DoubleDeckerBus/FormBusConfig.resx +++ b/DoubleDeckerBus/FormBusConfig.resx @@ -1,4 +1,64 @@ - + + + diff --git a/DoubleDeckerBus/FormDoubleDeckerbusCollection.Designer.cs b/DoubleDeckerBus/FormDoubleDeckerbusCollection.Designer.cs index f6d2d48..b625dd7 100644 --- a/DoubleDeckerBus/FormDoubleDeckerbusCollection.Designer.cs +++ b/DoubleDeckerBus/FormDoubleDeckerbusCollection.Designer.cs @@ -28,155 +28,211 @@ /// private void InitializeComponent() { - buttonAddBus = new Button(); - pictureBoxCollection = new PictureBox(); - labelInstruments = new Label(); - buttonUpdate = new Button(); - buttonDeleteBus = new Button(); - colorDialog = new ColorDialog(); - maskedTextBoxNumber = new MaskedTextBox(); - label1 = new Label(); - listBoxStorages = new ListBox(); - buttonAddStorage = new Button(); - buttonDeleteStorage = new Button(); - textBoxStorageName = new TextBox(); - ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); - SuspendLayout(); + this.buttonAddBus = new System.Windows.Forms.Button(); + this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); + this.labelInstruments = new System.Windows.Forms.Label(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDeleteBus = new System.Windows.Forms.Button(); + this.colorDialog = new System.Windows.Forms.ColorDialog(); + this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.listBoxStorages = new System.Windows.Forms.ListBox(); + this.buttonAddStorage = new System.Windows.Forms.Button(); + this.buttonDeleteStorage = new System.Windows.Forms.Button(); + this.textBoxStorageName = new System.Windows.Forms.TextBox(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.toolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); + this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); // // buttonAddBus // - buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonAddBus.Location = new Point(859, 331); - buttonAddBus.Name = "buttonAddBus"; - buttonAddBus.Size = new Size(118, 28); - buttonAddBus.TabIndex = 0; - buttonAddBus.Text = "Добавить автобус"; - buttonAddBus.UseVisualStyleBackColor = true; - buttonAddBus.Click += buttonAddBus_Click; + this.buttonAddBus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonAddBus.Location = new System.Drawing.Point(859, 331); + this.buttonAddBus.Name = "buttonAddBus"; + this.buttonAddBus.Size = new System.Drawing.Size(118, 28); + this.buttonAddBus.TabIndex = 0; + this.buttonAddBus.Text = "Добавить автобус"; + this.buttonAddBus.UseVisualStyleBackColor = true; + this.buttonAddBus.Click += new System.EventHandler(this.buttonAddBus_Click); // // pictureBoxCollection // - pictureBoxCollection.Location = new Point(3, 0); - pictureBoxCollection.Name = "pictureBoxCollection"; - pictureBoxCollection.Size = new Size(830, 475); - pictureBoxCollection.TabIndex = 1; - pictureBoxCollection.TabStop = false; + this.pictureBoxCollection.Location = new System.Drawing.Point(0, 20); + this.pictureBoxCollection.Name = "pictureBoxCollection"; + this.pictureBoxCollection.Size = new System.Drawing.Size(830, 475); + this.pictureBoxCollection.TabIndex = 1; + this.pictureBoxCollection.TabStop = false; // // labelInstruments // - labelInstruments.Anchor = AnchorStyles.Top | AnchorStyles.Right; - labelInstruments.AutoSize = true; - labelInstruments.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); - labelInstruments.Location = new Point(859, 0); - labelInstruments.Name = "labelInstruments"; - labelInstruments.Size = new Size(108, 21); - labelInstruments.TabIndex = 2; - labelInstruments.Text = "Инструменты"; + this.labelInstruments.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.labelInstruments.AutoSize = true; + this.labelInstruments.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.labelInstruments.Location = new System.Drawing.Point(859, 0); + this.labelInstruments.Name = "labelInstruments"; + this.labelInstruments.Size = new System.Drawing.Size(108, 21); + this.labelInstruments.TabIndex = 2; + this.labelInstruments.Text = "Инструменты"; // // buttonUpdate // - buttonUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonUpdate.Location = new Point(851, 130); - buttonUpdate.Name = "buttonUpdate"; - buttonUpdate.Size = new Size(131, 25); - buttonUpdate.TabIndex = 3; - buttonUpdate.Text = "Обновить набор"; - buttonUpdate.UseVisualStyleBackColor = true; - buttonUpdate.Click += buttonUpdate_Click; + this.buttonUpdate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUpdate.Location = new System.Drawing.Point(851, 130); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(131, 25); + this.buttonUpdate.TabIndex = 3; + this.buttonUpdate.Text = "Обновить набор"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); // // buttonDeleteBus // - buttonDeleteBus.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonDeleteBus.Location = new Point(859, 394); - buttonDeleteBus.Name = "buttonDeleteBus"; - buttonDeleteBus.Size = new Size(118, 28); - buttonDeleteBus.TabIndex = 4; - buttonDeleteBus.Text = "Удалить автобус"; - buttonDeleteBus.UseVisualStyleBackColor = true; - buttonDeleteBus.Click += buttonDeleteBus_Click; + this.buttonDeleteBus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDeleteBus.Location = new System.Drawing.Point(859, 394); + this.buttonDeleteBus.Name = "buttonDeleteBus"; + this.buttonDeleteBus.Size = new System.Drawing.Size(118, 28); + this.buttonDeleteBus.TabIndex = 4; + this.buttonDeleteBus.Text = "Удалить автобус"; + this.buttonDeleteBus.UseVisualStyleBackColor = true; + this.buttonDeleteBus.Click += new System.EventHandler(this.buttonDeleteBus_Click); // // maskedTextBoxNumber // - maskedTextBoxNumber.Anchor = AnchorStyles.Top | AnchorStyles.Right; - maskedTextBoxNumber.Location = new Point(851, 365); - maskedTextBoxNumber.Mask = "00"; - maskedTextBoxNumber.Name = "maskedTextBoxNumber"; - maskedTextBoxNumber.Size = new Size(138, 23); - maskedTextBoxNumber.TabIndex = 5; - maskedTextBoxNumber.ValidatingType = typeof(int); + this.maskedTextBoxNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.maskedTextBoxNumber.Location = new System.Drawing.Point(851, 365); + this.maskedTextBoxNumber.Mask = "00"; + this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + this.maskedTextBoxNumber.Size = new System.Drawing.Size(138, 23); + this.maskedTextBoxNumber.TabIndex = 5; + this.maskedTextBoxNumber.ValidatingType = typeof(int); // // label1 // - label1.Anchor = AnchorStyles.Top | AnchorStyles.Right; - label1.AutoSize = true; - label1.Location = new Point(851, 38); - label1.Name = "label1"; - label1.Size = new Size(52, 15); - label1.TabIndex = 7; - label1.Text = "Наборы"; + this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(851, 38); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(52, 15); + this.label1.TabIndex = 7; + this.label1.Text = "Наборы"; // // listBoxStorages // - listBoxStorages.FormattingEnabled = true; - listBoxStorages.ItemHeight = 15; - listBoxStorages.Location = new Point(850, 160); - listBoxStorages.Margin = new Padding(3, 2, 3, 2); - listBoxStorages.Name = "listBoxStorages"; - listBoxStorages.Size = new Size(132, 109); - listBoxStorages.TabIndex = 8; - listBoxStorages.SelectedIndexChanged += listBoxObjects_SelectedIndexChanged; + this.listBoxStorages.FormattingEnabled = true; + this.listBoxStorages.ItemHeight = 15; + this.listBoxStorages.Location = new System.Drawing.Point(850, 160); + this.listBoxStorages.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.listBoxStorages.Name = "listBoxStorages"; + this.listBoxStorages.Size = new System.Drawing.Size(132, 109); + this.listBoxStorages.TabIndex = 8; + this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged); // // buttonAddStorage // - buttonAddStorage.Location = new Point(850, 102); - buttonAddStorage.Margin = new Padding(3, 2, 3, 2); - buttonAddStorage.Name = "buttonAddStorage"; - buttonAddStorage.Size = new Size(131, 25); - buttonAddStorage.TabIndex = 9; - buttonAddStorage.Text = "Добавить набор"; - buttonAddStorage.UseVisualStyleBackColor = true; - buttonAddStorage.Click += buttonAddStorage_Click; + this.buttonAddStorage.Location = new System.Drawing.Point(850, 102); + this.buttonAddStorage.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAddStorage.Name = "buttonAddStorage"; + this.buttonAddStorage.Size = new System.Drawing.Size(131, 25); + this.buttonAddStorage.TabIndex = 9; + this.buttonAddStorage.Text = "Добавить набор"; + this.buttonAddStorage.UseVisualStyleBackColor = true; + this.buttonAddStorage.Click += new System.EventHandler(this.buttonAddStorage_Click); // // buttonDeleteStorage // - buttonDeleteStorage.Location = new Point(850, 273); - buttonDeleteStorage.Margin = new Padding(3, 2, 3, 2); - buttonDeleteStorage.Name = "buttonDeleteStorage"; - buttonDeleteStorage.Size = new Size(131, 25); - buttonDeleteStorage.TabIndex = 10; - buttonDeleteStorage.Text = "Удалить набор"; - buttonDeleteStorage.UseVisualStyleBackColor = true; - buttonDeleteStorage.Click += buttonDeleteStorage_Click; + this.buttonDeleteStorage.Location = new System.Drawing.Point(850, 273); + this.buttonDeleteStorage.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDeleteStorage.Name = "buttonDeleteStorage"; + this.buttonDeleteStorage.Size = new System.Drawing.Size(131, 25); + this.buttonDeleteStorage.TabIndex = 10; + this.buttonDeleteStorage.Text = "Удалить набор"; + this.buttonDeleteStorage.UseVisualStyleBackColor = true; + this.buttonDeleteStorage.Click += new System.EventHandler(this.buttonDeleteStorage_Click); // // textBoxStorageName // - textBoxStorageName.Location = new Point(850, 77); - textBoxStorageName.Margin = new Padding(3, 2, 3, 2); - textBoxStorageName.Name = "textBoxStorageName"; - textBoxStorageName.Size = new Size(132, 23); - textBoxStorageName.TabIndex = 11; + this.textBoxStorageName.Location = new System.Drawing.Point(850, 77); + this.textBoxStorageName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxStorageName.Name = "textBoxStorageName"; + this.textBoxStorageName.Size = new System.Drawing.Size(132, 23); + this.textBoxStorageName.TabIndex = 11; + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); + this.menuStrip.Size = new System.Drawing.Size(1003, 24); + this.menuStrip.TabIndex = 12; + this.menuStrip.Text = "menuStrip1"; + // + // toolStripMenuItem + // + this.toolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.saveToolStripMenuItem, + this.loadToolStripMenuItem}); + this.toolStripMenuItem.Name = "toolStripMenuItem"; + this.toolStripMenuItem.Size = new System.Drawing.Size(48, 20); + this.toolStripMenuItem.Text = "Файл"; + // + // saveToolStripMenuItem + // + this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; + this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.saveToolStripMenuItem.Text = "Сохранить"; + this.saveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click); + // + // loadToolStripMenuItem + // + this.loadToolStripMenuItem.Name = "loadToolStripMenuItem"; + this.loadToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.loadToolStripMenuItem.Text = "Загрузить"; + this.loadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click); + // + // saveFileDialog + // + this.saveFileDialog.Filter = "txt file | *.txt"; + // + // openFileDialog + // + this.openFileDialog.FileName = "openFileDialog1"; + this.openFileDialog.Filter = "txt file | *.txt"; // // FormDoubleDeckerbusCollection // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1003, 480); - Controls.Add(textBoxStorageName); - Controls.Add(buttonDeleteStorage); - Controls.Add(buttonAddStorage); - Controls.Add(listBoxStorages); - Controls.Add(label1); - Controls.Add(buttonAddBus); - Controls.Add(maskedTextBoxNumber); - Controls.Add(buttonDeleteBus); - Controls.Add(buttonUpdate); - Controls.Add(labelInstruments); - Controls.Add(pictureBoxCollection); - Name = "FormDoubleDeckerbusCollection"; - Text = "Набор автобусов"; - ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); - ResumeLayout(false); - PerformLayout(); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1003, 504); + this.Controls.Add(this.textBoxStorageName); + this.Controls.Add(this.buttonDeleteStorage); + this.Controls.Add(this.buttonAddStorage); + this.Controls.Add(this.listBoxStorages); + this.Controls.Add(this.label1); + this.Controls.Add(this.buttonAddBus); + this.Controls.Add(this.maskedTextBoxNumber); + this.Controls.Add(this.buttonDeleteBus); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.labelInstruments); + this.Controls.Add(this.pictureBoxCollection); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormDoubleDeckerbusCollection"; + this.Text = "Набор автобусов"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion @@ -193,5 +249,11 @@ private Button buttonAddStorage; private Button buttonDeleteStorage; private TextBox textBoxStorageName; + private MenuStrip menuStrip; + private ToolStripMenuItem toolStripMenuItem; + private ToolStripMenuItem saveToolStripMenuItem; + private ToolStripMenuItem loadToolStripMenuItem; + private SaveFileDialog saveFileDialog; + private OpenFileDialog openFileDialog; } } \ No newline at end of file diff --git a/DoubleDeckerBus/FormDoubleDeckerbusCollection.cs b/DoubleDeckerBus/FormDoubleDeckerbusCollection.cs index 04954be..2b22de3 100644 --- a/DoubleDeckerBus/FormDoubleDeckerbusCollection.cs +++ b/DoubleDeckerBus/FormDoubleDeckerbusCollection.cs @@ -11,11 +11,13 @@ using DoubleDeckerbus.Generic; using DoubleDeckerbus.Drawing; using DoubleDeckerbus.Move_Strategy; + namespace DoubleDeckerbus { public partial class FormDoubleDeckerbusCollection : Form { private readonly BusesGenericStorage _storage; + public FormDoubleDeckerbusCollection() { InitializeComponent(); @@ -37,6 +39,7 @@ namespace DoubleDeckerbus { listBoxStorages.SelectedIndex = index; } + } private void buttonAddStorage_Click(object sender, EventArgs e) { @@ -64,12 +67,15 @@ namespace DoubleDeckerbus ReloadObjects(); } } + private void buttonAddBus_Click(object sender, EventArgs e) { + var formBusConfig = new FormBusConfig(); formBusConfig.AddEvent(AddBus); formBusConfig.Show(); } + private void AddBus(DrawingBus selectedBus) { if (listBoxStorages.SelectedIndex == -1) @@ -84,15 +90,16 @@ namespace DoubleDeckerbus } selectedBus.ChangeBordersPicture(pictureBoxCollection.Width, pictureBoxCollection.Height); if (obj + selectedBus != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowBus(); - } + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowBus(); + } else - { - MessageBox.Show("Не удалось добавить объект"); - } + { + MessageBox.Show("Не удалось добавить объект"); + } } + private void buttonDeleteBus_Click(object sender, EventArgs e) { if (listBoxStorages.SelectedIndex == -1) @@ -118,7 +125,7 @@ namespace DoubleDeckerbus MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (obj - pos) + if (obj - pos) { MessageBox.Show("Объект удален"); pictureBoxCollection.Image = obj.ShowBus(); @@ -142,5 +149,36 @@ namespace DoubleDeckerbus } pictureBoxCollection.Image = obj.ShowBus(); } + private void SaveToolStripMenuItem_Click(object sender, EventArgs e) + { + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + if (_storage.SaveData(saveFileDialog.FileName)) + { + MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void LoadToolStripMenuItem_Click(object sender, EventArgs e) + { + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + if (_storage.LoadData(openFileDialog.FileName)) + { + ReloadObjects(); + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + pictureBoxCollection.Image = obj.ShowBus(); + MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } } diff --git a/DoubleDeckerBus/FormDoubleDeckerbusCollection.resx b/DoubleDeckerBus/FormDoubleDeckerbusCollection.resx index 71459e5..40da1d6 100644 --- a/DoubleDeckerBus/FormDoubleDeckerbusCollection.resx +++ b/DoubleDeckerBus/FormDoubleDeckerbusCollection.resx @@ -1,64 +1,4 @@ - - - + @@ -120,6 +60,15 @@ 17, 17 + + 152, 17 + + + 428, 16 + + + 590, 16 + 36 diff --git a/DoubleDeckerBus/Generic/BusGenericCollection.cs b/DoubleDeckerBus/Generic/BusGenericCollection.cs index 34b8735..ca4eef3 100644 --- a/DoubleDeckerBus/Generic/BusGenericCollection.cs +++ b/DoubleDeckerBus/Generic/BusGenericCollection.cs @@ -43,10 +43,13 @@ namespace DoubleDeckerbus.Generic } return collect?._collection.Remove(pos) ?? false; } + + public IEnumerable GetBus => _collection.GetBus(); public U? GetU(int pos) { return (U?)_collection[pos]?.GetMoveableObject; } + public Bitmap ShowBus() { Bitmap bmp = new(_pictureWidth, _pictureHeight); @@ -55,6 +58,7 @@ namespace DoubleDeckerbus.Generic DrawObjects(gr); return bmp; } + private void DrawBackground(Graphics gr) { Pen pen = new(Color.Black, 3); @@ -67,9 +71,9 @@ namespace DoubleDeckerbus.Generic } } } + private void DrawObjects(Graphics g) { - int x = _pictureWidth / _placeSizeWidth - 1; int y = 0; diff --git a/DoubleDeckerBus/Generic/BusesGenericStorage.cs b/DoubleDeckerBus/Generic/BusesGenericStorage.cs index a40ad90..9b542a2 100644 --- a/DoubleDeckerBus/Generic/BusesGenericStorage.cs +++ b/DoubleDeckerBus/Generic/BusesGenericStorage.cs @@ -14,12 +14,17 @@ namespace DoubleDeckerbus.Generic public List Keys => _busStorages.Keys.ToList(); private readonly int _pictureWidth; private readonly int _pictureHeight; + private static readonly char _separatorForKeyValue = '|'; + private readonly char _separatorRecords = ';'; + private static readonly char _separatorForObject = ':'; + public BusesGenericStorage(int pictureWidth, int pictureHeight) { _busStorages = new Dictionary>(); _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; } + public void AddSet(string name) { foreach (string nameStorage in Keys) @@ -32,12 +37,14 @@ namespace DoubleDeckerbus.Generic } _busStorages.Add(name, new BusGenericCollection(_pictureWidth, _pictureHeight)); } + public void DelSet(string name) { if (_busStorages.ContainsKey(name)) { _busStorages.Remove(name); } + } public BusGenericCollection? this[string ind] { @@ -50,5 +57,69 @@ namespace DoubleDeckerbus.Generic return null; } } + + public bool SaveData(string filename) + { + if (File.Exists(filename)) + { + File.Delete(filename); + } + + using (StreamWriter sw = File.CreateText(filename)) + { + sw.WriteLine($"DoubleDeckerBusStorage"); + foreach (var record in _busStorages) + { + StringBuilder records = new(); + foreach (DrawingBus? elem in record.Value.GetBus) + { + records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); + } + sw.WriteLine($"{record.Key}{_separatorForKeyValue}{records}"); + } + } + + return true; + } + + public bool LoadData(string filename) + { + if (!File.Exists(filename)) + { + return false; + } + + using (StreamReader sr = File.OpenText(filename)) + { + string? curLine = sr.ReadLine(); + if (curLine == null || !curLine.Contains("AirbusStorage")) + { + return false; + } + _busStorages.Clear(); + curLine = sr.ReadLine(); + while (curLine != null) + { + string[] record = curLine.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); + BusGenericCollection collection = new(_pictureWidth, _pictureHeight); + string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); + + foreach (string elem in set) + { + DrawingBus? Bus = elem?.CreateDrawingBus(_separatorForObject, _pictureWidth, _pictureHeight); + if (Bus != null) + { + if (collection + Bus == -1) + { + return false; + } + } + } + _busStorages.Add(record[0], collection); + curLine = sr.ReadLine(); + } + } + return true; + } } } diff --git a/DoubleDeckerBus/Generic/SetGeneric.cs b/DoubleDeckerBus/Generic/SetGeneric.cs index f4216c0..9823d3a 100644 --- a/DoubleDeckerBus/Generic/SetGeneric.cs +++ b/DoubleDeckerBus/Generic/SetGeneric.cs @@ -17,11 +17,13 @@ namespace DoubleDeckerbus.Generic _maxCount = count; _places = new List(count); } + public int Insert(T bus) { _places.Insert(0, bus); return 0; } + public bool Insert(T bus, int position) { if (position < 0 || position >= Count || Count >= _maxCount) @@ -72,4 +74,4 @@ namespace DoubleDeckerbus.Generic } } } -} \ No newline at end of file +} diff --git a/DoubleDeckerBus/Move_Strategy/AbstractStrategy.cs b/DoubleDeckerBus/Move_Strategy/AbstractStrategy.cs index 2cc7507..1a739b1 100644 --- a/DoubleDeckerBus/Move_Strategy/AbstractStrategy.cs +++ b/DoubleDeckerBus/Move_Strategy/AbstractStrategy.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using DoubleDeckerbus.Entities; using static System.Windows.Forms.VisualStyles.VisualStyleElement; + namespace DoubleDeckerbus.Move_Strategy { public abstract class AbstractStrategy @@ -69,4 +70,5 @@ namespace DoubleDeckerbus.Move_Strategy return false; } } -} \ No newline at end of file +} + diff --git a/DoubleDeckerBus/Move_Strategy/DrawingObjectBus.cs b/DoubleDeckerBus/Move_Strategy/DrawingObjectBus.cs index 067f6c9..99528c0 100644 --- a/DoubleDeckerBus/Move_Strategy/DrawingObjectBus.cs +++ b/DoubleDeckerBus/Move_Strategy/DrawingObjectBus.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using DoubleDeckerbus.Entities; using DoubleDeckerbus.Drawing; + namespace DoubleDeckerbus.Move_Strategy { public class DrawingObjectBus : IMoveableObject diff --git a/DoubleDeckerBus/Properties/Resources.Designer.cs b/DoubleDeckerBus/Properties/Resources.Designer.cs index 588fb30..85f449f 100644 --- a/DoubleDeckerBus/Properties/Resources.Designer.cs +++ b/DoubleDeckerBus/Properties/Resources.Designer.cs @@ -65,7 +65,7 @@ namespace DoubleDeckerbus.Properties { /// internal static System.Drawing.Bitmap стрелка_вверх { get { - object obj = ResourceManager.GetObject("ArrowUp", resourceCulture); + object obj = ResourceManager.GetObject("стрелка вверх", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } @@ -75,7 +75,7 @@ namespace DoubleDeckerbus.Properties { /// internal static System.Drawing.Bitmap стрелка_влево { get { - object obj = ResourceManager.GetObject("ArrowLeft", resourceCulture); + object obj = ResourceManager.GetObject("стрелка влево", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } @@ -85,7 +85,7 @@ namespace DoubleDeckerbus.Properties { /// internal static System.Drawing.Bitmap стрелка_вниз { get { - object obj = ResourceManager.GetObject("ArrowDown", resourceCulture); + object obj = ResourceManager.GetObject("стрелка вниз", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } @@ -95,7 +95,7 @@ namespace DoubleDeckerbus.Properties { /// internal static System.Drawing.Bitmap стрелка_вправо { get { - object obj = ResourceManager.GetObject("ArrowRight", resourceCulture); + object obj = ResourceManager.GetObject("стрелка вправо", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } diff --git a/DoubleDeckerBus/Properties/Resources.resx b/DoubleDeckerBus/Properties/Resources.resx index aebcb60..39ee3cd 100644 --- a/DoubleDeckerBus/Properties/Resources.resx +++ b/DoubleDeckerBus/Properties/Resources.resx @@ -118,16 +118,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - ..\Resources\ArrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\стрелка вверх.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\ArrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\стрелка влево.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\ArrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\стрелка вниз.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\ArrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\стрелка вправо.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file