//创建出钢记号显示列 // if (varieties_code == "A" || varieties_code == "B" || varieties_code == "D") // { // //创建牌号显示列 // DevExpress.XtraGrid.Columns.GridColumn gridColumn = this.gridView1.Columns.Add(); // gridColumn.Caption = "牌号"; // gridColumn.FieldName = "SG_SIGN"; // gridColumn.Name = "colSG_SIGN"; // gridColumn.Width = 90; // gridColumn.Visible = false; // gridColumn.OptionsColumn.AllowEdit = false; // gridColumn.OptionsColumn.ReadOnly = true; // gridColumn.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; // DevExpress.XtraGrid.Columns.GridColumn gridColumn4 = this.gridView1.Columns.Add(); // gridColumn4.Caption = "牌号"; // gridColumn4.FieldName = "SG_SIGN1"; // gridColumn4.Name = "colSG_SIGN1"; // gridColumn4.Width = 90; // gridColumn4.Visible = true; // gridColumn4.OptionsColumn.AllowEdit = false; // gridColumn4.OptionsColumn.ReadOnly = true; // gridColumn4.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; // //创建炼钢钢种显示列 // DevExpress.XtraGrid.Columns.GridColumn gridColumn1 = this.gridView1.Columns.Add(); // gridColumn1.Caption = "炼钢钢种"; // gridColumn1.FieldName = "LG_ST"; // gridColumn1.Name = "colLG_ST"; // gridColumn1.Width = 80; // gridColumn1.Visible = true; // gridColumn1.OptionsColumn.AllowEdit = false; // gridColumn1.OptionsColumn.ReadOnly = true; // gridColumn1.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; // } // if (varieties_code == "C") // { // //创建炼钢钢种显示列 // DevExpress.XtraGrid.Columns.GridColumn gridColumn = this.gridView1.Columns.Add(); // gridColumn.Caption = "炼钢钢种"; // gridColumn.FieldName = "LG_ST"; // gridColumn.Name = "colLG_ST"; // gridColumn.Width = 80; // gridColumn.Visible = false; // gridColumn.OptionsColumn.AllowEdit = false; // gridColumn.OptionsColumn.ReadOnly = true; // gridColumn.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; // DevExpress.XtraGrid.Columns.GridColumn gridColumn4 = this.gridView1.Columns.Add(); // gridColumn4.Caption = "炼钢钢种"; // gridColumn4.FieldName = "LG_ST1"; // gridColumn4.Name = "colLG_ST1"; // gridColumn4.Width = 80; // gridColumn4.Visible = true; // gridColumn4.OptionsColumn.AllowEdit = false; // gridColumn4.OptionsColumn.ReadOnly = true; // gridColumn4.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; // //创建炼钢钢种显示列 // DevExpress.XtraGrid.Columns.GridColumn gridColumn1 = this.gridView1.Columns.Add(); // gridColumn1.Caption = "出钢记号"; // gridColumn1.FieldName = "ST_NO"; // gridColumn1.Name = "colST_NO"; // gridColumn1.Width = 80; // gridColumn1.Visible = true; // gridColumn1.OptionsColumn.AllowEdit = false; // gridColumn1.OptionsColumn.ReadOnly = true; // gridColumn1.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; // } // //创建出钢记号显示列 // DevExpress.XtraGrid.Columns.GridColumn gridColumn2 = this.gridView1.Columns.Add(); // gridColumn2.Caption = "轧宽"; // gridColumn2.FieldName = "OUT_MAT_WIDTH"; // gridColumn2.Name = "colOUT_MAT_WIDTH"; // gridColumn2.Width = 75; // gridColumn2.Visible = true; // gridColumn2.OptionsColumn.AllowEdit = false; // gridColumn2.OptionsColumn.ReadOnly = true; // gridColumn2.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric; // gridColumn2.DisplayFormat.FormatString = "0"; // gridColumn2.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; // for (int i = 3; i < outBlock.Tables[0].Columns.Count; i++) // { // colName = outBlock.Tables[0].Columns[i].ColumnName; // addCol(colName); // } // //创建总计显示列 // DevExpress.XtraGrid.Columns.GridColumn gridColumn3 = this.gridView1.Columns.Add(); // gridColumn3.Caption = "总计"; // gridColumn3.FieldName = "TOTAL"; // gridColumn3.Name = "colTOTAL"; // gridColumn3.Width = 75; // gridColumn3.Visible = true; // gridColumn3.OptionsColumn.AllowEdit = false; // gridColumn3.OptionsColumn.ReadOnly = true; // gridColumn3.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric; // gridColumn3.DisplayFormat.FormatString = "0"; // gridColumn3.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.False; // #endregion // #region 总数与汇总 // cut = outBlock.Tables[0].Rows.Count;//数据行条数 // if (cut > 0) // { // outBlock.Tables[0].Columns.Add("TOTAL", typeof(decimal)); // outBlock.Tables[0].Columns.Add("LG_ST1", typeof(string));//新加列用来显示(相邻行数据一样只在第一行显示)__牌号(商品材和冷轧材) // outBlock.Tables[0].Columns.Add("SG_SIGN1", typeof(string));//新加列用来显示(相邻行数据一样只在第一行显示)__钢种(硅钢材) // totalall = new decimal[outBlock.Tables[0].Columns.Count - 6];//给数组赋值长度(日期的个数) // int o = 0;//声明一个变量用来定位行数给新加列赋值 // //循环数据行 // for (int i = 0; i < cut; i++) // { // k = 0; // //循环累加表头为日期的数据存到数组 // for (int j = 3; j < outBlock.Tables[0].Columns.Count - 3; j++) // { // colName = outBlock.Tables[0].Columns[j].ColumnName; // totalall[k] += Convert.ToDecimal(outBlock.Tables[0].Rows[i][colName].ToString().Trim()); // k++; // } // //商品材和冷轧材用牌号做判断 // if (varieties_code == "A" || varieties_code == "B" || varieties_code == "D") // { // sg_sign = outBlock.Tables[0].Rows[i]["SG_SIGN"].ToString(); // if (i + 1 < cut) // { // sg_sign1 = outBlock.Tables[0].Rows[i + 1]["SG_SIGN"].ToString(); // } // } // //硅钢材用钢种做判断 // if (varieties_code == "C") // { // sg_sign = outBlock.Tables[0].Rows[i]["LG_ST"].ToString(); // if (i + 1 < cut) // { // sg_sign1 = outBlock.Tables[0].Rows[i + 1]["LG_ST"].ToString(); // } // } // bool isok = true;//声明一个变量来判断是否有过新增行 // if (sg_sign != sg_sign1 || i + 1 == cut) // { // //声明一个结构为outBlock.Tables[0]的数据行并插入数据(用来汇总) // DataRow dr = outBlock.Tables[0].NewRow(); // //商品材和冷轧材用牌号显示 // if (varieties_code == "A" || varieties_code == "B" || varieties_code == "D") // { // //赋值新加列(通过定位变量o来定位相同数据的第一行) // outBlock.Tables[0].Rows[i - o]["SG_SIGN1"] = outBlock.Tables[0].Rows[i]["SG_SIGN"]; // dr["SG_SIGN1"] = "汇总"; // dr["SG_SIGN"] = sg_sign; // } // //硅钢材用钢种显示 // if (varieties_code == "C") // { // //赋值新加列(通过定位变量o来定位相同数据的第一行) // outBlock.Tables[0].Rows[i - o]["LG_ST1"] = outBlock.Tables[0].Rows[i]["LG_ST"]; // dr["LG_ST1"] = "汇总"; // dr["LG_ST"] = sg_sign; // } // //循环数据行的列名并插入数组里对应的统计数据 // k = 0; // for (int j = 3; j < outBlock.Tables[0].Columns.Count - 3; j++) // { // colName = outBlock.Tables[0].Columns[j].ColumnName; // dr[colName] = totalall[k]; // k++; // } // //将存好数据的的数据行插入到当前行之后 // outBlock.Tables[0].Rows.InsertAt(dr, i + 1); // cut++;//插入了数据行所以数据源长度+1 // i++;//循环次数加1用来跳过插入的汇总行 // Array.Clear(totalall, 0, totalall.Length);//将数组的值重置为0用来统计下一组数据 // o = 0;//将定问坐标初始为0 // isok = false;//新增过汇总行将变量设置为false // } // //变量为true才给定问坐标加1(跳过汇总行) // if (isok == true) // { // o++; // } // } // //总计列 // for (int i = 0; i < cut; i++) // { // //循环累积总计列并赋值 // total = 0; // for (int j = 3; j < outBlock.Tables[0].Columns.Count - 3; j++) // { // colName = outBlock.Tables[0].Columns[j].ColumnName; // total += Convert.ToDecimal(outBlock.Tables[0].Rows[i][colName].ToString().Trim()); // } // outBlock.Tables[0].Rows[i]["TOTAL"] = total; // } // //总计行 // totalall = new decimal[outBlock.Tables[0].Columns.Count - 5];//给数组赋值长度(日期的个数和总计) // //声明一个结构为outBlock.Tables[0]的数据行并插入数据(用来纵向汇总) // DataRow dr1 = outBlock.Tables[0].NewRow(); // dr1["SG_SIGN1"] = "总计"; // dr1["LG_ST1"] = "总计"; // for (int i = 0; i < cut; i++) // { // //跳过汇总行 // if (outBlock.Tables[0].Rows[i]["SG_SIGN1"].ToString().Trim() == "汇总" || outBlock.Tables[0].Rows[i]["LG_ST1"].ToString().Trim() == "汇总") // { // continue; // } // k = 0; // for (int j = 3; j < outBlock.Tables[0].Columns.Count - 2; j++) // { // colName = outBlock.Tables[0].Columns[j].ColumnName; // totalall[k] += Convert.ToDecimal(outBlock.Tables[0].Rows[i][colName].ToString().Trim()); // k++; // } // } // k = 0; // //循环数据行的列名并插入数组里对应的统计数据 // for (int j = 3; j < outBlock.Tables[0].Columns.Count - 2; j++) // { // colName = outBlock.Tables[0].Columns[j].ColumnName; // dr1[colName] = totalall[k]; // k++; // } // //将存好数据的的数据行插入最后 // outBlock.Tables[0].Rows.InsertAt(dr1, 0); // } // #endregion // this.efDevGrid1.ShowSelectionColumn = true; //设置选择是否可见 // //绑定数据 // efDevGrid1.DataSource = outBlock.Tables[0]; // efDevGrid2.DataSource = outBlock.Tables[1]; // } // catch (Exception e) // { // this.EFMsgInfo = e.Message; // } //}
//创建出钢记号显示列 if (varieties_code == "A" || varieties_code == "B" || varieties_code == "D") { //创建牌号显示列 DevExpress.XtraGrid.Columns.GridColumn gridColumn = this.gridView1.Columns.Add(); gridColumn.Caption = "牌号"; gridColumn.FieldName = "SG_SIGN"; gridColumn.Name = "colSG_SIGN"; gridColumn.Width = 90; gridColumn.Visible = false; gridColumn.OptionsColumn.AllowEdit = false; gridColumn.OptionsColumn.ReadOnly = true; gridColumn.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; DevExpress.XtraGrid.Columns.GridColumn gridColumn4 = this.gridView1.Columns.Add(); gridColumn4.Caption = "牌号"; gridColumn4.FieldName = "SG_SIGN1"; gridColumn4.Name = "colSG_SIGN1"; gridColumn4.Width = 90; gridColumn4.Visible = true; gridColumn4.OptionsColumn.AllowEdit = false; gridColumn4.OptionsColumn.ReadOnly = true; gridColumn4.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; //创建炼钢钢种显示列 DevExpress.XtraGrid.Columns.GridColumn gridColumn1 = this.gridView1.Columns.Add(); gridColumn1.Caption = "炼钢钢种"; gridColumn1.FieldName = "LG_ST"; gridColumn1.Name = "colLG_ST"; gridColumn1.Width = 80; gridColumn1.Visible = true; gridColumn1.OptionsColumn.AllowEdit = false; gridColumn1.OptionsColumn.ReadOnly = true; gridColumn1.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; } if (varieties_code == "C") { //创建炼钢钢种显示列 DevExpress.XtraGrid.Columns.GridColumn gridColumn = this.gridView1.Columns.Add(); gridColumn.Caption = "炼钢钢种"; gridColumn.FieldName = "LG_ST"; gridColumn.Name = "colLG_ST"; gridColumn.Width = 80; gridColumn.Visible = false; gridColumn.OptionsColumn.AllowEdit = false; gridColumn.OptionsColumn.ReadOnly = true; gridColumn.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; DevExpress.XtraGrid.Columns.GridColumn gridColumn4 = this.gridView1.Columns.Add(); gridColumn4.Caption = "炼钢钢种"; gridColumn4.FieldName = "LG_ST1"; gridColumn4.Name = "colLG_ST1"; gridColumn4.Width = 80; gridColumn4.Visible = true; gridColumn4.OptionsColumn.AllowEdit = false; gridColumn4.OptionsColumn.ReadOnly = true; gridColumn4.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; //创建炼钢钢种显示列 DevExpress.XtraGrid.Columns.GridColumn gridColumn1 = this.gridView1.Columns.Add(); gridColumn1.Caption = "出钢记号"; gridColumn1.FieldName = "ST_NO"; gridColumn1.Name = "colST_NO"; gridColumn1.Width = 80; gridColumn1.Visible = true; gridColumn1.OptionsColumn.AllowEdit = false; gridColumn1.OptionsColumn.ReadOnly = true; gridColumn1.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; } //创建出钢记号显示列 DevExpress.XtraGrid.Columns.GridColumn gridColumn2 = this.gridView1.Columns.Add(); gridColumn2.Caption = "轧宽"; gridColumn2.FieldName = "OUT_MAT_WIDTH"; gridColumn2.Name = "colOUT_MAT_WIDTH"; gridColumn2.Width = 75; gridColumn2.Visible = true; gridColumn2.OptionsColumn.AllowEdit = false; gridColumn2.OptionsColumn.ReadOnly = true; gridColumn2.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric; gridColumn2.DisplayFormat.FormatString = "0"; gridColumn2.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; for (int i = 3; i < outBlock.Tables[0].Columns.Count; i++) { colName = outBlock.Tables[0].Columns[i].ColumnName; addCol(colName); } //创建总计显示列 DevExpress.XtraGrid.Columns.GridColumn gridColumn3 = this.gridView1.Columns.Add(); gridColumn3.Caption = "总计"; gridColumn3.FieldName = "TOTAL"; gridColumn3.Name = "colTOTAL"; gridColumn3.Width = 75; gridColumn3.Visible = true; gridColumn3.OptionsColumn.AllowEdit = false; gridColumn3.OptionsColumn.ReadOnly = true; gridColumn3.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric; gridColumn3.DisplayFormat.FormatString = "0"; gridColumn3.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.False; #endregion #region 总数与汇总 cut = outBlock.Tables[0].Rows.Count;//数据行条数 if (cut > 0) { outBlock.Tables[0].Columns.Add("TOTAL", typeof(decimal)); outBlock.Tables[0].Columns.Add("LG_ST1", typeof(string));//新加列用来显示(相邻行数据一样只在第一行显示)__牌号(商品材和冷轧材) outBlock.Tables[0].Columns.Add("SG_SIGN1", typeof(string));//新加列用来显示(相邻行数据一样只在第一行显示)__钢种(硅钢材) totalall = new decimal[outBlock.Tables[0].Columns.Count - 6];//给数组赋值长度(日期的个数) int o = 0;//声明一个变量用来定位行数给新加列赋值 //循环数据行 for (int i = 0; i < cut; i++) { k = 0; //循环累加表头为日期的数据存到数组 for (int j = 3; j < outBlock.Tables[0].Columns.Count - 3; j++) { colName = outBlock.Tables[0].Columns[j].ColumnName; totalall[k] += Convert.ToDecimal(outBlock.Tables[0].Rows[i][colName].ToString().Trim()); k++; } //商品材和冷轧材用牌号做判断 if (varieties_code == "A" || varieties_code == "B" || varieties_code == "D") { sg_sign = outBlock.Tables[0].Rows[i]["SG_SIGN"].ToString(); if (i + 1 < cut) { sg_sign1 = outBlock.Tables[0].Rows[i + 1]["SG_SIGN"].ToString(); } } //硅钢材用钢种做判断 if (varieties_code == "C") { sg_sign = outBlock.Tables[0].Rows[i]["LG_ST"].ToString(); if (i + 1 < cut) { sg_sign1 = outBlock.Tables[0].Rows[i + 1]["LG_ST"].ToString(); } } bool isok = true;//声明一个变量来判断是否有过新增行 if (sg_sign != sg_sign1 || i + 1 == cut) { //声明一个结构为outBlock.Tables[0]的数据行并插入数据(用来汇总) DataRow dr = outBlock.Tables[0].NewRow(); //商品材和冷轧材用牌号显示 if (varieties_code == "A" || varieties_code == "B" || varieties_code == "D") { //赋值新加列(通过定位变量o来定位相同数据的第一行) outBlock.Tables[0].Rows[i - o]["SG_SIGN1"] = outBlock.Tables[0].Rows[i]["SG_SIGN"]; dr["SG_SIGN1"] = "汇总"; dr["SG_SIGN"] = sg_sign; } //硅钢材用钢种显示 if (varieties_code == "C") { //赋值新加列(通过定位变量o来定位相同数据的第一行) outBlock.Tables[0].Rows[i - o]["LG_ST1"] = outBlock.Tables[0].Rows[i]["LG_ST"]; dr["LG_ST1"] = "汇总"; dr["LG_ST"] = sg_sign; } //循环数据行的列名并插入数组里对应的统计数据 k = 0; for (int j = 3; j < outBlock.Tables[0].Columns.Count - 3; j++) { colName = outBlock.Tables[0].Columns[j].ColumnName; dr[colName] = totalall[k]; k++; } //将存好数据的的数据行插入到当前行之后 outBlock.Tables[0].Rows.InsertAt(dr, i + 1); cut++;//插入了数据行所以数据源长度+1 i++;//循环次数加1用来跳过插入的汇总行 Array.Clear(totalall, 0, totalall.Length);//将数组的值重置为0用来统计下一组数据 o = 0;//将定问坐标初始为0 isok = false;//新增过汇总行将变量设置为false } //变量为true才给定问坐标加1(跳过汇总行) if (isok == true) { o++; } } //总计列 for (int i = 0; i < cut; i++) { //循环累积总计列并赋值 total = 0; for (int j = 3; j < outBlock.Tables[0].Columns.Count - 3; j++) { colName = outBlock.Tables[0].Columns[j].ColumnName; total += Convert.ToDecimal(outBlock.Tables[0].Rows[i][colName].ToString().Trim()); } outBlock.Tables[0].Rows[i]["TOTAL"] = total; } //总计行 totalall = new decimal[outBlock.Tables[0].Columns.Count - 5];//给数组赋值长度(日期的个数和总计) //声明一个结构为outBlock.Tables[0]的数据行并插入数据(用来纵向汇总) DataRow dr1 = outBlock.Tables[0].NewRow(); dr1["SG_SIGN1"] = "总计"; dr1["LG_ST1"] = "总计"; for (int i = 0; i < cut; i++) { //跳过汇总行 if (outBlock.Tables[0].Rows[i]["SG_SIGN1"].ToString().Trim() == "汇总" || outBlock.Tables[0].Rows[i]["LG_ST1"].ToString().Trim() == "汇总") { continue; } k = 0; for (int j = 3; j < outBlock.Tables[0].Columns.Count - 2; j++) { colName = outBlock.Tables[0].Columns[j].ColumnName; totalall[k] += Convert.ToDecimal(outBlock.Tables[0].Rows[i][colName].ToString().Trim()); k++; } } k = 0; //循环数据行的列名并插入数组里对应的统计数据 for (int j = 3; j < outBlock.Tables[0].Columns.Count - 2; j++) { colName = outBlock.Tables[0].Columns[j].ColumnName; dr1[colName] = totalall[k]; k++; } //将存好数据的的数据行插入最后 outBlock.Tables[0].Rows.InsertAt(dr1, 0); } #endregion this.efDevGrid1.ShowSelectionColumn = true; //设置选择是否可见 //绑定数据 efDevGrid1.DataSource = outBlock.Tables[0]; efDevGrid2.DataSource = outBlock.Tables[1]; } catch (Exception e) { this.EFMsgInfo = e.Message; } }