private void LoadProjects()
 {
     IProjectService projectService = new ProjectService();
     List<Core.Project> activeProjects = projectService.GetAllActiveProjects();
     activeProjects.Insert(0, new Core.Project() { Id = 0, ProjectName = "- Select Project -" });
     comProjects.DataSource = activeProjects;
     comProjects.DisplayMember = "ProjectName";
     comProjects.ValueMember = "Id";
 }
        public ActionResult Create()
        {
            IVehicleService vehicleServcie = new VehicleService();
            IProjectService projectService = new ProjectService();

            RunningchartModel model = new RunningchartModel();
            model.BillDate = DateTime.Now;
            model.Vehicles = ModelMapper.GetVehicleModelList(vehicleServcie.GetAllVehicles());
            model.Lubricants = ModelMapper.GetLubricantModelList(vehicleServcie.GetAllLubricantTypes());
            model.Projects = ModelMapper.GetProjectModelList(projectService.GetAllActiveProjects());

            ViewBag.Mode = "create";
            return View(model);
        }
        public ActionResult Create(RunningchartModel model)
        {
            try
            {
                Runningchart runningChart = ModelMapper.GetRunningchartFromRunningchartModel(model);
                runningChart.EnteredBy = (Session[SessionKeys.UserInfo] as UserModel).Id; // Set DEO
                int chartId = runningchartService.AddRunningchart(runningChart);
                return RedirectToAction("index", new { lastChartId = chartId });
            }
            catch
            {
                IVehicleService vehicleServcie = new VehicleService();
                IProjectService projectService = new ProjectService();

                model.RunningchartId = runningchartService.GetNextRunningchartId();
                model.Vehicles = ModelMapper.GetVehicleModelList(vehicleServcie.GetAllVehicles());
                model.Lubricants = ModelMapper.GetLubricantModelList(vehicleServcie.GetAllLubricantTypes());
                model.Projects = ModelMapper.GetProjectModelList(projectService.GetAllActiveProjects());

                return View(model);
            }
        }
        private RunningchartModel GetRunningchartModel(int runningChartId)
        {
            IVehicleService vehicleServcie = new VehicleService();
            IProjectService projectService = new ProjectService();
            IPumpstationService pumpstationService = new PumpstationService();
            var chart = runningchartService.GetRunningChart(runningChartId);
            var model = ModelMapper.GetRunningchartModel(chart);
            model.Vehicles = ModelMapper.GetVehicleModelList(vehicleServcie.GetAllVehicles());
            model.Lubricants = ModelMapper.GetLubricantModelList(vehicleServcie.GetAllLubricantTypes());
            model.Projects = ModelMapper.GetProjectModelList(projectService.GetAllActiveProjects());
            model.Pumpstations = ModelMapper.GetPumpStationModelList(pumpstationService.GetAllPumpstations());
            model.VehicleRentalTypes = new List<VehicleRentalTypeModel>()
            {
                new VehicleRentalTypeModel() { Id = (int)RentalType.Company, RentalTypeName = StringEnum.GetEnumStringValue(RentalType.Company) },
                new VehicleRentalTypeModel() { Id = (int)RentalType.CompanyHired, RentalTypeName = StringEnum.GetEnumStringValue(RentalType.CompanyHired) },
                new VehicleRentalTypeModel() { Id = (int)RentalType.Hired, RentalTypeName = StringEnum.GetEnumStringValue(RentalType.Hired) }
            }; // Not worth to do a DB call since this is very static

            return model;
        }
        public ActionResult Print(int id)
        {
            IVehicleService vehicleServcie = new VehicleService();
            IProjectService projectService = new ProjectService();
            IPumpstationService pumpstationService = new PumpstationService();
            var pumpstations = pumpstationService.GetAllPumpstations();
            var projects = projectService.GetAllActiveProjects();
            var lubricants = vehicleServcie.GetAllLubricantTypes();
            var vehicles = vehicleServcie.GetAllVehicles();
            var chart = runningchartService.GetRunningChart(id);

            dsRunningchart ds = new dsRunningchart();
            DataTable runningchartTable = ds.Tables["Runningchart"].Clone();
            DataTable runningchartDetailsTable = ds.Tables["RunningchartDetails"].Clone();
            DataTable runningchartPumpstationsTable = ds.Tables["RunningchartPumpstation"].Clone();
            DataTable runningchartLubricantsTable = ds.Tables["RunningchartLubricant"].Clone();

            PopulateRunningchartTable(chart, runningchartTable, vehicles);
            PopulateRunningchartDetailsTable(chart.RunningchartDetails, runningchartDetailsTable, projects);
            PopulateRunningchartPumpstationTable(chart.RunningchartPumpstation, runningchartPumpstationsTable, pumpstations);
            PopulateRunningchartLubricantTable(chart.RunningchartLubricants, runningchartLubricantsTable, pumpstations, lubricants);

            ReportClass reportClass = new ReportClass();
            reportClass.FileName = Server.MapPath("~/Reports/Runningchart.rpt");
            reportClass.Load();
            reportClass.SummaryInfo.ReportTitle = "Running Chart";
            reportClass.Database.Tables["Runningchart"].SetDataSource(runningchartTable);
            reportClass.Database.Tables["RunningchartDetails"].SetDataSource(runningchartDetailsTable);
            reportClass.Database.Tables["RunningchartPumpstation"].SetDataSource(runningchartPumpstationsTable);
            reportClass.Database.Tables["RunningchartLubricant"].SetDataSource(runningchartLubricantsTable);

            Stream compStream = reportClass.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            return File(compStream, "application/pdf");
        }
        public ActionResult PoulateChartItems(bool isAddingNewItem, bool isVehicle)
        {
            RunningchartModel model = new RunningchartModel();
            List<ChartItemModel> existingChartItems = new List<ChartItemModel>();
            UpdateModel<List<ChartItemModel>>(existingChartItems);

            IProjectService projectService = new ProjectService();
            model.Projects = ModelMapper.GetProjectModelList(projectService.GetAllActiveProjects());
            model.VehicleRentalTypes = new List<VehicleRentalTypeModel>()
            {
                new VehicleRentalTypeModel() { Id = (int)RentalType.Company, RentalTypeName = StringEnum.GetEnumStringValue(RentalType.Company) },
                new VehicleRentalTypeModel() { Id = (int)RentalType.CompanyHired, RentalTypeName = StringEnum.GetEnumStringValue(RentalType.CompanyHired) },
                new VehicleRentalTypeModel() { Id = (int)RentalType.Hired, RentalTypeName = StringEnum.GetEnumStringValue(RentalType.Hired) }
            }; // Not worth to do a DB call since this is very static

            model.SelectedChartItems = new List<ChartItemModel>();
            model.isVehicle = isVehicle;

            // Add existing chart items
            foreach (var item in existingChartItems)
            {
                if (!item.IsRemoving)
                {
                    model.SelectedChartItems.Add(item);
                }
            }

            // Add new chart item
            if (isAddingNewItem)
            {
                ChartItemModel newChartItem = new ChartItemModel()
                {
                    StartTime = string.Empty,
                    EndTime = string.Empty,
                    SelectedProjectId = 0,
                    SelectedProjectManager = string.Empty
                };

                if (existingChartItems.Count > 0)
                {
                    newChartItem.SelectedProjectId = existingChartItems[0].SelectedProjectId;
                    newChartItem.SelectedProjectManager = existingChartItems[0].SelectedProjectManager;
                    newChartItem.SelectedRentalTypeId = existingChartItems[0].SelectedRentalTypeId;
                }

                model.SelectedChartItems.Add(newChartItem);
            }

            return PartialView("_ChartItems", model);
        }