Esempio n. 1
0
        void SaveRecord()
        {
            string strError = "";

            if (this.ReaderBarcode == "")
            {
                strError = "尚未装载读者记录,缺乏证条码号";
                goto ERROR1;
            }

            string strXml = "";
            int    nRet   = BuildXml(out strXml,
                                     out strError);

            if (nRet == -1)
            {
                goto ERROR1;
            }


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

            EnableControls(false);

            try
            {
                ErrorCodeValue kernel_errorcode;

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

                // changestate操作需要"setreaderinfo"和"changereaderstate"之一权限。
                long lRet = Channel.SetReaderInfo(
                    stop,
                    "changestate",   // "change",
                    this.RecPath,
                    strXml,
                    this.OldRecord,
                    this.Timestamp,
                    out strExistingXml,
                    out strSavedXml,
                    out strSavedPath,
                    out baNewTimestamp,
                    out kernel_errorcode,
                    out strError);
                if (lRet == -1)
                {
                    if (kernel_errorcode == ErrorCodeValue.TimestampMismatch)
                    {
                        CompareReaderForm dlg = new CompareReaderForm();
                        dlg.Initial(
                            //Program.MainForm,
                            this.RecPath,
                            strExistingXml,
                            baNewTimestamp,
                            strXml,
                            this.Timestamp,
                            "数据库中的记录在编辑期间发生了改变。请仔细核对,并重新修改窗口中的未保存记录,按确定按钮后可重试保存。");

                        dlg.StartPosition = FormStartPosition.CenterScreen;
                        dlg.ShowDialog(this);
                        if (dlg.DialogResult == DialogResult.OK)
                        {
                            this.OldRecord = dlg.UnsavedXml;
                            this.RecPath   = dlg.RecPath;
                            this.Timestamp = dlg.UnsavedTimestamp;

                            nRet = LoadOperationInfo(out strError);
                            if (nRet == -1)
                            {
                                MessageBox.Show(this, strError);
                            }
                            MessageBox.Show(this, "请注意重新保存记录");
                            return;
                        }
                    }

                    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
                {
                    // 重新装载记录到编辑器

                    /*
                     * this.OldRecord = strSavedXml;
                     * this.RecPath = strSavedPath;
                     * this.Timestamp = baNewTimestamp;
                     *
                     * int nRet = LoadOperationInfo(out strError);
                     * if (nRet == -1)
                     *  goto ERROR1;
                     *
                     * //
                     * this.SetXmlToWebbrowser(this.webBrowser_xml,
                     *  strSavedXml);
                     * */
                }
            }
            finally
            {
                EnableControls(true);

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

            MessageBox.Show(this, "保存成功");
            this.Changed = false;

            // 重新装载记录到编辑器
            string strReaderBarcode = this.ReaderBarcode;

            this.LoadRecord(ref strReaderBarcode);
            if (this.ReaderBarcode != strReaderBarcode)
            {
                this.ReaderBarcode = strReaderBarcode;
            }
            return;

ERROR1:
            MessageBox.Show(this, strError);
        }
Esempio n. 2
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;
        }
Esempio n. 3
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(
                            //Program.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);
        }
Esempio n. 4
0
        void SaveRecord()
        {
            string strError = "";

            if (this.ReaderBarcode == "")
            {
                strError = "尚未装载读者记录,缺乏证条码号";
                goto ERROR1;
            }

            string strXml = "";
            int nRet = BuildXml(out strXml,
                out strError);
            if (nRet == -1)
                goto ERROR1;


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

            EnableControls(false);

            try
            {
                ErrorCodeValue kernel_errorcode;

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

                // changestate操作需要"setreaderinfo"和"changereaderstate"之一权限。
                long lRet = Channel.SetReaderInfo(
                    stop,
                    "changestate",   // "change",
                    this.RecPath,
                    strXml,
                    this.OldRecord,
                    this.Timestamp,
                    out strExistingXml,
                    out strSavedXml,
                    out strSavedPath,
                    out baNewTimestamp,
                    out kernel_errorcode,
                    out strError);
                if (lRet == -1)
                {
                    if (kernel_errorcode == ErrorCodeValue.TimestampMismatch)
                    {
                        CompareReaderForm dlg = new CompareReaderForm();
                        dlg.Initial(
                            this.MainForm,
                            this.RecPath,
                            strExistingXml,
                            baNewTimestamp,
                            strXml,
                            this.Timestamp,
                            "数据库中的记录在编辑期间发生了改变。请仔细核对,并重新修改窗口中的未保存记录,按确定按钮后可重试保存。");

                        dlg.StartPosition = FormStartPosition.CenterScreen;
                        dlg.ShowDialog(this);
                        if (dlg.DialogResult == DialogResult.OK)
                        {
                            this.OldRecord = dlg.UnsavedXml;
                            this.RecPath = dlg.RecPath;
                            this.Timestamp = dlg.UnsavedTimestamp;

                            nRet = LoadOperationInfo(out strError);
                            if (nRet == -1)
                            {
                                MessageBox.Show(this, strError);
                            }
                            MessageBox.Show(this, "请注意重新保存记录");
                            return;
                        }
                    }

                    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
                {
                    // 重新装载记录到编辑器
                    /*
                    this.OldRecord = strSavedXml;
                    this.RecPath = strSavedPath;
                    this.Timestamp = baNewTimestamp;

                    int nRet = LoadOperationInfo(out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    // 
                    this.SetXmlToWebbrowser(this.webBrowser_xml,
                        strSavedXml);
                     * */

                }

            }
            finally
            {
                EnableControls(true);

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

            MessageBox.Show(this, "保存成功");
            this.Changed = false;

            // 重新装载记录到编辑器
            string strReaderBarcode = this.ReaderBarcode;
            this.LoadRecord(ref strReaderBarcode);
            if (this.ReaderBarcode != strReaderBarcode)
                this.ReaderBarcode = strReaderBarcode;
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Esempio n. 5
0
        // 保存
        private void button_save_Click(object sender, EventArgs e)
        {
            string strError = "";

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

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

            EnableControls(false);

            try
            {
                string strNewXml = "";
                int nRet = this.readerEditControl1.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,
                    this.m_strSetAction,
                    this.readerEditControl1.RecPath,
                    strNewXml,
                    this.m_strSetAction != "new" ? this.readerEditControl1.OldRecord : null,
                    this.m_strSetAction != "new" ? this.readerEditControl1.Timestamp : null,
                    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,
                            this.readerEditControl1.RecPath,
                            strExistingXml,
                            baNewTimestamp,
                            strNewXml,
                            this.readerEditControl1.Timestamp,
                            "数据库中的记录在编辑期间发生了改变。请仔细核对,并重新修改窗口中的未保存记录,按确定按钮后可重试保存。");

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

                    goto ERROR1;
                }

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

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

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

                    // 2007/11/12
                    this.m_strSetAction = "change";

                }

            }
            finally
            {
                EnableControls(true);

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

            MessageBox.Show(this, "保存成功");
            return;
        ERROR1:
            MessageBox.Show(this, strError);
            return;
        }
Esempio n. 6
0
        // 删除
        private void button_delete_Click(object sender, EventArgs e)
        {
            string strError = "";

            if (this.readerEditControl1.Barcode == "")
            {
                strError = "尚未输入证条码号,无法删除";
                goto ERROR1;
            }

            DialogResult result = MessageBox.Show(this,
"确实要删除证条码号为 '" + this.readerEditControl1.Barcode + "' 的读者记录 ? ",
"ReaderInfoForm",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
            if (result != DialogResult.Yes)
                return;

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在删除读者记录 " + this.readerEditControl1.Barcode + " ...");
            stop.BeginLoop();

            EnableControls(false);

            try
            {

                string strNewXml = "";
                int nRet = this.readerEditControl1.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,
                    "delete",
                    null,   // this.readerEditControl1.RecPath,
                    "", // strNewXml,
                    this.readerEditControl1.OldRecord,
                    this.readerEditControl1.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,
                            this.readerEditControl1.RecPath,
                            strExistingXml,
                            baNewTimestamp,
                            strNewXml,
                            this.readerEditControl1.Timestamp,
                            "数据库中的记录在编辑期间发生了改变。请仔细核对,若还想继续删除,按‘确定’按钮后可重试删除。如果不想删除了,请按‘取消’按钮");

                        dlg.StartPosition = FormStartPosition.CenterScreen;
                        dlg.ShowDialog(this);
                        if (dlg.DialogResult == DialogResult.OK)
                        {
                            nRet = this.readerEditControl1.SetData(dlg.UnsavedXml,
                                dlg.RecPath,
                                dlg.UnsavedTimestamp,
                                out strError);
                            if (nRet == -1)
                            {
                                MessageBox.Show(this, strError);
                            }
                            MessageBox.Show(this, "请注意读者记录此时***并未***删除。\r\n\r\n如要删除记录,请按‘删除’按钮重新提交删除请求。");
                            return;
                        }
                    }

                    goto ERROR1;
                }

                // 保留删除过的窗口,一旦需要,还可以重新保存回去
                this.m_strSetAction = "new";

                nRet = this.readerEditControl1.SetData(strExistingXml,
                    null,
                    null,
                    out strError);
                if (nRet == -1)
                {
                    strError = "删除操作后的SetDate()操作失败: " + strError;
                    MessageBox.Show(this, strError);
                }

                this.readerEditControl1.Changed = false;

            }
            finally
            {
                EnableControls(true);

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

            MessageBox.Show(this, "删除成功。\r\n\r\n您会发现编辑窗口中还留着读者记录内容,但请不要担心,数据库里的读者记录已经被删除了。\r\n\r\n如果您这时后悔了,还可以按“保存按钮”把读者记录原样保存回去。");
            return;
        ERROR1:
            MessageBox.Show(this, strError);
            return;
        }
Esempio n. 7
0
        // 删除记录
        void DeleteRecord()
        {
            string strError = "";

            if (this.readerEditControl1.Barcode == "")
            {
                strError = "尚未输入证条码号,无法删除";
                goto ERROR1;
            }

            // bool bForceDelete = false;
            string strRecPath = null;
            string strText = "确实要删除证条码号为 '" + this.readerEditControl1.Barcode + "' 的读者记录 ? ";

            // 如果同时按下control键,表示强制按照记录路径删除
            if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
            {
                // bForceDelete = true;
                strRecPath = this.readerEditControl1.RecPath;
                strText = "确实要删除证条码号为 '" + this.readerEditControl1.Barcode + "' 并且记录路径为 '" + strRecPath + "' 的读者记录 ? ";
            }

            DialogResult result = MessageBox.Show(this,
                strText,
                "ReaderInfoForm",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button2);
            if (result != DialogResult.Yes)
                return;

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在删除读者记录 " + this.readerEditControl1.Barcode + " ...");
            stop.BeginLoop();

            EnableControls(false);

            try
            {

                string strNewXml = "";
                int nRet = this.readerEditControl1.GetData(
                    out strNewXml,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                string strOldBarcode = this.readerEditControl1.Barcode;

                ErrorCodeValue kernel_errorcode;

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

                long lRet = Channel.SetReaderInfo(
                    stop,
                    "delete",
                    strRecPath,   // this.readerEditControl1.RecPath,
                    "", // strNewXml,
                    this.readerEditControl1.OldRecord,
                    this.readerEditControl1.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,
                            this.readerEditControl1.RecPath,
                            strExistingXml,
                            baNewTimestamp,
                            strNewXml,
                            this.readerEditControl1.Timestamp,
                            "数据库中的记录在编辑期间发生了改变。请仔细核对,若还想继续删除,按‘确定’按钮后可重试删除。如果不想删除了,请按‘取消’按钮");

                        dlg.StartPosition = FormStartPosition.CenterScreen;
                        dlg.ShowDialog(this);
                        if (dlg.DialogResult == DialogResult.OK)
                        {
                            nRet = this.readerEditControl1.SetData(dlg.UnsavedXml,
                                dlg.RecPath,
                                dlg.UnsavedTimestamp,
                                out strError);
                            if (nRet == -1)
                            {
                                MessageBox.Show(this, strError);
                            }
                            MessageBox.Show(this, "请注意读者记录此时***并未***删除。\r\n\r\n如要删除记录,请按‘删除’按钮重新提交删除请求。");
                            return;
                        }
                    }

                    goto ERROR1;
                }

                // 保留删除过的窗口,一旦需要,还可以重新保存回去
                this.m_strSetAction = "new";

                nRet = this.readerEditControl1.SetData(strExistingXml,
                    null,
                    null,
                    out strError);
                if (nRet == -1)
                {
                    strError = "删除操作后的SetData()操作失败: " + strError;
                    MessageBox.Show(this, strError);
                }

                this.readerEditControl1.Changed = false;

                // 更新指纹高速缓存
                if (string.IsNullOrEmpty(this.MainForm.FingerprintReaderUrl) == false
                    && string.IsNullOrEmpty(this.readerEditControl1.Barcode) == false)
                {
                    // return:
                    //      -2  remoting服务器连接失败。驱动程序尚未启动
                    //      -1  出错
                    //      0   成功
                    nRet = UpdateFingerprintCache(
                         strOldBarcode,
                         "",
                         out strError);
                    if (nRet == -1)
                    {
                        strError = "虽然读者记录已经删除成功,但更新指纹缓存时发生了错误: " + strError;
                        goto ERROR1;
                    }
                    // -2 故意不报错。因为用户可能配置了URL,但是当前驱动程序并没有启动
                }
            }
            finally
            {
                EnableControls(true);

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

            MessageBox.Show(this, "删除成功。\r\n\r\n您会发现编辑窗口中还留着读者记录内容,但请不要担心,数据库里的读者记录已经被删除了。\r\n\r\n如果您这时后悔了,还可以按“保存按钮”把读者记录原样保存回去。");
            return;
        ERROR1:
            MessageBox.Show(this, strError);
            return;

        }
Esempio n. 8
0
        void SaveTo()
        {
            string strError = "";
            int nRet = 0;
            bool bReserveFieldsCleared = false;

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

            // 校验证条码号
            if (this.NeedVerifyBarcode == true
                && StringUtil.IsIdcardNumber(this.readerEditControl1.Barcode) == false)
            {
                // 形式校验条码号
                // return:
                //      -2  服务器没有配置校验方法,无法校验
                //      -1  error
                //      0   不是合法的条码号
                //      1   是合法的读者证条码号
                //      2   是合法的册条码号
                nRet = VerifyBarcode(
                    this.Channel.LibraryCodeList,
                    this.readerEditControl1.Barcode,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                // 输入的条码格式不合法
                if (nRet == 0)
                {
                    strError = "您输入的证条码号 " + this.readerEditControl1.Barcode + " 格式不正确(" + strError + ")。";
                    goto ERROR1;
                }

                // 实际输入的是册条码号
                if (nRet == 2)
                {
                    strError = "您输入的条码号 " + this.readerEditControl1.Barcode + " 是册条码号。请输入读者证条码号。";
                    goto ERROR1;
                }

                /*
                // 对于服务器没有配置校验功能,但是前端发出了校验要求的情况,警告一下
                if (nRet == -2)
                    MessageBox.Show(this, "警告:前端开启了校验条码功能,但是服务器端缺乏相应的脚本函数,无法校验条码。\r\n\r\n若要避免出现此警告对话框,请关闭前端校验功能");
                 * */
            }

            // 出现对话框,让用户可以选择目标库
            ReaderSaveToDialog saveto_dlg = new ReaderSaveToDialog();
            MainForm.SetControlFont(saveto_dlg, this.Font, false);
            saveto_dlg.Text = "新增一条读者记录";
            saveto_dlg.MessageText = "请选择要保存的目标记录位置\r\n(记录ID为 ? 表示追加保存到数据库末尾)";
            saveto_dlg.MainForm = this.MainForm;
            saveto_dlg.RecPath = this.readerEditControl1.RecPath;
            saveto_dlg.RecID = "?";

            this.MainForm.AppInfo.LinkFormState(saveto_dlg, "readerinfoform_savetodialog_state");
            saveto_dlg.ShowDialog(this);
            this.MainForm.AppInfo.UnlinkFormState(saveto_dlg);

            if (saveto_dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                return;

            if (saveto_dlg.RecID == "?")
                this.m_strSetAction = "new";
            else
                this.m_strSetAction = "change";

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

            EnableControls(false);

            try
            {
                string strNewXml = "";

                if (this.m_strSetAction == "new")
                    nRet = GetReaderXml(
                        false,  // 不创建<dprms:file>元素
                        true,   // 清除<dprms:file>元素
                        out strNewXml,
                        out strError);
                else
                    nRet = GetReaderXml(
                        true,  // 创建<dprms:file>元素
                        false,
                        out strNewXml,
                        out strError);
                if (nRet == -1)
                    goto ERROR1;

                // 需要消除password/displayName元素内容
                if (this.m_strSetAction == "new")
                {
                            // 清除一些保留字段的内容
                    nRet = ClearReserveFields(
            ref strNewXml,
            out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    bReserveFieldsCleared = true;
                }

                ErrorCodeValue kernel_errorcode;

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

                // 调试
                // MessageBox.Show(this, "2 this.m_strSetAction='" + this.m_strSetAction + "'");

                long lRet = Channel.SetReaderInfo(
                    stop,
                    this.m_strSetAction,
                    saveto_dlg.RecPath, // this.readerEditControl1.RecPath,
                    strNewXml,
                    this.m_strSetAction != "new" ? this.readerEditControl1.OldRecord : null,
                    this.m_strSetAction != "new" ? this.readerEditControl1.Timestamp : null,
                    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,
                            this.readerEditControl1.RecPath,
                            strExistingXml,
                            baNewTimestamp,
                            strNewXml,
                            this.readerEditControl1.Timestamp,
                            "数据库中的记录在编辑期间发生了改变。请仔细核对,并重新修改窗口中的未保存记录,按确定按钮后可重试保存。");

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

                    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
                {
                    this.binaryResControl1.BiblioRecPath = strSavedPath;
                    // 提交对象保存请求
                    // return:
                    //		-1	error
                    //		>=0 实际上载的资源对象数
                    nRet = this.binaryResControl1.Save(out strError);
                    if (nRet == -1)
                    {
                        MessageBox.Show(this, strError);
                    }
                    if (nRet >= 1)
                    {
                        // 重新获得时间戳
                        string[] results = null;
                        string strOutputPath = "";
                        lRet = Channel.GetReaderInfo(
                            stop,
                            "@path:" + strSavedPath,
                            "", // "xml,html",
                            out results,
                            out strOutputPath,
                            out baNewTimestamp,
                            out strError);
                        if (lRet == -1 || lRet == 0)
                        {
                            MessageBox.Show(this, strError);
                        }
                    }

                    // 重新装载记录到编辑器
                    nRet = this.readerEditControl1.SetData(strSavedXml,
                        strSavedPath,
                        baNewTimestamp,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                    /*
                    this.SetXmlToWebbrowser(this.webBrowser_xml,
                        strSavedXml);
                     * */
                    Global.SetXmlToWebbrowser(this.webBrowser_xml,
this.MainForm.DataDir,
"xml",
strSavedXml);
                    // 2007/11/12
                    this.m_strSetAction = "change";

                    // 接着装入对象资源
                    {
                        nRet = this.binaryResControl1.LoadObject(strSavedPath,    // 2008/11/2 changed
                            strSavedXml,
                            out strError);
                        if (nRet == -1)
                        {
                            MessageBox.Show(this, strError);
                            // return -1;
                        }
                    }

                    // 2011/11/23
                    // 装载记录到HTML
                    {
                        byte[] baTimestamp = null;
                        string strOutputRecPath = "";

                        string strBarcode = this.readerEditControl1.Barcode;

                        stop.SetMessage("正在装入读者记录 " + strBarcode + " ...");

                        string[] results = null;
                        lRet = Channel.GetReaderInfo(
                            stop,
                            strBarcode,
                            "html",
                            out results,
                            out strOutputRecPath,
                            out baTimestamp,
                            out strError);
                        if (lRet == -1)
                        {
                            strError = "保存记录已经成功,但在刷新HTML显示的时候发生错误: " + strError;
                            // Global.SetHtmlString(this.webBrowser_readerInfo, strError);
                            this.m_webExternalHost.SetTextString(strError);
                            goto ERROR1;
                        }

                        if (lRet == 0)
                        {
                            strError = "保存记录已经成功,但在刷新HTML显示的时候发生错误: " + strError;
                            Global.SetHtmlString(this.webBrowser_readerInfo, strError);
                            goto ERROR1;
                        }

                        if (lRet > 1)
                        {
                            strError = "条码 " + strBarcode + " 命中记录 " + lRet.ToString() + " 条,注意这是一个严重错误,请系统管理员尽快排除。";
                            strError = "保存记录已经成功,但在刷新HTML显示的时候发生错误: " + strError;
                            // Global.SetHtmlString(this.webBrowser_readerInfo, strError);
                            this.m_webExternalHost.SetTextString(strError);
                            goto ERROR1;    // 当出错处理
                        }

                        string strHtml = results[0];

#if NO
                        Global.SetHtmlString(this.webBrowser_readerInfo,
                            strHtml,
        this.MainForm.DataDir,
        "readerinfoform_reader");
#endif
                        this.SetReaderHtmlString(strHtml);
                    }

                }
            }
            finally
            {
                EnableControls(true);

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

            if (bReserveFieldsCleared == true)
                MessageBox.Show(this, "另存成功。新记录的密码为初始状态,显示名尚未设置。");
            else
                MessageBox.Show(this, "另存成功。");
            return;
        ERROR1:
            MessageBox.Show(this, strError);
            return;
        }
Esempio n. 9
0
        // return:
        //      -1  error
        //      0   canceled
        //      1   succeed
        /// <summary>
        /// 保存记录
        /// </summary>
        /// <param name="strStyle">风格。为 displaysuccess/verifybarcode/changereaderbarcode 之一或者组合。缺省值为 displaysuccess,verifybarcode</param>
        /// <returns>-1: 出错; 0: 放弃; 1: 成功</returns>
        public int SaveRecord(string strStyle = "displaysuccess,verifybarcode")
        {
            string strError = "";
            int nRet = 0;

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

            // 校验证条码号
            if (this.NeedVerifyBarcode == true
                && StringUtil.IsIdcardNumber(this.readerEditControl1.Barcode) == false)
            {
                // 形式校验条码号
                // return:
                //      -2  服务器没有配置校验方法,无法校验
                //      -1  error
                //      0   不是合法的条码号
                //      1   是合法的读者证条码号
                //      2   是合法的册条码号
                nRet = VerifyBarcode(
                    this.Channel.LibraryCodeList,
                    this.readerEditControl1.Barcode,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                // 输入的条码格式不合法
                if (nRet == 0)
                {
                    strError = "您输入的证条码 " + this.readerEditControl1.Barcode + " 格式不正确("+strError+")。";
                    goto ERROR1;
                }

                // 实际输入的是册条码号
                if (nRet == 2)
                {
                    strError = "您输入的条码号 " + this.readerEditControl1.Barcode + " 是册条码号。请输入读者证条码号。";
                    goto ERROR1;
                }

                /*
                // 对于服务器没有配置校验功能,但是前端发出了校验要求的情况,警告一下
                if (nRet == -2)
                    MessageBox.Show(this, "警告:前端开启了校验条码功能,但是服务器端缺乏相应的脚本函数,无法校验条码。\r\n\r\n若要避免出现此警告对话框,请关闭前端校验功能");
                 * */
            }

            // TODO: 保存时候的选项


            // 当 this.readerEditControl1.RecPath 为空的时候,需要出现对话框,让用户可以选择目标库
            string strTargetRecPath = this.readerEditControl1.RecPath;
            if (string.IsNullOrEmpty(this.readerEditControl1.RecPath) == true)
            {
                // 出现对话框,让用户可以选择目标库
                ReaderSaveToDialog saveto_dlg = new ReaderSaveToDialog();
                MainForm.SetControlFont(saveto_dlg, this.Font, false);
                saveto_dlg.MessageText = "请选择记录位置";
                saveto_dlg.MainForm = this.MainForm;
                saveto_dlg.RecPath = this.readerEditControl1.RecPath;
                saveto_dlg.RecID = "?";

                this.MainForm.AppInfo.LinkFormState(saveto_dlg, "readerinfoform_savetodialog_state");
                saveto_dlg.ShowDialog(this);
                this.MainForm.AppInfo.UnlinkFormState(saveto_dlg);

                if (saveto_dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                    return 0;

                strTargetRecPath = saveto_dlg.RecPath;
            }

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

            EnableControls(false);

            try
            {
                string strNewXml = "";
                nRet = GetReaderXml(
            true,
            false,
            out strNewXml,
            out strError);
                if (nRet == -1)
                    goto ERROR1;

                ErrorCodeValue kernel_errorcode;

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

                bool bChangeReaderBarcode = StringUtil.IsInList("changereaderbarcode", strStyle);
                string strAction = this.m_strSetAction;
                if (strAction == "change" && bChangeReaderBarcode)
                {
                    if (this.MainForm.ServerVersion < 2.51)
                    {
                        strError = "需要 dp2library 版本在 2.51 以上才能实现强制修改册条码号的功能。当前 dp2library 版本为 " + this.MainForm.ServerVersion;
                        goto ERROR1;
                    }
                    strAction = "changereaderbarcode";
                }

                // 调试
                // MessageBox.Show(this, "1 this.m_strSetAction='"+this.m_strSetAction+"'");

                long lRet = Channel.SetReaderInfo(
                    stop,
                    strAction,  // this.m_strSetAction,
                    strTargetRecPath,
                    strNewXml,
                    // 2007/11/5 changed
                    this.m_strSetAction != "new" ? this.readerEditControl1.OldRecord : null,
                    this.m_strSetAction != "new" ? this.readerEditControl1.Timestamp : null,

                    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,
                            this.readerEditControl1.RecPath,
                            strExistingXml,
                            baNewTimestamp,
                            strNewXml,
                            this.readerEditControl1.Timestamp,
                            "数据库中的记录在编辑期间发生了改变。请仔细核对,并重新修改窗口中的未保存记录,按确定按钮后可重试保存。");

                        dlg.StartPosition = FormStartPosition.CenterScreen;
                        dlg.ShowDialog(this);
                        if (dlg.DialogResult == DialogResult.OK)
                        {
                            nRet = this.readerEditControl1.SetData(dlg.UnsavedXml,
                                dlg.RecPath,
                                dlg.UnsavedTimestamp,
                                out strError);
                            if (nRet == -1)
                            {
                                MessageBox.Show(this, strError);
                            }
                            MessageBox.Show(this, "请注意重新保存记录");
                            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
                {
                    this.binaryResControl1.BiblioRecPath = strSavedPath;
                    // 提交对象保存请求
                    // return:
                    //		-1	error
                    //		>=0 实际上载的资源对象数
                    nRet = this.binaryResControl1.Save(out strError);
                    if (nRet == -1)
                    {
                        MessageBox.Show(this, strError);
                    }
                    if (nRet >= 1)
                    {
                        // 重新获得时间戳
                        string[] results = null;
                        string strOutputPath = "";
                        lRet = Channel.GetReaderInfo(
                            stop,
                            "@path:" + strSavedPath,
                            "", // "xml,html",
                            out results,
                            out strOutputPath,
                            out baNewTimestamp,
                            out strError);
                        if (lRet == -1 || lRet == 0)
                        {
                            MessageBox.Show(this, strError);
                        }
                    }

                    // 重新装载记录到编辑器
                    nRet = this.readerEditControl1.SetData(strSavedXml,
                        strSavedPath,
                        baNewTimestamp,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    // 刷新XML显示
                    /*
                    this.SetXmlToWebbrowser(this.webBrowser_xml,
                        strSavedXml);
                     * */
                    Global.SetXmlToWebbrowser(this.webBrowser_xml,
this.MainForm.DataDir,
"xml",
strSavedXml);
                    // 2007/11/12
                    this.m_strSetAction = "change";

                    // 装载记录到HTML
                    {
                        byte[] baTimestamp = null;
                        string strOutputRecPath = "";

                        string strBarcode = this.readerEditControl1.Barcode;

                        stop.SetMessage("正在装入读者记录 " + strBarcode + " ...");

                        string[] results = null;
                        lRet = Channel.GetReaderInfo(
                            stop,
                            strBarcode,
                            "html",
                            out results,
                            out strOutputRecPath,
                            out baTimestamp,
                            out strError);
                        if (lRet == -1)
                        {
                            strError = "保存记录已经成功,但在刷新HTML显示的时候发生错误: " + strError;
                            // Global.SetHtmlString(this.webBrowser_readerInfo, strError);
                            this.m_webExternalHost.SetTextString(strError);
                            goto ERROR1;
                        }

                        if (lRet == 0)
                        {
                            strError = "保存记录已经成功,但在刷新HTML显示的时候发生错误: " + strError;
                            // Global.SetHtmlString(this.webBrowser_readerInfo, strError);
                            this.m_webExternalHost.SetTextString(strError);
                            goto ERROR1;
                        }

                        if (lRet > 1)
                        {
                            strError = "条码 " + strBarcode + " 命中记录 " + lRet.ToString() + " 条,注意这是一个严重错误,请系统管理员尽快排除。";
                            strError = "保存记录已经成功,但在刷新HTML显示的时候发生错误: " + strError;
                            // Global.SetHtmlString(this.webBrowser_readerInfo, strError);
                            this.m_webExternalHost.SetTextString(strError);
                            goto ERROR1;    // 当出错处理
                        }

                        string strHtml = results[0];

#if NO
                        Global.SetHtmlString(this.webBrowser_readerInfo,
                            strHtml,
        this.MainForm.DataDir,
        "readerinfoform_reader");
#endif
                        this.SetReaderHtmlString(strHtml);
                    }

                }

                // 更新指纹高速缓存
                if (string.IsNullOrEmpty(this.MainForm.FingerprintReaderUrl) == false
                    && string.IsNullOrEmpty(this.readerEditControl1.Barcode) == false)
                {
                    // return:
                    //      -2  remoting服务器连接失败。驱动程序尚未启动
                    //      -1  出错
                    //      0   成功
                    nRet = UpdateFingerprintCache(
                         this.readerEditControl1.Barcode,
                         this.readerEditControl1.Fingerprint,
                         out strError);
                    if (nRet == -1)
                    {
                        strError = "虽然读者记录已经保存成功,但更新指纹缓存时发生了错误: " + strError;
                        goto ERROR1;
                    }
                    // -2 故意不报错。因为用户可能配置了URL,但是当前驱动程序并没有启动
                }

            }
            finally
            {
                EnableControls(true);

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

            if (StringUtil.IsInList("displaysuccess", strStyle) == true)
                this.MainForm.StatusBarMessage = "读者记录保存成功";
            // MessageBox.Show(this, "保存成功");
            return 1;
        ERROR1:
            MessageBox.Show(this, strError);
            return -1;
        }