private void btnAction_Click(object sender, EventArgs e)
        {
            _rt          = rtbo.GetRecord(_rt.RecordId);
            _rt.RoomName = txtRoomName.Text;
            var newAllotment = int.Parse(txtDefaultAllotment.Text);

            if (_rt.RecordId == 0)
            {
                _rt.DefaultAllotment = newAllotment;
                rtbo.Add(_rt);
            }
            else
            {
                if (newAllotment < _rt.DefaultAllotment)
                {
                    var arbo = new BO.AllotmentRecordBO();
                    arbo.ExecuteSql(@"DELETE FROM AllotmentRecords WHERE AllotmentRoomTypeId={0} AND
                        CurrentAllotment>={1}", new object[] { _rt.RecordId, newAllotment });
                }
                _rt.DefaultAllotment   = newAllotment;
                _rt.IgnoreThisRoomType = cxIgnoreThis.Checked;
                rtbo.Save();
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Beispiel #2
0
        void CrawlSingleHotel(Models.Hotel h)
        {
            _wk.ReportProgress(0, "Crawl hotel " + h.HotelName);
            objBrowse._inputDatas["HMSID"] = h.HMSID;
            objBrowse.ExecuteAction(false);
            objGetWebRoomTypes.ExecuteAction(false);
            //Find out what room types are available
            var crTypes = h.ContractRooms.ToList();
            var opthtml = objGetWebRoomTypes._ReturnDataCollection["cmbRoomTypeInnerHtml"] as string;
            var rtdoc   = new HtmlAgilityPack.HtmlDocument();

            rtdoc.LoadHtml(opthtml);
            var opts = rtdoc.DocumentNode.SelectNodes("//option");
            var rts  = opts.Select(o => o.InnerText).ToList();

            foreach (var cr in crTypes)
            {
                if (!opts.Any(x => x.InnerText == cr.RoomName))
                {
                    var editor = new frmRoomTypeReMatch(cr, rts);
                    if (editor.ShowDialog() == DialogResult.Cancel)
                    {
                        return;
                    }
                }
            }
            var validDate = h.ContractValidTo;

            if (validDate < DateTime.Now.Date)
            {
                return;
            }
            //here is the limit of HMS
            if (validDate > DateTime.Today.AddDays(365))
            {
                validDate = DateTime.Today.AddDays(365);
            }
            var fromDate = h.ContractValidFrom;
            var minDt    = DateTime.UtcNow.Date.AddDays(h.MinCutOffDates);

            if (fromDate < minDt)
            {
                fromDate = minDt;
            }
            //reload room types to update
            var crbo = new BO.ContractRoomBO();

            crTypes = crbo.GetQueryable(h.HotelId).ToList();
            objEnterData._inputDatas["ToDate"]   = validDate.ToString("MM/dd/yyyy");
            objEnterData._inputDatas["FromDate"] = fromDate.ToString("MM/dd/yyyy");
            objEnterData.ExecuteAction(false);
            foreach (var cr in crTypes)
            {
                objClickCmbRoomTypes.ExecuteAction(false);
                /* We don't want to get text into XPath because it can causes err*/
                var cmbXPath = objGetWebRoomTypes._ActionData.ElementLabels.FirstOrDefault().XPath;
                cmbXPath += "/option";
                var elmOption = Modules.BrowserSupport.FindElementInCollection(cmbXPath, cr.RoomName);
                elmOption.Click();
                objClick.ExecuteAction(false);
                objGetHtml.ExecuteAction(false);
                var html     = objGetHtml._ReturnDataCollection["PageHtml"] as string;
                var analyzer = new Modules.AllotmentAnalyzer(true);
                var records  = analyzer.AnalyzeData(html);
                foreach (var record in records)
                {
                    var rbo   = new BO.AllotmentRoomTypeBO();
                    var rtype = rbo.GetRecord(h.HotelId, record.RoomName);
                    if (rtype == null)
                    {
                        rtype                  = new Models.AllotmentRoomType();
                        rtype.RoomName         = record.RoomName;
                        rtype.HotelId          = h.HotelId;
                        rtype.DefaultAllotment = 1;
                        rbo.Add(rtype);
                    }
                    if (record.Allotment >= rtype.DefaultAllotment)
                    {
                        continue;
                    }
                    var arbo = new BO.AllotmentRecordBO();
                    //while record date is 12:00:00AM, saving in db will change it to 00:00:00
                    //so we never get the record. need to reset all to zero here
                    var dt = record.Date;
                    dt = new DateTime(dt.Year, dt.Month, dt.Day);

                    if (record.Allotment < rtype.DefaultAllotment)
                    {
                        var r = arbo.GetRecord(dt, rtype.RecordId);
                        if (r == null)
                        {
                            r = new Models.AllotmentRecord();
                            r.CurrentAllotment    = record.Allotment;
                            r.AllotmentDate       = dt;
                            r.Acknowledged        = false;
                            r.AllotmentRoomTypeId = rtype.RecordId;
                            arbo.Add(r);
                        }
                        else
                        {
                            //REcord existed, may be acknowledged may be not. Just leave it there
                            if (record.Allotment < r.CurrentAllotment)
                            {
                                //Need to notify us again
                                r.Acknowledged = false;
                                arbo.Save();
                            }
                        }
                    }
                }
            }
            // var path = @"C:\Users\Thuy Tran\Documents\AllDocs\Disposable\Test\allotment" + h.HotelId + "-" + DateTime.Now.ToString("mm-dd-yyyy-hh-mm-ss") + ".txt";
            //System.IO.File.WriteAllText(path, html);
        }