готовы формы Purchase и Purchases

This commit is contained in:
Alkin Ivan 2024-12-10 13:59:36 +04:00
parent 4d25400ec6
commit e8ad22da86
6 changed files with 212 additions and 86 deletions

View File

@ -80,9 +80,9 @@ namespace ProjectGasStation.Forms
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private void buttonCancel_Click(object sender, EventArgs e) => Close();
private Purchase CreatePurchase(int id) => Purchase.CreateOperation(id, comboBoxProduct.SelectedIndex, comboBoxSupplier.SelectedIndex, Convert.ToDateTime(dateTimePicker1), n);
private Purchase CreatePurchase(int id) => Purchase.CreateOperation(id, comboBoxProduct.SelectedIndex, comboBoxSupplier.SelectedIndex, (double)numericUpDown2.Value, Convert.ToDateTime(dateTimePicker1), (double)numericUpDown1.Value);
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{

View File

@ -0,0 +1,101 @@
namespace ProjectGasStation.Forms
{
partial class FormPurchases
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
dataGridView1 = new DataGridView();
panel1 = new Panel();
buttonUpdate = new Button();
buttonAdd = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
panel1.SuspendLayout();
SuspendLayout();
//
// dataGridView1
//
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView1.Dock = DockStyle.Fill;
dataGridView1.Location = new Point(0, 0);
dataGridView1.Name = "dataGridView1";
dataGridView1.RowHeadersWidth = 45;
dataGridView1.Size = new Size(800, 450);
dataGridView1.TabIndex = 0;
//
// panel1
//
panel1.Controls.Add(buttonUpdate);
panel1.Controls.Add(buttonAdd);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(647, 0);
panel1.Name = "panel1";
panel1.Size = new Size(153, 450);
panel1.TabIndex = 1;
//
// buttonUpdate
//
buttonUpdate.BackgroundImage = Properties.Resources.edit;
buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpdate.Location = new Point(32, 269);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(83, 75);
buttonUpdate.TabIndex = 1;
buttonUpdate.UseVisualStyleBackColor = true;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources.plus1;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(32, 84);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(83, 75);
buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += this.buttonAdd_Click;
//
// FormPurchases
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(panel1);
Controls.Add(dataGridView1);
Name = "FormPurchases";
Text = "FormPurchase";
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
panel1.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView1;
private Panel panel1;
private Button buttonUpdate;
private Button buttonAdd;
}
}

View File

@ -0,0 +1,84 @@
using ProjectGasStation.Repositories;
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;
using Unity;
namespace ProjectGasStation.Forms;
public partial class FormPurchases : Form
{
private readonly IUnityContainer _container;
private readonly IPurchaseRepository _purchaseRepository;
public FormPurchases(IUnityContainer container, IPurchaseRepository purchaseRepository)
{
InitializeComponent();
_container = container ?? throw new ArgumentNullException(nameof(container));
_purchaseRepository = purchaseRepository ?? throw new ArgumentNullException(nameof(_purchaseRepository));
}
private void FormPurchases_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
{
_container.Resolve<FormPurchase>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
try
{
var form = _container.Resolve<FormPurchase>();
form.Id = findId;
form.ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridView1.DataSource = _purchaseRepository.ReadPurchases();
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridView1.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value);
return true;
}
}

View File

@ -1,39 +0,0 @@
namespace ProjectGasStation.Forms
{
partial class FormPurchasess
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "FormPurchase";
}
#endregion
}
}

View File

@ -1,20 +0,0 @@
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 ProjectGasStation.Forms
{
public partial class FormPurchasess : Form
{
public FormPurchasess()
{
InitializeComponent();
}
}
}