WPF的打印技术

    科技2024-11-22  17

                                              WPF的打印技术

    思路

    1.创建一个Window窗体,给一个点击事件

    2.把查询的数据转换成DataTable然后把数据集和DataTable表格合并,在绑定水晶报表。

    前端

    3.添加引用

    4.在App.config里面添加

     <startup  useLegacyV2RuntimeActivationPolicy="true">     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>   </startup>

    更改

     

    数据集和水晶报表

    1.把需要的数据存入数据集里面

    后台

    public DataTable LINQToDataTable<T>(IEnumerable<T> varlist) { //定义要返回的DataTable对象 DataTable dtReturn = new DataTable(); //保存列集合的属性信息数组 PropertyInfo[] oProps = null; if (varlist == null) return dtReturn;//安全性检查 //循环遍历集合,使用反射获取类型的属性信息 foreach (T rec in varlist) { //使用反射获取T类型的属性信息,返回一个PropertyInfo类型的集合 #region if (oProps == null) { oProps = ((Type)rec.GetType()).GetProperties(); //循环PropertyInfo数组 foreach (PropertyInfo pi in oProps) { //得到属性的类型 Type colType = pi.PropertyType; //如果属性为泛型类型 if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>))) { //获取泛型类型的参数 colType = colType.GetGenericArguments()[0]; } //将类型的属性名称与属性类型作为DataTable的列数据 dtReturn.Columns.Add(pi.Name, colType); } } #endregion //新建一个用于添加到DataTable中的DataRow对象 DataRow dr = dtReturn.NewRow(); //循环遍历属性集合 foreach (PropertyInfo pi in oProps) { //为DataRow中的指定列赋值 dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue(rec, null); } //将具有结果值的DataRow添加到DataTable集合中 dtReturn.Rows.Add(dr); } return dtReturn;//返回DataTable对象 }

     

    2.查询数据

    //2.查询数据 var listAchievement = (from dbRegister in myMode.PW_Register join dbPerson in myMode.PW_Person on dbRegister.PersonID equals dbPerson.PersonID join dbManPerson in myMode.PW__ManPerson on dbPerson.ManPersonID equals dbManPerson.ManPersonID join dbFemalePerson in myMode.PW__FemalePerson on dbPerson.FemalePersonID equals dbFemalePerson.FemalePersonID join dbNationality in myMode.BS_Nationality on dbManPerson.NationalityID equals dbNationality.NationalityID join dbNational in myMode.BS_National on dbManPerson.NationalID equals dbNational.NationalID join dbNationalitys in myMode.BS_Nationality on dbFemalePerson.NationalityID equals dbNationalitys.NationalityID join dbNationals in myMode.BS_National on dbFemalePerson.NationalID equals dbNationals.NationalID where dbRegister.RegistrationBusinessID == RegistrationBusiness && dbRegister.StateID == 1 select new AchievementInfor { RegisterID = dbRegister.RegisterID, PersonID = dbRegister.PersonID, DateRegistration = dbRegister.DateRegistration.ToString(), ManPersonID = dbPerson.ManPersonID, FemalePersonID = dbPerson.FemalePersonID, ManPersonName = dbManPerson.ManPersonName, ManCertificateNumber = dbManPerson.ManCertificateNumber, NationalityID = dbManPerson.NationalityID, NationalID = dbManPerson.NationalID, NationalityMC = dbNationality.NationalityMC, NationalMC = dbNational.NationalMC, FemalePersonName = dbFemalePerson.FemalePersonName, FemaleCertificateNumber = dbFemalePerson.FemaleCertificateNumber, NationalitysID = dbFemalePerson.NationalityID, NationalsID = dbFemalePerson.NationalID, NationalitysMC = dbNationalitys.NationalityMC, NationalsMC = dbNationals.NationalMC, }).ToList(); listAchievement = listAchievement.Where(m => Convert.ToDateTime(m.DateRegistration) <= Convert.ToDateTime(DateRegistration)).ToList(); //3. 合并数据集(给数据集表格赋值) DataTable dt = LINQToDataTable(listAchievement); //实例化数据集 FFP myCMRS = new FFP(); //把数据集和表格合并(给数据集绑定数据) myCMRS.Tables["FPP"].Merge(dt); //4. 绑定窗口控件 //实例化水晶报表 FFPA myCRP_Staff = new FFPA(); //给水晶报表设置数据集 myCRP_Staff.SetDataSource(myCMRS); //打开第三方控件(绑定数据) Inadmissible.ViewerCore.ReportSource = myCRP_Staff;

     

    Processed: 0.010, SQL: 8