/// <summary> /// 初始化数据 /// </summary> /// <param name="list">数据源</param> public void DataInit(IList list) { try { foreach (var item in list) { AllList.Add(item); } this.datagrid.ItemsSource = this.AllList; imgAddItem.Source = CommonMethod.GetImageSource(MhczTBG.Properties.Resources.AddItem); imgEdit.Source = CommonMethod.GetImageSource(MhczTBG.Properties.Resources.Edit); imgReflesh.Source = CommonMethod.GetImageSource(MhczTBG.Properties.Resources.Reflesh); imgSearch.Source = CommonMethod.GetImageSource(MhczTBG.Properties.Resources.Search); } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "DataInit", ex.ToString(), list); } finally { } }
/// <summary> /// 判断行数 /// </summary> /// <param name="width">父容器宽度</param> /// <returns>返回列的数量</returns> int GetWidthNum(int width) { //返回的列的数量 int countReturn = gridMain.ColumnDefinitions.Count; try { List <int> intList = new List <int>(); //获取硬性参数 for (int i = 0; i < 20; i++) { intList.Add(50 + 150 * i); } //通过硬性参数来设置 for (int i = 0; i < 20; i++) { if (width >= intList[i] && width < intList[i + 1]) { countReturn = i + 1; } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "GetWidthNum", ex.ToString(), width); } finally { } return(countReturn); }
/// <summary> /// 加载多内容的使用(多项加载) /// </summary> /// <param name="strCuLiJingGuoList">故障处理经过</param> /// <param name="splitt1">分隔符1</param> /// <param name="splitt2">分隔符2</param> public void ItemsArrageAdd(string strCuLiJingGuoList, char splitt1, char splitt2) { try { #region 设置分割符 this.split1 = splitt1; this.split2 = splitt2; #endregion //分割内容 string[] strList = strCuLiJingGuoList.Split(new char[] { split1 }); if (strList.Contains(splitt2.ToString())) { //多条加载 foreach (var item in strList) { ItemsAdd(item, splitt2); } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "ItemsArrageAdd", ex.ToString(), strCuLiJingGuoList, splitt1, splitt2); } finally { } }
/// <summary> ///刷新(更改子项数量时发生) /// </summary> public void ReFlush() { try { this.ReFlush(GetListStart(Convert.ToInt32(txtBoxSelect.Text)), whoTheList); if (PageBookCount > 0) { //如果当前页的数量大于页的总数量,那就将当前页设置为最后一页 this.PageCount = (int)Math.Ceiling(this.bookList.Count / Convert.ToDouble(PageBookCount)); } else { //如果当前页的数量大于页的总数量,那就将当前页设置为最后一页 this.PageCount = (int)Math.Ceiling(this.bookList.Count / Convert.ToDouble(1)); } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "ReFlush", ex.ToString()); } finally { } }
/// <summary> /// 书架尺寸发生更改时的事件,调整行与列 /// </summary> void TomBookShell_SizeChanged(object sender, SizeChangedEventArgs e) { try { //获取当前窗体的宽度 double width = (sender as FrameworkElement).ActualWidth; //获取当前窗体的高度 double height = (sender as FrameworkElement).ActualHeight; //通过窗体高度来设置书架的行数 this.RowCount = this.getHeightNum(Convert.ToInt32(height)); //通过窗体的宽度来设置书架的列数 this.ColumnCount = this.GetWidthNum(Convert.ToInt32(width)); if (pageNow > PageCount) { PageNow = PageCount; } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "TomBookShell_SizeChanged", ex.ToString(), sender, e); } finally { } }
void btnShiTu_Click(object sender, RoutedEventArgs e) { try { SelectColumns selection = new SelectColumns(titlelist); selection.Closed += (object sender1, EventArgs e1) => { SelectColumns quanxian2 = ((SelectColumns)sender1); bool?result = quanxian2.DialogResult; if (result.HasValue && result.Value) { titlelist.Clear(); foreach (var item in quanxian2.VisbleList) { titlelist.Add(item.Key, item.Value); } TitleInit(titlelist.Values.ToList()); } }; selection.ShowDialog(); } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "btnShiTu_Click", ex.ToString()); } }
void btExcel_Click(object sender, RoutedEventArgs e) { try { this.borTip.Visibility = System.Windows.Visibility.Visible; ThreadPool.QueueUserWorkItem((o) => { try { if (this._dataGrid.Items.Count > 0) { CommonMethod.FHDataGrid_btn_导入Excel("历史故障---" + DateTime.Now.ToShortDateString(), this._dataGrid, this.fhFormListSave, ref _excelother); } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "btExcel_Click", ex.ToString(), sender, e); } finally { } this.Dispatcher.BeginInvoke(new System.Action(() => { this.borTip.Visibility = System.Windows.Visibility.Collapsed; })); }); } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "btExcel_Click", ex.ToString()); } }
/// <summary> /// 控制向左滑动的计时器 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void timerLeft_Tick(object sender, EventArgs e) { try { //偏移量大于0,才可以向左移动 if (offset > 0) { //启动偏移 scro.ScrollToHorizontalOffset(offset); //偏移量减小(衡量的标准是左面的切点和向右的偏移) offset -= this.scro.ActualWidth / 20; } else { //到了临界点,切换标志为0 selectIndex = 0; //精确调整位置 scro.ScrollToHorizontalOffset(0); //关闭计时器 timerLeft.Stop(); CanMovingLeft = true; } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "timerLeft_Tick", ex.ToString(), sender, e); } finally { } }
/// <summary> /// 控制向右滑动的计时器 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void timerRight_Tick(object sender, EventArgs e) { try { //偏移量小于所见到的容器宽度,便可继续向左偏移 if (offset < this.bor.ActualWidth) { //启动向左偏移 scro.ScrollToHorizontalOffset(offset); //偏移位置增加 offset += this.scro.ActualWidth / 20; } else { //到了临界点,切换标志为1 selectIndex = 1; //精确调整位置 scro.ScrollToHorizontalOffset(this.bor.ActualWidth); //关闭计时器 timerRight.Stop(); CanMovingRight = true; } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "timerRight_Tick", ex.ToString(), sender, e); } finally { } }
/// <summary> /// 大小更改事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void TabChange_SizeChanged(object sender, SizeChangedEventArgs e) { try { //遍历子项 foreach (var item in this.stackPanel1.Children) { //调整宽度(这个20是因为bor设置了Pading的缘故) (item as FrameworkElement).Width = this.bor.ActualWidth; //调整切换的精确度 if (selectIndex == 1) { scro.ScrollToHorizontalOffset(this.bor.ActualWidth); } else { scro.ScrollToHorizontalOffset(0); } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "TabChange_SizeChanged", ex.ToString(), sender, e); } finally { } }
/// <summary> /// 调整精确度 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void scro_ScrollChanged(object sender, ScrollChangedEventArgs e) { try { if (CanMovingLeft && CanMovingRight) { //调整切换的精确度 if (selectIndex == 1) { scro.ScrollToHorizontalOffset(this.bor.ActualWidth); } else { scro.ScrollToHorizontalOffset(0); } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "scro_ScrollChanged", ex.ToString(), sender, e); } finally { } }
/// <summary> /// 指定类型获取标题 /// </summary> /// <param name="type">指定类型</param> /// <returns>返回所有标题</returns> List <string> GetTittleList(Type type) { //创建一个标题集合 List <string> listTittles = new List <string>(); try { //获取指定类型的属性集 PropertyInfo[] propertyInfoes = type.GetProperties(); //将所有属性名称收集 foreach (var property in propertyInfoes) { listTittles.Add(property.Name); } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "GetTittleList", ex.ToString(), type); } finally { } //返回属性集合 return(listTittles); }
/// <summary> /// 设置标题(key为标题名称,value为属性的名称) /// </summary> /// <param name="dicTittles">标题</param> public void TitleInit(Dictionary <string, string> dicTittles) { try { //清楚列表column this.datagrid.Columns.Clear(); //循环设置标题 foreach (var item in dicTittles) { //创建一个Column DataGridTextColumn column = new DataGridTextColumn(); //可以排列 column.CanUserSort = true; //可以拖动 column.CanUserReorder = true; //设置标题 column.Header = item.Key; //标题绑定 column.Binding = new Binding(item.Value); //添加标题 datagrid.Columns.Add(column); } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "TitleInit", ex.ToString(), dicTittles); } finally { } }
/// <summary> /// 设置标题 /// </summary> /// <param name="type">类型</param> public void TitleInit(Type type) { try { //清楚列表column this.datagrid.Columns.Clear(); //获取所有标题名称 List <string> listTittles = GetTittleList(type); //循环设置标题 foreach (var item in listTittles) { //创建一个Column DataGridTextColumn column = new DataGridTextColumn(); //可以排列 column.CanUserSort = true; //可以拖动 column.CanUserReorder = true; //设置标题 column.Header = item; //标题绑定 column.Binding = new Binding(item); //添加标题 datagrid.Columns.Add(column); } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "TitleInit", ex.ToString(), type); } finally { } }
void ParaMersInit() { try { //读取配置文件 string FuHeChaXunView = UIHelper.frombase(IniConfig.IniReadValue(Proxy.UserName, "FuHeChaXunView").ToString()); if (FuHeChaXunView != "") { foreach (string item in FuHeChaXunView.Split(new char[] { ';' })) { //将配置文件中的字段添加到标题字段字典 titlelist.Add(item.Split(new char[] { ',' })[0], item.Split(new char[] { ',' })[1]); } } else { titlelist.Add("ID", "ID"); titlelist.Add("附件", "附件"); titlelist.Add("startData", "故障发生日期时间"); titlelist.Add("Line", "线别"); titlelist.Add("GuZhangSheBeiMingCheng", "障碍设备名称"); titlelist.Add("GongQuMingCheng", "工区"); titlelist.Add("CheJianMingCheng", "责任单位"); titlelist.Add("ZhangAiXianXiang", "障碍现象"); titlelist.Add("YingXiangFanWei", "影响范围"); } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "ParaMersInit", ex.ToString()); } }
/// <summary> /// 选择默认模式 /// </summary> public void DataGridModeStart() { try { //创建第一个子项(特殊列表) ucDataGrid = new UcDataGrid() { MaxHeight = 655 }; //创建第二个子项(特殊Panel) ucPanel = new UcPanel() { MaxHeight = 655 }; //加载子项 this.ItemsAdd(ucDataGrid); this.ItemsAdd(ucPanel); } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "DataGridModeStart", ex.ToString()); } finally { } }
void btnSearch_Click(object sender, RoutedEventArgs e) { try { comS.expander.IsExpanded = false; TomDisPatcherLb tomdisPatcher = new TomDisPatcherLb(new System.Action(() => { DataInit(); })); TomDisPatcherLb tomdisPatcher2 = new TomDisPatcherLb(new System.Action(() => { this.borTip.Visibility = System.Windows.Visibility.Visible; CommonMethod.ReFresh(); tomdisPatcher.Start(); })); tomdisPatcher2.Start(); } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "btnSearch_Click", ex.ToString()); } }
/// <summary> /// 添加子项 /// </summary> /// <param name="control"></param> public void ItemsAdd(FrameworkElement control) { try { //该容器只能放置两个项 if (this.stackPanel1.Children.Count < 3) { //宽度调整 control.Width = this.bor.ActualWidth; //加载子项 this.stackPanel1.Children.Add(control); //第二个子项定义大小变化 if (this.stackPanel1.Children.Count == 2) { this.bor.SizeChanged += new SizeChangedEventHandler(TabChange_SizeChanged); } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "ItemsAdd", ex.ToString(), control); } finally { } }
public void TitleInit(List <string> titles) { try { this._dataGrid.Columns.Clear(); foreach (var item in titles) { if (item.Contains("附件")) { DataGridTemplateColumn column1 = new DataGridTemplateColumn(); column1.CanUserSort = true; column1.CanUserReorder = true; column1.Header = "附件"; column1.CellTemplate = (DataTemplate)this.TryFindResource("DataTemplate1"); _dataGrid.Columns.Add(column1); } else if (item.Contains("ID")) { DataGridTemplateColumn column3 = new DataGridTemplateColumn(); column3.CanUserSort = true; column3.CanUserReorder = true; column3.Header = "ID"; column3.CellTemplate = (DataTemplate)this.TryFindResource("DataTemplate2"); _dataGrid.Columns.Add(column3); } else if (item.Contains("故障发生日期时间")) { DataGridTemplateColumn column = new DataGridTemplateColumn(); column.CanUserSort = true; column.CanUserReorder = true; column.Header = "故障发生日期时间"; column.CellTemplate = (DataTemplate)this.TryFindResource("DataTemplate3"); _dataGrid.Columns.Add(column); } else if (item.Contains("责任单位")) { DataGridTemplateColumn column = new DataGridTemplateColumn(); column.CanUserSort = true; column.CanUserReorder = true; column.Header = "责任单位"; column.CellTemplate = (DataTemplate)this.TryFindResource("DataTemplate4"); _dataGrid.Columns.Add(column); } else { DataGridTextColumn column = new DataGridTextColumn(); column.CanUserSort = true; column.CanUserReorder = true; column.Header = item; column.Binding = new Binding(item); _dataGrid.Columns.Add(column); } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "TitleInit", ex.ToString(), titles); } }
/// <summary> /// 下一页 /// </summary> void Next() { try { //总页数必须大于1,翻页才有效 ,当前页需小于总页数 if (this.intPageCount > 1 && intPageNow < intPageCount) { //清除分配数据 ClearAll(); //当前页加1 intPageNow += 1; //当前页显示 this.txtNow.Text = intPageNow.ToString(); //给分配数据填充 for (int i = (intPageNow - 1) * IntPageSize; i < IntPageSize * intPageNow; i++) { if (i < list.Count) { Collection.AddNewItem(list[i]); } } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "Next", ex.ToString()); } finally { } }
public ChaXun() { try { InitializeComponent(); #region 注册事件 this.comS.btnShiTu.Click += new RoutedEventHandler(btnShiTu_Click); this.comS.btnSearch.Click += new RoutedEventHandler(btnSearch_Click); this.comS.btf3.Click += new RoutedEventHandler(btf3_Click); this.comS.btExcel.Click += new RoutedEventHandler(btExcel_Click); #endregion ParaMersInit(); TitleInit(titlelist.Values.ToList()); DataInit(); System.Windows.Application.Current.Exit += new ExitEventHandler(Current_Exit); } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "ChaXun", ex.ToString()); } }
void Last() { try { //总页数必须大于1 if (this.intPageCount > 1) { //清除分配数据 ClearAll(); //当前页为总页数,也就是最后一页 intPageNow = intPageCount; //显示页数 this.txtNow.Text = intPageNow.ToString(); // //给分配数据填充 for (int i = (intPageNow - 1) * IntPageSize; i < IntPageSize * intPageNow; i++) { if (i < list.Count) { Collection.AddNewItem(list[i]); } } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "Last", ex.ToString()); } finally { } }
/// <summary> /// 生成书架 /// </summary> void BookShellInit() { try { //书架 gridMain = new Grid(); //书架背景 if (!string.IsNullOrEmpty(BookShellImageUri)) { gridMain.Background = GetImageBrush(BookShellImageUri); } else { gridMain.Background = CommonMethod.GetImagebrush("BookShell"); } //用于调整rowCount和columnCount gridMain.SizeChanged += new SizeChangedEventHandler(TomBookShell_SizeChanged); //设置书架的行数 this.RowCount = gridMain.RowDefinitions.Count; Grid.SetRow(gridMain, 1); //添加书架 this.Children.Add(gridMain); } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "BookShellInit", ex.ToString()); } finally { } }
/// <summary> /// 将展现出的视图源进行清空,以备重新填充 /// </summary> void ClearAll() { try { if (Collection != null && Collection.Count > 0) { //是否正在执行添加子项 if (Collection.IsAddingNew) { //禁止添加子项 Collection.CancelNew(); } //是否可以移除子项 if (Collection.CanRemove) { for (int i = Collection.Count - 1; i > -1; i--) { Collection.RemoveAt(i); } } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "ClearAll", ex.ToString()); } finally { } }
/// <summary> /// 通过高度获设置行的数量 /// </summary> /// <param name="height">窗体当前高度</param> int getHeightNum(int height) { //返回的行的数量 int countReturn = 0; try { //通过硬性参数来设置 if (height >= 150 && height < 400) { countReturn = 1; } else if (height >= 400 && height < 800) { countReturn = 2; } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "getHeightNum", ex.ToString(), height); } finally { } return(countReturn); }
/// <summary> /// 复制标题(打印时用) /// </summary> /// <param name="columns">DataGridColumn</param> public void TitleInit(System.Collections.ObjectModel.ObservableCollection <DataGridColumn> columns) { try { datagrid.Columns.Clear(); //DataGridTemplateColumn column1 = new DataGridTemplateColumn(); //column1.CanUserSort = true; //column1.CanUserReorder = true; //column1.Header = "附件"; //column1.CellTemplate = (DataTemplate)this.TryFindResource("DataTemplate1"); //datagrid.Columns.Add(column1); foreach (var columnData in columns) { //if (columnData.Header.ToString().Contains("附件")) continue; DataGridTextColumn column = new DataGridTextColumn(); column.CanUserSort = true; column.CanUserReorder = true; column.Header = columnData.Header; column.Binding = new Binding(columnData.Header.ToString()); datagrid.Columns.Add(column); } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "TitleInit", ex.ToString(), columns); } finally { } }
/// <summary> /// 子项加载样式(单项加载) /// </summary> /// <param name="strCuLiJingGuo">故障处理经过</param> /// <param name="splitt2">分隔符2</param> public void ItemsAdd(string strCuLiJingGuo, char splitt2) { try { #region 设置分割符 this.split2 = splitt2; #endregion #region 设计子项 TextBox textBox = new TextBox(); textBox.Style = this.Resources["textStyle"] as Style; textBox.Text = strCuLiJingGuo; #endregion stackPanel.Children.Add(textBox); } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "ItemsAdd", ex.ToString(), strCuLiJingGuo, splitt2); } finally { } }
/// <summary> /// 初始化参数 /// </summary> void ParmesInit() { try { this.cboxYear.Style = MhczTBG.StyleResource.TongXinStyle.Instacnce.Resources["ComboBoxStyle1"] as Style; this.btnAddGuzhang.Style = this.btnShiTu.Style = MhczTBG.StyleResource.TongXinStyle.Instacnce.Resources["btnStyle9"] as Style; for (int i = 0; i < 5; i++) { ComboBoxItem conboxitem = new ComboBoxItem(); conboxitem.Content = string.Format("{0}年", DateTime.Now.Year - i); conboxitem.Tag = DateTime.Now.Year - i; this.cboxYear.Items.Add(conboxitem); } this.cboxYear.SelectedIndex = 0; one.Style = two.Style = three.Style = fore.Style = five.Style = six.Style = seven.Style = eight.Style = nine.Style = ten.Style = eleven.Style = twelve.Style = MhczTBG.StyleResource.TongXinStyle.Instacnce.Resources["btnStyle10"] as Style; } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "ParmesInit", ex.ToString()); } finally { } }
/// <summary> /// 设计规则 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void StackPanel_Loaded(object sender, RoutedEventArgs e) { try { if (sender is StackPanel && (sender as StackPanel).Tag != null && (sender as StackPanel).Children.Count > 1) { ///获取到承载体(模板里的) var stackPanel = sender as StackPanel; if (stackPanel.Children[0] is TextBox && stackPanel.Children[1] is TextBox) { string strChuLiJinGuo = stackPanel.Tag.ToString(); //一条信息的panel(故障经过不为空,而且至少必须有两个&分割符) if (!string.IsNullOrEmpty(strChuLiJinGuo) && strChuLiJinGuo.Count(Item => Item.Equals(split2)) > 1) { //分割(获取时间和内容) string[] str = strChuLiJinGuo.Split(new char[] { split2 }); //设置显示时间的文本 (stackPanel.Children[0] as TextBox).Text = str[0] + " " + str[1] + ":"; //设置显示内容的文本 (stackPanel.Children[1] as TextBox).Text = str[2]; } } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "StackPanel_Loaded", ex.ToString(), sender, e); } finally { } }
/// <summary> /// 皮肤更换 /// </summary> /// <param name="color">指定颜色</param> public void SkinChange(Color color) { try { (this.Resources["backBrush"] as LinearGradientBrush).GradientStops[1].Color = color; (this.Resources["ArrowBrush"] as SolidColorBrush).Color = color; (this.Resources["btnBrush"] as LinearGradientBrush).GradientStops[1].Color = color; foreach (var item in listBoxItemList) { if (item != selectBoxItem) { item.Foreground = this.Resources["btnBrush"] as LinearGradientBrush; } } (this.Resources["linEnter"] as LinearGradientBrush).GradientStops[1].Color = color; (this.Resources["daohangBrush"] as LinearGradientBrush).GradientStops[0].Color = color; (this.Resources["daohangBrush"] as LinearGradientBrush).GradientStops[2].Color = color; } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "SkinChange", ex.ToString(), color); } finally { } }