private void btnDelete_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtRoomNumber.Text) || roomId == 0) { MessageBox.Show("Please select Room first!", "Delete Message", MessageBoxButtons.OK, MessageBoxIcon.Error); initForm(); } else { ActionResult deleteResult = formCtrl._deleteFormData(new RoomsModel() { RoomId = roomId }); if (deleteResult.State) { RoomsModel deleteObj = deleteResult.Data; MessageBox.Show("Room " + deleteObj.RoomNumber + " Sucessfully Deleted!", "Delete Message", MessageBoxButtons.OK, MessageBoxIcon.Information); initForm(); } else { MessageBox.Show(deleteResult.Data, "Delete Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private async void DeleteRoomCommandExecuted(RoomsModel obj) { if (obj.TypeStatusRoom == 0 || obj.TypeStatusRoom == 2) { bool answer = await App.Current.MainPage.DisplayAlert("Eliminar", $"Desea eliminar el cuarto: {obj.Name}", "Si", "No"); if (answer) { var response = await client.Delete <ListResponse>($"room/delroom?IdRoom={obj.IdRoom}&IdOwner={obj.IdOwner}"); if (response != null) { if (response.Result && response.Count > 0) { SnackSucces("Se elimino correctamente", "KYA", Helpers.TypeSnackBar.Top); LoadOwner(); } else { SnackError(response.Message, "Error", Helpers.TypeSnackBar.Top); } } else { SnackError("Hubo un error intentelo mas tarde", "Error", Helpers.TypeSnackBar.Top); } } } else { SnackError("No puedes eliminar un cuarto que esta ocupado", "Error", Helpers.TypeSnackBar.Top); } }
public static RoomsModel EntityToModel(this Rooms entity, bool virtualActive = false) { try { RoomsModel model = new RoomsModel() { BlockFloorId = entity.BlockFloorId, Number = entity.Number, RoomTypeId = entity.RoomTypeId, IsActive = entity.IsActive, Id = entity.Id }; if (virtualActive) { model.RoomSales = entity.RoomSales; model.BlockFloor = entity.BlockFloor; model.RoomSales = entity.RoomSales; model.RoomStatuses = entity.RoomStatuses; model.RoomType = entity.RoomType; } return(model); } catch (Exception) { return(new RoomsModel()); } }
public UpdateRoomAdminPopup(RoomsModel room) { InitializeComponent(); this.Room = room; lblHeader.Text = room.Name; txtname.Text = room.Name; txtprice.Text = room.Price.ToString(); btnupdateroom.Clicked += Btnupdateroom_Clicked; }
public ActionResult CreateBooking() { var rooms = scheduleService.GetRooms(); var roomsModel = new RoomsModel() { Rooms = rooms }; return(View(roomsModel)); }
public ActionResult Index() { // get rooms var rooms = new RoomsModel(); rooms.Items = this.roomRepository.GetRooms(); // put rooms into view bag ViewBag.Rooms = rooms; return(View()); }
private async void AddRoomCommandExecuted() { if (SelectedOwner != null) { if (!string.IsNullOrWhiteSpace(Room)) { if (!string.IsNullOrWhiteSpace(Price)) { var admin = DbContext.Instance.GetAdministrator(); var room = new RoomsModel(); room.IdAdmin = admin.IdAdmin; room.IdOwner = SelectedOwner.IdOwner; room.Name = Room; room.Price = Convert.ToDouble(Price); var response = await client.Post <ListResponse, RoomsModel>(room, "room/insroom"); if (response != null) { if (response.Result && response.Count > 0) { await PopupNavigation.Instance.PopAllAsync(); MessagingCenter.Send <AddRoomAdminPopupViewModel>(this, "loadroom"); SnackSucces("Se registro correctamente", "KyA", Helpers.TypeSnackBar.Top); } else { SnackError(response.Message, "Error", Helpers.TypeSnackBar.Top); } } else { SnackError("Hubo un error intentelo mas tarde", "Error", Helpers.TypeSnackBar.Top); } } else { SnackError("Ingrese un precio", "Error", Helpers.TypeSnackBar.Top); } } else { SnackError("Ingrese un nombre de cuarto", "Error", Helpers.TypeSnackBar.Top); } } else { SnackError("seleccione un propietario", "Error", Helpers.TypeSnackBar.Top); } }
public ActionResult AddRoom(RoomsModel rm) { if (rm.ID == 0) { HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("Rooms", rm).Result; TempData["SuccessMessage"] = "Saved Successfully"; } else { HttpResponseMessage response = GlobalVariables.WebApiClient.PutAsJsonAsync("Rooms/" + rm.ID, rm).Result; TempData["SuccessMessage"] = "Update Successfully"; } return(RedirectToAction("ViewRoom")); }
/* * /// <summary> * /// 分页获取数据列表 * /// </summary> * public DataSet GetList(int PageSize,int PageIndex,string strWhere) * { * SqlParameter[] parameters = { * new SqlParameter("tblName", SqlDbType.VarChar, 255), * new SqlParameter("fldName", SqlDbType.VarChar, 255), * new SqlParameter("PageSize", SqlDbType.Int), * new SqlParameter("PageIndex", SqlDbType.Int), * new SqlParameter("IsReCount", SqlDbType.Bit), * new SqlParameter("OrderType", SqlDbType.Bit), * new SqlParameter("strWhere", SqlDbType.VarChar,1000), * }; * parameters[0].Value = "Rooms"; * parameters[1].Value = "ID"; * parameters[2].Value = PageSize; * parameters[3].Value = PageIndex; * parameters[4].Value = 0; * parameters[5].Value = 0; * parameters[6].Value = strWhere; * return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds"); * }*/ #endregion BasicMethod #region ExtensionMethod public List <RoomsModel> GetModelList(string sqlwhere) { var ds = GetList(sqlwhere); List <RoomsModel> list = null; var dt = ds.Tables[0]; list = new List <RoomsModel>(); RoomsModel p = null; foreach (DataRow item in dt.Rows) { p = GetModel(Convert.ToInt32(item["ID"].ToString())); list.Add(p); } return(list); }
public ActionResult RoomEdit(RoomsModel room, int[] StatusList) { Rooms rooms = room.ModelToEnity(); rooms.IsActive = true; _serviceRooms.Update(rooms); foreach (var item in StatusList) { RoomStatuses rs = new RoomStatuses(); rs.RoomId = rooms.Id; rs.StatusId = item; _serviceRoomStatuses.Insert(rs); } return(RedirectToAction("RoomList")); }
private void updateTag() { listBox1.Items.Clear(); listBox2.Items.Clear(); ActionResult roomsWithSubResult = formCtrl._getFormData(typeof(RoomsForASubjectModel), "RoomsForASubject"); if (roomsWithSubResult.State) { List <RoomsForASubjectModel> roomsWithSubResultList = roomsWithSubResult.Data; var SelectedRWSList = roomsWithSubResultList.Where(RWS => RWS.Subject == comboSub.SelectedItem.ToString() && RWS.Tag == comboTag.SelectedItem.ToString()).ToList(); SelectedRWSList.ForEach(RWS => listBox2.Items.Add(RWS.Room) ); ActionResult roomsResult = formCtrl._getFormData(typeof(RoomsModel), "Rooms"); if (roomsResult.State) { List <RoomsModel> roomsList = roomsResult.Data; for (int i = roomsList.Count - 1; i >= 0; --i) { RoomsModel room = roomsList[i]; SelectedRWSList.ForEach(selected => { if (selected.Room == room.RoomNumber) { roomsList.RemoveAt(i); } }); } roomsList.ForEach(room => { listBox1.Items.Add(room.RoomNumber); }); } dataGridView1.DataSource = roomsWithSubResult.Data; dataGridView1.Columns[1].HeaderCell.Value = "Tag"; dataGridView1.Columns[2].HeaderCell.Value = "Subject"; dataGridView1.Columns[3].HeaderCell.Value = "Room"; dataGridView1.Columns[0].Visible = false; dataGridView1.RowHeadersVisible = false; } }
private void updateLecturer() { listBox1.Items.Clear(); listBox2.Items.Clear(); ActionResult subgroupResult = formCtrl._getFormData(typeof(RoomsforaSubGroupModel), "RoomsforaSubGroup"); if (subgroupResult.State) { List <RoomsforaSubGroupModel> RoomsWithLecModalList = subgroupResult.Data; var SelectedRWTList = RoomsWithLecModalList.Where(RWT => RWT.SubGroup == comboBox1.SelectedItem.ToString()).ToList(); SelectedRWTList.ForEach(RWT => listBox2.Items.Add(RWT.Room) ); ActionResult roomsResult = formCtrl._getFormData(typeof(RoomsModel), "Rooms"); if (roomsResult.State) { List <RoomsModel> roomsList = roomsResult.Data; for (int i = roomsList.Count - 1; i >= 0; --i) { RoomsModel room = roomsList[i]; SelectedRWTList.ForEach(selected => { if (selected.Room == room.RoomNumber) { roomsList.RemoveAt(i); } }); } roomsList.ForEach(room => { listBox1.Items.Add(room.RoomNumber); }); } dataGridView1.DataSource = subgroupResult.Data; dataGridView1.Columns[1].HeaderCell.Value = "SubGroup"; dataGridView1.Columns[2].HeaderCell.Value = "Room"; dataGridView1.Columns[0].Visible = false; dataGridView1.RowHeadersVisible = false; } }
/// <summary> /// Overridden method to customly bind a string to a List<string> after splitting and sanitizing it /// </summary> /// <param name="controllerContext"></param> /// <param name="bindingContext"></param> /// <param name="propertyDescriptor"></param> protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor) { if (propertyDescriptor.Name == "Rooms") { RoomsModel model = (RoomsModel)bindingContext.Model; model.Rooms = BindingHelper.GetValue <string>(bindingContext, "Rooms.Rooms") .Trim() .Split(" ".ToCharArray()) .Distinct() .ToList(); } else { base.BindProperty(controllerContext, bindingContext, propertyDescriptor); } }
public ActionResult RoomInsert(RoomsModel roomModel, int[] StatusList) { Rooms room = roomModel.ModelToEnity(); room.IsActive = true; _serviceRooms.Insert(room); RoomStatuses roomstatus = new RoomStatuses(); foreach (var item in StatusList) { roomstatus.RoomId = room.Id; roomstatus.IsActive = true; roomstatus.StatusId = item; _serviceRoomStatuses.Insert(roomstatus); } return(RedirectToAction("RoomList")); }
private void btnUpdate_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtRoomNumber.Text)) { MessageBox.Show("Please Enter Room Number!", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtRoomNumber.Focus(); } else if (comboBuilding.SelectedIndex == 0) { MessageBox.Show("Please Select Building!", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); comboBuilding.Focus(); } else if (comboTag.SelectedIndex == 0) { MessageBox.Show("Please Select Tag!", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); comboTag.Focus(); } else if (string.IsNullOrEmpty(txtCapacity.Text)) { MessageBox.Show("Please Enter Capacity!", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtCapacity.Focus(); } else { ActionResult updateResult = formCtrl._updateFormData(new RoomsModel() { RoomId = roomId, RoomNumber = txtRoomNumber.Text.Trim(), Building = comboBuilding.SelectedItem.ToString(), Tag = comboTag.SelectedItem.ToString(), Capacity = Int32.Parse(txtCapacity.Text.Trim()), }); if (updateResult.State) { RoomsModel updateObj = updateResult.Data; MessageBox.Show("Room " + updateObj.RoomNumber + " Sucessfully Updated!", "Update Message", MessageBoxButtons.OK, MessageBoxIcon.Information); initForm(); } else { MessageBox.Show(updateResult.Data, "Update Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static Rooms ModelToEnity(this RoomsModel model, bool virtualActive = false) { Rooms entity = new Rooms() { BlockFloorId = model.BlockFloorId, Number = model.Number, RoomTypeId = model.RoomTypeId, Id = model.Id, IsActive = model.IsActive }; if (virtualActive) { entity.RoomSales = model.RoomSales; entity.RoomStatuses = model.RoomStatuses; entity.RoomType = model.RoomType; entity.BlockFloor = model.BlockFloor; } return(entity); }
public string Join(RoomsModel roomsModel) { if (!ModelState.IsValid) { Response.StatusCode = 400; // Bad Request return(Resources.Strings.CharRoomsError); } if (roomsModel.Rooms[0] == "") { return(""); } MvcApplication.Db.AddUser(roomsModel.Rooms, (string)Session["nick"]); roomsModel.Rooms.Clear(); roomsModel.Rooms.AddRange(MvcApplication.Db.GetRooms((string)Session["nick"])); MvcApplication.Pub.Publish(Resources.Internals.RoomsEventChannel, JsonConvert.SerializeObject(MvcApplication.Db.GetRooms())); return(JsonConvert.SerializeObject(roomsModel.Rooms)); }
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(); }
private async void SelectedRoomExecuted(RoomsModel obj) { await PopupNavigation.Instance.PushAsync(new Views.Administrator.Popup.UpdateRoomAdminPopup(obj)); }
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("所有酒店查询完毕"); }