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

相关文章

java中BigDecimal里面的subtract函数介绍及实现方法

《java中BigDecimal里面的subtract函数介绍及实现方法》在Java中实现减法操作需要根据数据类型选择不同方法,主要分为数值型减法和字符串减法两种场景,本文给大家介绍java中BigD... 目录Java中BigDecimal里面的subtract函数的意思?一、数值型减法(高精度计算)1.

C#代码实现解析WTGPS和BD数据

《C#代码实现解析WTGPS和BD数据》在现代的导航与定位应用中,准确解析GPS和北斗(BD)等卫星定位数据至关重要,本文将使用C#语言实现解析WTGPS和BD数据,需要的可以了解下... 目录一、代码结构概览1. 核心解析方法2. 位置信息解析3. 经纬度转换方法4. 日期和时间戳解析5. 辅助方法二、L

使用Python和Matplotlib实现可视化字体轮廓(从路径数据到矢量图形)

《使用Python和Matplotlib实现可视化字体轮廓(从路径数据到矢量图形)》字体设计和矢量图形处理是编程中一个有趣且实用的领域,通过Python的matplotlib库,我们可以轻松将字体轮廓... 目录背景知识字体轮廓的表示实现步骤1. 安装依赖库2. 准备数据3. 解析路径指令4. 绘制图形关键

解决mysql插入数据锁等待超时报错:Lock wait timeout exceeded;try restarting transaction

《解决mysql插入数据锁等待超时报错:Lockwaittimeoutexceeded;tryrestartingtransaction》:本文主要介绍解决mysql插入数据锁等待超时报... 目录报错信息解决办法1、数据库中执行如下sql2、再到 INNODB_TRX 事务表中查看总结报错信息Lock

使用C#删除Excel表格中的重复行数据的代码详解

《使用C#删除Excel表格中的重复行数据的代码详解》重复行是指在Excel表格中完全相同的多行数据,删除这些重复行至关重要,因为它们不仅会干扰数据分析,还可能导致错误的决策和结论,所以本文给大家介绍... 目录简介使用工具C# 删除Excel工作表中的重复行语法工作原理实现代码C# 删除指定Excel单元

Linux lvm实例之如何创建一个专用于MySQL数据存储的LVM卷组

《Linuxlvm实例之如何创建一个专用于MySQL数据存储的LVM卷组》:本文主要介绍使用Linux创建一个专用于MySQL数据存储的LVM卷组的实例,具有很好的参考价值,希望对大家有所帮助,... 目录在Centos 7上创建卷China编程组并配置mysql数据目录1. 检查现有磁盘2. 创建物理卷3. 创

Nacos日志与Raft的数据清理指南

《Nacos日志与Raft的数据清理指南》随着运行时间的增长,Nacos的日志文件(logs/)和Raft持久化数据(data/protocol/raft/)可能会占用大量磁盘空间,影响系统稳定性,本... 目录引言1. Nacos 日志文件(logs/ 目录)清理1.1 日志文件的作用1.2 是否可以删除

使用Python实现网页表格转换为markdown

《使用Python实现网页表格转换为markdown》在日常工作中,我们经常需要从网页上复制表格数据,并将其转换成Markdown格式,本文将使用Python编写一个网页表格转Markdown工具,需... 在日常工作中,我们经常需要从网页上复制表格数据,并将其转换成Markdown格式,以便在文档、邮件或

Python实现pdf电子发票信息提取到excel表格

《Python实现pdf电子发票信息提取到excel表格》这篇文章主要为大家详细介绍了如何使用Python实现pdf电子发票信息提取并保存到excel表格,文中的示例代码讲解详细,感兴趣的小伙伴可以跟... 目录应用场景详细代码步骤总结优化应用场景电子发票信息提取系统主要应用于以下场景:企业财务部门:需

使用Python获取JS加载的数据的多种实现方法

《使用Python获取JS加载的数据的多种实现方法》在当今的互联网时代,网页数据的动态加载已经成为一种常见的技术手段,许多现代网站通过JavaScript(JS)动态加载内容,这使得传统的静态网页爬取... 目录引言一、动态 网页与js加载数据的原理二、python爬取JS加载数据的方法(一)分析网络请求1