(排班表二)后台动态绘制Grid表格

 后台动态绘制值班表(Grid表格 列名不固定)

要求:表头除了值班人姓名,还要显示日期,及每天的星期值,用斜杠‘/’分隔。即:几号/星期几

最终实现的效果:根据查询的年月显示每个值班人查询月份每天的值班信息

 

注:当查询月份不足31天时,显示空白列。如下图:

    

1.前台页面(WPF页面.xaml)显示

 1   <Grid Background="White">
 2                                 <Grid.RowDefinitions>
 3                                     <RowDefinition Height="35"></RowDefinition>
 4                                     <RowDefinition Height="*"></RowDefinition>
 5                                     <!--<RowDefinition Height="30"></RowDefinition>
 6                                     <RowDefinition Height="0.5*"></RowDefinition>-->
 7                                 </Grid.RowDefinitions>
 8 
 9                                 <!--筛选条件-->
10                                 <Grid>
11                                     <Grid.ColumnDefinitions>
12                                         <ColumnDefinition Width="120"></ColumnDefinition>
13                                         <ColumnDefinition Width="100"></ColumnDefinition>
14                                         <ColumnDefinition Width="110"></ColumnDefinition>
15                                         <ColumnDefinition Width="80"></ColumnDefinition>
16                                         <ColumnDefinition Width="120"></ColumnDefinition>
17                                         <ColumnDefinition Width="150"></ColumnDefinition>
18                                     </Grid.ColumnDefinitions>
19 
20                                     <!-- 日期星期(方法一)-->
21                                     <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="5 0">
22                                         <TextBlock Text=" 年度:" VerticalAlignment="Center"></TextBlock>
23                                         <telerik:RadComboBox x:Name="rcb_year" VerticalAlignment="Center" HorizontalContentAlignment="Right" Width="65" SelectionChanged="rcb_year_SelectionChanged"/>
24                                     </StackPanel>
25 
26                                     <StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
27                                         <TextBlock Text=" 月份:" VerticalAlignment="Center"></TextBlock>
28                                         <telerik:RadComboBox x:Name="rcb_month" VerticalAlignment="Center" HorizontalContentAlignment="Right" Width="55" SelectionChanged="rcb_month_SelectionChanged"/>
29                                     </StackPanel>
30 
31                                     <!--导出-->
32                                     <telerik:RadButton Grid.Row="0" Grid.Column="2" x:Name="btn_export_1" Background="#FA824F" Margin="5" CornerRadius="2" FontSize="13" Click="btn_export_1_Click">
33                                         <StackPanel Orientation="Horizontal">
34                                             <Image Source="/PMS_BZ;component/Images/edit.png" Margin="3" Height="12"></Image>
35                                             <TextBlock Text=" 导出值班表 " Foreground="#FFFFFF" VerticalAlignment="Center"></TextBlock>
36                                         </StackPanel>
37                                     </telerik:RadButton>
38                                     <!--刷新-->
39                                     <telerik:RadButton Grid.Row="0" Grid.Column="3" x:Name="btn_refresh_1" Background="Orange" Margin="5" CornerRadius="2" FontSize="13" Click="btn_refresh_1_Click">
40                                         <StackPanel Orientation="Horizontal">
41                                             <Image Source="/PMS_BZ;component/Images/reset.png" Margin="3" Height="12"></Image>
42                                             <TextBlock Text=" 刷 新 " Foreground="#FFFFFF" VerticalAlignment="Center"></TextBlock>
43                                         </StackPanel>
44                                     </telerik:RadButton>
45 
46                                     <!--添加值班-->
47                                     <telerik:RadButton Grid.Row="0" Grid.Column="4" x:Name="btn_add_schedule" Background="#1DA02B" Margin="5" CornerRadius="2" FontSize="13" Click="btn_add_schedule_Click" Visibility="Collapsed">
48                                         <StackPanel Orientation="Horizontal">
49                                             <Image Source="/PMS_BZ;component/Images/input.png" Margin="3" Height="12"></Image>
50                                             <TextBlock Text=" 值班信息管理 " Foreground="#FFFFFF" VerticalAlignment="Center"></TextBlock>
51                                         </StackPanel>
52                                     </telerik:RadButton>
53 
54                                     <!--添加案件录入权限信息-->
55                                     <telerik:RadButton Grid.Row="0" Grid.Column="5" x:Name="btn_add_power" Background="DarkGoldenrod" Margin="5" CornerRadius="2" FontSize="13" Click="btn_add_power_Click" Visibility="Collapsed">
56                                         <StackPanel Orientation="Horizontal">
57                                             <Image Source="/PMS_BZ;component/Images/comp.png" Margin="3" Height="12"></Image>
58                                             <TextBlock Text=" 案件录入权限管理 " Foreground="#FFFFFF" VerticalAlignment="Center"></TextBlock>
59                                         </StackPanel>
60                                     </telerik:RadButton>
61                                 </Grid>
62                                 <!--排班表-->
63                                 <ScrollViewer x:Name="sv_data" Grid.Row="1" BorderBrush="#25A0DA" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
64 
65                                     <Grid x:Name="rgv_schedule" Background="White" Width="3150"></Grid>
66 
67                                 </ScrollViewer>
68 
69                                 <!--案件录入权限表-->
70                                 <!--<StackPanel Grid.Row="2" Background="#25A0DA" Orientation="Horizontal">
71                                     <Image Source="/PMS_BZ;component/Images/grid.png" Height="20" Margin="5 0"></Image>
72                                     <TextBlock Text="案件录入权限表" FontSize="13" VerticalAlignment="Center" Foreground="White" Margin="5 0"></TextBlock>
73 
74                                     <telerik:RadButton Grid.Row="0" Grid.Column="3" x:Name="btn_export_power" Background="#FA824F" Margin="5 2" CornerRadius="2" FontSize="13" Click="btn_export_power_Click">
75                                         <StackPanel Orientation="Horizontal">
76                                             <Image Source="/PMS_BZ;component/Images/edit.png" Margin="3" Height="12"></Image>
77                                             <TextBlock Text=" 导出录入权限表 " Foreground="#FFFFFF" VerticalAlignment="Center"></TextBlock>
78                                         </StackPanel>
79                                     </telerik:RadButton>
80                                 </StackPanel>
81 
82                                 <ScrollViewer x:Name="sv_data_power" Grid.Row="3" BorderBrush="#25A0DA" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
83                                     <Grid x:Name="rgv_power" Background="White" Width="3150"></Grid>
84                                 </ScrollViewer>-->
85 
86                             </Grid>
显示页面代码

2.初始化年度、月份下拉框数据:年度只显示最近5年的年度

 1         // 设置时间控件的默认值
 2         private void SetDateControl()
 3         {
 4             try
 5             {
 6                 RadComboBoxItem cmbi_year;
 7                 RadComboBoxItem cmbi_month;
 8                 int years = DateTime.Now.Year;
 9          //设置年度
10                 for (int i = 0; i < 5; i++)
11                 {
12                     int year = years - i;
13                     cmbi_year = new RadComboBoxItem();
14                     cmbi_year.Tag = cmbi_year.Content = year;
15                     rcb_year.Items.Add(cmbi_year);
16                     if (year == DateTime.Now.Year)
17                     {
18                         rcb_year.SelectedItem = cmbi_year;
19                     }
20                 }
21              //设置月份
22                 for (int i = 1; i <= 12; i++)
23                 {
24                     cmbi_month = new RadComboBoxItem();
25                     cmbi_month.Tag = i;
26                     cmbi_month.Content = i.ToString() + "";
27                     rcb_month.Items.Add(cmbi_month);
28                 }
29                 if (Convert.ToInt32((rcb_year.SelectedItem as RadComboBoxItem).Tag) == DateTime.Now.Year)
30                 {
31                     rcb_month.SelectedIndex = DateTime.Now.Month - 1;
32                 }
33                 else
34                     rcb_month.SelectedIndex = 11;
35             }
36             catch (Exception ex)
37             {
38                 MessageBox.Show(ex.Message);
39             }
40         }
41 
42          // 窗体加载
43         private void Page_Loaded(object sender, RoutedEventArgs e)
44         {
45             MyRadBusy.IsBusy = true;
46 
47             System.Threading.ThreadPool.QueueUserWorkItem((threadState) =>
48             {
49                 System.Threading.Thread.Sleep(800);
50                 Dispatcher.BeginInvoke((Action)delegate()
51                 {
52                     try
53                     {
54                         SetDateControl();//时间变化
55                     }
56                     catch (Exception ex)
57                     {
58                         RadWindow.Alert(ex.Message);
59                     }
60                 });
61             });
62         }
设置年度、月份

3.当年度或月份发生改变时,值班表信息也相应的发生改变

 1         //年度发生改变
 2         private void rcb_year_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
 3         {
 4             BindingScheduleGrid();
 5         }
 6         //月份发生改变
 7         private void rcb_month_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
 8         {
 9             BindingScheduleGrid();
10         }
下拉框改变事件

4.绑定表格数据

 1 //绑定表格值班信息
 2         public void BindingScheduleGrid()//rgv_schedule
 3         {
 4             //选择的时间
 5             int select_year = rcb_year.SelectedItem == null ? DateTime.Now.Year : Convert.ToInt32((rcb_year.SelectedItem as RadComboBoxItem).Tag);
 6             int select_month = rcb_month.SelectedItem == null ? DateTime.Now.Month : Convert.ToInt32((rcb_month.SelectedItem as RadComboBoxItem).Tag);
 7 
 8             #region
 9             //判断该月有多少天
10             totalDays = DateTime.DaysInMonth(select_year, select_month);//selectTime.Year, selectTime.Month
11 
12             //清空列表
13             rgv_schedule.Children.Clear();
14             //添加第一行(表头)
15             RowDefinition row = new RowDefinition() { Height = new GridLength(30) };
16             rgv_schedule.RowDefinitions.Add(row);
17             //姓名列
18             ColumnDefinition col_name = new ColumnDefinition() { Width = new GridLength(50) };
19             rgv_schedule.ColumnDefinitions.Add(col_name);
20 
21             System.Windows.Controls.Border b_name = new System.Windows.Controls.Border() { BorderThickness = new Thickness(1, 1, 1, 1), BorderBrush = new SolidColorBrush(System.Windows.Media.Colors.Black) };
22             TextBlock txt_name = new TextBlock() { Text = "姓名", FontSize = 13, FontWeight = FontWeights.Black, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
23             b_name.Child = txt_name;
24             b_name.SetValue(Grid.ColumnProperty, 0);//设置边框所在列
25             b_name.SetValue(Grid.RowProperty, 0);//设置边框所在行
26             rgv_schedule.Children.Add(b_name);//将边框添加到表格中
27  for (int i = 1; i <= 31; i++)
28             {
29                 string cols = "";
30                 if (i <= totalDays)
31                 {
32                     DateTime dtime = Convert.ToDateTime(select_year + "-" + select_month + "-" + i);
33                     cols = i + "号/" + week_str[Convert.ToInt16(dtime.DayOfWeek)];
34                 }
35 
36                 //添加日期列  rgv_schedule
37                 ColumnDefinition colum = new ColumnDefinition() { Width = new GridLength(100) };
38                 rgv_schedule.ColumnDefinitions.Add(colum);
39 
40                 System.Windows.Controls.Border b_3 = new System.Windows.Controls.Border() { BorderThickness = new Thickness(0, 1, 1, 1), BorderBrush = new SolidColorBrush(System.Windows.Media.Colors.Black) };
41                 TextBlock txt_3 = new TextBlock() { Text = cols, FontSize = 13, FontWeight = FontWeights.Black, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
42                 b_3.Child = txt_3;
43                 //设置TextBlock在Grid中的位置   
44                 b_3.SetValue(Grid.ColumnProperty, i);
45                 b_3.SetValue(Grid.RowProperty, 0);
46                 rgv_schedule.Children.Add(b_3);
47             }
48 
49             MyRadBusy.IsBusy = true;
50             System.Threading.ThreadPool.QueueUserWorkItem((threadState) =>
51             {
52                 System.Threading.Thread.Sleep(800);
53                 Dispatcher.BeginInvoke((Action)delegate()
54                 {
55                     try
56                     {                        InterFace.Service.AllSchePowerByWhereAsync(totalDays, Session.CurrentLoginUser.sysorgno, select_year, select_month);
57                         InterFace.Service.AllSchePowerByWhereCompleted += Service_AllSchePowerByWhereCompleted;
58                     }
59                     catch (Exception ex)
60                     {
61                         RadWindow.Alert(ex.Message);
62                     }
63                 });
64             });
65             #endregion
66         }
设置值班表
  1   //值班表与录入权限表数据合并显示:显示优先顺序班 > 录 > 休
  2     void Service_AllSchePowerByWhereCompleted(object sender, AllSchePowerByWhereCompletedEventArgs e)
  3         {
  4             InterFace.Service.AllSchePowerByWhereCompleted -= Service_AllSchePowerByWhereCompleted;
  5             try
  6             {
  7                 if (e.Result != null && e.Result.Count() > 0)
  8                 {
  9 List<ScheduleModel> ltDataSchedule = new List<ScheduleModel>();
 10                     ltDataSchedule = e.Result.ToList();
 11                     btn_export_1.IsEnabled = true;
 12 
 13                     for (int i = 0; i < ltDataSchedule.Count(); i++)
 14                     {
 15                         //添加行
 16                         RowDefinition row = new RowDefinition() { Height = new GridLength(30) };
 17                         rgv_schedule.RowDefinitions.Add(row);
 18 
 19                         //姓名列
 20                         ColumnDefinition col_name = new ColumnDefinition() { Width = new GridLength(50) };
 21                         rgv_schedule.ColumnDefinitions.Add(col_name);
 22 
 23                         System.Windows.Controls.Border b_name = new System.Windows.Controls.Border() { BorderThickness = new Thickness(1, 0, 1, 1), BorderBrush = new SolidColorBrush(System.Windows.Media.Colors.Black) };
 24                         TextBlock txt_name = new TextBlock() { Text = ltDataSchedule[i].name, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
 25                         b_name.Child = txt_name;
 26                         b_name.SetValue(Grid.ColumnProperty, 0);
 27                         b_name.SetValue(Grid.RowProperty, i + 1);
 28                         rgv_schedule.Children.Add(b_name);
 29 
 30                         for (int j = 1; j <= 31; j++)
 31                         {
 32                             ColumnDefinition col_j = new ColumnDefinition() { Width = new GridLength(50) };
 33                             rgv_schedule.ColumnDefinitions.Add(col_j);
 34 
 35                             System.Windows.Controls.Border b_j = new System.Windows.Controls.Border() { BorderThickness = new Thickness(0, 0, 1, 1), BorderBrush = new SolidColorBrush(System.Windows.Media.Colors.Black) };
 36                             TextBlock txt_j = null;
 37   #region 填充列值
 38 
 39                             if (j == 1)
 40                             {
 41                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day1, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
 42                                 if (ltDataSchedule[i].day1 != null && ltDataSchedule[i].day1.Contains("") || ltDataSchedule[i].day1.Contains("")) 
 43                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
 44                             }
 45                             else if (j == 2)
 46                             {
 47                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day2, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
 48                                 if (ltDataSchedule[i].day2 != null && ltDataSchedule[i].day2.Contains("") || ltDataSchedule[i].day2.Contains("")) 
 49                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
 50                             }
 51                             else if (j == 3)
 52                             {
 53                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day3, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
 54                                 if (ltDataSchedule[i].day3 != null && ltDataSchedule[i].day3.Contains("") || ltDataSchedule[i].day3.Contains("")) 
 55                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
 56                             }
 57                             else if (j == 4)
 58                             {
 59                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day4, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
 60                                 if (ltDataSchedule[i].day4 != null && ltDataSchedule[i].day4.Contains("") || ltDataSchedule[i].day4.Contains("")) 
 61                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
 62                             }
 63  else if (j == 5)
 64                             {
 65                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day5, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
 66                                 if (ltDataSchedule[i].day5 != null && ltDataSchedule[i].day5.Contains("") || ltDataSchedule[i].day5.Contains("")) 
 67                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
 68                             }
 69                             else if (j == 6)
 70                             {
 71                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day6, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
 72                                 if (ltDataSchedule[i].day6 != null && ltDataSchedule[i].day6.Contains("") || ltDataSchedule[i].day6.Contains(""))
 73                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
 74                             }
 75                             else if (j == 7)
 76                             {
 77                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day7, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
 78                                 if (ltDataSchedule[i].day7 != null && ltDataSchedule[i].day7.Contains("") || ltDataSchedule[i].day7.Contains("")) 
 79                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
 80                             }
 81                             else if (j == 8)
 82                             {
 83                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day8, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
 84                                 if (ltDataSchedule[i].day8 != null && ltDataSchedule[i].day8.Contains("") || ltDataSchedule[i].day8.Contains("")) 
 85                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
 86                             }
 87   else if (j == 9)
 88                             {
 89                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day9, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
 90                                 if (ltDataSchedule[i].day9 != null && ltDataSchedule[i].day9.Contains("") || ltDataSchedule[i].day9.Contains("")) 
 91                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
 92                             }
 93                             else if (j == 10)
 94                             {
 95                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day10, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
 96                                 if (ltDataSchedule[i].day10 != null && ltDataSchedule[i].day10.Contains("") || ltDataSchedule[i].day10.Contains("")) 
 97                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
 98                             }
 99                             else if (j == 11)
100                             {
101                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day11, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
102                                 if (ltDataSchedule[i].day11 != null && ltDataSchedule[i].day11.Contains("") || ltDataSchedule[i].day11.Contains(""))  
103                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
104                             }
105  else if (j == 12)
106                             {
107                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day12, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
108                                 if (ltDataSchedule[i].day12 != null && ltDataSchedule[i].day12.Contains("") || ltDataSchedule[i].day12.Contains("")) 
109                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
110                             }
111                             else if (j == 13)
112                             {
113                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day13, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
114                                 if (ltDataSchedule[i].day13 != null && ltDataSchedule[i].day13.Contains("") || ltDataSchedule[i].day13.Contains("")) 
115                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
116                             }
117                             else if (j == 14)
118                             {
119                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day14, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
120                                 if (ltDataSchedule[i].day14 != null && ltDataSchedule[i].day14.Contains("") || ltDataSchedule[i].day14.Contains("")) 
121                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
122                             }
123                             else if (j == 15)
124                             {
125                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day15, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
126                                 if (ltDataSchedule[i].day15 != null && ltDataSchedule[i].day15.Contains("") || ltDataSchedule[i].day15.Contains("")) 
127                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
128                             }
129    else if (j == 16)
130                             {
131                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day16, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
132                                 if (ltDataSchedule[i].day16 != null && ltDataSchedule[i].day16.Contains("") || ltDataSchedule[i].day16.Contains("")) 
133                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
134                             }
135                             else if (j == 17)
136                             {
137                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day17, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
138                                 if (ltDataSchedule[i].day17 != null && ltDataSchedule[i].day17.Contains("") || ltDataSchedule[i].day17.Contains("")) 
139                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
140                             }
141                             else if (j == 18)
142                             {
143                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day18, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
144                                 if (ltDataSchedule[i].day18 != null && ltDataSchedule[i].day18.Contains("") || ltDataSchedule[i].day18.Contains("")) 
145                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
146                             }
147                             else if (j == 19)
148                             {
149                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day19, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
150                                 if (ltDataSchedule[i].day19 != null && ltDataSchedule[i].day19.Contains("") || ltDataSchedule[i].day19.Contains("")) 
151                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
152                             }
153  else if (j == 20)
154                             {
155                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day20, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
156                                 if (ltDataSchedule[i].day20 != null && ltDataSchedule[i].day20.Contains("") || ltDataSchedule[i].day20.Contains("")) 
157                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
158                             }
159                             else if (j == 21)
160                             {
161                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day21, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
162                                 if (ltDataSchedule[i].day21 != null && ltDataSchedule[i].day21.Contains("") || ltDataSchedule[i].day21.Contains("")) 
163                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
164                             }
165                             else if (j == 22)
166                             {
167                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day22, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
168                                 if (ltDataSchedule[i].day22 != null && ltDataSchedule[i].day22.Contains("") || ltDataSchedule[i].day22.Contains("")) 
169                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
170                             }
171                             else if (j == 23)
172                             {
173                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day23, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
174                                 if (ltDataSchedule[i].day23 != null && ltDataSchedule[i].day23.Contains("") || ltDataSchedule[i].day23.Contains("")) 
175                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
176                             }
177    else if (j == 24)
178                             {
179                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day24, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
180                                 if (ltDataSchedule[i].day24 != null && ltDataSchedule[i].day24.Contains("") || ltDataSchedule[i].day24.Contains("")) 
181                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
182                             }
183                             else if (j == 25)
184                             {
185                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day25, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
186                                 if (ltDataSchedule[i].day25 != null && ltDataSchedule[i].day25.Contains("") || ltDataSchedule[i].day25.Contains(""))
187                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
188                             }
189                             else if (j == 26)
190                             {
191                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day26, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
192                                 if (ltDataSchedule[i].day26 != null && ltDataSchedule[i].day26.Contains("") || ltDataSchedule[i].day26.Contains("")) 
193                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
194                             }
195  else if (j == 27)
196                             {
197                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day27, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
198                                 if (ltDataSchedule[i].day27 != null && ltDataSchedule[i].day27.Contains("") || ltDataSchedule[i].day27.Contains("")) 
199                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
200                             }
201                             else if (j == 28)
202                             {
203                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day28, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
204                                 if (ltDataSchedule[i].day28 != null && ltDataSchedule[i].day28.Contains("") || ltDataSchedule[i].day28.Contains("")) 
205                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
206                             }
207                             else if (j == 29)
208                             {
209                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day29, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
210                                 if (ltDataSchedule[i].day29 != null && ltDataSchedule[i].day29.Contains("") || ltDataSchedule[i].day29.Contains("")) 
211                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
212                             }
213  else if (j == 30)
214                             {
215                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day30, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
216                                 if (ltDataSchedule[i].day30 != null && ltDataSchedule[i].day30.Contains("") || ltDataSchedule[i].day30.Contains("")) 
217                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
218                             }
219                             else if (j == 31)
220                             {
221                                 txt_j = new TextBlock() { Text = ltDataSchedule[i].day31, FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
222                                 if (ltDataSchedule[i].day31 != null && ltDataSchedule[i].day31.Contains("") || ltDataSchedule[i].day31.Contains("")) 
223                                 { txt_j.Foreground = new SolidColorBrush(System.Windows.Media.Colors.Red); }
224                             }
225                             else
226                             {
227                                 txt_j = new TextBlock() { Text = "", FontSize = 13, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
228                             }
229 
230                             #endregion
231   b_j.Child = txt_j;
232                             b_j.SetValue(Grid.ColumnProperty, j);
233                             b_j.SetValue(Grid.RowProperty, i + 1);
234                             rgv_schedule.Children.Add(b_j);
235                         }
236                     }
237                 }
238                 else
239                 {
240                     //  RadWindow.Alert("当前查询月份暂无排班信息!");
241                     ltDataSchedule = null;
242                     btn_export_1.IsEnabled = false;
243                 }
244             }
245             catch (Exception)
246             {
247                 RadWindow.Alert(e.Error.Message);
248             }
249             finally { MyRadBusy.IsBusy = false; }
250         }
绑定值班表数据

5.Wcf获取值班表数据

  1 /// <summary>
  2         /// 值班表与录入权限表信息合并
  3         /// </summary>
  4         /// <param name="p_days">月天数</param>
  5         /// <param name="p_sysorgno">所属机构</param>
  6         /// <param name="p_year">年份</param>
  7         /// <param name="p_month">月份</param>
  8         /// <returns></returns>
  9         [OperationContract]
 10         public List<ScheduleModel> AllSchePowerByWhere(int p_days, string p_sysorgno, int p_year, int p_month)
 11         {
 12             //审核人员
 13             string sqlStr = string.Format(@"select username ,des from sys_users where roleno = '0002' and sysorgno='{0}';", p_sysorgno);
 14 
 15             //值班表  
 16             sqlStr += string.Format(@"select schedule01 as loginname,schedule02 as name");
 17             for (int i = 1; i <= p_days; i++)
 18             {
 19                 sqlStr += string.Format(@",max(case when scheduleday={0} then (CASE WHEN state= 1 THEN '班' ELSE '休' END) end) as day{0} ", i);
 20             }
 21             sqlStr += string.Format(@"from loc_schedule where sysorgno='{0}' and scheduleyear={1} and schedulemonth={2} group by schedule01,schedule02 order by schedule01 ;"
 22                   , p_sysorgno, p_year, p_month);
 23  //录入权限表
 24             sqlStr += string.Format(@"select power01 as loginname,power02 as name");
 25             for (int i = 1; i <= p_days; i++)
 26             {
 27                 sqlStr += string.Format(@",max(case when powerday={0} then (CASE WHEN state= 1 THEN '录' ELSE '禁' END) end) as day{0} ", i);
 28             }
 29             sqlStr += string.Format(@"from loc_power where sysorgno='{0}' and poweryear={1} and powermonth={2} group by power01 ,power02 order by power01 ;"
 30                 , p_sysorgno, p_year, p_month);
 31 
 32             DataSet ds = pgSqlService.Query(sqlStr.ToString());
 33             List<sys_users> ltdate = pgSqlService.ConvertToModel<sys_users>(ds.Tables[0]); //审核人员
 34             List<ScheduleModel> ltdata_1 = pgSqlService.ConvertToModel<ScheduleModel>(ds.Tables[1]); //值班表  
 35             List<ScheduleModel> ltdata_2 = pgSqlService.ConvertToModel<ScheduleModel>(ds.Tables[2]);//录入权限表
 36 
 37       List<ScheduleModel> dataList = new List<ScheduleModel>();
 38             var data = from t in ltdate
 39                        join t1 in ltdata_1 on t.UserName equals t1.Loginname into temp1
 40                        from a in temp1.DefaultIfEmpty()
 41                        join t2 in ltdata_2 on t.UserName equals t2.Loginname into temp2
 42                        from b in temp2.DefaultIfEmpty()
 43                        select new { t, t1 = a, t2 = b };
 44             //取出数据
 45             ScheduleModel _model;
 46 
 47             foreach (var item in data)
 48             {
 49                 _model = new ScheduleModel();
 50                 _model.Loginname = item.t.UserName;//编号
 51                 _model.Name = item.t.Des;//姓名
 52 
 53                 if (item.t1 != null || item.t2 != null)
 54                 {
 55                     #region 显示的优先顺序:班>录>休
 56 
 57                     if (item.t1 != null && item.t1.Day1.Equals(""))
 58                         _model.Day1 = item.t1.Day1;
 59                     else if (item.t2 != null && item.t2.Day1.Equals(""))
 60                         _model.Day1 = item.t2.Day1;
 61                     else { _model.Day1 = ""; }
 62   if (item.t1 != null && item.t1.Day2.Equals(""))
 63                         _model.Day2 = item.t1.Day2;
 64                     else if (item.t2 != null && item.t2.Day2.Equals(""))
 65                         _model.Day2 = item.t2.Day2;
 66                     else { _model.Day2 = ""; }
 67 
 68                     if (item.t1 != null && item.t1.Day3.Equals(""))
 69                         _model.Day3 = item.t1.Day3;
 70                     else if (item.t2 != null && item.t2.Day3.Equals(""))
 71                         _model.Day3 = item.t2.Day3;
 72                     else { _model.Day3 = ""; }
 73 
 74                     if (item.t1 != null && item.t1.Day4.Equals(""))
 75                         _model.Day4 = item.t1.Day4;
 76                     else if (item.t2 != null && item.t2.Day4.Equals(""))
 77                         _model.Day4 = item.t2.Day4;
 78                     else { _model.Day4 = ""; }
 79   if (item.t1 != null && item.t1.Day5.Equals(""))
 80                         _model.Day5 = item.t1.Day5;
 81                     else if (item.t2 != null && item.t2.Day5.Equals(""))
 82                         _model.Day5 = item.t2.Day5;
 83                     else { _model.Day5 = ""; }
 84 
 85                     if (item.t1 != null && item.t1.Day6.Equals(""))
 86                         _model.Day6 = item.t1.Day6;
 87                     else if (item.t2 != null && item.t2.Day6.Equals(""))
 88                         _model.Day6 = item.t2.Day6;
 89                     else { _model.Day6 = ""; }
 90 
 91                     if (item.t1 != null && item.t1.Day7.Equals(""))
 92                         _model.Day7 = item.t1.Day7;
 93                     else if (item.t2 != null && item.t2.Day7.Equals(""))
 94                         _model.Day7 = item.t2.Day7;
 95                     else { _model.Day7 = ""; }
 96 
 97                     if (item.t1 != null && item.t1.Day8.Equals(""))
 98                         _model.Day8 = item.t1.Day8;
 99                     else if (item.t2 != null && item.t2.Day8.Equals(""))
100                         _model.Day8 = item.t2.Day8;
101                     else { _model.Day8 = ""; }
102 
103                     if (item.t1 != null && item.t1.Day9.Equals(""))
104                         _model.Day9 = item.t1.Day9;
105                     else if (item.t2 != null && item.t2.Day9.Equals(""))
106                         _model.Day9 = item.t2.Day9;
107                     else { _model.Day9 = ""; }
108    if (item.t1 != null && item.t1.Day10.Equals(""))
109                         _model.Day10 = item.t1.Day10;
110                     else if (item.t2 != null && item.t2.Day10.Equals(""))
111                         _model.Day10 = item.t2.Day10;
112                     else { _model.Day10 = ""; }
113 
114                     if (item.t1 != null && item.t1.Day11.Equals(""))
115                         _model.Day11 = item.t1.Day11;
116                     else if (item.t2 != null && item.t2.Day11.Equals(""))
117                         _model.Day11 = item.t2.Day11;
118                     else { _model.Day11 = ""; }
119 
120                     if (item.t1 != null && item.t1.Day12.Equals(""))
121                         _model.Day12 = item.t1.Day12;
122                     else if (item.t2 != null && item.t2.Day12.Equals(""))
123                         _model.Day12 = item.t2.Day12;
124                     else { _model.Day12 = ""; }
125 
126                     if (item.t1 != null && item.t1.Day13.Equals(""))
127                         _model.Day13 = item.t1.Day13;
128                     else if (item.t2 != null && item.t2.Day13.Equals(""))
129                         _model.Day13 = item.t2.Day13;
130                     else { _model.Day13 = ""; }
131 
132                     if (item.t1 != null && item.t1.Day14.Equals(""))
133                         _model.Day14 = item.t1.Day14;
134                     else if (item.t2 != null && item.t2.Day14.Equals(""))
135                         _model.Day14 = item.t2.Day14;
136                     else { _model.Day14 = ""; }
137   if (item.t1 != null && item.t1.Day15.Equals(""))
138                         _model.Day15 = item.t1.Day15;
139                     else if (item.t2 != null && item.t2.Day15.Equals(""))
140                         _model.Day15 = item.t2.Day15;
141                     else { _model.Day15 = ""; }
142 
143                     if (item.t1 != null && item.t1.Day16.Equals(""))
144                         _model.Day16 = item.t1.Day16;
145                     else if (item.t2 != null && item.t2.Day16.Equals(""))
146                         _model.Day16 = item.t2.Day16;
147                     else { _model.Day16 = ""; }
148 
149                     if (item.t1 != null && item.t1.Day17.Equals(""))
150                         _model.Day17 = item.t1.Day17;
151                     else if (item.t2 != null && item.t2.Day17.Equals(""))
152                         _model.Day17 = item.t2.Day17;
153                     else { _model.Day17 = ""; }
154 
155                     if (item.t1 != null && item.t1.Day18.Equals(""))
156                         _model.Day18 = item.t1.Day18;
157                     else if (item.t2 != null && item.t2.Day18.Equals(""))
158                         _model.Day18 = item.t2.Day18;
159                     else { _model.Day18 = ""; }
160 
161                     if (item.t1 != null && item.t1.Day19.Equals(""))
162                         _model.Day19 = item.t1.Day19;
163                     else if (item.t2 != null && item.t2.Day19.Equals(""))
164                         _model.Day19 = item.t2.Day19;
165                     else { _model.Day19 = ""; }
166    if (item.t1 != null && item.t1.Day20.Equals(""))
167                         _model.Day20 = item.t1.Day20;
168                     else if (item.t2 != null && item.t2.Day20.Equals(""))
169                         _model.Day20 = item.t2.Day20;
170                     else { _model.Day20 = ""; }
171 
172                     if (item.t1 != null && item.t1.Day21.Equals(""))
173                         _model.Day21 = item.t1.Day21;
174                     else if (item.t2 != null && item.t2.Day21.Equals(""))
175                         _model.Day21 = item.t2.Day21;
176                     else { _model.Day21 = ""; }
177 
178                     if (item.t1 != null && item.t1.Day22.Equals(""))
179                         _model.Day22 = item.t1.Day22;
180                     else if (item.t2 != null && item.t2.Day22.Equals(""))
181                         _model.Day22 = item.t2.Day22;
182                     else { _model.Day22 = ""; }
183 
184                     if (item.t1 != null && item.t1.Day23.Equals(""))
185                         _model.Day23 = item.t1.Day23;
186                     else if (item.t2 != null && item.t2.Day23.Equals(""))
187                         _model.Day23 = item.t2.Day23;
188                     else { _model.Day23 = ""; }
189 
190                     if (item.t1 != null && item.t1.Day24.Equals(""))
191                         _model.Day24 = item.t1.Day24;
192                     else if (item.t2 != null && item.t2.Day24.Equals(""))
193                         _model.Day24 = item.t2.Day24;
194                     else { _model.Day24 = ""; }
195 
196                     if (item.t1 != null && item.t1.Day25.Equals(""))
197                         _model.Day25 = item.t1.Day25;
198                     else if (item.t2 != null && item.t2.Day25.Equals(""))
199                         _model.Day25 = item.t2.Day25;
200                     else { _model.Day25 = ""; }
201   if (item.t1 != null && item.t1.Day26.Equals(""))
202                         _model.Day26 = item.t1.Day26;
203                     else if (item.t2 != null && item.t2.Day26.Equals(""))
204                         _model.Day26 = item.t2.Day26;
205                     else { _model.Day26 = ""; }
206 
207                     if (item.t1 != null && item.t1.Day27.Equals(""))
208                         _model.Day27 = item.t1.Day27;
209                     else if (item.t2 != null && item.t2.Day27.Equals(""))
210                         _model.Day27 = item.t2.Day27;
211                     else { _model.Day27 = ""; }
212 
213                     if (item.t1 != null && item.t1.Day28.Equals(""))
214                         _model.Day28 = item.t1.Day28;
215                     else if (item.t2 != null && item.t2.Day28.Equals(""))
216                         _model.Day28 = item.t2.Day28;
217                     else { _model.Day28 = ""; }
218 
219                     if ((item.t1 != null && !string.IsNullOrEmpty(item.t1.Day29)) || (item.t2 != null && !string.IsNullOrEmpty(item.t2.Day29)))
220                     {
221   if (item.t1 != null && item.t1.Day29.Equals(""))
222                             _model.Day29 = item.t1.Day29;
223                         else if (item.t2 != null && item.t2.Day29.Equals(""))
224                             _model.Day29 = item.t2.Day29;
225                         else { _model.Day29 = ""; }
226                     }
227                     else _model.Day29 = "";
228 
229                     if ((item.t1 != null && !string.IsNullOrEmpty(item.t1.Day30)) || (item.t2 != null && !string.IsNullOrEmpty(item.t2.Day30)))
230                     {
231                         if (item.t1 != null && item.t1.Day30.Equals(""))
232                             _model.Day30 = item.t1.Day30;
233                         else if (item.t2 != null && item.t2.Day30.Equals(""))
234                             _model.Day30 = item.t2.Day30;
235                         else { _model.Day30 = ""; }
236                     }
237                     else _model.Day30 = "";
238 
239                     if ((item.t1 != null && !string.IsNullOrEmpty(item.t1.Day31)) || (item.t2 != null && !string.IsNullOrEmpty(item.t2.Day31)))
240                     {
241                         if (item.t1 != null && item.t1.Day31.Equals(""))
242                             _model.Day31 = item.t1.Day31;
243                         else if (item.t2 != null && item.t2.Day31.Equals(""))
244                             _model.Day31 = item.t2.Day31;
245                         else { _model.Day31 = ""; }
246                     }
247                     else _model.Day31 = "";
248 
249                     #endregion
250 
251                     dataList.Add(_model);
252                 }
253             }
254 
255             return dataList;
256         }
WCF
原文地址:https://www.cnblogs.com/KLLQBKY/p/9299565.html