Beispiel #1
0
        private void CreateRelated(bool isSelector)
        {
            TourModuleBase module = Module;

            if (module != null)
            {
                SelectorControl Selecter;
                if (isSelector)
                {
                    Selecter = LoadControl("/Modules/TourManagement/Admin/RelatedTour.ascx") as SelectorControl;
                }
                else
                {
                    Selecter = LoadControl(module.OverviewPath) as SelectorControl;
                }
                if (Selecter == null)
                {
                    return;
                }
                if (isSelector)
                {
                    Selecter.ID = "Selector";
                }
                else
                {
                    Selecter.ID = "Selector" + module.Section.Id;
                }
                Selecter.Module = module;
                plhConfig.Controls.Add(Selecter);
            }
        }
Beispiel #2
0
        private void CreateSelector(Section section, bool isSelector)
        {
            TourModuleBase module = _moduleLoader.GetModuleFromSection(section) as TourModuleBase;

            if (module != null)
            {
                SelectorControl Selecter;
                if (isSelector)
                {
                    Selecter = LoadControl(module.SelecterPath) as SelectorControl;
                }
                else
                {
                    Selecter = LoadControl(module.OverviewPath) as SelectorControl;
                }
                if (Selecter == null)
                {
                    return;
                }
                if (isSelector)
                {
                    Selecter.ID = "Selector";
                }
                else
                {
                    Selecter.ID = "Selector" + section.Id;
                }
                Selecter.Module = module;
                plhConfig.Controls.Add(Selecter);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            section = Module.Section.Connections["Listing"] as Section;
            if (section != null)
            {
                _path = UrlHelper.GetUrlFromSection(section);
            }
            else
            {
                _path = UrlHelper.GetUrlFromNode(Module.Section.Node);
                return;
            }
            _listModule = ModuleHelper.GetModuleFromSection(section, PageEngine.Container) as TourModuleBase;
            if (_listModule == null)
            {
                return;
            }
            if (!IsPostBack)
            {
                if (!HasCachedOutput)
                {
                    #region -- Xử lý cây --

                    // Lấy toàn bộ Root Location
                    IList listLocations = Module.LocationGetRoot();

                    // Đối với mỗi root Location, thêm vào tree (nếu có data)
                    // Nếu root có con, cho phép populate on demand
                    foreach (Location rootLocation in listLocations)
                    {
                        if (!_listModule.CheckDataExists(rootLocation))
                        {
                            continue;
                        }
                        TreeNode rootNode = new TreeNode(rootLocation.Name, rootLocation.Id.ToString());
                        //if (rootLocation.Id == 1)
                        //{
                        // Đoạn này xử lý cứng để kịp thời gian
                        //TODO: Fix triệt để
                        //    rootNode.NavigateUrl = "/10/view.aspx?locationId=1";
                        //}
                        //else
                        //{
                        if (section != null)
                        {
                            rootNode.NavigateUrl = _listModule.GetLinkFromLocation(section, rootLocation);
                        }
                        else
                        {
                            rootNode.NavigateUrl = string.Format("{0}/list?locationId={1}", _path, rootLocation.Id);
                        }
                        //}
                        if (rootLocation.Children.Count > 0)
                        {
                            rootNode.PopulateOnDemand = false;
                        }
                        treeViewLocation.Nodes.Add(rootNode);

                        // Expand root
                        BuildChildNode(rootLocation, rootNode);
                        rootNode.Expanded = true;
                    }

                    #endregion

                    #region -- Xử lý khi có tham số locationId truyền vào --

                    if (Request.QueryString["LocationId"] != null)
                    {
                        try
                        {
                            // Lấy Location truyền vào
                            Location location =
                                Module.LocationGetById(Convert.ToInt32(Request.QueryString["LocationId"]));

                            List <Location> locationList = new List <Location>();
                            // Khởi tạo cây phả hệ của địa điểm truyền vào
                            while (location != null)
                            {
                                locationList.Add(location);
                                location = location.Parent;
                            }

                            TreeNode currentNode = null;
                            // Xử lý toàn bộ cây phả hệ
                            while (locationList.Count > 0)
                            {
                                // Xử lý từ tổ tiên trở xuống
                                Location current = locationList[locationList.Count - 1];
                                // Nếu CurrentNode không phải null, tức là đây không phải là ông tổ
                                if (currentNode != null)
                                {
                                    // Xử lý từng con của CurrentNode để xác định node ứng với current Location
                                    foreach (TreeNode node in currentNode.ChildNodes)
                                    {
                                        if (node.Value == current.Id.ToString())
                                        {
                                            node.Expand();
                                            currentNode = node;
                                        }
                                    }
                                }
                                else
                                {
                                    // Nếu currentLocation thuộc dạng ông tổ, tìm ngay trên các node gốc
                                    foreach (TreeNode node in treeViewLocation.Nodes)
                                    {
                                        if (node.Value == current.Id.ToString())
                                        {
                                            node.Expand();
                                            currentNode = node;
                                        }
                                    }
                                }
                                locationList.Remove(current);
                            }
                        }
                        catch
                        {
                            throw new Exception("Bad Request");
                        }
                        return;
                    }

                    #endregion

                    #region -- Xử lý khi có tham số locationId truyền vào --

                    if (PageEngine.GlobalVar.ContainsKey("Location"))
                    {
                        try
                        {
                            // Lấy Location truyền vào
                            Location location = (Location)PageEngine.GlobalVar["Location"];

                            List <Location> locationList = new List <Location>();
                            // Khởi tạo cây phả hệ của địa điểm truyền vào
                            while (location != null)
                            {
                                locationList.Add(location);
                                location = location.Parent;
                            }

                            TreeNode currentNode = null;
                            // Xử lý toàn bộ cây phả hệ
                            while (locationList.Count > 0)
                            {
                                // Xử lý từ tổ tiên trở xuống
                                Location current = locationList[locationList.Count - 1];
                                // Nếu CurrentNode không phải null, tức là đây không phải là ông tổ
                                if (currentNode != null)
                                {
                                    // Xử lý từng con của CurrentNode để xác định node ứng với current Location
                                    foreach (TreeNode node in currentNode.ChildNodes)
                                    {
                                        if (node.Value == current.Id.ToString())
                                        {
                                            node.Expand();
                                            currentNode = node;
                                        }
                                    }
                                }
                                else
                                {
                                    // Nếu currentLocation thuộc dạng ông tổ, tìm ngay trên các node gốc
                                    foreach (TreeNode node in treeViewLocation.Nodes)
                                    {
                                        if (node.Value == current.Id.ToString())
                                        {
                                            node.Expand();
                                            currentNode = node;
                                        }
                                    }
                                }
                                locationList.Remove(current);
                            }
                        }
                        catch
                        {
                            throw new Exception("Bad Request");
                        }
                    }

                    #endregion
                }
            }
        }
Beispiel #4
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");
        }
Beispiel #5
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            Tour      tour  = Module.TourGetById(_tourId);
            DataTable table = new DataTable();

            #region -- CREATE TABLE --
            // Tạo 10 cột, trong đó có 2 cột tiêu đề, các cột còn lại là giá từ 1-8 người
            table.Columns.Add("Service", typeof(string));
            table.Columns.Add("Detail", typeof(string));
            table.Columns.Add("1", typeof(double));
            table.Columns.Add("2", typeof(double));
            table.Columns.Add("3", typeof(double));
            table.Columns.Add("4", typeof(double));
            table.Columns.Add("5", typeof(double));
            table.Columns.Add("6", typeof(double));
            table.Columns.Add("7", typeof(double));
            table.Columns.Add("8", typeof(double));
            #endregion

            #region -- Xuất dữ liệu từ các module sang table theo định dạng như trên --
            if (Module.HotelSection != null)
            {
                TourModuleBase hotelModule =
                    _moduleLoader.GetModuleFromSection(Module.HotelSection) as TourModuleBase;
                if (hotelModule != null)
                {
                    hotelModule.ExportTourConfigToDataTable(_tourId, table);
                }
            }

            if (Module.RestaurantSection != null)
            {
                TourModuleBase hotelModule =
                    _moduleLoader.GetModuleFromSection(Module.RestaurantSection) as TourModuleBase;
                if (hotelModule != null)
                {
                    hotelModule.ExportTourConfigToDataTable(_tourId, table);
                }
            }

            if (Module.TransportSection != null)
            {
                TourModuleBase hotelModule =
                    _moduleLoader.GetModuleFromSection(Module.TransportSection) as TourModuleBase;
                if (hotelModule != null)
                {
                    hotelModule.ExportTourConfigToDataTable(_tourId, table);
                }
            }

            if (Module.LandscapeSection != null)
            {
                TourModuleBase hotelModule =
                    _moduleLoader.GetModuleFromSection(Module.LandscapeSection) as TourModuleBase;
                if (hotelModule != null)
                {
                    hotelModule.ExportTourConfigToDataTable(_tourId, table);
                }
            }

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

            if (Module.BoatSection != null)
            {
                TourModuleBase hotelModule =
                    _moduleLoader.GetModuleFromSection(Module.BoatSection) as TourModuleBase;
                if (hotelModule != null)
                {
                    hotelModule.ExportTourConfigToDataTable(_tourId, table);
                }
            }
            #endregion

            #region -- Cột tổng giá net--
            DataRow totalRow = table.NewRow();
            totalRow[1] = "TOTAL NET";
            IList tourPrices = Module.TourPriceGetByTour(tour);
            foreach (TourPrice price in tourPrices)
            {
                totalRow[price.NumberOfCustomers + TourManagementModule.TITLECOLUMN - 1] = price.TotalNet;
            }
            table.Rows.Add(totalRow);
            #endregion

            //int currentRow = table.Rows.Count - 1;

            // Lấy giá sale đã tính ở bảng ra rồi xuất sang table
            #region -- Giá sale --
            IList     roleList = Module.RoleGetAll();
            Hashtable rolemap  = new Hashtable(roleList.Count);
            foreach (Role role in roleList)
            {
                DataRow row = table.NewRow();
                row[1] = role.Name;
                table.Rows.Add(row);
                rolemap.Add(role.Id, table.Rows.Count - 1);
            }

            IList tourSalePrices = Module.TourSalePriceGetByTour(tour);
            foreach (TourSalePrice saleprice in tourSalePrices)
            {
                table.Rows[Convert.ToInt32(rolemap[saleprice.RoleId])][
                    saleprice.NumberOfCustomers + TourManagementModule.TITLECOLUMN - 1] = saleprice.Total;
            }
            #endregion

            // Cuối cùng xuất ra excel
            DataExports.ExportToExcel(Context, table, tour.Name, UrlHelper.ConvertToUrl(tour.Name) + ".xls");
        }