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.Data4Owner
|
{
|
[DefaultEvent("_selectProductSeriestProductSeriesChangedEvent")]
|
public partial class SelectSeriesComboxCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public SelectSeriesComboxCtrl()
|
{
|
InitializeComponent();
|
this.popupContainerEdit1.Popup += new System.EventHandler(this.popupContainerEdit_Popup);
|
this.popupContainerEdit1.CustomDisplayText += new DevExpress.XtraEditors.Controls.CustomDisplayTextEventHandler(this.popupContainerEdit_CustomDisplayText);
|
|
this.productSeriesCtrl1.AddDataChanedEvent += ProductSeriesCtrl1_AddDataChanedEvent;
|
this.productSeriesCtrl1.EditDataChanedEvent += ProductSeriesCtrl1_EditDataChanedEvent;
|
this.productSeriesCtrl1.FocusedDataChangedEvent += ProductSeriesCtrl1_FocusedDataChangedEvent;
|
}
|
|
public event Action<Model.ProductSeries> FocusedDataChangedEvent = null;
|
public event Action<Model.ProductSeries> AddDataChanedEvent = null;
|
public event Action<Model.ProductSeries> EditDataChanedEvent = null;
|
//是否修改了数组成员
|
public bool IsChangeList { get { return productSeriesCtrl1.IsChangeList; } }
|
/// <summary>
|
/// 选择的产品
|
/// </summary>
|
public Model.ProductSeries SelectProductSeries
|
{
|
get { return _selectProductSeries; }
|
private set
|
{
|
long origin_id = 0;
|
if(_selectProductSeries != null)
|
{
|
origin_id = _selectProductSeries.ID;
|
}
|
_selectProductSeries = value;
|
if(_selectProductSeries != null)
|
{
|
this.popupContainerEdit1.Text = _selectProductSeries.Name;
|
if (_selectProductSeries.ID != origin_id)
|
{
|
this.FocusedDataChangedEvent?.Invoke(value);
|
}
|
}
|
else
|
{
|
this.popupContainerEdit1.Text = null;
|
}
|
}
|
}
|
private Model.ProductSeries _selectProductSeries = null;
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="height"></param>
|
public void SetHeight(int height)
|
{
|
//this.popupContainerEdit1.MaximumSize = new System.Drawing.Size(0, height);
|
this.popupContainerEdit1.MinimumSize = new System.Drawing.Size(0, height);
|
}
|
/// <summary>
|
/// 默认值初始化
|
/// </summary>
|
public void SetBindingData(Model.eProductType type,long ID)
|
{
|
_selectProductSeries = this.productSeriesCtrl1.SetBindingData(type, ID);
|
if (_selectProductSeries != null)
|
this.popupContainerEdit1.EditValue = _selectProductSeries;
|
}
|
|
/// <summary>
|
/// 保证弹出时, 是 当时选择的
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void popupContainerEdit_Popup(object sender, EventArgs e)
|
{
|
if (_selectProductSeries != null)
|
this.productSeriesCtrl1.SetFocusedData(_selectProductSeries);
|
}
|
//自定义显示
|
private void popupContainerEdit_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.ProductSeries;
|
e.DisplayText = model?.Name;
|
}
|
|
private void ProductSeriesCtrl1_FocusedDataChangedEvent(Model.ProductSeries obj)
|
{
|
this.popupContainerEdit1.ClosePopup();
|
if (_selectProductSeries != null)
|
{
|
if (_selectProductSeries.ID == obj.ID)
|
return;
|
}
|
_selectProductSeries = obj;
|
this.popupContainerEdit1.EditValue = _selectProductSeries;
|
this.FocusedDataChangedEvent?.Invoke(_selectProductSeries);
|
}
|
|
private void ProductSeriesCtrl1_EditDataChanedEvent(Model.ProductSeries obj)
|
{
|
EditDataChanedEvent?.Invoke(obj);
|
}
|
|
private void ProductSeriesCtrl1_AddDataChanedEvent(Model.ProductSeries obj)
|
{
|
AddDataChanedEvent?.Invoke(obj);
|
}
|
|
//设置为不可编辑
|
public void SetReadOnly()
|
{
|
productSeriesCtrl1.SetReadOnly();
|
}
|
}
|
}
|