Exemple #1
0
        public async Task <IActionResult> Edit(int id, [Bind("EntranceTestsProtocolId,AbiturientId,DataVidachi,FileName")] EntranceTestsProtocol entranceTestsProtocol)
        {
            if (id != entranceTestsProtocol.EntranceTestsProtocolId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(entranceTestsProtocol);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EntranceTestsProtocolExists(entranceTestsProtocol.EntranceTestsProtocolId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AbiturientId"] = new SelectList(_context.Abiturients, "AbiturientId", "AbiturientId", entranceTestsProtocol.AbiturientId);
            return(View(entranceTestsProtocol));
        }
Exemple #2
0
        // GET: EntranceTestsProtocols/Create
        public IActionResult Create()
        {
            ViewBag.Abiturients = _selectListRepository.GetSelectListAbiturients();

            var entranceTestsProtocol = new EntranceTestsProtocol {
                DataVidachi = DateTime.Now
            };

            return(View(entranceTestsProtocol));
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("EntranceTestsProtocolId,AbiturientId,DataVidachi,FileName")] EntranceTestsProtocol entranceTestsProtocol)
        {
            if (ModelState.IsValid)
            {
                _context.Add(entranceTestsProtocol);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AbiturientId"] = new SelectList(_context.Abiturients, "AbiturientId", "AbiturientId", entranceTestsProtocol.AbiturientId);
            return(View(entranceTestsProtocol));
        }
Exemple #4
0
        /// <summary>
        /// Создаёт pdf-файл протокола вступительных испытаний
        /// и возвращает путь к созданному файлу
        /// </summary>
        /// <param name="entranceTestsProtocol"></param>
        /// <returns></returns>
        public string GenerateEntranceTestsProtocol(EntranceTestsProtocol entranceTestsProtocol,
                                                    string userPhotoPath)
        {
            #region Free Spire.PDF
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            // Create one page
            PdfPageBase page = doc.Pages.Add();


            PrintShapka(page);



            page.Canvas.DrawString("ПРОТОКОЛ ВСТУПИТЕЛЬНЫХ ИСПЫТАНИЙ № ____",
                                   FontUtf_TNR_16_b,
                                   new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                   280, 150,
                                   new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));

            int y  = 190;
            int dy = 25;
            page.Canvas.DrawString("Фамилия: " + entranceTestsProtocol.Abiturient.AppUser.LastName,
                                   FontUtf_TNR_14,
                                   new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                   20, y,
                                   new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle));


            y += dy;
            page.Canvas.DrawString("Имя: " + entranceTestsProtocol.Abiturient.AppUser.FirstName,
                                   FontUtf_TNR_14,
                                   new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                   20, y,
                                   new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle));

            y += dy;
            page.Canvas.DrawString("Отчество: " + entranceTestsProtocol.Abiturient.AppUser.Patronymic,
                                   FontUtf_TNR_14,
                                   new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                   20, y,
                                   new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle));

            y += dy;
            page.Canvas.DrawString("Дата выдачи: " + entranceTestsProtocol.DataVidachi.ToString("dd.MM.yyyy"),
                                   FontUtf_TNR_14,
                                   new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                   20, y,
                                   new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle));



            //Draw the image
            if (!string.IsNullOrWhiteSpace(userPhotoPath))
            {
                PdfImage image        = PdfImage.FromFile(Path.Combine(_appEnvironment.WebRootPath, userPhotoPath));
                float    y_to_x_coeff = (float)image.Height / image.Width;
                page.Canvas.DrawImage(image, 40, 290, 100, 100 * y_to_x_coeff);
            }


            y += 50;
            page.Canvas.DrawString("и.о. Ответственный секретарь приёмной комиссии",
                                   FontUtf_TNR_14,
                                   new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                   160, y,
                                   new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle));

            y += 50;
            page.Canvas.DrawString("______________________________ В.П. Скворцов",
                                   FontUtf_TNR_14,
                                   new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                   160, y,
                                   new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle));



            y += 110;
            page.Canvas.DrawString("РЕЗУЛЬТАТЫ ВСТУПИТЕЛЬНЫХ ИСПЫТАНИЙ",
                                   FontUtf_TNR_14,
                                   new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                   280, y,
                                   new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));


            y += 40;
            page.Canvas.DrawString("Предмет",
                                   FontUtf_TNR_14,
                                   new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                   60, y,
                                   new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));



            page.Canvas.DrawString("Результаты вступительных",
                                   FontUtf_TNR_14,
                                   new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                   230, y - 7,
                                   new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));

            page.Canvas.DrawString("испытаний, баллов",
                                   FontUtf_TNR_14,
                                   new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                   230, y + 7,
                                   new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));



            page.Canvas.DrawString("Дата проведения",
                                   FontUtf_TNR_14,
                                   new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                   420, y - 7,
                                   new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));

            page.Canvas.DrawString("вступительных испытаний",
                                   FontUtf_TNR_14,
                                   new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                   420, y + 7,
                                   new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));


            int y_top_line = y - 15;
            page.Canvas.DrawLine(new PdfPen(new PdfRGBColor(0, 0, 0)), 20, y_top_line, 510, y_top_line);
            page.Canvas.DrawLine(new PdfPen(new PdfRGBColor(0, 0, 0)), 20, y + 15, 510, y + 15);



            for (int i = 0; i < (entranceTestsProtocol.Abiturient.EntranceTestRegistrationForms?.Count ?? 0); i++)
            {
                y += dy;

                page.Canvas.DrawString(entranceTestsProtocol.Abiturient.EntranceTestRegistrationForms[i].DisciplineName,
                                       FontUtf_TNR_14,
                                       new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                       25, y,
                                       new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle));

                page.Canvas.DrawString(entranceTestsProtocol.Abiturient.EntranceTestRegistrationForms[i].EntranceTestResult ?? "",
                                       FontUtf_TNR_14,
                                       new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                       230, y,
                                       new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));

                page.Canvas.DrawString(entranceTestsProtocol.Abiturient.EntranceTestRegistrationForms[i].Date.ToString("dd.MM.yyyy"),
                                       FontUtf_TNR_14,
                                       new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                       420, y,
                                       new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));

                page.Canvas.DrawLine(new PdfPen(new PdfRGBColor(0, 0, 0)), 20, y + 15, 510, y + 15);

                // Формируем вертикальные линии
                if (i == entranceTestsProtocol.Abiturient.EntranceTestRegistrationForms.Count - 1)
                {
                    page.Canvas.DrawLine(new PdfPen(new PdfRGBColor(0, 0, 0)), 20, y_top_line, 20, y + 15);
                    page.Canvas.DrawLine(new PdfPen(new PdfRGBColor(0, 0, 0)), 140, y_top_line, 140, y + 15);
                    page.Canvas.DrawLine(new PdfPen(new PdfRGBColor(0, 0, 0)), 330, y_top_line, 330, y + 15);
                    page.Canvas.DrawLine(new PdfPen(new PdfRGBColor(0, 0, 0)), 510, y_top_line, 510, y + 15);
                }
            }



            /////////////////////////////////////////////////////////////////////////////////////

            y += dy * 2;
            page.Canvas.DrawString("Члены комиссии",
                                   FontUtf_TNR_14,
                                   new PdfSolidBrush(new PdfRGBColor(0, 0, 0)),
                                   20, y,
                                   new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle));

            y += 10;
            for (int i = 0; i < 7; i++)
            {
                page.Canvas.DrawLine(new PdfPen(new PdfRGBColor(0, 0, 0)), 220, y, 320, y);
                page.Canvas.DrawLine(new PdfPen(new PdfRGBColor(0, 0, 0)), 350, y, 510, y);
                y += 15;
            }

            ///////////////////////////////////////////////////////////////////////////////////////


            string fileName = "EntranceTestsProtocol_" +
                              Guid.NewGuid().ToString() +
                              ".pdf";
            // путь к папке files
            string[] paths = { _appEnvironment.WebRootPath, "tmp", fileName };

            string pathToDirectory = Path.Combine(paths[0], paths[1]);
            if (!Directory.Exists(pathToDirectory))
            {
                Directory.CreateDirectory(pathToDirectory);
            }

            string path = Path.Combine(paths);
            doc.SaveToFile(path);
            doc.Close();


            // Если файл существует, удаляем его
            if (!string.IsNullOrWhiteSpace(entranceTestsProtocol.FileName))
            {
                string oldFilePath = Path.Combine(paths[0], entranceTestsProtocol.FileName);
                if (File.Exists(oldFilePath))
                {
                    File.Delete(oldFilePath);
                }
            }

            string newFileName = Path.Combine(paths[1], paths[2]);
            entranceTestsProtocol.FileName = newFileName;
            _context.SaveChanges();

            return(newFileName);

            #endregion
        }