Esempio n. 1
0
        private string getHtmlData(MongoTools database, string collectionName)
        {
            string htmlData = "";

            if (collectionName == "drivers")
            {
                List <Driver> drivers = database.LoadAllDocuments <Driver>("drivers");

                int count = drivers.Count();

                DateTime dt                    = DateTime.Now;
                string   dayOfWeek             = dt.ToString("ddd");
                int      withWorkingBusesCount = drivers.Where(driver => database.LoadDocumentById <Bus>("buses", driver.BusId).IsWorking).Count();

                List <Driver> todayWorkingList  = drivers.Where(driver => driver.Schedule.Contains(dayOfWeek)).ToList();
                int           todayWorkingCount = todayWorkingList.Count();
                string        todayWorkingHtml  = "";

                foreach (Driver driver in todayWorkingList)
                {
                    Bus bus = database.LoadDocumentById <Bus>("buses", driver.BusId);
                    todayWorkingHtml += $"<div class=\"drivers__drivers\">{driver.LastName} {driver.Name}: <span>{bus.Number}</span></div>";
                }
                htmlData = $"<div class=\"data__block\"><span>Количество водителей: </span> {count}</div>" +
                           $"<div class=\"data__block\"><span>Количество водителей с работающими автобусами: </span> {withWorkingBusesCount}</div>" +
                           $"<div class=\"data__block\"><span>Сегодня работает водителей: </span> {todayWorkingCount}</div>" +
                           $"<div class=\"data__block\"><span>Сегодня работают: </span> {todayWorkingHtml}</div>";
            }
            else if (collectionName == "buses")
            {
                List <Bus> buses = database.LoadAllDocuments <Bus>("buses");

                int count        = buses.Count();
                int workingCount = buses.Where(bus => bus.IsWorking).Count();

                int    maxEndTime    = 0;
                string maxEndTimeStr = "";
                string driversList   = "";

                foreach (var bus in buses)
                {
                    List <Driver> drivers = database.LoadAllDocuments <Driver>("drivers");
                    Driver        driver  = drivers.Find(d => d.BusId == bus.Id);

                    if (driver != null)
                    {
                        ObjectId routeId = driver.RouteId;

                        Route route = database.LoadDocumentById <Route>("routes", routeId);

                        driversList += $"<div class='bus__drivers'><span>{bus.Number}</span>: {driver.LastName} {driver.Name}</div>";

                        string endTimeStr = route.EndTime;
                        int    endTime    = Convert.ToInt32(endTimeStr[0]) + Convert.ToInt32(endTimeStr[1]);

                        if (endTime > maxEndTime)
                        {
                            maxEndTime    = endTime;
                            maxEndTimeStr = endTimeStr;
                        }
                    }
                }
                htmlData = $"<div class=\"data__block\"><span>Количество автобусов:</span> {count}</div>" +
                           $"<div class=\"data__block\"><span>Количество сломанных автобусов:</span> {count - workingCount}</div>" +
                           $"<div class=\"data__block\"><span>Последний автобус приедет в:</span> {maxEndTimeStr}</div>" +
                           $"<div class=\"data__block\"><span>Список водителей:</span> {driversList}</div>";
            }
            else if (collectionName == "routes")
            {
                List <Route>  routes  = database.LoadAllDocuments <Route>("routes");
                List <Driver> drivers = database.LoadAllDocuments <Driver>("drivers");
                List <Bus>    buses   = database.LoadAllDocuments <Bus>("buses");

                int count = routes.Count();

                string busesByRoutesCountHtml = "";

                foreach (Route route in routes)
                {
                    List <Driver> driversByRoute      = drivers.Where(driver => driver.RouteId == route.Id).ToList();
                    int           driversByRouteCount = driversByRoute.Count;
                    if (driversByRouteCount > 0)
                    {
                        busesByRoutesCountHtml += $"<div class=\"bold tab\">Автобусы на маршруте {route.Number} ({driversByRouteCount} автобусов): </div>";

                        foreach (Driver driver in driversByRoute)
                        {
                            Bus bus = database.LoadDocumentById <Bus>("buses", driver.BusId);
                            busesByRoutesCountHtml += $"<div class=\"routes__drivers\">{driver.LastName}: <span>{bus.Number}</span></div>";
                        }
                    }
                }
                htmlData = $"<div class=\"data__block\"><span>Количество маршрутов:</span> {count}</div>" +
                           $"<div class=\"data__block\"><span>Маршруты:</span> {busesByRoutesCountHtml}</div>";
            }
            return(htmlData);
        }
Esempio n. 2
0
        private void saveDriverBtn_Click(object sender, EventArgs e)
        {
            if (NameInput.Text.Length > 0 &&
                LastNameInput.Text.Length > 0 &&
                GradeInput.SelectedIndex > -1 &&
                ExpInput.Text.Length > 0 &&
                BusInput.SelectedIndex > -1 &&
                RouteInput.SelectedIndex > -1
                )
            {
                var buses_doc  = database.LoadAllDocuments <Bus>("buses");
                var routes_doc = database.LoadAllDocuments <Route>("routes");

                var driver = database.LoadDocumentById <Driver>(collectionName, id);

                driver.Name       = NameInput.Text;
                driver.LastName   = LastNameInput.Text;
                driver.Patronymic = PatronymicInput.Text;
                driver.Grade      = GradeInput.SelectedIndex + 1;
                driver.Experience = Convert.ToInt32(ExpInput.Text);
                driver.BusId      = buses_doc[BusInput.SelectedIndex].Id;
                driver.RouteId    = routes_doc[RouteInput.SelectedIndex].Id;

                driver.Schedule.Clear();

                if (MonCheck.Checked)
                {
                    driver.Schedule.Add("Пн");
                }
                if (TuesCheck.Checked)
                {
                    driver.Schedule.Add("Вт");
                }
                if (WedCheck.Checked)
                {
                    driver.Schedule.Add("Ср");
                }
                if (ThursCheck.Checked)
                {
                    driver.Schedule.Add("Чт");
                }
                if (FriCheck.Checked)
                {
                    driver.Schedule.Add("Пт");
                }
                if (SatCheck.Checked)
                {
                    driver.Schedule.Add("Сб");
                }
                if (SunCheck.Checked)
                {
                    driver.Schedule.Add("Вс");
                }

                driver.Salary = (2000 + 100 * driver.Experience) / driver.Grade * driver.Schedule.Count * 4;

                database.UpdateDocument <Driver>("drivers", id, driver);
                this.Close();
            }
            else
            {
                saveDriverBtn.ForeColor = Color.FromName("red");
                saveDriverBtn.Text      = "Заполните обязательные поля и попробуйте снова!";
            }
        }