상단에 전역변수로 설정
private PrintCsFIle _PrintCsFIle = new PrintCsFIle();
private DataTable _DTPRINT1 = new DataTable();
private DataTable _DTPRINT2 = new DataTable();
private DataTable _DTPRINT3 = new DataTable();
출력 버튼 클릭 시 타는 함수
_printCsFile.printCsFile(_DTPRINT1, _DTPRINT2, _DTPRINT3);
각 데이터테이블의 컬럼 설정
private void SetDataTable()
{
_DTPRINT1.Columns.Add("A");
_DTPRINT1.Columns.Add("B");
_DTPRINT1.Columns.Add("C");
_DTPRINT1.Columns.Add("D");
_DTPRINT1.Columns.Add("E");
_DTPRINT1.Columns.Add("F");
_DTPRINT1.Columns.Add("G");
_DTPRINT1.Columns.Add("H");
_DTPRINT1.Columns.Add("I");
_DTPRINT1.Columns.Add("J");
_DTPRINT1.Columns.Add("K");
_DTPRINT1.Columns.Add("L");
_DTPRINT1.Columns.Add("M");
_DTPRINT1.Columns.Add("N");
_DTPRINT1.Columns.Add("O");
_DTPRINT1.Columns.Add("P");
_DTPRINT1.Columns.Add("Q");
_DTPRINT1.Columns.Add("R");
_DTPRINT1.Columns.Add("S");
_DTPRINT1.Columns.Add("T");
//
_DTPRINT2.Columns.Add("A");
_DTPRINT2.Columns.Add("B");
_DTPRINT2.Columns.Add("C");
_DTPRINT2.Columns.Add("D");
_DTPRINT2.Columns.Add("E");
_DTPRINT2.Columns.Add("F");
_DTPRINT2.Columns.Add("G");
_DTPRINT2.Columns.Add("H");
_DTPRINT2.Columns.Add("I");
_DTPRINT2.Columns.Add("J");
_DTPRINT2.Columns.Add("K");
_DTPRINT2.Columns.Add("L");
//
_DTPRINT3.Columns.Add("A");
_DTPRINT3.Columns.Add("B");
_DTPRINT3.Columns.Add("C");
_DTPRINT3.Columns.Add("D");
_DTPRINT3.Columns.Add("E");
_DTPRINT3.Columns.Add("F");
_DTPRINT3.Columns.Add("G");
_DTPRINT3.Columns.Add("H");
_DTPRINT3.Columns.Add("I");
_DTPRINT3.Columns.Add("J");
_DTPRINT3.Columns.Add("K");
_DTPRINT3.Columns.Add("L");
_DTPRINT3.Columns.Add("M");
_DTPRINT3.Columns.Add("N");
_DTPRINT3.Columns.Add("O");
}
데이터테이블에 스프레드 값들 담아주기
_DTPRINT1.Clear();
for (int i = 0; i < fpSpread1.Sheets[0].Rows.Count; i++)
{
_DTPRINT1.Rows.Add(new object[] { i
, fpSpread1.Sheets[0].Cells[i, 0].Value
, fpSpread1.Sheets[0].Cells[i, 1].Value
, fpSpread1.Sheets[0].Cells[i, 2].Value
, fpSpread1.Sheets[0].Cells[i, 3].Value
, fpSpread1.Sheets[0].Cells[i, 4].Value
, fpSpread1.Sheets[0].Cells[i, 5].Value
, fpSpread1.Sheets[0].Cells[i, 6].Value
, fpSpread1.Sheets[0].Cells[i, 7].Value
, fpSpread1.Sheets[0].Cells[i, 8].Value
, fpSpread1.Sheets[0].Cells[i, 9].Value
, fpSpread1.Sheets[0].Cells[i, 10].Value
, fpSpread1.Sheets[0].Cells[i, 11].Value
, fpSpread1.Sheets[0].Cells[i, 12].Value
, fpSpread1.Sheets[0].Cells[i, 13].Value
, fpSpread1.Sheets[0].Cells[i, 14].Value
, fpSpread1.Sheets[0].Cells[i, 15].Value
, fpSpread1.Sheets[0].Cells[i, 16].Value
, fpSpread1.Sheets[0].Cells[i, 17].Value
, fpSpread1.Sheets[0].Cells[i, 18].Value
}
);
따로 만들어준 PrintCsFile.cs 파일에서 레포트 그려주기
using System;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using GrapeCity.DataVisualization.TypeScript;
namespace ScrsFrame.Common
{
internal class PrintCsFile
{
System.Drawing.Font fnt1 = new System.Drawing.Font("굴림체", 15);
System.Drawing.Font fnt2 = new System.Drawing.Font("굴림체", 7);
StringFormat sf = new StringFormat();
StringFormat sf2 = new StringFormat();
StringFormat sf3 = new StringFormat();
// 출력용
private DataTable _DTPRINT1 = new DataTable();
private DataTable _DTPRINT2 = new DataTable();
private DataTable _DTPRINT3 = new DataTable();
private string _TITLE1 = string.Empty;
private string _TITLE2 = string.Empty;
public printCsFile() { }
public void printCsFile(DataTable DT1, DataTable DT2, DataTable DT3)
{
_DTPRINT1 = DT1;
_DTPRINT2 = DT2;
_DTPRINT3 = DT3;
_TITLE1 = DateTime.Now.ToString("yyyy-MM-dd dddd");
_TITLE2 = "";
PrintDocument doc = new PrintDocument();
/*
// 여백 설정
doc.DefaultPageSettings.Margins.Left = Convert.ToInt32(10 * 4);
doc.DefaultPageSettings.Margins.Right = Convert.ToInt32(10 * 4);
doc.DefaultPageSettings.Margins.Top = Convert.ToInt32(10 * 4);
doc.DefaultPageSettings.Margins.Bottom = Convert.ToInt32(10 * 4);
*/
// 용지방향
doc.DefaultPageSettings.Landscape = true;//가로방향(true), 세로방향(false)
PrintPreviewDialog dlg = new PrintPreviewDialog();
dlg.Document = doc;
doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);
dlg.ShowDialog();
}
void doc_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
Brush brushDG = Brushes.DarkGray;
Brush brushB = Brushes.Black;
Pen penB = Pens.Black;
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
sf2.LineAlignment = StringAlignment.Center;
sf2.Alignment = StringAlignment.Near;
sf3.LineAlignment = StringAlignment.Center;
sf3.Alignment = StringAlignment.Far;
#region 상단 타이틀 및 결재 영역
// 왼쪽 상단 STAFF 정보
Rectangle recA001 = new Rectangle(10, 20, 200, 20);
Rectangle recA002 = new Rectangle(10, 40, 200, 20);
g.DrawRectangle(penB, recA001);
g.DrawString($@" SALES DATE {_TITLE1}", fnt2, brushB, recA001, sf2);
g.DrawRectangle(penB, recA002);
g.DrawString($@" STAFF MEMBER {_TITLE2} (sign)", fnt2, brushB, recA002, sf2);
// 타이틀
Rectangle recA01 = new Rectangle(420, 30, 410, 25); // 타이틀 1
Rectangle recA02 = new Rectangle(420, 55, 410, 1); // 타이틀 선
Rectangle recA03 = new Rectangle(420, 55, 410, 20); // 타이틀 2
g.DrawString("D A I L Y R O O M S R E P O R T", fnt1, brushB, recA01, sf);
g.DrawRectangle(penB, recA02);
g.DrawString("", fnt2, brushB, recA03, sf);
// 결재라인
Rectangle recB01 = new Rectangle(900, 20, 20, 60); // 결재라인 결재
Rectangle recB02 = new Rectangle(920, 20, 60, 20); // 결재라인 담당
Rectangle recB03 = new Rectangle(920, 40, 60, 40); // 결재라인 싸인
Rectangle recB04 = new Rectangle(980, 20, 60, 20); // 결재라인 팀장
Rectangle recB05 = new Rectangle(980, 40, 60, 40); // 결재라인 싸인
Rectangle recB06 = new Rectangle(1040, 20, 60, 20); // 결재라인 본부장
Rectangle recB07 = new Rectangle(1040, 40, 60, 40); // 결재라인 싸인
Rectangle recB08 = new Rectangle(1100, 20, 60, 20); // 결재라인 사장
Rectangle recB09 = new Rectangle(1100, 40, 60, 40); // 결재라인 싸인
g.DrawRectangle(penB, recB01); g.DrawString("결\r\n\r\n재", fnt2, brushB, recB01, sf);
g.DrawRectangle(penB, recB02); g.DrawString("담 당", fnt2, brushB, recB02, sf);
g.DrawRectangle(penB, recB03);
g.DrawRectangle(penB, recB04); g.DrawString("과 장", fnt2, brushB, recB04, sf);
g.DrawRectangle(penB, recB05);
g.DrawRectangle(penB, recB06); g.DrawString("부 장", fnt2, brushB, recB06, sf);
g.DrawRectangle(penB, recB07);
g.DrawRectangle(penB, recB08); g.DrawString("임 원", fnt2, brushB, recB08, sf);
g.DrawRectangle(penB, recB09);
#endregion
#region
Rectangle recC01 = new Rectangle(10, 95, 150, 15); // 타이틀
// (_DTPRINT1)
Rectangle recD01 = new Rectangle(10, 110, 60, 30); // ROOM CATEGORY
Rectangle recD02 = new Rectangle(70, 110, 60, 30); // ROOMS COUNT
Rectangle recD03 = new Rectangle(130, 110, 60, 30); // GUEST COUNT
Rectangle recD04 = new Rectangle(190, 110, 300, 15); // SALES CHANNEL
Rectangle recD05 = new Rectangle(190, 125, 60, 15); // ONLINE
Rectangle recD06 = new Rectangle(250, 125, 60, 15); // DIRECT
Rectangle recD07 = new Rectangle(310, 125, 60, 15); // CORPORATE
Rectangle recD08 = new Rectangle(370, 125, 60, 15); // WALK-IN
Rectangle recD09 = new Rectangle(430, 125, 60, 15); // TOTAL SALES
Rectangle recD10 = new Rectangle(490, 110, 60, 30); // ROOMS AVAILABLE
Rectangle recD11 = new Rectangle(550, 110, 300, 15); // CURRENT MONTH
Rectangle recD12 = new Rectangle(550, 125, 60, 15); // ONLINE BOOKINGS
Rectangle recD13 = new Rectangle(610, 125, 60, 15); // DIRECT BOOKINGS
Rectangle recD14 = new Rectangle(670, 125, 60, 15); // CORPORATE BOOKINGS
Rectangle recD15 = new Rectangle(730, 125, 60, 15); // WALK-IN BOOKINGS
Rectangle recD16 = new Rectangle(790, 125, 60, 15); // TOTAL BOOKINGS
Rectangle recD17 = new Rectangle(850, 110, 300, 15); // PREVIOUS MONTH
Rectangle recD18 = new Rectangle(850, 125, 60, 15); // ONLINE BOOKINGS
Rectangle recD19 = new Rectangle(910, 125, 60, 15); // DIRECT BOOKINGS
Rectangle recD20 = new Rectangle(970, 125, 60, 15); // CORPORATE BOOKINGS
Rectangle recD21 = new Rectangle(1030, 125, 60, 15); // WALK-IN BOOKINGS
Rectangle recD22 = new Rectangle(1090, 125, 60, 15); // TOTAL BOOKINGS
g.DrawString("◈ ROOM OCCUPANCY", fnt2, brushB, recC01, sf2);
g.DrawRectangle(penB, recD01); g.FillRectangle(brushDG, recD01); g.DrawString("ROOM CATEGORY", fnt2, brushB, recD01, sf);
g.DrawRectangle(penB, recD02); g.FillRectangle(brushDG, recD02); g.DrawString("ROOMS COUNT", fnt2, brushB, recD02, sf);
g.DrawRectangle(penB, recD03); g.FillRectangle(brushDG, recD03); g.DrawString("GUEST COUNT", fnt2, brushB, recD03, sf);
g.DrawRectangle(penB, recD04); g.FillRectangle(brushDG, recD04); g.DrawString("SALES CHANNEL", fnt2, brushB, recD04, sf);
g.DrawRectangle(penB, recD05); g.FillRectangle(brushDG, recD05); g.DrawString("ONLINE", fnt2, brushB, recD05, sf);
g.DrawRectangle(penB, recD06); g.FillRectangle(brushDG, recD06); g.DrawString("DIRECT", fnt2, brushB, recD06, sf);
g.DrawRectangle(penB, recD07); g.FillRectangle(brushDG, recD07); g.DrawString("CORPORATE", fnt2, brushB, recD07, sf);
g.DrawRectangle(penB, recD08); g.FillRectangle(brushDG, recD08); g.DrawString("WALK-IN", fnt2, brushB, recD08, sf);
g.DrawRectangle(penB, recD09); g.FillRectangle(brushDG, recD09); g.DrawString("TOTAL SALES", fnt2, brushB, recD09, sf);
g.DrawRectangle(penB, recD10); g.FillRectangle(brushDG, recD10); g.DrawString("ROOMS AVAILABLE", fnt2, brushB, recD10, sf);
g.DrawRectangle(penB, recD11); g.FillRectangle(brushDG, recD11); g.DrawString("CURRENT MONTH", fnt2, brushB, recD11, sf);
g.DrawRectangle(penB, recD12); g.FillRectangle(brushDG, recD12); g.DrawString("ONLINE BOOKINGS", fnt2, brushB, recD12, sf);
g.DrawRectangle(penB, recD13); g.FillRectangle(brushDG, recD13); g.DrawString("DIRECT BOOKINGS", fnt2, brushB, recD13, sf);
g.DrawRectangle(penB, recD14); g.FillRectangle(brushDG, recD14); g.DrawString("CORPORATE BOOKINGS", fnt2, brushB, recD14, sf);
g.DrawRectangle(penB, recD15); g.FillRectangle(brushDG, recD15); g.DrawString("WALK-IN BOOKINGS", fnt2, brushB, recD15, sf);
g.DrawRectangle(penB, recD16); g.FillRectangle(brushDG, recD16); g.DrawString("TOTAL BOOKINGS", fnt2, brushB, recD16, sf);
g.DrawRectangle(penB, recD17); g.FillRectangle(brushDG, recD17); g.DrawString("PREVIOUS MONTH", fnt2, brushB, recD17, sf);
g.DrawRectangle(penB, recD18); g.FillRectangle(brushDG, recD18); g.DrawString("ONLINE BOOKINGS", fnt2, brushB, recD18, sf);
g.DrawRectangle(penB, recD19); g.FillRectangle(brushDG, recD19); g.DrawString("DIRECT BOOKINGS", fnt2, brushB, recD19, sf);
g.DrawRectangle(penB, recD20); g.FillRectangle(brushDG, recD20); g.DrawString("CORPORATE BOOKINGS", fnt2, brushB, recD20, sf);
g.DrawRectangle(penB, recD21); g.FillRectangle(brushDG, recD21); g.DrawString("WALK-IN BOOKINGS", fnt2, brushB, recD21, sf);
g.DrawRectangle(penB, recD22); g.FillRectangle(brushDG, recD22); g.DrawString("TOTAL BOOKINGS", fnt2, brushB, recD22, sf);