public string GetSelectField(string field) { if (TableInfo != null) { var dbField = TableInfo.GetField(field); if (dbField != null && dbField.DbFieldName != field) { return(dbField.DbFieldName + " AS " + field); } else { return(field); } } var property = GetProperty(field); if (property != null) { var dbField = DbAttributes.GetDbFieldName(property); if (dbField == field) { return(field); } else { return(dbField + " AS " + field); } } return(field); }
public DBControlInfo(string columnName, DbAttributes attribute, ParseType parseType, bool required) { this.columnName = columnName; isRequired = required; this.parseType = parseType; this.attribute = attribute; }
public void GetTableNameTest() { var actual = DbAttributes.GetTableName(typeof(AttributeModel)); var expected = "TestModel"; Assert.AreEqual(expected, actual); }
public string GetKeyWhere(string where = null) { if (!string.IsNullOrEmpty(where)) { return(GetWhere(where)); } if (TableInfo != null) { var field = TableInfo.GetPrimaryKeyField(); if (field != null) { return(" WHERE " + field.DbFieldName + "=@" + field.PropertyName); } } foreach (var property in ModelType.GetProperties()) { if (!DbAttributes.CheckPrimaryKey(property)) { continue; } var fieldName = property.Name; var attr = DbAttributes.GetDbFieldInfo(property); if (attr != null) { fieldName = attr.FieldName; } return(" WHERE " + fieldName + "=@" + property.Name); } throw new Exception("can't find primary key when generate delete command!"); }
public bool CheckAutoIncrement(PropertyInfo property) { if (TableInfo != null) { return(TableInfo.CheckAutoIncrement(property.Name)); } return(DbAttributes.CheckAutoIncrement(property)); }
public bool CheckPrimaryKey(PropertyInfo property) { if (TableInfo != null) { return(TableInfo.CheckPrimaryKey(property.Name)); } return(DbAttributes.CheckPrimaryKey(property)); }
public bool CheckDbField(PropertyInfo property) { if (TableInfo != null) { return(TableInfo.CheckDbField(property.Name)); } return(DbAttributes.CheckDbField(property)); }
public GridColumnAttrib(string colName, string caption, DbAttributes attribs, ColumnFormatType format) { ColumnName = colName; ColumnCaption = caption; ColumnType = typeof(string); ColumnReadOnly = false; ColumnVisible = true; this.Attributes = attribs; ColumnFormatType = format; }
private static void PopulateMunisAttributes() // How to pull this from cache? { var tmpAttribs = new DbAttributes(); using (var results = DBFactory.GetSqliteCacheDatabase().DataTableFromQueryString(Queries.Munis.SelectLocations()))//MunisDatabase.ReturnSqlTable(Queries.Munis.SelectLocations())) { foreach (DataRow row in results.Rows) { tmpAttribs.Add(row[MunisLocations.Description].ToString().Trim(), row[MunisLocations.Code].ToString().Trim(), Convert.ToInt32(row[MunisLocations.Code])); } } AttributeInstances.MunisAttributes.MunisLocations = tmpAttribs; }
private static void PopulateSubnetLocationAttributes() { var tmpAttribs = new DbAttributes(); using (var results = DBFactory.GetSqliteCacheDatabase().DataTableFromQueryString(Queries.Assets.SelectSubnetLocations())) { foreach (DataRow row in results.Rows) { tmpAttribs.Add(row[SubnetLocationsTable.Description].ToString(), row[SubnetLocationsTable.Subnet].ToString(), Convert.ToInt32(row[SubnetLocationsTable.Id])); } } AttributeInstances.DeviceAttributes.SubnetLocation = tmpAttribs; }
private static void PopulateMunisToAssetAttributes() { var tmpAttribs = new DbAttributes(); using (var results = DBFactory.GetSqliteCacheDatabase().DataTableFromQueryString(Queries.Assets.SelectMunisAndAssetLocationCodes())) { foreach (DataRow row in results.Rows) { tmpAttribs.Add(row[DeviceCodesTable.HumanValue].ToString(), row[MunisDepartmentsTable.MunisLocation].ToString(), Convert.ToInt32(row[MunisDepartmentsTable.Id])); } } AttributeInstances.MunisAttributes.MunisToAssetLocations = tmpAttribs; }
public void CheckPrimaryKeyTest() { var type = typeof(AttributeModel); var intProperty = type.GetProperties().Where(p => p.Name == "IntProperty").FirstOrDefault(); var idProperty = type.GetProperties().Where(p => p.Name == "ID").FirstOrDefault(); if (intProperty == null || idProperty == null) { Assert.Fail(); } Assert.IsFalse(DbAttributes.CheckPrimaryKey(intProperty)); Assert.IsTrue(DbAttributes.CheckPrimaryKey(idProperty)); }
public void CheckDbFieldTest() { var type = typeof(AttributeModel); var intProperty = type.GetProperties().Where(p => p.Name == "IntProperty").FirstOrDefault(); var noDbProperty = type.GetProperties().Where(p => p.Name == "NotField").FirstOrDefault(); if (intProperty == null || noDbProperty == null) { Assert.Fail(); } Assert.IsTrue(DbAttributes.CheckDbField(intProperty)); Assert.IsFalse(DbAttributes.CheckDbField(noDbProperty)); }
private static DataGridViewComboBoxColumn DataGridComboColumn(DbAttributes attributes, string headerText, string name) { var newCombo = new DataGridViewComboBoxColumn(); newCombo.Items.Clear(); newCombo.HeaderText = headerText; newCombo.DataPropertyName = name; newCombo.Name = name; newCombo.Width = 200; newCombo.SortMode = DataGridViewColumnSortMode.Automatic; newCombo.DisplayMember = nameof(DbAttribute.DisplayValue); newCombo.ValueMember = nameof(DbAttribute.Code); newCombo.DataSource = attributes.GetArray(); return(newCombo); }
public static void FillComboBox(this ComboBox combo, DbAttributes attributes) { combo.SuspendLayout(); combo.BeginUpdate(); combo.DataSource = null; combo.Text = ""; AddAutoSizeDropWidthHandler(combo); combo.DisplayMember = nameof(DbAttribute.DisplayValue); combo.ValueMember = nameof(DbAttribute.Code); combo.BindingContext = new BindingContext(); combo.DataSource = attributes.GetArray(); combo.SelectedIndex = -1; combo.EndUpdate(); combo.ResumeLayout(); }
public string GetTableName() { if (TableInfo != null) { return(TableInfo.TableName); } var attrName = DbAttributes.GetTableName(ModelType); if (!string.IsNullOrEmpty(attrName)) { return(attrName); } return(ModelType.Name); }
public FieldsAndValues MakeFields() { var result = new FieldsAndValues(); foreach (var field in FieldsPart.Split(',')) { if (TableInfo != null) { var fieldInfo = TableInfo.GetField(field); if (fieldInfo != null) { if (fieldInfo.NotDbField) { continue; } if (fieldInfo.IsAutoIncrement) { continue; } result.Add(field, fieldInfo.DbFieldName); continue; } } var property = GetProperty(field); if (property == null) { result.Add(field); } else { if (!DbAttributes.CheckDbField(property)) { continue; } if (DbAttributes.CheckAutoIncrement(property)) { continue; } var dbFieldName = DbAttributes.GetDbFieldName(property); result.Add(property.Name, dbFieldName); } } return(result); }
public void GetDbFieldInfoTest() { var type = typeof(AttributeModel); var property = type.GetProperties().Where(p => p.Name == "IntProperty").FirstOrDefault(); if (property == null) { Assert.Fail(); } var attr = DbAttributes.GetDbFieldInfo(property); if (attr == null) { Assert.Fail(); } Assert.AreEqual("IntField", attr.FieldName); }
public string GetFieldName(PropertyInfo property) { if (property == null) { return(null); } if (!CheckDbProperty(property)) { return(null); } if (TableInfo != null) { return(TableInfo.GetDbFieldName(property.Name)); } return(DbAttributes.GetDbFieldName(property)); }
private static DbAttributes BuildIndex(string attribTable, string attribName) { //try //{ using (DataTable results = DBFactory.GetSqliteCacheDatabase().DataTableFromQueryString(Queries.Assets.SelectAttributeCodes(attribTable, attribName))) { var tmpAttrib = new DbAttributes(); foreach (DataRow r in results.Rows) { string displayValue = ""; if (r.Table.Columns.Contains("munis_code")) { if (r["munis_code"] != DBNull.Value) { displayValue = r[ComboCodesBaseCols.DisplayValue].ToString() + " - " + r["munis_code"].ToString(); } else { displayValue = r[ComboCodesBaseCols.DisplayValue].ToString(); } } else { displayValue = r[ComboCodesBaseCols.DisplayValue].ToString(); } Color attribColor = Color.Empty; if (!string.IsNullOrEmpty(r[ComboCodesBaseCols.Color].ToString())) { attribColor = ColorTranslator.FromHtml(r[ComboCodesBaseCols.Color].ToString()); } tmpAttrib.Add(displayValue, r[ComboCodesBaseCols.CodeValue].ToString(), Convert.ToInt32(r[ComboCodesBaseCols.Id]), attribColor); } return(tmpAttrib); } //} //catch (Exception ex) //{ // // ErrorHandling.ErrHandle(ex, System.Reflection.MethodBase.GetCurrentMethod()); // return null; //} }
public static void SetDBInfo(this Control control, string columnName, DbAttributes attribs, ParseType parseType, bool required = false) { // SetControlMaxLength(control, columnName); control.Tag = new DBControlInfo(columnName, attribs, parseType, required); }
public static void SetDBInfo(this Control control, string columnName, DbAttributes attribs, bool required = false) { SetDBInfo(control, columnName, attribs, ParseType.UpdateAndDisplay, required); }