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("SelectProductMotorChangedEvent")]
|
public partial class SelectMotorComboxCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public SelectMotorComboxCtrl()
|
{
|
InitializeComponent();
|
|
this.productCtrl.AddDataChanedEvent += Content_AddDataChanedEvent;
|
this.productCtrl.EditDataChanedEvent += Content_EditDataChanedEvent;
|
this.productCtrl.FocusedDataChangedEvent += Content_FocusedDataChangedEvent;
|
|
this.popupContainerEdit1.Popup += new System.EventHandler(this.popupContainerEdit_Popup);
|
this.popupContainerEdit1.CustomDisplayText += new DevExpress.XtraEditors.Controls.CustomDisplayTextEventHandler(this.popupContainerEdit_CustomDisplayText);
|
|
}
|
|
public event Action<Model.ProductMainExMotor> FocusedDataChangedEvent = null;
|
public event Action<Model.ProductMainExMotor> AddDataChanedEvent = null;
|
public event Action<Model.ProductMainExMotor> EditDataChanedEvent = null;
|
|
/// <summary>
|
/// 选择的产品
|
/// </summary>
|
public Model.ProductMainExMotor SelectMotor
|
{
|
get { return _selectMotor; }
|
private set
|
{
|
long origin_id = 0;
|
if (_selectMotor != null)
|
{
|
origin_id = _selectMotor.ID;
|
}
|
|
_selectMotor = value;
|
if (_selectMotor != null)
|
{
|
this.popupContainerEdit1.Text = _selectMotor.Name;
|
if (_selectMotor.ID != origin_id)
|
{
|
this.FocusedDataChangedEvent?.Invoke(value);
|
}
|
}
|
else
|
{
|
this.popupContainerEdit1.Text = null;
|
}
|
}
|
}
|
private Model.ProductMainExMotor _selectMotor = null;
|
|
public void SetBindingData(long SeriesID, long ProductID)
|
{
|
_selectMotor = this.productCtrl.SetBindingData(SeriesID, ProductID);
|
if (_selectMotor != null)
|
this.popupContainerEdit1.EditValue = _selectMotor;
|
}
|
//是否修改了数组成员
|
public bool IsChangeList { get { return productCtrl.IsChangeList; } }
|
|
|
//设置为不可编辑
|
public void SetReadOnly()
|
{
|
productCtrl.SetReadOnly();
|
}
|
|
|
//自定义显示
|
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.ProductMainExMotor;
|
e.DisplayText = model?.Name;
|
}
|
/// <summary>
|
/// 保证弹出时, 是 当时选择的
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void popupContainerEdit_Popup(object sender, EventArgs e)
|
{
|
if (_selectMotor != null)
|
this.productCtrl.SetFocusedData(_selectMotor);
|
}
|
|
private void Content_EditDataChanedEvent(Model.ProductMainExMotor obj)
|
{
|
EditDataChanedEvent?.Invoke(obj);
|
}
|
|
private void Content_AddDataChanedEvent(Model.ProductMainExMotor obj)
|
{
|
AddDataChanedEvent?.Invoke(obj);
|
}
|
private void Content_FocusedDataChangedEvent(Model.ProductMainExMotor obj)
|
{
|
this.popupContainerEdit1.ClosePopup();
|
if (_selectMotor != null)
|
{
|
if (_selectMotor.ID == obj.ID)
|
return;
|
}
|
_selectMotor = obj;
|
this.popupContainerEdit1.EditValue = _selectMotor;
|
this.FocusedDataChangedEvent?.Invoke(_selectMotor);
|
}
|
|
}
|
}
|