using DevExpress.XtraEditors;
|
using System.ComponentModel;
|
using System.Data;
|
|
namespace PBS.WinFrmUI
|
{
|
public partial class AddElectricDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public AddElectricDlg()
|
{
|
InitializeComponent();
|
}
|
|
private BindingList<Vmo.ElecPriceHourSetting> _allBindingList = null; //这就是输入进去立马就获取到的值
|
|
public event Func<Vmo.ElecPriceMonthSetting, Task<bool>> ReloadDataEvent;
|
|
public void SetBindingData()
|
{
|
_allBindingList = new BindingList<Vmo.ElecPriceHourSetting>();
|
this.bindingSource1.DataSource = _allBindingList;
|
}
|
|
//验证
|
private bool verify()
|
{
|
this.dxErrorProvider1.ClearErrors();
|
if (string.IsNullOrEmpty(this.txtStartMonth.Text))
|
{
|
this.dxErrorProvider1.SetError(this.txtStartMonth, "必填项");
|
return false;
|
}
|
if (string.IsNullOrEmpty(this.txtEndMonth.Text))
|
{
|
this.dxErrorProvider1.SetError(this.txtEndMonth, "必填项");
|
return false;
|
}
|
var AllHour = _allBindingList;
|
var hour = AllHour.OrderBy(x => x.EndHour).ToList();
|
var HourCount = hour.Count;
|
if (hour.First().StartHour != 0 || hour.Last().EndHour != 24)
|
{
|
XtraMessageBox.Show("开始时间和结束时间有误");
|
return false;
|
}
|
for (int x = 0; x < hour.Count - 1; x++)
|
{
|
var frist = hour[x];
|
var second = hour[x + 1];
|
var last = hour[hour.Count - 1];
|
if (second.StartHour == second.EndHour)
|
{
|
XtraMessageBox.Show("开始时间和结束时间相同");
|
return false;
|
}
|
if (frist.EndHour != second.StartHour)
|
{
|
XtraMessageBox.Show("时间输入有误");
|
return false;
|
}
|
}
|
return true;
|
}
|
|
//确定
|
private async void btnOk_Click(object sender, EventArgs e)
|
{
|
if (!verify())
|
{
|
return;
|
}
|
if (this.ReloadDataEvent == null)
|
return;
|
var Eleprice = new Vmo.ElecPriceMonthSetting();
|
int Startmonth = 0;
|
if (!int.TryParse(this.txtStartMonth.Text, out Startmonth))
|
{
|
MessageBox.Show("输入有误");
|
return;
|
}
|
/* if (Startmonth > 11)
|
{
|
MessageBox.Show("开始月小于12");
|
return;
|
}
|
*/
|
Eleprice.StartMonth = Startmonth;
|
int Endmonth = 0;
|
if (!int.TryParse(this.txtEndMonth.Text, out Endmonth))
|
{
|
MessageBox.Show("输入有误");
|
return;
|
}
|
|
if (Endmonth < 1 || Endmonth > 12)
|
{
|
MessageBox.Show("请输入不小于1且不大于12的数字");
|
return;
|
}
|
/* if (Startmonth >=Endmonth)
|
{
|
MessageBox.Show("开始月不能小于或等于结束月");
|
return;
|
}*/
|
Eleprice.EndMonth = Endmonth;
|
Eleprice.HourList = _allBindingList.ToList();
|
var isok = await this.ReloadDataEvent.Invoke(Eleprice);
|
if (isok == false)
|
{
|
XtraMessageBox.Show("添加失败");
|
return;
|
}
|
XtraMessageBox.Show("添加成功");
|
this.DialogResult = System.Windows.Forms.DialogResult.OK;
|
this.Close();
|
}
|
|
//行删除
|
private void gridView2_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
|
{
|
if (_allBindingList == null || _allBindingList.Count < 1)
|
return;
|
var row = this.gridView2.GetFocusedRow() as Vmo.ElecPriceHourSetting;
|
if (row == null)
|
return;
|
if (e.Column == this.ColDelete)
|
_allBindingList.Remove(row);
|
}
|
}
|
}
|