public ActionResult InsertOrUpdateQuery(int id, string name, string where, int tabid, int tid, List <QueryModel> qLines) { int no = -1; if (id == 0) { string sql = "SELECT Count(*) FROM AD_UserQuery WHERE AD_Table_ID=" + tid + " AND AD_Tab_ID=" + tabid + " AND Upper(Name)='" + name.ToUpper() + "'"; int count = Convert.ToInt32(DB.ExecuteScalar(MRole.GetDefault(Session["ctx"] as VAdvantage.Utility.Ctx).AddAccessSQL(sql, "AD_UserQuery", true, false))); if (count > 0) { return(Json(-5)); } } var uq = new VAdvantage.Model.MUserQuery(Session["ctx"] as VAdvantage.Utility.Ctx, id, null); //set query name if (name != null && name.Length > 0) { uq.SetName(name); } // set query code uq.SetCode(where); // set tab id uq.SetAD_Tab_ID(tabid); // set table id uq.SetAD_Table_ID(tid); // save the values in database if (uq.Save()) { no = uq.Get_ID(); // delete existing query lines uq.DeleteLines(); // if no lines then return if (qLines == null || qLines.Count < 1) { ; } else { int totCnt = qLines.Count; // save each the query lines in the dataset for (int i = 0; i < totCnt; i++) { QueryModel m = qLines[i]; // set values VAdvantage.Model.MUserQueryLine line = new VAdvantage.Model.MUserQueryLine(uq, (i + 1) * 10, m.KEYNAME ?? "", m.KEYVALUE ?? "", m.OPERATORNAME ?? "", m.VALUE1NAME ?? "", m.VALUE1VALUE ?? "", m.VALUE2NAME ?? "", m.VALUE2VALUE ?? "", m.FULLDAY == "Y" ? true : false); // save query line line.Save(); } } } return(Json(no)); }
public ActionResult DeleteQuery(int id) { int no = -1; var uq = new VAdvantage.Model.MUserQuery(Session["ctx"] as VAdvantage.Utility.Ctx, id, null); if (uq != null) { // get name of the query string name = uq.GetName(); // delete query if (uq.Delete(true)) { no = 1; } } return(Json(no)); }
/// <summary> /// Parameterized Contstructor /// Sets value in context /// </summary> /// <param name="parent">parent</param> /// <param name="seqNo">seq no</param> /// <param name="keyName">column Name(Key name)</param> /// <param name="keyValue">column Value(Key Value)</param> /// <param name="optr">operator</param> /// <param name="value1Name">query value text</param> /// <param name="value1Value">query value's value</param> /// <param name="value2Name">"to query value" text</param> /// <param name="value2Value">"to query value's" value</param> public MUserQueryLine(MUserQuery parent, int seqNo, string keyName, string keyValue, string optr, string value1Name, string value1Value, string value2Name, string value2Value) : base(parent.GetCtx(), 0, parent.Get_TrxName()) { SetClientOrg(parent); SetAD_UserQuery_ID(parent.GetAD_UserQuery_ID()); SetSeqNo(seqNo); // SetKeyValue(keyValue); SetKeyName(keyName); SetOperator(optr); // SetValue1Value(value1Value); SetValue1Name(value1Name); if (value2Name != null && value2Name.Length != 0) { SetValue2Value(value2Value); SetValue2Name(value2Name); } }