예제 #1
0
        /// <summary>
        /// Get the insert company into database
        /// </summary>
        /// <param name="html"></param>
        public void InsertCompany(string html)
        {
            try
                {
                    var company = new CKS_Company
                    {
                        CreateDate = DateTime.Now,
                        UpdateDate = DateTime.Now
                    };

                    var htmlDocument = new HtmlDocument();
                    htmlDocument.LoadHtml(html);

                    #region Main Info

                    var mainInfo = htmlDocument.DocumentNode.Descendants("div")
                        .FirstOrDefault(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("infoDetail"));

                    if (mainInfo != null)
                    {
                        foreach (var descendant in mainInfo.Descendants("div"))
                        {
                            var objTitle = descendant.Descendants("span").FirstOrDefault();
                            if (objTitle != null)
                            {
                                objTitle.Remove();
                                string title = objTitle.InnerText.Trim().ToLower(),
                                       value = descendant.InnerText.Trim();

                                switch (title)
                                {
                                    case "tên doanh nghiệp:":
                                        company.Title = value;
                                        break;
                                    case "tên giao dịch:":
                                        company.TransTitle = value;
                                        break;
                                    case "loại hình doanh nghiệp:":
                                        company.CompanyType = value;
                                        break;
                                    case "địa chỉ:":
                                        company.Address = value;
                                        break;
                                    case "tỉnh/thành phố:":
                                        company.City = value;
                                        break;
                                    case "số điện thoại:":
                                        company.Phone = value;
                                        break;
                                    case "fax:":
                                        company.Fax = value;
                                        break;
                                    case "email:":
                                        company.Email = value;
                                        break;
                                    case "website:":
                                        company.Website = value;
                                        break;
                                }

                            }
                        }
                    }

                    #endregion

                    #region Sub Info

                    var subInfo = htmlDocument.DocumentNode.Descendants("div")
                        .FirstOrDefault(d => d.Attributes.Contains("style")
                            && d.Attributes["style"].Value.Contains("background:#f5f5f5; padding:10px"));

                    if (subInfo != null)
                    {
                        foreach (var descendant in subInfo.Descendants("div"))
                        {
                            var objTitle = descendant.Descendants("span").FirstOrDefault();
                            if (objTitle != null)
                            {
                                objTitle.Remove();
                                string title = objTitle.InnerText.Trim().ToLower(),
                                       value = descendant.InnerText.Trim();

                                switch (title)
                                {
                                    case "mã số doanh nghiệp:":
                                        company.CompanyCode = value;
                                        break;
                                    case "ngày hoạt động chính thức:":
                                        company.ActiveDate = GetDate(value);
                                        break;
                                    case "người đại diện pháp luật:":
                                        company.LegalRepresentive = value;
                                        break;
                                    case "nơi thường trú:":
                                        company.LegalRepresentiveAddress = value;
                                        break;
                                    case "vốn điều lệ:":
                                        company.AuthorizedCapital = value;
                                        break;
                                    case "ngành nghề kinh doanh:":
                                        company.DescriptionMajor = value;
                                        break;
                                    case "thông tin thêm:":
                                        company.Description = value;
                                        break;
                                    case "hội đồng quản trị(hoặc danh sách cổ đông):":
                                        company.Directors = value;
                                        break;
                                }

                            }
                        }
                    }

                    var allowedDateObj = htmlDocument.DocumentNode.Descendants("td")
                        .FirstOrDefault(d => d.Id.Equals("scate"));
                    if (allowedDateObj != null)
                    {
                        var span = allowedDateObj.Descendants("span").FirstOrDefault();
                        if (span != null)
                        {
                            span.Remove();
                            company.AllowedDate = GetDate(Regex.Replace(allowedDateObj.InnerText, @"\t|\n|\r", "").Trim());
                        }
                    }

                    #endregion

                               var tmpCompany = RepositoryFactory.Company.GetByCode(company.Title);

                if (tmpCompany == null)
                {
                    RepositoryFactory.Company.Insert(company);
                }

                }
                catch (Exception ex)
                {
                    SingletonLogger.Instance.Error("InsertCompany", ex);
                }
        }
예제 #2
0
        /// <summary>
        /// Get the insert company into database
        /// </summary>
        /// <param name="html"></param>
        private void InsertCompany(string html)
        {
            try
            {
                var company = new CKS_Company
                {
                    CreateDate = DateTime.Now,
                    UpdateDate = DateTime.Now
                };

                var htmlDocument = new HtmlDocument();
                htmlDocument.LoadHtml(html);

                var infoBox = htmlDocument.DocumentNode.Descendants("dl")
                    .FirstOrDefault(d => d.Attributes.Contains("class")
                                         && d.Attributes["class"].Value.Contains("company-info"));
                var infos = infoBox.Descendants("dd").ToArray();

                company.Title = HttpUtility.HtmlDecode(infos[0].InnerText).Trim();
                if (string.IsNullOrEmpty(company.Title))
                {
                    company.Title = HttpUtility.HtmlDecode(infos[1].InnerText).Trim();
                }

                company.Address = HttpUtility.HtmlDecode(infos[4].InnerText).Trim();
                company.City = HttpUtility.HtmlDecode(infos[5].InnerText).Trim();
                company.CompanyType = HttpUtility.HtmlDecode(infos[6].InnerText).Trim();
                company.Phone = HttpUtility.HtmlDecode(infos[8].InnerText).Trim();
                company.Fax = HttpUtility.HtmlDecode(infos[9].InnerText).Trim();
                company.Email = HttpUtility.HtmlDecode(infos[10].InnerText).Trim();
                company.Website = HttpUtility.HtmlDecode(infos[11].InnerText).Trim();

                company.DescriptionMajor = HttpUtility.HtmlDecode(infos[7].InnerText).Trim();
                company.Description = HttpUtility.HtmlDecode(infos[12].InnerText).Trim();
                company.Directors = HttpUtility.HtmlDecode(infos[3].InnerText).Trim();

                var tmpCompany = RepositoryFactory.Company.GetByTitle(company.Title);

                if (tmpCompany == null)
                {
                    RepositoryFactory.Company.Insert(company);
                }
            }
            catch (Exception ex)
            {
                SingletonLogger.Instance.Error("InsertCompany", ex);
            }
        }
예제 #3
0
 public CKS_Company Insert(CKS_Company item)
 {
     dbEntities.CKS_Company.Add(item);
     dbEntities.SaveChanges();
     return item;
 }