Beispiel #1
0
        private void buttonDiagram_Click(object sender, EventArgs e)
        {
            try
            {
                ComponentWordHistogram comp = new ComponentWordHistogram();
                // var fbd = new FolderBrowserDialog();
                using (var dialog = new SaveFileDialog {
                    Filter = "docx|*.docx"
                })
                {
                    using (var context = new Database())
                    {
                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            List <DiagramModel> list = new List <DiagramModel>();
                            var list1 = context.Students.GroupBy(p => p.Scholarship)
                                        .Select(p => new { p.Key, Count = p.Count() })
                                        .ToDictionary(p => p.Key, p => p.Count);

                            foreach (var g in list1)
                            {
                                list.Add(new DiagramModel
                                {
                                    Scholarship = g.Key,
                                    Count       = g.Value
                                });
                            }

                            comp.CreateDiagram(list, "Студенты", dialog.FileName);
                            MessageBox.Show("Сохранение прошло успешно");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Не удалось сохранить диаграмму " + ex.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// создание гистограммы с количеством отпусков в каждом месяце
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonWordVacation_Click(object sender, EventArgs e)
        {
            try
            {
                ComponentWordHistogram comp = new ComponentWordHistogram();
                using (var dialog = new SaveFileDialog {
                    Filter = "docx|*.docx"
                })
                {
                    using (var context = new Database())
                    {
                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            List <DiagramModel> list = new List <DiagramModel>();
                            var employees            = context.Employees
                                                       .GroupBy(p => p.VacationStart.Value.Month)
                                                       .Select(p => new { p.Key, Count = p.Count() })
                                                       .ToDictionary(p => p.Key, p => p.Count);

                            foreach (var employee in employees)
                            {
                                list.Add(new DiagramModel
                                {
                                    Count = employee.Key,
                                    Month = employee.Value
                                });
                            }

                            comp.CreateDiagram(list, "Employees", dialog.FileName);
                            MessageBox.Show("Сохранение прошло успешно");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Не удалось сохранить диаграмму\n" + ex.Message);
            }
        }