Get Filter Query Repricing Gap

mail@pastecode.io avatar
unknown
plain_text
21 days ago
2.5 kB
1
Indexable
Never
  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