This commit is contained in:
Олег Кудринский 2024-11-22 13:47:41 +04:00
parent 746109f7a7
commit 336ff04b4c
9 changed files with 134 additions and 84 deletions

View File

@ -27,6 +27,18 @@ namespace ProjectWorkshop.Forms
throw new ArgumentNullException(nameof(assemblyRepository));
}
private void FormAssemblies_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
@ -83,10 +95,7 @@ namespace ProjectWorkshop.Forms
}
private void FormAssemblies_Load(object sender, EventArgs e)
{
}
private void LoadList() => dataGridView.DataSource = _assemblyRepository.ReadAssemblies();

View File

@ -30,15 +30,13 @@
{
labelWorkHours = new Label();
numericUpDownWorkHours = new NumericUpDown();
groupBox = new GroupBox();
dataGridViewAssemblerShift = new DataGridView();
ColumnAssembler = new DataGridViewComboBoxColumn();
ColumnShift = new DataGridViewComboBoxColumn();
buttonSave = new Button();
buttonCancel = new Button();
comboBoxAssembler = new ComboBox();
comboBoxShift = new ComboBox();
labelAssembler = new Label();
labelShift = new Label();
((System.ComponentModel.ISupportInitialize)numericUpDownWorkHours).BeginInit();
groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewAssemblerShift).BeginInit();
SuspendLayout();
//
// labelWorkHours
@ -52,52 +50,15 @@
//
// numericUpDownWorkHours
//
numericUpDownWorkHours.Location = new Point(198, 31);
numericUpDownWorkHours.Location = new Point(190, 31);
numericUpDownWorkHours.Name = "numericUpDownWorkHours";
numericUpDownWorkHours.Size = new Size(113, 23);
numericUpDownWorkHours.Size = new Size(121, 23);
numericUpDownWorkHours.TabIndex = 1;
//
// groupBox
//
groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
groupBox.Controls.Add(dataGridViewAssemblerShift);
groupBox.Location = new Point(35, 78);
groupBox.Name = "groupBox";
groupBox.Size = new Size(280, 328);
groupBox.TabIndex = 3;
groupBox.TabStop = false;
groupBox.Text = "groupBox1";
//
// dataGridViewAssemblerShift
//
dataGridViewAssemblerShift.AllowUserToResizeColumns = false;
dataGridViewAssemblerShift.AllowUserToResizeRows = false;
dataGridViewAssemblerShift.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewAssemblerShift.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewAssemblerShift.Columns.AddRange(new DataGridViewColumn[] { ColumnAssembler, ColumnShift });
dataGridViewAssemblerShift.Dock = DockStyle.Fill;
dataGridViewAssemblerShift.Location = new Point(3, 19);
dataGridViewAssemblerShift.Name = "dataGridViewAssemblerShift";
dataGridViewAssemblerShift.RowHeadersVisible = false;
dataGridViewAssemblerShift.Size = new Size(274, 306);
dataGridViewAssemblerShift.TabIndex = 3;
//
// ColumnAssembler
//
ColumnAssembler.HeaderText = "Сборщик";
ColumnAssembler.Name = "ColumnAssembler";
//
// ColumnShift
//
ColumnShift.HeaderText = "Смена";
ColumnShift.Name = "ColumnShift";
ColumnShift.Resizable = DataGridViewTriState.True;
ColumnShift.SortMode = DataGridViewColumnSortMode.Automatic;
//
// buttonSave
//
buttonSave.Anchor = AnchorStyles.Bottom;
buttonSave.Location = new Point(53, 431);
buttonSave.Location = new Point(53, 216);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(75, 23);
buttonSave.TabIndex = 4;
@ -108,7 +69,7 @@
// buttonCancel
//
buttonCancel.Anchor = AnchorStyles.Bottom;
buttonCancel.Location = new Point(220, 431);
buttonCancel.Location = new Point(220, 216);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 5;
@ -116,21 +77,56 @@
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// comboBoxAssembler
//
comboBoxAssembler.FormattingEnabled = true;
comboBoxAssembler.Location = new Point(190, 92);
comboBoxAssembler.Name = "comboBoxAssembler";
comboBoxAssembler.Size = new Size(121, 23);
comboBoxAssembler.TabIndex = 6;
//
// comboBoxShift
//
comboBoxShift.FormattingEnabled = true;
comboBoxShift.Location = new Point(190, 157);
comboBoxShift.Name = "comboBoxShift";
comboBoxShift.Size = new Size(121, 23);
comboBoxShift.TabIndex = 7;
//
// labelAssembler
//
labelAssembler.AutoSize = true;
labelAssembler.Location = new Point(53, 95);
labelAssembler.Name = "labelAssembler";
labelAssembler.Size = new Size(63, 15);
labelAssembler.TabIndex = 8;
labelAssembler.Text = "Сборщик:";
//
// labelShift
//
labelShift.AutoSize = true;
labelShift.Location = new Point(70, 165);
labelShift.Name = "labelShift";
labelShift.Size = new Size(46, 15);
labelShift.TabIndex = 9;
labelShift.Text = "Смена:";
//
// FormAssesmblerShift
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(355, 466);
ClientSize = new Size(355, 251);
Controls.Add(labelShift);
Controls.Add(labelAssembler);
Controls.Add(comboBoxShift);
Controls.Add(comboBoxAssembler);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(groupBox);
Controls.Add(numericUpDownWorkHours);
Controls.Add(labelWorkHours);
Name = "FormAssesmblerShift";
Text = "Смена сборщика";
Text = "Выход на смену";
((System.ComponentModel.ISupportInitialize)numericUpDownWorkHours).EndInit();
groupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewAssemblerShift).EndInit();
ResumeLayout(false);
PerformLayout();
}
@ -139,11 +135,11 @@
private Label labelWorkHours;
private NumericUpDown numericUpDownWorkHours;
private GroupBox groupBox;
private DataGridView dataGridViewAssemblerShift;
private DataGridViewComboBoxColumn ColumnAssembler;
private DataGridViewComboBoxColumn ColumnShift;
private Button buttonSave;
private Button buttonCancel;
private ComboBox comboBoxAssembler;
private ComboBox comboBoxShift;
private Label labelAssembler;
private Label labelShift;
}
}

View File

@ -25,25 +25,25 @@ namespace ProjectWorkshop.Forms
numericUpDownWorkHours.Value = 1;
ColumnAssembler.DataSource = assemblerRepository.ReadAssemblers();
ColumnAssembler.DisplayMember = "FullName";
ColumnAssembler.ValueMember = "Id";
comboBoxAssembler.DataSource = assemblerRepository.ReadAssemblers();
comboBoxAssembler.DisplayMember = "FullName";
comboBoxAssembler.ValueMember = "Id";
ColumnShift.DataSource = shiftRepository.ReadShifts();
ColumnShift.DisplayMember = "Id";
ColumnShift.ValueMember = "Id";
comboBoxShift.DataSource = shiftRepository.ReadShifts();
comboBoxShift.DisplayMember = "Id";
comboBoxShift.ValueMember = "Id";
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (numericUpDownWorkHours.Value < 1 || dataGridViewAssemblerShift.RowCount < 1)
if (numericUpDownWorkHours.Value < 1 || comboBoxAssembler.SelectedIndex < 0 || comboBoxShift.SelectedIndex < 0)
{
throw new Exception("Имеются незаполненные поля");
}
_assemblerShiftRepository.CreateAssemblerShift(AssemblerShift.CreateOperation((int)numericUpDownWorkHours.Value,
Convert.ToInt32(ColumnAssembler.ValueMember), Convert.ToInt32(ColumnShift.ValueMember)));
(int)comboBoxAssembler.SelectedValue!, (int)comboBoxShift.SelectedValue!));
Close();
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
@ -117,16 +117,4 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ColumnAssembler.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnShift.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnAssembler.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnShift.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -31,6 +31,7 @@
buttonAdd = new Button();
dataGridView = new DataGridView();
panel1 = new Panel();
buttonDel = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
panel1.SuspendLayout();
SuspendLayout();
@ -66,6 +67,7 @@
//
// panel1
//
panel1.Controls.Add(buttonDel);
panel1.Controls.Add(buttonAdd);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(647, 0);
@ -73,6 +75,17 @@
panel1.Size = new Size(153, 450);
panel1.TabIndex = 2;
//
// buttonDel
//
buttonDel.BackgroundImage = Properties.Resources.minus;
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
buttonDel.Location = new Point(28, 164);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(100, 86);
buttonDel.TabIndex = 1;
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// FormProductAssemblies
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -93,5 +106,6 @@
private Button buttonAdd;
private DataGridView dataGridView;
private Panel panel1;
private Button buttonDel;
}
}

View File

@ -39,6 +39,29 @@ namespace ProjectWorkshop.Forms
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
if (MessageBox.Show("Удалить запись?", "Удаление",
MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
try
{
_productAssemblyRepository.DeleteProductAssembly(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridView.DataSource = _productAssemblyRepository.ReadProductAssembly();
private void FormProductAssemblies_Load(object sender, EventArgs e)
@ -52,5 +75,18 @@ namespace ProjectWorkshop.Forms
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridView.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
return true;
}
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter

View File

@ -12,4 +12,6 @@ public interface IProductAssemblyRepository
IEnumerable<ProductAssembly> ReadProductAssembly(int? productID = null, int? assemblyID = null, int? count = null);
void CreateProductAssembly(ProductAssembly productAssembly);
void DeleteProductAssembly(int id);
}

View File

@ -13,6 +13,11 @@ public class ProductAssemblyRepository : IProductAssemblyRepository
{
}
public void DeleteProductAssembly(int id)
{
throw new NotImplementedException();
}
public IEnumerable<ProductAssembly> ReadProductAssembly(int? productID = null, int? assemblyID = null, int? count = null)
{
return [];