Exemple #1
0
        //private List<int> sumColumns = new List<int>();

        public void SetDataTable(DataTable _dt, string title, List <int> columnNumbers)
        {
            this.dt            = _dt.Copy();
            this.title         = title;
            this.columnNumbers = columnNumbers;
            _title.Text        = "▪ " + title;

            _gridview.Columns.Clear();
            foreach (DataColumn c in dt.Columns)
            {
                GridViewColumn gvc = new GridViewColumn();
                gvc.Header = c.ColumnName;
                if (BShowDetails)
                {
                    gvc.Width = (_listview.ActualWidth - 65) / dt.Columns.Count;
                }
                else
                {
                    gvc.Width = (_listview.ActualWidth - 25) / dt.Columns.Count;
                }
                //gvc.DisplayMemberBinding = (new Binding(c.ColumnName));
                FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
                text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                text.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
                text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
                DataTemplate dataTemplate = new DataTemplate()
                {
                    VisualTree = text
                };
                gvc.CellTemplate = dataTemplate;
                gvc.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);
                _gridview.Columns.Add(gvc);
            }
            if (BShowDetails)
            {
                GridViewColumn gvc_details = new GridViewColumn();
                gvc_details.Header = "详情";
                FrameworkElementFactory button_details = new FrameworkElementFactory(typeof(Button));
                button_details.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_details.SetValue(Button.WidthProperty, 40.0);
                button_details.AddHandler(Button.ClickEvent, new RoutedEventHandler(details_Click));
                button_details.SetBinding(Button.TagProperty, new Binding(dt.Columns[1].ColumnName));
                button_details.SetValue(Button.ContentProperty, ">>");
                button_details.SetValue(Button.ForegroundProperty, Brushes.Blue);
                button_details.SetValue(Button.FontSizeProperty, 14.0);
                button_details.SetBinding(Button.VisibilityProperty, new Binding(dt.Columns[0].ColumnName)
                {
                    Converter = new VisibleBtnConverter()
                });
                DataTemplate dataTemplate_details = new DataTemplate()
                {
                    VisualTree = button_details
                };
                gvc_details.CellTemplate = dataTemplate_details;
                _gridview.Columns.Add(gvc_details);
            }
            _listview.ItemsSource = dt.DefaultView;
        }
Exemple #2
0
 void UcTableView_SizeChanged(object sender, SizeChangedEventArgs e)
 {
     if (dt == null)
     {
         return;
     }
     _gridview.Columns.Clear();
     foreach (DataColumn c in dt.Columns)
     {
         GridViewColumn gvc = new GridViewColumn();
         gvc.Header = c.ColumnName;
         if (BShowDetails)
         {
             gvc.Width = (_listview.ActualWidth - 65) / dt.Columns.Count;
         }
         else
         {
             gvc.Width = (_listview.ActualWidth - 25) / dt.Columns.Count;
         }
         gvc.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);
         //gvc.DisplayMemberBinding = (new Binding(c.ColumnName));
         FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
         text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
         text.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
         text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
         DataTemplate dataTemplate = new DataTemplate()
         {
             VisualTree = text
         };
         gvc.CellTemplate = dataTemplate;
         _gridview.Columns.Add(gvc);
     }
     if (BShowDetails)
     {
         GridViewColumn gvc_details = new GridViewColumn();
         gvc_details.Header = "详情";
         FrameworkElementFactory button_details = new FrameworkElementFactory(typeof(Button));
         button_details.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
         button_details.SetValue(Button.WidthProperty, 40.0);
         button_details.AddHandler(Button.ClickEvent, new RoutedEventHandler(details_Click));
         button_details.SetBinding(Button.TagProperty, new Binding(dt.Columns[1].ColumnName));
         button_details.SetValue(Button.ContentProperty, ">>");
         button_details.SetValue(Button.ForegroundProperty, Brushes.Blue);
         button_details.SetValue(Button.FontSizeProperty, 14.0);
         button_details.SetBinding(Button.VisibilityProperty, new Binding(dt.Columns[0].ColumnName)
         {
             Converter = new VisibleBtnConverter()
         });
         DataTemplate dataTemplate_details = new DataTemplate()
         {
             VisualTree = button_details
         };
         gvc_details.CellTemplate = dataTemplate_details;
         _gridview.Columns.Add(gvc_details);
     }
     _listview.ItemsSource = null;
     _listview.ItemsSource = dt.DefaultView;
 }
        /// <inheritdoc/>
        protected override void Write(WpfRenderer renderer, LinkInline link)
        {
            if (renderer == null)
            {
                throw new ArgumentNullException(nameof(renderer));
            }
            if (link == null)
            {
                throw new ArgumentNullException(nameof(link));
            }

            var url = link.GetDynamicUrl != null?link.GetDynamicUrl() ?? link.Url : link.Url;

            if (!Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
            {
                url = "#";
            }

            if (link.IsImage)
            {
                var template = new ControlTemplate();
                var image    = new FrameworkElementFactory(typeof(Image));
                image.SetValue(Image.SourceProperty, new BitmapImage(new Uri(url, UriKind.RelativeOrAbsolute)));
                image.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.ImageStyleKey);
                template.VisualTree = image;

                var btn = new Button()
                {
                    Template         = template,
                    Command          = Commands.Image,
                    CommandParameter = url
                };

                renderer.WriteInline(new InlineUIContainer(btn));
            }
            else
            {
                var hyperlink = new Hyperlink
                {
                    Command          = Commands.Hyperlink,
                    CommandParameter = url,
                    NavigateUri      = new Uri(url, UriKind.RelativeOrAbsolute),
                    ToolTip          = !string.IsNullOrEmpty(link.Title) ? link.Title : null,
                };

                hyperlink.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.HyperlinkStyleKey);

                renderer.Push(hyperlink);
                renderer.WriteChildren(link);
                renderer.Pop();
            }
        }
        private void update()
        {
            if (table == null)
            {
                return;
            }
            _gridview.Columns.Clear();
            //int sumWidth = 0;
            //for (int j = 0; j < table.Columns.Count; j++)
            //{
            //    int maxWidth = System.Text.Encoding.Default.GetByteCount(table.Columns[j].ColumnName.ToString());
            //    for (int i = 0; i < table.Rows.Count; i++)
            //    {
            //        if (maxWidth < System.Text.Encoding.Default.GetByteCount(table.Rows[i][j].ToString().Trim()))
            //        {
            //            maxWidth = System.Text.Encoding.Default.GetByteCount(table.Rows[i][j].ToString().Trim());
            //        }
            //    }
            //    sumWidth += maxWidth;
            //    myColumns[table.Columns[j].ColumnName.ToLower()].Width = maxWidth;
            //}
            for (int i = 0; i < table.Columns.Count; i++)
            {
                DataColumn c = table.Columns[i];
                if (myColumns[c.ColumnName.ToLower()].Column_show == "总行数")
                {
                    if (table.Rows.Count != 0)
                    {
                        RowTotal  = Convert.ToInt32(table.Rows[0][c.ColumnName].ToString());
                        PageTotal = (int)Math.Ceiling((double)RowTotal / (double)RowMax);
                    }
                    else
                    {
                        RowTotal  = 0;
                        PageTotal = 0;
                    }
                }


                if (!myColumns[c.ColumnName.ToLower()].BShow)
                {
                    continue;
                }
                GridViewColumn gvc = new GridViewColumn();
                gvc.Header = myColumns[c.ColumnName.ToLower()].Column_show;
                FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
                text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                text.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
                text.SetBinding(TextBlock.ForegroundProperty, new Binding(c.ColumnName)
                {
                    Converter = new RedFontConverter()
                });
                if (table.Columns[i].ColumnName.ToLower().Contains("date"))
                {
                    text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
                }
                else
                {
                    text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
                }
                //当检测结果是疑似阳性或者阳性时,内容为红色
                if (myColumns[c.ColumnName.ToLower()].Column_show == "疑似阳性" || myColumns[c.ColumnName.ToLower()].Column_show == "阳性")
                {
                    text.SetValue(TextBlock.ForegroundProperty, Brushes.Red);
                }

                DataTemplate dataTemplate = new DataTemplate()
                {
                    VisualTree = text
                };
                gvc.CellTemplate = dataTemplate;
                gvc.Width        = 10 * myColumns[c.ColumnName.ToLower()].Width;
                _gridview.Columns.Add(gvc);
            }
            if (BShowModify)
            {
                GridViewColumn gvc_modify = new GridViewColumn();
                gvc_modify.Header = "修改";
                FrameworkElementFactory button_modify = new FrameworkElementFactory(typeof(Button));
                button_modify.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_modify.SetValue(Button.WidthProperty, 20.0);
                button_modify.AddHandler(Button.ClickEvent, new RoutedEventHandler(modify_Click));
                button_modify.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
                button_modify.SetResourceReference(Button.StyleProperty, "ListModifyImageButtonTemplate");
                DataTemplate dataTemplate_modify = new DataTemplate()
                {
                    VisualTree = button_modify
                };
                gvc_modify.CellTemplate = dataTemplate_modify;
                _gridview.Columns.Add(gvc_modify);
            }

            if (BShowDelete)
            {
                GridViewColumn gvc_delete = new GridViewColumn();
                gvc_delete.Header = "删除";
                FrameworkElementFactory button_delete = new FrameworkElementFactory(typeof(Button));
                button_delete.SetValue(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_delete.SetValue(Button.WidthProperty, 20.0);
                button_delete.AddHandler(Button.ClickEvent, new RoutedEventHandler(delete_Click));
                button_delete.SetResourceReference(Button.StyleProperty, "ListDeleteImageButtonTemplate");
                button_delete.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
                DataTemplate dataTemplate_delete = new DataTemplate()
                {
                    VisualTree = button_delete
                };

                gvc_delete.CellTemplate = dataTemplate_delete;
                _gridview.Columns.Add(gvc_delete);
            }

            if (BShowDetails)
            {
                GridViewColumn gvc_details = new GridViewColumn();
                gvc_details.Header = "详情";
                FrameworkElementFactory button_details = new FrameworkElementFactory(typeof(Button));
                button_details.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_details.SetValue(Button.WidthProperty, 40.0);
                button_details.AddHandler(Button.ClickEvent, new RoutedEventHandler(details_Click));
                button_details.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
                //button_details.SetResourceReference(Button.StyleProperty, "ListDetailsImageButtonTemplate");
                button_details.SetValue(Button.ContentProperty, ">>");
                button_details.SetValue(Button.ForegroundProperty, Brushes.White);
                button_details.SetValue(Button.FontSizeProperty, 14.0);
                //button_details.SetValue(Button.FontFamilyProperty, "黑体");
                DataTemplate dataTemplate_details = new DataTemplate()
                {
                    VisualTree = button_details
                };
                gvc_details.CellTemplate = dataTemplate_details;
                _gridview.Columns.Add(gvc_details);
            }
            if (BShowState)
            {
                GridViewColumn gvc_state = new GridViewColumn();
                gvc_state.Header = "状态";
                FrameworkElementFactory button_state = new FrameworkElementFactory(typeof(Button));
                button_state.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_state.SetValue(Button.WidthProperty, 60.0);
                button_state.AddHandler(Button.ClickEvent, new RoutedEventHandler(state_Click));
                button_state.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
                button_state.SetBinding(Button.ContentProperty, new Binding(table.Columns[1].ColumnName));
                button_state.SetValue(Button.ForegroundProperty, Brushes.White);
                button_state.SetValue(Button.FontSizeProperty, 12.0);

                DataTemplate dataTemplate_state = new DataTemplate()
                {
                    VisualTree = button_state
                };
                gvc_state.CellTemplate = dataTemplate_state;
                _gridview.Columns.Add(gvc_state);
            }

            if (BShowSold)
            {
                GridViewColumn gvc_sold = new GridViewColumn();
                gvc_sold.Header = "出栏";
                FrameworkElementFactory button_sold = new FrameworkElementFactory(typeof(Button));
                button_sold.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_sold.SetValue(Button.WidthProperty, 40.0);
                button_sold.AddHandler(Button.ClickEvent, new RoutedEventHandler(Sold_Click));
                button_sold.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
                //button_sold.SetResourceReference(Button.StyleProperty, "ListDetailsImageButtonTemplate");
                button_sold.SetValue(Button.ContentProperty, "出栏");
                button_sold.SetValue(Button.ForegroundProperty, Brushes.White);
                button_sold.SetValue(Button.FontSizeProperty, 14.0);
                //button_sold.SetValue(Button.FontFamilyProperty, "黑体");
                DataTemplate dataTemplate_sold = new DataTemplate()
                {
                    VisualTree = button_sold
                };
                gvc_sold.CellTemplate = dataTemplate_sold;
                _gridview.Columns.Add(gvc_sold);
            }
            _listview.ItemsSource = null;
            _listview.ItemsSource = table.DefaultView;

            if (PageTotal > 1)
            {
                _page.Visibility = Visibility.Visible;
            }
            else
            {
                _page.Visibility = Visibility.Hidden;
            }
        }
Exemple #5
0
        private DataGridColumn CreateColumn([NotNull] string weaver)
        {
            var configurationBindingPath = "Configuration[" + weaver + "]";
            var configurationBinding     = new Binding(configurationBindingPath);

            var contentStyle = new Style(typeof(ContentControl))
            {
                Setters = { new Setter {
                                Property = ContentControl.ContentProperty, Value = configurationBinding
                            } },
                Triggers =
                {
                    new DataTrigger {
                        Binding = configurationBinding, Value = -1, Setters ={ new Setter                                           {
                                          Property = ContentControl.ContentProperty, Value = null
                                      } }
                    },
                    new DataTrigger {
                        Binding = configurationBinding, Value = 0, Setters ={ new Setter                                           {
                                          Property = ContentControl.ContentProperty, Value = "S"
                                      } }
                    },
                }
            };

            // ReSharper disable AssignNullToNotNullAttribute
            var visualTree = new FrameworkElementFactory(typeof(Border));

            visualTree.SetBinding(Border.BackgroundProperty, new Binding(configurationBindingPath)
            {
                Converter = _indexToBrushConverter
            });

            var content = new FrameworkElementFactory(typeof(ContentControl));

            content.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center);
            content.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);
            content.SetValue(FrameworkElement.StyleProperty, contentStyle);
            content.SetResourceReference(TextElement.ForegroundProperty, SystemColors.WindowTextBrushKey);
            visualTree.AppendChild(content);
            // ReSharper restore AssignNullToNotNullAttribute

            var header = new TextBlock
            {
                Text            = weaver,
                LayoutTransform = new RotateTransform(-90),
                Margin          = new Thickness(2)
            };

            TextOptions.SetTextRenderingMode(header, TextRenderingMode.Grayscale);

            var column = new DataGridTemplateColumn
            {
                Header         = header,
                CanUserResize  = false,
                SortMemberPath = configurationBindingPath,
                CellTemplate   = new DataTemplate(typeof(int))
                {
                    VisualTree = visualTree
                }
            };

            column.SetIsFilterVisible(false);

            return(column);
        }
        private void update()
        {
            if (table == null)
            {
                return;
            }

            //int sumWidth = 0;
            //for (int j = 0; j < table.Columns.Count; j++)
            //{
            //    int maxWidth = System.Text.Encoding.Default.GetByteCount(table.Columns[j].ColumnName.ToString());
            //    for (int i = 0; i < table.Rows.Count; i++)
            //    {
            //        if (maxWidth < System.Text.Encoding.Default.GetByteCount(table.Rows[i][j].ToString().Trim()))
            //        {
            //            maxWidth = System.Text.Encoding.Default.GetByteCount(table.Rows[i][j].ToString().Trim());
            //        }
            //    }
            //    sumWidth += maxWidth;
            //    myColumns[table.Columns[j].ColumnName.ToLower()].Width = maxWidth;
            //}

            _gridview.Columns.Clear();
            for (int i = 0; i < table.Columns.Count; i++)
            {
                DataColumn c = table.Columns[i];

                if (!myColumns[c.ColumnName.ToLower()].BShow)
                {
                    continue;
                }
                GridViewColumn gvc = new GridViewColumn();
                gvc.Header = myColumns[c.ColumnName.ToLower()].Column_show;
                FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
                text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                text.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
                if (table.Columns[i].ColumnName.ToLower().Contains("date"))
                {
                    text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
                }
                else
                {
                    text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
                }

                //当列为任务完成率和任务总完成率时,显示为红色
                if (myColumns[c.ColumnName.ToLower()].Column_show == "任务完成率" || myColumns[c.ColumnName.ToLower()].Column_show == "任务总完成率" ||
                    myColumns[c.ColumnName.ToLower()].Column_show == "抽检率" || myColumns[c.ColumnName.ToLower()].Column_show == "综合平均抽检率")
                {
                    text.SetValue(TextBlock.ForegroundProperty, Brushes.Blue);
                }

                //当检测结果是疑似阳性或者阳性时,内容为红色
                if (myColumns[c.ColumnName.ToLower()].Column_show == "疑似阳性样本" || myColumns[c.ColumnName.ToLower()].Column_show == "阳性样本")
                {
                    text.SetValue(TextBlock.ForegroundProperty, Brushes.Red);
                }

                DataTemplate dataTemplate = new DataTemplate()
                {
                    VisualTree = text
                };
                gvc.CellTemplate = dataTemplate;
                gvc.Width        = 12 * myColumns[c.ColumnName.ToLower()].Width;
                _gridview.Columns.Add(gvc);
            }
            if (BShowModify)
            {
                GridViewColumn gvc_modify = new GridViewColumn();
                gvc_modify.Width  = 60;
                gvc_modify.Header = "设置";
                FrameworkElementFactory button_modify = new FrameworkElementFactory(typeof(Button));
                button_modify.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_modify.SetValue(Button.WidthProperty, 20.0);
                button_modify.AddHandler(Button.ClickEvent, new RoutedEventHandler(modify_Click));
                button_modify.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
                button_modify.SetResourceReference(Button.StyleProperty, "ListSetImageButtonTemplate");
                button_modify.SetBinding(Button.VisibilityProperty, new Binding(table.Columns[0].ColumnName)
                {
                    Converter = new VisibleBtnConverter()
                });
                DataTemplate dataTemplate_modify = new DataTemplate()
                {
                    VisualTree = button_modify
                };
                gvc_modify.CellTemplate = dataTemplate_modify;
                _gridview.Columns.Add(gvc_modify);
            }

            if (BShowDelete)
            {
                GridViewColumn gvc_delete = new GridViewColumn();
                gvc_delete.Header = "删除";
                FrameworkElementFactory button_delete = new FrameworkElementFactory(typeof(Button));
                button_delete.SetValue(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_delete.SetValue(Button.WidthProperty, 20.0);
                button_delete.AddHandler(Button.ClickEvent, new RoutedEventHandler(delete_Click));
                button_delete.SetResourceReference(Button.StyleProperty, "ListDeleteImageButtonTemplate");
                button_delete.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
                DataTemplate dataTemplate_delete = new DataTemplate()
                {
                    VisualTree = button_delete
                };

                gvc_delete.CellTemplate = dataTemplate_delete;
                _gridview.Columns.Add(gvc_delete);
            }

            if (BShowDetails)
            {
                GridViewColumn gvc_details = new GridViewColumn();
                gvc_details.Header = "详情";
                FrameworkElementFactory button_details = new FrameworkElementFactory(typeof(Button));
                button_details.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_details.SetValue(Button.WidthProperty, 40.0);
                button_details.AddHandler(Button.ClickEvent, new RoutedEventHandler(details_Click));
                button_details.SetBinding(Button.TagProperty, new Binding(table.Columns[1].ColumnName));
                //button_details.SetResourceReference(Button.StyleProperty, "ListDetailsImageButtonTemplate");
                button_details.SetValue(Button.ContentProperty, ">>");
                button_details.SetValue(Button.ForegroundProperty, Brushes.White);
                button_details.SetValue(Button.FontSizeProperty, 14.0);
                button_details.SetBinding(Button.VisibilityProperty, new Binding(table.Columns[0].ColumnName)
                {
                    Converter = new VisibleBtnConverter()
                });
                //button_details.SetValue(Button.FontFamilyProperty, "黑体");
                DataTemplate dataTemplate_details = new DataTemplate()
                {
                    VisualTree = button_details
                };
                gvc_details.CellTemplate = dataTemplate_details;
                _gridview.Columns.Add(gvc_details);
            }

            if (BShowState)
            {
                GridViewColumn gvc_state = new GridViewColumn();
                gvc_state.Header = "状态";
                FrameworkElementFactory button_state = new FrameworkElementFactory(typeof(Button));
                button_state.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_state.SetValue(Button.WidthProperty, 20.0);
                button_state.AddHandler(Button.ClickEvent, new RoutedEventHandler(state_Click));
                button_state.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
                button_state.SetBinding(Button.ContentProperty, new Binding(table.Columns[1].ColumnName));

                if (button_state.Text == "0")
                {
                    button_state.SetResourceReference(Button.StyleProperty, "AddImageImageButtonTemplate");
                }
                else //if (button_state.Text == "1")
                {
                    button_state.SetResourceReference(Button.StyleProperty, "ListModifyImageButtonTemplate");
                }
                DataTemplate dataTemplate_state = new DataTemplate()
                {
                    VisualTree = button_state
                };
                gvc_state.CellTemplate = dataTemplate_state;
                _gridview.Columns.Add(gvc_state);
            }
            _listview.ItemsSource = null;
            _listview.ItemsSource = table.DefaultView;
        }
        private void update()
        {
            if (table == null)
            {
                return;
            }

            int sumWidth = 0;

            for (int j = 0; j < table.Columns.Count; j++)
            {
                int maxWidth = System.Text.Encoding.Default.GetByteCount(table.Columns[j].ColumnName.ToString());
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    if (maxWidth < System.Text.Encoding.Default.GetByteCount(table.Rows[i][j].ToString().Trim()))
                    {
                        maxWidth = System.Text.Encoding.Default.GetByteCount(table.Rows[i][j].ToString().Trim());
                    }
                }
                sumWidth += maxWidth;
                myColumns[table.Columns[j].ColumnName.ToLower()].Width = maxWidth;
            }

            _gridview.Columns.Clear();
            for (int i = 0; i < table.Columns.Count; i++)
            {
                DataColumn c = table.Columns[i];

                if (!myColumns[c.ColumnName.ToLower()].BShow)
                {
                    continue;
                }
                GridViewColumn gvc = new GridViewColumn();
                gvc.Header = myColumns[c.ColumnName.ToLower()].Column_show;
                FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
                text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                text.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
                if (table.Columns[i].ColumnName.ToLower().Contains("date"))
                {
                    text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
                }
                else
                {
                    text.SetBinding(TextBlock.TextProperty, new Binding(c.ColumnName));
                }

                DataTemplate dataTemplate = new DataTemplate()
                {
                    VisualTree = text
                };
                gvc.CellTemplate = dataTemplate;
                gvc.Width        = 12 * myColumns[c.ColumnName.ToLower()].Width;
                _gridview.Columns.Add(gvc);
            }
            if (BShowModify)
            {
                GridViewColumn gvc_modify = new GridViewColumn();
                gvc_modify.Header = "修改";
                FrameworkElementFactory button_modify = new FrameworkElementFactory(typeof(Button));
                button_modify.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_modify.SetValue(Button.WidthProperty, 20.0);
                button_modify.AddHandler(Button.ClickEvent, new RoutedEventHandler(modify_Click));
                button_modify.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
                button_modify.SetResourceReference(Button.StyleProperty, "ListModifyImageButtonTemplate");
                DataTemplate dataTemplate_modify = new DataTemplate()
                {
                    VisualTree = button_modify
                };
                gvc_modify.CellTemplate = dataTemplate_modify;
                _gridview.Columns.Add(gvc_modify);
            }

            if (BShowDelete)
            {
                GridViewColumn gvc_delete = new GridViewColumn();
                gvc_delete.Header = "删除";
                FrameworkElementFactory button_delete = new FrameworkElementFactory(typeof(Button));
                button_delete.SetValue(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_delete.SetValue(Button.WidthProperty, 20.0);
                button_delete.AddHandler(Button.ClickEvent, new RoutedEventHandler(delete_Click));
                button_delete.SetResourceReference(Button.StyleProperty, "ListDeleteImageButtonTemplate");
                button_delete.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
                DataTemplate dataTemplate_delete = new DataTemplate()
                {
                    VisualTree = button_delete
                };

                gvc_delete.CellTemplate = dataTemplate_delete;
                _gridview.Columns.Add(gvc_delete);
            }

            if (BShowDetails)
            {
                GridViewColumn gvc_details = new GridViewColumn();
                gvc_details.Header = "详情";
                FrameworkElementFactory button_details = new FrameworkElementFactory(typeof(Button));
                button_details.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_details.SetValue(Button.WidthProperty, 20.0);
                button_details.AddHandler(Button.ClickEvent, new RoutedEventHandler(details_Click));
                button_details.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
                button_details.SetResourceReference(Button.StyleProperty, "ListModifyImageButtonTemplate");
                DataTemplate dataTemplate_details = new DataTemplate()
                {
                    VisualTree = button_details
                };
                gvc_details.CellTemplate = dataTemplate_details;
                _gridview.Columns.Add(gvc_details);
            }

            if (BShowState)
            {
                GridViewColumn gvc_state = new GridViewColumn();
                gvc_state.Header = "状态";
                FrameworkElementFactory button_state = new FrameworkElementFactory(typeof(Button));
                button_state.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                button_state.SetValue(Button.WidthProperty, 20.0);
                button_state.AddHandler(Button.ClickEvent, new RoutedEventHandler(state_Click));
                button_state.SetBinding(Button.TagProperty, new Binding(table.Columns[0].ColumnName));
                button_state.SetBinding(Button.ContentProperty, new Binding(table.Columns[1].ColumnName));

                if (button_state.Text == "0")
                {
                    button_state.SetResourceReference(Button.StyleProperty, "AddImageImageButtonTemplate");
                }
                else //if (button_state.Text == "1")
                {
                    button_state.SetResourceReference(Button.StyleProperty, "ListModifyImageButtonTemplate");
                }
                DataTemplate dataTemplate_state = new DataTemplate()
                {
                    VisualTree = button_state
                };
                gvc_state.CellTemplate = dataTemplate_state;
                _gridview.Columns.Add(gvc_state);
            }
            _listview.ItemsSource = null;
            _listview.ItemsSource = table.DefaultView;
        }