本文主要是介绍FastReport ERP code 获取字段数据,将数据写到表格里面,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
FastReport ERP code 获取字段数据,将数据写到表格里面
1.FastReport 通过code页获取数据库字段数据
DataSourceBase ds = Report.GetDataSource("明细数据"); ds.Init();ds.First(); while(ds.HasMoreRows){ list.Add((String)Report.GetColumnValue("明细数据.ym00910")); //lotproduct_name.Add(((String)Report.GetColumnValue("明细数据.bs00203")));// CheckedListBox1.Items.Add(((Decimal)Report.GetColumnValue("明细数据.leftQty")));Inventory.Add((Decimal)Report.GetColumnValue("明细数据.leftQty"));//total_num +=((Decimal)Report.GetColumnValue("明细数据.ym00905"));all_amount.Add((Decimal)Report.GetColumnValue("明细数据.ym00905"));ds.Next(); }
这个部分是获取数据库某字段的数据,当时在网上找了好久都没有找到资料,网上说的都是PrintOn,经过不断验证和调试,发现通过上面这段代码能让我们通过code获取ERP数据库字段里面的数据,这也是最难的一部分,因为拿不到数据,就不能进行下面的数据处理,当时为了这个,整整搞了半个月的时间,才能摸索出来获取数据的方法。
DataSourceBase ds = Report.GetDataSource("明细数据");
这段代码是得到表数据的对象,然后循环获取对应字段的数据
获取到数据后接着对数据处理,因为在ERP使用的是C#,所以要简单的学习C#的语法。
数据处理完了以后,如何把数组里面的数据循环输出到表格里面,这是数据处理完以后,要输出到表格里最重要的一步,如果这一步做不出来,前期的数据获取和数据处理都没有任何意义。
下面这一步也是最重要的一步,就是获取page页Table的对象 ⮧
TableObject table1 = Report.FindObject("Table1") as TableObject;
这是获取table对象,并把数组里面的数写到这个对象里面去
接下来是如何调用table对象的方法,并且能够实现Cell行数自动添加,将数据输出为自己想要的表格格式,可以针对报表的多样性,做出不一样的格式
if (table1 != null){ //设置表格的边框颜色table1.Border.Color = Color.Black;//设置表格的border全显示table1.Border.Lines = BorderLines.All;TableRow row1 = new TableRow();//定义Table行对象TableColumn col1 = new TableColumn();//定义Table列对象TableCell cell1 = new TableCell();//定义Cell单元对象TableCell cell2 = new TableCell();TableCell cell3 = new TableCell();TableCell cell4 = new TableCell();TableCell cell5 = new TableCell();TableCell cell6 = new TableCell();TableCell cell7 = new TableCell();TableCell cell8 = new TableCell();TableCell cell9 = new TableCell();TableCell cell10 = new TableCell();TableCell cell11 = new TableCell();TableCell cell12 = new TableCell();TableCell cell13 = new TableCell();TableCell cell14 = new TableCell(); TableCell cell15 = new TableCell();cell1.Border.Color = Color.Black;//设置Cell单元方法属性cell1.Border.Lines = BorderLines.All;cell1.Text = "1"; cell1.FlagPreviewVisible = true;cell1.VertAlign = VertAlign.Center;cell2.Border.Color = Color.Black;cell2.Border.Lines = BorderLines.All; cell2.Text = mc[0].Value;cell3.Border.Color = Color.Black;cell3.Border.Lines = BorderLines.All;row1.AddChild(cell1);//Table行方法添加row1.AddChild(cell2);row1.AddChild(cell3);row1.AddChild(cell4);row1.AddChild(cell5);row1.AddChild(cell6);row1.AddChild(cell7);row1.AddChild(cell8);row1.AddChild(cell9);row1.AddChild(cell10);row1.AddChild(cell11);row1.AddChild(cell12);row1.AddChild(cell13);row1.AddChild(cell14);row1.AddChild(cell15); table1.Rows.Add(row1);//Table的对象Rows调用Add的方法,使得Table的行数添加一行str_id = "";str_lot = "";sum = 0; }
说实话,ERP对表格的操作没有想象中的那么轻松,也许我方法不对,没办法对上下的单元格进行合并,如果有哪位大神找到了合并的方法,麻烦告知,谢谢。
代码示例:
public void Get_data(){DataSourceBase ds = Report.GetDataSource("明细数据"); ds.Init();ds.First(); while(ds.HasMoreRows){ list.Add((String)Report.GetColumnValue("明细数据.ym00910")); //lotproduct_name.Add(((String)Report.GetColumnValue("明细数据.bs00203")));// CheckedListBox1.Items.Add(((Decimal)Report.GetColumnValue("明细数据.leftQty")));Inventory.Add((Decimal)Report.GetColumnValue("明细数据.leftQty"));//total_num +=((Decimal)Report.GetColumnValue("明细数据.ym00905"));all_amount.Add((Decimal)Report.GetColumnValue("明细数据.ym00905"));//CheckedListBox1.Items.Add(((Decimal)Report.GetColumnValue("明细数据.ym00905")));ds.Next(); } }public void DealWith_data(){int list_num,index,i,j,len;double amount;string str,str_content;ArrayList lot_list = new ArrayList();ArrayList product_list = new ArrayList();sum = 0;Hashtable ht = new Hashtable();list_num = list.Count; //TableObject table1 = Report.FindObject("Table8") as TableObject;str_id = "";str_content = "";Regex match_name = new Regex(@"\w+[\d]+",RegexOptions.IgnoreCase);Regex match_name1 = new Regex(@"\s+\w*",RegexOptions.IgnoreCase);Regex match_ID = new Regex(@"#[0-9]*");Regex match_lot = new Regex(@"[0-9a-z\.]+",RegexOptions.IgnoreCase);string str_name = (String)Report.GetColumnValue("主数据.bs00203");MatchCollection mc;MatchCollection mc1;MatchCollection ID;MatchCollection lot;mc = match_name.Matches(str_name);mc1 = match_name1.Matches(str_name);// string[] aa = match_name.Split(str_name);// CheckedListBox1.Items.Add("产品名称:" + aa[0].ToString());CheckedListBox1.Items.Add("产品名称:" + mc1[0].Value);for (i = 0 ; i < list_num; i++ ){ str = (String)list[i];index = str.IndexOf('#',1);str_lot = str.Substring(0,index - 1);lot_list.Add(str_lot); total_num+=Convert.ToDecimal(all_amount[i]);amount = (Convert.ToDouble(Inventory[i]));if(amount != 0.00){str = (String)product_name[i];string[] str_name_Array = Regex.Split(str,@"/");amount = (Convert.ToDouble(all_amount[i]));string get_str_ID =(String)list[i];ID = match_ID.Matches(get_str_ID);lot = match_lot.Matches(get_str_ID);if(str_name_Array.Length == 3){str_content += " 取" + lot[0].Value + " " + ID[0].Value + " 蓝膜:" + (amount.ToString("#0")) + "颗 。 ";}if(str_name_Array.Length == 2){str_content += " 取" + lot[0].Value + " " + ID[0].Value + " 蓝膜:" + (amount.ToString("#0")) + "颗 。 ";}if(str_name_Array.Length == 1){str_content += " 取" + lot[0].Value + " " + ID[0].Value + " 蓝膜:" + (amount.ToString("#0")) + "颗 。 ";} }else if(amount == 0.00){amount = (Convert.ToDouble(all_amount[i]));if(amount <= 30000.00){str = (String)product_name[i];string[] str_name_Array = Regex.Split(str,@"/");string get_str_ID =(String)list[i];ID = match_ID.Matches(get_str_ID);lot = match_lot.Matches(get_str_ID);if(str_name_Array.Length == 3){str_content += " 取" + lot[0].Value + " " + ID[0].Value + " 剩下蓝膜:" + (amount.ToString("#0")) + "颗 。 ";}if(str_name_Array.Length == 2){str_content += " 取" + lot[0].Value + " " + ID[0].Value + " 剩下蓝膜:" + (amount.ToString("#0")) + "颗 。 ";}if(str_name_Array.Length == 1){str_content += " 取" + lot[0].Value + " " + ID[0].Value + " 剩下蓝膜:" + (amount.ToString("#0")) + "颗 。 ";} }}}Cell608.Text = '3' + str_content;for (i = 0 ; i < list_num; i++ ){str = (String)product_name[i];if(str != ""){string[] strArray = Regex.Split(str,@"/");if(strArray.Length == 3){product_list.Add(strArray[1]);}if(strArray.Length == 2){product_list.Add(strArray[0]);}if(strArray.Length == 1){product_list.Add(strArray[0]);}}} for (i = 0; i < lot_list.Count - 1; i++){for (j = i + 1; j < lot_list.Count; j++){if (lot_list[i].Equals(lot_list[j]) && product_list[i].Equals(product_list[j])){lot_list.RemoveAt(j);product_list.RemoveAt(j);j--;} } }lot_num = lot_list.Count;//CheckedListBox1.Items.Add(get_inventory_name);int Inventory_sum;for (i = 0; i < lot_num; i++){Inventory_sum = 0;str_lot = (String)lot_list[i];str_product = (String)product_list[i];for (j = 0; j < list_num; j++){ str = (String)list[j]; //len = str.Length; if (str.Contains(str_lot)){Inventory_sum = Convert.ToInt32(Inventory[j]) + Convert.ToInt32(all_amount[j]) + Inventory_sum;//所有wafer数量index = str.IndexOf('#',1);index = index + 1; str_id += str.Substring(index , len - index) + ',';sum += 1;} }str_id = str_id.Substring(0,str_id.LastIndexOf(','));string[] idArray = Regex.Split(str_id,@",");int idTotal,a,b;string temp;idTotal = idArray.Length; for( a = 0; a < idTotal ; a++){ for( b = a+1; b < idTotal; b++){if(Convert.ToDecimal(idArray[a]) > Convert.ToDecimal(idArray[b])){temp = idArray[a];idArray[a] = idArray[b];idArray[b] = temp;} } } str_id = "";for(int k = 0; k < idTotal; k++){str_id=str_id+idArray[k].ToString()+ ','; }str_id = str_id.Substring(0,str_id.LastIndexOf(',')); CheckedListBox1.Items.Add(("Lot ID: " + str_lot + " Wafer ID: " + str_id) + " Wafer Total:" + sum.ToString()); if (str_id != ""){if (table1 != null){ //设置表格的边框颜色table1.Border.Color = Color.Black;//设置表格的border全显示table1.Border.Lines = BorderLines.All;TableRow row1 = new TableRow();TableColumn col1 = new TableColumn();TableCell cell1 = new TableCell();TableCell cell2 = new TableCell();TableCell cell3 = new TableCell();TableCell cell4 = new TableCell();TableCell cell5 = new TableCell();TableCell cell6 = new TableCell();TableCell cell7 = new TableCell();TableCell cell8 = new TableCell();TableCell cell9 = new TableCell();TableCell cell10 = new TableCell();TableCell cell11 = new TableCell();TableCell cell12 = new TableCell();TableCell cell13 = new TableCell();TableCell cell14 = new TableCell(); TableCell cell15 = new TableCell();TableCell cell16 = new TableCell();cell1.Border.Color = Color.Black;cell1.Border.Lines = BorderLines.All;cell1.Text = "1"; cell1.FlagPreviewVisible = true;cell1.VertAlign = VertAlign.Center;cell2.Border.Color = Color.Black;cell2.Border.Lines = BorderLines.All; cell2.Text = (String)mc[0].Value;cell2.AutoWidth = true;cell2.FlagPreviewVisible = true;cell3.Border.Color = Color.Black;cell3.Border.Lines = BorderLines.All;cell3.AutoWidth = true;cell13.Text = mc1[0].Value + "\\" + "2002";cell13.AutoWidth = true;cell9.Border.Color = Color.Black;cell9.Border.Lines = BorderLines.All; if(str_product.Contains("VCS104")){ cell3.Text = "ASIC" + "(" + str_product + ")"; }else{cell3.Text = "AMR" + "(" + str_product + ")";}cell13.Border.Color = Color.Black;cell13.Border.Lines = BorderLines.All;cell12.Border.Color = Color.Black;cell12.Border.Lines = BorderLines.All; if(cell2.Text.Contains("1373")){cell9.Text = "SOT23-3";cell12.Text = "1165BD0002";//Cell91.Text = "备注:3种晶圆均为full-mask wafer: mobius2 & QMG6B2 通用MAP;使用blind mapping;QMG6B1已完成bump process,需使用 mapping。 " + str_content; }cell13.ColSpan = 1;cell4.Border.Color = Color.Black;cell4.Border.Lines = BorderLines.All;cell4.Text = str_lot + "\r\n" + str_id;cell4.AutoWidth = true;cell5.Border.Color = Color.Black;cell5.Border.Lines = BorderLines.All;cell5.Text = Convert.ToString(sum);;cell6.Border.Color = Color.Black;cell6.Border.Lines = BorderLines.All;cell6.Text = Inventory_sum.ToString();cell7.Border.Color = Color.Black;cell7.Border.Lines = BorderLines.All;cell7.Text = ((total_num/lot_num).ToString("#0"));cell8.Border.Color = Color.Black;cell8.Border.Lines = BorderLines.Right;cell8.Text = ""; cell10.Border.Color = Color.Black;cell10.Border.Lines = BorderLines.Right; cell11.Border.Color = Color.Black;cell11.Border.Lines = BorderLines.Right;cell14.Border.Lines = BorderLines.Right;cell15.Border.Lines = BorderLines.Right;row1.AddChild(cell1);row1.AddChild(cell2);row1.AddChild(cell3);row1.AddChild(cell4);row1.AddChild(cell5);row1.AddChild(cell6);row1.AddChild(cell7);row1.AddChild(cell8);row1.AddChild(cell9);row1.AddChild(cell10);row1.AddChild(cell11);row1.AddChild(cell12);row1.AddChild(cell13);row1.AddChild(cell14);row1.AddChild(cell15);row1.AddChild(cell16); table1.Rows.Add(row1);//table1.Columns.Add(col1);str_id = "";str_lot = "";sum = 0; } }}}
如果转载,请注明出处,否则将追究法律责任。
这篇关于FastReport ERP code 获取字段数据,将数据写到表格里面的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!