//------------------------------------------------------------------------------------- #region << Methods >> private void Fill() { try { this.Controls.Clear(); if(obj == null) return; this.SuspendLayout(); //List<Tuple<PropertyDescriptor,int?>> list = new List<Tuple<PropertyDescriptor, int?>>(); //foreach(PropertyDescriptor pd in TypeDescriptor.GetProperties(obj)) // if(((showID && pd.Name == "OID") || pd.IsBrowsable) && // (typeFilter == null || typeFilter.Contains(pd.ComponentType))) // { // DisplayOrderAttribute attr = pd.Attributes.OfType<DisplayOrderAttribute>().FirstOrDefault(); // list.Add(new Tuple<PropertyDescriptor, int?>(pd, attr == null ? null : (int?)attr.Order)); // } //list.Sort(Sorter); if(IsTableView) { SimDataGridView grid = new SimDataGridView(); List<ValuesPair<string, string>> viewList = new List<ValuesPair<string, string>>(); foreach(PropertyDescriptor i in TypeDescriptor.GetProperties(obj)) { if(!((showID && i.Name == "OID") || i.IsBrowsable)) continue; if(typeFilter != null && typeFilter.Contains(i.ComponentType) == false) continue; ValuesPair<string, string> item = new ValuesPair<string, string>(); item.Value1 = i.DisplayName; object val = i.GetValue(obj) ?? "(пусто)"; if(val is DateTime) { DateTime d = (DateTime)val; if(d.TimeOfDay.Ticks == 0) item.Value2 = d.ToShortDateString(); else item.Value2 = val.ToString(); } else if(val is IList) { StringBuilder sb = new StringBuilder(); for(int a = 0; a < ((IList)val).Count; a++) { sb.AppendFormat("{0}", i.Converter is ReferenceConverter ? (((IList)val)[a] ?? "").ToString() : i.Converter.ConvertToString(((IList)val)[a])); if(!(((IList)val).Count < 2 || a == ((IList)val).Count -1)) sb.AppendLine(""); } if(sb.Length == 0) item.Value2 = "(пусто)"; else item.Value2 = sb.ToString(); } else if(i.Converter is ReferenceConverter) item.Value2 = (val ?? "").ToString(); else item.Value2 = i.Converter.ConvertToString(val); viewList.Add(item); } grid.RowHeadersVisible = false; grid.BorderStyle = System.Windows.Forms.BorderStyle.None; grid.CellBorderStyle = DataGridViewCellBorderStyle.None; grid.RowTemplate.Height = 16; grid.ColumnHeadersVisible = false; grid.DefaultCellStyle.SelectionForeColor = grid.DefaultCellStyle.ForeColor; grid.Dock = DockStyle.Fill; grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; grid.BackgroundColor = this.BackColor; grid.DefaultCellStyle.BackColor = this.BackColor; grid.DefaultCellStyle.SelectionBackColor = this.BackColor; grid.CellPainting += new DataGridViewCellPaintingEventHandler(grid_CellPainting); grid.DataSource = new ListBinder(viewList); grid.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader; this.Controls.Add(grid); } else { SimLayoutPanel p = new SimLayoutPanel() { AutoSizeMode = AutoSizeMode.GrowAndShrink, AutoSize = true }; foreach(PropertyDescriptor i in TypeDescriptor.GetProperties(obj)) { if(!((showID && i.Name == "OID") || i.IsBrowsable)) continue; if(typeFilter != null && typeFilter.Contains(i.ComponentType) == false) continue; SimTwoLabel l = new SimTwoLabel(); l.Label1Text = i.DisplayName + ":"; l.Label1Image = global::Sim.Common.Properties.Resources.Point_x6; l.Label1Font = new Font(this.Font, FontStyle.Bold); l.Label1ForeColor = SystemColors.ControlDark; object val = i.GetValue(obj) ?? "(пусто)"; if(val is DateTime) l.Label2Text = ((DateTime)val).TimeOfDay.Ticks == 0 ? ((DateTime)val).ToShortDateString() : val.ToString(); else l.Label2Text = TypeDescriptor.GetConverter(val).ConvertToString(val); l.Margin = new Padding(0, 0, 6, 4); p.Controls.Add(l); } //p.BackColor = Color.Red; p.Dock = DockStyle.Top; this.Controls.Add(p); } } catch(Exception Err) { Sim.Controls.ModalErrorBox.Show(Err, this.FindModalContainer()); } finally { this.PerformLayout(); this.ResumeLayout(); } }
//------------------------------------------------------------------------------------- /// <summary> /// Инициализирующий конструктор. /// </summary> /// <param name="items">Отображаемые элементы.</param> /// <param name="checkedItems">Выбраные элементы</param> public SimCheckList(IEnumerable items, IEnumerable checkedItems) : this() { if (items == null) throw new ArgumentNullException("items"); list = new PList<ValuesPair<bool, object>>(); foreach (var x in items) { ValuesPair<bool, object> i = new ValuesPair<bool, object>(false, x); i.Value1 = checkedItems != null && checkedItems.Contains(x); list.Add(i); } ListBinder b = new ListBinder(list); fdgv.DataSource = b; }
public static ValuesPair<CodeQuery, List<String>> GetCodeQuery(Type type, string typeWrapperCode) { CSharpCodeProvider cscp = null; try { cscp = new CSharpCodeProvider(); ValuesPair<CodeQuery, List<String>> res = new ValuesPair<CodeQuery, List<string>>(null, new List<string>()); CodeQuery query = new CodeQuery(); query.CodeText = typeWrapperCode; query.ObjectType = type.FullName; CompilerParameters cp = new CompilerParameters(); cp.GenerateInMemory = true; cp.TreatWarningsAsErrors = false; foreach(Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) if(asm.IsDynamic == false) cp.ReferencedAssemblies.Add(asm.Location); CompilerResults cr = cscp.CompileAssemblyFromSource(cp, typeWrapperCode); if(cr.Errors.Count > 0) { foreach(CompilerError err in cr.Errors) res.Value2.Add(String.Format("[{0},{1}] {2} {3}: {4}", err.Line, err.Column, err.IsWarning ? "Warning" : "Error", err.ErrorNumber, err.ErrorText)); } if(cr.Errors.HasErrors) return res; MethodInfo mi = cr.CompiledAssembly.GetType(type.Name).GetMethod("DynamicMethod", BindingFlags.NonPublic | BindingFlags.Instance); MethodBody mb = mi.GetMethodBody(); query.MaxStackSize = mb.MaxStackSize; query.Body = mb.GetILAsByteArray(); query.Schema = Discover(query.Body, mi, type); if(mb.LocalVariables.Count > 0) { query.LocalVariables = new List<KeyValuePair<Type, bool>>(mb.LocalVariables.Count); foreach(LocalVariableInfo lvi in mb.LocalVariables) query.LocalVariables.Add(new KeyValuePair<Type, bool>(lvi.LocalType, lvi.IsPinned)); } res.Value1 = query; return res; } finally { if(cscp != null) cscp.Dispose(); } }