public void PlaceUsers(List <object[]> userAttendances) { try { if (userAttendances == null || userAttendances.Count == 0) { return; } last = new int[4]; ArchivedMeeting archivedMeeting = meetingController.archivedMeetingModel.Get(((Attendance)(userAttendances.First()[1])).archivedMeetingId); foreach (object[] obj in userAttendances) { User user = (User)obj[0]; Attendance att = (Attendance)obj[1]; if (user.departmentId != departmentId) { continue; } Grid DynamicGrid = new Grid { Background = new SolidColorBrush(Colors.White), Width = 120 }; Border border = new Border { BorderThickness = new Thickness(1, 1, 1, 0), Margin = new Thickness(5, 5, 5, 5) }; border.Child = DynamicGrid; DynamicGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); DynamicGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(100) }); DynamicGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30) }); DynamicGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30) }); BitmapImage webImage = meetingController.GetUserImage(user); float scaleHeight = (float)120 / (float)webImage.Height; float scaleWidth = (float)100 / (float)webImage.Width; float scale = Math.Max(scaleHeight, scaleWidth); Image image = new Image { Source = webImage, Height = (int)(webImage.Width * scale), Width = (int)(webImage.Height * scale) }; Label name = new Label { Content = user.fname + " " + user.lname, HorizontalAlignment = HorizontalAlignment.Center, FontSize = 17 }; ComboBox combobox = new ComboBox { FontWeight = FontWeights.Bold, FontSize = 17 }; foreach (KeyValuePair <int, string> entry in statuses) { if (entry.Key == 14) { continue; } ComboBoxItem comboboxItem = new ComboBoxItem { Content = entry.Key == 2 ? "(" + (att.regTime != -1 ? att.regTime : 0) + ")" + statuses[entry.Key] : entry.Value, Foreground = Brushes.Black, HorizontalAlignment = HorizontalAlignment.Stretch, HorizontalContentAlignment = HorizontalAlignment.Center, FontWeight = FontWeights.Bold, FontSize = 15 }; comboboxItem.Tag = entry.Key; switch (entry.Key) { case 1: comboboxItem.Background = Brushes.LightGreen; break; case 2: comboboxItem.Background = Brushes.LightSalmon; break; case 15: comboboxItem.Background = Brushes.LightCoral; break; default: comboboxItem.Background = Brushes.LightBlue; break; } combobox.Items.Add(comboboxItem); if (entry.Key == att.statusId) { combobox.SelectedItem = comboboxItem; switch (entry.Key) { case 1: border.BorderBrush = Brushes.DarkGreen; break; case 2: border.BorderBrush = Brushes.DarkOrange; break; case 15: border.BorderBrush = Brushes.DarkRed; break; default: border.BorderBrush = Brushes.DarkSlateBlue; break; } } } combobox.SelectionChanged += (e, o) => { ChangeUserAttendance(obj, e); }; Grid.SetColumn(image, 0); Grid.SetColumn(name, 0); Grid.SetColumn(combobox, 0); Grid.SetRow(image, 0); Grid.SetRow(name, 1); Grid.SetRow(combobox, 2); DynamicGrid.Children.Add(image); DynamicGrid.Children.Add(name); DynamicGrid.Children.Add(combobox); if (att.statusId == 1) { depAttWrapPanel.Children.Insert(last[0] + last[1] + last[2], border); last[3]++; } else if (att.statusId == 2) { depAttWrapPanel.Children.Insert(last[0], border); last[1]++; } else if (att.statusId == 15) { depAttWrapPanel.Children.Insert(0, border); last[0]++; } else { depAttWrapPanel.Children.Insert(last[0] + last[1], border); last[2]++; } userGrids.Add(user.id, DynamicGrid); } depAttTextBox1.Text = (last[0] + last[1] + last[3]).ToString(); depAttTextBox2.Text = (last[3]).ToString(); depAttTextBox3.Text = (last[1]).ToString(); depAttTextBox4.Text = (last[0]).ToString(); } catch (Exception ex) { MessageBox.Show("Хурлын цонх нээхэд алдаа гарлаа. Алдааны мессеж: " + ex.ToString()); } }
public void PlaceUsers(List <object[]> userAttendances) { try { if (userAttendances == null || userAttendances.Count == 0) { return; } last = new Dictionary <int, int[]>(); foreach (KeyValuePair <int, string> entry in departments) { last.Add(entry.Key, new int[4]); } ArchivedMeeting archivedMeeting = meetingController.onGoingArchivedMeeting; foreach (object[] obj in userAttendances) { User user = (User)obj[0]; Attendance att = (Attendance)obj[1]; System.Windows.Controls.Grid DynamicGrid = new System.Windows.Controls.Grid { Background = new SolidColorBrush(Colors.White), Width = 60 }; Border border = new Border { BorderThickness = new Thickness(1, 1, 1, 0), Margin = new Thickness(5, 5, 5, 5) }; border.Child = DynamicGrid; DynamicGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); DynamicGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(60) }); DynamicGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30) }); DynamicGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30) }); BitmapImage webImage = meetingController.GetUserImage(user); float scaleHeight = (float)60 / (float)webImage.Height; float scaleWidth = (float)60 / (float)webImage.Width; float scale = Math.Max(scaleHeight, scaleWidth); Image image = new Image { Source = webImage, Height = (int)(webImage.Width * scale), Width = (int)(webImage.Height * scale) }; Label name = new Label { Content = user.fname + " " + user.lname, HorizontalAlignment = HorizontalAlignment.Center, FontSize = 15 }; Label status = new Label { Content = att.statusId == 2 ? "(" + att.regTime + ") " + statuses[att.statusId] : statuses[att.statusId], Foreground = Brushes.White, HorizontalAlignment = HorizontalAlignment.Stretch, HorizontalContentAlignment = HorizontalAlignment.Center, FontWeight = FontWeights.Bold }; switch (att.statusId) { case 1: border.BorderBrush = status.Background = Brushes.DarkGreen; break; case 2: border.BorderBrush = status.Background = Brushes.DarkOrange; break; case 15: border.BorderBrush = status.Background = Brushes.DarkRed; break; default: border.BorderBrush = status.Background = Brushes.DarkSlateBlue; break; } System.Windows.Controls.Grid.SetColumn(image, 0); System.Windows.Controls.Grid.SetColumn(name, 0); System.Windows.Controls.Grid.SetColumn(status, 0); System.Windows.Controls.Grid.SetRow(image, 0); System.Windows.Controls.Grid.SetRow(name, 1); System.Windows.Controls.Grid.SetRow(status, 2); DynamicGrid.Children.Add(image); DynamicGrid.Children.Add(name); DynamicGrid.Children.Add(status); if (att.statusId == 1) { if (last[user.departmentId][0] + last[user.departmentId][1] + last[user.departmentId][2] < departmentWrapPanels[user.departmentId].Children.Count) { departmentWrapPanels[user.departmentId].Children.Insert(last[user.departmentId][0] + last[user.departmentId][1] + last[user.departmentId][2], border); } else { departmentWrapPanels[user.departmentId].Children.Add(border); } last[user.departmentId][3]++; border.Visibility = Visibility.Hidden; } else if (att.statusId == 2) { if (last[user.departmentId][0] < departmentWrapPanels[user.departmentId].Children.Count) { departmentWrapPanels[user.departmentId].Children.Insert(last[user.departmentId][0], border); } else { departmentWrapPanels[user.departmentId].Children.Add(border); } last[user.departmentId][1]++; border.Visibility = Visibility.Visible; } else if (att.statusId == 15) { departmentWrapPanels[user.departmentId].Children.Insert(0, border); last[user.departmentId][0]++; border.Visibility = Visibility.Visible; } else { if (last[user.departmentId][0] + last[user.departmentId][1] < departmentWrapPanels[user.departmentId].Children.Count) { departmentWrapPanels[user.departmentId].Children.Insert(last[user.departmentId][0] + last[user.departmentId][1], border); } else { departmentWrapPanels[user.departmentId].Children.Add(border); } last[user.departmentId][2]++; border.Visibility = Visibility.Hidden; } userGrids.Add(user.id, DynamicGrid); } foreach (KeyValuePair <int, string> entry in departments) { if (!last.ContainsKey(entry.Key)) { last.Add(entry.Key, new int[4]); } departmentAttendance[entry.Key][0].Text = ((int)(last[entry.Key][0] + last[entry.Key][1] + last[entry.Key][3])).ToString(); departmentAttendance[entry.Key][1].Text = last[entry.Key][3].ToString(); departmentAttendance[entry.Key][2].Text = last[entry.Key][1].ToString(); departmentAttendance[entry.Key][3].Text = last[entry.Key][0].ToString(); } int grandTotal = last.Sum(x => x.Value[0] + x.Value[1] + x.Value[2] + x.Value[3]); int totalAttendance = last.Sum(x => x.Value[0] + x.Value[1] + x.Value[3]); int totalArrived = last.Sum(x => x.Value[3]); int totalFree = last.Sum(x => x.Value[2]); int totalLate = last.Sum(x => x.Value[1]); int totalMissing = last.Sum(x => x.Value[0]); AttendanceLabel1.Text = totalAttendance.ToString(); AttendanceLabel2.Text = totalArrived.ToString(); AttendanceLabel3.Text = totalLate.ToString(); AttendanceLabel4.Text = totalMissing.ToString(); AttendancePercentageLabel1.Text = Math.Round((((double)totalArrived / totalAttendance) * 100)).ToString() + '%'; AttendancePercentageLabel2.Text = Math.Round((((double)totalLate / totalAttendance) * 100)).ToString() + '%'; AttendancePercentageLabel3.Text = Math.Round((((double)totalMissing / totalAttendance) * 100)).ToString() + '%'; //Add a new chart-series chart.Series.Clear(); string seriesname = "Хүмүүс"; chart.Series.Add(seriesname); //set the chart-type to "Pie" chart.Series[seriesname].ChartType = SeriesChartType.Pie; chart.Series[seriesname].Font = new System.Drawing.Font("Arial", 13f, System.Drawing.FontStyle.Bold); chart.Series[seriesname].Label = "#PERCENT{0 %}"; chart.Series[seriesname].LegendText = "#VALX"; //Add some datapoints so the series. in this case you can pass the values to this method chart.Series[seriesname].Points.AddXY("Ирсэн", totalArrived); chart.Series[seriesname].Points.AddXY("Хоцорсон", totalLate); chart.Series[seriesname].Points.AddXY("Чөлөөтэй", totalFree); chart.Series[seriesname].Points.AddXY("Ирээгүй", totalMissing); chart.Series[0].Points[0].Color = System.Drawing.Color.LightGreen; chart.Series[0].Points[1].Color = System.Drawing.Color.LightSalmon; chart.Series[0].Points[2].Color = System.Drawing.Color.LightSkyBlue; chart.Series[0].Points[3].Color = System.Drawing.Color.LightCoral; } catch (Exception ex) { MessageBox.Show("Хурлын цонх нээхэд алдаа гарлаа. Алдааны мессеж: " + ex.ToString()); } }