Exemplo n.º 1
0
        private static Dictionary <string, int> GetQuestionPoints(ExcelQuestion selectedQuestion, ExcelProfile selectedProfile, ExcelDocument selectedDocument)
        {
            Dictionary <string, int> points = new Dictionary <string, int>();
            var answersList     = selectedProfile.GetProfileAnswers();
            int openAnswerCount = 0;

            foreach (var answerItem in answersList)
            {
                if (answerItem == "другое")
                {
                    var currentResults = selectedDocument.AnswerListContent.Where(a => a.ProfileNum == selectedProfile.Id && a.QuestionNum == selectedQuestion.Id).ToList();
                    foreach (var resultItem in currentResults)
                    {
                        var a = resultItem.GetAnswers(selectedProfile.Type).Except(answersList).ToList();
                        if (a.Count != 0)
                        {
                            openAnswerCount++;
                        }
                    }
                    points.Add(answerItem, openAnswerCount);
                }
                else
                {
                    var countCurrentAnswers = selectedDocument.AnswerListContent.Where(a => a.ProfileNum == selectedProfile.Id && a.QuestionNum == selectedQuestion.Id && a.GetAnswers(selectedProfile.Type).Contains(answerItem)).Count();
                    points.Add(answerItem, countCurrentAnswers);
                }
            }

            return(points);
        }
Exemplo n.º 2
0
        public static Dictionary <string, int> GetOpenAnswers(ExcelQuestion selectedQuestion, ExcelProfile selectedProfile, ExcelDocument selectedDocument)
        {
            Dictionary <string, int> points = new Dictionary <string, int>();

            var currentResults = selectedDocument.AnswerListContent.Where(a => a.ProfileNum == selectedProfile.Id && a.QuestionNum == selectedQuestion.Id).ToList();

            foreach (var resultItem in currentResults)
            {
                var openAnswers = resultItem.GetAnswers(selectedProfile.Type).Except(selectedProfile.GetProfileAnswers()).ToList();
                if (openAnswers.Count != 0)
                {
                    foreach (var item in openAnswers)
                    {
                        if (points.ContainsKey(item))
                        {
                            points[item]++;
                        }
                        else
                        {
                            points.Add(item, 1);
                        }
                    }
                }
            }

            return(points);
        }
Exemplo n.º 3
0
        public static Tuple <Dictionary <string, int>, int, int> GetQuestionInfo(ExcelQuestion selectedQuestion, ExcelProfile selectedProfile, ExcelDocument selectedDocument)
        {
            var points = GetQuestionPoints(selectedQuestion, selectedProfile, selectedDocument);

            int questionedCount = selectedDocument.AnswerListContent.Where(a => a.ProfileNum == selectedProfile.Id && a.QuestionNum == selectedQuestion.Id).Count();
            int respondedCount  = selectedDocument.AnswerListContent.Where(a => a.ProfileNum == selectedProfile.Id && a.QuestionNum == selectedQuestion.Id && a.Answer != "").Count();

            return(new Tuple <Dictionary <string, int>, int, int>(points, respondedCount, questionedCount));
        }
Exemplo n.º 4
0
        private void saveQuestionInfoBtn_Click(object sender, EventArgs e)
        {
            DataGridViewRow selectedDataGridRow = saveQuestionInfoBtn.Tag as DataGridViewRow;
            ExcelQuestion   selectedQuestion    = selectedDataGridRow.Cells["question"].Value as ExcelQuestion;
            ExcelProfile    selectedProfile     = mainTab.SelectedTab.Tag as ExcelProfile;

            string filePath = CommonService.SaveFilePath("*.xlsx|*.xlsx", "Вопрос " + selectedQuestion.Id + " результаты");

            if (filePath != null)
            {
                DataManipulationService.SaveQuestionInfoExcel(selectedQuestion, selectedProfile, Document, filePath);
            }
        }
        public static void SaveQuestionInfoExcel(ExcelQuestion excelQuestion, ExcelProfile excelProfile, ExcelDocument document, string filePath)
        {
            using (ExcelPackage excelPackage = new ExcelPackage())
            {
                var questionInfo    = ProccesingDataService.GetQuestionInfo(excelQuestion, excelProfile, document);
                var points          = questionInfo.Item1;
                var respondedCount  = questionInfo.Item2;
                var questionedCount = questionInfo.Item3;

                excelPackage.Workbook.Properties.Author  = "User";
                excelPackage.Workbook.Properties.Title   = excelQuestion.GetForSeries();
                excelPackage.Workbook.Properties.Created = DateTime.Now;

                ExcelWorksheet infoSheet = excelPackage.Workbook.Worksheets.Add("Результаты");

                int rowInfoNumber = 1;

                infoSheet.Cells[rowInfoNumber, 1].Value = excelProfile.Name;
                rowInfoNumber++;

                int column = WriteRowExcel(new string[] { "Номер вопроса", "Вопрос", "Число ответивших", "Число прошедших" }, points.Keys.ToArray(), infoSheet, 1, rowInfoNumber);
                if (points.ContainsKey("другое"))
                {
                    var questionOpenInfo = ProccesingDataService.GetOpenInfo(excelQuestion, excelProfile, document);;
                    var openPoints       = questionOpenInfo.Item1;
                    WriteRowExcel(new string[] { }, openPoints.Keys.ToArray(), infoSheet, column, rowInfoNumber);
                }
                rowInfoNumber++;

                //-----------------------------------------------
                string[] pointsValue = points.Values.Select(x => x.ToString()).ToArray();
                column = WriteRowExcel(new string[] { excelQuestion.Id.ToString(), excelQuestion.GetForSeries(), respondedCount.ToString(), questionedCount.ToString() }, pointsValue, infoSheet, 1, rowInfoNumber);
                if (points.ContainsKey("другое"))
                {
                    var      questionOpenInfo = ProccesingDataService.GetOpenInfo(excelQuestion, excelProfile, document);;
                    var      openPoints       = questionOpenInfo.Item1;
                    string[] openPointsValue  = openPoints.Values.Select(x => x.ToString()).ToArray();
                    column = WriteRowExcel(new string[] { }, openPointsValue, infoSheet, column, rowInfoNumber);
                }


                infoSheet.Cells[infoSheet.Dimension.Address].AutoFitColumns();
                infoSheet.Column(2).Width          = 125;
                infoSheet.Column(2).Style.WrapText = true;
                FileInfo fi = new FileInfo(filePath);

                excelPackage.SaveAs(fi);
            }
        }
Exemplo n.º 6
0
        private void openAnswerInfoBtn_Click(object sender, EventArgs e)
        {
            DataGridViewRow selectedDataGridRow = saveQuestionInfoBtn.Tag as DataGridViewRow;
            ExcelQuestion   selectedQuestion    = selectedDataGridRow.Cells["question"].Value as ExcelQuestion;
            ExcelProfile    selectedProfile     = mainTab.SelectedTab.Tag as ExcelProfile;

            Dictionary <ExcelQuestion, Tuple <Dictionary <string, int>, int, int> > questionInfoMap = new Dictionary <ExcelQuestion, Tuple <Dictionary <string, int>, int, int> >();

            questionInfoMap.Add(selectedQuestion, ProccesingDataService.GetOpenInfo(selectedQuestion, selectedProfile, Document));

            using (QuestionInfoForm qif = new QuestionInfoForm())
            {
                qif.QuestionInfoMap = questionInfoMap;
                qif.ShowDialog();
            }
        }
Exemplo n.º 7
0
        public static List <ExcelQuestion> GetQuestionsEP(string pathToExcelFile, string sheetName)
        {
            List <ExcelQuestion> excelProfile = new List <ExcelQuestion>();

            var ids         = GetColumn(1, 1, pathToExcelFile, sheetName);
            var question    = GetColumn(1, 2, pathToExcelFile, sheetName);
            var leftLimits  = GetColumn(1, 3, pathToExcelFile, sheetName);
            var rightLimits = GetColumn(1, 4, pathToExcelFile, sheetName);

            if (leftLimits.Count == 0 || rightLimits.Count == 0)
            {
                leftLimits  = null;
                rightLimits = null;
            }

            if (ids.Count == question.Count)
            {
                for (int i = 0; i < ids.Count(); i++)
                {
                    int id;
                    try
                    {
                        id = Convert.ToInt32(ids[i]);
                    }
                    catch (Exception)
                    {
                        throw new Exception("Первый столбец в листе \"" + sheetName + "\" должен содержать только цифры.");
                    }
                    ExcelQuestion profile;
                    if (leftLimits == null && rightLimits == null)
                    {
                        profile = new ExcelQuestion()
                        {
                            Id         = id,
                            Content    = GetClearString(question[i].ToString()),
                            LeftLimit  = null,
                            RightLimit = null
                        };
                    }
                    else
                    {
                        if (leftLimits.Count != rightLimits.Count || leftLimits.Count != ids.Count || rightLimits.Count != ids.Count)
                        {
                            throw new Exception("Лист \"" + sheetName + "\" не соответствует формату.");
                        }
                        profile = new ExcelQuestion()
                        {
                            Id         = id,
                            Content    = GetClearString(question[i].ToString()),
                            LeftLimit  = GetClearString(leftLimits[i].ToString()),
                            RightLimit = GetClearString(rightLimits[i].ToString())
                        };
                    }

                    excelProfile.Add(profile);
                }
            }
            else
            {
                throw new Exception("Лист \"" + sheetName + "\" не соответствует формату.");
            }

            return(excelProfile);
        }
Exemplo n.º 8
0
        public static Chart CreateDefaultChart(Chart currentChart, Tuple <Dictionary <string, int>, int, int> questionInfo, ExcelQuestion excelQuestion, SeriesChartType seriesType, bool add = false)
        {
            string question = excelQuestion.GetForSeries();
            Dictionary <string, int> points = questionInfo.Item1;
            int respondedCount = questionInfo.Item2;

            currentChart.Series.Add(question);
            currentChart.Series[question].ChartType = seriesType;
            currentChart.Series[question].Color     = Form1.CompanyColor.Values.ToList()[0];

            if (!add)
            {
                currentChart.Titles.Add(CommonService.CreateTitle("mainTitle", question));
                currentChart.Titles.Add(CommonService.CreateTitle("allTitle", "Всего " + respondedCount + " ответивших участников"));
            }

            foreach (var item in points)
            {
                currentChart.Series[question].Points.AddXY(item.Key, item.Value);
            }

            if (currentChart.Series[question].ChartType == SeriesChartType.Pie || currentChart.Series[question].ChartType == SeriesChartType.Doughnut)
            {
                int colorIndex = 0;
                foreach (var item in currentChart.Series[question].Points)
                {
                    if (item.YValues[0] == 0)
                    {
                        item.LabelForeColor = Color.Transparent;
                    }
                    item.Color = Form1.CompanyColor.Values.ToList()[colorIndex];
                    colorIndex++;
                }

                currentChart.Series[question].LabelForeColor = Color.White;
            }
            else
            {
                currentChart.Series[question].LabelForeColor = Color.Black;
            }

            if (!add)
            {
                Legend legend = CommonService.CreateLegend(currentChart.Series[question], "mainLegend");
                currentChart.Legends.Add(legend);
            }

            return(currentChart);
        }