The Safe class provide static methods to read items from a QBFC object.
示例#1
0
        private void HostQuerySuccess(SDK.IQBBase baseObj)
        {
            var respHost = baseObj as SDK.IHostRet;

            if (respHost == null)
            {
                string typeName = "null type";

                if (baseObj != null)
                {
                    typeName = baseObj.Type.GetAsString();
                }
                throw new Exception("1.0 host query failure: unexpected detail type:" + typeName);
            }

            var    lstVersion       = respHost.SupportedQBXMLVersionList;
            double candidateVersion = 0.0;
            string versionList      = string.Empty;

            for (int idx = 0; idx < lstVersion.Count; idx++)
            {
                string svers = lstVersion.GetAt(idx);

                if (versionList != string.Empty)
                {
                    versionList += ", ";
                }

                versionList += svers;

                double dver = 0.0;

                if (!double.TryParse(svers, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out dver))
                {
                    StatusMgr.LogStatus("Unexpected SDK version:" + svers);

                    continue;
                }

                if (dver > candidateVersion && dver <= MAX_DESKTOP_QBXML_VERSION)
                {
                    candidateVersion = dver;
                }
            }

            if (candidateVersion == 0.0)
            {
                StatusMgr.FormatError("No compatible SDK version found, using {0}", MAX_DESKTOP_QBXML_VERSION);
                candidateVersion = MAX_DESKTOP_QBXML_VERSION;
            }

            _SDKMajorVersion = (short)candidateVersion;

            string minor = (candidateVersion - _SDKMajorVersion).ToString();

            if (minor.Length > 1)
            {
                minor            = minor.Substring(2, minor.Length - 1);
                _SDKMinorVersion = short.Parse(minor);
            }
            else
            {
                _SDKMinorVersion = 0;
            }

            var successEntry = new StatusEntry()
            {
                Summary     = "QuickBooks Connection Established",
                TypeOfEntry = StatusEntry.EntryType.Status
            };

            successEntry.AddLine(string.Format("{0} version {1}.{2}", Safe.Value(respHost.ProductName),
                                               Safe.Value(respHost.MajorVersion), Safe.Value(respHost.MinorVersion)));

            successEntry.AddLine(string.Format("Supported qbXML versions:{0}", versionList));
            successEntry.AddLine(string.Format("Using version {0}.{1}", _SDKMajorVersion, _SDKMinorVersion));

            StatusMgr.LogEntry(successEntry);
        }