// strStart, // 起始路径, ""表示根 Package GetOneLevelDirPackage(string strStart) { int nRet; byte [] baPackage = null; // bool bSetDefault = false; // 表示是否使用过缺省帐户 //bool bFirstLogin = true; Package package = new Package(); // CWaitCursor cursor; if (Channel == null) { Channel = channelarray.CreateChannel(0); } Debug.Assert(Channel != null, "channel尚未初始化"); Cursor.Current = Cursors.WaitCursor; if (Stop != null) { Stop.OnStop += new StopEventHandler(this.DoStop); Stop.SetMessage("正在列目录 '" + strStart + "' ..."); Stop.BeginLoop(); } try { nRet = Channel.Dir(strStart, out baPackage); } finally { if (Stop != null) { Stop.EndLoop(); Stop.OnStop -= new StopEventHandler(this.DoStop); Stop.Initial(""); } Cursor.Current = Cursors.Default; } if (nRet == -1) { Channel.ErrorBox(this, "restree", "列目录发生错误"); goto ERROR1; } package.LoadPackage(baPackage, Channel.GetPathEncoding(strStart)); package.Parse(PackageFormat.String); return(package); ERROR1: return(null); }
// 得到下一条记录 // return: // -1 出错 // 0 继续 // 1 到达末尾(超过m_strEndNumber) // 2 没有找到记录 public int NextRecord(ref int nRecCount, out string strError) { strError = ""; string strPath; string strNumber; string strNextNumber; byte[] baPackage = null; int nSearchStyle = DtlpChannel.XX_STYLE; int nRet; int nErrorNo; int nDirStyle = 0; // 方向风格 byte[] baMARC = null; if (this.channel == null) { this.channel = this.Channels.CreateChannel(0); } Debug.Assert(m_strStartNumber != "", "m_strStartNumber值不能为空"); Debug.Assert(m_strEndNumber != "", "m_strEndNumber值不能为空"); // 首次进入本函数 if (nRecCount == -1) { strNumber = m_strStartNumber; nDirStyle = 0; nRecCount = 0; } else { strNumber = m_strNextNumber; if (Convert.ToInt64(m_strStartNumber) <= Convert.ToInt64(m_strEndNumber)) { nDirStyle = DtlpChannel.NEXT_RECORD; if (Convert.ToInt64(strNumber) >= Convert.ToInt64(m_strEndNumber)) { return(1); // 结束 } } else { nDirStyle = DtlpChannel.PREV_RECORD; if (Convert.ToInt64(strNumber) <= Convert.ToInt64(m_strEndNumber)) { return(1); // 结束 } } } strPath = m_strDBPath; strPath += "/ctlno/"; strPath += strNumber; // REDO: nRet = channel.Search(strPath, nSearchStyle | nDirStyle, out baPackage); if (nRet == -1) { nErrorNo = channel.GetLastErrno(); if (nErrorNo == DtlpChannel.GL_NOTLOGIN) { // 重新登录的事情,已经被Search()接管了 } else { if (nErrorNo == DtlpChannel.GL_NOTEXIST) { // 增量号码 Int64 n64Number = Convert.ToInt64(strNumber); string strVersion; // GetDTLPVersion(m_strDBPath, strVersion); // 可以将库名再去除,效果更好 strVersion = "0.9"; if (n64Number + 1 < 9999999 && strVersion == "0.9") { //strNumber.Format(_T("%I0764d"), n64Number+1); // 确保7位数字 strNumber = String.Format("{0:D7}", n64Number + 1); // "{0,7:D}" BUG!!! 左边实际上是空格 2009/2/26 } else { // strNumber.Format(_T("%I64d"), n64Number+1); strNumber = String.Format("{0:D7}", n64Number + 1); // "{0,7:D}" BUG!!! 左边实际上是空格 2009/2/26 } m_strCurNumber = strNumber; goto NOTFOUND; } this.ErrorNo = nErrorNo; if (nErrorNo == DtlpChannel.GL_INVALIDCHANNEL) { this.channel = null; } // 得到字符串即可 /* * channel.ErrorBox(owner, "DtlpIO", * "检索发生错误\nSearch() error"); * */ strError = "检索发生错误\nSearch() error: \r\n" + channel.GetErrorDescription(); goto ERROR1; } m_strPath = strPath; goto ERROR1; } /// Package package = new Package(); package.LoadPackage(baPackage, channel.GetPathEncoding(strPath)); nRet = package.Parse(PackageFormat.Binary); if (nRet == -1) { Debug.Assert(false, "Package::Parse() error"); strError = "Package::Parse() error"; goto ERROR1; } nRet = package.GetFirstBin(out baMARC); if (nRet == -1 || nRet == 0) { Debug.Assert(false, "Package::GetFirstBin() error"); strError = "Package::GetFirstBin() error"; goto ERROR1; } if (baMARC.Length >= 9) { Array.Copy(baMARC, 0, m_baTimeStamp, 0, 9); byte [] baBody = new byte[baMARC.Length - 9]; Array.Copy(baMARC, 9, baBody, 0, baMARC.Length - 9); baMARC = baBody; //baMARC.RemoveAt(0, 9); // 时间戳 } else { // 记录有问题,放入一个空记录? } // ---????????? 编写一个在byte[]末尾追加东西的函数? // baMARC = ByteArray.Add(baMARC, (byte)0); // baMARC.Add(0); // baMARC.Add(0); m_strRecord = channel.GetPathEncoding(strPath).GetString(baMARC); strPath = package.GetFirstPath(); nRet = GetCtlNoFromPath(strPath, out strNextNumber); if (nRet == -1) { Debug.Assert(false, "GetCtlNoFromPath() return error ..."); strError = "GetCtlNoFromPath() error ..."; goto ERROR1; } m_strNextNumber = strNextNumber; if (nRecCount == 0) // 首次 { m_strCurNumber = strNumber; } else { m_strCurNumber = strNextNumber; } m_strPath = strPath; // nRecCount++; return(0); ERROR1: return(-1); NOTFOUND: return(2); }