private void SetBindingSourceToDetails(BaseEdit itemEdit, BindingSource detailBindingSource, string dataMember, Type type) { if (itemEdit.GetType() != type) { return; } (itemEdit as Control).DataBindings.Clear(); (itemEdit as Control).DataBindings.Add(new System.Windows.Forms.Binding("EditValue", detailBindingSource, dataMember, true)); }
public virtual void Clear() { try { if (this.QueryControl != null) { foreach (Sys_Bind sys_Bind in BindList.Where(b => b.Bind_Type == 0).OrderBy(b => b.Bind_Sort)) { Control[] Controls = this.QueryControl.Controls.Find(sys_Bind.Bind_Field, true); if (Controls.Length > 0) { BaseEdit baseEdit = (BaseEdit)Controls[0]; baseEdit.Text = string.Empty; baseEdit.EditValue = sys_Bind.Bind_Default; if (baseEdit.GetType().Equals(typeof(CheckEdit))) { CheckEdit chkEdit = (CheckEdit)baseEdit; chkEdit.Text = string.Empty; chkEdit.Checked = sys_Bind.Bind_Default.ToBoolEx(); } //RefreshEditValue if (baseEdit.GetType().Equals(typeof(CheckedComboBoxEdit))) { CheckedComboBoxEdit chkComboBox = (CheckedComboBoxEdit)baseEdit; chkComboBox.RefreshEditValue(); } } } } } catch (Exception ex) { throw ex; } //if (this.QueryControl != null) //{ // InitializeQuery(); // //ClearControl(this.QueryControl); //} finally { } }
/// <summary> /// This method retrieves the value of the used editor as a double value. /// </summary> private static double?getEditorValue(BaseEdit editor) { var propInfo = editor.GetType().GetProperty("Value"); if (propInfo == null) { return(null); } return(Decimal.ToDouble((decimal)propInfo.GetValue(editor, null))); }
public static void PopularItensControle(this IEnumerable <sDadosEnum> valor, BaseEdit itemControle) { try { MethodInfo memberInfo = itemControle .GetType() .GetMethod("get_Properties"); if (memberInfo != null) { //delegate int IntFunc (int x); //Delegate staticD = Delegate.CreateDelegate(typeof(IntFunc), typeof(Program), "Square"); //delegate int IntFunc (int x); //Console.WriteLine(staticD.DynamicInvoke(3)); object getProperties = memberInfo .Invoke(itemControle, null); if (getProperties != null) { memberInfo = getProperties .GetType() .GetMethod("get_Items"); } object itensProperties = null; if (memberInfo != null) { itensProperties = memberInfo .Invoke(getProperties, null); } if (itensProperties != null) { itensProperties .GetType() .GetMethod("Clear") .Invoke(itensProperties, null); //var xx = itensProperties // .GetType() // .GetMethod("AddRange"); //var item = Activator // .CreateInstance(itensProperties // .GetType() // .GetMethod("get_Item") // .ReturnType); //string valorItem = String.Empty; //if (item.GetType().GetProperty("Description") == null) // item.GetType().GetMethod("set_Description").Invoke(item, new object[] { "aaaaaaaaa" }); //else // item.GetType().GetMethod("set_Description").Invoke(item, new object[] { "aaaaaaaaa" }); //if (item.GetType().GetProperty("Value") == null) // item.GetType().GetMethod("set_Value").Invoke(item, new object[] { "aaaaaaaaa" }); //else // item.GetType().GetMethod("set_Value").Invoke(item, new object[] { "aaaaaaaaa" }); //var aaa = new object[] { item } as System.Collections.ICollection; ////var list = Activator.CreateInstance(itensProperties //// .GetType() //// .GetMethod("get_Item") //// .ReturnType); //Type objType = itensProperties.GetType(); //MemberInfo addMethod = objType.GetMember("Add").FirstOrDefault() ; //addMethod.GetType().InvokeMember(null, BindingFlags.Public | BindingFlags.CreateInstance, null, item, null); //if (addMethod == null) //{ //} } } } catch (Exception ex) { MessageBox.Show(String.Concat(ex)); } }
private void InitializeQuery() { try { if (this.QueryControl == null) { return; } this.QueryControl.DoubleClick += QueryAutoClear; this.QueryControl.Controls.Clear(); this.Width = 1024; this.QueryControl.Width = 1024; LayoutControl eLayoutControl = new LayoutControl(); eLayoutControl.BeginUpdate(); eLayoutControl.AllowCustomization = false; LayoutControlGroup eLayoutControlGroup = new LayoutControlGroup(); eLayoutControl.Dock = System.Windows.Forms.DockStyle.Fill; eLayoutControl.Location = new System.Drawing.Point(2, 21); eLayoutControl.Name = "eLayoutControl"; eLayoutControl.Root = eLayoutControlGroup; eLayoutControl.Size = new System.Drawing.Size(1000, 90); eLayoutControl.TabIndex = 0; eLayoutControl.Text = "QueryLayout"; eLayoutControlGroup.EnableIndentsWithoutBorders = DevExpress.Utils.DefaultBoolean.True; eLayoutControlGroup.GroupBordersVisible = false; eLayoutControlGroup.Location = new Point(0, 0); eLayoutControlGroup.Name = "eLayoutControlGroup"; eLayoutControlGroup.Size = new Size(1000, 90); eLayoutControlGroup.TextVisible = false; this.QueryControl.Controls.Add(eLayoutControl); List <BaseLayoutItem> baseLayoutItems = new List <BaseLayoutItem>(); List <string> baseControls = new List <string>(); int curLeft = 0; int curTop = 0; foreach (Sys_Bind sys_Bind in BindList.Where(b => b.Bind_Name.StartsWith("@") && !string.IsNullOrEmpty(b.Bind_Field) && !b.Bind_Field.Contains(".") && WorkSetList.Find(w => w.WorkSet_Id == b.Bind_WorkSet && (w.WorkSet_Type == (int)Sys_WorkSet_Type.Submit || w.WorkSet_Type == (int)Sys_WorkSet_Type.Grid || w.WorkSet_Type == (int)Sys_WorkSet_Type.Tree)) != null).OrderBy(b => b.Bind_Sort)) { if (baseControls.Contains(sys_Bind.Bind_Field)) { continue; } baseControls.Add(sys_Bind.Bind_Field); sys_Bind.Bind_Type = 0; //查询字段 //界面已有控件不再生成 Control[] Controls = this.Controls.Find(sys_Bind.Bind_Field, true); if (Controls.Length > 0) { if (!string.IsNullOrEmpty(sys_Bind.Bind_Popup)) { BaseEdit cBaseEdit = (BaseEdit)Controls[0]; InitializeBaseEdit(sys_Bind, cBaseEdit); } continue; } BaseEdit baseEdit = InitializeBaseEdit(sys_Bind, null); baseEdit.Name = sys_Bind.Bind_Field; if (!string.IsNullOrEmpty(sys_Bind.Bind_Default)) { object obj = sys_Bind.Bind_Default; if (obj.ToString().StartsWith("wk:")) { obj = BaseService.Get(obj.ToString().Replace("wk:", ""), null); } ReflectionHelper.SetProperty(baseEdit, string.IsNullOrEmpty(sys_Bind.Bind_Property) ? "EditValue" : sys_Bind.Bind_Property, obj); //baseEdit.EditValue = sys_Bind.Bind_Default; if (baseEdit.GetType().Equals(typeof(CheckEdit))) { CheckEdit chkEdit = (CheckEdit)baseEdit; chkEdit.Text = string.Empty; chkEdit.Checked = obj.ToBoolEx(); } } if (baseEdit.GetType().Equals(typeof(CheckedComboBoxEdit))) { CheckedComboBoxEdit chkComboBox = (CheckedComboBoxEdit)baseEdit; chkComboBox.RefreshEditValue(); } baseEdit.EnterMoveNextControl = true; baseEdit.Width = (int)Math.Round(eLayoutControlGroup.Width * (sys_Bind.Bind_Width / 100.00)); baseEdit.Properties.Appearance.Options.UseTextOptions = true; baseEdit.Properties.Appearance.TextOptions.HAlignment = (DevExpress.Utils.HorzAlignment)sys_Bind.Bind_TextAlignment; if (sys_Bind.Bind_ForeColor < 0) { baseEdit.ForeColor = Color.FromArgb(sys_Bind.Bind_ForeColor); } if (sys_Bind.Bind_BackColor < 0) { baseEdit.BackColor = Color.FromArgb(sys_Bind.Bind_BackColor); } if (sys_Bind.Bind_BorderColor < 0) { baseEdit.Properties.Appearance.Options.UseBorderColor = true; baseEdit.Properties.Appearance.BorderColor = Color.FromArgb(sys_Bind.Bind_BorderColor); baseEdit.BorderStyle = BorderStyles.Simple; } baseEdit.ToolTip = sys_Bind.Bind_ToolTip; baseEdit.ReadOnly = sys_Bind.Bind_ReadOnly; baseEdit.Visible = sys_Bind.Bind_Visible; baseEdit.GotFocus += Control_GotFocus; eLayoutControl.GotFocus += Control_GotFocus; LayoutControlItem eLayoutControlItem = new LayoutControlItem(); eLayoutControlItem.Location = new System.Drawing.Point(curLeft, curTop); curLeft += baseEdit.Width; if (curLeft >= eLayoutControlGroup.Width) { curLeft = 0; curTop += baseEdit.Height; } //eLayoutControlItem.Width = (int)Math.Round(eLayoutControl.Width * (sys_Bind.Bind_Width / 100.00)); eLayoutControlItem.AppearanceItemCaption.TextOptions.HAlignment = (DevExpress.Utils.HorzAlignment)sys_Bind.Bind_TitleAlignment; eLayoutControlItem.Name = "oli_" + sys_Bind.Bind_Name; eLayoutControlItem.Text = sys_Bind.Bind_Nick; eLayoutControlItem.Size = new Size(baseEdit.Width, baseEdit.Height); eLayoutControlItem.Control = baseEdit; eLayoutControlItem.Visibility = sys_Bind.Bind_Visible ? DevExpress.XtraLayout.Utils.LayoutVisibility.Always : DevExpress.XtraLayout.Utils.LayoutVisibility.Never; baseLayoutItems.Add(eLayoutControlItem); } if (curLeft < eLayoutControlGroup.Width && curLeft > 0) { EmptySpaceItem emptySpaceItem = new EmptySpaceItem(); emptySpaceItem.AllowHotTrack = false; emptySpaceItem.Location = new System.Drawing.Point(curLeft, curTop); emptySpaceItem.Name = "oli_Space"; emptySpaceItem.Size = new System.Drawing.Size(eLayoutControlGroup.Width - curLeft, 24); baseLayoutItems.Add(emptySpaceItem); } eLayoutControlGroup.Items.AddRange(baseLayoutItems.ToArray()); eLayoutControl.EndUpdate(); } catch (Exception ex) { SharedFunc.RaiseError(ex); } }