private void gridMain_CellLeave(object sender, ODGridClickEventArgs e) { QuerySetStmtObject qObjCur = (QuerySetStmtObject)gridMain.SelectedGridRows[0].Tag; string stmtOld = qObjCur.Stmt; string varOld = qObjCur.Variable; string valOld = qObjCur.Value; string valNew = gridMain.SelectedGridRows[0].Cells[1].Text.ToString(); if (UserQueries.SplitQuery(valNew, true, ";").Count > 1) { Point _selectedCell = gridMain.SelectedCell; MsgBox.Show(this, "You may not include semicolons in the value text. Please remove all semicolons."); gridMain.SelectedGridRows[0].Cells[1].Text = valOld; gridMain.SetSelected(_selectedCell); //this just refreshes the cell that is being left. Is there an easy way to cancel the CellLeave action? return; } if (valOld == valNew) { return; //don't bother doing any of the logic below if nothing changed. } //Regular expression for the expression @Variable = Value. Regex r = new Regex(Regex.Escape(varOld) + @"\s*=\s*" + Regex.Escape(valOld)); string stmtNew = r.Replace(stmtOld, varOld + "=" + valNew); _queryCur.QueryText = _queryCur.QueryText.Replace(stmtOld, stmtNew); textQuery.Text = _queryCur.QueryText; qObjCur.Stmt = stmtNew; qObjCur.Value = valNew; gridMain.Rows.OfType <ODGridRow>().Where(x => ((QuerySetStmtObject)x.Tag).Stmt == stmtOld).ToList().ForEach(y => { ((QuerySetStmtObject)y.Tag).Stmt = stmtNew; }); }
private void SelectTextForSelectedRow() { QuerySetStmtObject qObjCur = (QuerySetStmtObject)gridMain.SelectedGridRows[0].Tag; int startidx = textQuery.Text.IndexOf(qObjCur.Stmt); if (startidx == -1) { //the query object does not have comments in it, while the text area does. //this can cause finding the index of the set statement to fail if the user //has comments contained within their set statements (which should never happen unless the query is malformed). //In this case, we'll just suppress any failures. return; } textQuery.Select(startidx, qObjCur.Stmt.Length); }
///<summary>When a row is double clicked, bring up an input box that allows the user to change the variable's value.</summary> private void gridMain_CellDoubleClick(object sender, ODGridClickEventArgs e) { QuerySetStmtObject qObjCur = (QuerySetStmtObject)gridMain.SelectedGridRows[0].Tag; InputBox inputBox = new InputBox(new List <InputBoxParam> { new InputBoxParam(InputBoxType.TextBox, Lan.g(this, "Set value for") + " " + qObjCur.Variable, text: qObjCur.Value) }); inputBox.ShowDialog(); if (inputBox.DialogResult == DialogResult.OK) { string stmtOld = qObjCur.Stmt; //Regular expression for the expression @Variable = Value. Regex r = new Regex(Regex.Escape(qObjCur.Variable) + @"\s*=\s*" + Regex.Escape(qObjCur.Value)); string stmtNew = r.Replace(stmtOld, qObjCur.Variable + "=" + inputBox.textResult.Text); _queryCur.QueryText = _queryCur.QueryText.Replace(stmtOld, stmtNew); if (stmtOld == stmtNew) { return; //don't bother refilling the grid if the value didn't change. } textQuery.Text = _queryCur.QueryText; FillGrid(); } }
///<summary>Returns the list of variables in the query contained within the passed-in SET statement. ///Pass in one SET statement. Used in conjunction with GetListVals.</summary> private List <QuerySetStmtObject> GetListQuerySetStmtObjs(string setStmt) { List <string> strSplits = UserQueries.SplitQuery(setStmt, false, ","); for (int i = 0; i < strSplits.Count; i++) { Regex r = new Regex(@"\s*set\s+", RegexOptions.IgnoreCase); strSplits[i] = r.Replace(strSplits[i], ""); } UserQueries.TrimList(strSplits); strSplits.RemoveAll(x => string.IsNullOrWhiteSpace(x) || !x.StartsWith("@") || x.StartsWith("@_")); List <QuerySetStmtObject> bufferList = new List <QuerySetStmtObject>(); for (int i = 0; i < strSplits.Count; i++) { QuerySetStmtObject qObj = new QuerySetStmtObject(); qObj.Stmt = setStmt; qObj.Variable = strSplits[i].Split(new char[] { '=' }, 2).First(); qObj.Value = strSplits[i].Split(new char[] { '=' }, 2).Last(); bufferList.Add(qObj); } return(bufferList); }