using DevExpress.XtraEditors; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; namespace IStation.WinFrmUI.CalcErQu { public partial class SetPrjItemSpanTimeGrid : XtraUserControl { public SetPrjItemSpanTimeGrid() { InitializeComponent(); this.bandedGridView1.RowHeight = 35; this.bandedGridView1.InitNewRow += new DevExpress.XtraGrid.Views.Grid.InitNewRowEventHandler(this.gridView1_InitNewRow); } public Action> OnRefreshData = null; private DateTime _startTime,_endTime; internal void SetAnaDay(DateTime rangeStartTime, DateTime rangeEndTime) { _startTime = rangeStartTime; _endTime = rangeEndTime; } internal void SetBindingData( CalcModel.AnaPrj anaPrj) { if (anaPrj == null) return; _startTime = anaPrj.StartTime; _endTime = anaPrj.EndTime; if (_bindList == null) _bindList = new BindingList(); else _bindList.Clear(); for (int i = 0; i < anaPrj.BlockTimes.Count(); i++) { _bindList.Add(new CurrentViewModel( anaPrj.BlockTimes[i].OpenPumpCount, anaPrj.BlockTimes[i].StartTime, anaPrj.BlockTimes[i].EndTime)); } this.bindingSource1.DataSource = _bindList; this.bindingSource1.ResetBindings(false); } internal void SetBindingData(List list) { if (_bindList == null) _bindList = new BindingList(); else _bindList.Clear(); foreach (var item in list) { var vm = new CurrentViewModel(); vm.PumpNumber = item.PumpNumber; vm.StartH = item.StartTime.Hour; vm.StartM = item.StartTime.Minute; vm.EndH = item.EndTime.Hour; vm.EndM = item.EndTime.Minute; vm.StartDay = item.StartTime; vm.EndDay = item.EndTime; _bindList.Add(vm); } this.bindingSource1.DataSource = _bindList; } public class CurrentViewModel { public CurrentViewModel() { } public CurrentViewModel(int pumpNumber, DateTime start, DateTime end) { PumpNumber = pumpNumber; StartDay = start; EndDay = end; StartH = start.Hour; StartM = start.Minute; EndH = end.Hour; EndM = end.Minute; } public int PumpNumber { get; set; } public DateTime StartDay { get; set; } public DateTime EndDay { get; set; } public int? StartH { get; set; } public int? StartM { get; set; } = 0; public int? EndH { get; set; } public int? EndM { get; set; } = 0; public double Duration { get { return Math.Round((EndDay - StartDay).TotalHours, 1); } } } private BindingList _bindList; private void AddManuPrjDlg_Load(object sender, EventArgs e) { if(_bindList == null) { _bindList = new BindingList(); this.bindingSource1.DataSource = _bindList; this.bandedGridView1.RowHeight = 35; } } public List GetPumpRunRange() { if (_bindList.Count == 0) { return null; } var vm_list = new List(); foreach (var m in _bindList) { if (m.PumpNumber <= 0) continue; if (m.StartH == null && m.EndH == null) { continue; } CalcModel.PumpRunRange v = new CalcModel.PumpRunRange(); v.PumpNumber = m.PumpNumber; int StartH = m.StartH == null ? _startTime.Hour : m.StartH.Value; int StartM = m.StartM == null ? 0 : m.StartM.Value; v.StartTime = new DateTime(m.StartDay.Year, m.StartDay.Month, m.StartDay.Day, StartH, StartM, 0); int EndH = m.EndH == null ? _endTime.Hour : m.EndH.Value; int EndM = m.EndM == null ? 0 : m.EndM.Value; if (EndH >= 24) { v.EndTime = new DateTime(m.EndDay.Year, m.EndDay.Month, m.EndDay.Day); v.EndTime = v.EndTime.AddDays(1); } else { v.EndTime = new DateTime(m.EndDay.Year, m.EndDay.Month, m.EndDay.Day, EndH, EndM, 0); } if (v.StartTime > v.EndTime) { continue; } vm_list.Add(v); } return vm_list; } private void gridView1_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e) { bandedGridView1.SetRowCellValue(e.RowHandle, colStartDay, this._startTime.Date); bandedGridView1.SetRowCellValue(e.RowHandle, colEndDay, this._startTime.Date); bandedGridView1.SetRowCellValue(e.RowHandle, colStartH, this._startTime.Hour); bandedGridView1.SetRowCellValue(e.RowHandle, colEndH, this._startTime.Hour); } /// /// /// /// /// private void repositoryItemImageComboBox1_SelectedIndexChanged(object sender, EventArgs e) { var row = this.bandedGridView1.FocusedRowObject as IStation.WinFrmUI.CalcErQu.SetPrjItemSpanTimeGrid.CurrentViewModel; if (row == null) return; var sel_combox = sender as DevExpress.XtraEditors.ImageComboBoxEdit; row.PumpNumber = Convert.ToInt32(sel_combox.EditValue); if (OnRefreshRangePumpCount != null) { OnRefreshRangePumpCount(row.StartDay, row.EndDay, row.PumpNumber); } } public Action OnRefreshRangePumpCount; } }