コード例 #1
0
ファイル: Factory.cs プロジェクト: netthanhhung/RoomSearch
        public static Post Post(System.Data.IDataReader reader)
        {
            Post result = null;

            if (null != reader && reader.Read())
            {
                result = new Post();
                PopulatePost(result, reader);
            }

            return result;
        }
コード例 #2
0
ファイル: KenhNhaTroJob.cs プロジェクト: tmthang86/RoomSearch
        private Post GetDetailPost(string urlDetail, int cityId, int districtId)
        {
            Post result = null;
            try
            {
                result = new Post();
                result.PostTypeId = (int)PostTypes.Room;
                result.CityId = cityId;
                result.CountryId = 232;
                result.DistrictId = districtId;
                result.RoomTypeId = (int)RoomTypes.Standard;
                result.AvailableRooms = 1;
                result.CreatedBy = "KenhNhaTroCollector";

                HtmlAgilityPack.HtmlWeb web = new HtmlWeb();
                HtmlAgilityPack.HtmlDocument document = web.Load(urlDetail);

                HtmlNode matrixResultsNode = RequestHelper.FindElementNodeByClassName(document.DocumentNode, "detail");
                if (matrixResultsNode != null)
                {
                    HtmlNode titleNode = RequestHelper.FindElementNodeByClassName(matrixResultsNode, "dtitle");
                    if (titleNode != null)
                    {
                        result.Description = titleNode.InnerText;
                    }

                    HtmlNode personNode = RequestHelper.FindElementNodeByClassName(matrixResultsNode, "dtnguoidang");
                    if (personNode != null)
                    {
                        foreach (HtmlNode child in personNode.ChildNodes)
                        {
                            if (child.Name == "span")
                            {
                                result.PersonName = child.InnerText;
                                break;
                            }
                        }
                    }

                    HtmlNode emailNode = RequestHelper.FindElementNodeByClassName(matrixResultsNode, "dtemail");
                    if (emailNode != null)
                    {
                        foreach (HtmlNode child in emailNode.ChildNodes)
                        {
                            if (child.Name == "a")
                            {
                                result.Email = child.InnerText;
                                break;
                            }
                        }
                    }

                    HtmlNode addressNode = RequestHelper.FindElementNodeByClassName(matrixResultsNode, "direction");
                    if (addressNode != null)
                    {
                        HtmlNode parent = addressNode.ParentNode;
                        foreach (HtmlNode child in parent.ChildNodes)
                        {
                            if (child.Name == "span" && child.Attributes["class"].Value == "green")
                            {
                                result.Address = child.InnerText;
                                break;
                            }
                        }
                    }

                    HtmlNode phoneNode = RequestHelper.FindElementNodeByClassName(matrixResultsNode, "dphone info");
                    if (phoneNode != null)
                    {
                        foreach (HtmlNode child in phoneNode.ChildNodes)
                        {
                            if (child.Name == "span")
                            {
                                result.PhoneNumber = child.InnerText;
                                break;
                            }
                        }
                    }

                    HtmlNode priceNode = RequestHelper.FindElementNodeByClassName(matrixResultsNode, "dgia info");
                    if (priceNode != null)
                    {
                        foreach (HtmlNode child in priceNode.ChildNodes)
                        {
                            if (child.Name == "span")
                            {
                                string price = child.InnerText;
                                string[] array = price.Split(' ');
                                if (array.Length > 0 && !string.IsNullOrEmpty(array[0]))
                                {
                                    string priceReal = array[0].Replace(".", "");
                                    decimal priceDec;
                                    if (decimal.TryParse(priceReal, out priceDec))
                                    {
                                        result.Price = priceDec / 1000000;
                                        if (result.Price >= 10)
                                        {
                                            result.RoomTypeId = (int)RoomTypes.Exclusive;
                                        }
                                    }
                                    else
                                    {
                                        result.Price = 2;
                                    }
                                }
                                break;
                            }
                        }
                    }

                    HtmlNode squreNode = RequestHelper.FindElementNodeByClassName(matrixResultsNode, "ddientich infos");
                    if (squreNode != null)
                    {
                        foreach (HtmlNode child in squreNode.ChildNodes)
                        {
                            if (child.Name == "span")
                            {
                                string price = child.InnerText;
                                string[] array = price.Split(' ');
                                if (array.Length > 0 && !string.IsNullOrEmpty(array[0]))
                                {
                                    string priceReal = array[0].Replace(".", "");
                                    decimal priceDec;
                                    if (decimal.TryParse(priceReal, out priceDec))
                                    {
                                        result.MeterSquare = priceDec / 100;
                                    }
                                    else
                                    {
                                        result.MeterSquare = 20;
                                    }
                                }
                                break;
                            }
                        }
                    }

                    HtmlNode desNode = RequestHelper.FindElementNodeByClassName(matrixResultsNode, "dnoidung");
                    if (desNode != null)
                    {
                        string description = desNode.InnerText;
                        int index1 = description.IndexOf("tags:");
                        int index2 = description.IndexOf("quang cao adsense");
                        if (!string.IsNullOrEmpty(description) && (index1 > 0 || index2 > 0))
                        {
                            if (index1 > 0)
                            {
                                description = description.Substring(0, index1 - 1);
                            }
                            else if (index2 > 5)
                            {
                                description = description.Substring(0, index2 - 5);
                            }
                        }
                        description = RequestHelper.SplitLongStringIntoMultilines(description);
                        result.Description += description;
                        HtmlNode imageNode = RequestHelper.FindElementNodeByClassName(matrixResultsNode, "imgnhatro");
                        if (imageNode != null)
                        {
                            result.ImageList = new List<Image>();
                            foreach (HtmlNode child in imageNode.ChildNodes)
                            {
                                if (child.Name == "p")
                                {
                                    foreach (HtmlNode imgItem in child.ChildNodes)
                                    {
                                        if (imgItem.Name == "img" && !string.IsNullOrEmpty(imgItem.Attributes["src"].Value))
                                        {
                                            string source = imgItem.Attributes["src"].Value;
                                            using (var client = new WebClient())
                                            {
                                                byte[] imageFile = client.DownloadData(source);
                                                Image newImage = new Image();
                                                newImage.ImageSmallContent = RequestHelper.ResizeImageByteArray(100, imageFile);
                                                newImage.ImageContent = RequestHelper.ResizeImageByteArray(400, imageFile);
                                                newImage.FileName = "noname";
                                                newImage.ImageTypeId = (int)ImageType.Room;
                                                newImage.CreatedBy = result.CreatedBy;
                                                result.ImageList.Add(newImage);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex.Message, ex);
            }
            return result;
        }
コード例 #3
0
ファイル: Factory.cs プロジェクト: netthanhhung/RoomSearch
 public static void PopulatePost(Post input, System.Data.IDataReader reader)
 {
     PopulateRecord(input, reader);
     input.RecordId = input.PostId = Utilities.ToInt(reader[RoomSearch.Common.Post.ColumnNames.PostId]);
     input.PostTypeId = Utilities.ToInt(reader[RoomSearch.Common.Post.ColumnNames.PostTypeId]);
     input.PersonName = Utilities.ToString(reader[RoomSearch.Common.Post.ColumnNames.PersonName]);
     input.PhoneNumber = Utilities.ToString(reader[RoomSearch.Common.Post.ColumnNames.PhoneNumber]);
     input.Email = Utilities.ToString(reader[RoomSearch.Common.Post.ColumnNames.Email]);
     input.Gender = Utilities.ToNInt(reader[RoomSearch.Common.Post.ColumnNames.Gender]);
     input.Floor = Utilities.ToNInt(reader[RoomSearch.Common.Post.ColumnNames.Floor]);
     input.Address = Utilities.ToString(reader[RoomSearch.Common.Post.ColumnNames.Address]);
     input.District = Utilities.ToString(reader[RoomSearch.Common.Post.ColumnNames.District]);
     input.DistrictId = Utilities.ToNInt(reader[RoomSearch.Common.Post.ColumnNames.DistrictId]);
     input.City = Utilities.ToString(reader[RoomSearch.Common.Post.ColumnNames.City]);
     input.CityId = Utilities.ToNInt(reader[RoomSearch.Common.Post.ColumnNames.CityId]);
     input.Country = Utilities.ToString(reader[RoomSearch.Common.Post.ColumnNames.Country]);
     input.CountryId = Utilities.ToNInt(reader[RoomSearch.Common.Post.ColumnNames.CountryId]);
     input.RoomTypeId = Utilities.ToNInt(reader[RoomSearch.Common.Post.ColumnNames.RoomTypeId]);
     input.RealestateTypeId = Utilities.ToNInt(reader[RoomSearch.Common.Post.ColumnNames.RealestateTypeId]);
     input.RoomType = Utilities.ToString(reader[RoomSearch.Common.Post.ColumnNames.RoomType]);
     input.RealestateType = Utilities.ToString(reader[RoomSearch.Common.Post.ColumnNames.RealestateType]);
     input.AvailableRooms = Utilities.ToNInt(reader[RoomSearch.Common.Post.ColumnNames.AvailableRooms]);
     input.Description = Utilities.ToString(reader[RoomSearch.Common.Post.ColumnNames.Description]);
     input.MeterSquare = Utilities.ToNDecimal(reader[RoomSearch.Common.Post.ColumnNames.MeterSquare]);
     input.Price = Utilities.ToNDecimal(reader[RoomSearch.Common.Post.ColumnNames.Price]);
     input.IsLegacy = Utilities.ToBool(reader[RoomSearch.Common.Post.ColumnNames.IsLegacy]);
 }
コード例 #4
0
 //void btnLink_Click(object sender, EventArgs e)
 //{
 //    throw new NotImplementedException();
 //}
 void BindReadonlyImageList(Post post)
 {
     if (post != null && post.ImageList != null && post.ImageList.Count > 0)
     {
         foreach (Common.Image imageData in post.ImageList)
         {
             System.Web.UI.WebControls.Image imageSource = new System.Web.UI.WebControls.Image();
             if (imageData.ImageContent != null)
             {
                 imageSource.ImageUrl = "data:image/jpeg;base64," + Convert.ToBase64String(imageData.ImageContent);
             }
             else if (imageData.ImageSmallContent != null)
             {
                 imageSource.ImageUrl = "data:image/jpeg;base64," + Convert.ToBase64String(imageData.ImageSmallContent);
             }
             imageSource.Width = 400;
             imageSource.Style.Add("margin-top", "5px");
             imageSource.Style.Add("margin-left", "5px");
             imageSource.Style.Add("margin-right", "5px");
             imageSource.Style.Add("margin-bottom", "5px");
             panelImage.Controls.Add(imageSource);
         }
     }
 }
コード例 #5
0
        private Post GetSavePost()
        {
            Post saveItem = ViewState["CurrentPost"] as Post;
            int displayIndex = 1;
            if (saveItem == null)
            {
                saveItem = new Post();
                saveItem.ImageList = new List<Common.Image>();
                saveItem.PostTypeId = (int)PostTypes.Room;
                saveItem.CountryId = 232;
            }
            else if (saveItem.ImageList != null)
            {
                int? max = saveItem.ImageList.Max(i => i.DisplayIndex);
                displayIndex = (max.HasValue ? max.Value : 0) + 1;
            }
            saveItem.PersonName = txtPersonName.Text;
            saveItem.PhoneNumber = txtPhoneNumber.Text;
            saveItem.Email = txtEmail.Text;
            saveItem.CityId = Convert.ToInt32(cbbCity.SelectedValue);
            saveItem.DistrictId = Convert.ToInt32(cbbDistrict.SelectedValue);
            saveItem.Address = txtAddress.Text;

            saveItem.MeterSquare = Convert.ToDecimal(txtMeterSQuare.Value);
            saveItem.AvailableRooms = txtAvailableRooms.Value.HasValue ? Convert.ToInt32(txtAvailableRooms.Value) : 1;
            saveItem.Price = Convert.ToDecimal(txtPrice.Value);
            saveItem.Description = txtDescription.Text;
            saveItem.PostTypeId = GetPostTypeId();

            if (saveItem.PostTypeId == (int)PostTypes.Room)
            {
                saveItem.RoomTypeId = Convert.ToInt32(cbbRoomType.SelectedValue);
            }
            if (saveItem.PostTypeId == (int)PostTypes.StayWith)
            {
                saveItem.RoomTypeId = Convert.ToInt32(cbbRoomType.SelectedValue);
                saveItem.Gender = radMale.Checked ? 1 : 0;
            }
            else if (saveItem.PostTypeId == (int)PostTypes.House)
            {
                saveItem.Gender = radMale.Checked ? 1 : 0;
                saveItem.RealestateTypeId = Convert.ToInt32(cbbRealestateType.SelectedValue); ;
            }

            foreach (UploadedFile file in radUploadMulti.UploadedFiles)
            {
                string fileName = file.GetName();
                System.Web.UI.WebControls.Image imageSource = new System.Web.UI.WebControls.Image();
                Stream imageStream = file.InputStream;
                int bufferSize = Convert.ToInt32(imageStream.Length);
                byte[] byteArray = new byte[bufferSize];
                imageStream.Read(byteArray, 0, bufferSize);

                MemoryStream resizedStream = UtilityHelper.ResizeFromStream(400, imageStream);

                Common.Image newImage = new Common.Image();
                newImage.ImageContent = byteArray;
                newImage.ImageSmallContent = resizedStream.ToArray(); ;
                newImage.DisplayIndex = displayIndex++;
                newImage.ImageTypeId = (int)Common.ImageType.Room;
                newImage.FileName = fileName;
                newImage.CreatedBy = newImage.UpdatedBy = saveItem.PersonName;

                saveItem.ImageList.Add(newImage);
            }

            saveItem.CreatedBy = saveItem.UpdatedBy = saveItem.PersonName;

            return saveItem;
        }
コード例 #6
0
        void BindData(Post post)
        {
            btnLink.Text = HttpContext.Current.Request.Url.AbsoluteUri.Replace("PostDetailPopup", "PostDetailPage");

            //linkRealLink.NavigateUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace("PostDetailPopup", "PostDetailPage");
            //+string.Format("/PostDetailPage?PostId={0}&PostType={1}", post.PostId, GetPostTypeId());
            txtPersonName.Text = post.PersonName;
            txtEmail.Text = post.Email;
            txtPhoneNumber.Text = post.PhoneNumber;
            cbbCity.SelectedValue = post.CityId.ToString();
            cbbDistrict.SelectedValue = post.DistrictId.ToString();
            txtAddress.Text = post.Address;
            txtAvailableRooms.Value = post.AvailableRooms;
            txtMeterSQuare.Value = post.MeterSquare.HasValue ? Convert.ToDouble(post.MeterSquare.Value) : 0;
            txtPrice.Value = post.Price.HasValue ? Convert.ToDouble(post.Price.Value) : 0;
            cbbRoomType.SelectedValue = post.RoomTypeId.ToString();
            txtDescription.Text = post.Description;
            radMale.Checked = post.Gender == 1;
            radFemale.Checked = post.Gender == 0;
            cbbRealestateType.SelectedValue = post.RealestateTypeId.ToString();
            datPostDate.SelectedDate = post.DateUpdated;
        }
コード例 #7
0
        public static void SavePost(Post saveItem)
        {
            if (saveItem != null)
            {
                bool isUpdate = saveItem.PostId > 0;
                SaveRecord(saveItem);

                if (!isUpdate && saveItem.ImageList != null && saveItem.ImageList.Count > 0)
                {
                    foreach (Image image in saveItem.ImageList)
                    {
                        image.ItemId = saveItem.PostId = Convert.ToInt32(saveItem.RecordId);
                        SaveRecord(image);
                    }
                }
                else
                {
                    List<Image> oldImages = ListImage(null, saveItem.PostId, (int)ImageType.Room, 0);
                    foreach (Image oldItem in oldImages)
                    {
                        if (saveItem.ImageList == null || saveItem.ImageList.Count(i => i.ImageId == oldItem.ImageId) == 0)
                        {
                            DeleteRecord(oldItem);
                        }
                    }

                    if (saveItem.ImageList != null)
                    {
                        foreach (Image image in saveItem.ImageList)
                        {
                            if (image.ImageId <= 0)
                            {
                                image.ItemId = saveItem.PostId = Convert.ToInt32(saveItem.RecordId);
                                SaveRecord(image);
                            }
                        }
                    }

                }

            }
        }
コード例 #8
0
        private Post GetDetailPost(string urlDetail, int cityId, int districtId)
        {
            Post result = null;
            try
            {
                result = new Post();
                result.PostTypeId = (int)PostTypes.Room;
                result.CityId = cityId;
                result.CountryId = 232;
                result.DistrictId = districtId;
                result.RoomTypeId = (int)RoomTypes.Standard;
                result.AvailableRooms = 1;
                result.CreatedBy = "BatDongSanCollector";

                HtmlAgilityPack.HtmlWeb web = new HtmlWeb();
                HtmlAgilityPack.HtmlDocument document = web.Load(urlDetail);

                HtmlNode matrixResultsNode = RequestHelper.FindElementNodeById(document.DocumentNode, "product-detail");
                if (matrixResultsNode != null)
                {
                    HtmlNode titleNode = RequestHelper.FindElementNodeByClassName(matrixResultsNode, "pm-title");
                    if (titleNode != null)
                    {
                        result.Description = titleNode.InnerText;
                    }

                    HtmlNode chitietNode = RequestHelper.FindElementNodeByClassName(matrixResultsNode, "kqchitiet");
                    if (chitietNode != null)
                    {
                        List<HtmlNode> nodes = RequestHelper.FindAllElementNodeByType(chitietNode, "strong");
                        if (nodes != null && nodes.Count >= 2)
                        {
                            string price = RequestHelper.GetCleanString(nodes[0].InnerText);
                            string[] array = price.Split(' ');
                            if (array.Length > 0 && !string.IsNullOrEmpty(array[0]))
                            {
                                string priceReal = array[0];
                                decimal priceDec;
                                if (decimal.TryParse(priceReal, out priceDec))
                                {
                                    if (priceDec > 100)
                                    {
                                        priceDec = priceDec / 1000;
                                    }
                                    result.Price = priceDec;
                                    if (result.Price >= 10)
                                    {
                                        result.RoomTypeId = (int)RoomTypes.Exclusive;
                                    }
                                }
                                else
                                {
                                    result.Price = 2;
                                }
                            }

                            string square = RequestHelper.GetCleanString(nodes[1].InnerText);
                            string[] arrayS = square.Split('m');
                            if (array.Length > 0 && !string.IsNullOrEmpty(arrayS[0]))
                            {
                                string squareReal = arrayS[0];
                                decimal squareDec;
                                if (decimal.TryParse(squareReal, out squareDec))
                                {
                                    result.MeterSquare = squareDec;
                                }
                                else
                                {
                                    result.MeterSquare = 20;
                                }
                            }
                        }
                    }

                    HtmlNode desNode = RequestHelper.FindElementNodeByClassName(matrixResultsNode, "pm-content stat");
                    if (desNode != null)
                    {
                        string description = desNode.InnerText;
                        int index1 = description.IndexOf("Tìm kiếm theo từ khóa");
                        if (!string.IsNullOrEmpty(description) && (index1 > 0))
                        {
                            description = description.Substring(0, index1 - 1);
                        }
                        description = RequestHelper.SplitLongStringIntoMultilines(description);
                        result.Description += description;
                    }

                    HtmlNode imgNode = RequestHelper.FindElementNodeByClassName(matrixResultsNode, "list-img");
                    if (imgNode != null)
                    {
                        result.ImageList = new List<Image>();
                        List<HtmlNode> nodes = RequestHelper.FindAllElementNodeByType(imgNode, "img");
                        foreach (HtmlNode imgItem in nodes)
                        {
                            if (!string.IsNullOrEmpty(imgItem.Attributes["src"].Value))
                            {
                                string source = imgItem.Attributes["src"].Value;
                                source = source.Replace("80x60", "745x510");
                                using (var client = new WebClient())
                                {
                                    byte[] imageFile = client.DownloadData(source);
                                    if (imageFile != null && imageFile.Length > 0)
                                    {
                                        Image newImage = new Image();
                                        newImage.ImageSmallContent = RequestHelper.ResizeImageByteArray(100, imageFile);
                                        newImage.ImageContent = RequestHelper.ResizeImageByteArray(400, imageFile);
                                        newImage.FileName = "noname";
                                        newImage.ImageTypeId = (int)ImageType.Room;
                                        newImage.CreatedBy = result.CreatedBy;
                                        result.ImageList.Add(newImage);
                                    }
                                }
                            }
                        }
                    }

                    HtmlNode detailNode = RequestHelper.FindElementNodeByClassName(matrixResultsNode, "pm-content-detail");
                    if (detailNode != null)
                    {
                        HtmlNode leftDetailNode = RequestHelper.FindElementNodeByClassName(detailNode, "left-detail");
                        if (leftDetailNode != null)
                        {
                            HtmlNode addressNode = RequestHelper.FindElementNodeByClassName(leftDetailNode, "right");
                            if (addressNode != null)
                            {
                                result.Address = RequestHelper.GetCleanString(addressNode.InnerText);
                            }
                        }
                    }

                    HtmlNode cusInfoNode = RequestHelper.FindElementNodeById(matrixResultsNode, "divCustomerInfo");
                    if (cusInfoNode != null)
                    {
                        List<HtmlNode> nodes = RequestHelper.FindAllElementNodeByClassName(cusInfoNode, "right-content");
                        foreach (HtmlNode item in nodes)
                        {
                            HtmlNode leftNode = RequestHelper.FindElementNodeByClassName(item, "normalblue left");
                            HtmlNode rightNode = RequestHelper.FindElementNodeByClassName(item, "right");
                            if (leftNode != null && rightNode != null)
                            {
                                if (RequestHelper.GetCleanString(leftNode.InnerText) == "Tên liên lạc")
                                {
                                    result.PersonName = RequestHelper.GetCleanString(rightNode.InnerText);
                                }
                                if (RequestHelper.GetCleanString(leftNode.InnerText) == "Điện thoại"
                                    || RequestHelper.GetCleanString(leftNode.InnerText) == "Mobile")
                                {
                                    result.PhoneNumber = RequestHelper.GetCleanString(rightNode.InnerText);
                                }
                            }
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex.Message, ex);
            }
            return result;
        }
コード例 #9
0
ファイル: RongBayJob.cs プロジェクト: netthanhhung/RoomSearch
        private Post GetDetailPost(string urlDetail, int cityId, int districtId)
        {
            Post result = null;
            try
            {
                result = new Post();
                result.PostTypeId = (int)PostTypes.Room;
                result.CityId = cityId;
                result.CountryId = 232;
                result.DistrictId = districtId;
                result.RoomTypeId = (int)RoomTypes.Standard;
                result.AvailableRooms = 1;
                result.CreatedBy = "RongBayCollector";
                result.ImageList = new List<Image>();

                HtmlAgilityPack.HtmlWeb web = new HtmlWeb();
                HtmlAgilityPack.HtmlDocument document = web.Load(urlDetail);

                HtmlNode authorNode = RequestHelper.FindElementNodeById(document.DocumentNode, "NewsAuthor");
                if (authorNode != null)
                {
                    HtmlNode mobileNode = RequestHelper.FindElementNodeByClassName(authorNode, "mobilecall");
                    if (mobileNode != null)
                    {
                        HtmlNode spanNode = RequestHelper.FindFirstElementNodeByType(mobileNode, "span");
                        if (spanNode != null)
                        {
                            result.PhoneNumber = RequestHelper.GetStringFromAsciiHex(RequestHelper.GetCleanString(spanNode.InnerText));
                        }
                    }

                    HtmlNode personNode = RequestHelper.FindElementNodeByClassName(authorNode, "detail_personal");
                    if (personNode != null)
                    {
                        HtmlNode aNode = RequestHelper.FindFirstElementNodeByType(personNode, "a");
                        if (aNode != null)
                        {
                            result.PersonName = RequestHelper.GetCleanString(aNode.InnerText);
                        }
                    }
                }

                HtmlNode descriptionNode = RequestHelper.FindElementNodeById(document.DocumentNode, "NewsContent");
                if (descriptionNode != null)
                {
                    string description = string.Empty;
                    List<HtmlNode> pNodes = RequestHelper.FindAllElementNodeByType(descriptionNode, "p");
                    if (pNodes.Count > 0)
                    {
                        foreach (HtmlNode pNode in pNodes)
                        {
                            string paragraph = RequestHelper.GetCleanString(pNode.InnerText);
                            if (!string.IsNullOrEmpty(paragraph))
                            {
                                description += paragraph + "\n";
                            }
                        }
                    }
                    else
                    {
                        description = RequestHelper.GetCleanString(descriptionNode.InnerText);
                    }
                    description = RequestHelper.SplitLongStringIntoMultilines(description);
                    result.Description = description;

                    result.Price = RequestHelper.ParsePrice(description);
                    if (result.Price >= 10)
                    {
                        result.RoomTypeId = (int)RoomTypes.Exclusive;
                    }

                    if (!result.Price.HasValue)
                    {
                        return null;
                    }
                }

                HtmlNode imgNode = RequestHelper.FindElementNodeById(document.DocumentNode, "show_galley_d");
                if (imgNode != null)
                {
                    List<HtmlNode> aNodes = RequestHelper.FindAllElementNodeByType(imgNode, "a");
                    foreach (HtmlNode aNode in aNodes)
                    {
                        if (aNode.Attributes["href"] != null)
                        {
                            string imgLink = aNode.Attributes["href"].Value;
                            if (!imgLink.Contains("http:"))
                            {
                                imgLink = "http://rongbay.com" + imgLink;
                            }
                            using (var client = new WebClient())
                            {
                                byte[] imageFile = client.DownloadData(imgLink);
                                Image newImage = new Image();
                                newImage.ImageSmallContent = RequestHelper.ResizeImageByteArray(100, imageFile);
                                newImage.ImageContent = RequestHelper.ResizeImageByteArray(400, imageFile);
                                newImage.FileName = "noname";
                                newImage.ImageTypeId = (int)ImageType.Room;
                                newImage.CreatedBy = result.CreatedBy;
                                result.ImageList.Add(newImage);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex.Message, ex);
            }
            return result;
        }
コード例 #10
0
        void BindData(Post post)
        {
            int postTypeId = GetPostTypeId();

            if (postTypeId == (int)PostTypes.Room)
            {
                this.Page.Title = "Phòng trọ : " + post.ShortTitle;
            }
            else if (postTypeId == (int)PostTypes.StayWith)
            {
                this.Page.Title = "Ở ghép : " + post.ShortTitle;
            }
            else if (postTypeId == (int)PostTypes.House)
            {
                this.Page.Title = "Nhà đất : " + post.ShortTitle;
            }

            txtPersonName.Text = post.PersonName;
            txtEmail.Text = post.Email;
            txtPhoneNumber.Text = post.PhoneNumber;
            cbbCity.SelectedValue = post.CityId.ToString();
            cbbDistrict.SelectedValue = post.DistrictId.ToString();
            txtAddress.Text = post.Address;
            txtAvailableRooms.Value = post.AvailableRooms;
            txtMeterSQuare.Value = post.MeterSquare.HasValue ? Convert.ToDouble(post.MeterSquare.Value) : 0;
            txtPrice.Value = post.Price.HasValue ? Convert.ToDouble(post.Price.Value) : 0;
            cbbRoomType.SelectedValue = post.RoomTypeId.ToString();
            txtDescription.Text = post.Description;
            radMale.Checked = post.Gender == 1;
            radFemale.Checked = post.Gender == 0;
            cbbRealestateType.SelectedValue = post.RealestateTypeId.ToString();
            datPostDate.SelectedDate = post.DateUpdated;
        }