/// <summary> /// Jako klucze podziałowe wykorzystujemy obiekty dedykowanej klasy 'KluczType'. /// Proporcje w tym podzielniku będą wyznaczone przez ilość kontrahentów przypisaną do województw. /// </summary> public override IEnumerable GetKluczeList() { // słownik ze statystyką województwo/ilość kontrahentów var stats = new Dictionary <Wojewodztwa, int>(); // dane kontrahentów var kontrahenci = Row.Session.Get <CRMModule>().Kontrahenci.WgKodu; // budujemy statystyke foreach (var kontrahent in kontrahenci) { int count; var woj = kontrahent.Adres.Wojewodztwo; stats.TryGetValue(woj, out count); stats[woj] = ++count; } // dla każdego zarejestrowanego województwa tworzymy klucz podziałowy foreach (var key in stats) { yield return new KluczType { // proporcja to ilość kontrahentów w województwie Proporcja = key.Value, // opis elementu: nazwa województwa Opis = CaptionAttribute.EnumToString(key.Key), // symbol zbudowany z wykorzystaniem numeru wojewodztwa Symbol = string.Format("501-01-papier-{0:00}", (int)key.Key) } } ; } }
protected static string makeFieldName(IRow row, string name) { string prefix = row.Prefix; if (prefix == "") { return(name); } return(CaptionAttribute.ConvertName(prefix + '.' + name)); }
public ActionInfo(Type type) { this.action = type.GetConstructor(new Type[0]).Invoke(new object[0]); this.priority = PriorityAttribute.GetPriority(this.action, 1000); this.text = CaptionAttribute.GetCaption(this.action, type.Name); this.description = BAL.Types.AttributesExtensions.GetDescription(null, this.action); var pinfo = type.GetProperty("Target", BindingFlags.Instance | BindingFlags.Public); if (pinfo != null) { this.target = (ActionTarget)pinfo.GetValue(this.action, null); } else { this.target = ActionTarget.None; } pinfo = type.GetProperty("MarginLeft", BindingFlags.Instance | BindingFlags.Public); if (pinfo != null) { this.MarginLeft = (int)pinfo.GetValue(this.action, null); } pinfo = type.GetProperty("MarginRight", BindingFlags.Instance | BindingFlags.Public); if (pinfo != null) { this.MarginRight = (int)pinfo.GetValue(this.action, null); } pinfo = type.GetProperty("MarginTop", BindingFlags.Instance | BindingFlags.Public); if (pinfo != null) { this.MarginTop = (int)pinfo.GetValue(this.action, null); } pinfo = type.GetProperty("MarginBottom", BindingFlags.Instance | BindingFlags.Public); if (pinfo != null) { this.MarginBottom = (int)pinfo.GetValue(this.action, null); } this.propertySelectedRows = type.GetProperty("SelectedRows"); this.propertyCurrentRow = type.GetProperty("CurrentRow"); this.propertyFireReload = type.GetProperty("FireReload"); this.propertyFireRefresh = type.GetProperty("FireRefresh"); this.propertyFireSelectionChanged = type.GetProperty("FireSelectionChanged"); this.methodOnAction = type.GetMethod("OnAction", BindingFlags.Instance | BindingFlags.Public); this.methodOnSelectionChanged = type.GetMethod("OnSelectionChanged", BindingFlags.Instance | BindingFlags.Public); }
public ActionButton(object action) { this.action = action; this.Text = CaptionAttribute.GetCaption(this.action, this.action.GetType().Name); var pinfo = this.action.GetType().GetProperty("Control"); if (pinfo != null) { pinfo.SetValue(this.action, this, null); } method = action.GetType().GetMethod("OnAction"); pinfo = this.action.GetType().GetProperty("WaitCursorEnable"); if (pinfo != null) { this.waitCursor = (bool)pinfo.GetValue(this.action, null); } }
protected virtual void InitColumns() { var type = this.GetDataType(); this.columns = new ColumnCollection(); this.columns.BeginInit(); foreach (var pinfo in type.GetProperties()) { if (pinfo.GetCustomAttributes(typeof(HiddenAttribute), true).Length > 0) { continue; } Column column = new Column(); column.HeaderText = CaptionAttribute.GetCaption(pinfo, pinfo.Name); column.TextAlign = TextAlign.Left; column.Width = 100; column.Visible = true; column.PropertyPath = new PropertyPath(pinfo); this.columns.Add(column); } this.columns.EndInit(); }
/// <summary> /// 校验对象属性值是否合法 /// </summary> /// <param name="obj">待校验对象</param> /// <returns></returns> public static ValidateResult Validate(this IValidate obj) { ValidateResult result = new ValidateResult(); PropertyInfo[] infos = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo p in infos) { //获取数据校验特性。 Attribute[] attrs = Attribute.GetCustomAttributes(p, typeof(ValidateAttribute), false); if (attrs.Length <= 0) { continue; } //获取名称描述特性 CaptionAttribute caption = Attribute.GetCustomAttribute(p, typeof(CaptionAttribute), false) as CaptionAttribute; object value = p.GetValue(obj); foreach (Attribute attr in attrs) { ValidateAttribute validate = attr as ValidateAttribute; if (validate == null) { continue; } result = Validate(validate, value, caption); if (!result.IsSuccess) { return(result); } } } return(result); }
/// <summary> /// 校验数据是否合法 /// </summary> /// <param name="validate">校验规则</param> /// <param name="value">待校验值</param> /// <param name="caption">描述</param> /// <returns></returns> private static ValidateResult Validate(ValidateAttribute validate, object value, CaptionAttribute caption) { ValidateResult result = new ValidateResult(); if (!validate.Validate(value)) { result.IsSuccess = false; if (caption == null) { result.ErrorMessage = validate.GetErrorMessage(); } else { result.ErrorMessage = validate.GetErrorMessage(caption.Name); } } return(result); }
/// <summary> /// Geneates the label from the Caption Attribute /// </summary> /// <param name="pi">Property to geneate label</param> /// <returns></returns> private Control GetLabel(PropertyInfo pi) { object[] attributes = pi.GetCustomAttributes(false); //quering for the caption attribute var att = (from ca in attributes where ca.GetType() == typeof(CaptionAttribute) select ca).SingleOrDefault(); Control LabelControls = new Control(); if (att == null) //Assign the propety name as a caption att = new CaptionAttribute(pi.Name); PropertyInfo typePropertyInfo = att.GetType().GetProperty("LabelTypeName"); if (typePropertyInfo != null) { string typeName = typePropertyInfo.GetValue(att, null).ToString(); Control control = (Control)System.Activator.CreateInstance(Type.GetType(typeName)); FieldInfo[] fields = att.GetType().GetFields(); foreach (FieldInfo fld in fields) { string fieldName = fld.Name; object fieldValue = fld.GetValue(att); PropertyInfo controlProperty = control.GetType().GetProperty(fieldName); if (controlProperty != null) controlProperty.SetValue(control, fieldValue, null); } //firing the event OnLabelCreated(control, new FieldEventArgs(pi.Name, pi.PropertyType)); LabelControls.Controls.Add(control); } return LabelControls; }
/// <summary> /// Fill the grid with specified data. /// </summary> /// <param name="oData"></param> /// <returns></returns> public virtual bool Fill(IEnumerable oData) { string fn = MethodBase.GetCurrentMethod().Name; try { object rec0 = null; foreach (object rec in oData) { rec0 = rec; break; } if (null == rec0) { return(false); } Type type = rec0.GetType(); FieldInfo[] fields = type.GetFields(); PropertyInfo[] properties = type.GetProperties(); List <object> top_n_records = new List <object>(); foreach (object rec in oData) { top_n_records.Add(rec); if (top_n_records.Count >= 100) { break; } } List <MemberInfo> fields_and_props = new List <MemberInfo>(); fields_and_props.AddRange(fields); fields_and_props.AddRange(properties); Dictionary <string, DataGridViewTextBoxColumn> column_lut = new Dictionary <string, DataGridViewTextBoxColumn>(); foreach (FieldInfo fi in fields_and_props) { if (!fi.IsPublic) { continue; } string fname = fi.Name; string scaption = CaptionAttribute.Get(fi); Type ftype = fi.FieldType; DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn(); col.Tag = fi; col.Name = fi.Name; col.ReadOnly = true; col.Width = CalcColumnWidth(fi, top_n_records); column_lut.Add(fname, col); DataGridViewCellStyle cellstyle = new DataGridViewCellStyle(); cellstyle.Tag = fi; cellstyle.Font = new Font("Courier New", 8.0F); cellstyle.Alignment = DataGridViewContentAlignment.MiddleLeft; // default, overridden for dates and numbers if (typeof(DateTime).IsAssignableFrom(ftype)) { cellstyle.Alignment = DataGridViewContentAlignment.MiddleRight; } if ((typeof(double).IsAssignableFrom(ftype)) || (typeof(int).IsAssignableFrom(ftype)) || (typeof(Decimal).IsAssignableFrom(ftype)) || (typeof(IList).IsAssignableFrom(ftype)) ) { cellstyle.Alignment = DataGridViewContentAlignment.MiddleRight; cellstyle.Format = "F8.3"; } DataGridViewColumnHeaderCell header_cell = new DataGridViewColumnHeaderCell(); header_cell.Value = scaption; col.HeaderCell = header_cell; m_dgMain.Columns.Add(col); } // end foreach(field - column) // Step 2: loop through data and display: int nrows = 0; foreach (object rec in oData) { nrows++; if (nrows >= MaxDisplayRows) { break; } int irow = m_dgMain.Rows.Add(); DataGridViewRow row = m_dgMain.Rows[irow]; foreach (DataGridViewColumn col in m_dgMain.Columns) { FieldInfo fi = col.Tag as FieldInfo; object val = fi.GetValue(rec); DataGridViewCell cell = row.Cells[col.Index]; cell.Value = Format(val, fi); cell.Tag = val; cell.Style = overrideCellStyle(col.DefaultCellStyle, fi); } } return(true); } catch (Exception exc) { LogHelper.HandleExc(this, fn, exc); return(false); } } // end method()