Get Filter Query Repricing Gap

 avatar
unknown
plain_text
a year ago
2.5 kB
3
Indexable
  public static string GetFilterQuery(ComponentEndOfMonth componentEndOfMonth, DateTime reportDate, string randomString)
  {
      string sqlWhere = string.Empty;

      List<ComponentEndOfMonthFormulaVariable> componentFormula = componentEndOfMonth.ComponentEndOfMonthFormulaVariables.ToList();
      if (componentFormula.Count > 0)
      {
          #region Sql Where
          int orderNo = 0;
          List<string> replaceValue = new List<string>() { "VAR", "OP", "IN", "LOG" };
          FormulaTemplate formulaTemplate = componentEndOfMonth.FormulaTemplate;
          ComponentEndOfMonthFormulaVariable obj = new ComponentEndOfMonthFormulaVariable();

          string[] formulaValue = formulaTemplate.Value.Split(' ');
          foreach (string item in formulaValue)
          {
              if (replaceValue.IndexOf(item) > -1)
              {
                  orderNo++;
                  obj = componentFormula.Where(a => a.OrderNo == orderNo).FirstOrDefault();
              }

              switch (item)
              {
                  case "(":
                  case ")":
                      {
                          sqlWhere += item + " ";
                      }
                      break;
                  case "VAR":
                      {
                          string tableName = GetTableName(obj.FormulaVariable.Value1, reportDate, randomString);
                          sqlWhere += "LOWER(" + tableName + "." + obj.FormulaVariable.Value2 + ")" + " ";
                      }
                      break;
                  case "OP":
                      {
                          sqlWhere += obj.FormulaVariable.Value1 + " ";
                      }
                      break;
                  case "IN":
                      {
                          if (obj.FormulaVariable.Value1 == "string")
                              sqlWhere += "LOWER(" + "'" + obj.Value + "'" + ")" + " ";
                          else if (obj.FormulaVariable.Value1 == "num")
                              sqlWhere += "LOWER(" + obj.Value + ")" + " ";
                      }
                      break;
                  case "LOG":
                      {
                          sqlWhere += obj.FormulaVariable.Value1 + " ";
                      }
                      break;
              }
          }
          #endregion
      }
      return sqlWhere;
  }
Leave a Comment