From 72cf329ce1c456222fcc5276bb65e67cbf6760f0 Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期四, 22 一月 2026 14:52:39 +0800
Subject: [PATCH] 优化主界面显示为行列矩阵形式,实现鼠标左键双击对应窗体最大化,再次双击恢复之前布局。

---
 LB_SmartVision/Forms/Pages/HistoricalDataPage/HistoricalDataEditPage.cs |  174 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 147 insertions(+), 27 deletions(-)

diff --git a/LB_SmartVision/Forms/Pages/HistoricalDataPage/HistoricalDataEditPage.cs b/LB_SmartVision/Forms/Pages/HistoricalDataPage/HistoricalDataEditPage.cs
index d4c539d..477bcfd 100644
--- a/LB_SmartVision/Forms/Pages/HistoricalDataPage/HistoricalDataEditPage.cs
+++ b/LB_SmartVision/Forms/Pages/HistoricalDataPage/HistoricalDataEditPage.cs
@@ -1,9 +1,12 @@
-锘縰sing LB_SmartVisionCommon;
+锘縰sing LB_SmartVision.CSV;
+using LB_SmartVision.SQL;
+using LB_SmartVisionCommon;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
+using System.Globalization;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -14,44 +17,34 @@
     public partial class HistoricalDataEditPage : UserControl
     {
         public Action<string, LogInfoType> LogInfo;
+        // 淇濆瓨鍘熷鏁版嵁鐨勫垪琛�
+        private List<DataGridViewRow> originalRows = new List<DataGridViewRow>();
 
-        private Panel currentContentPanel;
+        private int row2OriginalHeight;
+        private int row3OriginalHeight;
+
+        List<RecordProductData> RecordProductDatas = new List<RecordProductData>();
         public HistoricalDataEditPage()
         {
             Name = "HistoricalDataEditPage";
             Text = "鍘嗗彶鏁版嵁鏌ヨ";
 
             InitializeComponent();
+
+            // 淇濆瓨鍘熷琛岄珮搴�
+            row2OriginalHeight = (int)tableLayoutPanel3.RowStyles[1].Height;
+            row3OriginalHeight = (int)tableLayoutPanel3.RowStyles[2].Height;
+
             InitializeDataGridView();
             InitializeComboBox();
         }
 
+        /// <summary>
+        /// 鏁版嵁鏄剧ず琛ㄦ牸鍒濆鍖�
+        /// </summary>
         private void InitializeDataGridView()
         {
-            // 璁剧疆DataGridView鍒楀
-            dataGridViewHD.ColumnCount = 4;
-
-            int totalWidth = dataGridViewHD.ClientSize.Width;
-            int columnCount = dataGridViewHD.ColumnCount;
-            int columnWidth = totalWidth / columnCount;
-
-            // 璁剧疆鏈�灏忓搴�
-            int minWidth = 100; // 鏈�灏忓搴�
-            if (columnWidth < minWidth)
-            {
-                columnWidth = minWidth;
-            }
-
-            for (int i = 0; i < columnCount; i++)
-            {
-                dataGridViewHD.Columns[i].Width = columnWidth;
-            }
-
-            // 璁剧疆鍒楁爣棰�
-            dataGridViewHD.Columns[0].Name = "SN鍙�";
-            dataGridViewHD.Columns[1].Name = "鏃堕棿";
-            dataGridViewHD.Columns[2].Name = "NG绫�";
-            dataGridViewHD.Columns[3].Name = "缂洪櫡澶у皬";
+            this.dataGridViewHD.DataSource = RecordProductDatas;
 
             dataGridViewHD.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
 
@@ -65,6 +58,9 @@
             dataGridViewHD.RowHeadersVisible = true;
         }
 
+        /// <summary>
+        /// 閫夋嫨渚濇嵁涓嬫媺妗嗗垵濮嬪寲
+        /// </summary>
         private void InitializeComboBox()
         {
             comboBoxSearchBasis.Items.Add("鏃ユ湡");
@@ -74,9 +70,133 @@
             comboBoxSearchBasis.SelectedIndex = 0;
         }
 
-        private void tableLayoutPanel2_Paint(object sender, PaintEventArgs e)
+        /// <summary>
+        /// 涓嬫媺妗嗘帶鍒堕�夐」瑙嗗浘鍙樻崲
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void comboBoxSearchBasis_SelectedIndexChanged(object sender, EventArgs e)
         {
+            ComboBox cb = sender as ComboBox;
+
+            if (cb.SelectedIndex == 0)
+            {
+                ShowRow2();
+            }
+            else if (cb.SelectedIndex == 1)
+            {
+                ShowRow3();
+            }
+        }
+
+        private void ShowRow2()
+        {
+            // 鏄剧ずRow2锛堟仮澶嶉珮搴︼級
+            tableLayoutPanel3.RowStyles[1].SizeType = SizeType.Absolute;
+            tableLayoutPanel3.RowStyles[1].Height = row2OriginalHeight;
+
+            // 闅愯棌Row3锛堥珮搴﹁涓�0锛�
+            tableLayoutPanel3.RowStyles[2].SizeType = SizeType.Absolute;
+            tableLayoutPanel3.RowStyles[2].Height = 0;
+
+            // 鏄剧ずRow2涓殑鎺т欢
+            foreach (Control ctrl in tableLayoutPanel3.Controls)
+            {
+                int row = tableLayoutPanel3.GetRow(ctrl);
+                if (row == 1)
+                    ctrl.Visible = true;
+                else if (row == 2)
+                    ctrl.Visible = false;
+            }
+        }
+
+        private void ShowRow3()
+        {
+            // 闅愯棌Row2锛堥珮搴﹁涓�0锛�
+            tableLayoutPanel3.RowStyles[1].SizeType = SizeType.Absolute;
+            tableLayoutPanel3.RowStyles[1].Height = 0;
+
+            // 鏄剧ずRow3锛堟仮澶嶉珮搴︼級
+            tableLayoutPanel3.RowStyles[2].SizeType = SizeType.Absolute;
+            tableLayoutPanel3.RowStyles[2].Height = row3OriginalHeight;
+
+            // 鏄剧ずRow3涓殑鎺т欢
+            foreach (Control ctrl in tableLayoutPanel3.Controls)
+            {
+                int row = tableLayoutPanel3.GetRow(ctrl);
+                if (row == 1)
+                    ctrl.Visible = false;
+                else if (row == 2)
+                    ctrl.Visible = true;
+            }
+        }
+
+        private void dateTimePickerStart_ValueChanged(object sender, EventArgs e)
+        {
+            dateTimePickerEnd.MinDate = dateTimePickerStart.Value;
+        }
+        public string OpenFileForSave()
+        {
+            using (SaveFileDialog saveFileDialog = new SaveFileDialog())
+            {
+                // 璁剧疆榛樿鏂囦欢鍚嶅拰鎵╁睍鍚�
+                saveFileDialog.FileName = $"鍘嗗彶鏁版嵁_{DateTime.Now:yyyyMMdd_HHmmss}";
+                saveFileDialog.DefaultExt = "xlsx";
+
+                // 璁剧疆鏂囦欢杩囨护鍣�
+                saveFileDialog.Filter = "Excel鏂囦欢 (*.xlsx)|*.xlsx|" +
+                                        "CSV鏂囦欢 (*.csv)|*.csv|" +
+                                        "鏂囨湰鏂囦欢 (*.txt)|*.txt|" +
+                                        "鎵�鏈夋枃浠� (*.*)|*.*";
+
+                saveFileDialog.Title = "閫夋嫨鏂囦欢淇濆瓨浣嶇疆";
+                saveFileDialog.RestoreDirectory = true;  // 璁颁綇涓婃鎵撳紑鐨勭洰褰�
+                saveFileDialog.OverwritePrompt = true;   // 瑕嗙洊鏃舵彁绀�
+
+                if (saveFileDialog.ShowDialog() == DialogResult.OK)
+                {
+                    string filePathHD = saveFileDialog.FileName;
+                    return filePathHD;
+                }
+            }
+
+            return null;
+        }
+        private void btnHisDataExport_Click(object sender, EventArgs e)
+        {
+            CsvDataHelperRecordProductData.SaveToCsv(OpenFileForSave(), RecordProductDatas);
+        }
+        
+        private void btnHisDataFind_Click(object sender, EventArgs e)
+        {
+            
+            DateTime startDate = dateTimePickerStart.Value.Date;
+            DateTime endDate = dateTimePickerEnd.Value.Date;
+
+            switch(comboBoxSearchBasis.SelectedIndex)
+            {
+                //渚濇嵁鏃ユ湡鏌ヨ
+                case 0:
+                    RecordProductDatas = RecordProductDataRepository.GetRecordsByTimeRange(DateTime.Parse(this.dateTimePickerStart.Value.ToString()), DateTime.Parse(this.dateTimePickerEnd.Value.ToString()));
+                    break;
+                //渚濇嵁SN鍙锋煡璇�
+                case 1:
+                    if(string.IsNullOrEmpty(textBoxSN.Text))
+                    {
+                        MessageBox.Show("璇峰~鍐橲N鍙凤紒", "鎻愮ず", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+                    }
+                    else
+                    {
+                        RecordProductDatas = RecordProductDataRepository.GetRecordsByProductNumber(textBoxSN.Text);
+                    }
+                        break;
+            }
+
+            this.dataGridViewHD.DataSource = RecordProductDatas;
+            this.dataGridViewHD.AutoGenerateColumns = true;
 
         }
+
     }
 }
+

--
Gitblit v1.9.3