From f7d479db638f3d9e3aeb05ec82dc2818f14bf903 Mon Sep 17 00:00:00 2001
From: ningshuxia <ningshuxia0927@outlook.com>
Date: 星期一, 24 三月 2025 17:25:20 +0800
Subject: [PATCH] Merge branch 'master' of http://47.103.154.90:83/r/HStation/XHS.V1.0

---
 WinFrmUI/PBS.WinFrmUI/03-elecPrice/ElecPriceMgr.cs |  204 ++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 147 insertions(+), 57 deletions(-)

diff --git a/WinFrmUI/PBS.WinFrmUI/03-elecPrice/ElecPriceMgr.cs b/WinFrmUI/PBS.WinFrmUI/03-elecPrice/ElecPriceMgr.cs
index 4436e80..86565d4 100644
--- a/WinFrmUI/PBS.WinFrmUI/03-elecPrice/ElecPriceMgr.cs
+++ b/WinFrmUI/PBS.WinFrmUI/03-elecPrice/ElecPriceMgr.cs
@@ -1,4 +1,8 @@
 锘縰sing DevExpress.XtraEditors;
+using DevExpress.XtraGantt.Scheduling;
+using DevExpress.XtraGrid.Views.Grid;
+using System.ComponentModel;
+using Yw.WinFrmUI;
 
 namespace PBS.WinFrmUI
 {
@@ -7,6 +11,9 @@
         public ElecPriceMgr()
         {
             InitializeComponent();
+            this.gridView1.SetNormalView(30);
+            this.gridView1.CellMerge += GridView1_CellMerge;
+            this.gridView1.OptionsView.AllowCellMerge = true;
         }
 
         private void BtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
@@ -14,80 +21,163 @@
             AddElePrice();
         }
 
+        private BindingList<ElecPriceViewModel> _allBindingList = null;//鎵�鏈夌粦瀹氬垪琛�
+
+        private PBS.Vmo.ElecPriceVmo _elecPrice = null;
+
+        public override void InitialDataSource()
+        {
+            SetBindingData();
+        }
+
+        /// <summary>
+        /// 缁戝畾鏁版嵁
+        /// </summary>
+        public async void SetBindingData()
+        {
+            _allBindingList = new BindingList<ElecPriceViewModel>();
+            var bll = new BLL.ElecPrice();
+            var allList = await bll.GetAll();
+            if (allList != null)
+                _elecPrice = allList.First();
+            if (_elecPrice != null)
+            {
+                if (_elecPrice.Settings != null && _elecPrice.Settings.MonthList != null)
+                {
+                    var months = _elecPrice.Settings.MonthList.OrderBy(x => x.StartMonth);
+                    foreach (var month in months)
+                    {
+                        if (month.HourList == null)
+                            continue;
+                        var belongName = $"{month.StartMonth}~{month.EndMonth}(鏈�)";
+                        var hours = month.HourList.OrderBy(x => x.StartHour);
+                        foreach (var hour in hours)
+                        {
+                            var vm = new ElecPriceViewModel(belongName, hour);
+                            vm.StartMonth = month.StartMonth;
+                            vm.EndMonth = month.EndMonth;
+                            _allBindingList.Add(vm);
+                        }
+                    }
+                }
+                else
+                {
+                    _elecPrice.Settings = new Vmo.ElecPriceSetting();
+                    _elecPrice.Settings.MonthList = new List<Vmo.ElecPriceMonthSetting> { new Vmo.ElecPriceMonthSetting() };
+                }
+            }
+            this.elecPriceViewModelBindingSource.DataSource = _allBindingList;
+            this.elecPriceViewModelBindingSource.ResetBindings(false);
+            //this.gridView1.BestFitColumns();
+        }
+
         //娣诲姞鐢佃垂
         public void AddElePrice()
         {
             var dlg = new AddElectricDlg();
             dlg.SetBindingData();
-            dlg.ReloadDataEvent += (price) =>
+            dlg.ReloadDataEvent += async (price) =>
             {
-                /* var bll = new BLL.ElecPrice();
-                 _elecPrice.Settings.MonthList.Add(price);
-                 var bol = bll.Update(_elecPrice);
-                 if (bol)
-                 {
-                     this.SetBindingData();
-                     this.currentViewModelBindingSource.ResetBindings(false);
-                     return true;
-                 }*/
+                var bll = new BLL.ElecPrice();
+                _elecPrice.Settings.MonthList.Add(price);
+                var bol = await bll.Update(_elecPrice);
+                if (bol)
+                {
+                    foreach (var item in price.HourList)
+                    {
+                        this._allBindingList.Add(new ElecPriceViewModel
+                        {
+                            BelongName = $"{price.StartMonth}~{price.EndMonth}(鏈�)",
+                            StartHour = item.StartHour,
+                            EndHour = item.EndHour,
+                            Price = item.Price
+                        });
+                    }
+                    this.elecPriceViewModelBindingSource.ResetBindings(false);
+                    return true;
+                }
                 return false;
             };
             dlg.ShowDialog();
         }
 
-        //  var oldbelongName= _allBindingList.Where(e=>e.BelongName==belongName).FirstOrDefault();
-        //if (oldbelongName == null)
-
         //缂栬緫鐢佃垂
-        /*       public void EditElePrice()
-               {
-                   var row = gridView1.GetCurrentViewModel(_allBindingList);
-                   if (row == null)
-                       return;
-                   var editTime = _elecPrice.Settings;  //鎻愰棶:杩欏彞璇濈偣涓嶅埌hourlist   new涓�涓猰onthsetting灏辫兘.鍒癶ourlist
-                   var FindMonth = editTime.MonthList.Find(x => x.StartMonth == row.StartMonth && x.EndMonth == row.EndMonth);
-                   var addHour = _elecPrice.Settings.MonthList.IndexOf(FindMonth);
-                   var editHour = editTime.MonthList[addHour];
-                   var dlg = new EditElectricDlg();
-                   dlg.SetBindingData(editHour.HourList);
-                   dlg.ReLoadDataevent += (price) =>
-                   {
-                       editHour.HourList.Clear();
-                       editHour.HourList = price;
-                       var bll = new BLL.ElecPrice();
-                       var isok = bll.Update(_elecPrice);
-                       if (isok)
-                       {
-                           this.currentViewModelBindingSource.ResetBindings(false);
-                           this.SetBindingData();
-                           return true;
-                       }
-                       return false;
-                   };
-                   dlg.ShowDialog();
-               }*/
+        public void EditElePrice()
+        {
+            var row = gridView1.GetCurrentViewModel(_allBindingList);
+            if (row == null)
+                return;
+            var editTime = _elecPrice.Settings;
+            var FindMonth = editTime.MonthList.Find(x => x.StartMonth == row.StartMonth && x.EndMonth == row.EndMonth);
+            var dlg = new EditElectricDlg();
+            dlg.SetBindingData(FindMonth.HourList);
+            dlg.ReLoadDataevent += async (price) =>
+            {
+                FindMonth.HourList.Clear();
+                FindMonth.HourList = price;
+                var bll = new BLL.ElecPrice();
+                var isok = await bll.Update(_elecPrice);
+                if (isok)
+                {
+                   this.SetBindingData();
+                    return true;
+                }
+                return false;
+            };
+            dlg.ShowDialog();
+        }
 
         /// <summary>
         /// 鍒犻櫎鐢佃垂
         /// </summary>
-        /*  public void DeletePrice()
-          {
-              var row = this.gridView1.GetCurrentViewModel(_allBindingList);
-              if (row == null)
-                  return;
-              if (XtraMessageBox.Show("纭畾瑕佸垹闄ゆ墍閫変腑?", "鎻愮ず", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) != DialogResult.OK)
-                  return;
+        public async void DeletePrice()
+        {
+            var row = this.gridView1.GetCurrentViewModel(_allBindingList);
+            if (row == null)
+                return;
+            if (XtraMessageBox.Show("纭畾瑕佸垹闄ゆ墍閫変腑?", "鎻愮ず", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) != DialogResult.OK)
+                return;
 
-              _elecPrice.Settings.MonthList.RemoveAll(x => x.StartMonth == row.StartMonth && x.EndMonth == row.EndMonth);
+            _elecPrice.Settings.MonthList.RemoveAll(x => x.StartMonth == row.StartMonth && x.EndMonth == row.EndMonth);
+            var isok = await new BLL.ElecPrice().Update(_elecPrice);
+            if (isok)
+            {
+                this.elecPriceViewModelBindingSource.ResetBindings(false);
+            }
+            this.SetBindingData();
+            this.elecPriceViewModelBindingSource.ResetBindings(false);
+            MessageBox.Show("鍒犻櫎鎴愬姛", "鎻愮ず");
+        }
 
-              var isok = new BLL.ElecPrice().Update(_elecPrice);
-              if (isok)
-              {
-                  this.currentViewModelBindingSource.ResetBindings(false);
-              }
-              this.SetBindingData();
-              this.currentViewModelBindingSource.ResetBindings(false);
-              MessageBox.Show("鍒犻櫎鎴愬姛", "鎻愮ず");
-          }*/
+        //鎺у埗鍙厑璁稿垎缁勫悎骞�
+        private void GridView1_CellMerge(object sender, DevExpress.XtraGrid.Views.Grid.CellMergeEventArgs e)
+        {
+            if (e.Column.FieldName == "BelongName")
+            {
+                // 鑾峰彇褰撳墠鍗曞厓鏍煎拰涓嬩竴涓崟鍏冩牸鐨勫��
+                var value1 = gridView1.GetRowCellValue(e.RowHandle1, e.Column);
+                var value2 = gridView1.GetRowCellValue(e.RowHandle2, e.Column);
+
+                // 濡傛灉涓や釜鍗曞厓鏍肩殑鍊肩浉绛夛紝鍒欏厑璁稿悎骞�
+                e.Merge = value1 != null && value1.Equals(value2);
+                e.Handled = true;
+            }
+            else
+            {
+                // 鍏朵粬鍒椾笉鍏佽鍚堝苟
+                e.Merge = false;
+                e.Handled = true;
+            }
+        }
+
+        private void BtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
+        {
+            EditElePrice();
+        }
+
+        private void BtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
+        {
+            DeletePrice();
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3