Exemplo n.º 1
0
        // 外部调用
        // 特殊版本,具有缓存问题和答案的功能
        // return:
        //      -2  strID验证失败
        //      -1  error
        //      0   canceled
        //      1   succeed
        public static int GetAuthorNumber(
            ref Hashtable question_table,
            Stop stop,
            System.Windows.Forms.IWin32Window parent,
            string strUrl,
            string strAuthor,
            bool bSelectPinyin,
            bool bSelectEntry,
            bool bOutputDebugInfo,
            out string strNumber,
            out string strDebugInfo,
            out string strError)
        {
            strError     = "";
            strDebugInfo = "";
            strNumber    = "";

            long nRet = 0;

            Question[] questions = (Question[])question_table[strAuthor];
            if (questions == null)
            {
                questions = new Question[0];
            }

            for (; ;)
            {
                LibraryChannel channel = Program.MainForm.GetChannel(strUrl, "public");
                try
                {
                    // 这个函数具有catch 通讯中 exeption的能力
                    // return:
                    //		-3	需要回答问题
                    //      -2  strID验证失败
                    //      -1  出错
                    //      0   成功
                    nRet = channel.GetAuthorNumber(
                        strAuthor,
                        bSelectPinyin,
                        bSelectEntry,
                        bOutputDebugInfo,
                        ref questions,
                        out strNumber,
                        out strDebugInfo,
                        out strError);
                    if (nRet != -3)
                    {
                        break;
                    }

                    Debug.Assert(nRet == -3, "");
                }
                finally
                {
                    Program.MainForm.ReturnChannel(channel);
                }

                string strTitle = strError;

                string strQuestion = questions[questions.Length - 1].Text;

                QuestionDlg dlg = new QuestionDlg();
                GuiUtil.AutoSetDefaultFont(dlg);
                dlg.StartPosition = FormStartPosition.CenterScreen;
                dlg.MessageTitle  = strTitle;
                dlg.Question      = strQuestion.Replace("\n", "\r\n");
                dlg.ShowDialog(parent);

                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "放弃";
                    return(0);
                }

                questions[questions.Length - 1].Answer = dlg.Question;

                question_table[strAuthor] = questions;  // 保存
            }

            if (nRet == -1)
            {
                return(-1);
            }
            if (nRet == -2)
            {
                return(-2);  // strID验证失败
            }
            return(1);
        }
Exemplo n.º 2
0
        protected void Button_get_Click(object sender, System.EventArgs e)
        {
            string strNumber    = "";
            string strDebugInfo = "";
            string strError     = "";

            long nRet = 0;

            this.TextBox_number.Text     = "";
            this.Label_debugInfo.Text    = "";
            this.Label_debugInfo.Visible = false;

            Question[] questions = JsonConvert.DeserializeObject <Question[]>(this.hidden_questions.Value);

            if (questions != null && string.IsNullOrEmpty(this.TextBox_answer.Text) == false)
            {
                Question question = questions[questions.Length - 1];
                question.Answer = this.TextBox_answer.Text;
            }

            LibraryChannel channel = sessioninfo.GetChannel(true);

            try
            {
                // return:
                //      -4  "著者 'xxx' 的整体或局部均未检索命中" 2017/3/1
                //		-3	需要回答问题
                //      -2  strID验证失败
                //      -1  出错
                //      0   成功
                nRet = channel.GetAuthorNumber(this.TextBox_author.Text,
                                               this.CheckBox_selectPinyin.Checked,
                                               this.CheckBox_selectEntry.Checked,
                                               this.CheckBox_outputDebugInfo.Checked,
                                               ref questions,
                                               out strNumber,
                                               out strDebugInfo,
                                               out strError);
                if (nRet == 0)
                {
                    this.Clear();

                    this.TextBox_number.Text     = strNumber;
                    this.Panel_debuginfo.Visible = this.CheckBox_outputDebugInfo.Checked;
                    this.Label_debugInfo.Text    = "<b>调试信息:</b><br/>" + GetHtmlString(strDebugInfo);
                    this.Label_debugInfo.Visible = true;
                }
                else if (nRet == -3)
                {
                    Debug.Assert(nRet == -3, "");       // 需要回答问题

                    EnableEdit(false);
                    this.Panel_debuginfo.Visible = false;

                    this.question_frame.Visible = true;

                    this.hidden_questions.Value = JsonConvert.SerializeObject(questions);

                    Question question = questions[questions.Length - 1];
                    this.Label_questionText.Text = GetHtmlString(question.Text);
                }
                else
                {
                    this.Clear();
                    this.Label_errorInfo.Text    = strError;
                    this.Panel_debuginfo.Visible = false;
                }
            }
            finally
            {
                sessioninfo.ReturnChannel(channel);
            }
        }