private void BuildStaffFromTable() { staffTable = dbManager.GetDataTable(SQLStatement.GetStaffTableQuery()); if (staffTable != null) { foreach (DataRow r in staffTable.Rows) { Staff staff = new Staff(r["Name"].ToString(), r["Phone"].ToString()); fromStaffs.Add(staff); } } UpdateButtonsStatus(ButtonStatus.CanAdd); StaffListFrom.DataContext = fromStaffs; StaffListTo.DataContext = toStaffs; }
private void CreateReportGroup() { int periodNum; // remove all rows if (PeriodGrid.RowDefinitions.Count > 0) { PeriodGrid.RowDefinitions.RemoveRange(0, PeriodGrid.RowDefinitions.Count); PeriodGrid.Children.Clear(); } periodTable = dbManager.GetDataTable(SQLStatement.GetPeriodTypeTableQuery()); if (periodTable == null || periodTable.Rows.Count == 0) { // create a message label to indicate there is no period type available // and offer a button to create default period type table RowDefinition periodRow1 = new RowDefinition(); RowDefinition periodRow2 = new RowDefinition(); PeriodGrid.RowDefinitions.Add(periodRow1); PeriodGrid.RowDefinitions.Add(periodRow2); // add a label to the first row TextBlock txtMsg = new TextBlock(); txtMsg.Text = @"Unable to detect any period type in the database, please either add a new period type from the Period button, or use the button below to create default period types: Daily, Weekly, Fortnightly, Monthly, Quarterly, Annually."; txtMsg.TextWrapping = TextWrapping.Wrap; txtMsg.FontSize = 15; txtMsg.FontWeight = FontWeights.Bold; txtMsg.Margin = new Thickness(12); btnPeriod.BorderBrush = Brushes.Red; btnPeriod.BorderThickness = new Thickness(6); Grid.SetRow(txtMsg, 0); PeriodGrid.Children.Add(txtMsg); // add a button to the second row Button btnAddDefault = new Button(); btnAddDefault.Content = @"Restore Default Period Types"; btnAddDefault.FontSize = 15; btnAddDefault.Foreground = Brushes.Red; btnAddDefault.Margin = new Thickness(12); btnAddDefault.VerticalAlignment = VerticalAlignment.Top; btnAddDefault.Click += btnAddDefault_Click; Grid.SetRow(btnAddDefault, 1); PeriodGrid.Children.Add(btnAddDefault); } else { periodNum = periodTable.Rows.Count; for (int i = 1; i <= periodNum; i++) { RowDefinition periodRow = new RowDefinition(); PeriodGrid.RowDefinitions.Add(periodRow); } // add buttons for (int i = 0; i < periodNum; i++) { Button btn = new Button(); string btnContent = string.Format("{0} Report", periodTable.Rows[i]["Period_Type"].ToString()); btn.Content = btnContent; btn.FontSize = 15; // btn.Foreground = Brushes.Red; btn.Margin = new Thickness(12); // set tag btn.Tag = periodTable.Rows[i]["Period_Type_ID"]; btn.Click += BTN_Period_Type_Clicked; Grid.SetRow(btn, i); PeriodGrid.Children.Add(btn); } } }