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 MgrWorkBenchMainValvePage : DocumentPage { public MgrWorkBenchMainValvePage() { InitializeComponent(); this.PageTitle.Caption = "测试台信息(阀)"; this._pageOperateInfo = "测试台信息列表"; this.gridViewMain.SetNormalEditView(35); this.gridViewMain.SetGridMianViewColor(); this.gridViewMain.RegistCustomDrawRowIndicator(); } 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); this.ID = work.ID; this.CreateUserID = work.CreateUserID; this.CreateTime = work.CreateTime; this.UpdateUserID = work.UpdateUserID; this.UpdateTime = work.UpdateTime; this.Code = work.Code; this.Name = work.Name; this.ProductStyleID = work.ProductStyleID; this.LastUseTime = work.LastUseTime; this.LastUseUserID = work.LastUseUserID; this.UseStatus = work.UseStatus; this.PipeParas = work.PipeParas; var pipeParas = new Model.PipeParas4Valve(work.PipeParas); if (pipeParas != null) { if (pipeParas.DiaP1 != null) this.DiaP1 = pipeParas.DiaP1.ToString(); if (pipeParas.DiaP2 != null) this.DiaP2 = pipeParas.DiaP2.ToString(); if (pipeParas.DiaP3 != null) this.DiaP3 = pipeParas.DiaP3.ToString(); } if (work.LinkType == Model.eLinkType.ShunZhou) { LinkTypeName = "无线 (SZ)"; } if (work.LinkType == Model.eLinkType.KeDi) { LinkTypeName = "有线 (KD)";// string.Format("有线 KD ({0})", work.LinkTag); } } public string DiaP1 { get; set; } public string DiaP2 { get; set; } public string DiaP3 { get; set; } public string ProductStyleName { get; set; } public string LastUseUserName { get; set; } public string TestTypeName { get; set; } public string LinkTypeName { 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.Valve); var works = new BLL.WorkBenchBase().GetByProductType(Model.eProductType.Valve); 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 barBtnAddPump_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { AddWorkBench(); } private void AddWorkBench() { WaitFrmHelper.ShowWaitForm(); var dlg = new AddWorkBench4ValveDlg(); 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("添加测试台"); dlg.ShowDialog(); ShowCmdOperateInfo(_pageOperateInfo); } //编辑 private void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var row = this.gridViewMain.GetCurrentViewModel(_bindList); if (row == null) { XtraMessageBox.Show("未选择数据!"); ShowCmdOperateInfo("未选择数据!"); return; } if (row.ProductType != Model.eProductType.Valve) { return; } WaitFrmHelper.ShowWaitForm(); var dlg = new EditWorkBench4ValveDlg(); 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) ); } this.gridViewMain.RefreshData(); XtraMessageBox.Show("更新成功!"); }; 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("未选择数据!"); ShowCmdOperateInfo("未选择数据!"); return; } if (row.LastUseTime != 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; } 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("删除失败!"); } } //设置仪器 private void barButSetInstrument_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var row = this.gridViewMain.GetCurrentViewModel(_bindList); if (row == null) { XtraMessageBox.Show("未选择数据!"); 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 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 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.Valve) { 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); } } }