Exemple #1
0
        public static string GenerateFilterFromJsonObject(Type T, string _filter, int authenticatedUserId, string connectionString)
        {
            string toReturn = "";

            try
            {
                JObject jObj = JObject.Parse(_filter);
                if (jObj.Count == 2)
                {
                    /*
                     * JToken j1 = jObj[0];
                     * JToken j2 = jObj[1];
                     * if(JsonConvert.DeserializeObject(JsonConvert.SerializeObject( j1), T).GetType().Name.IndexOf("Dosar") > -1 && j2.HasValues)
                     */
                    JToken j1 = jObj["jDosar"];
                    JToken j2 = jObj["jdosarJson"];
                    if (jObj["jDosar"] != null && jObj["jdosarJson"] != null)
                    {
                        string f1 = GenerateFilterFromJsonObject(T, JsonConvert.SerializeObject(j1), authenticatedUserId, connectionString);
                        string f2 = GenerateFilterFromJsonObject(T, JsonConvert.SerializeObject(j2), authenticatedUserId, connectionString);
                        toReturn = !String.IsNullOrEmpty(f1) && !String.IsNullOrEmpty(f2) ? String.Format("{0} AND {1}", f1, f2) : String.Format("{0}{1}", f1 == null ? "" : f1, f2 == null ? "" : f2);
                        return(toReturn);
                    }
                }
            }
            catch { }


            try
            {
                //dynamic jObj = JsonConvert.DeserializeObject(_filter);
                JObject        jObj        = JObject.Parse(_filter);
                var            x           = Activator.CreateInstance(T, new object[] { authenticatedUserId, connectionString });
                string         className   = x.GetType().Name; // to check if it returns only the short name
                string         tableAllias = CommonFunctions.ClassNamesTableNamesAlliases[className].ToUpper();
                PropertyInfo[] pisX        = x.GetType().GetProperties();
                //PropertyInfo[] pisJObj = jObj.GetType().GetProperties();
                //foreach (PropertyInfo piJObj in pisJObj)
                foreach (var t in jObj)
                {
                    string key = t.Key;
                    JToken j   = t.Value;
                    bool   propertyInMasterObject = false;
                    foreach (PropertyInfo piX in pisX)
                    {
                        //if (piX.Name == piJObj.Name)
                        if (piX.Name != "ID" && (j != null && !String.IsNullOrEmpty(j.ToString())))
                        {
                            if (piX.Name == key)
                            {
                                string op = "";
                                switch (piX.PropertyType.ToString())
                                {
                                case "System.Boolean":
                                case "System.Nullable`1[System.Boolean]":
                                    op        = String.IsNullOrEmpty(j.ToString()) ? "is null" : String.Format("= {0}", j.ToString().ToLower());
                                    toReturn += String.Format("{0}{1}.`{2}` {3}", (toReturn == "" ? "" : " AND "), tableAllias, piX.Name, op);
                                    break;

                                case "System.DateTime":
                                case "System.Nullable`1[System.DateTime]":
                                    if (j.ToString().IndexOf('?') > -1)
                                    {
                                        DateTime dStart = Convert.ToDateTime(j.ToString().Split('?')[0]);
                                        DateTime dEnd   = Convert.ToDateTime(j.ToString().Split('?')[1]);
                                        toReturn += String.Format("{0}(DATE({1}.`{2}`) >= '{3}' AND DATE({1}.`{2}`) <= '{4}')", (toReturn == "" ? " " : " AND "), tableAllias, piX.Name, CommonFunctions.ToMySqlFormatDate(dStart), CommonFunctions.ToMySqlFormatDate(dEnd));
                                    }
                                    else
                                    {
                                        DateTime d = Convert.ToDateTime(j.ToString());
                                        toReturn += String.Format("{0} {1}.`{2}` = '{3}'", (toReturn == "" ? " " : " AND "), tableAllias, piX.Name, CommonFunctions.ToMySqlFormatDate(d));
                                    }
                                    break;

                                case "System.Double":
                                case "System.Nullable`1[System.Double]":
                                case "System.Decimal":
                                case "System.Nullable`1[System.Decimal]":
                                    op = j.ToString().StartsWith("*") && j.ToString().EndsWith("*") ? String.Format("like '%{0}%'", j.ToString() == null?null:Convert.ToDouble(CommonFunctions.BackDoubleValue(j.ToString().Substring(1, j.ToString().Length - 2))).ToString(CultureInfo.InvariantCulture)) :
                                         j.ToString().StartsWith("*") ? String.Format("like '%{0}'", j.ToString() == null ? null : Convert.ToDouble(CommonFunctions.BackDoubleValue(j.ToString().Substring(1, j.ToString().Length - 1))).ToString(CultureInfo.InvariantCulture)) :
                                         j.ToString().EndsWith("*") ? String.Format("like '{0}%'", j.ToString() == null?null: Convert.ToDouble(CommonFunctions.BackDoubleValue(j.ToString().Substring(0, j.ToString().Length - 1))).ToString(CultureInfo.InvariantCulture)) :
                                         String.Format("= '{0}'", j.ToString() == null? null:Convert.ToDouble(CommonFunctions.BackDoubleValue(j.ToString())).ToString(CultureInfo.InvariantCulture));
                                    toReturn += String.Format("{0}{1}.`{2}` {3}", (toReturn == "" ? "" : " AND "), tableAllias, piX.Name, op);
                                    break;

                                default:
                                    op        = j.ToString().StartsWith("*") && j.ToString().EndsWith("*") ? String.Format("like '%{0}%'", j.ToString().Substring(1, j.ToString().Length - 2)) : j.ToString().StartsWith("*") ? String.Format("like '%{0}'", j.ToString().Substring(1, j.ToString().Length - 1)) : j.ToString().EndsWith("*") ? String.Format("like '{0}%'", j.ToString().Substring(0, j.ToString().Length - 1)) : String.Format("= '{0}'", j.ToString());
                                    toReturn += String.Format("{0}{1}.`{2}` {3}", (toReturn == "" ? "" : " AND "), tableAllias, piX.Name, op);
                                    break;
                                }

                                propertyInMasterObject = true;
                                break;
                            }
                        }
                    }
                    if (!propertyInMasterObject && (j != null && !String.IsNullOrEmpty(j.ToString()))) // pt. campuri externe trimise pt. filtrare - ex. Nume societate sau asigurat din Dosar
                    {
                        string op = j.ToString().StartsWith("*") && j.ToString().EndsWith("*") ? String.Format("like '%{0}%'", j.ToString().Substring(1, j.ToString().Length - 2)) : j.ToString().StartsWith("*") ? String.Format("like '%{0}'", j.ToString().Substring(1, j.ToString().Length - 1)) : j.ToString().EndsWith("*") ? String.Format("like '{0}%'", j.ToString().Substring(0, j.ToString().Length - 2)) : String.Format("= '{0}'", j.ToString());
                        //switch (piJObj.Name.ToLower().Replace("_", "").Replace(" ", ""))
                        switch (key.ToLower().Replace("_", "").Replace(" ", ""))
                        {
                        case "asiguratcasco":
                        case "numeasiguratcasco":
                            //toReturn += String.Format("{2}ASIGC.`{0}` LIKE '%{1}%'", "DENUMIRE", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}ASIGC.`{0}` LIKE '{1}%'", "DENUMIRE", j.ToString(), (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}ASIGC.`{0}` {1}", "DENUMIRE", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "asiguratrca":
                        case "numeasiguratrca":
                            //toReturn += String.Format("{2}ASIGR.`{0}` LIKE '%{1}%'", "DENUMIRE", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}ASIGR.`{0}` LIKE '{1}%'", "DENUMIRE", j.ToString(), (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}ASIGR.`{0}` {1}", "DENUMIRE", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "autocasco":
                        case "numarautocasco":
                            //toReturn += String.Format("{2}AC.`{0}` LIKE '%{1}%'", "NR_AUTO", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}AC.`{0}` LIKE '{1}%'", "NR_AUTO", j.ToString(), (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}AC.`{0}` {1}", "NR_AUTO", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "autorca":
                        case "numarautorca":
                            //toReturn += String.Format("{2}AR.`{0}` LIKE '%{1}%'", "NR_AUTO", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}AR.`{0}` LIKE '{1}%'", "NR_AUTO", j.ToString(), (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}AR.`{0}` {1}", "NR_AUTO", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "societatecasco":
                        case "asiguratorcasco":
                            //toReturn += String.Format("{2}SC.`{0}` LIKE '%{1}%'", "DENUMIRE_SCURTA", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}SC.`{0}` LIKE '{1}%'", "DENUMIRE_SCURTA", j.ToString(), (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}SC.`{0}` {1}", "DENUMIRE_SCURTA", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "societaterca":
                        case "asiguratorrca":
                            //toReturn += String.Format("{2}SR.`{0}` LIKE '%{1}%'", "DENUMIRE_SCURTA", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}SR.`{0}` LIKE '{1}%'", "DENUMIRE_SCURTA", j.ToString(), (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}SR.`{0}` {1}", "DENUMIRE_SCURTA", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "intervenient":
                        case "numeintervenient":
                            //toReturn += String.Format("{2}I.`{0}` LIKE '%{1}%'", "DENUMIRE", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}I.`{0}` LIKE '{1}%'", "DENUMIRE", j.ToString(), (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}I.`{0}` {1}", "DENUMIRE", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "tipdosar":
                            //toReturn += String.Format("{2}TD.`{0}` LIKE '%{1}%'", "DENUMIRE", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}TD.`{0}` LIKE '{1}%'", "DENUMIRE", j.ToString(), (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}TD.`{0}` {1}", "DENUMIRE", op, (toReturn == "" ? "" : " AND "));
                            break;
                        }
                    }
                }

                /*
                 * MethodInfo mi = x.GetType().GetMethod("ValidareColoane");
                 * response res = (response)mi.Invoke(x, new object[] { _filter });
                 * if (res.Status)
                 * {
                 *  mi = x.GetType().GetMethod("GenerateFilterFromJsonObject");
                 *  var r = mi.Invoke(x, null);
                 *  toReturn = r.ToString();
                 * }
                 */
            }
            catch { }
            return(toReturn);
        }
Exemple #2
0
        public static string GenerateFilterFromJsonObject(Type T, string _filter, int authenticatedUserId, string connectionString)
        {
            string toReturn = "";

            try
            {
                JObject jObj = JObject.Parse(_filter);
                if (jObj.Count == 2)
                {
                    /*
                     * JToken j1 = jObj[0];
                     * JToken j2 = jObj[1];
                     * if(JsonConvert.DeserializeObject(JsonConvert.SerializeObject( j1), T).GetType().Name.IndexOf("Dosar") > -1 && j2.HasValues)
                     */
                    JToken j1 = jObj["jObject"];
                    JToken j2 = jObj["jobjectJson"];
                    if (jObj["jObject"] != null && jObj["jobjectJson"] != null)
                    {
                        string f1 = GenerateFilterFromJsonObject(T, JsonConvert.SerializeObject(j1), authenticatedUserId, connectionString);
                        string f2 = GenerateFilterFromJsonObject(T, JsonConvert.SerializeObject(j2), authenticatedUserId, connectionString);
                        toReturn = !String.IsNullOrEmpty(f1) && !String.IsNullOrEmpty(f2) ? String.Format("{0} AND {1}", f1, f2) : String.Format("{0}{1}", f1 == null ? "" : f1, f2 == null ? "" : f2);
                        return(toReturn);
                    }
                }
            }
            catch { }


            try
            {
                //dynamic jObj = JsonConvert.DeserializeObject(_filter);
                JObject        jObj        = JObject.Parse(_filter);
                var            x           = Activator.CreateInstance(T, new object[] { authenticatedUserId, connectionString });
                string         className   = x.GetType().Name; // to check if it returns only the short name
                string         tableAllias = CommonFunctions.ClassNamesTableNamesAlliases[className].ToUpper();
                PropertyInfo[] pisX        = x.GetType().GetProperties();
                //PropertyInfo[] pisJObj = jObj.GetType().GetProperties();
                //foreach (PropertyInfo piJObj in pisJObj)
                foreach (var t in jObj)
                {
                    string key = t.Key;
                    JToken j   = t.Value;
                    string v   = j == null || j.IsNullOrEmpty() ? null : (j.Type == JTokenType.Float ? j.ToString(Formatting.None) : j.ToString());
                    bool   propertyInMasterObject = false;
                    foreach (PropertyInfo piX in pisX)
                    {
                        ////if (piX.Name == piJObj.Name)
                        //if (piX.Name != "ID" && (j != null && !String.IsNullOrEmpty(v)))
                        if (j != null && !String.IsNullOrEmpty(v))
                        {
                            if (piX.Name == key)
                            {
                                string op = "";
                                switch (piX.PropertyType.ToString())
                                {
                                case "System.Boolean":
                                case "System.Nullable`1[System.Boolean]":
                                    op        = String.IsNullOrEmpty(v) ? "is null" : String.Format("= {0}", v.ToLower());
                                    toReturn += String.Format("{0}{1}.`{2}` {3}", (toReturn == "" ? "" : " AND "), tableAllias, piX.Name, op);
                                    break;

                                case "System.DateTime":
                                case "System.Nullable`1[System.DateTime]":
                                    if (v.IndexOf('?') > -1)
                                    {
                                        DateTime dStart = Convert.ToDateTime(v.Split('?')[0]);
                                        DateTime dEnd   = Convert.ToDateTime(v.Split('?')[1]);
                                        toReturn += String.Format("{0}(DATE({1}.`{2}`) >= '{3}' AND DATE({1}.`{2}`) <= '{4}')", (toReturn == "" ? " " : " AND "), tableAllias, piX.Name, CommonFunctions.ToMySqlFormatDate(dStart), CommonFunctions.ToMySqlFormatDate(dEnd));
                                    }
                                    else
                                    {
                                        DateTime d = Convert.ToDateTime(v);
                                        toReturn += String.Format("{0} {1}.`{2}` = '{3}'", (toReturn == "" ? " " : " AND "), tableAllias, piX.Name, CommonFunctions.ToMySqlFormatDate(d));
                                    }
                                    break;

                                case "System.Double":
                                case "System.Nullable`1[System.Double]":
                                case "System.Decimal":
                                case "System.Nullable`1[System.Decimal]":
                                    op = v.StartsWith("*") && v.EndsWith("*") ? String.Format("like '%{0}%'", v == null?null:Convert.ToDouble(CommonFunctions.BackDoubleValue(v.Substring(1, v.Length - 2))).ToString(CultureInfo.InvariantCulture)) :
                                         v.StartsWith("*") ? String.Format("like '%{0}'", v == null ? null : Convert.ToDouble(CommonFunctions.BackDoubleValue(v.Substring(1, v.Length - 1))).ToString(CultureInfo.InvariantCulture)) :
                                         v.EndsWith("*") ? String.Format("like '{0}%'", v == null?null: Convert.ToDouble(CommonFunctions.BackDoubleValue(v.Substring(0, v.Length - 1))).ToString(CultureInfo.InvariantCulture)) :
                                         String.Format("= '{0}'", v == null? null:Convert.ToDouble(CommonFunctions.BackDoubleValue(v)).ToString(CultureInfo.InvariantCulture));
                                    toReturn += String.Format("{0}{1}.`{2}` {3}", (toReturn == "" ? "" : " AND "), tableAllias, piX.Name, op);
                                    break;

                                default:
                                    op        = v.StartsWith("*") && v.EndsWith("*") ? String.Format("like '%{0}%'", v.Substring(1, v.Length - 2)) : v.StartsWith("*") ? String.Format("like '%{0}'", v.Substring(1, v.Length - 1)) : v.EndsWith("*") ? String.Format("like '{0}%'", v.Substring(0, v.Length - 1)) : String.Format("= '{0}'", v);
                                    toReturn += String.Format("{0}{1}.`{2}` {3}", (toReturn == "" ? "" : " AND "), tableAllias, piX.Name, op);
                                    break;
                                }

                                propertyInMasterObject = true;
                                break;
                            }
                        }
                    }
                    if (!propertyInMasterObject && (j != null && !String.IsNullOrEmpty(v))) // pt. campuri externe trimise pt. filtrare - ex. Nume societate sau asigurat din Dosar
                    {
                        string op = v.StartsWith("*") && v.EndsWith("*") ? String.Format("like '%{0}%'", v.Substring(1, v.Length - 2)) : v.StartsWith("*") ? String.Format("like '%{0}'", v.Substring(1, v.Length - 1)) : v.EndsWith("*") ? String.Format("like '{0}%'", v.Substring(0, v.Length - 1)) : String.Format("= '{0}'", v);
                        //switch (piJObj.Name.ToLower().Replace("_", "").Replace(" ", ""))
                        switch (key.ToLower().Replace("_", "").Replace(" ", ""))
                        {
                        //dosare
                        case "calitatesocietate":
                            string[] statuses = op.Replace("=", "").Replace("'", "").Trim().Split(',');
                            toReturn += String.Format("{0}(DOSARE.STATUS IN (", (toReturn == "" ? "" : " AND "));
                            for (int i = 0; i < statuses.Length; i++)
                            {
                                toReturn += String.Format("'{1}'{0}", i == statuses.Length - 1 ? "" : ",", statuses[i]);
                            }
                            toReturn += "))";
                            break;

                        case "asiguratcasco":
                        case "numeasiguratcasco":
                            //toReturn += String.Format("{2}ASIGC.`{0}` LIKE '%{1}%'", "DENUMIRE", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}ASIGC.`{0}` LIKE '{1}%'", "DENUMIRE", v, (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}ASIGC.`{0}` {1}", "DENUMIRE", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "asiguratrca":
                        case "numeasiguratrca":
                            //toReturn += String.Format("{2}ASIGR.`{0}` LIKE '%{1}%'", "DENUMIRE", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}ASIGR.`{0}` LIKE '{1}%'", "DENUMIRE", v, (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}ASIGR.`{0}` {1}", "DENUMIRE", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "autocasco":
                        case "numarautocasco":
                            //toReturn += String.Format("{2}AC.`{0}` LIKE '%{1}%'", "NR_AUTO", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}AC.`{0}` LIKE '{1}%'", "NR_AUTO", v, (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}AC.`{0}` {1}", "NR_AUTO", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "autorca":
                        case "numarautorca":
                            //toReturn += String.Format("{2}AR.`{0}` LIKE '%{1}%'", "NR_AUTO", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}AR.`{0}` LIKE '{1}%'", "NR_AUTO", v, (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}AR.`{0}` {1}", "NR_AUTO", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "societatecasco":
                        case "asiguratorcasco":
                            //toReturn += String.Format("{2}SC.`{0}` LIKE '%{1}%'", "DENUMIRE_SCURTA", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}SC.`{0}` LIKE '{1}%'", "DENUMIRE_SCURTA", v, (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}SC.`{0}` {1}", "DENUMIRE_SCURTA", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "societaterca":
                        case "asiguratorrca":
                            //toReturn += String.Format("{2}SR.`{0}` LIKE '%{1}%'", "DENUMIRE_SCURTA", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}SR.`{0}` LIKE '{1}%'", "DENUMIRE_SCURTA", v, (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}SR.`{0}` {1}", "DENUMIRE_SCURTA", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "intervenient":
                        case "numeintervenient":
                            //toReturn += String.Format("{2}I.`{0}` LIKE '%{1}%'", "DENUMIRE", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}I.`{0}` LIKE '{1}%'", "DENUMIRE", v, (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}I.`{0}` {1}", "DENUMIRE", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "tipdosar":
                            //toReturn += String.Format("{2}TD.`{0}` LIKE '%{1}%'", "DENUMIRE", piJObj.GetValue(jObj, null), (toReturn == "" ? "" : " AND "));
                            //toReturn += String.Format("{2}TD.`{0}` LIKE '{1}%'", "DENUMIRE", v, (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}TD.`{0}` {1}", "DENUMIRE", op, (toReturn == "" ? "" : " AND "));
                            break;

                        //procese
                        case "tipproces":
                            toReturn += String.Format("{2}TD.`{0}` {1}", "DENUMIRE", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "complet":
                            toReturn += String.Format("{2}C.`{0}` {1}", "DENUMIRE", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "instanta":
                            toReturn += String.Format("{2}I.`{0}` {1}", "DENUMIRE", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "reclamant":
                            toReturn += String.Format("{2} (REC1.`{0}` {1} OR REC2.`{3}` {4})", "DENUMIRE", op, (toReturn == "" ? "" : " AND "), "DENUMIRE", op);
                            break;

                        case "parat":
                            toReturn += String.Format("{2} (PAR1.`{0}` {1} OR PAR2.`{3}` {4})", "DENUMIRE", op, (toReturn == "" ? "" : " AND "), "DENUMIRE", op);
                            break;

                        case "tert":
                            toReturn += String.Format("{2} (TER.`{0}` {1})", "DENUMIRE", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "contract":
                            toReturn += String.Format("{2}CTR.`{0}` {1}", "NR_CONTRACT", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "stadiu":
                            toReturn += String.Format("{2}S.`{0}` {1}", "ID", op, (toReturn == "" ? "" : " AND "));
                            break;

                        case "datastadiu":
                            if (v.IndexOf('?') > -1)
                            {
                                DateTime dStart = Convert.ToDateTime(v.Split('?')[0]);
                                DateTime dEnd   = Convert.ToDateTime(v.Split('?')[1]);
                                toReturn += String.Format("{0} (DATE({1}.`{2}`) >= '{3}' AND DATE({1}.`{2}`) <= '{4}')", (toReturn == "" ? " " : " AND "), "PS", "DATA", CommonFunctions.ToMySqlFormatDate(dStart), CommonFunctions.ToMySqlFormatDate(dEnd));
                            }
                            else
                            {
                                DateTime d = Convert.ToDateTime(v);
                                toReturn += String.Format("{0} {1}.`{2}` = '{3}'", (toReturn == "" ? " " : " AND "), "PS", "DATA", CommonFunctions.ToMySqlFormatDate(d));
                            }
                            break;

                        case "calitate":
                            toReturn += String.Format("{0} {1}", (toReturn == "" ? "" : " AND "), v);
                            break;

                        case "dosarfaradocumente":
                            //toReturn += String.Format("{2}IFNULL(DS.`{0}`, 0) {1}", "CNT", op.ToLower().IndexOf("true") > -1 ? " = 0 " : op.ToLower().IndexOf("false") > -1 ? " > 0 " : " >= 0 ", (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}IFNULL(DOSARE.`{0}`, 0) {1}", "COUNT_DOCUMENTE", op.ToLower().IndexOf("true") > -1 ? " = 0 " : op.ToLower().IndexOf("false") > -1 ? " > 0 " : " >= 0 ", (toReturn == "" ? "" : " AND "));
                            break;

                        case "dosarfaraproces":
                            //toReturn += String.Format("{2}IFNULL(P.`{0}`, 0) {1}", "CNT", op.ToLower().IndexOf("true") > -1 ? " = 0 " : op.ToLower().IndexOf("false") > -1 ? " > 0 " : " >= 0 ", (toReturn == "" ? "" : " AND "));
                            toReturn += String.Format("{2}IFNULL(DOSARE.`{0}`, 0) {1}", "COUNT_PROCESE", op.ToLower().IndexOf("true") > -1 ? " = 0 " : op.ToLower().IndexOf("false") > -1 ? " > 0 " : " >= 0 ", (toReturn == "" ? "" : " AND "));
                            break;
                        }
                    }
                }

                /*
                 * MethodInfo mi = x.GetType().GetMethod("ValidareColoane");
                 * response res = (response)mi.Invoke(x, new object[] { _filter });
                 * if (res.Status)
                 * {
                 *  mi = x.GetType().GetMethod("GenerateFilterFromJsonObject");
                 *  var r = mi.Invoke(x, null);
                 *  toReturn = r.ToString();
                 * }
                 */
            }
            catch { }
            return(toReturn);
        }