diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormPurchase.cs b/ProjectGasStation/ProjectGasStation/Forms/FormPurchase.cs index fd29b62..1be10b9 100644 --- a/ProjectGasStation/ProjectGasStation/Forms/FormPurchase.cs +++ b/ProjectGasStation/ProjectGasStation/Forms/FormPurchase.cs @@ -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) { diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.Designer.cs b/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.Designer.cs new file mode 100644 index 0000000..a646abe --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.Designer.cs @@ -0,0 +1,101 @@ +namespace ProjectGasStation.Forms +{ + partial class FormPurchases + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.cs b/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.cs new file mode 100644 index 0000000..1b96e0b --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.cs @@ -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().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(); + 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; + } +} + diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormPurchasess.resx b/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.resx similarity index 93% rename from ProjectGasStation/ProjectGasStation/Forms/FormPurchasess.resx rename to ProjectGasStation/ProjectGasStation/Forms/FormPurchases.resx index 1af7de1..af32865 100644 --- a/ProjectGasStation/ProjectGasStation/Forms/FormPurchasess.resx +++ b/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.resx @@ -1,17 +1,17 @@  - diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormPurchasess.Designer.cs b/ProjectGasStation/ProjectGasStation/Forms/FormPurchasess.Designer.cs deleted file mode 100644 index a2f9b10..0000000 --- a/ProjectGasStation/ProjectGasStation/Forms/FormPurchasess.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ProjectGasStation.Forms -{ - partial class FormPurchasess - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - 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 - } -} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormPurchasess.cs b/ProjectGasStation/ProjectGasStation/Forms/FormPurchasess.cs deleted file mode 100644 index c28c482..0000000 --- a/ProjectGasStation/ProjectGasStation/Forms/FormPurchasess.cs +++ /dev/null @@ -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(); - } - } -}