Beispiel #1
0
        private void button_login_Click(object sender, EventArgs e)
        {
            MainForm mainForm = null;

            if (this.Owner is MainForm)
            {
                mainForm = this.Owner as MainForm;
            }

            Debug.Assert(mainForm != null, "登录对话框的父窗口为空");

            LibraryChannel channel = mainForm.GetChannel();

            try
            {
                channel.Url = LibraryUrl;
                string        strParameters = "type=worker,client=dp2Mini|" + Program.ClientVersion;
                LoginResponse response      = channel.Login(Username, Password, strParameters);
                if (response.LoginResult.Value == -1 || response.LoginResult.Value == 0)
                {
                    MessageBox.Show(this, response.LoginResult.ErrorInfo);
                    return;
                }

                Properties.Settings.Default.cfg_library_url      = LibraryUrl;
                Properties.Settings.Default.cfg_library_username = Username;
                Properties.Settings.Default.cfg_savePassword     = IsSavePassword;

                if (IsSavePassword)
                {
                    Properties.Settings.Default.cfg_library_password = Password;
                }
                Properties.Settings.Default.Save();

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message);
            }
            finally
            {
                mainForm.ReturnChannel(channel);
            }
        }
Beispiel #2
0
        private void button_search_Click(object sender, EventArgs e)
        {
            string strError = "";

            this.listView_results.Items.Clear();

            MainForm mainForm = null;

            if (this.MdiParent is MainForm)
            {
                mainForm = this.MdiParent as MainForm;
            }

            Debug.Assert(mainForm != null, "MdiParent 父窗口为 null");

            mainForm.SetMessage("");

            string strQueryWord  = this.textBox_queryWord.Text;
            string strFrom       = "读者证条码号";
            string strMatchStyle = "exact";

            if (string.IsNullOrEmpty(strQueryWord))
            {
                strFrom       = "__id";
                strMatchStyle = "left";
            }

            string strQueryXml = "<target list='" + mainForm.ArrivedDbName + ":" + strFrom + "'>" +
                                 "<item>" +
                                 "<word>" + strQueryWord + "</word>" +
                                 "<match>" + strMatchStyle + "</match>" +
                                 "<relation>=</relation>" +
                                 "<dataType>string</dataType>" +
                                 "</item>" +
                                 "<lang>zh</lang>" +
                                 "</target>";

            LibraryChannel channel = mainForm.GetChannel();

            try
            {
                string         strOutputStyle = "";
                SearchResponse searchResponse = channel.Search(strQueryXml, "arrived", strOutputStyle);
                long           lRet           = searchResponse.SearchResult.Value;
                if (lRet == -1)
                {
                    strError = "检索发生错误:" + strError;
                    goto ERROR1;
                }
                else if (lRet == 0)
                {
                    strError = "读者'" + strQueryWord + "'没有到书信息";
                    goto ERROR1;
                }


                long     lHitCount     = lRet;
                long     lStart        = 0;
                long     lCount        = lHitCount;
                Record[] searchresults = null;
                for (; ;)
                {
                    Application.DoEvents();

                    lRet = channel.GetSearchResult("arrived",
                                                   lStart,
                                                   lCount,
                                                   "id,xml",// cols,
                                                   "zh",
                                                   out searchresults,
                                                   out strError);
                    if (lRet == -1)
                    {
                        strError = "获得检索结果发生错误:" + strError;
                        goto ERROR1;
                    }
                    else if (lRet == 0)
                    {
                        strError = "没有获得到 0 条检索结果";
                        goto ERROR1;
                    }


                    int i = 0;
                    foreach (Record record in searchresults)
                    {
                        string strPath = record.Path;

                        string[] cols = FillListViewItem(channel, record);

                        AppendNewLine(this.listView_results, strPath, cols);

                        mainForm.SetMessage((lStart + i + 1).ToString() + " / " + lHitCount);
                        i++;
                    }

                    lStart += searchresults.Length;
                    // lCount -= searchresults.Length;
                    if (lStart >= lHitCount || lCount <= 0)
                    {
                        break;
                    }
                }

                // this.listView_results.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            }
            finally
            {
                mainForm.ReturnChannel(channel);
            }
            return;

ERROR1:
            MessageBox.Show(strError);
        }
Beispiel #3
0
        private void button_search_Click(object sender, EventArgs e)
        {
            string strError = "";

            this.listView_results.Items.Clear();

            MainForm mainForm = null;

            if (this.MdiParent is MainForm)
            {
                mainForm = this.MdiParent as MainForm;
            }

            Debug.Assert(mainForm != null, "MdiParent 父窗口为 null");

            mainForm.SetMessage("");

            string strQueryWord  = this.textBox_queryWord.Text;
            string strFrom       = "读者证条码号";
            string strMatchStyle = "exact";

            if (string.IsNullOrEmpty(strQueryWord))
            {
                strFrom       = "__id";
                strMatchStyle = "left";
            }

            string strQueryXml = "<target list='" + mainForm.ArrivedDbName + ":" + strFrom + "'>" +
                                 "<item>" +
                                 "<word>" + strQueryWord + "</word>" +
                                 "<match>" + strMatchStyle + "</match>" +
                                 "<relation>=</relation>" +
                                 "<dataType>string</dataType>" +
                                 "</item>" +
                                 "<lang>zh</lang>" +
                                 "</target>";

            LibraryChannel channel = mainForm.GetChannel();

            try
            {
                string         strOutputStyle = "";
                SearchResponse searchResponse = channel.Search(strQueryXml, "", strOutputStyle);
                long           lRet           = searchResponse.SearchResult.Value;
                if (lRet == -1)
                {
                    strError = "检索发生错误:" + strError;
                    goto ERROR1;
                }
                else if (lRet == 0)
                {
                    strError = "读者'" + strQueryWord + "'没有到书信息";
                    goto ERROR1;
                }


                long     lHitCount     = lRet;
                long     lStart        = 0;
                long     lCount        = lHitCount;
                Record[] searchresults = null;
                for (; ;)
                {
                    Application.DoEvents();

                    lRet = channel.GetSearchResult("",
                                                   lStart,
                                                   lCount,
                                                   "id,xml",// cols,
                                                   "zh",
                                                   out searchresults,
                                                   out strError);
                    if (lRet == -1)
                    {
                        strError = "获得检索结果发生错误:" + strError;
                        goto ERROR1;
                    }
                    else if (lRet == 0)
                    {
                        strError = "没有获得到 0 条检索结果";
                        goto ERROR1;
                    }


                    int i = 0;
                    foreach (Record record in searchresults)
                    {
                        // string[] cols = record.Cols;
                        string strPath = record.Path;

                        string      strXML = record.RecordBody.Xml;
                        XmlDocument dom    = new XmlDocument();
                        dom.LoadXml(strXML);


                        string strState = DomUtil.GetElementText(dom.DocumentElement, "state");
                        if ("arrived" == strState)
                        {
                            strState = "图书在馆";
                        }
                        else if ("outof" == strState)
                        {
                            strState = "超过保留期";
                        }

                        string strLocation = DomUtil.GetElementText(dom.DocumentElement, "location");
                        string strAccessNo = DomUtil.GetElementText(dom.DocumentElement, "accessNo");


                        string strItemBarcode = DomUtil.GetElementText(dom.DocumentElement, "itemBarcode");
                        if (string.IsNullOrEmpty(strItemBarcode))
                        {
                            continue;
                        }
                        GetItemInfoResponse itemInfoResponse = channel.GetItemInfo(strItemBarcode,
                                                                                   "xml", // "xml:noborrowhistory", // resultType (itemType)
                                                                                   "xml"  // biblioType
                                                                                   );
                        lRet = itemInfoResponse.GetItemInfoResult.Value;
                        string strErrorInfo = itemInfoResponse.GetItemInfoResult.ErrorInfo;
                        if (lRet != 1)
                        {
                            MessageBox.Show(strErrorInfo);
                            continue;
                        }

                        string strOutMarcSyntax = "";
                        string strMARC          = "";
                        string strMarcXml       = itemInfoResponse.strBiblio;
                        int    nRet             = MarcUtil.Xml2Marc(strMarcXml,
                                                                    false,
                                                                    "", // 自动识别 MARC 格式
                                                                    out strOutMarcSyntax,
                                                                    out strMARC,
                                                                    out strError);
                        if (nRet == -1)
                        {
                            continue;
                        }

                        MarcRecord marcRecord = new MarcRecord(strMARC);
                        string     strISBN    = marcRecord.select("field[@name='010']/subfield[@name='a']").FirstContent;
                        string     strTitle   = marcRecord.select("field[@name='200']/subfield[@name='a']").FirstContent;
                        string     strAuthor  = marcRecord.select("field[@name='200']/subfield[@name='f']").FirstContent;


                        string strReaderBarcode = DomUtil.GetElementText(dom.DocumentElement, "readerBarcode");
                        GetReaderInfoResponse readerInfoResponse = channel.GetReaderInfo(strReaderBarcode, "xml:noborrowhistory");
                        lRet         = readerInfoResponse.GetReaderInfoResult.Value;
                        strErrorInfo = readerInfoResponse.GetReaderInfoResult.ErrorInfo;
                        if (lRet != 1)
                        {
                            MessageBox.Show(strErrorInfo);
                            continue;
                        }

                        string strReaderXml = readerInfoResponse.results[0];
                        dom.LoadXml(strReaderXml);
                        string strName = DomUtil.GetElementText(dom.DocumentElement, "name");
                        string strDept = DomUtil.GetElementText(dom.DocumentElement, "department");


                        // MessageBox.Show(strXML);
                        string[] cols = new string[this.listView_results.Columns.Count];
                        cols[0]  = strItemBarcode;
                        cols[1]  = strISBN;
                        cols[2]  = strTitle;
                        cols[3]  = strAuthor;
                        cols[4]  = strAccessNo;
                        cols[5]  = strLocation;
                        cols[6]  = strReaderBarcode;
                        cols[7]  = strName;
                        cols[8]  = strDept;
                        cols[9]  = strState;
                        cols[10] = "未打印";


                        AppendNewLine(this.listView_results, strPath, cols);

                        mainForm.SetMessage((lStart + i + 1).ToString() + " / " + lHitCount);
                        i++;
                    }

                    lStart += searchresults.Length;
                    lCount -= searchresults.Length;
                    if (lStart >= lHitCount || lCount <= 0)
                    {
                        break;
                    }
                }

                // this.listView_results.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            }
            finally
            {
                mainForm.ReturnChannel(channel);
            }
            return;

ERROR1:
            MessageBox.Show(strError);
        }
Beispiel #4
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_login_Click(object sender, EventArgs e)
        {
            MainForm mainForm = null;

            if (this.Owner is MainForm)
            {
                mainForm = this.Owner as MainForm;
            }

            Debug.Assert(mainForm != null, "登录对话框的父窗口为空");

            // 登录地址必须为rest.开头的地址
            string url = this.textBox_libraryUrl.Text;

            if (url.Length < 5 ||
                (url.Substring(0, 5).ToLower() != "rest."))
            {
                MessageBox.Show(this, "服务器仅支持rest.开头的地址,请重新输入服务器地址或咨询管理员");
                return;
            }


            RestChannel channel = mainForm.GetChannel();

            try
            {
                string pureUrl = this._mainFrom.GetPurlUrl(this.LibraryUrl);// LibraryUrl.Substring(5);
                channel.Url = pureUrl;
                string strParameters = "type=worker"
                                       + ",client=dp2mini|" + ClientInfo.ClientVersion; //Program.ClientVersion;
                LoginResponse response = channel.Login(Username,
                                                       Password,
                                                       strParameters);
                if (response.LoginResult.Value == -1 || response.LoginResult.Value == 0)
                {
                    MessageBox.Show(this, response.LoginResult.ErrorInfo);
                    return;
                }

                // 保存配置信息
                SettingInfo info = new SettingInfo();
                info.Url            = LibraryUrl;
                info.UserName       = Username;
                info.Password       = Password;
                info.IsSavePassword = IsSavePassword;
                this._mainFrom.SaveSettings(info);

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message);
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
            finally
            {
                mainForm.ReturnChannel(channel);
            }
        }
Beispiel #5
0
        void changeAcctiveItemPrintState(ListViewItem[] items, string strChangeState = "已打印")
        {
            if (items.Length == 0)
            {
                return;
            }

            MainForm mainForm = null;

            if (this.MdiParent is MainForm)
            {
                mainForm = this.MdiParent as MainForm;
            }

            Debug.Assert(mainForm != null, "MdiParent 父窗口为 null");

            LibraryChannel channel = mainForm.GetChannel();

            try
            {
                string strResult        = "";
                string strMetaData      = "";
                byte[] baTimestamp      = null;
                string strOutputResPath = "";
                string strError         = "";
                foreach (ListViewItem item in items)
                {
                    Application.DoEvents();

                    string strResPath = item.Text;
                    long   lRet       = channel.GetRes(strResPath,
                                                       "content,data,metadata,timestamp,outputpath",
                                                       out strResult,
                                                       out strMetaData,
                                                       out baTimestamp,
                                                       out strOutputResPath,
                                                       out strError);
                    if (lRet == -1)
                    {
                        MessageBox.Show(this, strError);
                        return;
                    }

                    XmlDocument dom = new XmlDocument();
                    dom.LoadXml(strResult);

                    string strPrintState = DomUtil.GetElementText(dom.DocumentElement, "printState");
                    if (strPrintState == strChangeState)
                    {
                        continue;
                    }

                    DomUtil.SetElementText(dom.DocumentElement, "printState", strChangeState);

                    byte[] baOutTimestamp = null;
                    lRet = channel.WriteRes(strResPath,
                                            dom.DocumentElement.OuterXml,
                                            true,
                                            "",
                                            baTimestamp,
                                            out baOutTimestamp,
                                            out strOutputResPath,
                                            out strError);
                    if (lRet == -1)
                    {
                        MessageBox.Show(this, strError);
                        return;
                    }

                    ListViewUtil.ChangeItemText(item, 11, strChangeState);
                }
            }
            finally
            {
                mainForm.ReturnChannel(channel);
            }
        }