/// <summary> /// Add a node to the tree following initial build /// </summary> /// <param name="node"></param> public static void AddNode(MetaTreeNode node) { if (MetaTreeFactory == null) { DebugMx.DataException("MetaTreeFactory instance is not defined"); } if (Nodes == null) { DebugMx.DataException("Nodes dictionary is null"); } if (node == null) { DebugMx.DataException("Node parameter is null"); } if (Lex.IsNullOrEmpty(node.Name)) { DebugMx.DataException("Node name is not defined"); } if (Nodes.ContainsKey(node.Name.ToUpper())) { return; } Nodes.Add(node.Name.ToUpper(), node); return; }
/// <summary> /// Build the sql for the query /// </summary> /// <param name="eqp"></param> /// <returns></returns> public override string BuildSql( ExecuteQueryParms eqp) { string sql = ""; Eqp = eqp; if (Eqp == null) { DebugMx.DataException("Eqp parameter is null"); } Qt = eqp.QueryTable; if (Qt == null) { DebugMx.DataException("Eqp.QueryTable is null"); } MetaTable mt = Qt.MetaTable; if (mt == null) { DebugMx.DataException("Metatable not defined for CalcField Query Table"); } Query q = eqp.Qe.Query; QueryTableData[] qtd = eqp.Qe.Qtd; // query table data QueryColumn qc; MetaColumn mc; KeyMc = mt.KeyMetaColumn; if (KeyMc == null) { throw new Exception("Key (compound number) column not found for MetaTable " + mt.Name); } KeyQci = Qt.GetQueryColumnIndexByName(KeyMc.Name); KeyQc = Qt.QueryColumns[KeyQci]; KeyQc.Selected = true; // be sure key is selected Qt.MetaTable.KeyMetaColumn.ColumnMap = ""; // reset key column mapping Query q2 = InitializeSubQuery(Qt); foreach (QueryTable qtx in q2.Tables) { // todo... } return(sql); }
public DataTableMx _table; // associated DataTableMx /// <summary> /// Get/set a single element in the ItemArray object array /// </summary> /// <param name="columnIndex"></param> /// <returns></returns> public object this[int columnIndex] { get { if (_itemArray == null) { DebugMx.InvalidConditionException("_itemArray == null"); } if (columnIndex < 0 || columnIndex >= _itemArray.Length) { DebugMx.InvalidConditionException("columnIndex = " + columnIndex + " out of range for DataRow of size = " + _itemArray.Length); } object o = _itemArray[columnIndex]; if (o == null || o is DBNull) { return(o); } else if (Table == null || Table.UseNativeDataTypes) { return(o); } else { return(MobiusDataType.ConvertToPrimitiveValue(o)); } } set { _itemArray[columnIndex] = value; RowState = DataRowState.Modified; // say the row is now modified _table.CallDataChangedEventHandlers(ListChangedType.ItemChanged, this); } }
/// <summary> /// Create an annotation table from a DataTable /// </summary> /// <param name="fullyQualifiedName">Fully qualified name to assign to table</param> /// <param name="dataTable">DataTable containing table definition & data</param> /// <param name="showProgress">Display dialog box showing progress of creation</param> /// <returns>Internal name assigned to annotation table (ANNOTATION_12345)</returns> public static MetaTable CreateAnnotationTable( string fullyQualifiedName, DataTable dataTable, bool showProgress) { List <AnnotationVo> voList = new List <AnnotationVo>(); AnnotationVo avo; if (dataTable == null) { DebugMx.ArgException("DataTable is null"); } if (dataTable.Columns.Count == 0) { DebugMx.ArgException("No DataColumns are defined"); } if (dataTable.Columns[0].DataType != typeof(CompoundId)) { DebugMx.ArgException("The first column must be of type CompoundId"); } if (showProgress) { Progress.Show("Creating annotation table..."); } AnnotationDao aDao = new AnnotationDao(); UserObject auo = UserObjectUtil.ParseInternalUserObjectName(fullyQualifiedName); auo.Type = UserObjectType.Annotation; UserObjectTree.GetValidUserObjectTypeFolder(auo); UserObject auo2 = UserObjectDao.Read(auo); // see if there already MetaTable oldMt = null; if (auo2 == null) // get new identifier { auo.Id = UserObjectDao.GetNextId(); // id to store table under } else // reuse identifier { auo.Id = auo2.Id; // copy it over aDao.DeleteTable(auo.Id); // delete any existing data string oldMtName = "ANNOTATION_" + auo2.Id; oldMt = MetaTableCollection.Get(oldMtName); } MetaTable mt = new MetaTable(); mt.MetaBrokerType = MetaBrokerType.Annotation; mt.Name = "ANNOTATION_" + auo.Id; // name table by uo mt.Label = auo.Name; mt.Code = auo.Id.ToString(); // code for the metatable int mtCode = auo.Id; if (dataTable.ExtendedProperties.ContainsKey("ParentTableName")) { mt.Parent = MetaTableCollection.Get((string)dataTable.ExtendedProperties["ParentTableName"]); } foreach (DataColumn dc in dataTable.Columns) { MetaColumn mc = new MetaColumn(); mc.MetaTable = mt; mc.Name = dc.ColumnName; MetaColumn oldMc = null; if (oldMt != null) { oldMc = oldMt.GetMetaColumnByName(mc.Name); // see if column name exists } if (oldMc != null && oldMc.ResultCode != "") // use any existing code { mc.ResultCode = oldMc.ResultCode; } else { mc.ResultCode = aDao.GetNextIdLong().ToString(); } if (dc.Caption != null) { mc.Label = dc.Caption; } else { mc.Label = mc.Name; } if (dc.DataType == typeof(CompoundId)) { mc.DataType = MetaColumnType.CompoundId; if (dc.ExtendedProperties.ContainsKey("StorageType") && dc.ExtendedProperties["StorageType"] is MetaColumnType && ((MetaColumnType)dc.ExtendedProperties["StorageType"]) == MetaColumnType.String) { mc.ColumnMap = "EXT_CMPND_ID_TXT"; // text column } else { mc.ColumnMap = "EXT_CMPND_ID_NBR"; // numeric column otherwise } } else if (dc.DataType == typeof(int) || dc.DataType == typeof(Int16) || dc.DataType == typeof(Int32)) { mc.DataType = MetaColumnType.Integer; } else if (dc.DataType == typeof(float) || dc.DataType == typeof(double)) { mc.DataType = MetaColumnType.Number; } else if (dc.DataType == typeof(QualifiedNumber)) { mc.DataType = MetaColumnType.QualifiedNo; } else if (dc.DataType == typeof(string)) { mc.DataType = MetaColumnType.String; } else if (dc.DataType == typeof(DateTime)) { mc.DataType = MetaColumnType.Date; } else if (dc.DataType == typeof(MoleculeMx)) { mc.DataType = MetaColumnType.Structure; } else { throw new Exception("Invalid data type " + dc.DataType.ToString()); } if (dc.ExtendedProperties.ContainsKey("DisplayLevel")) { mc.InitialSelection = (ColumnSelectionEnum)dc.ExtendedProperties["DisplayLevel"]; } if (dc.ExtendedProperties.ContainsKey("DisplayWidth")) { mc.Width = (float)dc.ExtendedProperties["DisplayWidth"]; } if (dc.ExtendedProperties.ContainsKey("DisplayFormat")) { mc.Format = (ColumnFormatEnum)dc.ExtendedProperties["DisplayFormat"]; } if (dc.ExtendedProperties.ContainsKey("Decimals")) { mc.Decimals = (int)dc.ExtendedProperties["Decimals"]; } mt.MetaColumns.Add(mc); } ToolHelper.CreateAnnotationTable(mt, auo); aDao.BeginTransaction(); // insert all data in single transaction if (showProgress) { Progress.Show("Writing data to annotation table..."); } int t1 = TimeOfDay.Milliseconds(); int writeCount = 0; foreach (DataRow dr in dataTable.Rows) { if (dr.IsNull(0)) { continue; // shouldn't happen } string key = dr[0].ToString(); key = CompoundId.NormalizeForDatabase(key, mt.Root); long rslt_grp_id = aDao.GetNextIdLong(); for (int ci = 1; ci < dataTable.Columns.Count; ci++) // do columns after key { if (dr.IsNull(ci)) { continue; } DataColumn dc = dataTable.Columns[ci]; MetaColumn mc = mt.MetaColumns[ci]; int mcCode = Int32.Parse(mc.ResultCode); avo = new AnnotationVo(); avo.rslt_grp_id = rslt_grp_id; // keep row together if (dc.DataType == typeof(CompoundId)) // shouldn't happen since key processed already { avo.rslt_val_txt = dr[ci].ToString(); } else if (dc.DataType == typeof(int) || dc.DataType == typeof(Int16) || dc.DataType == typeof(Int32) || dc.DataType == typeof(float) || dc.DataType == typeof(double)) { avo.rslt_val_nbr = (double)dr[ci]; } else if (dc.DataType == typeof(QualifiedNumber)) { QualifiedNumber qn = (QualifiedNumber)dr[ci]; avo.rslt_val_nbr = qn.NumberValue; avo.rslt_val_prfx_txt = qn.Qualifier; avo.rslt_val_txt = qn.TextValue; avo.dc_lnk = qn.Hyperlink; } else if (dc.DataType == typeof(string)) { avo.rslt_val_txt = dr[ci].ToString(); } else if (dc.DataType == typeof(DateTime)) { avo.rslt_val_dt = (DateTime)dr[ci]; } else if (dc.DataType == typeof(MoleculeMx)) { avo.rslt_val_txt = dr[ci].ToString(); } AddAnnotationVoToList(avo, key, mtCode, mcCode, voList); } writeCount++; if (Progress.CancelRequested) // check for cancel { aDao.Commit(); aDao.Insert(voList); voList.Clear(); aDao.Commit(); aDao.Dispose(); if (showProgress) { Progress.Hide(); } MessageBoxMx.ShowError("Writing of annotation table cancelled."); return(null); } int t2 = TimeOfDay.Milliseconds(); if (showProgress && t2 - t1 >= 1000) { t1 = t2; Progress.Show("Writing data to annotation table " + writeCount.ToString() + " of " + dataTable.Rows.Count.ToString() + " ..."); aDao.Insert(voList); voList.Clear(); aDao.Commit(); } } aDao.Insert(voList); voList.Clear(); aDao.Commit(); aDao.Dispose(); if (showProgress) { Progress.Hide(); } return(mt); // return metatable name }