Exemple #1
0
 private void btnAction_Click(object sender, EventArgs e)
 {
     _hotel.HotelName         = txtHotelName.Text;
     _hotel.HMSID             = txtHmsId.Text;
     _hotel.CheckAllotment    = cxCheckAllotment.Checked;
     _hotel.ContractValidTo   = dtContractValidTo.Value;
     _hotel.ContractValidFrom = dtContractValidFrom.Value;
     _hotel.CityId            = ((Models.City)cmbCities.SelectedItem).CityId;
     _hotel.MinCutOffDates    = string.IsNullOrEmpty(txtMinCutOffDates.Text)?0: int.Parse(txtMinCutOffDates.Text);
     if (cmbCities.SelectedItem == null)
     {
         MessageBox.Show("Select a city");
         return;
     }
     if (_hotel.HotelId == 0)
     {
         var initDate = new DateTime(2000, 1, 1);
         _hotel.CreatedDate = DateTime.UtcNow;
         hbo.Add(_hotel);
         BindDetailData();
     }
     else
     {
         hbo.Save();
     }
 }
Exemple #2
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            var dlg = new OpenFileDialog();

            dlg.ShowDialog();
            var path = dlg.FileName;

            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            var dicColumns = new Dictionary <string, int>();
            var csv        = new CsvReader(File.OpenText(path));

            csv.Read();
            csv.ReadHeader();
            var headerRow = csv.Context.HeaderRecord;

            for (var i = 0; i < headerRow.Count(); i++)
            {
                var name = headerRow[i];
                dicColumns.Add(name, i);
            }
            var records = csv.GetRecords <CsvRow>();

            foreach (var record in records)
            {
                var hbo = new BO.HotelBO();

                var hotel = hbo.GetHotel(record.HotelName);
                if (hotel == null)
                {
                    hotel = hbo.GetQueryable(null).SingleOrDefault(h => h.HMSID == record.Id);
                }
                if (hotel == null)
                {
                    hotel = new Models.Hotel();
                    hotel.CheckAllotment = true;
                }
                hotel.HotelName  = record.HotelName;
                hotel.HMSID      = record.Id;
                hotel.StarRating = decimal.Parse(record.StarRating);
                if (hotel.CityId == 43 || hotel.CityId == 0)//43 is unknown
                {
                    var cbo = new BO.CityBO();
                    var c   = cbo.GetQueryable().FirstOrDefault(f => f.CityCode == record.CityCode);
                    if (c == null)
                    {
                        c            = new Models.City();
                        c.CityCode   = record.CityCode;
                        c.CityName   = record.CityCode;
                        c.HasAirport = false;
                        cbo.Add(c);
                    }
                    hotel.CityId = c.CityId;
                }
                if (hotel.HotelId == 0)
                {
                    hbo.Add(hotel);
                }
                else
                {
                    hbo.Save();
                }
            }
            MessageBox.Show("Done");
        }