Esempio n. 1
0
        public static void IsValid(TourPrice tourPrice, int?Id = null)
        {
            Exception ex             = new Exception("Validate excption");
            var       inputDateRange = new DateRange(tourPrice.StartDate, tourPrice.EndDate);
            var       tour           = TourDAL.GetById(tourPrice.TourId);

            if (tour == null)
            {
                ex.Data.Add("Tour", "Không tìm thấy tour");
            }

            var tourPrices = TourPriceDAL.Find(tp => (tp.TourId == tour.Id) && (!Id.HasValue || tp.Id != Id));

            foreach (var x in tourPrices)
            {
                var sourceDateRange = new DateRange(x.StartDate, x.EndDate);
                if (!inputDateRange.BeforeOrAfter(sourceDateRange))
                {
                    ex.Data.Add("Thời gian", "Thời gian bắt đầu và kết thúc không hợp lệ");
                    break;
                }
            }
            if (ex.Data.Count > 0)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        private TourPrice addNewTourPrice()
        {
            DateTime start_date = dtpStart_date.Value;
            DateTime end_date   = dtpEnd_date.Value;
            decimal  price      = 0;

            try
            {
                price = decimal.Parse(tbTourPrice.Text.Trim());
            }
            catch
            {
                MessageBox.Show("Giá tiền không hợp lệ!");
                tbTourPrice.Clear();
                tbTourPrice.Focus();
                return(null);
            }
            if (!checkDateTime(start_date, end_date))
            {
                MessageBox.Show("Ngày hết hạn không được nhỏ hơn ngày áp dụng!");
                return(null);
            }
            tourPrice            = new DTO.TourPrice();
            tourPrice.price      = price;
            tourPrice.start_date = start_date;
            tourPrice.end_date   = end_date;
            return(tourPrice);
        }
Esempio n. 3
0
 private void btnTourPriceEdit_Click(object sender, EventArgs e)
 {
     if (TourPriceMode != OperationType.Edit)
     {
         LoadTourPriceMode(OperationType.Edit);
         return;
     }
     try
     {
         var tourPrice = new TourPrice(
             Int32.Parse(tbTourID.Text),
             dtpTourPriceStartDate.Value,
             dtpTourPriceEndDate.Value,
             Int32.Parse(tbTourPriceValue.Text),
             tbTourPriceNote.Text
             );
         tourPrice.Id = Int32.Parse(tbTourPriceID.Text);
         TourPriceBLL.Update(tourPrice);
         MessageBox.Show($"Sửa giá tour cho tour {tbTourID.Text} thành công");
         LoadTourPriceMode(OperationType.View);
         Thread threadLoadTourPriceDataGridView = new Thread(new ThreadStart(() => LoadTourPriceDataGridView()));
         threadLoadTourPriceDataGridView.Start();
     }
     catch (Exception ex)
     {
         GUIExtensionMethod.HandleError(ex);
     }
 }
Esempio n. 4
0
 private void btnTourPriceAdd_Click(object sender, EventArgs e)
 {
     if (TourPriceMode != OperationType.Add)
     {
         LoadTourPriceMode(OperationType.Add);
         return;
     }
     try
     {
         var tourPrice = new TourPrice(
             Int32.Parse(tbTourID.Text),
             dtpTourPriceStartDate.Value,
             dtpTourPriceEndDate.Value,
             Int32.Parse(tbTourPriceValue.Text.Equals("") ? "-1" : tbTourPriceValue.Text),
             tbTourPriceNote.Text
             );
         TourPriceBLL.Add(tourPrice);
         MessageBox.Show($"Thêm giá tour cho tour {tbTourID.Text} thành công");
         LoadTourPriceMode(OperationType.View);
         Thread threadLoadTourPriceDataGridView = new Thread(new ThreadStart(() => LoadTourPriceDataGridView()));
         threadLoadTourPriceDataGridView.Start();
     }
     catch (FormatException)
     {
         MessageBox.Show("Giá tiền không được để số");
     }
     catch (Exception ex)
     {
         GUIExtensionMethod.HandleError(ex);
     }
 }
Esempio n. 5
0
        public void LoadTourPriceForm(TourPrice data)
        {
            tbTourPriceID.Text    = data.Id.ToString();
            tbTourPriceValue.Text = data.Price.ToString();
            tbTourPriceNote.Text  = data.Note?.ToString();

            dtpTourPriceStartDate.Value = data.StartDate;
            dtpTourPriceEndDate.Value   = data.EndDate;
        }
Esempio n. 6
0
 public static void Update(TourPrice tourPrice)
 {
     try
     {
         IsValid(tourPrice, tourPrice.Id);
         TourPriceDAL.Update(tourPrice);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 7
0
 public static void Add(TourPrice tourPrice)
 {
     try
     {
         IsValid(tourPrice);
         TourPriceDAL.Add(tourPrice);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public async Task <IActionResult> Update([FromBody] TourPrice tourPrice)
        {
            try
            {
                _logger.LogInformation("Try to update tourPrice: {0}", tourPrice.Id);
                _context.TourPrices.Update(tourPrice);
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(BadRequest(e.Message));
            }

            _logger.LogInformation("TourPrice was updated by user: {0}", User.Identity.Name);
            return(Ok("Info was updated successfully"));
        }
Esempio n. 9
0
        protected void btnCalculate_Click(object sender, EventArgs e)
        {
            Tour tour = Module.TourGetById(_tourId);

            // Danh sách các vai trò
            IList list = Module.RoleGetAll();

            for (int numberOfCustomer = 1; numberOfCustomer <= 8; numberOfCustomer++)
            {
                //Tính giá net cho từng số lượng khách hàng
                TourPrice tourPrice = Module.TourPriceGetByTourAndCustomers(tour, numberOfCustomer);

                //  Tạo một bảng giá sale, số lượng phần tử tối đa bằng số role
                Hashtable tourSalePrices = new Hashtable(list.Count);

                // Tạo một datatable
                DataTable table = new DataTable();
                table.Columns.Add("Service", typeof(string));
                table.Columns.Add("Detail", typeof(string));
                table.Columns.Add("Unit price", typeof(double));
                table.Columns.Add("Total", typeof(double));
                // Tạo một loạt các cột trong data table = role
                // Tạo dữ liệu trong hashtable theo id
                foreach (Role role in list)
                {
                    table.Columns.Add(role.Name, typeof(double));
                    // Thêm vào bảng băm các giá bán tương ứng
                    tourSalePrices.Add(role.Id, Module.TourSalePriceGet(tour, numberOfCustomer, role.Id));
                }

                int currentRow = 0;
                if (Module.HotelSection != null)
                {
                    TourModuleBase hotelModule =
                        _moduleLoader.GetModuleFromSection(Module.HotelSection) as TourModuleBase;
                    if (hotelModule != null)
                    {
                        hotelModule.ExportTourConfigToDataTable(_tourId, table, list, numberOfCustomer);
                    }
                    double[] hotel = Calculate(table, currentRow, table.Rows.Count);
                    tourPrice.TourNetHotelPrice = hotel[3];
                    int ii = 4;
                    foreach (Role role in list)
                    {
                        ((TourSalePrice)tourSalePrices[role.Id]).HotelPrice = hotel[ii];
                        ii++;
                    }
                    currentRow = table.Rows.Count - 1;
                }

                if (Module.RestaurantSection != null)
                {
                    TourModuleBase restaurantModule =
                        _moduleLoader.GetModuleFromSection(Module.RestaurantSection) as TourModuleBase;
                    if (restaurantModule != null)
                    {
                        restaurantModule.ExportTourConfigToDataTable(_tourId, table, list, numberOfCustomer);
                    }
                    double[] meal = Calculate(table, currentRow, table.Rows.Count);
                    tourPrice.TourNetMealPrice = meal[3];
                    int ii = 4;
                    foreach (Role role in list)
                    {
                        ((TourSalePrice)tourSalePrices[role.Id]).MealPrice = meal[ii];
                        ii++;
                    }
                    currentRow = table.Rows.Count - 1;
                }

                if (Module.TransportSection != null)
                {
                    TourModuleBase transportModule =
                        _moduleLoader.GetModuleFromSection(Module.TransportSection) as TourModuleBase;
                    if (transportModule != null)
                    {
                        transportModule.ExportTourConfigToDataTable(_tourId, table, list, numberOfCustomer);
                    }
                    double[] transport = Calculate(table, currentRow, table.Rows.Count);
                    tourPrice.TourNetTransportPrice = transport[3];
                    int ii = 4;
                    foreach (Role role in list)
                    {
                        ((TourSalePrice)tourSalePrices[role.Id]).TransportPrice = transport[ii];
                        ii++;
                    }
                    currentRow = table.Rows.Count - 1;
                }

                if (Module.LandscapeSection != null)
                {
                    TourModuleBase landscapeModule =
                        _moduleLoader.GetModuleFromSection(Module.LandscapeSection) as TourModuleBase;
                    if (landscapeModule != null)
                    {
                        landscapeModule.ExportTourConfigToDataTable(_tourId, table, list, numberOfCustomer);
                    }
                    double[] entrancefee = Calculate(table, currentRow, table.Rows.Count);
                    tourPrice.TourNetEntranceFeePrice = entrancefee[3];
                    int ii = 4;
                    foreach (Role role in list)
                    {
                        ((TourSalePrice)tourSalePrices[role.Id]).EntranceFeePrice = entrancefee[ii];
                        ii++;
                    }
                    currentRow = table.Rows.Count - 1;
                }

                if (Module.GuideSection != null)
                {
                    TourModuleBase guideModule =
                        _moduleLoader.GetModuleFromSection(Module.GuideSection) as TourModuleBase;
                    if (guideModule != null)
                    {
                        guideModule.ExportTourConfigToDataTable(_tourId, table, list, numberOfCustomer);
                    }

                    double[] guide = Calculate(table, currentRow, table.Rows.Count);
                    tourPrice.TourNetGuidesPrice = guide[3];
                    int ii = 4;
                    foreach (Role role in list)
                    {
                        ((TourSalePrice)tourSalePrices[role.Id]).GuidePrice = guide[ii];
                        ii++;
                    }
                    currentRow = table.Rows.Count - 1;
                }

                if (Module.BoatSection != null)
                {
                    TourModuleBase boatModule = _moduleLoader.GetModuleFromSection(Module.BoatSection) as TourModuleBase;
                    if (boatModule != null)
                    {
                        boatModule.ExportTourConfigToDataTable(_tourId, table, list, numberOfCustomer);
                    }
                    double[] boat = Calculate(table, currentRow, table.Rows.Count);
                    tourPrice.TourNetBoatPrice = boat[3];
                    int ii = 4;
                    foreach (Role role in list)
                    {
                        ((TourSalePrice)tourSalePrices[role.Id]).BoatPrice  = boat[ii];
                        ((TourSalePrice)tourSalePrices[role.Id]).OtherPrice = 0;
                        ii++;
                    }
                    //currentRow = table.Rows.Count - 1;
                }

                tourPrice.TourNetOtherPrice = 0;

                DataRow  row   = table.NewRow();
                double[] total = new double[table.Columns.Count];
                foreach (DataRow datarow in table.Rows)
                {
                    for (int ii = 2; ii < table.Columns.Count; ii++)
                    {
                        if (!string.IsNullOrEmpty(datarow[ii].ToString()))
                        {
                            total[ii] += Convert.ToDouble(datarow[ii]);
                        }
                    }
                }
                tourPrice.TotalNet = total[3];

                int jj = 4;
                foreach (Role role in list)
                {
                    ((TourSalePrice)tourSalePrices[role.Id]).Total             = total[jj];
                    ((TourSalePrice)tourSalePrices[role.Id]).NumberOfCustomers = numberOfCustomer;
                    ((TourSalePrice)tourSalePrices[role.Id]).LastCalculateDate = DateTime.Now;
                    ((TourSalePrice)tourSalePrices[role.Id]).ExtraFee          = 0;
                    ((TourSalePrice)tourSalePrices[role.Id]).Tour   = tour;
                    ((TourSalePrice)tourSalePrices[role.Id]).RoleId = role.Id;
                    Module.SaveOrUpdate((TourSalePrice)tourSalePrices[role.Id]);
                    jj++;
                }

                for (int ii = 2; ii < table.Columns.Count; ii++)
                {
                    row[ii] = total[ii];
                }
                table.Rows.Add(row);
                tourPrice.NumberOfCustomers = numberOfCustomer;
                tourPrice.LastCaculateDate  = DateTime.Now;
                tourPrice.ExtraFee          = 0;
                tourPrice.Tour = tour;
                Module.SaveOrUpdate(tourPrice);
            }
            ShowMessage("Calculating completed!");
            //DataExports.ExportToExcel(Context, table, "Report", "report.xls");
        }
Esempio n. 10
0
 public void update(TourPrice price)
 {
     _unitOfWork.TourPriceRepository.Update(price);
     _unitOfWork.Save();
 }
Esempio n. 11
0
 public int addWithoutId(TourPrice tourprice)
 {
     _unitOfWork.TourPriceRepository.Insert(tourprice);
     _unitOfWork.Save();
     return(tourprice.id);
 }
Esempio n. 12
0
 public void add(TourPrice tourprice)
 {
     _unitOfWork.TourPriceRepository.Insert(tourprice);
     _unitOfWork.Save();
 }
Esempio n. 13
0
 public void SaveOrUpdate(TourPrice tourPrice)
 {
     _commonDao.SaveOrUpdateObject(tourPrice);
 }