using DevExpress.XtraEditors;
|
using DevExpress.XtraGrid.Views.Grid;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Drawing;
|
using System.Linq;
|
using System.Windows.Forms;
|
|
namespace TProduct.WinFrmUI.Data4Factory
|
{
|
/// <summary>
|
/// 泵
|
/// </summary>
|
public partial class ProductPumpAndPartMgrPage : DocumentPage
|
{
|
protected Eventech.Model.UnitQ flow_unit = Eventech.Model.UnitQ.M3H;
|
public ProductPumpAndPartMgrPage()
|
{
|
InitializeComponent();
|
this.PageTitle.Caption = "泵管理";
|
this._pageOperateInfo = "泵列表";
|
this.gridView1.SetNormalView();
|
this.gridView1.SetGridMianViewColor();
|
this.gridView1.RegistCustomDrawRowIndicator();
|
this.gridView1.OptionsView.ShowViewCaption = false;
|
this.gridView1.OptionsView.ShowDetailButtons = true;
|
|
this.gridView2.SetNormalView();
|
this.gridView2.SetGridSubViewColor();
|
this.gridView1.OptionsView.EnableAppearanceOddRow = true; // 使能 // 和和上面绑定 同时使用有效
|
this.gridView1.Appearance.EvenRow.BackColor = Color.LightGray; // 设置偶数行颜色
|
this.gridView1.OptionsView.EnableAppearanceEvenRow = true;
|
this.gridView1.Appearance.OddRow.BackColor = Color.White; // 设置偶数行颜色
|
|
this.gridView2.OptionsView.EnableAppearanceOddRow = true; // 使能 // 和和上面绑定 同时使用有效
|
this.gridView2.Appearance.EvenRow.BackColor = Color.White; // 设置偶数行颜色
|
this.gridView2.OptionsView.EnableAppearanceEvenRow = true;
|
this.gridView2.Appearance.OddRow.BackColor = Color.White; // 设置偶数行颜色
|
|
this.colSdName.Visible = TProduct.UserSetting.Setting.Disp.IsShowSender;
|
this.colMfName.Visible = TProduct.UserSetting.Setting.Disp.IsShowManufacturer;
|
|
flow_unit = TProduct.UserSetting.Setting.PumpTest.UnitFlow;
|
colQ.Caption = string.Format("流量({0})", Eventech.Common.UnitQHelper.GetEnUnitName(flow_unit));
|
|
}
|
|
#region 当前视图
|
|
public class CurrentViewModel : Model.ProductMainExPump
|
{
|
Eventech.Model.UnitQ _flow_unit;
|
public CurrentViewModel() { }
|
public CurrentViewModel(Eventech.Model.UnitQ flow_unit, Model.ProductMainExPump rhs) : base(rhs)
|
{
|
|
_flow_unit = flow_unit;
|
}
|
|
public override void Reset(Model.ProductMainExPump rhs)
|
{
|
base.Reset(rhs);
|
}
|
#region 泵界面参数
|
|
public string strQ
|
{
|
get
|
{
|
var m3h = Model.RatedParas4Pump.ToModel(RatedParas).Q;
|
return m3h > 0 ?
|
Math.Round(Eventech.Common.UnitQHelper.fromM3H(
|
_flow_unit, m3h), 4).ToString() : "";
|
}
|
}
|
public string strH
|
{
|
get
|
{
|
return Model.RatedParas4Pump.ToModel(RatedParas).H > 0 ? Model.RatedParas4Pump.ToModel(RatedParas).H.ToString() : "";
|
}
|
}
|
|
public string strN
|
{
|
get
|
{
|
if (this.Ratedn > -1)
|
return this.Ratedn.ToString();
|
else
|
return "";
|
}
|
}
|
public string strD2
|
{
|
get
|
{
|
if (this.D2 > -1)
|
return this.D2.ToString();
|
else
|
return "";
|
}
|
}
|
public string strPosiAngle
|
{
|
get
|
{
|
if (this.PosiAngle > -1)
|
return this.PosiAngle.ToString();
|
else
|
return "";
|
}
|
}
|
|
public string MainCreateTime
|
{
|
get
|
{
|
var A = DateTime.Compare(this.CreateTime, Convert.ToDateTime("2008-8-8"));
|
if (A > 0)
|
{
|
return this.CreateTime.ToString("yyyy-MM-dd HH:mm");
|
}
|
else
|
return "";
|
}
|
}
|
public string MianUpdateTime
|
{
|
get
|
{
|
var A = DateTime.Compare(this.UpdateTime, Convert.ToDateTime("2008-8-8"));
|
if (A > 0)
|
{
|
return this.UpdateTime.ToString("yyyy-MM-dd HH:mm");
|
}
|
else
|
return "";
|
}
|
}
|
public List<CurrentViewModelSub> CurrentViewModelSubList { get; set; }
|
|
public string MotorName { get; set; }
|
public string UpadteName { get; set; }
|
public string CreateName { get; set; }
|
#endregion
|
}
|
|
public class CurrentViewModelSub : Model.PartBase
|
{
|
public CurrentViewModelSub(Model.PartBase rhs) : base(rhs) { }
|
|
public override void Reset(Model.PartBase rhs)
|
{
|
base.Reset(rhs);
|
}
|
#region 产品界面参数
|
public string strLastTestTime
|
{
|
get
|
{
|
if (this.LastTestTime != null)
|
{
|
return this.LastTestTime.Value.ToString("yyyy-MM-dd");
|
}
|
else
|
return "";
|
}
|
}
|
public string PartCreateTime
|
{
|
get
|
{
|
var A = DateTime.Compare(this.CreateTime, Convert.ToDateTime("2008-8-8"));
|
if (A > 0)
|
{
|
return this.CreateTime.ToString("yyyy-MM-dd HH:mm");
|
}
|
else
|
return "";
|
}
|
}
|
public string PartUpdateTime
|
{
|
get
|
{
|
var A = DateTime.Compare(this.UpdateTime, Convert.ToDateTime("2008-8-8"));
|
if (A > 0)
|
{
|
return this.UpdateTime.ToString("yyyy-MM-dd HH:mm");
|
}
|
else
|
return "";
|
}
|
}
|
public string MfName { get; set; }
|
public string SdName { get; set; }
|
public string LastRealName { get; set; }
|
public string UpadteName { get; set; }
|
public string CreateName { get; set; }
|
#endregion
|
}
|
|
#endregion
|
|
private List<CurrentViewModel> _bindList = null;//所有列表
|
private Model.ProductSeries _series = null;
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public override void InitialDataSource()
|
{
|
this.productTypeListCtr.SetBindData(Model.eProductType.Pump);
|
}
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="SeriesID"></param>
|
public void SetBindingData(long SeriesID)
|
{
|
_bindList = new List<CurrentViewModel>();
|
var allPumps = new BLL.ProductPump().GetExBySeriesID(SeriesID);
|
if (allPumps == null || allPumps.Count() == 0)
|
{
|
this.currentViewModelBindingSource.DataSource = _bindList;
|
this.currentViewModelBindingSource.ResetBindings(false);
|
return;
|
}
|
|
foreach (var pumpitem in allPumps)
|
{
|
var vm = new CurrentViewModel(flow_unit, pumpitem);
|
BuildViewModel(vm);
|
_bindList.Add(vm);
|
}
|
this.currentViewModelBindingSource.DataSource = _bindList;
|
this.currentViewModelBindingSource.ResetBindings(false);
|
}
|
|
#region 基础功能
|
|
//添加
|
private void barBtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_series == null)
|
{
|
XtraMessageBox.Show("您必须选择一个设备系列才能进行此项操作");
|
ShowCmdOperateInfo("您必须选择一个设备系列才能进行此项操作");
|
return;
|
}
|
if (_bindList == null)
|
_bindList = new List<CurrentViewModel>();
|
int max_sortCode = 1;
|
if (_bindList.Count() > 0)
|
max_sortCode = _bindList.Max(x => x.SortCode) + 1;
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new AddProductPumpDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(_series, max_sortCode);
|
|
dlg.ReloadDataEvent += (pump, motor) =>
|
{
|
_allPartList = new BLL.PartBase().GetAll();
|
_allProductMainList = new BLL.ProductMain().GetAll();
|
|
_bindList.Add(BuildViewModel(new CurrentViewModel(flow_unit, pump)));
|
ShowCmdOperateInfo("添加成功!");
|
XtraMessageBox.Show("添加成功!");
|
this.currentViewModelBindingSource.ResetBindings(false);
|
this.gridView1.RefreshData();
|
};
|
ShowCmdOperateInfo("添加泵信息");
|
dlg.ShowDialog();
|
ShowCmdOperateInfo(_pageOperateInfo);
|
}
|
|
//编辑
|
private void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_bindList == null || _bindList.Count < 1)
|
return;
|
var vm = this.gridView1.GetCurrentViewModel(_bindList);
|
if (vm == null)
|
{
|
XtraMessageBox.Show("您必须选择一个泵才能进行此项操作.");
|
ShowCmdOperateInfo("您必须选择一个泵才能进行此项操作");
|
return;
|
}
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new EditProductPumpDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(vm);
|
dlg.ReloadDataEvent += (pump, isChangePart, motor) =>
|
{
|
if (isChangePart)
|
{
|
_allPartList = new BLL.PartBase().GetAll();
|
_allProductMainList = new BLL.ProductMain().GetAll();
|
}
|
|
vm.Reset(pump);
|
|
BuildViewModel(vm);
|
ShowCmdOperateInfo("更新成功!");
|
XtraMessageBox.Show("更新成功!");
|
this.currentViewModelBindingSource.ResetBindings(false);
|
this.gridView1.RefreshData();
|
};
|
ShowCmdOperateInfo("编辑泵信息");
|
dlg.ShowDialog();
|
ShowCmdOperateInfo(_pageOperateInfo);
|
}
|
|
|
//详情
|
private void barBtnDictTypeView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
}
|
|
//删除
|
private void barBtnDictTypeDel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_bindList == null || _bindList.Count < 1)
|
return;
|
WaitFrmHelper.ShowWaitForm();
|
var row = this.gridView1.GetCurrentViewModel(_bindList);
|
if (row == null)
|
{
|
WaitFrmHelper.ShowWaitForm();
|
XtraMessageBox.Show("请选择一行数据!");
|
ShowCmdOperateInfo("请选择一行数据!");
|
return;
|
}
|
|
ShowCmdOperateInfo("删除数据:" + row.Name);
|
DialogResult dr = XtraMessageBox.Show("您确定要删除'" + row.Name + "'这条数据吗?\n(注:如果当前选中设备下仍有产品数据则不能将其删除.)", "删除提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
|
if (dr != DialogResult.OK)
|
{
|
ShowCmdOperateInfo(_pageOperateInfo);
|
return;
|
}
|
var partList = new BLL.PartBase().GetByProductMainID(row.ID);
|
if (partList.Count() > 0)
|
{
|
XtraMessageBox.Show("删除失败,当前选中项下仍有产品数据!");
|
ShowCmdOperateInfo("删除失败,当前选中项下仍有产品数据!");
|
return;
|
}
|
if (!new BLL.ProductPump().DeleteEx(row.ID))
|
{
|
XtraMessageBox.Show("Error:340,删除失败!");
|
ShowCmdOperateInfo("Error:340,删除失败!");
|
return;
|
}
|
SetBindingData(this._series.ID);
|
XtraMessageBox.Show("删除成功!");
|
ShowCmdOperateInfo(_pageOperateInfo);
|
}
|
|
|
#endregion
|
|
#region GridView
|
|
//设备列表
|
private GridView SysDataView = new GridView();
|
|
private void gridView1_MasterRowExpanded(object sender, CustomMasterRowEventArgs e)
|
{
|
this.SysDataView = this.gridView1.GetDetailView(e.RowHandle, e.RelationIndex) as GridView;
|
this.SysDataView.HorzScrollStep = this.SysDataView.RowCount;
|
}
|
private void barBtnExcelDown_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
ShowCmdOperateInfo("导出信息到Excel");
|
var path = ExcelSaveFilePathHelper.SaveFilePathName();
|
ShowCmdOperateInfo(_pageOperateInfo);
|
if (string.IsNullOrEmpty(path)) return;
|
gridView1.OptionsPrint.PrintDetails = true;//导出明细
|
gridView1.OptionsPrint.ExpandAllDetails = true;//导出所有明细,false的话,只会导出展开的明细
|
gridControl1.ExportToXlsx(path, new DevExpress.XtraPrinting.XlsxExportOptionsEx() { ExportType = DevExpress.Export.ExportType.WYSIWYG, TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text });
|
DialogResult dr = XtraMessageBox.Show("导出成功!是否打开刚刚保存的Excel文件?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
|
if (dr != DialogResult.OK)
|
return;
|
System.Diagnostics.Process.Start(path);
|
}
|
|
#endregion
|
|
private void seriesListCtrl_FocusedDataChangedEvent(Model.ProductSeries obj)
|
{
|
if (obj == null)
|
return;
|
SetBindingData(obj.ID);
|
if (obj.IsInnerMotor == 1)
|
{
|
colMotorName.Visible = false;
|
}
|
else
|
{
|
colMotorName.Visible = true;
|
}
|
_series = obj ;
|
}
|
List<Model.Senderbase> _allSenderList = null;
|
List<Model.ManufacturerBase> _allManufacturerList = null;
|
List<Model.LoginUser> _allUserList = null;
|
List<Model.PartBase> _allPartList = null;
|
List<Model.ProductMain> _allProductMainList = null;
|
private CurrentViewModel BuildViewModel(CurrentViewModel viewmodel)
|
{
|
if (_allManufacturerList == null)
|
{
|
_allManufacturerList = new BLL.ManufacturerBase().GetAll();
|
}
|
if (_allSenderList == null)
|
{
|
_allSenderList = new BLL.Senderbase().GetAll();
|
}
|
if (_allUserList == null)
|
{
|
_allUserList = new BLL.LoginUser().GetAll();
|
}
|
if (_allPartList == null)
|
{
|
_allPartList = new BLL.PartBase().GetAll();
|
}
|
if (_allProductMainList == null)
|
_allProductMainList = new BLL.ProductMain().GetAll();
|
|
viewmodel.UpadteName = _allUserList.Find(x => x.ID == viewmodel.UpdateUserID)?.RealName;
|
viewmodel.CreateName = _allUserList.Find(x => x.ID == viewmodel.UpdateUserID)?.RealName;
|
|
if (viewmodel.MotorMainID == null || viewmodel.MotorMainID < 1)
|
{
|
viewmodel.MotorName = "未设置电机";
|
}
|
else
|
{
|
var motor = _allProductMainList.Find(x => x.ID == viewmodel.MotorMainID);
|
if (motor == null)
|
{
|
viewmodel.MotorName = "电机数据已丢失";
|
}
|
else
|
{
|
viewmodel.MotorName = motor.Name;
|
}
|
}
|
|
var parts = _allPartList.Where(x => x.ProductMainID == viewmodel.ID);
|
if (parts != null && parts.Count() > 0)
|
{
|
viewmodel.CurrentViewModelSubList = new List<CurrentViewModelSub>();
|
foreach (var part in parts)
|
{
|
var vm_part = new CurrentViewModelSub(part);
|
if (part.ManufacturerID > 0)
|
{
|
var Manufacturer = _allManufacturerList.Find(m => m.ID == part.ManufacturerID);
|
vm_part.MfName = Manufacturer?.ShortName == "" ? Manufacturer?.FullName : Manufacturer?.ShortName;
|
}
|
if (part.SenderID > 0)
|
{
|
var Sender = _allSenderList.Find(s => s.ID == part.SenderID);
|
vm_part.SdName = Sender?.ShortName == "" ? Sender?.FullName : Sender?.ShortName;
|
}
|
if (part.LastTestUserID > 0)
|
vm_part.LastRealName = _allUserList.Find(x => x.ID == part.LastTestUserID)?.RealName;
|
viewmodel.CurrentViewModelSubList.Add(vm_part);
|
}
|
}
|
|
return viewmodel;
|
}
|
|
|
private void ProductPumpAndPartMgrPage_Load(object sender, EventArgs e)
|
{
|
//ShowCmdOperateInfo(_pageOperateInfo);
|
}
|
|
private void bbiImport样本曲线_EXCEL_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
var vm = this.gridView1.GetCurrentViewModel(_bindList);
|
if (vm == null)
|
{
|
XtraMessageBox.Show("您必须选择一个泵才能进行此项操作.");
|
ShowCmdOperateInfo("您必须选择一个泵才能进行此项操作");
|
return;
|
}
|
SampleCurveByExcelDlg frm = new SampleCurveByExcelDlg();
|
frm.SetBindingData(vm.ID);
|
frm.ShowDialog();
|
}
|
|
private void bbiImport样本曲线_IMAGE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
var vm = this.gridView1.GetCurrentViewModel(_bindList);
|
if (vm == null)
|
{
|
XtraMessageBox.Show("您必须选择一个泵才能进行此项操作.");
|
ShowCmdOperateInfo("您必须选择一个泵才能进行此项操作");
|
return;
|
}
|
SampleCurveByPictureDlg frm = new SampleCurveByPictureDlg();
|
frm.SetBindingData(vm.ID);
|
frm.ShowDialog();
|
}
|
|
private void bbiViewSampleCurve_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
var vm = this.gridView1.GetCurrentViewModel(_bindList);
|
if (vm == null)
|
{
|
XtraMessageBox.Show("您必须选择一个泵才能进行此项操作.");
|
ShowCmdOperateInfo("您必须选择一个泵才能进行此项操作");
|
return;
|
}
|
var model = new BLL.PumpSampleCurve().GetDefaultByPumpID(vm.ID);
|
if (model == null)
|
{
|
XtraMessageBox.Show("当前泵未定义样本曲线.");
|
return;
|
}
|
ViewSampleCurveDlg frm = new ViewSampleCurveDlg();
|
frm.SetBindingData(model);
|
frm.ShowDialog();
|
|
}
|
}
|
}
|