Esempio n. 1
0
/// <summary>
/// Add a MetaTableItem to the DataTable
/// </summary>
/// <param name="mtName"></param>

        void AddMetaTableItemToDataTable(
            string mtName)
        {
            MetaTreeNode mtn = MetaTreeNodeCollection.GetNode(mtName);

            if (mtn != null && mtn.IsFolderType)
            {
                return;                                              // ignore folders
            }
            MetaTable mt = MetaTableCollection.Get(mtName);

            if (mt == null)
            {
                MessageBoxMx.ShowError("The selected item is not a recognized data table: " + mtName);
                return;
            }

            string allowedTypes = Qc.MetaColumn.TableMap;

            if (Lex.IsDefined(allowedTypes))             // see if supplied table is allowed
            {
                int      ai;
                string[] sa = allowedTypes.Split(',');
                for (ai = 0; ai < sa.Length; ai++)
                {
                    string allowedType = sa[ai];
                    if (Lex.IsUndefined(allowedType))
                    {
                        continue;
                    }
                    if (Lex.Contains(mt.Name, allowedType.Trim()))
                    {
                        break;
                    }
                }

                if (ai >= sa.Length)
                {
                    MessageBoxMx.ShowError("The selected data table is not is not of a type that can be added here (" + allowedTypes + ")");
                    return;
                }
            }

            MetaTableItem i = new MetaTableItem();

            i.ExternalName = mt.Label;
            i.InternalName = mt.Name;
            AddMetaTableItemToDataTable(i);

            return;
        }
Esempio n. 2
0
/// <summary>
/// Paste assay data from clipboard
/// </summary>
/// <param name="s"></param>

        private void PasteMenuItem_Click(object sender, EventArgs e)
        {
            string s = Clipboard.GetText();

            if (Lex.IsUndefined(s))
            {
                return;
            }

            List <MetaTableItem> list = MetaTableItem.ParseList(s, false, false);

            foreach (MetaTableItem i in list)
            {
                AddMetaTableItemToDataTable(i);
            }

            return;
        }
Esempio n. 3
0
/// <summary>
/// Add a MetaTableItem to the DataTable
/// </summary>
/// <param name="mti"></param>

        void AddMetaTableItemToDataTable(
            MetaTableItem mti)
        {
            DataRow           dr;
            int               ri;
            DataRowCollection rows = ItemGridDataTable.Rows;

            for (ri = 0; ri < rows.Count; ri++)
            {
                dr = rows[ri];
                string       label = dr["LabelColumn"] as string;
                string       name  = dr["InternalNameColumn"] as string;
                MetaTreeNode mtn   = null;

                if (Lex.IsDefined(name) && Lex.IsDefined(mti.InternalName) && Lex.Eq(name, mti.InternalName))
                {
                    break;                                                                                                           // check internal name first for match
                }
                if (Lex.IsDefined(label) && Lex.IsDefined(mti.ExternalName) && Lex.Eq(label, mti.ExternalName))
                {
                    break;                                                                                                             // check table label
                }
            }

            if (ri < rows.Count)
            {
                return;                 // could focus on existing row
            }

            else
            {
                dr = ItemGridDataTable.NewRow();
                dr["LabelColumn"]        = mti.ExternalName;
                dr["InternalNameColumn"] = mti.InternalName;

                ItemGridDataTable.Rows.Add(dr);
            }

            return;
        }
Esempio n. 4
0
/// <summary>
/// Parse a string into a list of Items
/// </summary>
/// <param name="s"></param>
/// <returns></returns>

        public static List <MetaTableItem> ParseList(
            string s,
            bool mustExist,
            bool removeSuffixes)
        {
            List <MetaTableItem> list = new List <MetaTableItem>();

            s = s.Replace("\r", "");
            string[] sa = s.Split('\n');

            foreach (string txt in sa)
            {
                string       eName = "", iName = "";
                MetaTreeNode mtn = null;

                if (Lex.IsUndefined(txt))
                {
                    continue;
                }

                List <string> rowList = Csv.SplitCsvString(txt);
                if (rowList.Count == 0)
                {
                    continue;
                }

                eName = rowList[0];
                mtn   = GetNode(eName);
                if (mtn == null && rowList.Count > 1)
                {
                    iName = rowList[1];
                    mtn   = GetNode(iName);
                }

                if (mtn != null)
                {
                    iName = mtn.Target;
                    eName = mtn.Label;
                }

                else                 // no node found
                {
                    if (mustExist)
                    {
                        continue;
                    }
                }

                if (removeSuffixes)
                {
                    eName = MetaTable.RemoveSuffixesFromName(eName);
                }

                MetaTableItem i = new MetaTableItem();
                i.InternalName = iName;
                i.ExternalName = eName;

                list.Add(i);
            }

            return(list);
        }
Esempio n. 5
0
/// <summary>
/// Get values from form and update criteria in associated QueryColumn
/// </summary>
/// <returns></returns>

        bool UpdateCriteria()
        {
            MetaTable mt;
            string    label, name, listString;
            bool      summary;
            int       tableId;

            DataRowCollection rows = ItemGridDataTable.Rows;
            string            s    = "";
            List <string>     sl2  = new List <string>(new string[] { "", "" });

            foreach (DataRow dr in rows)
            {
                label = sl2[0] = dr["LabelColumn"] as string;
                name  = sl2[1] = dr["InternalNameColumn"] as string;

                if (Lex.IsUndefined(label) && Lex.IsUndefined(name))
                {
                    continue;
                }

                string txt = Csv.JoinCsvString(sl2);
                s += txt + "\r\n";
            }

            List <MetaTableItem> list = MetaTableItem.ParseList(s, true, true);
            string valueList          = "";    // list of values to match in criteria
            string displayList        = "";

            string mcDict      = Qc.MetaColumn.Dictionary;
            bool   searchId    = Lex.EndsWith(mcDict, ".Id");
            bool   searchLabel = Lex.EndsWith(mcDict, ".Label");

            foreach (MetaTableItem mti in list)
            {
                mt = MetaTableCollection.Get(mti.InternalName);
                if (mt == null)
                {
                    continue;
                }

                MetaTable.ParseMetaTableName(mt.Name, out tableId, out summary);

                label = MetaTable.RemoveSuffixesFromName(mt.Label);

                //mtn = MetaTree.GetNode(mti.InternalName); // need to check node name vs target?

                // Append to value list

                if (valueList.Length > 0)
                {
                    valueList += ", ";
                }

                if (searchId)                 // extract numeric id for table if matching against numeric column
                {
                    valueList += tableId.ToString();
                }

                else
                {
                    valueList += Lex.AddSingleQuotes(label);
                }

                // Append to label list

                if (displayList.Length == 0)                 // include first item label only in CriteriaDisplay
                {
                    displayList = label + " - ASSAY: ";
                }
                else
                {
                    displayList += ", ";
                }

                displayList += tableId.ToString();
            }

            if (valueList == "")
            {
                Qc.Criteria = Qc.CriteriaDisplay = "";
            }
            else
            {
                Qc.Criteria        = Qc.MetaColumn.Name + " in (" + valueList + ")";
                Qc.CriteriaDisplay = displayList;
            }

            return(true);
        }