/// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FileVersion GetModel(System.Data.SqlClient.SqlConnection connection, int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 * from [" + databaseprefix + "FileVersion] ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            FileVersion model = new FileVersion();
            DataSet     ds    = DbHelperSQLEx.Query(connection, null, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                model = ChangeRowToFile(ds.Tables[0].Rows[0]);
                return(model);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///根据文件名和文件md5判断是否已经上传
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="fileMd5"></param>
        /// <returns></returns>
        public int GetFileID(System.Data.SqlClient.SqlConnection connection, int forderID, string fileName, string fileMd5)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  ID from " + databaseprefix + "File");
            strSql.Append(" where File_DirId=@forderID and File_Name=@fileName  and isDeleted =0");
            SqlParameter[] parameters =
            {
                new SqlParameter("@forderID", SqlDbType.Int),
                new SqlParameter("@fileName", SqlDbType.VarChar),
                new SqlParameter("@fileMd5",  SqlDbType.VarChar),
            };
            parameters[0].Value = forderID;
            parameters[1].Value = fileName;
            parameters[2].Value = fileMd5;
            return(Convert.ToInt32(DbHelperSQLEx.GetSingle(connection, strSql.ToString(), parameters)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public int GetForderId(System.Data.SqlClient.SqlConnection connection, int parentId, string forderName, string userName, int projectId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id from " + databaseprefix + "Forder");
            strSql.Append(" where Parent_Id=@Parent_Id and Title=@Title and Project_Id=@Project_Id and isdeleted = 0");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Parent_Id",  SqlDbType.Int,       4),
                new SqlParameter("@Title",      SqlDbType.VarChar, 200),
                new SqlParameter("@Project_Id", SqlDbType.Int,       4),
            };
            parameters[0].Value = parentId;
            parameters[1].Value = forderName;
            parameters[2].Value = projectId;

            return(Convert.ToInt32(DbHelperSQLEx.GetSingle(connection, strSql.ToString(), parameters)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取文件最新版本
        /// </summary>
        /// <param name="fileId"></param>
        /// <returns></returns>
        public Model.FileVersion GetFileLastVer(System.Data.SqlClient.SqlConnection connection, int fileId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top 1 V.ID  from " + databaseprefix + "File F left join " + databaseprefix + "FileVersion V on F.id = V.File_Id");
            if (fileId > 0)
            {
                strSql.Append(" where  F.id = @fileId ");
            }
            strSql.Append("  order by v.ver desc");
            SqlParameter[] parameters =
            {
                new SqlParameter("@fileId", SqlDbType.Int, 4),
            };
            parameters[0].Value = fileId;

            int verID = Convert.ToInt32(DbHelperSQLEx.GetSingle(connection, strSql.ToString(), parameters));

            return(new FileVersionDalEx(databaseprefix).GetModel(connection, verID));
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            CtripHotelHttpServer ctrip = new CtripHotelHttpServer();
            string info                       = "";
            string html7                      = ctrip.QueryPriceHtml("939388", DateTime.Now.AddDays(1), DateTime.Now.AddDays(2), out info);
            var    rrrrr                      = ctrip.AnalysePriceHtml(html7, "", out info);
            HotelDetailViewServer h           = new HotelDetailViewServer();
            HotelPriceServer      priceserver = new HotelPriceServer();
            RoomsServer           roomsserver = new RoomsServer();

            Logger.WriteLog("请输入要查询的ID范围,日期范围,用半角逗号分隔:(如:992,2000,2017-10-09,2017-11-09)\r\n");

            string v = Console.ReadLine();

            //string v = "1,2000,2017-10-19,2017-10-30";
            Logger.WriteLog(v, false);
            string   city  = "北京";
            string   area  = "北京西城区酒店";
            int      count = h.GetRecordCount("[PlatID]=1 AND [City]='" + city + "'");
            string   sql   = "";
            DateTime d1    = Convert.ToDateTime(v.Split(',')[2]);
            DateTime d2    = Convert.ToDateTime(v.Split(',')[3]);

            Logger.WriteLog("正在加载所选酒店....");
            List <HotelDetailViewModel> list = h.GetModelList($"[PlatID]=1 AND [City]='北京' and id>=" + v.Split(',')[0] + " AND ID<=" + v.Split(',')[1]);//AND [AREA]='北京西城区酒店'

            //List<HotelDetailViewModel> list = h.GetModelList(sql);//AND [AREA]='北京西城区酒店'
            Logger.WriteLog($"所选酒店{list.Count}条加载完毕");
            DataTable dtprice     = DbHelperSQLEx.GetDataTable("SELECT TOP 1 * FROM HotelPrice");
            DataTable dtclone     = dtprice.Clone();
            DataTable dtroom      = DbHelperSQLEx.GetDataTable("SELECT TOP 1 * FROM Rooms");
            DataTable dtroomclone = dtroom.Clone();
            DateTime  dtbegin     = d1;// Convert.ToDateTime(v.Split(',')[2]);
            //int days = (Convert.ToDateTime(v.Split(',')[3]) - dtbegin).Days;
            int    days            = (d2 - d1).Days;
            Random ran             = new Random(DateTime.Now.Millisecond);
            HotelDetailViewModel m = null;
            string   parse_hotelid = "";
            DateTime parse_date;

            for (int i = 0; i < list.Count; i++)
            {
                m = list[i];
                for (int j = 0; j < days; j++)
                {
                    DateTime indate  = dtbegin.AddDays(j);
                    DateTime outdate = dtbegin.AddDays(j + 1);

                    /*
                     *如果这个酒店天前更新过价格,则跳过
                     */
                    int cou = priceserver.GetRecordCount($"HotelPlatID='{m.HotelPlatID}' AND  PlatID={m.PlatID} AND InDate='{indate.ToString("yyyy-MM-dd")}' AND (UpdateDate>='{DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd")}'  or createdate>='{DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd")}' )");//SELECT COUNT(1)  FROM [HotelPrice] HP  WHERE HP.HotelPlatID='' AND HP.PlatID=1 AND HP.InDate='' AND UpdateDate>=''
                    if (cou != 0)
                    {
                        Console.WriteLine(m.HotelName + "," + indate.ToShortDateString() + ",3天内已更新过");
                        continue;
                    }
                    //Thread.Sleep(ran.Next(1000, 4000));
                    #region 模拟请求
                    string url = "http://hotels.ctrip.com/Domestic/tool/AjaxHote1RoomListForDetai1.aspx?psid=&MasterHotelID=" + m.HotelPlatID
                                 + "&hotel=" + m.HotelPlatID + "&EDM=F&roomId=&IncludeRoom=&city=1&supplier=&showspothotel=T&IsDecoupleSpotHotelAndGroup=F&contrast=0&brand=614"
                                 + "&startDate=" + indate.ToString("yyyy-MM-dd") + "&depDate=" + outdate.ToString("yyyy-MM-dd")
                                 + "&IsFlash=F&RequestTravelMoney=F&hsids=&IsJustConfirm=&contyped=0&priceInfo=-1"
                                 + "&equip=&filter=bed|0,bf|0,network|0,policy|0,hourroom|0,&productcode=&couponList=&abForHuaZhu=&defaultLoad=F"
                                 + "&eleven=510e429809230c4b002cb9b567b407adb56118e161f3dbe20d2855dc652ff6a6&callback=CASJacaauulJVNspCzn&_=1506613336689";
                    string referer = "http://hotels.ctrip.com/hotel/" + m.HotelPlatID + ".html";
                    string log     = m.HotelName + "," + referer + "," + indate.ToString("yyyy-MM-dd");
                    //Console.WriteLine(log);
                    Thread.Sleep(ran.Next(2000, 5000));
                    string html = ctrip.GetRequest(url, referer);
                    CtripHotelPriceJSON json = null;
                    try
                    {
                        json = Newtonsoft.Json.JsonConvert.DeserializeObject <CtripHotelPriceJSON>(html);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteLog(JsonConvert.SerializeObject(m));
                        Thread.Sleep(ran.Next(5000, 10000));
                        Logger.WriteLog(referer);
                        continue;
                    }
                    #endregion
                    string d = json.html.Replace("\\/", "/").Replace("\\u000a", "").Replace("\\u0009", "");

                    HtmlDocument doc = new HtmlDocument();
                    doc.LoadHtml(d);
                    List <RoomsModel> rooms = new List <RoomsModel>();

                    var        room_types             = doc.DocumentNode.SelectNodes("//td[contains(@class,'room_type')]");
                    RoomsModel r                      = null;
                    Maticsoft.Model.HotelPriceModel p = null;
                    if (room_types == null)
                    {
                        Logger.WriteLog(log + "  没有查询到房间");
                        continue;
                    }
                    else
                    {
                        Logger.WriteLog(log + "");
                    }
                    foreach (var item in room_types)
                    {
                        List <Maticsoft.Model.HotelPriceModel> prices = new List <Maticsoft.Model.HotelPriceModel>();
                        #region 所有房型
                        r             = new RoomsModel();
                        r.PlatID      = 1;
                        r.CreateDate  = DateTime.Now;
                        r.HotelID     = m.HotelID;
                        r.HotelPlatID = m.HotelPlatID;
                        r.BaseRoomID  = item.ParentNode.SelectSingleNode("td").Id;
                        r.RoomName    = item.InnerText.Trim().Split('\n')[0];
                        r.RoomID      = "";
                        var c = DbHelperSQL.GetSingle("SELECT   COUNT(1)  FROM [Rooms]  WHERE [HotelPlatID]='" + m.HotelPlatID + "' AND PlatID=" + m.PlatID + " AND BaseRoomID='" + r.BaseRoomID + "'");
                        if (Convert.ToInt32(c.ToString()) == 0)
                        {
                            roomsserver.Add(r);
                        }
                        rooms.Add(r);
                        var roomprices = doc.DocumentNode.SelectNodes("//tr[@brid=" + r.BaseRoomID + "]");
                        //roomprices.RemoveAt(0);
                        int coun = 0;
                        foreach (var node in roomprices)
                        {//子房型
                            #region 子房型以及价格
                            p             = new Maticsoft.Model.HotelPriceModel();
                            p.CreateDate  = DateTime.Now;
                            p.HotelID     = m.HotelID;
                            p.HotelPlatID = r.HotelPlatID;
                            p.PlatID      = m.PlatID;
                            p.BaseRoomID  = r.BaseRoomID;
                            p.InDate      = indate;
                            p.OutDate     = outdate;
                            p.RoomID      = "";
                            var nodeprice = node.SelectSingleNode("td/div/a");
                            if (nodeprice == null)
                            {
                                continue;
                            }
                            string price = "";
                            try
                            {
                                price = nodeprice.Attributes["data-order"].Value;
                            }
                            catch (Exception ex)
                            {
                                continue;
                            }
                            string[] pp  = price.Split(',');
                            decimal  ppp = Convert.ToDecimal(nodeprice.Attributes["data-price"].Value);
                            p.RoomID = pp[0];
                            p.Price  = ppp - Convert.ToDecimal(pp[6]);
                            var t = node.SelectSingleNode("td/span[@class='room_type_name']");
                            if (t != null)
                            {
                                p.SaleTitle = t.InnerText;
                            }
                            if (string.IsNullOrEmpty(p.SaleTitle))
                            {
                                p.SaleTitle = t.SelectSingleNode("span[@class=\"supplier_logo\"]").Attributes["style"].Value;//.Replace("", "").Replace("","");
                            }
                            if (node.SelectSingleNode("td/span[2]") != null)
                            {
                                p.SaleTitle = p.SaleTitle + node.SelectSingleNode("td/span[2]").InnerText;
                            }
                            p.Tag = nodeprice.InnerText;// nodeprice.ParentNode.ParentNode.ParentNode.SelectSingleNode("//div[@class=\"btns_base22_skin02\"]").InnerText;

                            p.IsCancel       = pp[11];
                            p.BedType        = pp[9];
                            p.BreakfirstType = Convert.ToInt32(pp[10]);
                            p.RoomCount      = node.SelectSingleNode("td/div/div").InnerText;
                            var modellist = priceserver.GetModelList($@"SaleTitle='{p.SaleTitle}' and BedType='{p.BedType}' and BreakfirstType='{p.BreakfirstType}' and InDate='{p.InDate.ToString("yyyy-MM-dd")}' and OutDate='{p.OutDate.ToString("yyyy-MM-dd")}'
and PlatID={p.PlatID} and RoomID='{p.RoomID}' and HotelPlatID='{p.HotelPlatID}' and BaseRoomID='{p.BaseRoomID}'");

                            if (!p.SaleTitle.Contains("尊享惊喜优惠"))
                            {
                                coun++;
                            }
                            if (coun <= 4)
                            {
                                if (!p.SaleTitle.Contains("代理") && !p.Tag.Contains("担保") && !p.Tag.Contains("到店付"))
                                {
                                    p.IsAgentPrivate = true;
                                }
                            }
                            prices.Add(p);
                            if (modellist.Count > 0)
                            {//更新价格
                                priceserver.UpdatePrice(p.Price, modellist[0].ID);
                            }
                            else
                            {                         //添加
                                if (p.IsAgentPrivate) //只保存携程自营的价格
                                {
                                    try
                                    {
                                        priceserver.Add(p);
                                    }
                                    catch (Exception e)
                                    {
                                        Logger.WriteException(e);
                                        Logger.WriteLog(e.Message);
                                    }
                                }
                            }
                            #endregion
                            Logger.WriteLog("携程自营价格" + prices.FindAll(x => x.IsAgentPrivate).Count() + "条," + m.HotelPlatName + "," + r.RoomName + ",[" + indate.ToShortDateString() + "," + m.HotelPlatID + "," + m.ID + "]");
                        }
                        #endregion
                    }
                }
                Console.WriteLine("=========================================");
                Console.WriteLine("查询完毕");
                Console.WriteLine("=========================================");
            }
            Console.WriteLine("所有酒店查询完毕");
            Console.ReadKey();
        }
Ejemplo n.º 6
0
        public void FindPrice()
        {//string sql, DateTime d1, DateTime d2
            CtripHotelHttpServer ctrip = new CtripHotelHttpServer();

            HotelDetailViewServer h           = new HotelDetailViewServer();
            HotelPriceServer      priceserver = new HotelPriceServer();
            RoomsServer           roomsserver = new RoomsServer();

            //Logger.WriteLog("请输入要查询的ID范围,日期范围,用半角逗号分隔:");
            Logger.WriteLog("正在加载所选酒店....");
            //sql = "hotelplatid='2570579'";

            List <HotelDetailViewModel> list = h.GetModelList(sql);//AND [AREA]='北京西城区酒店'

            Logger.WriteLog($"所选酒店{list.Count}条加载完毕");
            DataTable            dtprice     = DbHelperSQLEx.GetDataTable("SELECT TOP 1 * FROM HotelPrice");
            DataTable            dtclone     = dtprice.Clone();
            DataTable            dtroom      = DbHelperSQLEx.GetDataTable("SELECT TOP 1 * FROM Rooms");
            DataTable            dtroomclone = dtroom.Clone();
            DateTime             dtbegin     = d1;
            int                  days        = (d2 - d1).Days;
            Random               ran         = new Random(DateTime.Now.Millisecond);
            HotelDetailViewModel m           = null;

            for (int i = 0; i < list.Count; i++)
            {
                if (!CtsFlag)
                {
                    goto BREAK;
                }
                m = list[i];
                for (int j = 0; j < days; j++)
                {
                    if (!CtsFlag)
                    {
                        goto BREAK;
                    }
                    DateTime indate  = dtbegin.AddDays(j);
                    DateTime outdate = dtbegin.AddDays(j + 1);
                    var      exists  = priceserver.GetModelList($"HotelPlatID='{m.HotelPlatID}' AND  PlatID={m.PlatID} AND InDate='{indate.ToString("yyyy-MM-dd")}'");
                    if (exists.Count != 0)
                    {
                        exists.ForEach(x => x.Price = 0);
                        priceserver.Update(exists.ToArray());
                    }
                    int cou = priceserver.GetRecordCount($"HotelPlatID='{m.HotelPlatID}' AND  PlatID={m.PlatID} AND InDate='{indate.ToString("yyyy-MM-dd")}' AND (UpdateDate>='{DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd")}'  or createdate>='{DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd")}' )");//SELECT COUNT(1)  FROM [HotelPrice] HP  WHERE HP.HotelPlatID='' AND HP.PlatID=1 AND HP.InDate='' AND UpdateDate>=''
                    if (cou != 0)
                    {
                        //Logger.WriteLog(m.HotelName + "," + indate.ToShortDateString() + ",3天内已更新过");
                        //continue;
                    }
                    #region 模拟请求
                    string url = "http://hotels.ctrip.com/Domestic/tool/AjaxHote1RoomListForDetai1.aspx?psid=&MasterHotelID=" + m.HotelPlatID
                                 + "&hotel=" + m.HotelPlatID + "&EDM=F&roomId=&IncludeRoom=&city=1&supplier=&showspothotel=T&IsDecoupleSpotHotelAndGroup=F&contrast=0&brand=614"
                                 + "&startDate=" + indate.ToString("yyyy-MM-dd") + "&depDate=" + outdate.ToString("yyyy-MM-dd");
                    //+ "&IsFlash=F&RequestTravelMoney=F&hsids=&IsJustConfirm=&contyped=0&priceInfo=-1"
                    //+ "&equip=&filter=bed|0,bf|0,network|0,policy|0,hourroom|0,&productcode=&couponList=&abForHuaZhu=&defaultLoad=F"
                    //+ "&eleven=510e429809230c4b002cb9b567b407adb56118e161f3dbe20d2855dc652ff6a6&callback=CASJacaauulJVNspCzn&_=1506613336689";
                    string referer = "http://hotels.ctrip.com/hotel/" + m.HotelPlatID + ".html";
                    string log     = m.HotelName + "," + referer + "," + indate.ToString("yyyy-MM-dd");
                    //Console.WriteLine(log);
                    Thread.Sleep(ran.Next(2000, 5000));
                    string html = ctrip.GetRequest(url, referer);
                    CtripHotelPriceJSON json = null;
                    try
                    {
                        json = JsonConvert.DeserializeObject <CtripHotelPriceJSON>(html);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteLog(JsonConvert.SerializeObject(m));
                        Thread.Sleep(ran.Next(5000, 10000));
                        Logger.WriteLog(referer);
                        continue;
                    }
                    #endregion
                    string d = json.html.Replace("\\/", "/").Replace("\\u000a", "").Replace("\\u0009", "");

                    HtmlDocument doc = new HtmlDocument();
                    doc.LoadHtml(d);
                    List <RoomsModel> rooms = new List <RoomsModel>();

                    var             room_types = doc.DocumentNode.SelectNodes("//td[contains(@class,'room_type')]");
                    RoomsModel      r          = null;
                    HotelPriceModel p          = null;
                    if (room_types == null)
                    {
                        Logger.WriteLog(log + "  没有查询到房间");
                        continue;
                    }
                    else
                    {
                        Logger.WriteLog(log + "");
                    }
                    foreach (var item in room_types)
                    {
                        List <HotelPriceModel> prices = new List <HotelPriceModel>();
                        #region 所有房型
                        r             = new RoomsModel();
                        r.PlatID      = 1;
                        r.CreateDate  = DateTime.Now;
                        r.HotelID     = m.HotelID;
                        r.HotelPlatID = m.HotelPlatID;
                        r.BaseRoomID  = item.ParentNode.SelectSingleNode("td").Id;
                        r.RoomName    = item.InnerText.Trim().Split('\n')[0];
                        r.RoomID      = "";
                        var c = DbHelperSQL.GetSingle("SELECT   COUNT(1)  FROM [Rooms]  WHERE [HotelPlatID]='" + m.HotelPlatID + "' AND PlatID=" + m.PlatID + " AND BaseRoomID='" + r.BaseRoomID + "'");
                        if (Convert.ToInt32(c.ToString()) == 0)
                        {
                            roomsserver.Add(r);
                        }
                        rooms.Add(r);
                        var roomprices = doc.DocumentNode.SelectNodes("//tr[@brid=" + r.BaseRoomID + "]");
                        //roomprices.RemoveAt(0);
                        int coun = 0;
                        foreach (var node in roomprices)
                        {//子房型
                            #region 子房型以及价格
                            p             = new Maticsoft.Model.HotelPriceModel();
                            p.CreateDate  = DateTime.Now;
                            p.HotelID     = m.HotelID;
                            p.HotelPlatID = r.HotelPlatID;
                            p.PlatID      = m.PlatID;
                            p.BaseRoomID  = r.BaseRoomID;
                            p.InDate      = indate;
                            p.OutDate     = outdate;
                            p.RoomID      = "";
                            var nodeprice = node.SelectSingleNode("td/div/a");
                            if (nodeprice == null)
                            {
                                continue;
                            }
                            string price = "";
                            try
                            {
                                price = nodeprice.Attributes["data-order"].Value;
                                //订完46554879,0,0.0,1539,FG,0.0,0.0,0,F,大床,1,免费取消,F,T,F,F,
                                //有房46554945,0,0.0,2298,FG,0.0,0.0,0,T,大床,2,免费取消,F,T,F,F,
                                //有房21706174,0,0.0,1562,PP,0,0.0,0,F,大床,1,不可取消,F,T,F,F,
                                //有房              0,0,0.0,1242,PP,0,0.0,0,F,大床,1,,F,T,F,F,
                            }
                            catch (Exception ex)
                            {
                                Logger.WriteException(ex);
                                continue;
                            }
                            string[] pp  = price.Split(',');
                            decimal  ppp = Convert.ToDecimal(nodeprice.Attributes["data-price"].Value);
                            p.RoomID = pp[0];
                            p.Price  = ppp - Convert.ToDecimal(pp[6]);
                            if (pp[8] == "T")
                            {
                                //有房
                            }
                            else
                            {
                                //p.Price = 0;
                                //没房
                            }
                            var t = node.SelectSingleNode("td/span[@class='room_type_name']");
                            if (t != null)
                            {
                                p.SaleTitle = t.InnerText;
                            }
                            if (string.IsNullOrEmpty(p.SaleTitle))
                            {
                                p.SaleTitle = t.SelectSingleNode("span[@class=\"supplier_logo\"]").Attributes["style"].Value;//.Replace("", "").Replace("","");
                            }

                            if (node.SelectSingleNode("td/span[2]") != null)
                            {
                                p.SaleTitle = p.SaleTitle + node.SelectSingleNode("td/span[2]").InnerText;
                            }
                            p.Tag = nodeprice.InnerText; // nodeprice.ParentNode.ParentNode.ParentNode.SelectSingleNode("//div[@class=\"btns_base22_skin02\"]").InnerText;
                            if (p.SaleTitle.Contains("background-image"))
                            {                            //background-image:url(http://pic.c-ctrip.com/hotels121118/supplier_logo/yichengb65x20.png)闪住
                                foreach (var image in ConfigurationManager.AppSettings.Keys)
                                {
                                    if (p.SaleTitle.Contains(image.ToString()))
                                    {
                                        Regex reg = new Regex(@"background-image:url\(.*\)");
                                        p.SaleTitle = reg.Replace(p.SaleTitle, ConfigurationManager.AppSettings[image.ToString()]);
                                    }
                                }
                            }


                            p.IsCancel       = pp[11];
                            p.BedType        = pp[9];
                            p.BreakfirstType = Convert.ToInt32(pp[10]);
                            p.RoomCount      = node.SelectSingleNode("td/div/div").InnerText;
                            var modellist = priceserver.GetModelList($@"SaleTitle='{p.SaleTitle}' and BedType='{p.BedType}' and BreakfirstType='{p.BreakfirstType}' and InDate='{p.InDate.ToString("yyyy-MM-dd")}' and OutDate='{p.OutDate.ToString("yyyy-MM-dd")}'
and PlatID={p.PlatID} and RoomID='{p.RoomID}' and HotelPlatID='{p.HotelPlatID}' and BaseRoomID='{p.BaseRoomID}'");

                            if (!p.SaleTitle.Contains("尊享惊喜优惠") || !p.SaleTitle.Contains("亿程旅行社"))
                            {
                                coun++;
                            }
                            if (coun <= 4)
                            {
                                if (!p.SaleTitle.Contains("代理") && !p.Tag.Contains("担保") && !p.Tag.Contains("到店付"))
                                {
                                    p.IsAgentPrivate = true;
                                }
                            }
                            prices.Add(p);
                            if (modellist.Count > 0)
                            {//更新价格
                                priceserver.UpdatePrice(p.Price, modellist[0].ID);
                                //int id = modellist[0].ID;
                                p.ID         = modellist[0].ID;
                                modellist[0] = p;

                                priceserver.Update(modellist[0]);
                            }
                            else
                            {                         //添加
                                if (p.IsAgentPrivate) //只保存携程自营的价格
                                {
                                    try
                                    {
                                        priceserver.Add(p);
                                    }
                                    catch (Exception e)
                                    {
                                        Logger.WriteException(e);
                                        Logger.WriteLog(e.Message);
                                    }
                                }
                            }
                            #endregion
                            Logger.WriteLog("携程自营价格" + prices.FindAll(x => x.IsAgentPrivate).Count() + "条," + m.HotelPlatName + "," + r.RoomName + ",[" + indate.ToShortDateString() + "," + m.HotelPlatID + "," + m.ID + "]");
                        }
                        #endregion
                    }
                }
                Console.WriteLine("=========================================");
                Console.WriteLine("查询完毕");
                Console.WriteLine("=========================================");
            }
BREAK:
            Console.WriteLine("所有酒店查询完毕");
        }
Ejemplo n.º 7
0
        private static void GetAllHotelInfo()
        {
            PlatServer p    = new PlatServer();
            var        ds   = p.GetList("");
            HttpServer http = new HttpServer();
            HttpResult result;

            http.Host           = "hotels.ctrip.com";
            http.Accept         = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
            http.AcceptEncoding = "gzip,deflate,sdch";
            http.AcceptLanguage = "zh-CN,zh;q=0.8";
            http.Method         = "get";
            //http.Url = "http://hotels.ctrip.com/hotel/511769.html#ctm_ref=hod_hp_hv_def_n_1";
            http.Url     = "http://hotels.ctrip.com/hotel/473871.html#ctm_ref=hod_hp_hv_def_n_1";
            result       = http.GetHttpResult();
            http.Referer = "http://hotels.ctrip.com/hotel/6074225.html";
            http.Url     = "http://hotels.ctrip.com/Domestic/tool/AjaxHote1RoomListForDetai1.aspx?psid=&MasterHotelID=6074225"
                           + "&hotel=6074225&EDM=F&roomId=&IncludeRoom=&city=1&supplier=&showspothotel=T&IsDecoupleSpotHotelAndGroup=F&contrast=0&brand=614"
                           + "&startDate=2017-10-03&depDate=2017-10-04"
                           + "&IsFlash=F&RequestTravelMoney=F&hsids=&IsJustConfirm=&contyped=0&priceInfo=-1"
                           + "&equip=&filter=bed|0,bf|0,network|0,policy|0,hourroom|0,&productcode=&couponList=&abForHuaZhu=&defaultLoad=F"
                           + "&eleven=510e429809230c4b002cb9b567b407adb56118e161f3dbe20d2855dc652ff6a6&callback=CASJacaauulJVNspCzn&_=1506613336689";
            result = http.GetHttpResult();

            CtripAppHttpServer c             = new CtripAppHttpServer();
            string             city          = "青岛";
            List <string>      listurl       = c.Index("sitemap-qingdao7");
            DataTable          dtHotelDetail = DbHelperSQLEx.GetDataTable("SELECT TOP (1) * FROM HotelDetail");

            DataTable     dtHotel = DbHelperSQLEx.GetDataTable("SELECT TOP (1) * FROM Hotel");
            List <string> idlist  = new List <string>();

            foreach (var item in listurl)
            {
                DataTable dtcHotelDetail = dtHotelDetail.Clone();
                var       dtcHotel       = dtHotel.Clone();
                string    html           = c.GetHotelUrls("http://m.ctrip.com" + item);
                Console.WriteLine("http://m.ctrip.com" + item);
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(html);
                var nodes = doc.DocumentNode.SelectNodes("//a[@class=\"noramla ainfooter\"]");
                //*[@id="client_id_viewport_239538_1506702718553"]/div[3]/a[1]
                List <string> pagehotel = new List <string>();

                if (pagehotel.Count == 0)
                {
                }
                if (nodes != null)
                {
                    //foreach (var url in nodes)
                    //{
                    //    pagehotel.Add("http://m.ctrip.com" + url.Attributes["href"].Value);
                    //}
                }
                else
                {
                    pagehotel.Add("http://m.ctrip.com" + item);
                    foreach (var url in pagehotel)
                    {
                        //每一页酒店列表
                        string area = "";
                        html = c.GetHotelUrls(url);

                        Console.WriteLine(url);

                        Console.Write(html);
                        doc = new HtmlDocument();
                        doc.LoadHtml(html);
                        nodes = doc.DocumentNode.SelectNodes("//a[@class=\"noramla line2items\"]");//j获取酒店节点
                        if (nodes == null)
                        {
                            Logger.WriteLog(url);
                            continue;
                        }
                        area = doc.DocumentNode.SelectSingleNode("//h2").InnerText;
                        //nodes.ToList().ForEach(x => { });
                        foreach (var hotel in nodes)
                        {
                            #region MyRegion
                            string id = "";
                            try
                            {
                                id = Regex.Match(hotel.Attributes["href"].Value, @"/(?<id>\d+)\.").Groups[1].Value;
                            }
                            catch (ArgumentException ex)
                            {
                                // Syntax error in the regular expression
                                continue;
                            }

                            string name  = hotel.InnerText;
                            var    count = DbHelperSQL.GetSingle("SELECT   COUNT(1)  FROM [HotelDetail]  WHERE [HotelPlatID]='" + id + "' AND PlatID=1");
                            if (Convert.ToInt32(count.ToString()) > 0)
                            {
                                continue;
                            }
                            var row = dtcHotelDetail.NewRow();
                            var r   = dtcHotel.NewRow();
                            r["HotelName"]  = name;
                            r["City"]       = city;
                            r["Area"]       = area;
                            r["Star"]       = 0;
                            r["CreateDate"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                            row["HotelID"]     = id;
                            row["PlatID"]      = 1;
                            row["HotelPlatID"] = id;
                            row["HotelName"]   = name;
                            row["CreateDate"]  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            dtcHotelDetail.Rows.Add(row);
                            dtcHotel.Rows.Add(r);
                            #endregion
                        }
                        DbHelperSQLEx.SqlBuckCopy(dtcHotelDetail, "HotelDetail");
                        DbHelperSQLEx.SqlBuckCopy(dtcHotel, "Hotel");
                        dtcHotelDetail.Rows.Clear();
                        dtcHotel.Rows.Clear();
                    }
                    continue;
                }
                //page
                foreach (var url in nodes)
                {//每一页酒店列表
                    Random ran = new Random(DateTime.Now.Millisecond);
                    Thread.Sleep(ran.Next(5000, 10000));
                    string area = "";
                    html = c.GetHotelUrls("http://m.ctrip.com" + url.Attributes["href"].Value);
                    doc  = new HtmlDocument();
                    doc.LoadHtml(html);

                    Console.WriteLine("http://m.ctrip.com" + url.Attributes["href"].Value);

                    Console.Write(html);
                    var nodes2 = doc.DocumentNode.SelectNodes("//a[@class=\"noramla line2items\"]");//j获取酒店节点//noramla line2items
                    if (nodes2 == null)
                    {
                        Logger.WriteLog("http://m.ctrip.com" + url.Attributes["href"].Value);
                        continue;
                    }
                    area = doc.DocumentNode.SelectSingleNode("//h2").InnerText;
                    //nodes.ToList().ForEach(x => { });
                    foreach (var hotel in nodes2)
                    {
                        #region MyRegion
                        string id = "";
                        try
                        {
                            id = Regex.Match(hotel.Attributes["href"].Value, @"/(?<id>\d+)\.").Groups[1].Value;
                        }
                        catch (ArgumentException ex)
                        {
                            // Syntax error in the regular expression
                            continue;
                        }
                        var count = DbHelperSQL.GetSingle("SELECT   COUNT(1)  FROM [HotelDetail]  WHERE [HotelPlatID]='" + id + "' AND PlatID=1");
                        if (Convert.ToInt32(count.ToString()) > 0)
                        {
                            continue;
                        }
                        string name = hotel.InnerText;

                        var row = dtcHotelDetail.NewRow();
                        var r   = dtcHotel.NewRow();
                        r["HotelName"]  = name;
                        r["City"]       = city;
                        r["Area"]       = area;
                        r["Star"]       = 0;
                        r["CreateDate"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");


                        row["HotelID"]     = id;
                        row["PlatID"]      = 1;
                        row["HotelPlatID"] = id;
                        row["HotelName"]   = name;
                        row["CreateDate"]  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        dtcHotelDetail.Rows.Add(row);
                        dtcHotel.Rows.Add(r);
                        #endregion
                    }
                    DbHelperSQLEx.SqlBuckCopy(dtcHotelDetail, "HotelDetail");
                    DbHelperSQLEx.SqlBuckCopy(dtcHotel, "Hotel");
                    dtcHotelDetail.Rows.Clear();
                    dtcHotel.Rows.Clear();
                }
            }
            Console.WriteLine("=========================================");
            Console.WriteLine(city + "查询完毕");
            Console.WriteLine("=========================================");
        }