コード例 #1
0
        private DateTime ParseDateTime(string value)
        {
            DateTimeFormatInfo dateformat = new DateTimeFormatInfo();

            dateformat.SetAllDateTimePatterns(new string[] { "dd/MM/yyyy HH:mm", "dd/MM/yyyy", "dd MM yyyy" }, 'd');
            dateformat.SetAllDateTimePatterns(new string[] { "dd/MM/yyyy HH:mm", "dd/MM/yyyy", "dd MM yyyy" }, 'D');
            CultureInfo culture = new CultureInfo("vi-VN");

            return(DateTime.Parse(value, dateformat));
        }
コード例 #2
0
        /// <summary>
        /// This method converts a Ruby Time string (yyyy-MM-dd HH:mm:ss zzz) to a .Net DateTime.
        /// </summary>
        /// <param name="date">A string containing the formatted date and time.</param>
        /// <returns>A DateTime containing the converted value.</returns>
        public static DateTime DateTimeFromRubyString(string date)
        {
            DateTimeFormatInfo dateFormat = new DateTimeFormatInfo();

            dateFormat.SetAllDateTimePatterns(new string[] { "yyyy-MM-dd HH:mm:ss zzz" }, 'Y');
            return(DateTime.Parse(date, dateFormat));
        }
コード例 #3
0
ファイル: dtfi1.cs プロジェクト: zhamppx97/dotnet-api-docs
    public static void Main()
    {
        string[] myDateTimePatterns = new string[] { "MM/dd/yy", "MM/dd/yyyy" };

// Get the en-US culture.
        CultureInfo ci = new CultureInfo("en-US");
// Get the DateTimeFormatInfo for the en-US culture.
        DateTimeFormatInfo dtfi = ci.DateTimeFormat;

// Display the effective culture.
        Console.WriteLine("This code example uses the {0} culture.", ci.Name);

// Display the native calendar name.
        Console.WriteLine("\nNativeCalendarName...");
        Console.WriteLine("\"{0}\"", dtfi.NativeCalendarName);

// Display month genitive names.
        Console.WriteLine("\nMonthGenitiveNames...");
        foreach (string name in dtfi.MonthGenitiveNames)
        {
            Console.WriteLine("\"{0}\"", name);
        }

// Display abbreviated month genitive names.
        Console.WriteLine("\nAbbreviatedMonthGenitiveNames...");
        foreach (string name in dtfi.AbbreviatedMonthGenitiveNames)
        {
            Console.WriteLine("\"{0}\"", name);
        }

// Display shortest day names.
        Console.WriteLine("\nShortestDayNames...");
        foreach (string name in dtfi.ShortestDayNames)
        {
            Console.WriteLine("\"{0}\"", name);
        }

// Display shortest day name for a particular day of the week.
        Console.WriteLine("\nGetShortestDayName(DayOfWeek.Sunday)...");
        Console.WriteLine("\"{0}\"", dtfi.GetShortestDayName(DayOfWeek.Sunday));

// Display the initial DateTime format patterns for the 'd' format specifier.
        Console.WriteLine("\nInitial DateTime format patterns for the 'd' format specifier...");
        foreach (string name in dtfi.GetAllDateTimePatterns('d'))
        {
            Console.WriteLine("\"{0}\"", name);
        }

// Change the initial DateTime format patterns for the 'd' DateTime format specifier.
        Console.WriteLine("\nChange the initial DateTime format patterns for the \n" +
                          "'d' format specifier to my format patterns...");
        dtfi.SetAllDateTimePatterns(myDateTimePatterns, 'd');

// Display the new DateTime format patterns for the 'd' format specifier.
        Console.WriteLine("\nNew DateTime format patterns for the 'd' format specifier...");
        foreach (string name in dtfi.GetAllDateTimePatterns('d'))
        {
            Console.WriteLine("\"{0}\"", name);
        }
    }
コード例 #4
0
        /// <summary>
        /// Initializes the <see cref="TypeSystem"/> class.
        /// </summary>
        static TypeSystem()
        {
            _dateTimeFormatInfo = new DateTimeFormatInfo();
            _datePattern        = new string[] {
                "dd/MM/yyyy",
                "MM/dd/yyyy",
                "yyyy/MM/dd",
                "yyyy/dd/MM"
            };
            _dateTimePattern = new string[] {
                "dd/MM/yyyy HH:mm:ss.fff",
                "MM/dd/yyyy HH:mm:ss.fff",
                "yyyy/MM/dd HH:mm:ss.fff",
                "yyyy/dd/MM HH:mm:ss.fff"
            };
            _timePattern = new string[] {
                "HH:mm:ss.fff",
                "HH:mm:ss"
            };
#if !SILVERLIGHT
            _dateTimeFormatInfo.SetAllDateTimePatterns(_dateTimePattern, 'd');
#endif
        }
コード例 #5
0
        public void AllDateTimePatternsTest(string cultureName)
        {
            char[]             formats = { 'd', 'D', 'f', 'F', 'g', 'G', 'm', 'o', 'r', 's', 't', 'T', 'u', 'U', 'y' };
            DateTimeFormatInfo dtfi    = (DateTimeFormatInfo) new CultureInfo(cultureName).DateTimeFormat.Clone();

            var allPatterns = dtfi.GetAllDateTimePatterns();
            Dictionary <string, string> dic = new Dictionary <string, string>();

            string value = "";

            foreach (char format in formats)
            {
                foreach (string pattern in dtfi.GetAllDateTimePatterns(format))
                {
                    if (!dic.TryGetValue(pattern, out value))
                    {
                        dic.Add(pattern, "");
                    }
                }
            }

            foreach (string pattern in allPatterns)
            {
                Assert.True(dic.TryGetValue(pattern, out value), "Couldn't find the pattern in the patterns list");
            }

            char[] setterFormats = { 'd', 'D', 't', 'T', 'y', 'Y' };
            foreach (char format in setterFormats)
            {
                var       formatPatterns = dtfi.GetAllDateTimePatterns(format);
                string [] newPatterns    = new string[1] {
                    formatPatterns[formatPatterns.Length - 1]
                };
                dtfi.SetAllDateTimePatterns(newPatterns, format);
                Assert.Equal(newPatterns, dtfi.GetAllDateTimePatterns(format));
            }
        }
コード例 #6
0
    private DateTime parseDate(string input)
    {
        DateTimeFormatInfo fmt = new DateTimeFormatInfo();
            fmt.SetAllDateTimePatterns(
                new string[] { "d MMM yyyy", "dd MMM yyyy", "d MMMM yyyy", "dd MMMM yyyy" },
                'd');

            input = "01 " + input;// eg. 01 may 2008

            return  DateTime.Parse(input, fmt);
    }
コード例 #7
0
 public DateFieldFormat(string name) : base(name)
 {
     dateFormatter = new DateTimeFormatInfo();
     dateFormatter.SetAllDateTimePatterns(new[] { FORMAT }, 'd');
 }
コード例 #8
0
        /// <summary>
        ///   Parses a string to a date time value
        /// </summary>
        /// <param name="originalValue">The original value.</param>
        /// <param name="dateFormat">The short date format.</param>
        /// <param name="dateSeparator">The date separator.</param>
        /// <param name="timeSeparator">The time separator.</param>
        /// <returns></returns>
        private static DateTime?OldStringToDateTime(string originalValue, string dateFormat, string dateSeparator,
                                                    string timeSeparator)
        {
            var stringDateValue = originalValue == null ? string.Empty : originalValue.Trim();

            if (string.IsNullOrEmpty(stringDateValue) || stringDateValue == "00000000" ||
                stringDateValue == "99999999")
            {
                return(null);
            }

            DateTime?dateFieldValue = null;

            try
            {
                var dateTimeFormats = StringUtils.SplitByDelimiter(dateFormat);

                /*
                 *       bool hasTime = (shortDateFormat.IndexOf('H') > -1) || (shortDateFormat.IndexOf('h') > -1);
                 *       bool hasDate = (shortDateFormat.IndexOf('d') > -1);
                 *
                 *      // HH:= hour as a number from 00 through 23;  FFF:= Fractions of a second (if present)
                 *      const string timeFormat = "HH:mm:ss.FFF";
                 *      List<string> dateTimeFormats = new List<string>(4);
                 *      dateTimeFormats.Add(shortDateFormat);
                 *      if (hasDate && !hasTime)
                 *        dateTimeFormats.Add(shortDateFormat + " " + timeFormat);
                 *      if (hasDate)
                 *      {
                 *        dateTimeFormats.Add(@"yyyyMMdd");
                 *        dateTimeFormats.Add(@"yyyyMMdd" + timeFormat);
                 *      }
                 */
                var dateTimeFormatInfo = new DateTimeFormatInfo();

                dateTimeFormatInfo.SetAllDateTimePatterns(dateTimeFormats, 'd');
                dateTimeFormatInfo.DateSeparator = dateSeparator;
                dateTimeFormatInfo.TimeSeparator = timeSeparator;

                // Use ParseExact since Parse does not work if a date sepertaor is set but
                // the date separator is not part of the date format
                try
                {
                    dateFieldValue = DateTime.ParseExact(stringDateValue, dateTimeFormats, dateTimeFormatInfo,
                                                         DateTimeStyles.AllowWhiteSpaces);
                    // Times get the current date added, remove it
                    //if ((!hasDate) && (dateFieldValue.Value.Date == DateTime.Now.Date))
                    //{
                    //  dateFieldValue = DateTime.MinValue.Date.Add(dateFieldValue.Value.TimeOfDay);
                    //}
                }
                catch (FormatException)
                {
                    if (dateSeparator != "/")
                    {
                        var dateTimeFormatInfoSlash = new DateTimeFormatInfo();

                        // Build a new formatter with / but otherwise the same settings
                        dateTimeFormatInfoSlash = (DateTimeFormatInfo)dateTimeFormatInfo.Clone();
                        dateTimeFormatInfoSlash.DateSeparator = "/";

                        // try with date separator of /
                        dateFieldValue = DateTime.ParseExact(stringDateValue, dateTimeFormats, dateTimeFormatInfoSlash,
                                                             DateTimeStyles.AllowWhiteSpaces);
                    }
                }
            }
            catch (Exception)
            {
                // ignoring all errors
            }

            return(dateFieldValue);
        }
コード例 #9
0
        public void ExtractTransactionData(ref CTransaction trans)
        {
            if (trans == null)
            {
                trans = new CTransaction();
            }
            string dom = browser.GetDocument();
            //Neu la don CCTT
            string namePartern = "[.]*<span id=\"ctl00_cphBody_show_results_title\">GCN kết quả tra cứu thông tin</span>[.]*";
            Regex  reg         = new Regex(namePartern, RegexOptions.IgnoreCase);

            int RefType = GetRefType();

            trans.RefType = RefType;
            if (RefType == 26)
            {
                ExtractCCTT(ref trans);
                return;
            }

            //========================

            //dom = "ABCDEF<span id=\"ucFilingDetailReview_ucFilerName_lblvalue\" class=\"FormControlNoEditLabel\">Ngân Hàng TMCP Xuất Nhập Khẩu Việt Nam Sở Giao Dịch I</span>aaafdsafe";
            namePartern = "[.]*<span id=\"[a-zA-Z0-9_]*FilingDetailReview_ucFilerName_lblvalue\"[^>]*>([^>]*)</span>[.]*";
            reg         = new Regex(namePartern, RegexOptions.IgnoreCase);
            if (reg.IsMatch(dom))
            {
                Match m = reg.Match(dom);
                trans.WarranterName = m.Groups[1].Value;
            }
            //<span id="ucFilingDetailReview_ucFilerAddress">66 Phó Đức Chính, phường Nguyễn Thái Bình,&nbsp;Quận 1, Hồ Chí Minh,&nbsp;Việt Nam</span>
            namePartern = "[.]*<span id=\"[a-zA-Z0-9_]*FilingDetailReview_ucFilerAddress\"[^>]*>([^>]*)</span>[.]*";
            reg         = new Regex(namePartern, RegexOptions.IgnoreCase);
            if (reg.IsMatch(dom))
            {
                Match m = reg.Match(dom);
                trans.WarranterAddress = m.Groups[1].Value;
            }
            //<span id="ucFilingDetailReview_ucNoticeType_lblvalue" class="FormControlNoEditLabel">Đăng ký giao dịch bảo đảm/Hợp đồng</span>
            namePartern = "[.]*<span id=\"[a-zA-Z0-9_]*FilingDetailReview_ucNoticeType_lblvalue\"[^>]*>([^>]*)</span>[.]*";
            reg         = new Regex(namePartern, RegexOptions.IgnoreCase);
            if (reg.IsMatch(dom))
            {
                Match m = reg.Match(dom);
                trans.TypeName = m.Groups[1].Value;
            }

            //<span id="ucFilingDetailReview_ucNoticeType_lblvalue" class="FormControlNoEditLabel">Đăng ký giao dịch bảo đảm/Hợp đồng</span>
            namePartern = "[.]*<span id=\"[a-zA-Z0-9_]*FilingDetailReview_ucNoticeType_lblvalue\"[^>]*>([^>]*)</span>[.]*";
            reg         = new Regex(namePartern, RegexOptions.IgnoreCase);
            if (reg.IsMatch(dom))
            {
                Match m = reg.Match(dom);
                trans.TypeName = m.Groups[1].Value;
            }

            //<span id="ucFilingDetailReview_ucFilingNumber_lblvalue" class="FormControlNoEditLabel">1146070105</span>
            namePartern = "[.]*<span id=\"[a-zA-Z0-9_]*FilingDetailReview_ucFilingNumber_lblvalue\"[^>]*>([^>]*)</span>[.]*";
            reg         = new Regex(namePartern, RegexOptions.IgnoreCase);
            if (reg.IsMatch(dom))
            {
                Match m = reg.Match(dom);
                trans.RefNo = m.Groups[1].Value;
            }

            namePartern = "[.]*<span id=\"[a-zA-Z0-9_]*FilingDetailReview_ucOriginalFilingNumber_lblvalue\"[^>]*>([^>]*)</span>[.]*";
            reg         = new Regex(namePartern, RegexOptions.IgnoreCase);
            if (reg.IsMatch(dom))
            {
                Match m = reg.Match(dom);
                trans.OldRefNo = m.Groups[1].Value;
                trans.OrgRefNo = trans.OldRefNo;
            }
            //<span id="ucFilingDetailReview_ucOriginalFilingDate_lblvalue" class="FormControlNoEditLabel">13/11/2009 11:00</span>
            //<span id="ctl00_cphBody_FilingDetailReview_ucOriginalFilingDate_lblvalue" class="FormControlNoEditLabel">09/03/2012 16:23</span>
            namePartern = "[.]*<span id=\"[a-zA-Z0-9_]*FilingDetailReview_ucOriginalFilingDate_lblvalue\"[^>]*>([^>]*)</span>[.]*";
            reg         = new Regex(namePartern, RegexOptions.IgnoreCase);
            if (reg.IsMatch(dom))
            {
                Match m = reg.Match(dom);

                DateTimeFormatInfo dateformat = new DateTimeFormatInfo();
                dateformat.SetAllDateTimePatterns(new string[] { "dd/MM/yyyy HH:mm", "dd/MM/yyyy", "dd MM yyyy" }, 'd');
                dateformat.SetAllDateTimePatterns(new string[] { "dd/MM/yyyy HH:mm", "dd/MM/yyyy", "dd MM yyyy" }, 'D');
                CultureInfo culture = new CultureInfo("vi-VN");

                trans.OldRefDate = DateTime.Parse(m.Groups[1].Value, dateformat);
            }

            //<span id="ucFilingDetailReview_ucFilingDate_lblvalue" class="FormControlNoEditLabel">01/07/2013 09:06</span>
            namePartern = "[.]*<span id=\"[a-zA-Z0-9_]*FilingDetailReview_ucFilingDate_lblvalue\"[^>]*>([^>]*)</span>[.]*";
            reg         = new Regex(namePartern, RegexOptions.IgnoreCase);
            if (reg.IsMatch(dom))
            {
                Match m = reg.Match(dom);
                //DateTimeFormatInfo dateformat = new DateTimeFormatInfo();
                //dateformat.SetAllDateTimePatterns(new string[]{"dd/MM/yyyy HH:mm","dd/MM/yyyy","dd MM yyyy"},'d');
                //dateformat.SetAllDateTimePatterns(new string[] { "dd/MM/yyyy HH:mm", "dd/MM/yyyy", "dd MM yyyy" }, 'D');
                //CultureInfo culture = new CultureInfo("vi-VN");
                trans.RefDate = ParseDateTime(m.Groups[1].Value);
                //trans.RefDate = DateTime.Parse(m.Groups[1].Value, dateformat);
            }

            // ContractNo
            //ucFilingDetailReview_ucReferenceNumber_lblvalue
            namePartern = "[.]*<span id=\"[a-zA-Z0-9_]*FilingDetailReview_ucReferenceNumber_lblvalue\"[^>]*>([^>]*)</span>[.]*";
            reg         = new Regex(namePartern, RegexOptions.IgnoreCase);
            if (reg.IsMatch(dom))
            {
                Match m = reg.Match(dom);
                trans.ContractNo = m.Groups[1].Value;
            }

            // ContractType
            //<span id="ucFilingDetailReview_ucSecuredInterestType_lblvalue" class="FormControlNoEditLabel">Hợp đồng cho thuê tài chính</span>
            namePartern = "[.]*<span id=\"[a-zA-Z0-9_]*FilingDetailReview_ucSecuredInterestType_lblvalue\"[^>]*>([^>]*)</span>[.]*";
            reg         = new Regex(namePartern, RegexOptions.IgnoreCase);
            if (reg.IsMatch(dom))
            {
                Match m = reg.Match(dom);
                trans.ContractTypeName = m.Groups[1].Value;
            }

            //<span id="ucFilingDetailReview_ucFilingDate_lblvalue" class="FormControlNoEditLabel">01/07/2013 09:06</span>
            namePartern = "[.]*<span id=\"[a-zA-Z0-9_]*txtCollateral_lblvalue\"[^>]*>([^>]*)</span>[.]*";
            reg         = new Regex(namePartern, RegexOptions.IgnoreCase);
            if (reg.IsMatch(dom))
            {
                Match m = reg.Match(dom);
                trans.Note = m.Groups[1].Value;
            }

            /*
             * <table class="GridView" cellspacing="0" rules="all" border="1" id="ucDebtorReview_gv" style="font-family:Khmer OS,Verdana;width:100%;border-collapse:collapse;">
             *          <tbody>
             * <tr class="GridViewHeader">
             *                  <th scope="col">Phân loại chủ thể</th>
             * <th scope="col">Số giấy tờ chứng minh tư cách pháp lý</th>
             * <th scope="col">Tên</th>
             * <th scope="col">Địa chỉ</th>
             *          </tr><tr class="GridViewRow">
             *                  <td>Tổ chức có đăng ký kinh doanh trong nước</td>
             * <td>Mã số thuế: 0307979603</td>
             * <td>Công Ty Cổ Phần Tân Thành đô City Ford</td>
             * <td>260 QL13, phường 26, Bình Thạnh,  Hồ Chí Minh, Việt Nam</td>
             *          </tr>
             *  </tbody></table>
             * */
            //<span id="ucFilingDetailReview_ucFilingDate_lblvalue" class="FormControlNoEditLabel">01/07/2013 09:06</span>
            //dom = "defg <t>abc</t><t id=\"a\">def</t> vfe";
            namePartern = "<table[^>]*id=\"[a-zA-Z0-9_]*DebtorReview_gv\"[^>]*>(((?!</table).)*)</table>";
            //namePartern = "<t id=\"a\">(((?!t).)*)</t>";
            reg = new Regex(namePartern, RegexOptions.IgnoreCase);

            dom = dom.Replace("\n", "");
            dom = dom.Replace("\r", "");
            if (reg.IsMatch(dom))
            {
                Match  m     = reg.Match(dom);
                string table = m.Groups[0].Value;
                table = PrepareHtmlToXml(table);
                //table = table.Replace("<br>", "&lt;br&gt;");
                //table = table.Replace("&nbsp;", "&#xA0;");
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(table);
                trans.AssetOwnnerList = new List <Person>();
                trans.AssetOwnerName  = "";
                XmlNodeList list = doc.SelectNodes("/table/tbody/tr");
                for (int i = 2; i <= list.Count; i++)
                {
                    string IdCardNo = doc.SelectSingleNode(string.Format("/table/tbody/tr[{0}]/td[2]", i)).InnerText;

                    if (IdCardNo.Contains(':'))
                    {
                        IdCardNo = IdCardNo.Split(':')[1].Trim();
                    }
                    else if (IdCardNo.Contains("Số hộ chiếu"))
                    {
                        if (IdCardNo.Contains("<br>"))
                        {
                            IdCardNo = IdCardNo.Substring(0, IdCardNo.IndexOf("<br>"));
                        }
                        IdCardNo = IdCardNo.Replace("Số hộ chiếu", "").Trim();
                    }
                    else
                    {
                        IdCardNo = "";
                    }

                    trans.AssetOwnnerList.Add(new Person()
                    {
                        ObjectName         = doc.SelectSingleNode(string.Format("/table/tbody/tr[{0}]/td[3]", i)).InnerText,
                        ObjectIDCardNumber = IdCardNo,
                        ObjectAddress      = doc.SelectSingleNode(string.Format("/table/tbody/tr[{0}]/td[4]", i)).InnerText
                    });

                    trans.AssetOwnerName += (string.IsNullOrEmpty(trans.AssetOwnerName) ? "" : " & ") + trans.AssetOwnnerList[i - 2].ObjectName;
                    trans.AssetIDCardNo   = IdCardNo;
                }
            }

            namePartern = "<table[^>]*id=\"[a-zA-Z0-9_]*SecuredPartyReview_gv\"[^>]*>(((?!</table).)*)</table>";
            //namePartern = "<t id=\"a\">(((?!t).)*)</t>";
            reg = new Regex(namePartern, RegexOptions.IgnoreCase);

            dom = dom.Replace("\n", "");
            dom = dom.Replace("\r", "");
            if (reg.IsMatch(dom))
            {
                Match  m     = reg.Match(dom);
                string table = m.Groups[0].Value;
                table = PrepareHtmlToXml(table);
                //table = table.Replace("<br>", "&lt;br&gt;");
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(table);
                trans.WarranterList = new List <Person>();
                XmlNodeList list = doc.SelectNodes("/table/tbody/tr");
                for (int i = 2; i <= list.Count; i++)
                {
                    trans.WarranterList.Add(new Person()
                    {
                        ObjectName    = doc.SelectSingleNode(string.Format("/table/tbody/tr[{0}]/td[1]", i)).InnerText,
                        ObjectAddress = doc.SelectSingleNode(string.Format("/table/tbody/tr[{0}]/td[2]", i)).InnerText
                    });
                }
            }
            else
            {
                //ctl00_cphBody_gvAuthorizingPartyReview_gv
                namePartern = "<table[^>]*id=\"[a-zA-Z0-9_]*gvAuthorizingPartyReview_gv\"[^>]*>(((?!</table).)*)</table>";
                reg         = new Regex(namePartern, RegexOptions.IgnoreCase);

                dom = dom.Replace("\n", "");
                dom = dom.Replace("\r", "");
                if (reg.IsMatch(dom))
                {
                    Match  m     = reg.Match(dom);
                    string table = m.Groups[0].Value;
                    table = PrepareHtmlToXml(table);
                    //table = table.Replace("<br>", "&lt;bt&gt;");
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(table);
                    trans.WarranterList = new List <Person>();
                    XmlNodeList list = doc.SelectNodes("/table/tbody/tr");
                    for (int i = 2; i <= list.Count; i++)
                    {
                        trans.WarranterList.Add(new Person()
                        {
                            ObjectName    = doc.SelectSingleNode(string.Format("/table/tbody/tr[{0}]/td[1]", i)).InnerText,
                            ObjectAddress = doc.SelectSingleNode(string.Format("/table/tbody/tr[{0}]/td[2]", i)).InnerText
                        });
                    }
                }
            }

            // Neu trong danh sach Warranter  co ten = ten KH thi gan Ma KHTX cho warranter do
            if (trans.WarranterList != null)
            {
                bool isMatchWarranterCode = false;
                for (int i = 0; i < trans.WarranterList.Count; i++)
                {
                    if (trans.WarranterList[i].ObjectName.Trim().Equals(trans.WarranterName.Trim(), StringComparison.OrdinalIgnoreCase))
                    {
                        trans.WarranterList[i].ObjectCode = trans.WarranterCode;
                        isMatchWarranterCode = true;
                    }
                }
                if (!isMatchWarranterCode && trans.WarranterList != null && trans.WarranterList.Count > 0)
                {
                    trans.WarranterList[0].ObjectCode = trans.WarranterCode;
                }
            }

            namePartern = "<table[^>]*id=\"[a-zA-Z0-9_]*SerialNumberReview_gv\"[^>]*>(((?!</table).)*)</table>";
            //namePartern = "<t id=\"a\">(((?!t).)*)</t>";
            reg = new Regex(namePartern, RegexOptions.IgnoreCase);

            dom = dom.Replace("\n", "");
            dom = dom.Replace("\r", "");
            if (reg.IsMatch(dom))
            {
                Match  m     = reg.Match(dom);
                string table = m.Groups[0].Value;
                table = PrepareHtmlToXml(table);
                //table = table.Replace("<br>", "&lt;br&gt;");
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(table);
                trans.AssetLicenseNumber = doc.SelectSingleNode("/table/tbody/tr[2]/td[1]").InnerText;
                trans.Assets             = new List <Asset>();
                XmlNodeList list = doc.SelectNodes("/table/tbody/tr");

                for (int i = 2; i <= list.Count; i++)
                {
                    trans.Assets.Add(new Asset()
                    {
                        AssetLicenseNumber = doc.SelectSingleNode(string.Format("/table/tbody/tr[{0}]/td[1]", i)).InnerText
                    });
                }
            }

            namePartern = "[.]*<span id=\"[a-zA-Z0-9_]*lblPINBefore\"[^>]*>([^>]*)</span>[.]*";
            reg         = new Regex(namePartern, RegexOptions.IgnoreCase);
            if (reg.IsMatch(dom))
            {
                Match    m    = reg.Match(dom);
                string   str  = m.Groups[1].Value;
                string[] arrs = str.Split(':');
                if (arrs.Length > 1)
                {
                    trans.AssetPersonalCode = arrs[1];
                }
            }
        }
コード例 #10
0
        public PragmaLicense FromXmlString(string xml)
        {
            PragmaLicense result = new PragmaLicense();

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            XmlElement docEl = doc.DocumentElement;

            if (docEl.Name.ToLowerInvariant() != "pragmalicense")
            {
                throw new Exception("XML document is not a PragmaLicense");
            }


            DateTimeFormatInfo fi = new DateTimeFormatInfo();

            fi.SetAllDateTimePatterns(new string[1] {
                "dd.MM.yyyy"
            }, 'd');

            foreach (XmlElement e in docEl.ChildNodes)
            {
                switch (e.Name.ToLowerInvariant())
                {
                case "product":
                    result.Product = (Product)ParseEnum(typeof(Product), e.InnerText);
                    break;

                case "productcodename":
                    result.ProductCodeName = (ProductCodeName)ParseEnum(typeof(ProductCodeName), e.InnerText);
                    break;

                case "activationkey":
                    result.ActivationKey = e.InnerText;
                    break;

                case "email":
                    result.EMail = e.InnerText;
                    break;

                case "purchasetype":
                    result.PurchaseType = (PurchaseType)ParseEnum(typeof(PurchaseType), e.InnerText);
                    break;

                case "lictype":
                    result.LicType = (LicType)ParseEnum(typeof(LicType), e.InnerText);
                    break;

                case "validfrom":
                    result.ValidFrom = String.IsNullOrEmpty(e.InnerText) ? null : (DateTime?)DateTime.Parse(e.InnerText, fi);
                    break;

                case "validto":
                    result.ValidTo = String.IsNullOrEmpty(e.InnerText) ? null : (DateTime?)DateTime.Parse(e.InnerText, fi);
                    break;

                case "machinekey":
                    result.MachineKey = new MachineID(e.InnerText);
                    break;

                case "machineidtype":
                    if (String.IsNullOrEmpty(e.InnerText))
                    {
                        result.MachineIdType = MachineIdType.Simple;
                    }
                    else
                    {
                        result.MachineIdType = (MachineIdType)ParseEnum(typeof(MachineIdType), e.InnerText);
                    }
                    break;

                default:
                    break;
                }
            }

            return(result);
        }