Beispiel #1
0
        public async Task None(IDialogContext context, LuisResult result)
        {
            string          textToShow  = string.Empty;
            List <string[]> queryResult = new List <string[]>();

            getValueAndType = new ValueOfResult(result);
            bool isHaveKey       = HelpMethod.isHave(getValueAndType, typeForLimit);//判断是否含有需要的用于查询的关键词关键词
            int  stateOfAskLevel = HelpMethod.isAskLevel(getValueAndType);

            if (stateOfAskLevel != 0 && isHaveKey)
            {
                //含有查询关键词,能够定义到某一行数据,由stateOfAskLevel判断为查询测试水平是否正常
                queryResult = new List <string[]>(getValueAndType.QueryByValue(connectString, tableOfExamination, typeForSelect, typeForLimit).ToArray()); //查询数据库
                string[] textToShows = HelpMethod.GenerateTextForAskLevel(getValueAndType, queryResult, stateOfAskLevel);                                  //比较单位,生成输出文本
                foreach (var itemText in textToShows)
                {
                    await context.PostAsync(itemText);
                }
            }
            else if (HelpMethod.isHave(getValueAndType, new string[] { "keyWordForAskInfo" }) && queryResultHistory.Count > 0)
            {
                //判断是否含有需要需要查询的信息
                //如果有,则认为是连续查询
                getValueAndType.generateSelectValue(typeForSelect);
                List <int> indexOfSelectField = HelpMethod.translateSelectIndex(getValueAndType.SelectValue, fieldOfTable); //确定需要查询的内容
                foreach (var item in indexOfSelectField)
                {                                                                                                           //合成查询结果,返回需要的信息
                    for (int i = 0; i < queryResultHistory.Count(); i++)
                    {
                        textToShow = fieldOfTableChineseName[item] + queryResultHistory[i][item] + "\r\n";
                    }
                }
            }
            else
            {
                textToShow = "不知道你说什么?";
            }
            if (textToShow.Length > 0)
            {
                await context.PostAsync(textToShow);
            }
            context.Wait(MessageReceived);
        }
Beispiel #2
0
        public async Task BodyCheck(IDialogContext context, LuisResult result)
        {
            string          textToShow  = string.Empty;
            List <string[]> queryResult = new List <string[]>();

            getValueAndType = new ValueOfResult(result);
            bool isHaveKey = HelpMethod.isHave(getValueAndType, typeForLimit);//判断是否含有需要的用于查询的关键词关键词

            if (isHaveKey)
            {
                //查询关键词
                queryResult = new List <string[]>(getValueAndType.QueryByValue(connectString, tableOfExamination, typeForSelect, typeForLimit).ToArray());//查询数据库
                if (queryResult.Count != 0)
                {
                    //如果查询得到相关信息,保证数据库返回了信息
                    int stateOfAskLevel = HelpMethod.isAskLevel(getValueAndType);
                    if (stateOfAskLevel != 0 && queryResult.Count == 1)
                    {
                        //如果是查询检测水平是否正常的话,执行如下代码
                        string[] textToShows = HelpMethod.GenerateTextForAskLevel(getValueAndType, queryResult, stateOfAskLevel);
                        foreach (var itemText in textToShows)
                        {
                            await context.PostAsync(itemText);
                        }
                    }
                    else
                    {
                        //不是查询检查水平是否正常,执行如下代码
                        List <int> indexOfSelectField = HelpMethod.translateSelectIndex(getValueAndType.SelectValue, fieldOfTable);//确定需要查询的内容
                        if (indexOfSelectField.Count == 0)
                        {
                            //如果没有指明要查询的内容,默认返回简要介绍
                            indexOfSelectField.Add(5);
                        }

                        foreach (var item in indexOfSelectField)
                        {//合成查询结果,返回需要的信息
                            for (int i = 0; i < queryResult.Count(); i++)
                            {
                                textToShow = fieldOfTableChineseName[item] + queryResult[i][item] + "\r\n";
                            }
                        }
                    }
                }
                else
                {
                    //数据库查询不到相关信息
                    textToShow = "数据库查询不到相关信息";
                }
            }
            else
            {
                //不含有查询关键词
                if (HelpMethod.isHave(getValueAndType, new string[] { "keyWordForAskInfo" }) && queryResultHistory.Count > 0)
                {
                    //判断是否含有需要需要查询的信息
                    //如果有,则认为是连续查询
                    getValueAndType.generateSelectValue(typeForSelect);
                    List <int> indexOfSelectField = HelpMethod.translateSelectIndex(getValueAndType.SelectValue, fieldOfTable); //确定需要查询的内容
                    foreach (var item in indexOfSelectField)
                    {                                                                                                           //合成查询结果,返回需要的信息
                        for (int i = 0; i < queryResultHistory.Count(); i++)
                        {
                            textToShow = fieldOfTableChineseName[item] + queryResultHistory[i][item] + "\r\n";
                        }
                    }
                }
                else
                {
                    textToShow = "识别不出指标名称,请输入合适的关键词(如指标名称,指标英文名称)";
                }
            }

            if (queryResult.Count() > 0)
            {
                queryResultHistory = queryResult;
            }
            if (textToShow.Length > 0)
            {
                await context.PostAsync(textToShow);
            }
            context.Wait(MessageReceived);
        }