Ejemplo n.º 1
0
        private bool IsFunctionName(string name, Bot ChatBot, User ChatUser, out SQLBot_Function function)
        {
            if (name == "UNKNOWN")
            {
                function = null;
            }
            else
            {
                try
                {
                    BazaRelacyjnaDataContext dc = new BazaRelacyjnaDataContext();
                    function = dc.SQLBot_Function.Where(fn => fn.sqlfn_Name == name).FirstOrDefault();
                }
                catch (Exception)
                {
                    function = null;
                }
            }

            return(function != null);
        }
Ejemplo n.º 2
0
 private SQLBot_Function findFunctionForWord(string word, Bot ChatBot, User ChatUser)
 {
     if (word == "UNKNOWN")
     {
         return(null);
     }
     try
     {
         BazaRelacyjnaDataContext dc       = new BazaRelacyjnaDataContext();
         SQLBot_Function          function = dc.SQLBot_Function.Where(fn => fn.sqlfn_Name == word).FirstOrDefault();
         if (function != null)
         {
             return(function);
         }
         else
         {
             return(findFunctionForWord(AIMLWhatIs(word, ChatBot, ChatUser), ChatBot, ChatUser));
         }
     }
     catch (Exception)
     {
     }
     return(null);
 }
Ejemplo n.º 3
0
        public void Initialize(Bot ChatBot, User ChatUser, string FieldName)
        {
            this.Word = FieldName;
            SQLWord sqlWord       = this;
            SQLWord sqlWordParent = null;

            while (sqlWord.Word != null && sqlWord.Word != string.Empty)
            {
                try
                {
                    string fieldDesc = AIMLWhatIs(sqlWord.Word, ChatBot, ChatUser);
                    string fieldType = AIMLWhatTypeIs(sqlWord.Word, ChatBot, ChatUser);

                    if (IsNumber(FieldName, ChatBot, ChatUser))
                    {
                        fieldType = "NUMBER";
                    }
                    else if (IsMonth(FieldName, ChatBot, ChatUser))
                    {
                        fieldType = "MONTH";
                    }


                    switch (fieldDesc)
                    {
                    case "UNKNOWN":
                        sqlWord.Definition = null;
                        break;

                    default:
                        sqlWord.Definition = fieldDesc;
                        break;
                    }
                    ;

                    switch (fieldType)
                    {
                    case "NUMBER":
                        sqlWord.WordType = EWordType.Number;
                        break;

                    case "TABLE":
                        sqlWord.WordType = EWordType.Table;
                        break;

                    case "FIELD":
                        sqlWord.WordType = EWordType.Field;
                        break;

                    case "VALUE":
                        sqlWord.WordType = EWordType.Value;
                        break;

                    case "FUNCTION":
                        sqlWord.WordType = EWordType.Function;
                        break;

                    case "DATE":
                        sqlWord.WordType = EWordType.Date;
                        break;

                    case "DATE PERIOD":
                        sqlWord.WordType = EWordType.Date;
                        break;

                    case "MONTH":
                        sqlWord.WordType = EWordType.Month;
                        break;

                    case "DATE AFFIX":
                        sqlWord.WordType = EWordType.DateAffix;
                        break;

                    case "UNKNOWN":
                    default:
                        sqlWord.WordType = EWordType.Unknown;
                        break;
                    }
                    ;

                    string[]        sqlTables = null;
                    string[]        sqlFields = null;
                    SQLBot_Function function  = null;

                    if (IsTableName(sqlWord.Word, out sqlTables) && sqlTables.Length > 0)
                    {
                        SQLTable = sqlTables[0];
                    }

                    if (IsFieldName(sqlWord.Word, out sqlFields, out sqlTables))
                    {
                        if (sqlFields.Length > 0)
                        {
                            SQLColumn = sqlFields[0];
                        }
                        if (sqlTables.Length > 0)
                        {
                            SQLTable = sqlTables[0];
                        }

                        if (SQLTable != null && SQLColumn != null)
                        {
                            SQLColumn = string.Format("{0}.{1}", SQLTable, SQLColumn);
                        }
                    }

                    if (IsFunctionName(sqlWord.Word, ChatBot, ChatUser, out function))
                    {
                        SQLFunction = new SQLFunction(function);
                    }
                }
                catch (Exception)
                { }
                finally
                {   // Tutaj jest źle!
                    if (sqlWordParent != null)
                    {
                        sqlWordParent.Child = sqlWord;
                    }

                    sqlWord.Parent = sqlWordParent;

                    sqlWordParent = sqlWord;
                    sqlWord       = new SQLWord();
                    sqlWord.Word  = sqlWordParent.Definition;

                    /*
                     * sqlWord.Parent = sqlWordParent;
                     * sqlWordParent = sqlWord;
                     * sqlWord = new SQLWord();
                     * sqlWord.Word = sqlWordParent.Definition;
                     *
                     * sqlWordParent.Child = sqlWord;
                     */
                }
            }
            ;

            sqlWordParent.Child = null;
        }