FastReport ERP code 获取字段数据,将数据写到表格里面

2024-04-10 15:32

本文主要是介绍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 获取字段数据,将数据写到表格里面的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/891454

相关文章

javaScript在表单提交时获取表单数据的示例代码

《javaScript在表单提交时获取表单数据的示例代码》本文介绍了五种在JavaScript中获取表单数据的方法:使用FormData对象、手动提取表单数据、使用querySelector获取单个字... 方法 1:使用 FormData 对象FormData 是一个方便的内置对象,用于获取表单中的键值

Rust中的BoxT之堆上的数据与递归类型详解

《Rust中的BoxT之堆上的数据与递归类型详解》本文介绍了Rust中的BoxT类型,包括其在堆与栈之间的内存分配,性能优势,以及如何利用BoxT来实现递归类型和处理大小未知类型,通过BoxT,Rus... 目录1. Box<T> 的基础知识1.1 堆与栈的分工1.2 性能优势2.1 递归类型的问题2.2

Python使用Pandas对比两列数据取最大值的五种方法

《Python使用Pandas对比两列数据取最大值的五种方法》本文主要介绍使用Pandas对比两列数据取最大值的五种方法,包括使用max方法、apply方法结合lambda函数、函数、clip方法、w... 目录引言一、使用max方法二、使用apply方法结合lambda函数三、使用np.maximum函数

如何利用Java获取当天的开始和结束时间

《如何利用Java获取当天的开始和结束时间》:本文主要介绍如何使用Java8的LocalDate和LocalDateTime类获取指定日期的开始和结束时间,展示了如何通过这些类进行日期和时间的处... 目录前言1. Java日期时间API概述2. 获取当天的开始和结束时间代码解析运行结果3. 总结前言在J

Android里面的Service种类以及启动方式

《Android里面的Service种类以及启动方式》Android中的Service分为前台服务和后台服务,前台服务需要亮身份牌并显示通知,后台服务则有启动方式选择,包括startService和b... 目录一句话总结:一、Service 的两种类型:1. 前台服务(必须亮身份牌)2. 后台服务(偷偷干

Redis的数据过期策略和数据淘汰策略

《Redis的数据过期策略和数据淘汰策略》本文主要介绍了Redis的数据过期策略和数据淘汰策略,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录一、数据过期策略1、惰性删除2、定期删除二、数据淘汰策略1、数据淘汰策略概念2、8种数据淘汰策略

轻松上手MYSQL之JSON函数实现高效数据查询与操作

《轻松上手MYSQL之JSON函数实现高效数据查询与操作》:本文主要介绍轻松上手MYSQL之JSON函数实现高效数据查询与操作的相关资料,MySQL提供了多个JSON函数,用于处理和查询JSON数... 目录一、jsON_EXTRACT 提取指定数据二、JSON_UNQUOTE 取消双引号三、JSON_KE

java获取图片的大小、宽度、高度方式

《java获取图片的大小、宽度、高度方式》文章介绍了如何将File对象转换为MultipartFile对象的过程,并分享了个人经验,希望能为读者提供参考... 目China编程录Java获取图片的大小、宽度、高度File对象(该对象里面是图片)MultipartFile对象(该对象里面是图片)总结java获取图片

Java通过反射获取方法参数名的方式小结

《Java通过反射获取方法参数名的方式小结》这篇文章主要为大家详细介绍了Java如何通过反射获取方法参数名的方式,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1、前言2、解决方式方式2.1: 添加编译参数配置 -parameters方式2.2: 使用Spring的内部工具类 -

Java如何获取视频文件的视频时长

《Java如何获取视频文件的视频时长》文章介绍了如何使用Java获取视频文件的视频时长,包括导入maven依赖和代码案例,同时,也讨论了在运行过程中遇到的SLF4J加载问题,并给出了解决方案... 目录Java获取视频文件的视频时长1、导入maven依赖2、代码案例3、SLF4J: Failed to lo