Ejemplo n.º 1
0
        public override void CreatePackage(string fileName)
        {
            // Извлекаем шаблон из вспомогательной сборки и создаем объект экселя
            var ef = ExcelFile.Load(DocumentTemplate.ExtractXls("AdmissionStatistic"));
            var ws = ef.Worksheets[0];

            // готовим шляпу
            string reportTitle = string.Empty;

            if (_isTodayStatistic)
            {
                reportTitle = string.Format("Статистика приёма за {0}",
                                            DateTime.Now.ToString("dd.MM.yyyy г."));
            }
            else
            {
                reportTitle = string.Format("Статистика приёма на {0}",
                                            DateTime.Now.ToString("dd.MM.yyyy г."));
            }
            ws.FindAndReplaceText("ReportTitle", reportTitle);

            ws.FindAndReplaceText("EducationForm",
                                  _educationForm.Name.BeginWithUpper() + " форма обучения");

            /****************************************************************************
             * ПОДГОТОВКА ДАННЫХ
             ***************************************************************************/
            // Копируем 7-ю строку как шаблон
            int i           = 7;
            var templateRow = ws.Rows[i];


            // Получить направления из конкурсных групп по по форме обучения
            var directions = (from compGroup in Session.DataModel.CompetitiveGroups
                              where compGroup.EducationForm.Id == _educationForm.Id &&
                              compGroup.Campaign.CampaignStatus.Id == 2
                              select compGroup.Direction).ToList();

            // Удалить дубликаты из коллекции, отсортировать по коду
            directions = directions.DistinctBy(d => d.Code).ToList();
            directions = directions.OrderBy(d => d.Code).ToList();

            int kcpBudgetTotal = 0, kcpExtrabudgetTotal = 0, kcpQuotaTotal = 0,
                kcpTotalTotal = 0, countBudgetFactTotal = 0, countBudgetOriginalTotal = 0,
                countExtrabudgetFactTotal = 0, countExtrabudgetOriginalTotal = 0,
                countQuotaFactTotal = 0, countQuotaOriginalTotal = 0,
                countTotalFactTotal = 0, countTotalOriginalTotal = 0;

            foreach (var direction in directions)
            {
                string directionName = string.Format("{0} {1}",
                                                     direction.Code, direction.Name);
                int kcpBudget = 0, kcpExtrabudget = 0, kcpQuota = 0,
                    kcpTotal = 0, countBudgetFact = 0, countBudgetOriginal = 0,
                    countExtrabudgetFact = 0, countExtrabudgetOriginal = 0,
                    countQuotaFact = 0, countQuotaOriginal = 0,
                    countTotalFact = 0, countTotalOriginal = 0;

                // Выбрать конкурсные группы по бюджету, направлению и форме обучения
                var competitiveGroupCollection = (from compGroup in direction.CompetitiveGroups
                                                  where compGroup.EducationForm.Id == _educationForm.Id &&
                                                  compGroup.FinanceSource.Id == 1 &&
                                                  compGroup.Campaign.CampaignStatus.Id == 2
                                                  select compGroup);
                // Если есть хоть одна такая, выдираем данные
                if (competitiveGroupCollection.Count() > 0)
                {
                    var currentCompetitiveGroup = competitiveGroupCollection.First();

                    // Заполняем КЦП
                    kcpBudget = currentCompetitiveGroup.PlaceCount ?? 0;
                    CalculateClaimCountInCompetitiveGroup(currentCompetitiveGroup,
                                                          out countBudgetFact, out countBudgetOriginal);
                }

                // Выбрать конкурсные группы по внебюджету, направлению и форме обучения
                competitiveGroupCollection = (from compGroup in direction.CompetitiveGroups
                                              where compGroup.EducationForm.Id == _educationForm.Id &&
                                              compGroup.FinanceSource.Id == 2 &&
                                              compGroup.Campaign.CampaignStatus.Id == 2
                                              select compGroup);
                // Если есть хоть одна такая, выдираем данные
                if (competitiveGroupCollection.Count() > 0)
                {
                    var currentCompetitiveGroup = competitiveGroupCollection.First();

                    // Заполняем КЦП
                    kcpExtrabudget = currentCompetitiveGroup.PlaceCount ?? 0;
                    CalculateClaimCountInCompetitiveGroup(currentCompetitiveGroup,
                                                          out countExtrabudgetFact, out countExtrabudgetOriginal);
                }

                // Выбрать конкурсные группы по льготе, направлению и форме обучения
                competitiveGroupCollection = (from compGroup in direction.CompetitiveGroups
                                              where compGroup.EducationForm.Id == _educationForm.Id &&
                                              compGroup.FinanceSource.Id == 3 &&
                                              compGroup.Campaign.CampaignStatus.Id == 2
                                              select compGroup);
                // Если есть хоть одна такая, выдираем данные
                if (competitiveGroupCollection.Count() > 0)
                {
                    var currentCompetitiveGroup = competitiveGroupCollection.First();

                    // Заполняем КЦП
                    kcpQuota = currentCompetitiveGroup.PlaceCount ?? 0;
                    CalculateClaimCountInCompetitiveGroup(currentCompetitiveGroup,
                                                          out countQuotaFact, out countQuotaOriginal);
                }

                // Считаем итоговые значения
                kcpTotal       = kcpBudget + kcpExtrabudget;
                countTotalFact = countBudgetFact + countExtrabudgetFact +
                                 countQuotaFact;
                countTotalOriginal = countBudgetOriginal + countExtrabudgetOriginal +
                                     countQuotaOriginal;

                // Совсем итоговые
                kcpBudgetTotal                += kcpBudget;
                kcpExtrabudgetTotal           += kcpExtrabudget;
                kcpQuotaTotal                 += kcpQuota;
                kcpTotalTotal                 += kcpTotal;
                countBudgetFactTotal          += countBudgetFact;
                countBudgetOriginalTotal      += countBudgetOriginal;
                countExtrabudgetFactTotal     += countExtrabudgetFact;
                countExtrabudgetOriginalTotal += countExtrabudgetOriginal;
                countQuotaFactTotal           += countQuotaFact;
                countQuotaOriginalTotal       += countQuotaOriginal;
                countTotalFactTotal           += countTotalFact;
                countTotalOriginalTotal       += countTotalOriginal;


                /***************************************************************************
                 * ДАННЫЕ ЗАГРУЖЕНЫ, ЗАНИМАЕМСЯ ЗАГРУЗКОЙ В ДОКУМЕНТ
                 **************************************************************************/

                // Подготовка строки
                ws.Rows.InsertCopy(i, templateRow);
                var currentRow = ws.Rows[i];
                i++;

                // Вставляем данные
                currentRow.Cells[0].Value  = directionName;
                currentRow.Cells[1].Value  = kcpBudget;
                currentRow.Cells[2].Value  = kcpQuota;
                currentRow.Cells[3].Value  = kcpExtrabudget;
                currentRow.Cells[4].Value  = kcpTotal;
                currentRow.Cells[5].Value  = countBudgetFact;
                currentRow.Cells[6].Value  = countBudgetOriginal;
                currentRow.Cells[7].Value  = countQuotaFact;
                currentRow.Cells[8].Value  = countQuotaOriginal;
                currentRow.Cells[9].Value  = countExtrabudgetFact;
                currentRow.Cells[10].Value = countExtrabudgetOriginal;
                currentRow.Cells[11].Value = countTotalFact;
                currentRow.Cells[12].Value = countTotalOriginal;
            }

            // Вставляем самые итоговые итоги
            ws.Rows.InsertCopy(i, templateRow);
            var totalRow = ws.Rows[i];

            totalRow.Cells[0].Value  = "ИТОГО";
            totalRow.Cells[1].Value  = kcpBudgetTotal;
            totalRow.Cells[2].Value  = kcpQuotaTotal;
            totalRow.Cells[3].Value  = kcpExtrabudgetTotal;
            totalRow.Cells[4].Value  = kcpTotalTotal;
            totalRow.Cells[5].Value  = countBudgetFactTotal;
            totalRow.Cells[6].Value  = countBudgetOriginalTotal;
            totalRow.Cells[7].Value  = countQuotaFactTotal;
            totalRow.Cells[8].Value  = countQuotaOriginalTotal;
            totalRow.Cells[9].Value  = countExtrabudgetFactTotal;
            totalRow.Cells[10].Value = countExtrabudgetOriginalTotal;
            totalRow.Cells[11].Value = countTotalFactTotal;
            totalRow.Cells[12].Value = countTotalOriginalTotal;

            ef.Save(fileName);
        }
Ejemplo n.º 2
0
        public override void CreatePackage(string fileName)
        {
            // Извлекаем шаблон из вспомогательной сборки и создаем объект экселя
            string         templateName = "GeneralizedEntrantList";
            ExcelFile      ef           = ExcelFile.Load(DocumentTemplate.ExtractXls(templateName));
            ExcelWorksheet worksheet    = ef.Worksheets[0];

            // Оформляем шляпу
            int rowIndex, columnIndex;

            if (worksheet.Cells.FindText("[ReportTitle]", true, true, out rowIndex, out columnIndex))
            {
                worksheet.Cells[rowIndex, columnIndex].Value = string.Format("Список абитуриентов на {0}",
                                                                             DateTime.Now.ToString("dd.MM.yyyy г."));
            }

            worksheet.FindAndReplaceText("EducationFormName", _educationForm.Name.BeginWithUpper() + " форма обучения");

            // Заполняем таблицу

            // Копируем 6-ую строку как шаблон
            int i           = 6;
            var templateRow = worksheet.Rows[i];

            // Выбираем заявления со статусом новое или принято и фильтруем по форме обучения
            var notPreparedClaims = Session.DataModel.Claims.ToList();
            var actualClaims      = notPreparedClaims.
                                    Where(c => c.ClaimStatusId == 1 || c.ClaimStatusId == 2 || c.ClaimStatus.Id == 3).
                                    Where(c => c.EducationForm.Id == _educationForm.Id);

            // Сортируем заявления
            actualClaims = actualClaims.OrderBy(c => c.FinanceSource.SortNumber).ThenByDescending(c => c.TotalScore);

            foreach (var claim in actualClaims)
            {
                // Подготовка данных
                var    entrant     = claim.Entrants.First();
                string entrantName = string.Format("{0} {1} {2}",
                                                   entrant.LastName, entrant.FirstName, entrant.Patronymic);
                string docType         = claim.IsOriginal ? "ориг." : "копия";
                string finSource       = claim.FinanceSource != null ? claim.FinanceSource.Name : string.Empty;
                string fisrtDirection  = claim.FirstDirection != null ? claim.FirstDirection.ShortName : string.Empty;
                string secondDirection = claim.SecondDirection != null ? claim.SecondDirection.ShortName : string.Empty;
                string thirdDirection  = claim.ThirdDirection != null ? claim.ThirdDirection.ShortName : string.Empty;
                string examType        = string.Empty;
                if (claim.EgeDocuments.Count > 0)
                {
                    examType = "ЕГЭ";
                }
                else
                {
                    if (claim.EntranceTestResults.Count > 0)
                    {
                        examType = "СЭ";
                    }
                }
                if (claim.EgeDocuments.Count > 0 && claim.EntranceTestResults.Count > 0)
                {
                    examType = "ЕГЭ/СЭ";
                }
                if (claim.EgeDocuments.Count == 0 && claim.EntranceTestResults.Count == 0)
                {
                    examType = "аттестат";
                }

                double totalScore = 0.0;

                if (claim.ClaimConditions.First().CompetitiveGroup.EducationLevel.Id == 2)
                {
                    if (claim.SchoolCertificateDocuments.Count > 0)
                    {
                        totalScore = claim.SchoolCertificateDocuments.First().MiddleMark;
                    }
                }
                else
                {
                    totalScore = Convert.ToDouble(claim.TotalScore);
                }

                string phone = string.Format("{0};{1}", entrant.Phone, entrant.MobilePhone);

                // Подготовка строки
                worksheet.Rows.InsertCopy(i, templateRow);
                var currentRow = worksheet.Rows[i];
                i++;

                // Вставка данных в документ
                currentRow.Cells[0].Value = entrantName;
                currentRow.Cells[1].Value = docType;
                currentRow.Cells[2].Value = finSource;
                currentRow.Cells[3].Value = fisrtDirection;
                currentRow.Cells[4].Value = secondDirection;
                currentRow.Cells[5].Value = thirdDirection;
                currentRow.Cells[6].Value = examType;
                currentRow.Cells[7].Value = totalScore;
                currentRow.Cells[8].Value = phone;
            }

            // Сохраняем документ
            ef.Save(fileName);
        }
Ejemplo n.º 3
0
        public override void CreatePackage(string fileName)
        {
            // Извлекаем шаблон из вспомогательной сборки и создаем объект экселя
            var ef = ExcelFile.Load(DocumentTemplate.ExtractXls("EnrollmentProtocol"));
            var ws = ef.Worksheets[0];

            // готовим шляпу
            string title = string.Format("Протокол зачисления приёмной комиссии № {0} от {1}",
                                         _protocol.Number, ((DateTime)_protocol.Date).ToString("dd.MM.yyyy г."));

            ws.FindAndReplaceText("Title", title);

            string enrollString = string.Format("Зачислить в число студентов РИИ АлтГТУ с {0}",
                                                ((DateTime)_protocol.TrainingBeginDate).ToString("dd.MM.yyyy г."));

            ws.FindAndReplaceText("EnrollmentString", enrollString);

            string cgString = string.Format("на направление подготовки (бакалавриат) ВО {0}\"{1}\" ({2}) ({3} форма обучения)",
                                            _protocol.Direction.Code, _protocol.Direction.Name, _protocol.CompetitiveGroup.EducationProgramType.Name,
                                            _protocol.EducationForm.Name);

            ws.FindAndReplaceText("CompetitiveGroupString", cgString);

            if (_protocol.EnrollmentClaims.Where(ec => ec.Claim != null).Count() > 1)
            {
                ws.FindAndReplaceText("NextEntrantsString", "следующих поступающих согласно списку:");
            }
            else
            {
                ws.FindAndReplaceText("NextEntrantsString", "следующего поступающего:");
            }
            // Шаблоны строк
            var tableStringTemplate     = ws.Rows[9];
            var statisticStringTemplate = ws.Rows[11];
            int i = 9;

            // ПОДГОТОВКА ДАННЫХ В ТАБЛИЦУ
            int j = 1;

            // Получаем заявления, сортируем по фамилии
            var claims = (from es in _protocol.EnrollmentClaims
                          where es.Claim != null
                          select es.Claim).ToList();

            claims = claims.OrderBy(c => c.Person.FullName).ToList();
            foreach (var claim in claims)
            {
                // Вставляем в таблицу
                ws.Rows.InsertCopy(i, tableStringTemplate);
                var currentRow = ws.Rows[i];
                currentRow.Cells[0].Value = j;
                currentRow.Cells[1].Value = claim.Person.FullName;
                currentRow.Cells[2].Value = claim.GetExamResultBySubjectId(3);
                currentRow.Cells[3].Value = claim.GetExamResultBySubjectId(2);
                currentRow.Cells[4].Value = claim.GetExamResultBySubjectId(1);
                currentRow.Cells[5].Value = claim.IndividualAchievementsScore;
                currentRow.Cells[6].Value = claim.TotalScore;
                currentRow.Cells[7].Value = claim.MiddleMark;
                currentRow.Cells[8].Value = claim.FinanceSource.Name;
                currentRow.Cells[9].Value = claim.Number;
                i++;
                j++;
            }

            // Как всегда костыль: скрываем лишнюю ебаную строку
            ws.Rows[i].Hidden = true;

            ef.Save(fileName);
        }
        public override void CreatePackage(string fileName)
        {
            // Извлекаем шаблон из вспомогательной сборки и создаем объект экселя
            var ef = ExcelFile.Load(DocumentTemplate.ExtractXls("InnerExaminationCheckProtocol"));
            var ws = ef.Worksheets[0];

            // Заполнение шляпы
            string protocolName = string.Format("№ {0} от {1}",
                                                _protocol.Number, ((DateTime)_protocol.Date).ToString("dd MMMM yyyy г."));

            ws.FindAndReplaceText("ProtocolName", protocolName);

            string subjectString = string.Format("по предмету: {0}",
                                                 _protocol.EntranceTests.First().ExamSubject.Name);

            ws.FindAndReplaceText("SubjectString", subjectString);

            string examinationDate = string.Format("Дата экзамена: {0}",
                                                   ((DateTime)_protocol.EntranceTests.First().ExaminationDate).ToString("dd MMMM yyyy г."));

            ws.FindAndReplaceText("ExaminationDate", examinationDate);

            // Подготовка данных
            // Получаем результаты по протоколу
            var results = new List <EntranceTestResult>();

            foreach (var exam in _protocol.EntranceTests)
            {
                foreach (var result in exam.EntranceTestResult)
                {
                    if (result.Claim != null)
                    {
                        results.Add(result);
                    }
                }
            }

            // Сортируем результаты по ФИО абитуриента
            results = results.OrderBy(res => res.Claim.Person.FullName).ToList();

            // Выгружаем в документ строки таблицы
            int i = 9;
            int j = 1;
            var tableStringTemplate = ws.Rows[i];

            foreach (var result in results)
            {
                ws.Rows.InsertCopy(i, tableStringTemplate);
                var currentRow = ws.Rows[i];
                currentRow.Cells[0].Value = j;
                currentRow.Cells[1].Value = result.Claim.Person.FullName;
                currentRow.Cells[2].Value = result.Value > 0 ? result.Value.ToString() : "н/я";
                i++;
                j++;
            }

            // Костыль
            ws.Rows[i].Hidden = true;

            ef.Save(fileName);
        }
Ejemplo n.º 5
0
        public override void CreatePackage(string fileName)
        {
            // Извлекаем шаблон из вспомогательной сборки и создаем объект экселя
            var ef = ExcelFile.Load(DocumentTemplate.ExtractXls("PublicEntrantList"));
            var ws = ef.Worksheets[0];

            // готовим шляпу
            string reportTitle = string.Format("Списки поступающих на {0} - {1} форма обучения",
                                               DateTime.Now.ToString("dd.MM.yyyy г."), _educationForm.Name);

            ws.FindAndReplaceText("ReportTitle", reportTitle);

            // Подготовка данных
            var directionNameTemplate = ws.Rows[0];
            var headTableTemplate     = ws.Rows[2];
            var itemTableTemplate     = ws.Rows[3];
            var i = 7;
            // Получаем список направлений
            var directions = (from compGroup in Session.DataModel.CompetitiveGroups
                              where compGroup.EducationForm.Id == _educationForm.Id &&
                              compGroup.Campaign.CampaignStatus.Id == 2
                              orderby compGroup.EducationLevel.Id, compGroup.Direction.Code
                              select compGroup.Direction).ToList();

            // Удалить дубликаты из коллекции, отсортировать по коду
            directions = directions.DistinctBy(d => d.Code).ToList();

            foreach (var direction in directions)
            {
                // Прописываем направление
                ws.Rows.InsertCopy(i, directionNameTemplate);
                ws.Rows[i].Cells[0].Value = string.Format("{0} {1}",
                                                          direction.Code, direction.Name);
                i += 2;

                ws.Rows.InsertCopy(i, headTableTemplate);
                i++;
                int j = 1;

                // Получаем конкурсные группы по направлению и форме обучения
                var actualCompetitiveGroups = (from compGroup in direction.CompetitiveGroups
                                               where compGroup.EducationForm.Id == _educationForm.Id &&
                                               compGroup.Campaign.CampaignStatus.Id == 2
                                               orderby compGroup.FinanceSource.SortNumber ascending
                                               select compGroup).ToList();
                int flag = i;
                foreach (var compGroup in actualCompetitiveGroups)
                {
                    // Получить список условий приёма
                    var conditions = (from cond in compGroup.ClaimConditions
                                      where cond.Claim != null &&
                                      (cond.Claim.ClaimStatus.Id == 1 || cond.Claim.ClaimStatus.Id == 2)
                                      select cond).OrderByDescending(c => c.Claim.TotalScore).ToList();
                    foreach (var condition in conditions)
                    {
                        ws.Rows.InsertCopy(i, itemTableTemplate);
                        var currentRow = ws.Rows[i];
                        currentRow.Cells[0].Value = j;
                        currentRow.Cells[1].Value = condition.Claim.Person.FullName;
                        currentRow.Cells[2].Value = condition.Claim.Number;
                        currentRow.Cells[3].Value = condition.Claim.IsOriginal ? "оригинал" : "копия";
                        currentRow.Cells[4].Value = condition.CompetitiveGroup.FinanceSource.Name;
                        currentRow.Cells[5].Value = condition.Priority;
                        currentRow.Cells[6].Value = condition.Claim.TotalScore;
                        i++;
                        j++;
                    }
                }

                // КОСТЫЛЬ: Если нет абитуриентов по направлению, то скрываем ко всем херам
                if (flag == i)
                {
                    ws.Rows[i - 3].Hidden = true;
                    ws.Rows[i - 2].Hidden = true;
                    ws.Rows[i - 1].Hidden = true;
                    ws.Rows[i].Hidden     = true;
                    continue;
                }
                i += 2;
            }

            // Скрываем шаблоны
            directionNameTemplate.Hidden = true;
            headTableTemplate.Hidden     = true;
            itemTableTemplate.Hidden     = true;
            ws.Rows[1].Hidden            = true;
            ws.Rows[4].Hidden            = true;

            ef.Save(fileName);
        }