Пример #1
0
        // 保存
        // return:
        //      -1  error
        //      0   成功
        //      1   服务器端记录发生改变,未保存。注意重新保存记录
        int SaveReaderInfo(ReaderEditControl edit,
            out string strError)
        {
            strError = "";

            if (edit.Barcode == "")
            {
                strError = "尚未输入证条码号";
                goto ERROR1;
            }

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在保存读者记录 " + edit.Barcode + " ...");
            stop.BeginLoop();

            EnableControls(false);

            try
            {
                string strNewXml = "";
                int nRet = edit.GetData(
                    out strNewXml,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                ErrorCodeValue kernel_errorcode;

                byte[] baNewTimestamp = null;
                string strExistingXml = "";
                string strSavedXml = "";
                string strSavedPath = "";

                long lRet = Channel.SetReaderInfo(
                    stop,
                    "change",
                    edit.RecPath,
                    strNewXml,
                    edit.OldRecord,
                    edit.Timestamp,
                    out strExistingXml,
                    out strSavedXml,
                    out strSavedPath,
                    out baNewTimestamp,
                    out kernel_errorcode,
                    out strError);
                if (lRet == -1)
                {
                    // Debug.Assert(false, "");

                    if (kernel_errorcode == ErrorCodeValue.TimestampMismatch)
                    {
                        CompareReaderForm dlg = new CompareReaderForm();
                        dlg.Initial(
                            this.MainForm,
                            edit.RecPath,
                            strExistingXml,
                            baNewTimestamp,
                            strNewXml,
                            edit.Timestamp,
                            "数据库中的记录在编辑期间发生了改变。请仔细核对,并重新修改窗口中的未保存记录,按确定按钮后可重试保存。");

                        dlg.StartPosition = FormStartPosition.CenterScreen;
                        dlg.ShowDialog(this);
                        if (dlg.DialogResult == DialogResult.OK)
                        {
                            nRet = edit.SetData(dlg.UnsavedXml,
                                dlg.RecPath,
                                dlg.UnsavedTimestamp,
                                out strError);
                            if (nRet == -1)
                            {
                                return -1;
                            }
                            strError = "请注意重新保存记录";
                            return 1;
                        }
                    }

                    goto ERROR1;
                }

                /*
                this.Timestamp = baNewTimestamp;
                this.OldRecord = strSavedXml;
                this.RecPath = strSavedPath;
                 */

                if (lRet == 1)
                {
                    // 部分字段被拒绝
                    MessageBox.Show(this, strError);

                    if (Channel.ErrorCode == ErrorCode.PartialDenied)
                    {
                        // 提醒重新装载?
                        MessageBox.Show(this, "请重新装载记录, 检查哪些字段内容修改被拒绝。");
                    }
                }
                else
                {
                    // 重新装载记录到编辑器
                    nRet = edit.SetData(strSavedXml,
                        strSavedPath,
                        baNewTimestamp,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                }

            }
            finally
            {
                EnableControls(true);

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }

            strError = "保存成功";
            return 0;
        ERROR1:
            return -1;
        }
Пример #2
0
        // 根据读者证条码号,装入读者记录
        // parameters:
        //      edit    读者编辑控件。可以==null
        //      webbHtml    用于显示HTML的WebBrowser控件。可以==null
        //      webbXml   用于显示XML的WebBrowser控件。可以==null
        // return:
        //      0   cancelled
        internal int LoadRecord(ref string strBarcode,
            ReaderEditControl edit,
            WebExternalHost external_html,
            // WebBrowser webbHtml,
            WebBrowser webbXml)
        {
            string strError = "";
            int nRet = 0;

            if (edit != null
                && edit.Changed == true)
            {
                // 警告尚未保存
                DialogResult result = MessageBox.Show(this,
"当前有信息被修改后尚未保存。若此时装载新内容,现有未保存信息将丢失。\r\n\r\n确实要根据证条码号重新装载内容? ",
"ActivateForm",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
                if (result != DialogResult.Yes)
                    return 0;   // cancelled

            }

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在初始化浏览器组件 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            EnableControls(false);

            if (edit != null)
                edit.Clear();
#if NO
            if (webbHtml != null)
            {
                Global.ClearHtmlPage(webbHtml,
                    this.MainForm.DataDir);
            }
#endif
            if (external_html != null)
            {
                external_html.ClearHtmlPage();
            }

            if (webbXml != null)
            {
                Global.ClearHtmlPage(webbXml,
                    this.MainForm.DataDir);
            }

            try
            {
                byte[] baTimestamp = null;
                string strRecPath = "";

                int nRedoCount = 0;
            REDO:
                stop.SetMessage("正在装入读者记录 " + strBarcode + " ...");

                string[] results = null;

                long lRet = Channel.GetReaderInfo(
                    stop,
                    strBarcode,
                    "xml,html",
                    out results,
                    out strRecPath,
                    out baTimestamp,
                    out strError);
                if (lRet == -1)
                    goto ERROR1;

                if (lRet == 0)
                    goto ERROR1;

                if (lRet > 1)
                {
                    // 如果重试后依然发生重复
                    if (nRedoCount > 0)
                    {
                        strError = "条码 " + strBarcode + " 命中记录 " + lRet.ToString() + " 条,放弃装入读者记录。\r\n\r\n注意这是一个严重错误,请系统管理员尽快排除。";
                        goto ERROR1;    // 当出错处理
                    }
                    SelectPatronDialog dlg = new SelectPatronDialog();

                    dlg.Overflow = StringUtil.SplitList(strRecPath).Count < lRet;
                    nRet = dlg.Initial(
                        this.MainForm,
                        this.Channel,
                        this.stop,
                        StringUtil.SplitList(strRecPath),
                        "请选择一个读者记录",
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                    // TODO: 保存窗口内的尺寸状态
                    this.MainForm.AppInfo.LinkFormState(dlg, "ActivateForm_SelectPatronDialog_state");
                    dlg.ShowDialog(this);
                    this.MainForm.AppInfo.UnlinkFormState(dlg);

                    if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                    {
                        strError = "放弃选择";
                        return 0;
                    }

                    strBarcode = dlg.SelectedBarcode;
                    nRedoCount++;
                    goto REDO;
                }



                // this.ReaderBarcode = strBarcode;

                if (results == null || results.Length < 2)
                {
                    strError = "返回的results不正常。";
                    goto ERROR1;
                }

                string strXml = "";
                strXml = results[0];
                string strHtml = results[1];

                if (edit != null)
                {
                    nRet = edit.SetData(
                        strXml,
                        strRecPath,
                        baTimestamp,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                }

                if (webbXml != null)
                {
                    /*
                    SetXmlToWebbrowser(webbXml,
                        strXml);
                     * */
                    Global.SetXmlToWebbrowser(webbXml,
                        this.MainForm.DataDir,
                        "xml",
                        strXml);
                }

                // this.m_strSetAction = "change";

#if NO
                if (webbHtml != null)
                {
                    Global.SetHtmlString(webbHtml,
                            strHtml,
                            this.MainForm.DataDir,
                            "activateform_html");
                }
#endif

                if (external_html != null)
                    external_html.SetHtmlString(strHtml, "activateform_html");
            }
            finally
            {
                EnableControls(true);

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }

            return 1;
        ERROR1:
            MessageBox.Show(this, strError);
            return -1;
        }