public bool SetRenderMainUI() { #region 计量业务信息控制 if (gridReader != null && gridReader.Children != null) { gridReader.Children.Clear(); } for (int i = gridReader.RowDefinitions.Count - 1; i > -1; i--) { gridReader.RowDefinitions.RemoveAt(i); } for (int i = gridReader.ColumnDefinitions.Count - 1; i > -1; i--) { gridReader.ColumnDefinitions.RemoveAt(i); } //增加判断 供方毛皮净 以及扣重 不再在动态列表显示……lt 2016-2-3 08:58:51…… List <RenderUI> getBullInfo = ReaderInfoList.Where(p => p.aboutweight == 0 && p.isdisplay == 1 && p.fieldname != "tareb" && p.fieldname != "grossb" && p.fieldname != "suttleb" && p.fieldname != "deduction").OrderBy(o => o.orderno).ToList <RenderUI>(); ColumnDefinition cd1 = new ColumnDefinition(); cd1.Width = new System.Windows.GridLength(70); ColumnDefinition cd2 = new ColumnDefinition(); ColumnDefinition cd3 = new ColumnDefinition(); cd3.Width = new System.Windows.GridLength(70); ColumnDefinition cd4 = new ColumnDefinition(); gridReader.ColumnDefinitions.Add(cd1); gridReader.ColumnDefinitions.Add(cd2); gridReader.ColumnDefinitions.Add(cd3); gridReader.ColumnDefinitions.Add(cd4); int columnNum = 0; int rowNum = 0;//控件添加在哪一行 lt 2016-2-3 09:36:46…… Color color = (Color)ColorConverter.ConvertFromString("#636363"); for (int i = 0; i <= getBullInfo.Count - 1; i++) { RowDefinition rd = new RowDefinition(); if (getBullInfo.Count > 12) { rd.Height = new System.Windows.GridLength(45); } else { rd.Height = new System.Windows.GridLength(50); } gridReader.RowDefinitions.Add(rd); TextBlock tb1 = getLableTB(); tb1.Text = getBullInfo[i].displayname; tb1.SetValue(Grid.RowProperty, rowNum); tb1.SetValue(Grid.ColumnProperty, columnNum);//0 tb1.Foreground = new SolidColorBrush(color); gridReader.Children.Add(tb1); columnNum = columnNum + 1; bool isBold = ComHelpClass.CheckIsFontWeightBold(getBullInfo[i].fieldname); TextBox tb2 = (i == 0 ? getInputTB(true) : getInputTB(false)); if (getBullInfo[i].quicksuggest == 1) { tb2.KeyDown += tb2_KeyDown; } tb2.TextWrapping = System.Windows.TextWrapping.Wrap; tb2.Name = getBullInfo[i].fieldname; tb2.VerticalContentAlignment = VerticalAlignment.Center; tb2.IsReadOnly = getBullInfo[i].writeable == 0?true:false;//0只读 1 可编辑 tb2.SetBinding(TextBox.TextProperty, new Binding(getBullInfo[i].fieldname) { Source = BindObject, Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); tb2.SetValue(Grid.RowProperty, rowNum); tb2.SetValue(Grid.ColumnProperty, columnNum);//1 if (isBold) { tb2.FontWeight = FontWeights.Bold; } gridReader.Children.Add(tb2); columnNum = columnNum + 1; bool checkIsOneRow = ComHelpClass.CheckIsOneRow(getBullInfo[i].fieldname);//文本框 是不是一行显示出来……lt 2016-2-3 09:17:49…… if (checkIsOneRow) { tb2.SetValue(Grid.ColumnSpanProperty, 3); columnNum = 0; rowNum = rowNum + 1; continue; } //todo: lt 2016-1-27 19:10:44…… 两个一组 奇数时 不存在第二个 错误:大于索引退出 …… if (i + 1 >= getBullInfo.Count) { break; } checkIsOneRow = ComHelpClass.CheckIsOneRow(getBullInfo[i + 1].fieldname);//如果第一个不是 第二个是 则直接换行…… 2016-2-3 09:57:12 if (checkIsOneRow) { columnNum = 0; rowNum = rowNum + 1; continue; } isBold = ComHelpClass.CheckIsFontWeightBold(getBullInfo[i + 1].fieldname); TextBlock tb3 = getLableTB(); tb3.Text = getBullInfo[i + 1].displayname; tb3.SetValue(Grid.RowProperty, rowNum); tb3.SetValue(Grid.ColumnProperty, columnNum);//2 tb3.Foreground = new SolidColorBrush(color); gridReader.Children.Add(tb3); columnNum = columnNum + 1; TextBox tb4 = (i == 0 ? getInputTB(true) : getInputTB(false)); if (getBullInfo[i + 1].quicksuggest == 1) { tb4.KeyDown += tb2_KeyDown; } tb4.TextWrapping = System.Windows.TextWrapping.Wrap; tb4.Name = getBullInfo[i + 1].fieldname; tb4.VerticalContentAlignment = VerticalAlignment.Center; tb4.IsReadOnly = getBullInfo[i + 1].writeable == 0 ? true : false;//0只读 1 可编辑 tb4.SetBinding(TextBox.TextProperty, new Binding(getBullInfo[i + 1].fieldname) { Source = BindObject, Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); //tb4.Text = "测试测试测试测试测试测试"; tb4.SetValue(Grid.RowProperty, rowNum); tb4.SetValue(Grid.ColumnProperty, columnNum);//3 if (isBold) { tb4.FontWeight = FontWeights.Bold; } gridReader.Children.Add(tb4); columnNum = 0; rowNum = rowNum + 1; i++; } #endregion int isDisplay = 0; #region 供方信息控制 //增加异常抛出 解决若不存在 供方信息时 则报 未将对象引用到实例的错误…… lt 2016-1-28 10:41:54 try { int tareBDis = ReaderInfoList.Where(p => p.fieldname == "tareb").FirstOrDefault().isdisplay; int grossbDis = ReaderInfoList.Where(p => p.fieldname == "grossb").FirstOrDefault().isdisplay; int suttlebDis = ReaderInfoList.Where(p => p.fieldname == "suttleb").FirstOrDefault().isdisplay; isDisplay = tareBDis * grossbDis * suttlebDis; //int isDisplay = ReaderInfoList.Where(p => p.fieldname == "tareb").FirstOrDefault().isdisplay * ReaderInfoList.Where(p => p.fieldname == "grossb").FirstOrDefault().isdisplay * ReaderInfoList.Where(p => p.fieldname == "suttleb").FirstOrDefault().isdisplay; if (isDisplay == 0) { gridSupplier.Visibility = Visibility.Collapsed; } else { gridSupplier.Visibility = Visibility.Visible; } } catch //(Exception ex) { } #endregion #region 称量信息控制 //解决扣重未配置时的错误…… lt 2016-1-28 10:43:26 try { isDisplay = 0; isDisplay = ReaderInfoList.Where(p => p.fieldname == "deduction").FirstOrDefault().isdisplay; //扣重是否显示 } catch //(Exception ex) { } //isDisplay = ReaderInfoList.Where(p => p.fieldname == "deduction").FirstOrDefault().isdisplay;//扣重是否显示 var getMinusDeduction = gridMeasureWeight.FindName("minusdeduction") as Border; var getTxtDeduction = gridMeasureWeight.FindName("txtdeduction") as TextBox; var getlblDeduction = gridMeasure.FindName("lbldeduction") as Label; if (isDisplay == 0) { if (getMinusDeduction != null) { getMinusDeduction.Visibility = Visibility.Hidden; } if (getTxtDeduction != null) { getTxtDeduction.Visibility = Visibility.Hidden; } if (getlblDeduction != null) { getlblDeduction.Visibility = Visibility.Hidden; } } else { if (getMinusDeduction != null) { getMinusDeduction.Visibility = Visibility.Visible; } if (getTxtDeduction != null) { getTxtDeduction.Visibility = Visibility.Visible; } if (getlblDeduction != null) { getlblDeduction.Visibility = Visibility.Visible; } } #endregion return(true); }
public bool SetRenderMainUI() { try { #region 计量业务信息控制 gridReader.Children.Clear(); for (int i = gridReader.RowDefinitions.Count - 1; i > -1; i--) { gridReader.RowDefinitions.RemoveAt(i); } //List<RenderUI> getBullInfo = ReaderInfoList.Where(p => p.aboutweight == 0 && p.isdisplay == 1).OrderBy(o => o.orderno).ToList<RenderUI>(); List <RenderUI> getBullInfo = ReaderInfoList.Where(p => p.aboutweight == 0 && p.isdisplay == 1 && p.fieldname != "tareb" && p.fieldname != "grossb" && p.fieldname != "suttleb" && p.fieldname != "deduction").OrderBy(o => o.orderno).ToList <RenderUI>(); int rowNum = 0; for (int i = 0; i < getBullInfo.Count; i += 2) { RowDefinition rd = new RowDefinition(); if (getBullInfo.Count > 12) { rd.Height = new System.Windows.GridLength(45); } else { gridReader.Margin = new System.Windows.Thickness(0, 50, 0, 0); rd.Height = new System.Windows.GridLength(50); } Border bd = new Border(); Color color = (Color)ColorConverter.ConvertFromString("#335365"); bd.BorderThickness = new System.Windows.Thickness(0, 0, 0, 1); bd.BorderBrush = new SolidColorBrush(color); bd.Margin = new System.Windows.Thickness(-24, 0, 0, 0); Grid itemGD = new Grid(); itemGD.Margin = new System.Windows.Thickness(24, 0, 0, 0); ColumnDefinition cd1 = new ColumnDefinition(); cd1.Width = new System.Windows.GridLength(85); ColumnDefinition cd2 = new ColumnDefinition(); ColumnDefinition cd3 = new ColumnDefinition(); cd3.Width = new System.Windows.GridLength(85); ColumnDefinition cd4 = new ColumnDefinition(); itemGD.ColumnDefinitions.Add(cd1); itemGD.ColumnDefinitions.Add(cd2); itemGD.ColumnDefinitions.Add(cd3); itemGD.ColumnDefinitions.Add(cd4); bd.Child = itemGD; TextBlock tb1 = getTB1(i); tb1.Name = "lb_" + i;//新增name 以后清除信息使用…lt…2016-2-17 09:58:01…… tb1.Text = getBullInfo[i].displayname; tb1.FontWeight = FontWeights.Bold; itemGD.Children.Add(tb1); Grid.SetRow(tb1, 0); Grid.SetColumn(tb1, 0); TextBlock tb2 = getTB2(i); tb2.Name = "tx_" + i; tb2.TextWrapping = System.Windows.TextWrapping.Wrap; tb2.SetBinding(TextBlock.TextProperty, new Binding(getBullInfo[i].fieldname) { Source = BindObject, Mode = BindingMode.TwoWay }); //tb2.Text = "测试测试测试测试测试测试"; itemGD.Children.Add(tb2); Grid.SetRow(tb2, 1); Grid.SetColumn(tb2, 1); bool checkIsOneRow = CheckIsOneRow(getBullInfo[i].fieldname);//文本框 是不是一行显示出来……lt 2016-2-3 09:17:49…… if (checkIsOneRow) { Grid.SetColumnSpan(tb2, 3); i = i - 1; gridReader.RowDefinitions.Add(rd); gridReader.Children.Add(bd); Grid.SetRow(bd, rowNum); Grid.SetColumn(bd, 0); rowNum = rowNum + 1; continue; } if ((i + 1) < getBullInfo.Count) { checkIsOneRow = CheckIsOneRow(getBullInfo[i + 1].fieldname);//如果第一个不是 第二个是 则直接换行…… 2016-2-3 09:57:12 if (checkIsOneRow) { i = i - 1; gridReader.RowDefinitions.Add(rd); gridReader.Children.Add(bd); Grid.SetRow(bd, rowNum); Grid.SetColumn(bd, 0); rowNum = rowNum + 1; continue; } TextBlock tb3 = getTB1(i); tb3.Name = "lb_" + i + 1; tb3.Text = getBullInfo[i + 1].displayname; tb3.FontWeight = FontWeights.Bold;//字体加粗 2016-3-10 11:18:18…… itemGD.Children.Add(tb3); Grid.SetRow(tb3, 2); Grid.SetColumn(tb3, 2); TextBlock tb4 = getTB2(i); tb4.Name = "tx_" + i + 1; tb2.TextWrapping = System.Windows.TextWrapping.Wrap; tb4.SetBinding(TextBlock.TextProperty, new Binding(getBullInfo[i + 1].fieldname) { Source = BindObject, Mode = BindingMode.TwoWay }); //tb4.Text = "测试测试测试测试测试测试"; itemGD.Children.Add(tb4); Grid.SetRow(tb4, 3); Grid.SetColumn(tb4, 3); } gridReader.RowDefinitions.Add(rd); gridReader.Children.Add(bd); Grid.SetRow(bd, rowNum); Grid.SetColumn(bd, 0); rowNum = rowNum + 1; //i++; } #endregion #region 供方信息控制 int isDisplay = 0; try { isDisplay = ReaderInfoList.Where(p => p.fieldname == "tareb").FirstOrDefault().isdisplay *ReaderInfoList.Where(p => p.fieldname == "grossb").FirstOrDefault().isdisplay *ReaderInfoList.Where(p => p.fieldname == "suttleb").FirstOrDefault().isdisplay; } catch //(Exception ex) { } foreach (UIElement element in gridSupplier.Children) { if (isDisplay == 0) { element.Visibility = Visibility.Hidden; } else { element.Visibility = Visibility.Visible; } } #endregion #region 称量信息控制 try { isDisplay = ReaderInfoList.Where(p => p.fieldname == "deduction").FirstOrDefault().isdisplay; //扣重是否显示 } catch //(Exception ex) { } var getMinusDeduction = gridMeasureWeight.FindName("txtMinusDeduction") as TextBlock; var getTxtDeduction = gridMeasureWeight.FindName("txtDeduction") as TextBox; var getlblDeduction = gridMeasure.FindName("lblDeduction") as TextBlock; var getEqualSuttle = gridMeasure.FindName("txtEqualSuttle") as TextBlock; var getSuttle = gridMeasure.FindName("txtSuttle") as TextBox; var getlblSuttle = gridMeasure.FindName("lblSuttle") as TextBlock; //设置当前计量重量的边框颜色 if (this.BindObject != null) { BullInfo bi = this.BindObject as BullInfo; if (!string.IsNullOrEmpty(bi.measurestate)) { if (bi.measurestate == "G")//计毛 { var getTxtGrossWeight = gridMeasureWeight.FindName("txtGrossWeight") as TextBox; //getTxtGrossWeight.SetValue(TextBox.BorderBrushProperty, Colors.Red); //解决 “#FF0000”#FFFF0000”不是属性“BorderBrush”的有效值 lt 2016-2-16 17:17:33…… getTxtGrossWeight.BorderBrush = new SolidColorBrush(Colors.Red); var getTxtTaireWeight = gridMeasureWeight.FindName("txtTaireWeight") as TextBox; getTxtTaireWeight.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 56, 69, 86)); //变为初始化 2016-2-25 10:52:58…… } else if (bi.measurestate == "T") //计皮 { var getTxtTaireWeight = gridMeasureWeight.FindName("txtTaireWeight") as TextBox; //getTxtTaireWeight.SetValue(TextBox.BorderBrushProperty, Colors.Red); //解决 “#FF0000”#FFFF0000”不是属性“BorderBrush”的有效值 lt 2016-2-16 17:17:33…… getTxtTaireWeight.BorderBrush = new SolidColorBrush(Colors.Red); var getTxtGrossWeight = gridMeasureWeight.FindName("txtGrossWeight") as TextBox; getTxtGrossWeight.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 56, 69, 86));//变为初始化 2016-2-25 10:52:58…… } } } if (isDisplay == 0) { if (getMinusDeduction != null) { getMinusDeduction.Visibility = Visibility.Hidden; } if (getTxtDeduction != null) { getTxtDeduction.Visibility = Visibility.Hidden; } //if (getMinusDeduction != null) //{ // getMinusDeduction.Visibility = Visibility.Hidden; //} if (getlblDeduction != null) { getlblDeduction.Visibility = Visibility.Hidden; } //去掉合并……2016-2-3 11:12:06 //if (getEqualSuttle != null) //{ // getEqualSuttle.SetValue(Grid.ColumnProperty, 3); //} //if (getSuttle!=null) //{ // getSuttle.SetValue(Grid.ColumnProperty, 4); //} //if (getlblSuttle!=null) //{ // getlblSuttle.SetValue(Grid.ColumnProperty, 4); //} //gridMeasureWeight.ColumnDefinitions.RemoveAt(6); //gridMeasureWeight.ColumnDefinitions.RemoveAt(5); //gridMeasure.ColumnDefinitions.RemoveAt(6); //gridMeasure.ColumnDefinitions.RemoveAt(5); } else { if (getMinusDeduction != null) { getMinusDeduction.Visibility = Visibility.Visible; } if (getTxtDeduction != null) { getTxtDeduction.Visibility = Visibility.Visible; } //if (getMinusDeduction != null) //{ // getMinusDeduction.Visibility = Visibility.Visible; //} if (getlblDeduction != null) { getlblDeduction.Visibility = Visibility.Visible; } //去掉 合并…… //gridMeasureWeight.ColumnDefinitions.Add(new ColumnDefinition()); //gridMeasureWeight.ColumnDefinitions.Add(new ColumnDefinition()); //gridMeasure.ColumnDefinitions.Add(new ColumnDefinition()); //gridMeasure.ColumnDefinitions.Add(new ColumnDefinition()); //gridMeasureWeight.ColumnDefinitions[5].Width = new System.Windows.GridLength(24); //gridMeasure.ColumnDefinitions[5].Width = new System.Windows.GridLength(24); //if (getEqualSuttle != null) //{ // getEqualSuttle.SetValue(Grid.ColumnProperty, 5); //} //if (getSuttle != null) //{ // getSuttle.SetValue(Grid.ColumnProperty, 6); //} //if (getlblSuttle != null) //{ // getlblSuttle.SetValue(Grid.ColumnProperty, 6); //} } #endregion } catch (Exception ex) { #region 写日志 LogModel log = new LogModel() { CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Msg = "RenderMainUI出错:" + ex.StackTrace, FunctionName = "称点主窗体_SetRenderMainUI", Origin = "汽车衡_" + ClientInfo.Name, Level = LogConstParam.LogLevel_Error }; Talent.ClinetLog.SysLog.Log(JsonConvert.SerializeObject(log)); #endregion } return(true); }