Your Name 2 năm trước cách đây
mục cha
commit
07fd67cce5

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

@@ -101,7 +101,9 @@ Manufacturer.IdManufacturer";
             LstOrder.Add(Item);
             OutPutInfo();
         }
-
+        /// <summary>
+        /// Вывод информации по сумме заказа и суммы скидки
+        /// </summary>
         public void OutPutInfo()
         {
             double Sum = 0, DiscountSum = 0;
@@ -124,6 +126,7 @@ Manufacturer.IdManufacturer";
             Frm.ShowDialog();
             
             OutPutInfo();
+            FillListProduct();
             if(LstOrder.Count == 0)
                 PanelOrder.Visible = false;
             

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

@@ -28,23 +28,32 @@
         /// </summary>
         private void InitializeComponent()
         {
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
+            this.components = new System.ComponentModel.Container();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
             this.panel1 = new System.Windows.Forms.Panel();
             this.label1 = new System.Windows.Forms.Label();
             this.pictureBox1 = new System.Windows.Forms.PictureBox();
             this.DgvProductList = new System.Windows.Forms.DataGridView();
+            this.Column2 = new System.Windows.Forms.DataGridViewImageColumn();
+            this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.PanelOrder = new System.Windows.Forms.Panel();
             this.LblSum = new System.Windows.Forms.Label();
             this.LblDiscount = new System.Windows.Forms.Label();
             this.BtnCheckOut = new System.Windows.Forms.Button();
-            this.Column2 = new System.Windows.Forms.DataGridViewImageColumn();
-            this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.BtnDell = new System.Windows.Forms.Button();
+            this.CmbPickUpPoint = new System.Windows.Forms.ComboBox();
+            this.label2 = new System.Windows.Forms.Label();
+            this.bookClubKMADataSet1 = new СУБД_Книжный_клуб.BookClubKMADataSet();
+            this.BSPickUpPoint = new System.Windows.Forms.BindingSource(this.components);
+            this.pickupPointTableAdapter = new СУБД_Книжный_клуб.BookClubKMADataSetTableAdapters.PickupPointTableAdapter();
+            this.SaveToPDF = new System.Windows.Forms.SaveFileDialog();
             this.panel1.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.DgvProductList)).BeginInit();
             this.PanelOrder.SuspendLayout();
+            ((System.ComponentModel.ISupportInitialize)(this.bookClubKMADataSet1)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.BSPickUpPoint)).BeginInit();
             this.SuspendLayout();
             // 
             // panel1
@@ -104,25 +113,49 @@
             this.DgvProductList.RowHeadersVisible = false;
             this.DgvProductList.RowTemplate.Height = 100;
             this.DgvProductList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
-            this.DgvProductList.Size = new System.Drawing.Size(748, 397);
+            this.DgvProductList.Size = new System.Drawing.Size(748, 328);
             this.DgvProductList.TabIndex = 2;
             this.DgvProductList.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.DgvProductList_CellValueChanged);
             // 
+            // Column2
+            // 
+            this.Column2.HeaderText = "Photo";
+            this.Column2.ImageLayout = System.Windows.Forms.DataGridViewImageCellLayout.Zoom;
+            this.Column2.Name = "Column2";
+            this.Column2.ReadOnly = true;
+            this.Column2.Resizable = System.Windows.Forms.DataGridViewTriState.False;
+            // 
+            // Column3
+            // 
+            this.Column3.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+            dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+            this.Column3.DefaultCellStyle = dataGridViewCellStyle1;
+            this.Column3.HeaderText = "Info";
+            this.Column3.Name = "Column3";
+            this.Column3.ReadOnly = true;
+            // 
+            // Column7
+            // 
+            this.Column7.HeaderText = "ProductCount";
+            this.Column7.Name = "Column7";
+            // 
             // PanelOrder
             // 
+            this.PanelOrder.Controls.Add(this.label2);
+            this.PanelOrder.Controls.Add(this.CmbPickUpPoint);
             this.PanelOrder.Controls.Add(this.LblSum);
             this.PanelOrder.Controls.Add(this.LblDiscount);
             this.PanelOrder.Controls.Add(this.BtnCheckOut);
             this.PanelOrder.Dock = System.Windows.Forms.DockStyle.Bottom;
-            this.PanelOrder.Location = new System.Drawing.Point(0, 514);
+            this.PanelOrder.Location = new System.Drawing.Point(0, 468);
             this.PanelOrder.Name = "PanelOrder";
-            this.PanelOrder.Size = new System.Drawing.Size(772, 70);
+            this.PanelOrder.Size = new System.Drawing.Size(772, 116);
             this.PanelOrder.TabIndex = 3;
             // 
             // LblSum
             // 
             this.LblSum.AutoSize = true;
-            this.LblSum.Location = new System.Drawing.Point(12, 13);
+            this.LblSum.Location = new System.Drawing.Point(3, 90);
             this.LblSum.Name = "LblSum";
             this.LblSum.Size = new System.Drawing.Size(65, 23);
             this.LblSum.TabIndex = 2;
@@ -131,7 +164,7 @@
             // LblDiscount
             // 
             this.LblDiscount.AutoSize = true;
-            this.LblDiscount.Location = new System.Drawing.Point(12, 38);
+            this.LblDiscount.Location = new System.Drawing.Point(358, 90);
             this.LblDiscount.Name = "LblDiscount";
             this.LblDiscount.Size = new System.Drawing.Size(65, 23);
             this.LblDiscount.TabIndex = 1;
@@ -141,7 +174,7 @@
             // 
             this.BtnCheckOut.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Right)));
-            this.BtnCheckOut.Location = new System.Drawing.Point(506, 13);
+            this.BtnCheckOut.Location = new System.Drawing.Point(540, 73);
             this.BtnCheckOut.Name = "BtnCheckOut";
             this.BtnCheckOut.Size = new System.Drawing.Size(229, 40);
             this.BtnCheckOut.TabIndex = 0;
@@ -149,39 +182,57 @@
             this.BtnCheckOut.UseVisualStyleBackColor = true;
             this.BtnCheckOut.Click += new System.EventHandler(this.BtnCheckOut_Click);
             // 
-            // Column2
-            // 
-            this.Column2.HeaderText = "Photo";
-            this.Column2.ImageLayout = System.Windows.Forms.DataGridViewImageCellLayout.Zoom;
-            this.Column2.Name = "Column2";
-            this.Column2.ReadOnly = true;
-            this.Column2.Resizable = System.Windows.Forms.DataGridViewTriState.False;
-            // 
-            // Column3
-            // 
-            this.Column3.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
-            dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
-            this.Column3.DefaultCellStyle = dataGridViewCellStyle4;
-            this.Column3.HeaderText = "Info";
-            this.Column3.Name = "Column3";
-            this.Column3.ReadOnly = true;
-            // 
-            // Column7
-            // 
-            this.Column7.HeaderText = "ProductCount";
-            this.Column7.Name = "Column7";
-            // 
             // 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.Location = new System.Drawing.Point(12, 422);
             this.BtnDell.Name = "BtnDell";
-            this.BtnDell.Size = new System.Drawing.Size(322, 27);
+            this.BtnDell.Size = new System.Drawing.Size(254, 40);
             this.BtnDell.TabIndex = 4;
             this.BtnDell.Text = "Удалить товар из заказа";
             this.BtnDell.UseVisualStyleBackColor = true;
             this.BtnDell.Click += new System.EventHandler(this.BtnDell_Click);
             // 
+            // CmbPickUpPoint
+            // 
+            this.CmbPickUpPoint.DataSource = this.BSPickUpPoint;
+            this.CmbPickUpPoint.DisplayMember = "AddressPickupPoint";
+            this.CmbPickUpPoint.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.CmbPickUpPoint.FormattingEnabled = true;
+            this.CmbPickUpPoint.Location = new System.Drawing.Point(540, 38);
+            this.CmbPickUpPoint.Name = "CmbPickUpPoint";
+            this.CmbPickUpPoint.Size = new System.Drawing.Size(229, 31);
+            this.CmbPickUpPoint.TabIndex = 5;
+            this.CmbPickUpPoint.ValueMember = "IdPickupPoint";
+            this.CmbPickUpPoint.SelectedIndexChanged += new System.EventHandler(this.CmbPickUpPoint_SelectedIndexChanged);
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Location = new System.Drawing.Point(536, 15);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(233, 23);
+            this.label2.TabIndex = 6;
+            this.label2.Text = "Выберите пункт выдачи";
+            // 
+            // bookClubKMADataSet1
+            // 
+            this.bookClubKMADataSet1.DataSetName = "BookClubKMADataSet";
+            this.bookClubKMADataSet1.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
+            // 
+            // BSPickUpPoint
+            // 
+            this.BSPickUpPoint.DataMember = "PickupPoint";
+            this.BSPickUpPoint.DataSource = this.bookClubKMADataSet1;
+            // 
+            // pickupPointTableAdapter
+            // 
+            this.pickupPointTableAdapter.ClearBeforeFill = true;
+            // 
+            // SaveToPDF
+            // 
+            this.SaveToPDF.DefaultExt = "pdf";
+            // 
             // FormOrder
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 23F);
@@ -206,6 +257,8 @@
             ((System.ComponentModel.ISupportInitialize)(this.DgvProductList)).EndInit();
             this.PanelOrder.ResumeLayout(false);
             this.PanelOrder.PerformLayout();
+            ((System.ComponentModel.ISupportInitialize)(this.bookClubKMADataSet1)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.BSPickUpPoint)).EndInit();
             this.ResumeLayout(false);
 
         }
@@ -224,5 +277,11 @@
         private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
         private System.Windows.Forms.DataGridViewTextBoxColumn Column7;
         private System.Windows.Forms.Button BtnDell;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.ComboBox CmbPickUpPoint;
+        private BookClubKMADataSet bookClubKMADataSet1;
+        private System.Windows.Forms.BindingSource BSPickUpPoint;
+        private BookClubKMADataSetTableAdapters.PickupPointTableAdapter pickupPointTableAdapter;
+        private System.Windows.Forms.SaveFileDialog SaveToPDF;
     }
 }

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

@@ -3,12 +3,15 @@ using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Data.SqlClient;
+using System.Diagnostics;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
-
+using static СУБД_Книжный_клуб.FormMain;
+using Excel = Microsoft.Office.Interop.Excel;
+ 
 namespace СУБД_Книжный_клуб
 {
     public partial class FormOrder : Form
@@ -18,6 +21,10 @@ namespace СУБД_Книжный_клуб
             InitializeComponent();
         }
         SqlConnection Con = new SqlConnection(FormMain.TxtCon);
+
+        /// <summary>
+        /// Вывод списка товаров в заказе
+        /// </summary>
         void FillListProduct()
         {
             DgvProductList.Rows.Clear();
@@ -48,6 +55,7 @@ where IdProduct =" + LstOrder[i].IdProduct;
                 catch
                 {
                     DgvProductList.Rows.Add( Image.FromFile(Application.StartupPath + "\\Фото\\blank.jpg" + Res["Photo"]), Info, LstOrder[i].CountInOrder);
+                    
                 }
                 Con.Close();
 
@@ -61,11 +69,88 @@ where IdProduct =" + LstOrder[i].IdProduct;
 
         private void BtnCheckOut_Click(object sender, EventArgs e)
         {
+           if (LstOrder.Count == 0)
+            {
+                MessageBox.Show("Нет товаров в заказе!","Внимание!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
+                return;
+            }
            
+            
+            Random Rnd = new Random();
+            int Code = Rnd.Next(100, 1000);
+            int DeliveryDay = 3;
+            for (int i = 0; i <= LstOrder.Count - 1; i++)
+                if (LstOrder[i].CountInStorage <= 3)
+                {
+                    DeliveryDay = 6;
+                    break;
+
+                }
+            Con.Open();
+            string TxtQuery = $@"insert into [Order] (IdUser, IdPickupPoint,DateOrder, Code,IdOrderStatus)
+Values (4,'{CmbPickUpPoint.SelectedValue.ToString()}',GetDate(),{Code},1)
+Select SCOPE_Identity()";
+            SqlCommand Com = new SqlCommand(TxtQuery,Con);
+            string IdOrder = Com.ExecuteScalar().ToString();
+            for (int i = 0; i<= LstOrder.Count-1; i++)
+            {
+                TxtQuery = $@"insert into OrderProduct (IdOrder, IdProduct, CountProduct)
+Values ({IdOrder},{LstOrder[i].IdProduct},{LstOrder[i].CountInOrder})";
+                Com = new SqlCommand(TxtQuery, Con);
+                Com.ExecuteNonQuery();
+
+
+                int NewCount = LstOrder[i].CountInStorage - LstOrder[i].CountInOrder;
+                
+                if (NewCount < 0 )
+                    NewCount= 0;
+                    TxtQuery = $@"Update Product Set CountProduct = {NewCount}
+where IdProduct ={LstOrder[i].IdProduct}";
+//              
+                Com = new SqlCommand(TxtQuery, Con);
+                Com.ExecuteNonQuery();
+               
+            }
+            Con.Close();
+            FillListProduct();
+
+            MessageBox.Show("Заказ сформирован. Код для получения: "+ Code,"Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information) ;
+            if (SaveToPDF.ShowDialog() != DialogResult.OK)
+            {
+                LstOrder.Clear();
+                Close();
+            }
+                
+
+            Excel.Application ExApp = new Excel.Application();
+            //ExApp.Visible= true;
+            ExApp.Workbooks.Open(Application.StartupPath + "\\Заказ.xlsx",null,true);
+            Excel.Worksheet MyList = ExApp.Worksheets.get_Item(1);
+
+            double Sum = 0, DiscountSum = 0;
+            CalcOrder(ref Sum, ref DiscountSum);
+
+            MyList.Cells[1, 2] = DateTime.Now.ToString("dd.MM.yyyy");
+            MyList.Cells[2, 2] = IdOrder;
+            MyList.Cells[3, 2] =Sum ;
+            MyList.Cells[4, 2] =  DiscountSum ;
+            MyList.Cells[5, 2] = CmbPickUpPoint.Text;
+            MyList.Cells[6, 2] = DeliveryDay + "д.";
+            MyList.Cells[7, 2] = Code;
+            for (int i = 0; i <= LstOrder.Count - 1; i++)
+                MyList.Cells[i+9, 1] = $"{LstOrder[i].NameProduct} - {LstOrder[i].CountInOrder}шт.";
+            MyList.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, SaveToPDF.FileName);
+            ExApp.DisplayAlerts = false;
+            ExApp.Quit();
+            Process.Start(SaveToPDF.FileName);
+            LstOrder.Clear();
+            Close();
         }
 
         private void FormOrder_Load(object sender, EventArgs e)
         {
+            // TODO: This line of code loads data into the 'bookClubKMADataSet1.PickupPoint' table. You can move, or remove it, as needed.
+            this.pickupPointTableAdapter.Fill(this.bookClubKMADataSet1.PickupPoint);
             FillListProduct();
             OutPutInfo();
         }
@@ -111,6 +196,9 @@ where IdProduct =" + LstOrder[i].IdProduct;
             }
             OutPutInfo();
         }
+        /// <summary>
+        /// Вывод информации о сумме заказа и сумме скидки
+        /// </summary>
         public void OutPutInfo()
         {
             double Sum = 0, DiscountSum = 0;
@@ -142,5 +230,10 @@ where IdProduct =" + LstOrder[i].IdProduct;
 
                
         }
+
+        private void CmbPickUpPoint_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            this.Text = CmbPickUpPoint.SelectedValue.ToString();
+        }
     }
 }

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

@@ -126,4 +126,16 @@
   <metadata name="Column7.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
+  <metadata name="BSPickUpPoint.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>197, 17</value>
+  </metadata>
+  <metadata name="bookClubKMADataSet1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+  <metadata name="pickupPointTableAdapter.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>328, 17</value>
+  </metadata>
+  <metadata name="SaveToPDF.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>517, 17</value>
+  </metadata>
 </root>

BIN
СУБД Книжный клуб/bin/Debug/Заказ.xlsx


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


+ 29 - 0
СУБД Книжный клуб/СУБД Книжный клуб.csproj

@@ -104,5 +104,34 @@
   <ItemGroup>
     <None Include="App.config" />
   </ItemGroup>
+  <ItemGroup>
+    <COMReference Include="Microsoft.Office.Core">
+      <Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
+      <VersionMajor>2</VersionMajor>
+      <VersionMinor>8</VersionMinor>
+      <Lcid>0</Lcid>
+      <WrapperTool>primary</WrapperTool>
+      <Isolated>False</Isolated>
+      <EmbedInteropTypes>True</EmbedInteropTypes>
+    </COMReference>
+    <COMReference Include="Microsoft.Office.Interop.Excel">
+      <Guid>{00020813-0000-0000-C000-000000000046}</Guid>
+      <VersionMajor>1</VersionMajor>
+      <VersionMinor>9</VersionMinor>
+      <Lcid>0</Lcid>
+      <WrapperTool>primary</WrapperTool>
+      <Isolated>False</Isolated>
+      <EmbedInteropTypes>True</EmbedInteropTypes>
+    </COMReference>
+    <COMReference Include="VBIDE">
+      <Guid>{0002E157-0000-0000-C000-000000000046}</Guid>
+      <VersionMajor>5</VersionMajor>
+      <VersionMinor>3</VersionMinor>
+      <Lcid>0</Lcid>
+      <WrapperTool>primary</WrapperTool>
+      <Isolated>False</Isolated>
+      <EmbedInteropTypes>True</EmbedInteropTypes>
+    </COMReference>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>