using DevExpress.XtraEditors;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
|
namespace TProduct.WinFrmUI.Data4Factory
|
{
|
public partial class SelectProductTypeComboxContentCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public SelectProductTypeComboxContentCtrl()
|
{
|
InitializeComponent();
|
this.gridView1.SetNormalEditView();
|
this.layoutControl1.SetupLayoutControl();
|
|
}
|
private class CurrentViewModel : Model.ProductStyle
|
{
|
public CurrentViewModel() { }
|
public CurrentViewModel(Model.ProductStyle rhs) : base(rhs)
|
{
|
|
}
|
|
public bool IsChecked { get; set; }
|
}
|
|
public event Action<Model.ProductStyle> FocusedDataChangedEvent = null;
|
public event Action<Model.ProductStyle> AddDataChanedEvent = null;
|
public event Action<Model.ProductStyle> EditDataChanedEvent = null;
|
|
private List<CurrentViewModel> _bindList = null;
|
public Model.eProductType _etype;
|
public void SetBindingData(Model.eProductType type)
|
{
|
_etype = type;
|
var all = new BLL.ProductStyle().GetAll()?.Where(x=>x.Type== type)?.ToList();
|
_bindList = new List<CurrentViewModel>();
|
all?.ForEach(x =>_bindList.Add(new CurrentViewModel(x)));
|
this.bindingSource1.DataSource = _bindList;
|
this.bindingSource1.ResetBindings(false);
|
}
|
|
|
/// <summary>
|
/// 初始化并设置默认值
|
/// </summary>
|
public bool SetFocused(Model.eProductType type,long ID)
|
{
|
this.SetBindingData(type);
|
if (ID<1)
|
return false;
|
var selModel = _bindList.Find(x => x.ID == ID);
|
if (selModel != null)
|
{
|
selModel.IsChecked = true;
|
this.bindingSource1.ResetBindings(false);
|
this.FocusedDataChangedEvent?.Invoke(selModel);
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 获取聚焦
|
/// </summary>
|
public object GetFocused()
|
{
|
var vm = this.gridView1.GetFocusedRow() as CurrentViewModel;
|
return vm;
|
}
|
|
private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
|
{
|
var row = this.gridView1.GetFocusedRow() as CurrentViewModel;
|
if (row == null)
|
return;
|
this.FocusedDataChangedEvent?.Invoke(row);
|
}
|
|
private void barButAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new AddProductStyleDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(_etype);
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
var vm = new CurrentViewModel(rhs);
|
_bindList.ForEach(x => x.IsChecked = false);
|
vm.IsChecked = true;
|
_bindList.Add(vm);
|
this.bindingSource1.ResetBindings(false);
|
this.AddDataChanedEvent?.Invoke(rhs as Model.ProductStyle);
|
this.FocusedDataChangedEvent?.Invoke(rhs as Model.ProductStyle);
|
XtraMessageBox.Show("添加成功!");
|
};
|
dlg.ShowDialog();
|
}
|
|
private void barButEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
WaitFrmHelper.ShowWaitForm();
|
var row = this.gridView1.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) =>
|
{
|
row.Reset(rhs);
|
this.bindingSource1.ResetBindings(false);
|
EditDataChanedEvent?.Invoke(rhs as Model.ProductStyle);
|
XtraMessageBox.Show("修改成功!");
|
};
|
dlg.ShowDialog();
|
}
|
|
private void barButSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (this.barButSearch1.Visibility == DevExpress.XtraBars.BarItemVisibility.Always)
|
this.barButSearch1.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
|
else
|
this.barButSearch1.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
|
}
|
}
|
}
|