Basis |
[Top] [Chapter] [Previous] [Next] |
Our demo uses a tab sheet with two pages.
One page #1 (wpdllInt1) we implement a regular word processor while on page #2 the editor responsible for reporting is placed (wpdllInt2).
We initialize both editors in the constructor:
using WPDynamic;
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent();
// Initialize the Editor #1 ------------------------------------------- wpdllInt1.EditorStart("your_name", "your_key"); // Load the PCC file (no password) wpdllInt1.SetLayout("buttons.pcc", ""); // Initialize the editor wpdllInt1.SetEditorMode( // as single editor (no splitscreen) EditorMode.wpmodSingleEditor, // with 16x16 toolbar (for 24x24 use wpmodexToolbarLG) EditorXMode.wpmodexToolbar | EditorXMode.wpmodexTables, // Select the GUI elements ruler, scrollbars and // the lower left panel to change zooming and layout EditorGUI.wpguiRuler | EditorGUI.wpguiHorzScrollBar | EditorGUI.wpguiVertScrollBar, // We have no second editor window, so use wpguiDontSet EditorGUI.wpguiDontSet);
// Set Default Font wpdllInt1.Memo.TextCommandStr(18, 11, "Verdana");
// Set PageSize (use smaller margins, 720 twips) wpdllInt1.Memo.PageSize.SetPageWH(-1, -1, 720, 720, 720, 720);
// This should be also used for new documents wpdllInt1.Memo.TextCommandStr(19, 0, "");
// Activate the Syntax Higlighting for fields and bands wpdllInt1.Memo.TextCommandStr(16, 4, "");
// Initialize the Editor #2 ------------------------------------------- wpdllInt2.EditorStart("your_name", "your_key"); // Load the PCC file (no password) wpdllInt2.SetLayout("buttons.pcc", ""); // A double editor WITH reporting and PDF! wpdllInt2.SetEditorMode( EditorMode.wpmodDoubleEditor,
EditorXMode.wpmodexTables | EditorXMode.wpmodexPDFExport | EditorXMode.wpmodexReporting,
EditorGUI.wpguiHorzScrollBar | EditorGUI.wpguiVertScrollBar , // We have no second editor window, so use wpguiDontSet EditorGUI.wpguiPanelH2 | EditorGUI.wpguiHorzScrollBar | EditorGUI.wpguiVertScrollBar | EditorGUI.wpguiVertRuler
);
// The upper editor should be readonly since we update it from // the template wpdllInt2.Memo.Readonly = true; wpdllInt2.Memo.AutoZoom = AutoZoom.wpAutoZoomOff;
// Set X offset to 360 twips wpdllInt2.Memo.SetIProp(5, 360);
wpdllInt2.Memo.LayoutMode = LayoutMode.wplayShowManualPageBreaks;
// Activate the Syntax Higlighting for fields and bands also in editor #2! wpdllInt2.Memo.TextCommandStr(16, 4, "");
// OPTIONAL: Add some initial text wpdllInt1.TextCursor.InputString("Example\r", 0); wpdllInt1.TextCursor.InputString("<<#group>>\r", 0); wpdllInt1.TextCursor.InputString("<<:data \"databand\"/>>\r", 0); wpdllInt1.TextCursor.InputString("<<Field/>>\r", 0); wpdllInt1.TextCursor.InputString("<<#/group>>\r", 0);
}
We use the OnSelectedIndexChange event of the tabcontrol to initialize the reporting engine, convert the tokens into the internal template format and, if this worked without a problem, start the reporting:
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { if (tabControl1.SelectedIndex == 1) { wpdllInt2.Memo2.Clear(false, false);
// Copy the text from Editor #1 to Editor #2 (on second page) object currtext = wpdllInt1.Memo.SaveToVar(false, "WPT"); wpdllInt2.Memo.LoadFromVar(currtext, false, "AUTO");
// Now do the auto conversion string res = wpdllInt2.Memo.TextCommandStr(17, 0, ""); if (res != null) { // Show an error message MessageBox.Show(res); } else { // Start reporting - fills any field with random data // and loops any group 10 times wpdllInt2.Report.Command(2); // Copy Header+Footer + Create Report }
} }
Please note that we use Report.Command(2) instead of Report.CreateReport to start reporting. This command will also copy any header and footer texts to the destination which can be desirable if the source template was a standard document with tokens. But without controlling events not much will happen, only the text will be copied from the template to the destination.
First we need an event to control the groups:
// This event is used to start, prepare and close a report group private void wpdllInt2_OnReportState(object Sender, string Name, int State, IWPReportBand Band, ref bool Abort) { if(State==0) //REP_BeforeProcessGroup { // Take Name to open a data base query. Move to first Record // and set Abort to TRUE if the query is empty! // Here also Set total variables to 0. Abort = Band.Count>10; } }
Please see "OnReportState" for a complete C# template.
Now some code to fill in data for our fields is missing. To do so the event OnFieldGetText is used. Here we would usually read out a dataset, but for simplicity we here just insert a random value:
Random rnd = new Random();
private void wpdllInt2_OnFieldGetText(object Sender, int Editor, string FieldName, IWPFieldContents Contents) { Contents.StringValue = Convert.ToString(rnd.NextDouble()); }
Now we can already test reporting:
a) Template (with activated syntax highlighting)
b) Second page top editor = template in internal format bottom editor = result
|