Your Name 2 年 前
コミット
da89d57287

+ 9 - 8
СУБД Книжный клуб/FormMain.Designer.cs

@@ -29,7 +29,7 @@
         private void InitializeComponent()
         private void InitializeComponent()
         {
         {
             this.components = new System.ComponentModel.Container();
             this.components = new System.ComponentModel.Container();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
             this.panel1 = new System.Windows.Forms.Panel();
             this.panel1 = new System.Windows.Forms.Panel();
             this.label1 = new System.Windows.Forms.Label();
             this.label1 = new System.Windows.Forms.Label();
             this.pictureBox1 = new System.Windows.Forms.PictureBox();
             this.pictureBox1 = new System.Windows.Forms.PictureBox();
@@ -63,7 +63,7 @@
             this.panel1.Location = new System.Drawing.Point(0, 0);
             this.panel1.Location = new System.Drawing.Point(0, 0);
             this.panel1.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
             this.panel1.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
             this.panel1.Name = "panel1";
             this.panel1.Name = "panel1";
-            this.panel1.Size = new System.Drawing.Size(855, 113);
+            this.panel1.Size = new System.Drawing.Size(855, 61);
             this.panel1.TabIndex = 0;
             this.panel1.TabIndex = 0;
             // 
             // 
             // label1
             // label1
@@ -71,7 +71,7 @@
             this.label1.Anchor = System.Windows.Forms.AnchorStyles.Top;
             this.label1.Anchor = System.Windows.Forms.AnchorStyles.Top;
             this.label1.AutoSize = true;
             this.label1.AutoSize = true;
             this.label1.Font = new System.Drawing.Font("Century", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
             this.label1.Font = new System.Drawing.Font("Century", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
-            this.label1.Location = new System.Drawing.Point(319, 42);
+            this.label1.Location = new System.Drawing.Point(318, 9);
             this.label1.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
             this.label1.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
             this.label1.Name = "label1";
             this.label1.Name = "label1";
             this.label1.Size = new System.Drawing.Size(234, 34);
             this.label1.Size = new System.Drawing.Size(234, 34);
@@ -85,7 +85,7 @@
             this.pictureBox1.Location = new System.Drawing.Point(735, 0);
             this.pictureBox1.Location = new System.Drawing.Point(735, 0);
             this.pictureBox1.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
             this.pictureBox1.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
             this.pictureBox1.Name = "pictureBox1";
             this.pictureBox1.Name = "pictureBox1";
-            this.pictureBox1.Size = new System.Drawing.Size(120, 113);
+            this.pictureBox1.Size = new System.Drawing.Size(120, 61);
             this.pictureBox1.TabIndex = 0;
             this.pictureBox1.TabIndex = 0;
             this.pictureBox1.TabStop = false;
             this.pictureBox1.TabStop = false;
             // 
             // 
@@ -109,13 +109,14 @@
             this.Column6,
             this.Column6,
             this.Column7});
             this.Column7});
             this.DgvProductList.ContextMenuStrip = this.contextMenuStrip1;
             this.DgvProductList.ContextMenuStrip = this.contextMenuStrip1;
-            this.DgvProductList.Location = new System.Drawing.Point(12, 121);
+            this.DgvProductList.Location = new System.Drawing.Point(12, 69);
+            this.DgvProductList.MultiSelect = false;
             this.DgvProductList.Name = "DgvProductList";
             this.DgvProductList.Name = "DgvProductList";
             this.DgvProductList.ReadOnly = true;
             this.DgvProductList.ReadOnly = true;
             this.DgvProductList.RowHeadersVisible = false;
             this.DgvProductList.RowHeadersVisible = false;
             this.DgvProductList.RowTemplate.Height = 100;
             this.DgvProductList.RowTemplate.Height = 100;
             this.DgvProductList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
             this.DgvProductList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
-            this.DgvProductList.Size = new System.Drawing.Size(831, 344);
+            this.DgvProductList.Size = new System.Drawing.Size(831, 396);
             this.DgvProductList.TabIndex = 1;
             this.DgvProductList.TabIndex = 1;
             this.DgvProductList.CellMouseDown += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DgvProductList_CellMouseDown);
             this.DgvProductList.CellMouseDown += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DgvProductList_CellMouseDown);
             // 
             // 
@@ -138,8 +139,8 @@
             // Column3
             // Column3
             // 
             // 
             this.Column3.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
             this.Column3.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
-            dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
-            this.Column3.DefaultCellStyle = dataGridViewCellStyle4;
+            dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+            this.Column3.DefaultCellStyle = dataGridViewCellStyle2;
             this.Column3.HeaderText = "Info";
             this.Column3.HeaderText = "Info";
             this.Column3.Name = "Column3";
             this.Column3.Name = "Column3";
             this.Column3.ReadOnly = true;
             this.Column3.ReadOnly = true;

+ 12 - 6
СУБД Книжный клуб/FormMain.cs

@@ -24,14 +24,14 @@ namespace СУБД_Книжный_клуб
             public double Cost, Discount;
             public double Cost, Discount;
             public int CountInStorage, Count, CountInOrder;
             public int CountInStorage, Count, CountInOrder;
         }
         }
-        List<OrderItem> LstOrder = new List<OrderItem>();
+        static List<OrderItem> LstOrder = new List<OrderItem>();
 
 
         /// <summary>
         /// <summary>
         /// Подччёт суммы заказа и суммы скидки
         /// Подччёт суммы заказа и суммы скидки
         /// </summary>
         /// </summary>
         /// <param name="Sum">Сумма заказа с учетом скидки</param>
         /// <param name="Sum">Сумма заказа с учетом скидки</param>
         /// <param name="DiscountSum">Сумма скидки</param>
         /// <param name="DiscountSum">Сумма скидки</param>
-        void CalcOrder(ref double Sum, ref double DiscountSum)
+        public static void CalcOrder(ref double Sum, ref double DiscountSum)
         {
         {
             Sum= 0;
             Sum= 0;
             DiscountSum= 0;
             DiscountSum= 0;
@@ -99,14 +99,17 @@ Manufacturer.IdManufacturer";
             Item.CountInStorage = int.Parse(DgvProductList.SelectedRows[0].Cells[6].Value.ToString());
             Item.CountInStorage = int.Parse(DgvProductList.SelectedRows[0].Cells[6].Value.ToString());
             Item.CountInOrder = 1;
             Item.CountInOrder = 1;
             LstOrder.Add(Item);
             LstOrder.Add(Item);
+            OutPutInfo();
+        }
 
 
-
+        public void OutPutInfo()
+        {
             double Sum = 0, DiscountSum = 0;
             double Sum = 0, DiscountSum = 0;
             CalcOrder(ref Sum, ref DiscountSum);
             CalcOrder(ref Sum, ref DiscountSum);
             LblSum.Text = $"Сумма заказа (с учетом скидки): {Sum}";
             LblSum.Text = $"Сумма заказа (с учетом скидки): {Sum}";
             LblDiscount.Text = $"Скидка: {DiscountSum}";
             LblDiscount.Text = $"Скидка: {DiscountSum}";
         }
         }
-        
+
         private void DgvProductList_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
         private void DgvProductList_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
         {
         {
             DgvProductList.ClearSelection();
             DgvProductList.ClearSelection();
@@ -117,10 +120,13 @@ Manufacturer.IdManufacturer";
         private void BtnOrder_Click(object sender, EventArgs e)
         private void BtnOrder_Click(object sender, EventArgs e)
         {
         {
             FormOrder Frm = new FormOrder();
             FormOrder Frm = new FormOrder();
-            //this.Hide();
             Frm.LstOrder = LstOrder;
             Frm.LstOrder = LstOrder;
             Frm.ShowDialog();
             Frm.ShowDialog();
-            //this.Show();
+            
+            OutPutInfo();
+            if(LstOrder.Count == 0)
+                PanelOrder.Visible = false;
+            
         }
         }
     }
     }
 }
 }

+ 25 - 9
СУБД Книжный клуб/FormOrder.Designer.cs

@@ -40,6 +40,7 @@
             this.Column2 = new System.Windows.Forms.DataGridViewImageColumn();
             this.Column2 = new System.Windows.Forms.DataGridViewImageColumn();
             this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.BtnDell = new System.Windows.Forms.Button();
             this.panel1.SuspendLayout();
             this.panel1.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.DgvProductList)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.DgvProductList)).BeginInit();
@@ -96,14 +97,16 @@
             this.Column2,
             this.Column2,
             this.Column3,
             this.Column3,
             this.Column7});
             this.Column7});
-            this.DgvProductList.Location = new System.Drawing.Point(12, 78);
+            this.DgvProductList.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
+            this.DgvProductList.Location = new System.Drawing.Point(16, 75);
+            this.DgvProductList.MultiSelect = false;
             this.DgvProductList.Name = "DgvProductList";
             this.DgvProductList.Name = "DgvProductList";
-            this.DgvProductList.ReadOnly = true;
             this.DgvProductList.RowHeadersVisible = false;
             this.DgvProductList.RowHeadersVisible = false;
             this.DgvProductList.RowTemplate.Height = 100;
             this.DgvProductList.RowTemplate.Height = 100;
             this.DgvProductList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
             this.DgvProductList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
-            this.DgvProductList.Size = new System.Drawing.Size(748, 415);
+            this.DgvProductList.Size = new System.Drawing.Size(748, 397);
             this.DgvProductList.TabIndex = 2;
             this.DgvProductList.TabIndex = 2;
+            this.DgvProductList.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.DgvProductList_CellValueChanged);
             // 
             // 
             // PanelOrder
             // PanelOrder
             // 
             // 
@@ -111,7 +114,7 @@
             this.PanelOrder.Controls.Add(this.LblDiscount);
             this.PanelOrder.Controls.Add(this.LblDiscount);
             this.PanelOrder.Controls.Add(this.BtnCheckOut);
             this.PanelOrder.Controls.Add(this.BtnCheckOut);
             this.PanelOrder.Dock = System.Windows.Forms.DockStyle.Bottom;
             this.PanelOrder.Dock = System.Windows.Forms.DockStyle.Bottom;
-            this.PanelOrder.Location = new System.Drawing.Point(0, 499);
+            this.PanelOrder.Location = new System.Drawing.Point(0, 514);
             this.PanelOrder.Name = "PanelOrder";
             this.PanelOrder.Name = "PanelOrder";
             this.PanelOrder.Size = new System.Drawing.Size(772, 70);
             this.PanelOrder.Size = new System.Drawing.Size(772, 70);
             this.PanelOrder.TabIndex = 3;
             this.PanelOrder.TabIndex = 3;
@@ -167,14 +170,25 @@
             // 
             // 
             this.Column7.HeaderText = "ProductCount";
             this.Column7.HeaderText = "ProductCount";
             this.Column7.Name = "Column7";
             this.Column7.Name = "Column7";
-            this.Column7.ReadOnly = true;
+            // 
+            // BtnDell
+            // 
+            this.BtnDell.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+            this.BtnDell.Location = new System.Drawing.Point(16, 481);
+            this.BtnDell.Name = "BtnDell";
+            this.BtnDell.Size = new System.Drawing.Size(322, 27);
+            this.BtnDell.TabIndex = 4;
+            this.BtnDell.Text = "Удалить товар из заказа";
+            this.BtnDell.UseVisualStyleBackColor = true;
+            this.BtnDell.Click += new System.EventHandler(this.BtnDell_Click);
             // 
             // 
             // FormOrder
             // FormOrder
             // 
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 23F);
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 23F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.BackColor = System.Drawing.Color.White;
             this.BackColor = System.Drawing.Color.White;
-            this.ClientSize = new System.Drawing.Size(772, 569);
+            this.ClientSize = new System.Drawing.Size(772, 584);
+            this.Controls.Add(this.BtnDell);
             this.Controls.Add(this.PanelOrder);
             this.Controls.Add(this.PanelOrder);
             this.Controls.Add(this.DgvProductList);
             this.Controls.Add(this.DgvProductList);
             this.Controls.Add(this.panel1);
             this.Controls.Add(this.panel1);
@@ -184,6 +198,7 @@
             this.Name = "FormOrder";
             this.Name = "FormOrder";
             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
             this.Text = "СУБД \"Книжный клуб\"";
             this.Text = "СУБД \"Книжный клуб\"";
+            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormOrder_FormClosing);
             this.Load += new System.EventHandler(this.FormOrder_Load);
             this.Load += new System.EventHandler(this.FormOrder_Load);
             this.panel1.ResumeLayout(false);
             this.panel1.ResumeLayout(false);
             this.panel1.PerformLayout();
             this.panel1.PerformLayout();
@@ -201,12 +216,13 @@
         private System.Windows.Forms.Label label1;
         private System.Windows.Forms.Label label1;
         private System.Windows.Forms.PictureBox pictureBox1;
         private System.Windows.Forms.PictureBox pictureBox1;
         private System.Windows.Forms.DataGridView DgvProductList;
         private System.Windows.Forms.DataGridView DgvProductList;
-        private System.Windows.Forms.DataGridViewImageColumn Column2;
-        private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
-        private System.Windows.Forms.DataGridViewTextBoxColumn Column7;
         private System.Windows.Forms.Panel PanelOrder;
         private System.Windows.Forms.Panel PanelOrder;
         private System.Windows.Forms.Label LblSum;
         private System.Windows.Forms.Label LblSum;
         private System.Windows.Forms.Label LblDiscount;
         private System.Windows.Forms.Label LblDiscount;
         private System.Windows.Forms.Button BtnCheckOut;
         private System.Windows.Forms.Button BtnCheckOut;
+        private System.Windows.Forms.DataGridViewImageColumn Column2;
+        private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
+        private System.Windows.Forms.DataGridViewTextBoxColumn Column7;
+        private System.Windows.Forms.Button BtnDell;
     }
     }
 }
 }

+ 74 - 0
СУБД Книжный клуб/FormOrder.cs

@@ -67,6 +67,80 @@ where IdProduct =" + LstOrder[i].IdProduct;
         private void FormOrder_Load(object sender, EventArgs e)
         private void FormOrder_Load(object sender, EventArgs e)
         {
         {
             FillListProduct();
             FillListProduct();
+            OutPutInfo();
+        }
+
+        private void DgvProductList_CellValueChanged(object sender, DataGridViewCellEventArgs e)
+        {
+            if (DgvProductList.CurrentRow == null)
+                return;
+            
+
+            int n = DgvProductList.CurrentRow.Index;
+            int OldNum = LstOrder[n].CountInOrder;
+            try
+            {
+                LstOrder[n].CountInOrder = int.Parse(DgvProductList.CurrentRow.Cells[2].Value.ToString());
+            }
+            catch
+            {
+                DgvProductList.CurrentRow.Cells[2].Value = OldNum;
+                MessageBox.Show("Произошла ошибка. Кол-во товара должно быть числом.", "Внимаение!", MessageBoxButtons.OK, MessageBoxIcon.Error);
+
+            }
+            if (LstOrder[n].CountInOrder < 0)
+            {
+                DgvProductList.CurrentRow.Cells[2].Value = OldNum;
+                MessageBox.Show("Кол-во не должно быть отрицательным!", "Внимаение!", MessageBoxButtons.OK, MessageBoxIcon.Error);
+               
+            }
+
+            if (LstOrder[n].CountInOrder == 0)
+            {
+                if (MessageBox.Show("Вы точно хотите удалить товар?", "Внимание!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+                {
+                    DgvProductList.CurrentRow.Cells[2].Value = OldNum;
+                    return;
+                }
+                else
+                {
+                    LstOrder.RemoveAt(e.RowIndex);
+                    FillListProduct();
+                }
+               
+            }
+            OutPutInfo();
+        }
+        public void OutPutInfo()
+        {
+            double Sum = 0, DiscountSum = 0;
+            FormMain.CalcOrder(ref Sum, ref DiscountSum);
+            LblSum.Text = $"Сумма заказа (с учетом скидки): {Sum}";
+            LblDiscount.Text = $"Скидка: {DiscountSum}";
+        }
+        private void FormOrder_FormClosing(object sender, FormClosingEventArgs e)
+        {
+            DgvProductList.EndEdit();
+            DgvProductList.Update();
+            FillListProduct();
+        }
+
+        private void BtnDell_Click(object sender, EventArgs e)
+        {
+            if (LstOrder.Count == 0)
+            {
+                MessageBox.Show("Нет товаров в заказе!", "Внимаение!", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                return;
+            }
+            int n = DgvProductList.CurrentRow.Index;
+            if (MessageBox.Show("Вы точно хотите удалить товар?", "Внимание!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+            {
+                LstOrder.RemoveAt(n);
+                FillListProduct();
+            }
+            OutPutInfo();
+
+               
         }
         }
     }
     }
 }
 }

+ 0 - 9
СУБД Книжный клуб/FormOrder.resx

@@ -126,13 +126,4 @@
   <metadata name="Column7.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
   <metadata name="Column7.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
     <value>True</value>
   </metadata>
   </metadata>
-  <metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
-  <metadata name="Column3.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
-  <metadata name="Column7.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
 </root>
 </root>

BIN
СУБД Книжный клуб/bin/Debug/СУБД Книжный клуб.exe