using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
namespace TProduct.WinFrmUI.TestBench
{
///
///
///
public partial class MgrWorkBenchMainPumpPage : DocumentPage
{
public MgrWorkBenchMainPumpPage()
{
InitializeComponent();
this.PageTitle.Caption = "测试台信息(泵)";
this._pageOperateInfo = "测试台信息列表";
this.gridViewMain.SetNormalEditView(35);
this.gridViewMain.SetGridMianViewColor();
this.gridViewMain.RegistCustomDrawRowIndicator();
//this.gridViewMain.RowClick += new DevExpress.XtraGrid.Views.Grid.RowClickEventHandler(this.GridViewMain_RowClick);
//this.gridViewMain.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(this.GridViewMain_CustomDrawRowIndicator);
//this.gridViewMain.CustomUnboundColumnData += new DevExpress.XtraGrid.Views.Base.CustomColumnDataEventHandler(this.GridViewMain_CustomUnboundColumnData);
//this.gridViewMain.DoubleClick += new System.EventHandler(this.GridViewMain_DoubleClick);
//this.gridViewMain.RowCellClick += new DevExpress.XtraGrid.Views.Grid.RowCellClickEventHandler(this.GridViewMain_RowCellClick);
}
private class CurrentViewModel : Model.WorkBenchBase
{
public CurrentViewModel() { }
public CurrentViewModel(
Model.WorkBenchBase work) : base(work)
{
Reset(work);
}
public override void Reset(
Model.WorkBenchBase work)
{
base.Reset(work);
var pipeParas = new Model.PipeParas4Pump(work.PipeParas);
if (pipeParas != null)
{
if (pipeParas.InletDia != null)
this.InletDia = pipeParas.InletDia.ToString();
if (pipeParas.OutletDia != null)
this.OutletDia = pipeParas.OutletDia.ToString();
}
if (work.LinkType == Model.eLinkType.ShunZhou)
{
LinkTypeName = "无线 (SZ)";
}
if (work.LinkType == Model.eLinkType.KeDi)
{
LinkTypeName = "有线 (KD)";// string.Format("有线 KD ({0})", work.LinkTag);
}
if (work.TestType == null || work.TestType.Count() == 0)
this.TestTypeName = "性能测试";
else if (work.TestType.Contains(Model.eTestType.FeatTest) &&
work.TestType.Contains(Model.eTestType.NpshTest))
{
this.TestTypeName = "性能测试,汽蚀测试";
}
else if (work.TestType.Contains(Model.eTestType.FeatTest) &&
!work.TestType.Contains(Model.eTestType.NpshTest))
{
this.TestTypeName = "性能测试";
}
else if (!work.TestType.Contains(Model.eTestType.FeatTest) &&
work.TestType.Contains(Model.eTestType.NpshTest))
{
this.TestTypeName = "汽蚀测试";
}
}
public string OutletDia { get; set; }
public string InletDia { get; set; }
public string ProductStyleName { get; set; }
public string TestTypeName { get; set; }
public string LinkTypeName { get; set; }
public string LastUseUserName { get; set; }
public void SetProductStyle(IEnumerable styles)
{
if (styles == null || styles.Count() == 0)
this.ProductStyleName = "";
else
this.ProductStyleName = String.Join(",", from x in styles select x.Name);
}
}
private List _bindList = null;
private List _allProductStyle = null;
///
/// 初始化
///
public override void InitialDataSource()
{
WaitFrmHelper.ShowWaitForm();
_allProductStyle = new BLL.ProductStyle().GetByProductType(Model.eProductType.Pump);
var works = new BLL.WorkBenchBase().GetByProductType(Model.eProductType.Pump);
if (works == null)
works = new List();
var mans = new BLL.LoginUser().GetAll();
_bindList = new List();
foreach (var work in works)
{
var v = new CurrentViewModel(work);
if (work.LastUseUserID > 0)
v.LastUseUserName = (from x in mans where x.ID == work.LastUseUserID select x.RealName).FirstOrDefault();
if (work.ProductStyleID != null)
{
v.SetProductStyle(
_allProductStyle.
Where(s => work.ProductStyleID.Contains(s.ID)).
Select(x => x));
}
_bindList.Add(v);
}
this.bindingSource1.DataSource = _bindList;
this.bindingSource1.ResetBindings(false);
WaitFrmHelper.HideWaitForm();
}
#region 按钮事件
//添加
private void barSubItemAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
WaitFrmHelper.ShowWaitForm();
var dlg = new AddWorkBench4PumpDlg();
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
dlg.SetBindingData();
dlg.ReloadDataEvent += (work) =>
{
var vm = new CurrentViewModel(work);
if (_bindList == null)
_bindList = new List();
if (work.ProductStyleID != null)
{
vm.SetProductStyle(
_allProductStyle.
Where(s => work.ProductStyleID.Contains(s.ID)).
Select(x => x));
}
_bindList.Add(vm);
this.bindingSource1.ResetBindings(false);
XtraMessageBox.Show("添加成功!");
ShowCmdOperateInfo("添加成功!");
};
ShowCmdOperateInfo("添加测试台");
dlg.ShowDialog();
ShowCmdOperateInfo(_pageOperateInfo);
}
//复制
private void barBtnCopy_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var row = this.gridViewMain.GetCurrentViewModel(_bindList);
if (row == null)
{
XtraMessageBox.Show("未选择数据!");
ShowCmdOperateInfo("未选择数据!");
return;
}
ShowCmdOperateInfo("复制测试台:" + row.Name);
DialogResult dr = XtraMessageBox.Show("是否复制测试台:" + row.Name, "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr != DialogResult.Yes)
{
ShowCmdOperateInfo(_pageOperateInfo);
return;
}
new BLL.WorkBenchBase().Copy(row);
this.InitialDataSource();
MessageBox.Show("已复制");
ShowCmdOperateInfo(_pageOperateInfo);
}
//编辑
private void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var row = this.gridViewMain.GetCurrentViewModel(_bindList);
if (row == null)
{
XtraMessageBox.Show("未选择数据!");
return;
}
if (row.ProductType != Model.eProductType.Pump)
{
return;
}
WaitFrmHelper.ShowWaitForm();
var dlg = new EditWorkBench4PumpDlg();
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
dlg.SetBindingData(row);
dlg.ReloadDataEvent += (work) =>
{
row.Reset(work);
if (work.ProductStyleID != null)
{
row.SetProductStyle(
_allProductStyle.
Where(s => work.ProductStyleID.Contains(s.ID)).
Select(x => x)
);
}
else
{
}
this.gridViewMain.RefreshData();
ShowCmdOperateInfo("更新成功!");
};
ShowCmdOperateInfo("编辑测试台信息!");
dlg.ShowDialog();
ShowCmdOperateInfo(_pageOperateInfo);
}
//
private void barButSetModel3d_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var row = this.gridViewMain.GetCurrentViewModel(_bindList);
if (row == null)
{
XtraMessageBox.Show("未选择数据!");
return;
}
if (row.ProductType != Model.eProductType.Pump)
{
return;
}
WaitFrmHelper.ShowWaitForm();
var dlg = new EditWorkBench4Mode3dDlg();
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
dlg.SetBindingData(row);
dlg.ReloadDataEvent += (work) =>
{
row.Reset(work);
this.gridViewMain.RefreshData();
ShowCmdOperateInfo("更新成功!");
};
ShowCmdOperateInfo("编辑测试台信息!");
dlg.ShowDialog();
ShowCmdOperateInfo(_pageOperateInfo);
}
//删除
private void barBtnDel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var row = this.gridViewMain.GetCurrentViewModel(_bindList);
if (row == null)
{
XtraMessageBox.Show("未选择数据!");
return;
}
if (row.LastUseTime != null)
{
XtraMessageBox.Show("该数据已经被使用,无法删除!");
return;
}
ShowCmdOperateInfo("删除测试台:" + row.Name);
DialogResult dr = XtraMessageBox.Show("是否删除测试台:" + row.Name, "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr != DialogResult.Yes)
{
ShowCmdOperateInfo(_pageOperateInfo);
return;
}
WaitFrmHelper.ShowWaitForm();
var result = new BLL.WorkBenchBase().Delete(row);
if (result)
{
_bindList.Remove(row);
this.bindingSource1.ResetBindings(false);
WaitFrmHelper.HideWaitForm();
XtraMessageBox.Show("删除成功!");
ShowCmdOperateInfo("删除成功!");
}
else
{
WaitFrmHelper.HideWaitForm();
XtraMessageBox.Show("删除失败!");
ShowCmdOperateInfo("删除失败!");
}
ShowCmdOperateInfo(_pageOperateInfo);
}
//设置仪器
private void barButSetInstrument_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var row = this.gridViewMain.GetCurrentViewModel(_bindList);
if (row == null)
{
XtraMessageBox.Show("未选择数据!");
ShowCmdOperateInfo("未选择数据!");
return;
}
if (row.LinkType == Model.eLinkType.ShunZhou)
{
WaitFrmHelper.ShowWaitForm();
var dlg = new TProduct.WinFrmUI.TestBench.SetAllInstruments4ShunDlg();
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
dlg.SetBindingData(row);
ShowCmdOperateInfo("设置仪器");
dlg.ShowDialog();
ShowCmdOperateInfo(_pageOperateInfo);
}
else if (row.LinkType == Model.eLinkType.KeDi)
{
WaitFrmHelper.ShowWaitForm();
var dlg = new TProduct.WinFrmUI.TestBench.SetAllInstruments4KeDiDlg();
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
dlg.SetBindingData(row);
ShowCmdOperateInfo("设置仪器");
dlg.ShowDialog();
ShowCmdOperateInfo(_pageOperateInfo);
}
}
//设置测点
private void barButPoint_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var row = this.gridViewMain.GetCurrentViewModel(_bindList);
if (row == null)
{
XtraMessageBox.Show("未选择数据!");
ShowCmdOperateInfo("未选择数据!");
return;
}
var dlg = new MgrWorkBenchMonitorPointDlg();
dlg.SetBindingData(row);
ShowCmdOperateInfo("设置测点");
dlg.ShowDialog();
ShowCmdOperateInfo(_pageOperateInfo);
}
// 刷新
private void barButReset_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
this.InitialDataSource();
MessageBox.Show("已刷新");
ShowCmdOperateInfo(_pageOperateInfo + ":数据已刷新");
}
#endregion
private void bbi进出口测点配置列表_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
WaitFrmHelper.ShowWaitForm();
var dlg = new MgrPumpBenchPressMonitorDlg();
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
dlg.SetBindingData();
ShowCmdOperateInfo("进出口测点配置");
dlg.ShowDialog();
ShowCmdOperateInfo(_pageOperateInfo);
}
}
}