Beispiel #1
0
        // 将 DataReader 的数据转储到 Grid++Report 的数据集中
        public static void FillRecordToReport(IGridppReport Report, IDataReader dr)
        {
            MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, dr.FieldCount)];
            //根据字段名称与列名称进行匹配,建立DataReader字段与Grid++Report记录集的字段之间的对应关系
            int MatchFieldCount = 0;

            for (int i = 0; i < dr.FieldCount; ++i)
            {
                foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
                {
                    if (String.Compare(fld.RunningDBField, dr.GetName(i), true) == 0)
                    {
                        MatchFieldPairs[MatchFieldCount].grField          = fld;
                        MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i;
                        ++MatchFieldCount;
                        break;
                    }
                }
            }
            // Loop through the contents of the OleDbDataReader object.
            // 将 DataReader 中的每一条记录转储到Grid++Report 的数据集中去
            while (dr.Read())
            {
                Report.DetailGrid.Recordset.Append();
                for (int i = 0; i < MatchFieldCount; ++i)
                {
                    if (!dr.IsDBNull(MatchFieldPairs[i].MatchColumnIndex))
                    {
                        MatchFieldPairs[i].grField.Value = dr.GetValue(MatchFieldPairs[i].MatchColumnIndex);
                    }
                }
                Report.DetailGrid.Recordset.Post();
            }
        }
Beispiel #2
0
        // 将 DataTable 的数据转储到 Grid++Report 的数据集中(jchl)
        public static void FillDataTableToReport(IGridppReport Report, DataTable dt)
        {
            MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, dt.Columns.Count)];

            //根据字段名称与列名称进行匹配,建立DataReader字段与Grid++Report记录集的字段之间的对应关系
            int MatchFieldCount = 0;

            for (int i = 0; i < dt.Columns.Count; ++i)
            {
                foreach (IGRField fld in Report.DetailGrid.Recordset.Fields)
                {
                    if (String.Compare(fld.DBFieldName, dt.Columns[i].ColumnName, true) == 0)
                    {
                        MatchFieldPairs[MatchFieldCount].grField          = fld;
                        MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i;
                        ++MatchFieldCount;
                        break;
                    }
                }
            }

            //Report.DetailGrid.Recordset.
            // 将 DataTable 中的每一条记录转储到 Grid++Report 的数据集中去
            foreach (DataRow dr in dt.Rows)
            {
                Report.DetailGrid.Recordset.Append();

                for (int i = 0; i < MatchFieldCount; ++i)
                {
                    if (!dr.IsNull(MatchFieldPairs[i].MatchColumnIndex))
                    {
                        MatchFieldPairs[i].grField.Value = dr[MatchFieldPairs[i].MatchColumnIndex];
                    }
                }

                Report.DetailGrid.Recordset.Post();
            }
        }
Beispiel #3
0
        private void btnState_Click(object sender, EventArgs e)
        {
            try
            {
                btnState.Enabled = false;
                btnPrint.Enabled = false;
                string message = "";
                bool   bOk     = ((ISelectionItemValidate)this.panel3.Controls[0]).Validing(out message);
                if (!bOk)
                {
                    throw new Exception(message);
                }

                ParameterEx[] parameters = ((IParameterEx)this.panel3.Controls[0]).GetStoreProcedureParameters();
                ri.ReportParameters = ((IParameterEx)this.panel3.Controls[0]).GetReportParameters();

                DataTable printTable = InstanceForm.BDatabase.GetDataTable(ri.StoreProcudeName, parameters);

                if (!System.IO.File.Exists(ri.TemplateFile))
                {
                    CreateReportTemplate(ri, printTable);
                }
                else
                {
                    UpdateReportTemplate(ri, printTable);
                }

                GridppReport Report = new GridppReport();

                Report.LoadFromFile(ri.TemplateFile);
                if (ri.ReportParameters != null)
                {
                    for (int i = 0; i < ri.ReportParameters.Length; i++)
                    {
                        if (Report.Parameters.IndexByName(ri.ReportParameters[i].Text) >= 0)
                        {
                            Report.ParameterByName(ri.ReportParameters[i].Text).AsString = ri.ReportParameters[i].Value.ToString();
                        }
                    }
                }

                Report.FetchRecord += delegate()
                {
                    int index;
                    MatchFieldPairType[] typeArray = new MatchFieldPairType[printTable.Columns.Count];
                    int num = 0;
                    for (index = 0; index < printTable.Columns.Count; index++)
                    {
                        foreach (grproLib.IGRField field in Report.DetailGrid.Recordset.Fields)
                        {
                            if (string.Compare(field.Name, printTable.Columns[index].ColumnName, true) == 0)
                            {
                                typeArray[num].grField          = field;
                                typeArray[num].MatchColumnIndex = index;
                                num++;
                                break;
                            }
                        }
                    }
                    foreach (DataRow row in printTable.Rows)
                    {
                        Report.DetailGrid.Recordset.Append();
                        for (index = 0; index < num; index++)
                        {
                            if (!row.IsNull(typeArray[index].MatchColumnIndex))
                            {
                                typeArray[index].grField.Value = row[typeArray[index].MatchColumnIndex];
                            }
                        }
                        Report.DetailGrid.Recordset.Post();
                    }
                };

                this.axGRDisplayViewer1.Stop();
                this.axGRDisplayViewer1.Report = Report;
                this.axGRDisplayViewer1.ResizeColumnToFitPage();
                this.axGRDisplayViewer1.Start();

                btnState.Enabled = true;
                btnPrint.Enabled = true;
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnState.Enabled = true;
                btnPrint.Enabled = true;
            }
        }