using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
using DevExpress.XtraEditors;
|
|
namespace IStation.WinFrmUI.River
|
{
|
public partial class ReservoirParaRequestCtrl : XtraUserControl
|
{
|
public ReservoirParaRequestCtrl()
|
{
|
InitializeComponent();
|
|
rowDropFlow.Visible = false;
|
checkBox总量.Checked = true;
|
vGridControl1.Visible = false;
|
layoutControlItem3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
|
layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
|
btn保存为模板.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
|
layoutControlItem4.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
|
//rowNeedHeightMin.Visible = false;
|
//rowNeedHeightMax.Visible = false;
|
|
//hourBlockRangePanel.OnFreshTotalHour += (h) =>
|
//{
|
// barStaticItem总时间.Text = string.Format("总时间: {0} H", h);
|
//};
|
|
}
|
public class CurrentViewModel
|
{
|
public int Hour { get; set; }
|
|
public string DropFlow { get; set; }
|
public string NeedMinHeight { get; set; }
|
public string NeedMaxHeight { get; set; }
|
}
|
List<CurrentViewModel> _bindDataList;
|
|
private void ReservoirParaRequestCtrl_Load(object sender, EventArgs e)
|
{
|
vGridControl1.RecordWidth = 50;
|
|
|
// vGridControl1.RowHeaderWidth = 30;
|
// vGridControl1.RecordHeaderHeight = 300;
|
|
//hourBlockRangePanel.InitialTimeBlock();
|
_bindDataList = new List<CurrentViewModel>();
|
for(int i = 1; i < 25; i++)
|
{
|
_bindDataList.Add(new CurrentViewModel() { Hour = i });
|
}
|
|
//barEditItem用水总量.EditValue =
|
// Settings.AnaSetting.LastReservoirDropFlow;
|
this.bindingSource1.DataSource = _bindDataList;
|
|
|
Task.Run(() =>
|
{
|
var last3 = BLL.TotalWaterOut.GetLastDay3( );
|
if (last3 != null && last3.Count == 3)
|
{
|
this.Invoke(new Action(() =>
|
{
|
bci前一日记录.Checked = true;
|
bci前一日记录.Tag = Math.Round(last3[0], 1);
|
barEditItem用水总量.Text = Math.Round(last3[0], 1).ToString();
|
|
bci前三日记录.Checked = false ;
|
bci前三日记录.Tag = Math.Round((last3[0] + last3[1]+ last3[2])/3, 1);
|
}));
|
}
|
});
|
}
|
|
|
public List<double> GetFlowHourValues()
|
{
|
List<double> list = new List<double>();
|
if (checkBox总量.Checked)
|
{
|
if (barEditItem用水总量.EditValue == null)
|
return null;
|
|
var total = Convert.ToDouble(barEditItem用水总量.EditValue);
|
|
// Settings.AnaSetting.LastReservoirDropFlow = total;
|
// IStation.SettingsHelper.Save();
|
|
for (int i = 0; i < 24; i++)
|
{
|
list.Add(total / 24);
|
}
|
}
|
else
|
{
|
double total = 0;
|
for (int i = 0; i < 24; i++)
|
{
|
if (!string.IsNullOrEmpty(_bindDataList[i].DropFlow))
|
{
|
var flow = Convert.ToDouble(_bindDataList[i].DropFlow);
|
total = total + flow;
|
list.Add(flow);
|
}
|
|
}
|
if (total < 10)
|
{
|
return null;
|
}
|
}
|
|
|
return list;
|
}
|
|
public List<double?> GetMinLevelHourValues()
|
{
|
List<double?> list = new List<double?>();
|
|
for (int i = 0; i < 24; i++)
|
{
|
if (!string.IsNullOrEmpty(_bindDataList[i].NeedMinHeight))
|
{
|
var levl = Convert.ToDouble(_bindDataList[i].NeedMinHeight);
|
|
list.Add(levl);
|
}
|
else
|
{
|
list.Add(null);
|
}
|
}
|
return list;
|
}
|
|
public List<double?> GetMaxLevelHourValues()
|
{
|
List<double?> list = new List<double?>();
|
|
for (int i = 0; i < 24; i++)
|
{
|
if (!string.IsNullOrEmpty(_bindDataList[i].NeedMaxHeight))
|
{
|
var levl = Convert.ToDouble(_bindDataList[i].NeedMaxHeight);
|
|
list.Add(levl);
|
}
|
else
|
{
|
list.Add(null);
|
}
|
}
|
return list;
|
}
|
|
|
|
private void btn保存为模板_Click(object sender, EventArgs e)
|
{
|
SaveAsTemplate();
|
}
|
|
|
private bool _isInitialTemplateList = false;
|
private void popupContainerEdit1_QueryPopUp(object sender, System.ComponentModel.CancelEventArgs e)
|
{
|
if (!SettingsHelper.IsDesingMode())
|
{
|
if (_isInitialTemplateList)
|
return;
|
_isInitialTemplateList = true;
|
InitialTemplateList();
|
}
|
}
|
|
private void listBoxControl1_DoubleClick(object sender, EventArgs e)
|
{
|
//if (listBoxControl1.SelectedValue == null) return;
|
//var fileName = listBoxControl1.SelectedValue.ToString();
|
|
//var folderPath = System.IO.Path.Combine(IStation.DataFolderHelper.GetRootPath(), "ReservoirDropTemplate");
|
//if (!System.IO.Directory.Exists(folderPath))
|
//{
|
// return;
|
//}
|
//LoadTemplate(System.IO.Path.Combine(folderPath, fileName));
|
}
|
|
private void InitialTemplateList()
|
{
|
//var folderPath = System.IO.Path.Combine(IStation.DataFolderHelper.GetRootPath(), "ReservoirDropTemplate");
|
//if (!System.IO.Directory.Exists(folderPath))
|
//{
|
// return;
|
//}
|
|
//DirectoryInfo folder = new DirectoryInfo(folderPath);
|
//listBoxControl1.Items.Clear();
|
|
//foreach (FileInfo file in folder.GetFiles("*.json",
|
// SearchOption.AllDirectories))
|
//{
|
// // 处理每个文件
|
// this.listBoxControl1.Items.Add(file.Name);
|
//}
|
}
|
|
private void LoadTemplate(string filePath)
|
{
|
if (!System.IO.File.Exists(filePath))
|
{
|
return;
|
}
|
|
//文件流读取
|
System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open);
|
System.IO.StreamReader sr = new System.IO.StreamReader(fs, Encoding.GetEncoding("gb2312"));
|
var contents = sr.ReadToEnd();
|
sr.Close(); fs.Close();
|
|
var templates = JsonHelper.Json2Object<List<HourValue>>(contents);
|
if (templates == null) { return; }
|
|
|
//var def = _bindList.First();
|
//def.ClearHourValues();
|
//foreach (var item in templates)
|
//{
|
// def.HourValues[item.Hour] = item.Value;
|
//}
|
//this.bindingSource1.DataSource = _bindList;
|
//this.bindingSource1.ResetBindings(false);
|
}
|
private void SaveAsTemplate()
|
{
|
var rootFolder = System.IO.Path.Combine(IStation.DataFolderHelper.GetRootPath(),
|
"ReservoirDropTemplate");
|
if (!System.IO.Directory.Exists(rootFolder))
|
{
|
System.IO.Directory.CreateDirectory(rootFolder);
|
}
|
InputTemplateNameDlg frm = new InputTemplateNameDlg();
|
if (frm.ShowDialog() != DialogResult.OK)
|
return;
|
var name = frm.TemplateName;
|
|
|
//var values = GetUseHourValues();
|
//if (values == null || values.Count == 0)
|
// return;
|
|
//var fileContents = JsonHelper.Object2Json(values);
|
|
//var fileName = System.IO.Path.Combine(rootFolder, name.Trim() + ".json");
|
//if (System.IO.File.Exists(fileName))
|
//{
|
// System.IO.File.Delete(fileName);
|
//}
|
//StreamWriter streamWriter = new StreamWriter(fileName, false, System.Text.Encoding.GetEncoding("gb2312"));
|
|
//streamWriter.Write(fileContents);
|
|
//streamWriter.Flush();
|
//streamWriter.Close();
|
|
//MessageBox.Show("保存成功");
|
}
|
|
private void checkBox总量_CheckedChanged(object sender, EventArgs e)
|
{
|
barEditItem用水总量.Enabled = checkBox总量.Checked;
|
vGridControl1.Visible = !checkBox总量.Checked;
|
rowDropFlow.Visible = !checkBox总量.Checked;
|
}
|
|
private void bci前一日记录_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
bci前一日记录.Checked = true;
|
barEditItem用水总量.Text = Convert.ToDouble(bci前一日记录.Tag).ToString();
|
|
bci前三日记录.Checked = false;
|
}
|
|
private void bci前三日记录_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
bci前一日记录.Checked = false;
|
barEditItem用水总量.Text = Convert.ToDouble(bci前三日记录.Tag).ToString();
|
|
bci前三日记录.Checked = true;
|
}
|
}
|
}
|