Open-source: Principles of MIS gold printing and implementation of step by step (1)

Source: Internet
Author: User

We have discussed the implementation of print page settings, printer settings, and print preview dialog box. You can modify this generic class for your own projects. This class will also be used in the MIS gold printing link we will explain and have implemented. Let's work together to implement our own MIS Printing program!

From now on, we will take a step-by-step approach to printing management information system (MIS) reports, documents (such as procurement orders, orders, etc.), contracts (such as industrial and mining enterprise contracts, the format is very complex, such as merging grids and text.

Many print programs are designed for specific grid controls such as DataGrid printing. However, for general purposes, what should we do?

The core of the implementation is to print two-dimensional data, and draw lines to form a grid. Multiple grids form reports and documents. What about printing text? Haha, it's still a grid. It's just a row and a column. You don't need to draw grid lines. Someone may ask, can my reports or document contracts be implemented if they are too complicated? The answer is yes. We can combine multiple grids to merge cells in the grid.

After the above analysis, we only need to print a two-dimensional data and draw a straight line or a rectangular line to achieve any printing. In future implementations, we will see an idraw interface that contains at least one void draw () method. The two core classes we want to perform inherit and implement draw (). So I have several grids to instantiate several such objects, and it is okay to call draw.

In the MIS golden print channel, the following default and common objects are provided: title, caption, top, header, multiheader, body, footer, bottom, and misgoldprinter. You can see why I have provided these objects, this is because the title, subtitle, grid header description, and grid column title are printed when you print a report or document. I am calling it a multi-layer header (generally, Chinese people want to make the table clear, the title of a grid column is complex. It can be illustrated by several rows and multiple columns and some merging units.), data grid subject, and subject grid footer, top and bottom are two rows and three columns of objects above and below them. The misgoldprinter class organizes these objects to flexibly manage these objects and print any complicated reports and bills.

Among the above common default objects, top, header, multiheader, body, footer, and bottom are directly or indirectly inherited from our core class, that is, drawing a grid, although Title and caption can also be implemented using a grid with one row and one column, I still implement it in another way. Caption can be used to set text and font. The title inherits from caption, because the title must contain two underscores.

If you want to set (for example, to print only the text of cells in a grid, do not plot the gridlines), you can add or disable the set attribute in misgoldprinter, or set the set attribute in each object, after determining whether to print the title, multi-layer header, and grid lines, or using Excel for format, analysis, and statistics, we only need to print the number of Excel files.

Our design philosophy is: simple, fast, easy to use and practical

For example, we drag a command button in the window and name it btnprinteasy. Double-click the button and write the following code to print the grid:

C #:
Private void btnprinteasy_click (Object sender, system. eventargs E)
{
Misgoldprinter webmis = new misgoldprinter (); // print component
Webmis. Title = "mis gold print \ nwww. webmis. com. cn"; // grid title
Webmis. datasource = This. datagrid1; // The DataGrid is used as the data source or any two-dimensional array.
Webmis. Preview (); // print preview
}

VB. NET:
Private sub btnprinteasy_click (byval sender as system. Object, byval e as system. eventargs) handles btnprinteasy. Click
Dim webmis as misgoldprinter print component
Webmis = new misgoldprinter
Webmis. Title = "mis "+ vbcrlf + "www. webmis. com. cn" 'grid title
Webmis. datasource = me. D1 D1 'datagrid as the data source
Webmis. Preview () 'print preview
End sub

Of course, do not forget the following code. We need to write some test data for the DataGrid. Double-click the blank window to call the form1_load event of the window, as shown below:
C #:

Private void form1_load (Object sender, system. eventargs E)
{
This. datagrid1.datasource = This. getdatasource ();
}

Private datatable getdatasource ()
{
Datatable dt = new datatable ();

Int rows = 50;
Int Cols = 6;

// Add rows
For (INT introwindex = 0; introwindex <rows; introwindex ++)
{
DT. Rows. Add (Dt. newrow ());
}
// Add a new column
For (INT intcolindex = 0; intcolindex <Cols; intcolindex ++)
{
// DT. Columns. Add (intcolindex. tostring ());
DT. Columns. Add ();
// Enter the default value as an empty string (. NET textcolumn is "null" by default ")
DT. Columns [intcolindex]. defaultvalue = "";
}

Int I, J;
For (I = 0; I <rows; I ++)
{
For (j = 0; j <Cols-3; j ++)
{
DT. Rows [I] [J] = (I + 1). tostring () + "row" + (J + 1). tostring () + "column ";
DT. Rows [I] [Cols-3] = (J + 1). tostring () + "." + (I + 1). tostring ();
DT. Rows [I] [Cols-2] = (I + 1). tostring ();
}
DT. rows [I] [Cols-1] = (double. parse (DT. rows [I] [Cols-2]. tostring () * double. parse (DT. rows [I] [Cols-3]. tostring ())). tostring ();
}

Return DT;
}

VB. NET:
Private sub form1_load (byval sender as system. Object, byval e as system. eventargs) handles mybase. Load
Me. datagrid1.datasource = me. getdatasource ()
End sub

Private function getdatasource () as system. Data. datatable
Dim dT as new system. Data. datatable
Dim rows, cols as int32
Rows = 50
Cols = 6

Dim I, j as int32
I = 0
While (I <rows)
DT. Rows. Add (Dt. newrow ())
I + = 1
End while

I = 0
While (I <Cols)
DT. Columns. Add ()
I + = 1
End while

For I = 0 to rows-1
For J = 0 to Cols-1
DT. Rows (I) (j) = (I + 1). tostring () + "row" + (J + 1). tostring () + "column"
DT. Rows (I) (Cols-3) = (J + 1). tostring () + "." + (I + 1). tostring ()
DT. Rows (I) (Cols-2) = (I + 1). tostring ()
Next
DT. rows (I) (Cols-1) = (double. parse (DT. rows (I) (Cols-2 ). tostring () * double. parse (DT. rows (I) (Cols-3 ). tostring ())). tostring ()
Next

Return dt
End Function

Private sub form1_load (byval sender as system. Object, byval e as system. eventargs) handles mybase. Load
Me. datagrid1.datasource = me. getdatasource ()
End sub

How is it? Isn't it complicated? If we want to change the title Font, we can easily do so. You can also set the sub-(sub-) Title, grid title, header, footer, and description of the Table Base appended to the grid. In short, printing can be easily done without having to do a lot of things.

We will use the Step by Step Method in subsequent articles to implement Printing Based on specific programs step by step. After you finish reading the article, you will feel that printing and managing the permanent topic of the information system will become a topic, and I can implement it myself.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.