lab2 последнее изменение от первой
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
namespace ComputerShop.Enums
|
||||
{
|
||||
public enum CategoryName
|
||||
{
|
||||
Процессоры = 1,
|
||||
МатеринскиеПлаты = 2,
|
||||
Видеокарты = 3,
|
||||
ОперативнаяПамять = 4,
|
||||
Корпуса = 5,
|
||||
БлокиПитания = 6,
|
||||
ОхлаждениеКомпьютера = 7,
|
||||
ТвердотельныеНакопителиSSD = 8,
|
||||
ЖесткиеДискиHDD = 9,
|
||||
Мониторы = 10
|
||||
}
|
||||
}
|
||||
@@ -4,19 +4,18 @@ public class Parts
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public CategoryName Category { get; set; }
|
||||
|
||||
public decimal Price { get; set; }
|
||||
public int WarrantyMonths { get; set; }
|
||||
|
||||
public PartFlags Flags { get; set; } = PartFlags.None;
|
||||
|
||||
public static Parts CreateEntity(int id, string name, CategoryName category, decimal price, int warranty, PartFlags flags = PartFlags.None)
|
||||
public static Parts CreateEntity(int id, string name, decimal price, int warranty, PartFlags flags = PartFlags.None)
|
||||
{
|
||||
return new Parts
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
Category = category,
|
||||
Price = price,
|
||||
WarrantyMonths = warranty,
|
||||
Flags = flags
|
||||
|
||||
@@ -18,9 +18,10 @@ namespace ProjectComputerShop.Forms
|
||||
InitializeComponent();
|
||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
_categoriesRepository = categoriesRepository ?? throw new ArgumentNullException(nameof(categoriesRepository));
|
||||
LoadList();
|
||||
}
|
||||
|
||||
private void FormCategories_Load(object sender, EventArgs e)
|
||||
private void FormCategories_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -12,23 +12,22 @@
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
comboBoxCategory = new ComboBox();
|
||||
textBoxCategory = new TextBox();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
label1 = new Label();
|
||||
SuspendLayout();
|
||||
//
|
||||
// comboBoxCategory
|
||||
// textBoxCategory
|
||||
//
|
||||
comboBoxCategory.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxCategory.FormattingEnabled = true;
|
||||
comboBoxCategory.Location = new Point(32, 27);
|
||||
comboBoxCategory.Name = "comboBoxCategory";
|
||||
comboBoxCategory.Size = new Size(310, 28);
|
||||
comboBoxCategory.TabIndex = 0;
|
||||
textBoxCategory.Location = new Point(32, 47);
|
||||
textBoxCategory.Name = "textBoxCategory";
|
||||
textBoxCategory.Size = new Size(310, 27);
|
||||
textBoxCategory.TabIndex = 0;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(32, 85);
|
||||
buttonSave.Location = new Point(32, 105);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(120, 40);
|
||||
buttonSave.TabIndex = 1;
|
||||
@@ -38,7 +37,7 @@
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(222, 85);
|
||||
buttonCancel.Location = new Point(222, 105);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(120, 40);
|
||||
buttonCancel.TabIndex = 2;
|
||||
@@ -46,10 +45,20 @@
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(32, 24);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(148, 20);
|
||||
label1.TabIndex = 3;
|
||||
label1.Text = "Название категории:";
|
||||
//
|
||||
// FormCategory
|
||||
//
|
||||
ClientSize = new Size(391, 160);
|
||||
Controls.Add(comboBoxCategory);
|
||||
ClientSize = new Size(391, 180);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(textBoxCategory);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(buttonCancel);
|
||||
FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||
@@ -59,10 +68,12 @@
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Категория";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
private System.Windows.Forms.ComboBox comboBoxCategory;
|
||||
private System.Windows.Forms.TextBox textBoxCategory;
|
||||
private System.Windows.Forms.Button buttonSave;
|
||||
private System.Windows.Forms.Button buttonCancel;
|
||||
private System.Windows.Forms.Label label1;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,29 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using ComputerShop.Enums;
|
||||
using ProjectComputerShop.Entities;
|
||||
|
||||
namespace ProjectComputerShop.Forms
|
||||
{
|
||||
public partial class FormCategory : Form
|
||||
{
|
||||
public CategoryName SelectedCategory { get; private set; }
|
||||
public string CategoryName { get; private set; } = string.Empty;
|
||||
public int Id { get; internal set; }
|
||||
|
||||
public FormCategory()
|
||||
{
|
||||
InitializeComponent();
|
||||
LoadCategories();
|
||||
}
|
||||
|
||||
private void LoadCategories()
|
||||
{
|
||||
comboBoxCategory.DataSource = Enum.GetValues(typeof(CategoryName));
|
||||
comboBoxCategory.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxCategory.SelectedValue == null)
|
||||
if (string.IsNullOrWhiteSpace(textBoxCategory.Text))
|
||||
{
|
||||
MessageBox.Show("Выберите категорию!", "Внимание",
|
||||
MessageBox.Show("Введите название категории!", "Внимание",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
SelectedCategory = (CategoryName)comboBoxCategory.SelectedValue;
|
||||
CategoryName = textBoxCategory.Text.Trim();
|
||||
this.DialogResult = DialogResult.OK;
|
||||
this.Close();
|
||||
}
|
||||
@@ -40,6 +33,5 @@ namespace ProjectComputerShop.Forms
|
||||
this.DialogResult = DialogResult.Cancel;
|
||||
this.Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,7 @@
|
||||
buttonSave.TabIndex = 15;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
@@ -127,6 +128,7 @@
|
||||
buttonCancel.TabIndex = 16;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// labelCategory
|
||||
//
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
InitializeComponent(checkRGB);
|
||||
}
|
||||
|
||||
private void InitializeComponent(CheckBox checkRGB)
|
||||
{
|
||||
_components = new System.ComponentModel.Container();
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace ProjectComputerShop.Forms
|
||||
|
||||
textBoxName.Text = part.Name;
|
||||
;
|
||||
comboBoxCategory.SelectedItem = part.Category;
|
||||
|
||||
numericPrice.Value = part.Price;
|
||||
numericWarranty.Value = part.WarrantyMonths;
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace ProjectComputerShop.Forms
|
||||
InitializeComponent();
|
||||
_repository = repository;
|
||||
|
||||
comboBoxCategory.DataSource = Enum.GetValues(typeof(CategoryName));
|
||||
|
||||
comboBoxCategory.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,6 @@ namespace ProjectComputerShop.Forms
|
||||
var part = Parts.CreateEntity(
|
||||
id: _partId ?? 0,
|
||||
name: textBoxName.Text.Trim(),
|
||||
category: (CategoryName)comboBoxCategory.SelectedValue,
|
||||
price: numericPrice.Value,
|
||||
warranty: (int)numericWarranty.Value,
|
||||
flags: flags
|
||||
|
||||
@@ -9,5 +9,6 @@ namespace ComputerShop.Repositories
|
||||
void Create(Parts part);
|
||||
void Update(Parts part);
|
||||
void Delete(int id);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user