This commit is contained in:
2025-11-24 11:20:28 +04:00
parent 44aa742bef
commit 383f53fe4f
11 changed files with 461 additions and 288 deletions

View File

@@ -12,7 +12,7 @@ public class Assemblies
public AssemblyStatus Status { get; private set; }
public static Assemblies CreateEntity(int id, string assemblyNumber, DateTime assemblyDate, decimal costPrice, AssemblyStatus status)
public static Assemblies CreateEntity(int id, string assemblyNumber, DateTime assemblyDate, decimal costPrice, AssemblyStatus status, decimal sellingPrice)
{
return new Assemblies
{

View File

@@ -1,11 +1,11 @@
namespace ComputerShop.Enums;
[Flags]
public enum AssemblyStatus
{
InProgress = 1,
Ready = 2,
Sold = 3
Sold = 4
}

View File

@@ -0,0 +1,20 @@
using System;
namespace ComputerShop.Enums
{
[Flags]
public enum PartFlags : int
{
None = 0,
RGB = 1,
LiquidCooling = 2,
Overclockable = 4,
Modular = 8,
NVMe = 16,
WiFi = 32,
Bluetooth = 64,
TouchScreen = 128,
BacklitKeyboard = 256,
MechanicalKeyboard = 512
}
}

View File

@@ -1,24 +1,25 @@
namespace ComputerShop.Entities;
using ComputerShop.Enums;
public class Parts
public class Part
{
public int Id { get; private set; }
public string Article { get; private set; } = string.Empty;
public string PartName { get; private set; } = string.Empty;
public int CategoryId { get; private set; }
public decimal RetailPrice { get; private set; }
public int StockQuantity { get; private set; }
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 static Parts CreateEntity(int id, string article, string partName, int categoryId, decimal retailPrice, int stockQuantity)
public PartFlags Flags { get; set; } = PartFlags.None;
public static Part CreateEntity(int id, string name, CategoryName category, decimal price, int warranty, PartFlags flags = PartFlags.None)
{
return new Parts
return new Part
{
Id = id,
Article = article,
PartName = partName,
CategoryId = categoryId,
RetailPrice = retailPrice,
StockQuantity = stockQuantity
Name = name,
Category = category,
Price = price,
WarrantyMonths = warranty,
Flags = flags
};
}
}

View File

@@ -12,63 +12,213 @@
private void InitializeComponent()
{
this.labelNumber = new Label();
this.labelDate = new Label();
this.labelCost = new Label();
this.labelPrice = new Label();
this.labelStatus = new Label();
this.textBoxNumber = new TextBox();
this.dateTimePickerAssembly = new DateTimePicker();
this.numericCostPrice = new NumericUpDown();
this.numericSellingPrice = new NumericUpDown();
this.comboBoxStatus = new ComboBox();
this.buttonSave = new Button();
this.buttonCancel = new Button();
((System.ComponentModel.ISupportInitialize)(numericCostPrice)).BeginInit();
((System.ComponentModel.ISupportInitialize)(numericSellingPrice)).BeginInit();
this.SuspendLayout();
labelNumber.AutoSize = true; labelNumber.Location = new Point(30, 25); labelNumber.Text = "Номер сборки";
labelDate.AutoSize = true; labelDate.Location = new Point(30, 65); labelDate.Text = "Дата сборки";
labelCost.AutoSize = true; labelCost.Location = new Point(30, 105); labelCost.Text = "Себестоимость";
labelPrice.AutoSize = true; labelPrice.Location = new Point(30, 145); labelPrice.Text = "Цена продажи";
labelStatus.AutoSize = true; labelStatus.Location = new Point(30, 185); labelStatus.Text = "Статус";
textBoxNumber.Location = new Point(160, 22); textBoxNumber.Size = new Size(280, 23);
dateTimePickerAssembly.Location = new Point(160, 62); dateTimePickerAssembly.Size = new Size(280, 23); dateTimePickerAssembly.Format = DateTimePickerFormat.Short;
numericCostPrice.Location = new Point(160, 102); numericCostPrice.Size = new Size(120, 23); numericCostPrice.DecimalPlaces = 2; numericCostPrice.ThousandsSeparator = true;
numericSellingPrice.Location = new Point(160, 142); numericSellingPrice.Size = new Size(120, 23); numericSellingPrice.DecimalPlaces = 2; numericSellingPrice.ThousandsSeparator = true;
comboBoxStatus.Location = new Point(160, 182); comboBoxStatus.Size = new Size(280, 23);
buttonSave.Location = new Point(160, 240); buttonSave.Size = new Size(120, 40); buttonSave.Text = "Сохранить"; buttonSave.Click += buttonSave_Click;
buttonCancel.Location = new Point(300, 240); buttonCancel.Size = new Size(120, 40); buttonCancel.Text = "Отмена"; buttonCancel.Click += buttonCancel_Click;
this.ClientSize = new Size(480, 300);
this.Controls.AddRange(new Control[] {
labelNumber, labelDate, labelCost, labelPrice, labelStatus,
textBoxNumber, dateTimePickerAssembly, numericCostPrice, numericSellingPrice, comboBoxStatus,
buttonSave, buttonCancel
});
this.Text = "Сборка";
this.StartPosition = FormStartPosition.CenterParent;
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
((System.ComponentModel.ISupportInitialize)(numericCostPrice)).EndInit();
((System.ComponentModel.ISupportInitialize)(numericSellingPrice)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
labelNumber = new Label();
textBoxNumber = new TextBox();
labelDate = new Label();
dateTimePickerAssembly = new DateTimePicker();
labelCost = new Label();
numericCostPrice = new NumericUpDown();
labelPrice = new Label();
numericSellingPrice = new NumericUpDown();
labelStatus = new Label();
comboBoxStatus = new ComboBox();
groupBoxParts = new GroupBox();
dataGridViewParts = new DataGridView();
buttonSave = new Button();
buttonCancel = new Button();
partColumn = new DataGridViewComboBoxColumn();
qtyColumn = new DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)numericCostPrice).BeginInit();
((System.ComponentModel.ISupportInitialize)numericSellingPrice).BeginInit();
groupBoxParts.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewParts).BeginInit();
SuspendLayout();
//
// labelNumber
//
labelNumber.AutoSize = true;
labelNumber.Location = new Point(25, 20);
labelNumber.Name = "labelNumber";
labelNumber.Size = new Size(114, 20);
labelNumber.TabIndex = 0;
labelNumber.Text = "Номер сборки:";
//
// textBoxNumber
//
textBoxNumber.Location = new Point(149, 17);
textBoxNumber.Name = "textBoxNumber";
textBoxNumber.Size = new Size(220, 27);
textBoxNumber.TabIndex = 1;
//
// labelDate
//
labelDate.AutoSize = true;
labelDate.Location = new Point(380, 20);
labelDate.Name = "labelDate";
labelDate.Size = new Size(98, 20);
labelDate.TabIndex = 2;
labelDate.Text = "Дата сборки:";
//
// dateTimePickerAssembly
//
dateTimePickerAssembly.Format = DateTimePickerFormat.Short;
dateTimePickerAssembly.Location = new Point(535, 15);
dateTimePickerAssembly.Name = "dateTimePickerAssembly";
dateTimePickerAssembly.Size = new Size(150, 27);
dateTimePickerAssembly.TabIndex = 3;
//
// labelCost
//
labelCost.AutoSize = true;
labelCost.Location = new Point(25, 60);
labelCost.Name = "labelCost";
labelCost.Size = new Size(118, 20);
labelCost.TabIndex = 4;
labelCost.Text = "Себестоимость:";
//
// numericCostPrice
//
numericCostPrice.DecimalPlaces = 2;
numericCostPrice.Location = new Point(149, 58);
numericCostPrice.Name = "numericCostPrice";
numericCostPrice.Size = new Size(120, 27);
numericCostPrice.TabIndex = 5;
numericCostPrice.ThousandsSeparator = true;
//
// labelPrice
//
labelPrice.AutoSize = true;
labelPrice.Location = new Point(380, 60);
labelPrice.Name = "labelPrice";
labelPrice.Size = new Size(115, 20);
labelPrice.TabIndex = 6;
labelPrice.Text = "Цена продажи:";
//
// numericSellingPrice
//
numericSellingPrice.DecimalPlaces = 2;
numericSellingPrice.Location = new Point(535, 60);
numericSellingPrice.Name = "numericSellingPrice";
numericSellingPrice.Size = new Size(120, 27);
numericSellingPrice.TabIndex = 7;
numericSellingPrice.ThousandsSeparator = true;
//
// labelStatus
//
labelStatus.AutoSize = true;
labelStatus.Location = new Point(25, 100);
labelStatus.Name = "labelStatus";
labelStatus.Size = new Size(55, 20);
labelStatus.TabIndex = 8;
labelStatus.Text = "Статус:";
//
// comboBoxStatus
//
comboBoxStatus.Location = new Point(149, 97);
comboBoxStatus.Name = "comboBoxStatus";
comboBoxStatus.Size = new Size(220, 28);
comboBoxStatus.TabIndex = 9;
//
// groupBoxParts
//
groupBoxParts.Controls.Add(dataGridViewParts);
groupBoxParts.Location = new Point(229, 156);
groupBoxParts.Name = "groupBoxParts";
groupBoxParts.Size = new Size(319, 225);
groupBoxParts.TabIndex = 10;
groupBoxParts.TabStop = false;
groupBoxParts.Text = "Комплектующие в сборке";
//
// dataGridViewParts
//
dataGridViewParts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewParts.Columns.AddRange(new DataGridViewColumn[] { partColumn, qtyColumn });
dataGridViewParts.Dock = DockStyle.Fill;
dataGridViewParts.EditMode = DataGridViewEditMode.EditOnEnter;
dataGridViewParts.Location = new Point(3, 23);
dataGridViewParts.Name = "dataGridViewParts";
dataGridViewParts.RowHeadersWidth = 51;
dataGridViewParts.Size = new Size(313, 199);
dataGridViewParts.TabIndex = 0;
dataGridViewParts.DefaultValuesNeeded += dataGridViewParts_DefaultValuesNeeded;
//
// buttonSave
//
buttonSave.Location = new Point(149, 430);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(100, 35);
buttonSave.TabIndex = 11;
buttonSave.Text = "Сохранить";
buttonSave.Click += buttonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(504, 430);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(100, 35);
buttonCancel.TabIndex = 12;
buttonCancel.Text = "Отмена";
buttonCancel.Click += buttonCancel_Click;
//
// partColumn
//
partColumn.HeaderText = "Комплектующее";
partColumn.MinimumWidth = 6;
partColumn.Name = "partColumn";
partColumn.Width = 125;
//
// qtyColumn
//
qtyColumn.HeaderText = "Количество";
qtyColumn.MinimumWidth = 6;
qtyColumn.Name = "qtyColumn";
qtyColumn.Width = 125;
//
// FormAssembly
//
ClientSize = new Size(776, 505);
Controls.Add(labelNumber);
Controls.Add(textBoxNumber);
Controls.Add(labelDate);
Controls.Add(dateTimePickerAssembly);
Controls.Add(labelCost);
Controls.Add(numericCostPrice);
Controls.Add(labelPrice);
Controls.Add(numericSellingPrice);
Controls.Add(labelStatus);
Controls.Add(comboBoxStatus);
Controls.Add(groupBoxParts);
Controls.Add(buttonSave);
Controls.Add(buttonCancel);
FormBorderStyle = FormBorderStyle.FixedDialog;
MaximizeBox = false;
Name = "FormAssembly";
StartPosition = FormStartPosition.CenterParent;
Text = "Редактирование сборки";
Load += FormAssembly_Load;
((System.ComponentModel.ISupportInitialize)numericCostPrice).EndInit();
((System.ComponentModel.ISupportInitialize)numericSellingPrice).EndInit();
groupBoxParts.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewParts).EndInit();
ResumeLayout(false);
PerformLayout();
}
private Label labelNumber, labelDate, labelCost, labelPrice, labelStatus;
private Label labelNumber;
private TextBox textBoxNumber;
private Label labelDate;
private DateTimePicker dateTimePickerAssembly;
private NumericUpDown numericCostPrice, numericSellingPrice;
private Label labelCost;
private NumericUpDown numericCostPrice;
private Label labelPrice;
private NumericUpDown numericSellingPrice;
private Label labelStatus;
private ComboBox comboBoxStatus;
private Button buttonSave, buttonCancel;
private GroupBox groupBoxParts;
private DataGridView dataGridViewParts;
private Button buttonSave;
private Button buttonCancel;
private DataGridViewComboBoxColumn partColumn;
private DataGridViewTextBoxColumn qtyColumn;
}
}

View File

@@ -9,14 +9,15 @@ namespace ProjectComputerShop.Forms
{
public partial class FormAssembly : Form
{
private readonly IAssembliesRepository _repository;
private readonly IAssembliesRepository _assembliesRepository;
private readonly IPartsRepository _partsRepository;
private int? _assemblyId;
public int Id
{
set
{
var assembly = _repository.ReadAll().FirstOrDefault(a => a.Id == value);
var assembly = _assembliesRepository.ReadAll().FirstOrDefault(a => a.Id == value);
if (assembly == null) return;
textBoxNumber.Text = assembly.AssemblyNumber;
@@ -24,36 +25,53 @@ namespace ProjectComputerShop.Forms
numericCostPrice.Value = assembly.CostPrice;
numericSellingPrice.Value = assembly.SellingPrice;
comboBoxStatus.SelectedValue = assembly.Status;
_assemblyId = value;
}
}
public FormAssembly(IAssembliesRepository repository)
public FormAssembly(IAssembliesRepository assembliesRepository, IPartsRepository partsRepository)
{
InitializeComponent();
_repository = repository;
_assembliesRepository = assembliesRepository;
_partsRepository = partsRepository;
comboBoxStatus.DataSource = Enum.GetValues(typeof(AssemblyStatus));
comboBoxStatus.DropDownStyle = ComboBoxStyle.DropDownList;
dateTimePickerAssembly.Value = DateTime.Today;
}
private void FormAssembly_Load(object sender, EventArgs e)
{
var parts = _partsRepository.ReadAll().Select(p => p.Name).ToList();
((DataGridViewComboBoxColumn)dataGridViewParts.Columns["PartColumn"]).DataSource = parts;
}
private void dataGridViewParts_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
e.Row.Cells["QuantityColumn"].Value = 1;
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(textBoxNumber.Text))
{
MessageBox.Show("Введите номер сборки.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
var assembly = Assemblies.CreateEntity(
_assemblyId ?? 0,
textBoxNumber.Text.Trim(),
dateTimePickerAssembly.Value,
numericCostPrice.Value,
(AssemblyStatus)comboBoxStatus.SelectedValue!
id: _assemblyId ?? 0,
assemblyNumber: textBoxNumber.Text.Trim(),
assemblyDate: dateTimePickerAssembly.Value.Date,
costPrice: numericCostPrice.Value,
sellingPrice: numericSellingPrice.Value,
status: (AssemblyStatus)comboBoxStatus.SelectedValue
);
if (_assemblyId.HasValue)
_repository.Update(assembly);
_assembliesRepository.Update(assembly);
else
_repository.Create(assembly);
_assembliesRepository.Create(assembly);
DialogResult = DialogResult.OK;
Close();
@@ -64,5 +82,7 @@ namespace ProjectComputerShop.Forms
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@@ -2,149 +2,115 @@
{
partial class FormPart
{
private System.ComponentModel.IContainer components = null;
private System.ComponentModel.IContainer _components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
if (disposing && this._components != null) _components.Dispose();
base.Dispose(disposing);
}
private void InitializeComponent()
{
label1 = new Label();
label2 = new Label();
label4 = new Label();
label5 = new Label();
textBoxArticle = new TextBox();
_components = new System.ComponentModel.Container();
labelName = new Label();
textBoxName = new TextBox();
numericUpDownRetailPrice = new NumericUpDown();
numericUpDownStock = new NumericUpDown();
ButtonSave = new Button();
ButtonCancel = new Button();
((System.ComponentModel.ISupportInitialize)numericUpDownRetailPrice).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownStock).BeginInit();
labelCategory = new Label();
comboBoxCategory = new ComboBox();
labelPrice = new Label();
numericPrice = new NumericUpDown();
labelWarranty = new Label();
numericWarranty = new NumericUpDown();
groupBoxFlags = new GroupBox();
checkRGB = new CheckBox();
checkLiquid = new CheckBox();
checkOC = new CheckBox();
checkModular = new CheckBox();
checkNVMe = new CheckBox();
checkWiFi = new CheckBox();
checkBluetooth = new CheckBox();
checkTouch = new CheckBox();
checkBacklit = new CheckBox();
checkMechanical = new CheckBox();
buttonSave = new Button();
buttonCancel = new Button();
((System.ComponentModel.ISupportInitialize)numericPrice).BeginInit();
((System.ComponentModel.ISupportInitialize)numericWarranty).BeginInit();
groupBoxFlags.SuspendLayout();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(30, 20);
label1.Name = "label1";
label1.Size = new Size(65, 20);
label1.TabIndex = 0;
label1.Text = "Артикул";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(30, 60);
label2.Name = "label2";
label2.Size = new Size(116, 20);
label2.TabIndex = 1;
label2.Text = "Наименование";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(24, 108);
label4.Name = "label4";
label4.Size = new Size(122, 20);
label4.TabIndex = 3;
label4.Text = "Розничная цена";
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(30, 155);
label5.Name = "label5";
label5.Size = new Size(63, 20);
label5.TabIndex = 4;
label5.Text = "Остаток";
//
// textBoxArticle
//
textBoxArticle.Location = new Point(160, 17);
textBoxArticle.Name = "textBoxArticle";
textBoxArticle.Size = new Size(200, 27);
textBoxArticle.TabIndex = 5;
//
// textBoxName
//
textBoxName.Location = new Point(160, 57);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(300, 27);
textBoxName.TabIndex = 6;
//
// numericUpDownRetailPrice
//
numericUpDownRetailPrice.DecimalPlaces = 2;
numericUpDownRetailPrice.Location = new Point(160, 108);
numericUpDownRetailPrice.Name = "numericUpDownRetailPrice";
numericUpDownRetailPrice.Size = new Size(120, 27);
numericUpDownRetailPrice.TabIndex = 8;
//
// numericUpDownStock
//
numericUpDownStock.Location = new Point(160, 155);
numericUpDownStock.Name = "numericUpDownStock";
numericUpDownStock.Size = new Size(80, 27);
numericUpDownStock.TabIndex = 9;
//
// ButtonSave
//
ButtonSave.Location = new Point(61, 207);
ButtonSave.Name = "ButtonSave";
ButtonSave.Size = new Size(100, 30);
ButtonSave.TabIndex = 10;
ButtonSave.Text = "Сохранить";
ButtonSave.UseVisualStyleBackColor = true;
ButtonSave.Click += ButtonSave_Click;
//
// ButtonCancel
//
ButtonCancel.Location = new Point(274, 207);
ButtonCancel.Name = "ButtonCancel";
ButtonCancel.Size = new Size(100, 30);
ButtonCancel.TabIndex = 11;
ButtonCancel.Text = "Отмена";
ButtonCancel.UseVisualStyleBackColor = true;
ButtonCancel.Click += ButtonCancel_Click;
//
// FormPartEdit
//
ClientSize = new Size(474, 268);
Controls.Add(label1);
Controls.Add(label2);
Controls.Add(label4);
Controls.Add(label5);
Controls.Add(textBoxArticle);
Controls.Add(textBoxName);
Controls.Add(numericUpDownRetailPrice);
Controls.Add(numericUpDownStock);
Controls.Add(ButtonSave);
Controls.Add(ButtonCancel);
Name = "FormPartEdit";
labelName.Location = new Point(20, 20); labelName.Text = "Наименование:"; labelName.AutoSize = true;
textBoxName.Location = new Point(140, 17); textBoxName.Size = new Size(300, 23);
labelCategory.Location = new Point(20, 60); labelCategory.Text = "Категория:"; labelCategory.AutoSize = true;
comboBoxCategory.Location = new Point(140, 57); comboBoxCategory.Size = new Size(300, 23);
labelPrice.Location = new Point(20, 100); labelPrice.Text = "Цена:"; labelPrice.AutoSize = true;
numericPrice.Location = new Point(140, 97); numericPrice.Size = new Size(120, 23);
numericPrice.DecimalPlaces = 2; numericPrice.ThousandsSeparator = true;
labelWarranty.Location = new Point(280, 100); labelWarranty.Text = "Гарантия (мес):"; labelWarranty.AutoSize = true;
numericWarranty.Location = new Point(400, 97); numericWarranty.Size = new Size(80, 23);
numericWarranty.Maximum = 120;
groupBoxFlags.Text = "Дополнительные характеристики";
groupBoxFlags.Location = new Point(20, 140);
groupBoxFlags.Size = new Size(460, 180);
groupBoxFlags.Controls.AddRange(new Control[] {
checkRGB, checkLiquid, checkOC, checkModular, checkNVMe,
checkWiFi, checkBluetooth, checkTouch, checkBacklit, checkMechanical
});
int y = 20;
checkRGB.Text = "RGB-подсветка"; checkRGB.Location = new Point(10, y); y += 25;
checkLiquid.Text = "Жидкостное охлаждение"; checkLiquid.Location = new Point(10, y); y += 25;
checkOC.Text = "Поддержка разгона"; checkOC.Location = new Point(10, y); y += 25;
checkModular.Text = "Модульный"; checkModular.Location = new Point(10, y); y += 25;
checkNVMe.Text = "NVMe"; checkNVMe.Location = new Point(10, y); y += 25;
checkWiFi.Text = "Wi-Fi"; checkWiFi.Location = new Point(200, 20);
checkBluetooth.Text = "Bluetooth"; checkBluetooth.Location = new Point(200, 45);
checkTouch.Text = "Сенсорный экран"; checkTouch.Location = new Point(200, 70);
checkBacklit.Text = "Подсветка клавиатуры"; checkBacklit.Location = new Point(200, 95);
checkMechanical.Text = "Механическая клавиатура"; checkMechanical.Location = new Point(200, 120);
buttonSave.Location = new Point(240, 340); buttonSave.Size = new Size(100, 35); buttonSave.Text = "Сохранить";
buttonSave.Click += buttonSave_Click;
buttonCancel.Location = new Point(360, 340); buttonCancel.Size = new Size(100, 35); buttonCancel.Text = "Отмена";
buttonCancel.Click += buttonCancel_Click;
ClientSize = new Size(510, 390);
Controls.AddRange(new Control[] {
labelName, textBoxName, labelCategory, comboBoxCategory,
labelPrice, numericPrice, labelWarranty, numericWarranty,
groupBoxFlags, buttonSave, buttonCancel
});
Text = "Редактирование комплектующего";
StartPosition = FormStartPosition.CenterParent;
Text = "Комплектующее";
((System.ComponentModel.ISupportInitialize)numericUpDownRetailPrice).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownStock).EndInit();
FormBorderStyle = FormBorderStyle.FixedDialog;
MaximizeBox = false;
((System.ComponentModel.ISupportInitialize)numericPrice).EndInit();
((System.ComponentModel.ISupportInitialize)numericWarranty).EndInit();
groupBoxFlags.ResumeLayout(false);
ResumeLayout(false);
PerformLayout();
}
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBoxArticle;
private System.Windows.Forms.TextBox textBoxName;
private System.Windows.Forms.NumericUpDown numericUpDownRetailPrice;
private System.Windows.Forms.NumericUpDown numericUpDownStock;
private System.Windows.Forms.Button ButtonSave;
private System.Windows.Forms.Button ButtonCancel;
private Label labelName, labelCategory, labelPrice, labelWarranty;
private TextBox textBoxName;
private ComboBox comboBoxCategory;
private NumericUpDown numericPrice, numericWarranty;
private GroupBox groupBoxFlags;
private CheckBox checkRGB, checkLiquid, checkOC, checkModular, checkNVMe;
private CheckBox checkWiFi, checkBluetooth, checkTouch, checkBacklit, checkMechanical;
private Button buttonSave, buttonCancel;
}
}

View File

@@ -1,78 +1,91 @@
using System;
using System.Windows.Forms;
using ComputerShop.Entities;
using ComputerShop.Enums;
using ComputerShop.Repositories;
namespace ProjectComputerShop.Forms
{
public partial class FormPart : Form
{
private readonly IPartsRepository _partsRepository;
private readonly IPartsRepository _repository;
private int? _partId;
public int Id
{
set
{
try
{
var part = _partsRepository.ReadById(value);
if (part == null) throw new Exception("Комплектующее не найдено");
var part = _repository.ReadAll().FirstOrDefault(p => p.Id == value);
if (part == null) return;
textBoxArticle.Text = part.Article;
textBoxName.Text = part.PartName;
numericUpDownRetailPrice.Value = part.RetailPrice;
numericUpDownStock.Value = part.StockQuantity;
textBoxName.Text = part.Name;
;
comboBoxCategory.SelectedItem = part.Category;
numericPrice.Value = part.Price;
numericWarranty.Value = part.WarrantyMonths;
_partId = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
checkRGB.Checked = (part.Flags & PartFlags.RGB) != 0;
checkLiquid.Checked = (part.Flags & PartFlags.LiquidCooling) != 0;
checkOC.Checked = (part.Flags & PartFlags.Overclockable) != 0;
checkModular.Checked = (part.Flags & PartFlags.Modular) != 0;
checkNVMe.Checked = (part.Flags & PartFlags.NVMe) != 0;
checkWiFi.Checked = (part.Flags & PartFlags.WiFi) != 0;
checkBluetooth.Checked = (part.Flags & PartFlags.Bluetooth) != 0;
checkTouch.Checked = (part.Flags & PartFlags.TouchScreen) != 0;
checkBacklit.Checked = (part.Flags & PartFlags.BacklitKeyboard) != 0;
checkMechanical.Checked = (part.Flags & PartFlags.MechanicalKeyboard) != 0;
_partId = value;
}
}
public FormPart(IPartsRepository partsRepository)
public FormPart(IPartsRepository repository)
{
InitializeComponent();
_partsRepository = partsRepository ?? throw new ArgumentNullException(nameof(partsRepository));
_repository = repository;
comboBoxCategory.DataSource = Enum.GetValues(typeof(CategoryName));
comboBoxCategory.DropDownStyle = ComboBoxStyle.DropDownList;
}
private void ButtonSave_Click(object sender, EventArgs e)
private void buttonSave_Click(object sender, EventArgs e)
{
try
if (string.IsNullOrWhiteSpace(textBoxName.Text))
{
if (string.IsNullOrWhiteSpace(textBoxArticle.Text) ||
string.IsNullOrWhiteSpace(textBoxName.Text))
{
throw new Exception("Заполните Артикул и Наименование");
}
var part = Parts.CreateEntity(
_partId ?? 0,
textBoxArticle.Text.Trim(),
textBoxName.Text.Trim(),
0,
numericUpDownRetailPrice.Value,
(int)numericUpDownStock.Value
);
if (_partId.HasValue)
_partsRepository.Update(part);
else
_partsRepository.Create(part);
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Введите наименование!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
PartFlags flags = PartFlags.None;
if (checkRGB.Checked) flags |= PartFlags.RGB;
if (checkLiquid.Checked) flags |= PartFlags.LiquidCooling;
if (checkOC.Checked) flags |= PartFlags.Overclockable;
if (checkModular.Checked) flags |= PartFlags.Modular;
if (checkNVMe.Checked) flags |= PartFlags.NVMe;
if (checkWiFi.Checked) flags |= PartFlags.WiFi;
if (checkBluetooth.Checked) flags |= PartFlags.Bluetooth;
if (checkTouch.Checked) flags |= PartFlags.TouchScreen;
if (checkBacklit.Checked) flags |= PartFlags.BacklitKeyboard;
if (checkMechanical.Checked) flags |= PartFlags.MechanicalKeyboard;
var part = Part.CreateEntity(
id: _partId ?? 0,
name: textBoxName.Text.Trim(),
category: (CategoryName)comboBoxCategory.SelectedValue,
price: numericPrice.Value,
warranty: (int)numericWarranty.Value,
flags: flags
);
if (_partId.HasValue)
_repository.Update(part);
else
_repository.Create(part);
DialogResult = DialogResult.OK;
Close();
}
private void ButtonCancel_Click(object sender, EventArgs e)
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}

View File

@@ -1,12 +1,13 @@
using ComputerShop.Entities;
namespace ComputerShop.Repositories;
public interface IPartsRepository
namespace ComputerShop.Repositories
{
IEnumerable<Parts> ReadAll();
Parts ReadById(int id);
void Create(Parts part);
void Update(Parts part);
void Delete(int id);
public interface IPartsRepository
{
IEnumerable<Part> ReadAll();
Part? ReadById(int id);
void Create(Part part);
void Update(Part part);
void Delete(int id);
}
}

View File

@@ -13,7 +13,7 @@ public class AssembliesRepository : IAssembliesRepository
public Assemblies ReadById(int id)
{
return Assemblies.CreateEntity(0, string.Empty, DateTime.MinValue, 0m, AssemblyStatus.InProgress);
return Assemblies.CreateEntity(0, string.Empty, DateTime.MinValue, 0m,AssemblyStatus.InProgress,0);
}
public void Create(Assemblies assembly)

View File

@@ -1,29 +1,31 @@
using ComputerShop.Entities;
using ComputerShop.Enums;
using ComputerShop.Repositories;
namespace ComputerShop.Implementations;
public class PartsRepository : IPartsRepository
namespace ComputerShop.Implementations
{
public IEnumerable<Parts> ReadAll()
public class PartsRepository : IPartsRepository
{
return [];
}
public IEnumerable<Part> ReadAll()
{
return [];
}
public Parts ReadById(int id)
{
return Parts.CreateEntity(0, string.Empty, string.Empty, 0, 0m,0);
}
public Part? ReadById(int id)
{
return null;
}
public void Create(Parts part)
{
}
public void Create(Part part)
{
}
public void Update(Parts part)
{
}
public void Update(Part part)
{
}
public void Delete(int id)
{
public void Delete(int id)
{
}
}
}