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

相关文章

解决pandas无法读取csv文件数据的问题

《解决pandas无法读取csv文件数据的问题》本文讲述作者用Pandas读取CSV文件时因参数设置不当导致数据错位,通过调整delimiter和on_bad_lines参数最终解决问题,并强调正确参... 目录一、前言二、问题复现1. 问题2. 通过 on_bad_lines=‘warn’ 跳过异常数据3

Python获取浏览器Cookies的四种方式小结

《Python获取浏览器Cookies的四种方式小结》在进行Web应用程序测试和开发时,获取浏览器Cookies是一项重要任务,本文我们介绍四种用Python获取浏览器Cookies的方式,具有一定的... 目录什么是 Cookie?1.使用Selenium库获取浏览器Cookies2.使用浏览器开发者工具

Java获取当前时间String类型和Date类型方式

《Java获取当前时间String类型和Date类型方式》:本文主要介绍Java获取当前时间String类型和Date类型方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录Java获取当前时间String和Date类型String类型和Date类型输出结果总结Java获取

C#监听txt文档获取新数据方式

《C#监听txt文档获取新数据方式》文章介绍通过监听txt文件获取最新数据,并实现开机自启动、禁用窗口关闭按钮、阻止Ctrl+C中断及防止程序退出等功能,代码整合于主函数中,供参考学习... 目录前言一、监听txt文档增加数据二、其他功能1. 设置开机自启动2. 禁止控制台窗口关闭按钮3. 阻止Ctrl +

java如何实现高并发场景下三级缓存的数据一致性

《java如何实现高并发场景下三级缓存的数据一致性》这篇文章主要为大家详细介绍了java如何实现高并发场景下三级缓存的数据一致性,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 下面代码是一个使用Java和Redisson实现的三级缓存服务,主要功能包括:1.缓存结构:本地缓存:使

在MySQL中实现冷热数据分离的方法及使用场景底层原理解析

《在MySQL中实现冷热数据分离的方法及使用场景底层原理解析》MySQL冷热数据分离通过分表/分区策略、数据归档和索引优化,将频繁访问的热数据与冷数据分开存储,提升查询效率并降低存储成本,适用于高并发... 目录实现冷热数据分离1. 分表策略2. 使用分区表3. 数据归档与迁移在mysql中实现冷热数据分

C#解析JSON数据全攻略指南

《C#解析JSON数据全攻略指南》这篇文章主要为大家详细介绍了使用C#解析JSON数据全攻略指南,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、为什么jsON是C#开发必修课?二、四步搞定网络JSON数据1. 获取数据 - HttpClient最佳实践2. 动态解析 - 快速

一文详解如何使用Java获取PDF页面信息

《一文详解如何使用Java获取PDF页面信息》了解PDF页面属性是我们在处理文档、内容提取、打印设置或页面重组等任务时不可或缺的一环,下面我们就来看看如何使用Java语言获取这些信息吧... 目录引言一、安装和引入PDF处理库引入依赖二、获取 PDF 页数三、获取页面尺寸(宽高)四、获取页面旋转角度五、判断

MyBatis-Plus通用中等、大量数据分批查询和处理方法

《MyBatis-Plus通用中等、大量数据分批查询和处理方法》文章介绍MyBatis-Plus分页查询处理,通过函数式接口与Lambda表达式实现通用逻辑,方法抽象但功能强大,建议扩展分批处理及流式... 目录函数式接口获取分页数据接口数据处理接口通用逻辑工具类使用方法简单查询自定义查询方法总结函数式接口

SQL中如何添加数据(常见方法及示例)

《SQL中如何添加数据(常见方法及示例)》SQL全称为StructuredQueryLanguage,是一种用于管理关系数据库的标准编程语言,下面给大家介绍SQL中如何添加数据,感兴趣的朋友一起看看吧... 目录在mysql中,有多种方法可以添加数据。以下是一些常见的方法及其示例。1. 使用INSERT I