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 gridMain_CellLeave(object sender, ODGridClickEventArgs e) { QuerySetStmtObject qObjCur; GridRow rowLeaving; try { //Can not use gridMain.SelectedGridRows due to leave being hit multiple times by input texboxes. //Base grid logic fires this leave function multiple times. rowLeaving = gridMain.ListGridRows[e.Row]; qObjCur = (QuerySetStmtObject)rowLeaving.Tag; } catch { //Has occurend when user types SHIFT+ENTER on the keyboard. return; } string stmtOld = qObjCur.Stmt; string varOld = qObjCur.Variable; string valOld = qObjCur.Value; string valNew = rowLeaving.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. } if (HasQuotes(valOld)) { valNew = "'" + valNew.Trim().Trim('\"').Trim('\'') + "'"; } //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 = r.Replace(_queryCur.QueryText, varOld + "=" + valNew); textQuery.Text = _queryCur.QueryText; qObjCur.Stmt = stmtNew; qObjCur.Value = valNew; gridMain.ListGridRows.OfType <GridRow>().Where(x => ((QuerySetStmtObject)x.Tag).Stmt == stmtOld).ToList().ForEach(y => { ((QuerySetStmtObject)y.Tag).Stmt = stmtNew; }); }
///<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); }