private void InsertSaltsForAllCompounds_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { DisplayStatusMsg("Inserting Salts, wait please..."); GetNormalizedListFromControl(CidList); List <string> al = MoleculeUtil.InsertSalts(CidList.ToStringList()); CidList newList = new CidList(al); newList.UserObject = CidList.UserObject; StringBuilder listBuild = new StringBuilder(newList.Count * 12 + 32); // build formatted list here foreach (CidListElement cle in newList.List) { // build formatted list with added items marked listBuild.Append(CompoundId.Format(cle.Cid, RootTable)); if (!CidList.Contains(cle.Cid)) { listBuild.Append(" (+)"); } listBuild.Append("\r\n"); } CidList = newList; CidListCtl.Text = listBuild.ToString(); DisplayStatusMsg(""); return; }
private void EditList_Click(object sender, EventArgs e) { string listText = CidListString.Trim(); List <string> al = Csv.SplitCsvString(listText); CidList cnList = new CidList(al, true); cnList.UserObject.Name = "Criteria List"; cnList.UserObject.Id = CidListEditor.EditInMemoryOnlyUoId; // indicate not to be persisted to user object cnList = CidListEditor.Edit(cnList, Qc.MetaColumn.MetaTable.Root); if (cnList == null) { return; } CidListString = CidList.BuildListCsvStringOfFormattedCids(Qc, cnList.ToStringList()); SetCidListDisplay(); if (CidListDisplayIsEditable() && CidListString.Length > 0) // no text selected { CidListDisplay.Select(0, 0); } else { InList.Focus(); } }
private void ImportList_Click(object sender, EventArgs e) { string filePath = UIMisc.SelectListFileDialog("List File to Import", ""); if (String.IsNullOrEmpty(filePath)) { return; } string fileName = Path.GetFileNameWithoutExtension(filePath); CidList cnList = CidList.ReadFromFile(filePath); // read file list if (cnList == null) { return; } CidListString = CidList.BuildListCsvStringOfFormattedCids(Qc, cnList.ToStringList()); SetCidListDisplay(); if (CidListDisplay.Text.Length > 0) // no text selected { CidListDisplay.Select(0, 0); } return; }
/// <summary> /// Set global QE parameter /// </summary> /// <param name="cidListString"></param> public static void SetParameter( string parm, string value) { if (Lex.Eq(parm, "DatabaseSubset")) { if (Lex.IsNullOrEmpty(value)) { DatabaseSubset = null; } else { DatabaseSubset = CidList.ToStringList(value); } } else if (Lex.Eq(parm, "AllowNetezzaUse")) { bool.TryParse(value, out AllowNetezzaUse); } else if (Lex.Eq(parm, "AllowMultiTablePivot")) { bool.TryParse(value, out AllowMultiTablePivot); } else if (Lex.Eq(parm, "DefaultToSingleStepQueryExecution")) { bool.TryParse(value, out MqlUtil.DefaultToSingleStepQueryExecution); } return; }
/// <summary> /// Open the specified query or copy the list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GridView_RowCellClick(object sender, RowCellClickEventArgs e) { StreamReader sr; int r = e.RowHandle; int c = e.Column.AbsoluteIndex; HistoryItem hi = SS.I.History[r]; // get item allowing for header row if (c == 0) // open query { sr = new StreamReader(hi.QueryFileName); string queryText = sr.ReadToEnd(); Query q = Query.Deserialize(queryText); q.UserObject.Name = // append time to name q.UserObject.Name + " - " + hi.DateTime.ToLongTimeString(); q.Mode = QueryMode.Build; // want to be in build mode q.UserObject.Content = q.Serialize(); // set content so not prompted for save when closed QbUtil.AddQueryAndRender(q, false); } // Copy list to current list sr = new StreamReader(hi.ListFileName); string listText = sr.ReadToEnd(); CidList cidList = new CidList(listText); CidListCommand.WriteCurrentList(cidList); SessionManager.CurrentResultKeys = cidList.ToStringList(); SessionManager.DisplayCurrentCount(); if (c == 1) // return message if just copying list to current { string msg = "The list has been copied to the current list (" + SessionManager.CurrentResultKeysCount + ")"; MessageBoxMx.Show(msg); } HistoryList_Deactivate(null, null); return; }
/// <summary> /// Read a compound id list given an internal list name (e.g. FOLDER_123.name or LIST_1234) /// </summary> /// <param name="name"></param> /// <param name="mt"></param> /// <returns></returns> public static CidList Read( string internalName, MetaTable mt, bool allowLocalRead) { UserObject uo, uo2; string fileName, cn; int i1; uo = UserObjectUtil.ParseInternalUserObjectName(internalName, UserObjectType.CnList); if (uo == null) { return(null); } if (allowLocalRead && UserObject.IsCurrentObjectInternalName(internalName)) // get from the current query { return(ReadCurrentListLocal()); } uo2 = UserObjectDao.Read(uo); // get from the server side if (uo2 == null) { MessageBoxMx.ShowError( "Unable to find list: " + internalName + "\r\n\r\n" + CommandExec.GetUserObjectReadAccessErrorMessage(uo.Id, "list")); return(null); } CidList cnList = CidList.Deserialize(uo2, mt); if (UserObject.IsCurrentObjectInternalName(internalName)) // if current list store keys with query { SessionManager.CurrentResultKeys = cnList.ToStringList(); } return(cnList); }
/// <summary> /// Write a compound number list /// </summary> /// <returns></returns> public static int Write( CidList list, UserObject uo) { string fileName; string content = list.ToMultilineString(); uo.Type = UserObjectType.CnList; if (Lex.IsNullOrEmpty(uo.Owner)) // set current user as owner if owner not defined { uo.Owner = SS.I.UserName; } if (Lex.IsNullOrEmpty(uo.ParentFolder)) { throw new Exception("No parent folder for list"); } uo.Content = content; uo.Count = list.Count; UserObjectDao.Write(uo, uo.Id); if (uo.IsCurrentObject) { SessionManager.CurrentResultKeys = list.ToStringList(); SessionManager.DisplayCurrentCount(); } if (uo.HasDefinedParentFolder) { MainMenuControl.UpdateMruList(uo.InternalName); } return(list.Count); }
/// <summary> /// Attempt to read existing results file into the query DataTable /// </summary> /// <param name="qm"></param> public void ReadBinaryResultsFile(string fileName) { QueryTable qt; QueryColumn qc; BinaryReader br = null; Stopwatch sw = Stopwatch.StartNew(); try { bool saveHandlersEnabled = Qm.DataTable.EnableDataChangedEventHandlers(false); // disable for faster load bool saveUpdateMaxRowsPerKey = UpdateMaxRowsPerKeyEnabled; UpdateMaxRowsPerKeyEnabled = false; // disable for faster load int id = Query.UserObject.Id; if (id <= 0) { throw new Exception("Query not saved"); } if (DataTableMx == null || DataTableMx.Columns.Count == 0) { throw new Exception("DataTable not defined"); } br = BinaryFile.OpenReader(fileName); string sq = br.ReadString(); Query q0 = Query.Deserialize(sq); // deserialize the saved query QueryManager qm0 = new QueryManager(); qm0.LinkMember(q0); ResultsFormat rf0 = new ResultsFormat(qm0, OutputDest.WinForms); ResultsFormatFactory rff0 = new ResultsFormatFactory(qm0, OutputDest.WinForms); rff0.Build(); // build format with vo positions // The cached query cols should match those of the current query: however, // we'll create a mapping just in case they don't int voArrayLen0 = br.ReadInt32(); // cached vo array len int voArrayLen = DataTableMx.Columns.Count - KeyValueVoPos; // current query vo array len List <int> q0VoMap = new List <int>(); // vo position in cached query data List <int> qVoMap = new List <int>(); // vo position in current version of query q0VoMap.Add(0); // first position is the common key value qVoMap.Add(0); foreach (QueryTable qt0 in q0.Tables) // scan each table in cached data { foreach (QueryColumn qc0 in qt0.QueryColumns) // and each column { if (qc0.VoPosition < 0) { continue; // skip if not mapped to the vo in cached data } int q0VoPos = qc0.VoPosition - KeyValueVoPos; // where it is in cache int qvoPos = -1; // where it will go qt = Query.GetTableByName(qt0.MetaTable.Name); if (qt != null) { qc = qt.GetQueryColumnByName(qc0.MetaColumn.Name); if (qc != null) { qvoPos = qc.VoPosition - KeyValueVoPos; } } q0VoMap.Add(q0VoPos); // where it is in saved data qVoMap.Add(qvoPos); // where it will go (not including attributes & check cols) } } if (q0VoMap.Count != voArrayLen0) { throw new Exception("Cached Vo length doesn't match list of selected columns"); } DataTableMx.Clear(); // clear the rows CidList cidList = new CidList(); object[] voa = new object[voArrayLen]; // array to fill while (!BinaryFile.ReaderEof(br)) // process each row { for (int mi = 0; mi < q0VoMap.Count; mi++) // each col { object o = VoArray.ReadBinaryItem(br); if (mi == 0 && o != null) // add to key list if key { cidList.Add(o.ToString(), false); } if (qVoMap[mi] >= 0) // save in new buf if mapped { voa[qVoMap[mi]] = o; } } DataRowMx dr = AddDataRow(voa); } br.Close(); Qm.DataTable.EnableDataChangedEventHandlers(saveHandlersEnabled); UpdateMaxRowsPerKeyEnabled = saveUpdateMaxRowsPerKey; InitializeRowAttributes(false); ResultsKeys = cidList.ToStringList(); // include keys in DTM as well double ms = sw.Elapsed.TotalMilliseconds; return; } catch (Exception ex) { if (br != null) { br.Close(); } throw new Exception(ex.Message, ex); } }
/// <summary> /// Setup the form for display /// </summary> /// <param name="cid"></param> /// <param name="qm"></param> /// <returns></returns> bool SetupForm( string cid, QueryManager qm) { AssertMx.IsDefined(cid, "Compound Id (CorpId)"); SelectedCid = cid; PreviousCid = cid; RootTable = CompoundId.GetRootMetaTableFromCid(cid); Qm = null; // no query context SourceQuery = null; CurrentBaseQueryCidHitList = null; if (qm != null) // if querymanager defined then base the related data query on the "current" query { Qm = qm; // setup query context SourceQuery = qm.Query; RootTable = qm.Query.RootMetaTable; if (qm.Query != null && qm.Query.Mode == QueryMode.Browse) // if browsing current base query results then get that cid list { CurrentBaseQueryCidHitList = Qm.DataTableManager.GetMostCompleteResultsKeyList(); } } //else throw new Exception("Parameters not defined"); //if (Lex.IsUndefined(SelectedCid) && // (Qm == null || Qm.MoleculeGrid == null || Qm.MoleculeGrid.Helpers == null)) // return false; SetupCheckmarks(); // Current Cid //if (Qm != null) // SelectedCid = Qm.MoleculeGrid.Helpers.GetCidForSelectedCell(); SelectedCid = CompoundId.Format(SelectedCid); CidCtl.Text = SelectedCid; //CidCtl.Focus(); // Marked cid count MarkedCidsList = null; if (Qm?.MoleculeGrid != null) { CidList cl = Qm.MoleculeGrid.GetMarkedList(); if (cl != null) { MarkedCidsList = cl.ToStringList(); } } int selCnt = (MarkedCidsList != null ? MarkedCidsList.Count : 0); MarkedCidsCheckEdit.Text = "Selected compound Ids (" + FormatCidListForDisplay(MarkedCidsList) + ")"; MarkedCidsCheckEdit.Enabled = (selCnt > 0); if (selCnt == 0 && MarkedCidsCheckEdit.Checked) { CurrentCidCheckEdit.Checked = true; } // All Cid count int allCnt = (CurrentBaseQueryCidHitList != null ? CurrentBaseQueryCidHitList.Count : 0); AllCidsCheckEdit.Text = "All Ids in the current result set (" + FormatCidListForDisplay(CurrentBaseQueryCidHitList) + ")"; AllCidsCheckEdit.Enabled = (allCnt > 0); if (selCnt == 0 && AllCidsCheckEdit.Checked) { CurrentCidCheckEdit.Checked = true; } // Structure MoleculeMx cs = new MoleculeMx(); if (Lex.IsDefined(SelectedCid)) { cs = MoleculeUtil.SelectMoleculeForCid(SelectedCid); } QueryMolCtl.SetupAndRenderMolecule(cs); // MRU list RenderMruList(); return(true); }
/// <summary> /// Analyze key criteria in token list. /// A saved list reference is returned as a set of key values & /// blanked out in the token list. /// Other key references are returned as a set of indexes in a list. /// </summary> /// <param name="q"></param> /// <param name="Qtd"></param> /// <param name="tokens"></param> /// <param name="keyCriteriaPositions">Token indexes for key criteria column names</param> /// <param name="keyCriteriaSavedListKeys">Keys in any referenced saved list</param> /// <param name="keyCriteriaInListKeys">Keys in any literal list </param> /// <param name="keyCriteriaConstantPositions">Positions of key values for literal lists</param> public static void AnalyzeKeyCriteria( Query q, QueryTableData[] Qtd, List <MqlToken> tokens, out CompareOp keyCriteriaOp, out List <int> keyCriteriaPositions, out List <string> keyCriteriaSavedListKeys, out List <string> keyCriteriaInListKeys, out List <int> keyCriteriaConstantPositions) { string tok1, tok2, tok3, tok4, tok5; keyCriteriaOp = CompareOp.Unknown; keyCriteriaPositions = new List <int>(); keyCriteriaSavedListKeys = null; keyCriteriaInListKeys = null; keyCriteriaConstantPositions = new List <int>(); for (int tki = 0; tki < tokens.Count; tki++) { QueryColumn qc = tokens[tki].Qc; if (qc == null) { continue; } if (!qc.IsKey) { continue; } keyCriteriaPositions.Add(tki); // remember position of key col reference if (tokens.Count < tki + 2) { throw new QueryException("Incomplete compound id criteria at end of statement"); } bool notLogic = false; tok1 = GetTokenListString(tokens, tki + 1); if (Lex.Eq(tok1, "Not")) { notLogic = true; tki++; if (tokens.Count < tki + 2) { throw new QueryException("Incomplete compound id criteria at end of statement"); } tok1 = GetTokenListString(tokens, tki + 1); } tok2 = GetTokenListString(tokens, tki + 2); tok3 = GetTokenListString(tokens, tki + 3); tok4 = GetTokenListString(tokens, tki + 4); tok5 = GetTokenListString(tokens, tki + 5); // Saved List if (tokens.Count > tki + 3 && Lex.Eq(tok1, "In") && Lex.Eq(tok2, "List")) { // have a saved list keyCriteriaOp = CompareOp.InList; if (keyCriteriaSavedListKeys != null) // already have it? { throw new UserQueryException("Only one condition is allowed for the " + qc.ActiveLabel + " field"); } if (notLogic) // not currently allowed for saved lists { throw new UserQueryException("\"Not\" logic is not allowed for " + qc.ActiveLabel + " saved lists"); } string listName = tokens[tki + 3].Tok.Text; UserObject uo = ResolveCidListReference(listName); if (uo == null) { throw new UserQueryException("Key list " + listName + " not found"); } listName = uo.InternalName; CidList keyCriteriaSavedList = CidListDao.Read(listName, QueryEngine.GetRootTable(q)); if (keyCriteriaSavedList == null) { throw new UserQueryException("Key list " + listName + " not found"); } keyCriteriaSavedListKeys = keyCriteriaSavedList.ToStringList(); tokens[tki].Qc = null; tokens[tki].Tok.Text = ""; for (int tki2 = tki + 1; tki2 <= tki + 3; tki2++) { tokens[tki2].Tok.Text = ""; } if (!MqlUtil.DisableAdjacentAndLogic(tokens, tki, tki + 3)) { throw new UserQueryException("Only \"And\" logic is allowed with " + qc.ActiveLabel + " saved lists"); } int ti = q.GetQueryTableIndexByAlias(qc.QueryTable.Alias); Qtd[ti].CriteriaCount--; keyCriteriaPositions.RemoveAt(keyCriteriaPositions.Count - 1); } // Explicit list of allowed keys else if (tokens.Count > tki + 2 && Lex.Eq(tok1, "In") && Lex.Eq(tok2, "(")) { keyCriteriaOp = CompareOp.In; int listKeyCount = 0; // count keys in this list for (int tki2 = tki + 3; tki2 < tokens.Count; tki2++) { tok1 = tokens[tki2].Tok.Text; if (tok1 == ",") { continue; } else if (tok1 == ")") { break; } keyCriteriaConstantPositions.Add(tki2); if (keyCriteriaInListKeys == null) { keyCriteriaInListKeys = new List <string>(); } MetaTable rootTable = QueryEngine.GetRootTable(q); string normKey = CompoundId.Normalize(tok1, rootTable); if (normKey != null && normKey != "") { keyCriteriaInListKeys.Add(normKey); listKeyCount++; } } if (listKeyCount == 0) { throw new UserQueryException("The query contains an invalid empty list of " + qc.ActiveLabel + "s"); } } // Between a range of key values else if (tokens.Count > tki + 4 && Lex.Eq(tok1, "Between") && Lex.Eq(tok3, "And")) { keyCriteriaOp = CompareOp.Between; keyCriteriaConstantPositions.Add(tki + 2); keyCriteriaConstantPositions.Add(tki + 4); } // Single key value, treat like a list with a single value else if (Lex.Eq(tok1, "=")) { keyCriteriaOp = CompareOp.Eq; keyCriteriaConstantPositions.Add(tki + 2); if (keyCriteriaInListKeys == null) { keyCriteriaInListKeys = new List <string>(); } MetaTable rootTable = QueryEngine.GetRootTable(q); string normKey = CompoundId.Normalize(tok2, rootTable); if (Lex.IsDefined(normKey)) { keyCriteriaInListKeys.Add(normKey); } } // Other binary operator else if (MqlUtil.IsBasicComparisonOperator(tok1)) { keyCriteriaOp = CompareOpString.ToCompareOp(tok1); keyCriteriaConstantPositions.Add(tki + 2); } // Unary operator "is null" else if (Lex.Eq(tok1, "Is") && Lex.Eq(tok2, "Null")) { keyCriteriaOp = CompareOp.IsNull; } // Unary operator "is not null" else if (Lex.Eq(tok1, "Is") && Lex.Eq(tok2, "Not") && Lex.Eq(tok3, "Null")) { keyCriteriaOp = CompareOp.IsNotNull; } else { throw new QueryException("Unrecognized compound id condition " + tok1); } } return; }