diff --git a/BeautySalon/BeautySalon/FormCheque.Designer.cs b/BeautySalon/BeautySalon/FormCheque.Designer.cs deleted file mode 100644 index c387ea9..0000000 --- a/BeautySalon/BeautySalon/FormCheque.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace BeautySalon -{ - partial class FormCheque - { - /// - /// 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 = "FormCheque"; - } - - #endregion - } -} \ No newline at end of file diff --git a/BeautySalon/BeautySalon/FormCheque.cs b/BeautySalon/BeautySalon/FormCheque.cs deleted file mode 100644 index 6df8804..0000000 --- a/BeautySalon/BeautySalon/FormCheque.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 BeautySalon -{ - public partial class FormCheque : Form - { - public FormCheque() - { - InitializeComponent(); - } - } -} diff --git a/BeautySalon/BeautySalon/FormCheque.resx b/BeautySalon/BeautySalon/FormCheque.resx deleted file mode 100644 index 1af7de1..0000000 --- a/BeautySalon/BeautySalon/FormCheque.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/BeautySalon/BeautySalon/FormCheques.Designer.cs b/BeautySalon/BeautySalon/FormCheques.Designer.cs index dc290cf..84ec7cb 100644 --- a/BeautySalon/BeautySalon/FormCheques.Designer.cs +++ b/BeautySalon/BeautySalon/FormCheques.Designer.cs @@ -28,12 +28,52 @@ /// 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 = "FormCheques"; + buttonDelete = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonDelete + // + buttonDelete.Location = new Point(583, 199); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(147, 56); + buttonDelete.TabIndex = 13; + buttonDelete.Text = "Уничтожить..."; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // dataGridView + // + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.BackgroundColor = SystemColors.ActiveCaption; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(493, 450); + dataGridView.TabIndex = 10; + // + // FormCheques + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonDelete); + Controls.Add(dataGridView); + Name = "FormCheques"; + Text = "Чеки"; + Load += FormCheques_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); } #endregion + + private Button buttonDelete; + private DataGridView dataGridView; } } \ No newline at end of file diff --git a/BeautySalon/BeautySalon/FormCheques.cs b/BeautySalon/BeautySalon/FormCheques.cs index 8f9fa48..0efaf57 100644 --- a/BeautySalon/BeautySalon/FormCheques.cs +++ b/BeautySalon/BeautySalon/FormCheques.cs @@ -1,20 +1,80 @@ -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 BeautySalonDBModels; +using BeautySalonDBModels.Implements; +using BeautySalonDBModels.Models; namespace BeautySalon { public partial class FormCheques : Form { - public FormCheques() + + private int? _id; + public int Id { + set { _id = value; } + } + + private readonly AbstractWorkWithStorage chequeStorage; + private readonly AbstractWorkWithStorage clientStorage; + private readonly AbstractWorkWithStorage serviceStorage; + + public FormCheques(AbstractWorkWithStorage chequeStorage, + AbstractWorkWithStorage clientStorage, + AbstractWorkWithStorage serviceStorage) + { + this.chequeStorage = chequeStorage; InitializeComponent(); + this.clientStorage = clientStorage; + this.serviceStorage = serviceStorage; + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ChequeId"].Value); + chequeStorage.Remove(id); + LoadData(); + } + } + + private void FormCheques_Load(object sender, EventArgs e) + { + LoadData(); + } + + public void LoadData() + { + /* var list = chequeStorage.GetObjects(); + if(list != null) + { + dataGridView.DataSource = list; + }*/ + + List cheques = chequeStorage.GetObjects(); + ChequeDatabase cdb = new ChequeDatabase(); + MasterDatabase mdb = new MasterDatabase(); + + dataGridView.Rows.Clear(); + + if (dataGridView.ColumnCount == 0) + { + dataGridView.Columns.Add("ChequeId", "ID"); + dataGridView.Columns.Add("ClientFIO", "ФИО клиента"); + dataGridView.Columns.Add("ServiceName", "Название"); + dataGridView.Columns.Add("Price", "Цена"); + } + + foreach (Cheque cheque in cheques) + { + string serviceName = + } + + foreach (Service service in services) + { + string specialisationName = mdb.GetNameSpecialisation(service); + dataGridView.Rows.Add(service.ServiceId, service.ServiceName, specialisationName, service.Price); + } + dataGridView.Columns["ChequeId"].Visible = false; } } } diff --git a/BeautySalon/BeautySalon/FormCheques.resx b/BeautySalon/BeautySalon/FormCheques.resx index 1af7de1..af32865 100644 --- a/BeautySalon/BeautySalon/FormCheques.resx +++ b/BeautySalon/BeautySalon/FormCheques.resx @@ -1,17 +1,17 @@  - diff --git a/BeautySalon/BeautySalonDBModels/Implements/ChequeDatabase.cs b/BeautySalon/BeautySalonDBModels/Implements/ChequeDatabase.cs index ee0e381..f8cb881 100644 --- a/BeautySalon/BeautySalonDBModels/Implements/ChequeDatabase.cs +++ b/BeautySalon/BeautySalonDBModels/Implements/ChequeDatabase.cs @@ -14,9 +14,11 @@ namespace BeautySalonDBModels.Implements { using var conn = GetConnection(); conn.Open(); - using var cmd = new NpgsqlCommand("INSERT INTO cheques (cheque_id, client_id, reception_id) VALUES ((nextval('seq_cheque')), @ClientId, @ReceptionId)", conn); + using var cmd = new NpgsqlCommand("INSERT INTO cheques (cheque_id, client_id, reception_id, price)" + + " VALUES ((nextval('seq_cheque')), @ClientId, @ReceptionId. @Price)", conn); cmd.Parameters.AddWithValue("@ClientId", cheque.ClientId); cmd.Parameters.AddWithValue("@ReceptionId", cheque.ReceptionId); + cmd.Parameters.AddWithValue("@Price", cheque.Price); cmd.ExecuteNonQuery(); } @@ -33,7 +35,8 @@ namespace BeautySalonDBModels.Implements { ChequeId = reader.GetInt32(0), ClientId = reader.GetInt32(1), - ReceptionId = reader.GetInt32(2) + ReceptionId = reader.GetInt32(2), + Price = reader.GetDouble(3) }; } return null; @@ -52,7 +55,8 @@ namespace BeautySalonDBModels.Implements { ChequeId = reader.GetInt32(0), ClientId = reader.GetInt32(1), - ReceptionId = reader.GetInt32(2) + ReceptionId = reader.GetInt32(2), + Price = reader.GetDouble(3) }); } return cheques; @@ -73,11 +77,12 @@ namespace BeautySalonDBModels.Implements { using var conn = GetConnection(); conn.Open(); - using var cmd = new NpgsqlCommand("update cheque set client_id = @ClientId, " + - "reception_id = @ReceptionId where cheque_id = @ChequeId", conn); + using var cmd = new NpgsqlCommand("update cheques set client_id = @ClientId, " + + "reception_id = @ReceptionId, price = @Price where cheque_id = @ChequeId", conn); cmd.Parameters.AddWithValue("@ClientId", cheque.ClientId); cmd.Parameters.AddWithValue("@ReceptionId", cheque.ReceptionId); cmd.Parameters.AddWithValue("@ChequeId", cheque.ChequeId); + cmd.Parameters.AddWithValue("@Price", cheque.Price); cmd.ExecuteNonQuery(); } } diff --git a/BeautySalon/BeautySalonDBModels/Models/Cheque.cs b/BeautySalon/BeautySalonDBModels/Models/Cheque.cs index 052dc98..9b7bebd 100644 --- a/BeautySalon/BeautySalonDBModels/Models/Cheque.cs +++ b/BeautySalon/BeautySalonDBModels/Models/Cheque.cs @@ -5,5 +5,6 @@ public int ChequeId { get; set; } public int ClientId { get; set; } public int ReceptionId { get; set; } + public double Price { get; set; } } }