You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
7.3 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace NetLibrary.ReportPrint
{
public partial class PrintSetup : Form
{
private PrintReport m_PrintReport = null;
public PrintReport PrintReport
{
get { return this.m_PrintReport; }
set { this.m_PrintReport = value; }
}
public PrintSetup(PrintReport print)
{
InitializeComponent();
this.PrintReport = print;
BindPinterName();
BindPagerKinds();
checkIsFillBlank.Checked = this.PrintReport.Report.IsFillBlank;
txtCopies.Value = print.Copies;
if (string.IsNullOrEmpty(PrintReport.Document.PrinterSettings.PrinterName) == false) listPinterName.SelectedItem = PrintReport.Document.PrinterSettings.PrinterName;
}
#region 获取打印机列表
public void BindPinterName()
{
int a = 0, b = 0;
foreach (string sc in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
listPinterName.Items.Add(sc);
if (sc == PrintReport.Document.PrinterSettings.PrinterName) b = a;
a++;
}
listPinterName.SelectedIndex = b;
}
#endregion
#region 可使用纸张列表
public void BindPagerKinds()
{
foreach (Kind kd in this.PrintReport.Report.PagerKind)
{
listPagerKinds.Items.Add(kd.Name);
}
if (this.PrintReport.Report.PagerKind[0].Landscape == false)
{
radioButton1.Checked = true;
txtWidth.Value = Convert.ToDecimal(this.PrintReport.Report.PagerKind[0].Width);
txtHeight.Value = Convert.ToDecimal(this.PrintReport.Report.PagerKind[0].Height);
}
else
{
radioButton2.Checked = true;
txtWidth.Value = Convert.ToDecimal(this.PrintReport.Report.PagerKind[0].Height);
txtHeight.Value = Convert.ToDecimal(this.PrintReport.Report.PagerKind[0].Width);
}
listPagerKinds.SelectedIndex = 0;
CheckPagerNumber.Checked = this.PrintReport.Report.ShowPagerNumber;
}
#endregion
private void listPagerKinds_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (this.PrintReport.Report.PagerKind[listPagerKinds.SelectedIndex].Landscape == false)
{
radioButton1.Checked = true;
txtWidth.Value = Convert.ToDecimal(this.PrintReport.Report.PagerKind[listPagerKinds.SelectedIndex].Width);
txtHeight.Value = Convert.ToDecimal(this.PrintReport.Report.PagerKind[listPagerKinds.SelectedIndex].Height);
}
else
{
radioButton2.Checked = true;
txtWidth.Value = Convert.ToDecimal(this.PrintReport.Report.PagerKind[listPagerKinds.SelectedIndex].Height);
txtHeight.Value = Convert.ToDecimal(this.PrintReport.Report.PagerKind[listPagerKinds.SelectedIndex].Width);
}
this.PrintReport.Report.Width = Convert.ToSingle(txtWidth.Value);
this.PrintReport.Report.Height = Convert.ToSingle(txtHeight.Value);
this.PrintReport.SetPageRecordNumber(Convert.ToInt32(txtWidth.Value), Convert.ToInt32(txtHeight.Value));
this.PrintReport.MathPageCount();
int PagerCount = this.PrintReport.GetPagerCount();
txtStart.Value = 1; txtStop.Maximum = PagerCount; txtStop.Value = PagerCount;
}
private void txtWidth_ValueChanged(object sender, System.EventArgs e)
{
if (this.PrintReport.Report.Width > Convert.ToSingle(txtWidth.Value)) { MessageBox.Show(this, "打印纸张宽度不能小于" + this.PrintReport.Report.Width.ToString() + "毫米"); return; }
}
private void txtHeight_ValueChanged(object sender, System.EventArgs e)
{
float h = this.PrintReport.Report.Header.Height + this.PrintReport.Report.Footer.Height;
if (h > Convert.ToSingle(txtHeight.Value)) { MessageBox.Show(this, "打印纸张高度不能小于" + h.ToString() + "毫米"); return; }
}
private void cmdPrint_Click(object sender, System.EventArgs e)
{
try
{
this.PrintReport.Document.PrinterSettings.PrinterName = listPinterName.Text;
this.PrintReport.Report.ShowPagerNumber = CheckPagerNumber.Checked;
this.PrintReport.IsFixHeaderFooter = CheckPagerHeader.Checked;
this.PrintReport.Copies = Convert.ToInt16(txtCopies.Value);
this.PrintReport.Collate = CheckCollate.Checked;
this.PrintReport.StartPageNumber = Convert.ToInt32(txtStart.Value) - 1;
this.PrintReport.StopPageNumber = Convert.ToInt32(txtStop.Value);
this.PrintReport.Kind = this.PrintReport.Report.PagerKind[listPagerKinds.SelectedIndex];
this.PrintReport.ColumnWidthRectify = Convert.ToSingle(txtColumnWidthRectify.Value);
this.PrintReport.IsFillBlank = checkIsFillBlank.Checked;
this.PrintReport.Print();
this.Close();
}
catch
{
}
}
private void cmdPrintView_Click(object sender, System.EventArgs e)
{
try
{
this.PrintReport.Document.PrinterSettings.PrinterName = listPinterName.Text;
this.PrintReport.Report.ShowPagerNumber = CheckPagerNumber.Checked;
this.PrintReport.IsFixHeaderFooter = CheckPagerHeader.Checked;
this.PrintReport.Copies = Convert.ToInt16(txtCopies.Value);
this.PrintReport.Collate = CheckCollate.Checked;
this.PrintReport.StartPageNumber = Convert.ToInt32(txtStart.Value) - 1;
this.PrintReport.StopPageNumber = Convert.ToInt32(txtStop.Value);
this.PrintReport.Kind = this.PrintReport.Report.PagerKind[listPagerKinds.SelectedIndex];
this.PrintReport.ColumnWidthRectify = Convert.ToSingle(txtColumnWidthRectify.Value);
this.PrintReport.IsFillBlank = checkIsFillBlank.Checked;
this.Hide();
PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
printPreviewDialog1.Document = this.m_PrintReport.Document;
printPreviewDialog1.SetDesktopLocation(0, 0);
printPreviewDialog1.SetDesktopBounds(0, 0, SystemInformation.PrimaryMonitorMaximizedWindowSize.Width, SystemInformation.PrimaryMonitorMaximizedWindowSize.Height);
printPreviewDialog1.PrintPreviewControl.Zoom = 0.9;
printPreviewDialog1.ShowDialog();
this.Close();
}
catch
{
}
}
private void txtStart_ValueChanged(object sender, System.EventArgs e)
{
if (txtStart.Value > txtStop.Value) txtStart.Value = txtStop.Value;
}
private void txtStop_ValueChanged(object sender, System.EventArgs e)
{
if (txtStart.Value > txtStop.Value) txtStop.Value = txtStart.Value;
}
}
}