using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Text; using System.Windows.Forms; using WMS.Attirubte; using WMS.Common; using WMS.Model.Base; using System.Data; using DevExpress.XtraEditors; namespace WMS.Ctrl { public partial class LookUpEditSystem : DevExpress.XtraEditors.LookUpEdit { /// /// 定义一个委托事件 /// //public delegate void ctlLoad(); //public event ctlLoad load; public LookUpEditSystem() { InitializeComponent(); this.DataBindings.CollectionChanged += new CollectionChangeEventHandler(DataBindings_CollectionChanged); // this.load += new ctlLoad(LookUpEditSystem_load); } //public void LookUpEditSystem_load() //{ // LoadData(); //} void DataBindings_CollectionChanged(object sender, CollectionChangeEventArgs e) { } /// /// 初始化控件加载数据绑定 /// public void LoadData() { if (this.DataBindings.Count > 0) { if ((this.DataBindings[0].DataSource as BindingSource).DataSource == null) { return; } string modelClass = (this.DataBindings[0].DataSource as BindingSource).DataSource.ToString(); Type classType = Type.GetType(modelClass); /// if (classType == null) { string dllPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName); classType = System.Reflection.Assembly.LoadFile(dllPath + "\\WMS.Model.dll").GetType(modelClass); if (classType == null) { return; } } string member= this.DataBindings[0].BindingMemberInfo.BindingMember; object[] TypeobjType = classType.GetProperty(member).GetCustomAttributes(typeof(TableClmAttribute), false); if (TypeobjType.Length == 0) { return; } object[] disPlay = classType.GetProperty(member).GetCustomAttributes(typeof(DisplayNameAttribute), false); if (disPlay.Length == 0) { return; } string captionName= (disPlay[0] as DisplayNameAttribute).DisplayName; ///取关联的数据库 string tableName=(TypeobjType[0] as TableClmAttribute).ClmJoinTable; string clmValue = (TypeobjType[0] as TableClmAttribute).JoinTableClm; string clmDis = (TypeobjType[0] as TableClmAttribute).JoinTableClmName; string clmWhere = (TypeobjType[0] as TableClmAttribute).JoinTableWhere; string clmClassName = (TypeobjType[0] as TableClmAttribute).ClassName; if (Properties.Columns.Count <= 0) { Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo(clmDis, captionName)); } if (string.IsNullOrEmpty(Properties.ValueMember)) { this.Properties.ValueMember = clmValue; } if (string.IsNullOrEmpty(Properties.DisplayMember)) { this.Properties.DisplayMember = clmDis; } if (Properties.DataSource != null) { Properties.DataSource = null; } if (Properties.DataSource == null ) { DataTable table = WMS.Business.IBussFactory.Instance().GetCustomCtrlData(tableName, clmValue, clmDis, clmWhere, clmClassName); if (table != null) { Properties.DataSource = table; } } } } } }