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
|
{
|
[DefaultEvent("SelectProductTypeChangedEvent")]
|
public partial class SelectProductTypeCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public SelectProductTypeCtrl()
|
{
|
InitializeComponent();
|
this.productTypeCtrl1.AddDataChanedEvent += Content_AddDataChanedEvent;
|
this.productTypeCtrl1.EditDataChanedEvent += Content_EditDataChanedEvent;
|
this.productTypeCtrl1.FocusedDataChangedEvent += Content_FocusedDataChangedEvent;
|
}
|
|
public event Action<Model.ProductStyle> FocusedDataChangedEvent = null;
|
public event Action<Model.ProductStyle> AddDataChanedEvent = null;
|
public event Action<Model.ProductStyle> EditDataChanedEvent = null;
|
|
/// <summary>
|
/// 当前选择的类别
|
/// </summary>
|
public Model.ProductStyle Selected { get; private set; }
|
|
/// <summary>
|
/// 选择的产品分类
|
/// </summary>
|
public Model.ProductStyle SelectProductStyle
|
{
|
get { return _selectProductStyle; }
|
private set
|
{
|
var temp = _selectProductStyle;
|
_selectProductStyle = value;
|
this.popupContainerEdit1.Text = _selectProductStyle == null ? null : _selectProductStyle.Name;
|
if (!System.Object.ReferenceEquals(_selectProductStyle, temp))
|
{
|
this.FocusedDataChangedEvent?.Invoke(value);
|
}
|
}
|
}
|
private Model.ProductStyle _selectProductStyle = null;
|
|
|
public void SetBindingData(Model.eProductType type)
|
{
|
this.productTypeCtrl1.SetBindingData(type);
|
}
|
|
/// <summary>
|
/// 默认值初始化
|
/// </summary>
|
public void SetFocused(Model.eProductType type,long ID)
|
{
|
var bol = this.productTypeCtrl1.SetFocused(type, ID);
|
if (bol)
|
{
|
var obj = this.productTypeCtrl1.GetFocused();
|
if (obj == null)
|
return;
|
var de = obj as Model.ProductStyle;
|
if (de == null)
|
return;
|
if (Selected != null)
|
{
|
if (Selected.ID == de.ID)
|
return;
|
}
|
Selected = de;
|
this.popupContainerEdit1.EditValue = Selected;
|
this.FocusedDataChangedEvent?.Invoke(Selected);
|
}
|
}
|
|
private void Content_FocusedDataChangedEvent(Model.ProductStyle obj)
|
{
|
this.popupContainerEdit1.ClosePopup();
|
if (Selected != null)
|
{
|
if (Selected.ID == obj.ID)
|
return;
|
}
|
Selected = obj;
|
this.popupContainerEdit1.EditValue = Selected;
|
this.FocusedDataChangedEvent?.Invoke(Selected);
|
}
|
|
//自定义显示
|
private void popupContainerEdit1_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
|
{
|
var width = this.Size.Width;
|
this.popupContainerControl1.Size = new Size(width, 300);
|
var model = e.Value as Model.ProductStyle;
|
e.DisplayText = model?.Name;
|
}
|
|
private void Content_EditDataChanedEvent(Model.ProductStyle obj)
|
{
|
EditDataChanedEvent?.Invoke(obj);
|
}
|
|
private void Content_AddDataChanedEvent(Model.ProductStyle obj)
|
{
|
AddDataChanedEvent?.Invoke(obj);
|
}
|
}
|
}
|