using DevExpress.XtraEditors;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
namespace TProduct.WinFrmUI.Data4Factory
|
{
|
public partial class SelectProductStyleComboxContentCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public SelectProductStyleComboxContentCtrl()
|
{
|
InitializeComponent();
|
|
this.layoutControl1.SetupLayoutControl();
|
|
this.gridViewMain.SetNormalView(30);
|
this.gridViewMain.SetGridMianViewColor();
|
this.gridViewMain.RegistCustomDrawRowIndicator();
|
this.gridViewMain.RowClick += new DevExpress.XtraGrid.Views.Grid.RowClickEventHandler(this.GridViewMain_RowClick);
|
}
|
|
public event Action<Model.ProductStyle> FocusedDataChangedEvent = null;
|
public event Action<Model.ProductStyle> AddDataChanedEvent = null;
|
public event Action<Model.ProductStyle> EditDataChanedEvent = null;
|
|
private List<Model.ProductStyle> _bindList = null;
|
|
|
|
|
/// <summary>
|
/// 初始化并设置默认值
|
/// </summary>
|
public Model.ProductStyle SetBindingData(TProduct.Model.eProductType ProductType,
|
long productStyleID)
|
{
|
_bindList = new BLL.ProductStyle().GetByProductType(ProductType);
|
|
this.bindingSource1.DataSource = _bindList;
|
this.bindingSource1.ResetBindings(false);
|
|
|
|
|
Model.ProductStyle find = null;
|
if (productStyleID > 0)
|
{
|
find = this._bindList.Find(x => x.ID == productStyleID);
|
}
|
if (find == null)
|
find = _bindList.First();
|
|
SetFocusedData(find);
|
|
|
|
this.FocusedDataChangedEvent?.Invoke(find);
|
|
|
return find;
|
}
|
|
public void SetReadOnly()
|
{
|
this.barButAdd.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
|
this.barButEdit.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
|
}
|
|
/// <summary>
|
/// 初始化并设置默认值
|
/// </summary>
|
/// <param name="sel"></param>
|
public bool SetFocusedData(Model.ProductStyle sel)
|
{
|
if (sel == null) { return false; }
|
var find_index = this._bindList.FindIndex(x => x.ID == sel.ID);
|
this.gridViewMain.SelectRow(find_index);
|
|
this.gridViewMain.FocusedRowHandle = find_index;
|
return true;
|
}
|
|
private void GridViewMain_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
|
{
|
var row = this.gridViewMain.GetFocusedRow() as Model.ProductStyle;
|
if (row == null)
|
return;
|
this.FocusedDataChangedEvent?.Invoke(row);
|
}
|
private bool _isChangeList = false;//是否修改了数组成员
|
|
public bool IsChangeList { get => _isChangeList; set => _isChangeList = value; }
|
|
private void barButAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new AddProductStyleDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData();
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
_isChangeList = true;
|
var vm = new Model.ProductStyle(rhs);
|
_bindList.Add(vm);
|
this.bindingSource1.ResetBindings(false);
|
this.AddDataChanedEvent?.Invoke(rhs);
|
this.FocusedDataChangedEvent?.Invoke(rhs);
|
XtraMessageBox.Show("添加成功!");
|
};
|
dlg.ShowDialog();
|
}
|
|
private void barButEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
WaitFrmHelper.ShowWaitForm();
|
var row = this.gridViewMain.GetCurrentViewModel(_bindList);
|
if (row == null)
|
{
|
WaitFrmHelper.ShowWaitForm();
|
XtraMessageBox.Show("请选择一行数据!");
|
return;
|
}
|
var dlg = new EditProductStyleDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(row);
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
_isChangeList = true;
|
row.Reset(rhs);
|
this.bindingSource1.ResetBindings(false);
|
EditDataChanedEvent?.Invoke(rhs);
|
XtraMessageBox.Show("修改成功!");
|
};
|
dlg.ShowDialog();
|
}
|
|
private void barButSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (this.gridViewMain.OptionsView.ShowGroupPanel)
|
this.gridViewMain.OptionsView.ShowGroupPanel = false;
|
else
|
this.gridViewMain.OptionsView.ShowGroupPanel = true;
|
}
|
|
}
|
}
|