using DevExpress.XtraEditors;
|
using System;
|
using System.Collections.Generic;
|
using System.Drawing;
|
|
namespace TProduct.WinFrmUI.Data4Factory
|
{
|
public partial class SelectPartBaseContentCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public SelectPartBaseContentCtrl()
|
{
|
InitializeComponent();
|
// this.layoutControl1.SetupLayoutControl();
|
//
|
this.gridViewMain.SetNormalView(30);
|
this.gridViewMain.SetGridMianViewColor();
|
this.gridViewMain.RegistCustomDrawRowIndicator();
|
this.gridViewMain.OptionsView.EnableAppearanceOddRow = true; // 使能 // 和和上面绑定 同时使用有效
|
this.gridViewMain.Appearance.EvenRow.BackColor = Color.LightGray; // 设置偶数行颜色
|
this.gridViewMain.OptionsView.EnableAppearanceEvenRow = true;
|
this.gridViewMain.Appearance.OddRow.BackColor = Color.White; // 设置偶数行颜色
|
|
}
|
#region 当前视图
|
//数据拼接
|
protected class CurrentViewModel : Model.PartBase
|
{
|
public CurrentViewModel() { }
|
public CurrentViewModel(Model.PartBase obj) : base(obj)
|
{
|
this.ID = obj.ID;
|
this.CreateUserID = obj.CreateUserID;
|
this.CreateTime = obj.CreateTime;
|
this.UpdateUserID = obj.UpdateUserID;
|
this.UpdateTime = obj.UpdateTime;
|
this.Code = obj.Code;
|
this.Name = obj.Name;
|
}
|
public string ProductName { get; set; }
|
public bool IsChecked { get; set; }
|
}
|
|
#endregion
|
|
public event Action<Model.PartBase> FocusedDataChangedEvent = null;
|
public event Action<Model.PartBase> AddDataChanedEvent = null;
|
public event Action<Model.PartBase> EditDataChanedEvent = null;
|
|
private List<CurrentViewModel> _bindList = null;
|
private long _productID = 0;
|
public void SetBindingData(long ProductID)
|
{
|
if (ProductID < 1)
|
return;
|
_productID = ProductID;
|
_bindList = new List<CurrentViewModel>();
|
|
var partList = new BLL.PartBase().GetByProductMainID(_productID);
|
var product = new BLL.ProductMain().GetByID(_productID);
|
partList?.ForEach(x => _bindList.Add(new CurrentViewModel(x) { ProductName = product?.Name }));
|
this.bindingSource1.DataSource = _bindList;
|
this.bindingSource1.ResetBindings(false);
|
this.gridViewMain.FocusedRowHandle = 0;
|
}
|
|
|
/// <summary>
|
/// 初始化并设置默认值
|
/// </summary>
|
public bool SetFocused(long ID)
|
{
|
this.SetBindingData(ID);
|
var selModel = _bindList.Find(x => x.ID == ID);
|
if (selModel == null)
|
return false;
|
if (selModel != null)
|
{
|
this.bindingSource1.ResetBindings(false);
|
this.FocusedDataChangedEvent?.Invoke(selModel);
|
}
|
return true;
|
}
|
/// <summary>
|
/// 获取聚焦
|
/// </summary>
|
public object GetFocused()
|
{
|
var vm = this.gridViewMain.GetFocusedRow() as CurrentViewModel;
|
return vm;
|
}
|
|
private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
|
{
|
var row = this.gridViewMain.GetFocusedRow() as CurrentViewModel;
|
if (row == null)
|
return;
|
var model = row as Model.PartBase;
|
this.FocusedDataChangedEvent?.Invoke(model);
|
}
|
|
private void barButAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
Add(_productID);
|
}
|
|
private void barButEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
Edit();
|
}
|
|
private void barButSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.gridViewMain.OptionsFind.AlwaysVisible = this.barCkSelect.Checked;
|
}
|
|
|
private void Edit()
|
{
|
WaitFrmHelper.ShowWaitForm();
|
var row = this.gridViewMain.GetCurrentViewModel(_bindList);
|
if (row == null)
|
{
|
WaitFrmHelper.ShowWaitForm();
|
XtraMessageBox.Show("请选择一行数据!");
|
return;
|
}
|
var dlg = new EditPartBaseDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(row as Model.PartBase);
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
row.Reset(rhs);
|
this.bindingSource1.ResetBindings(false);
|
EditDataChanedEvent?.Invoke(rhs as Model.PartBase);
|
XtraMessageBox.Show("修改成功!");
|
};
|
dlg.ShowDialog();
|
}
|
|
|
private void Add(long ProductID)
|
{
|
if (ProductID < 1)
|
return;
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new AddPartBaseOnListDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(ProductID);
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
var ProductName = new BLL.ProductMain().GetByID(rhs.ProductMainID)?.Name;
|
var vm = new CurrentViewModel(rhs) { ProductName = ProductName };
|
_bindList.Add(vm);
|
this.bindingSource1.ResetBindings(false);
|
this.AddDataChanedEvent?.Invoke(rhs as Model.PartBase);
|
this.FocusedDataChangedEvent?.Invoke(rhs as Model.PartBase);
|
XtraMessageBox.Show("添加成功!");
|
};
|
dlg.ShowDialog();
|
}
|
|
private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
|
{
|
var row = this.gridViewMain.GetFocusedRow() as CurrentViewModel;
|
if (row == null)
|
return;
|
var model = row as Model.PartBase;
|
this.FocusedDataChangedEvent?.Invoke(model);
|
}
|
}
|
}
|