Exemple #1
0
        // 获得著者号
        // return:
        //      -1  error
        //      0   canceled
        //      1   succeed
        public int GetGcatAuthorNumber(string strGcatWebServiceUrl,
                                       string strAuthor,
                                       out string strAuthorNumber,
                                       out string strError)
        {
            strError        = "";
            strAuthorNumber = "";

            if (String.IsNullOrEmpty(strGcatWebServiceUrl) == true)
            {
                strGcatWebServiceUrl = "http://dp2003.com/dp2library/";  // "http://dp2003.com/gcatserver/" //  "http://dp2003.com/dp2libraryws/gcat.asmx";
            }
#if OLD_CODE
            if (strGcatWebServiceUrl.IndexOf(".asmx") != -1)
            {
                if (this.GcatChannel == null)
                {
                    this.GcatChannel = new DigitalPlatform.GcatClient.Channel();
                }

                string strDebugInfo = "";

                BeginGcatLoop("正在获取 '" + strAuthor + "' 的著者号,从 " + strGcatWebServiceUrl + " ...");
                try
                {
                    // return:
                    //      -1  error
                    //      0   canceled
                    //      1   succeed
                    int nRet = this.GcatChannel.GetNumber(
                        this.DetailForm.stop,
                        this.DetailForm,
                        strGcatWebServiceUrl,
                        strAuthor,
                        true,   // bSelectPinyin
                        true,   // bSelectEntry
                        true,   // bOutputDebugInfo
                        new DigitalPlatform.GcatClient.BeforeLoginEventHandle(gcat_channel_BeforeLogin),
                        out strAuthorNumber,
                        out strDebugInfo,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "取 著者 '" + strAuthor + "' 之号码时出错 : " + strError;
                        return(-1);
                    }

                    return(nRet);
                }
                finally
                {
                    EndGcatLoop();
                }
            }
            else if (strGcatWebServiceUrl.Contains("gcat"))
            {
                // 新的WebService

                string strID   = this.DetailForm.MainForm.AppInfo.GetString("DetailHost", "gcat_id", "");
                bool   bSaveID = this.DetailForm.MainForm.AppInfo.GetBoolean("DetailHost", "gcat_saveid", false);

                Hashtable question_table = (Hashtable)this.DetailForm.MainForm.ParamTable["question_table"];
                if (question_table == null)
                {
                    question_table = new Hashtable();
                }

REDO_GETNUMBER:
                string strDebugInfo = "";

                BeginGcatLoop("正在获取 '" + strAuthor + "' 的著者号,从 " + strGcatWebServiceUrl + " ...");
                try
                {
                    // return:
                    //      -1  error
                    //      0   canceled
                    //      1   succeed
                    int nRet = GcatNew.GetNumber(
                        ref question_table,
                        this.DetailForm.stop,
                        this.DetailForm,
                        strGcatWebServiceUrl,
                        strID, // ID
                        strAuthor,
                        true,  // bSelectPinyin
                        true,  // bSelectEntry
                        true,  // bOutputDebugInfo
                        out strAuthorNumber,
                        out strDebugInfo,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "取 著者 '" + strAuthor + "' 之号码时出错 : " + strError;
                        return(-1);
                    }
                    if (nRet == -2)
                    {
                        IdLoginDialog login_dlg = new IdLoginDialog();
                        GuiUtil.AutoSetDefaultFont(login_dlg);
                        login_dlg.Text = "获得著者号 -- "
                                         + ((string.IsNullOrEmpty(strID) == true) ? "请输入ID" : strError);
                        login_dlg.ID            = strID;
                        login_dlg.SaveID        = bSaveID;
                        login_dlg.StartPosition = FormStartPosition.CenterScreen;
                        if (login_dlg.ShowDialog(this.DetailForm) == DialogResult.Cancel)
                        {
                            return(-1);
                        }

                        strID   = login_dlg.ID;
                        bSaveID = login_dlg.SaveID;
                        if (login_dlg.SaveID == true)
                        {
                            this.DetailForm.MainForm.AppInfo.SetString("DetailHost", "gcat_id", strID);
                        }
                        else
                        {
                            this.DetailForm.MainForm.AppInfo.SetString("DetailHost", "gcat_id", "");
                        }
                        this.DetailForm.MainForm.AppInfo.SetBoolean("DetailHost", "gcat_saveid", bSaveID);
                        goto REDO_GETNUMBER;
                    }

                    this.DetailForm.MainForm.ParamTable["question_table"] = question_table;

                    return(nRet);
                }
                finally
                {
                    EndGcatLoop();
                }
            }
            else
#endif
            // dp2library 服务器
            {
                Hashtable question_table = (Hashtable)Program.MainForm.ParamTable["question_table"];
                if (question_table == null)
                {
                    question_table = new Hashtable();
                }

                string strDebugInfo = "";

                BeginGcatLoop("正在获取 '" + strAuthor + "' 的著者号,从 " + strGcatWebServiceUrl + " ...");
                try
                {
                    // return:
                    //      -1  error
                    //      0   canceled
                    //      1   succeed
                    long nRet = GetAuthorNumber(
                        ref question_table,
                        this.DetailForm.stop,
                        this.DetailForm,
                        strGcatWebServiceUrl,
                        strAuthor,
                        true,   // bSelectPinyin
                        true,   // bSelectEntry
                        true,   // bOutputDebugInfo
                        out strAuthorNumber,
                        out strDebugInfo,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "取 著者 '" + strAuthor + "' 之号码时出错 : " + strError;
                        return(-1);
                    }
                    Program.MainForm.ParamTable["question_table"] = question_table;
                    return((int)nRet);
                }
                finally
                {
                    EndGcatLoop();
                }
            }
        }
        void DoGetNumber()
        {
            if (string.IsNullOrEmpty(this.TextBox_author.Text) == true)
            {
                this.Label_errorInfo.Text = "请输入著者";
                return;
            }

            Question[] questions = RestoreQuestions(this.HiddenField_questions.Value);
            if (questions.Length > 0)
            {
                Question q = questions[questions.Length - 1];
                q.Answer = this.TextBox_answer.Text;
            }

            if (this.HiddenField_memoID.Value == "yes")
            {
                this.Response.Cookies["id"].Value      = this.HiddenField_id.Value;
                this.Response.Cookies["memo_id"].Value = this.HiddenField_memoID.Value;
            }
            else
            {
                this.Response.Cookies["id"].Value      = "";
                this.Response.Cookies["memo_id"].Value = "no";
            }
            this.Response.Cookies["id"].Expires      = DateTime.Now.AddDays(30);
            this.Response.Cookies["memo_id"].Expires = DateTime.Now.AddDays(30);

            string strNumber    = "";
            string strDebugInfo = "";
            string strError     = "";

            int nRet = 0;

            string strUrl = System.Configuration.ConfigurationManager.AppSettings["gcatserverurl"];

            // return:
            //		-3	需要回答问题
            //      -2  strID验证失败
            //      -1  出错
            //      0   成功
            nRet = GcatNew.GetNumber(null,
                                     strUrl,                    // "http://localhost/gcatserver/",
                                     this.HiddenField_id.Value, // strID,
                                     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 == -3)
            {
                PrepareQustionDialog(questions, strError);
                return;
            }

            this.TextBox_answer.Text = "";
            this.PlaceHolder_questionDialog.Visible = false;

            if (nRet == -2)
            {
                PrepareLoginDialog(strError);
                return;
            }

            this.PlaceHolder_loginDialog.Visible = false;


            if (nRet == 0)
            {
                this.TextBox_number.Text = strNumber;

                if (string.IsNullOrEmpty(strDebugInfo) == false)
                {
                    this.Label_debugInfo.Text = "<b>调试信息:</b><br/>" + GetHtmlString(strDebugInfo);
                }
                else
                {
                    this.Label_debugInfo.Text = "";
                }

                if (this.Label_debugInfo.Text == "")
                {
                    this.Panel_debuginfo.Visible = false;
                }
                else
                {
                    this.Panel_debuginfo.Visible = true;
                }

                this.Label_debugInfo.Visible = true;
                return;
            }

            if (nRet == -1)
            {
                this.Label_errorInfo.Text = strError;
                return;
            }

            if (nRet == -2)
            {
                // id验证失败
            }
        }