using DevExpress.XtraEditors;
|
using System;
|
using System.Collections.Generic;
|
using System.Windows.Forms;
|
using TProduct.WinFrmUI.DataBase;
|
|
namespace TProduct.WinFrmUI.Data4Factory
|
{
|
public partial class ProductStyleMgrPage : DocumentPage
|
{
|
public ProductStyleMgrPage()
|
{
|
InitializeComponent();
|
this.PageTitle.Caption = "设备分类";
|
this._pageOperateInfo = "设备分类列表";
|
this.gridViewMain.SetNormalView(42);
|
this.gridViewMain.SetGridMianViewColor();
|
this.gridViewMain.RegistCustomDrawRowIndicator(25);
|
}
|
public class CurrentViewModel : Model.ProductStyle
|
{
|
public CurrentViewModel() { }
|
public CurrentViewModel(Model.ProductStyle rhs, List<Model.LoginUser> userList) : base(rhs)
|
{
|
this.UpadteName = userList?.Find(x => x.ID == rhs?.UpdateUserID)?.RealName;
|
this.CreateName = userList?.Find(x => x.ID == rhs?.CreateUserID)?.RealName;
|
}
|
public string UpadteName { get; set; }
|
public string CreateName { get; set; }
|
public string strCreateTime
|
{
|
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 strUpdateTime
|
{
|
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 "";
|
}
|
}
|
}
|
|
private List<CurrentViewModel> _bindList = null;
|
private List<Model.LoginUser> _userList = null;
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public override void InitialDataSource()
|
{
|
_bindList = new List<CurrentViewModel>();
|
var ProductStyleList = new BLL.ProductStyle().GetAll();
|
_userList = new BLL.LoginUser().GetAll();
|
ProductStyleList?.ForEach(x => _bindList.Add(new CurrentViewModel(x, _userList)));
|
|
this.bindingSource1.DataSource = _bindList;
|
this.bindingSource1.ResetBindings(false);
|
}
|
|
|
#region 基础方法
|
private void Add()
|
{
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new AddProductStyleDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData();
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
var vm = new CurrentViewModel(rhs, _userList);
|
_bindList.Add(vm);
|
this.bindingSource1.ResetBindings(false);
|
XtraMessageBox.Show("添加成功!");
|
ShowCmdOperateInfo("添加成功!");
|
this.gridViewMain.RefreshData();
|
|
};
|
ShowCmdOperateInfo("添加设备分类信息");
|
dlg.ShowDialog();
|
ShowCmdOperateInfo(_pageOperateInfo);
|
}
|
|
private void Edit()
|
{
|
var row = this.gridViewMain.GetCurrentViewModel(_bindList);
|
if (row == null)
|
{
|
XtraMessageBox.Show("请选择一行数据!");
|
ShowCmdOperateInfo("请选择一行数据!");
|
return;
|
}
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new EditProductStyleDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(row);
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
row.Reset(rhs);
|
this.bindingSource1.ResetBindings(false);
|
this.gridViewMain.RefreshData();
|
XtraMessageBox.Show("修改成功!");
|
ShowCmdOperateInfo(_pageOperateInfo);
|
|
};
|
ShowCmdOperateInfo("编辑设备分类信息");
|
dlg.ShowDialog();
|
ShowCmdOperateInfo(_pageOperateInfo);
|
|
}
|
#endregion
|
|
#region 界面操作
|
private void barBtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
Add();
|
}
|
|
private void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
Edit();
|
}
|
|
#endregion
|
|
private void barBtnExcelDown_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
ShowCmdOperateInfo("导出列表信息到Excel");
|
var path = ExcelSaveFilePathHelper.SaveFilePathName();
|
ShowCmdOperateInfo(_pageOperateInfo);
|
if (string.IsNullOrEmpty(path)) return;
|
DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
|
options.RawDataMode = true;//所见即所得
|
options.TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text;
|
this.colID.DisplayFormat.FormatString = "\t{0}";
|
this.colID.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
|
this.gridViewMain.OptionsPrint.AutoWidth = false;
|
|
this.gridViewMain.ExportToXls(path, options);
|
this.colID.DisplayFormat.FormatType = DevExpress.Utils.FormatType.None;
|
DialogResult dr = XtraMessageBox.Show("导出成功!是否打开刚刚保存的Excel文件?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
|
if (dr != DialogResult.OK)
|
return;
|
System.Diagnostics.Process.Start(path);
|
}
|
|
private void barBtnDel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
WaitFrmHelper.ShowWaitForm();
|
if (_bindList == null || _bindList.Count < 1)
|
return;
|
var row = this.gridViewMain.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 del = new BLL.ProductStyle().DeleteByID(row.ID);
|
if (del)
|
{
|
InitialDataSource();
|
XtraMessageBox.Show("删除成功!");
|
ShowCmdOperateInfo("删除成功!");
|
}
|
if (!del)
|
{
|
XtraMessageBox.Show("删除失败!");
|
ShowCmdOperateInfo("删除失败!");
|
}
|
this.Close();
|
|
}
|
|
private void barBtnView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
var row = this.gridViewMain.GetCurrentViewModel(_bindList);
|
if (row == null)
|
{
|
XtraMessageBox.Show("请选择一行数据!");
|
ShowCmdOperateInfo("请选择一行数据!");
|
return;
|
}
|
var dlg = new ViewProductStyleDlg();
|
dlg.SetBindingData(row);
|
ShowCmdOperateInfo("查看设备分类信息");
|
dlg.ShowDialog();
|
ShowCmdOperateInfo(_pageOperateInfo);
|
}
|
|
private void bbi注意事项配置_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
var row = this.gridViewMain.GetCurrentViewModel(_bindList);
|
if (row == null)
|
{
|
XtraMessageBox.Show("请选择一行数据!");
|
ShowCmdOperateInfo("请选择一行数据!");
|
return;
|
}
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new MgrTestNoticeMain4StyleDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(row.ID);
|
dlg.ShowDialog();
|
}
|
}
|
}
|