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.

241 lines
11 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 HuizhongLibrary.ReportPrint
{
public partial class PrintSetup : Form
{
private PrintReport m_PrintReport = null;
public PrintReport PrintReport
{
get { return this.m_PrintReport; }
set { this.m_PrintReport = value; }
}
private PrintMuchReport muchReport;
private MyReport report;
public PrintSetup(PrintReport print)
{
InitializeComponent();
this.PrintReport = print;
this.report = print.Report;
BindPinterName();
BindPagerKinds();
checkIsFillBlank.Checked = report.IsFillBlank;
txtCopies.Value = print.Copies;
if (string.IsNullOrEmpty(PrintReport.Document.PrinterSettings.PrinterName) == false) listPinterName.SelectedItem = PrintReport.Document.PrinterSettings.PrinterName;
}
public PrintSetup(PrintMuchReport print)
{
InitializeComponent();
this.muchReport = print;
this.report = print.Report[0];
BindPinterName();
BindPagerKinds();
checkIsFillBlank.Visible = false;
txtCopies.Value = print.Copies;
if (string.IsNullOrEmpty(muchReport.Document.PrinterSettings.PrinterName) == false) listPinterName.SelectedItem = muchReport.Document.PrinterSettings.PrinterName;
}
#region »ñÈ¡´òÓ¡»úÁбí
public void BindPinterName()
{
int a = 0, b = 0;
if (PrintReport != null)
{
foreach (string sc in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
listPinterName.Items.Add(sc);
if (sc == PrintReport.Document.PrinterSettings.PrinterName) b = a;
a++;
}
}
else
{
foreach (string sc in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
listPinterName.Items.Add(sc);
if (sc == muchReport.Document.PrinterSettings.PrinterName) b = a;
a++;
}
}
listPinterName.SelectedIndex = b;
}
#endregion
#region ¿ÉʹÓÃÖ½ÕÅÁбí
public void BindPagerKinds()
{
foreach (Kind kd in report.PagerKind)
{
listPagerKinds.Items.Add(kd.Name);
}
if (report.PagerKind[0].Landscape == false)
{
radioButton1.Checked = true;
txtWidth.Value = Convert.ToDecimal(report.PagerKind[0].Width);
txtHeight.Value = Convert.ToDecimal(report.PagerKind[0].Height);
}
else
{
radioButton2.Checked = true;
txtWidth.Value = Convert.ToDecimal(report.PagerKind[0].Height);
txtHeight.Value = Convert.ToDecimal(report.PagerKind[0].Width);
}
listPagerKinds.SelectedIndex = 0;
CheckPagerNumber.Checked = report.ShowPagerNumber;
}
#endregion
private void listPagerKinds_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (report.PagerKind[listPagerKinds.SelectedIndex].Landscape == false)
{
radioButton1.Checked = true;
txtWidth.Value = Convert.ToDecimal(report.PagerKind[listPagerKinds.SelectedIndex].Width);
txtHeight.Value = Convert.ToDecimal(report.PagerKind[listPagerKinds.SelectedIndex].Height);
}
else
{
radioButton2.Checked = true;
txtWidth.Value = Convert.ToDecimal(report.PagerKind[listPagerKinds.SelectedIndex].Height);
txtHeight.Value = Convert.ToDecimal(report.PagerKind[listPagerKinds.SelectedIndex].Width);
}
report.Width = Convert.ToSingle(txtWidth.Value);
report.Height = Convert.ToSingle(txtHeight.Value);
if (PrintReport != null)
{
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;
}
else
{
int PagerCount = muchReport.GetPagerCount();
txtStart.Value = 1; txtStop.Maximum = PagerCount; txtStop.Value = PagerCount;
}
}
private void txtWidth_ValueChanged(object sender, System.EventArgs e)
{
//if (report.Width > Convert.ToSingle(txtWidth.Value)) { MessageBox.Show(this, "´òÓ¡Ö½ÕÅ¿í¶È²»ÄÜСÓÚ" + report.Width.ToString() + "ºÁÃ×"); return; }
}
private void txtHeight_ValueChanged(object sender, System.EventArgs e)
{
//float h = report.Header.Height + 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
{
if (PrintReport != null)
{
this.PrintReport.Document.PrinterSettings.PrinterName = listPinterName.Text;
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 = report.PagerKind[listPagerKinds.SelectedIndex];
this.PrintReport.ColumnWidthRectify = Convert.ToSingle(txtColumnWidthRectify.Value);
this.PrintReport.IsFillBlank = checkIsFillBlank.Checked;
this.PrintReport.Print();
}
else
{
muchReport.Document.PrinterSettings.PrinterName = listPinterName.Text;
report.ShowPagerNumber = CheckPagerNumber.Checked;
//muchReport.IsFixHeaderFooter = CheckPagerHeader.Checked;
muchReport.Copies = Convert.ToInt16(txtCopies.Value);
muchReport.Collate = CheckCollate.Checked;
//muchReport.StartPageNumber = Convert.ToInt32(txtStart.Value) - 1;
//muchReport.StopPageNumber = Convert.ToInt32(txtStop.Value);
muchReport.Kind = report.PagerKind[listPagerKinds.SelectedIndex];
//muchReport.ColumnWidthRectify = Convert.ToSingle(txtColumnWidthRectify.Value);
//muchReport.IsFillBlank = checkIsFillBlank.Checked;
muchReport.Print();
}
this.Close();
}
catch
{
}
}
private void cmdPrintView_Click(object sender, System.EventArgs e)
{
try
{
if (PrintReport != null)
{
this.PrintReport.Document.PrinterSettings.PrinterName = listPinterName.Text;
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 = 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();
}
else
{
muchReport.Document.PrinterSettings.PrinterName = listPinterName.Text;
report.ShowPagerNumber = CheckPagerNumber.Checked;
//muchReport.IsFixHeaderFooter = CheckPagerHeader.Checked;
muchReport.Copies = Convert.ToInt16(txtCopies.Value);
muchReport.Collate = CheckCollate.Checked;
//muchReport.StartPageNumber = Convert.ToInt32(txtStart.Value) - 1;
//muchReport.StopPageNumber = Convert.ToInt32(txtStop.Value);
muchReport.Kind = report.PagerKind[listPagerKinds.SelectedIndex];
//muchReport.ColumnWidthRectify = Convert.ToSingle(txtColumnWidthRectify.Value);
//muchReport.IsFillBlank = checkIsFillBlank.Checked;
this.Hide();
PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
printPreviewDialog1.Document = muchReport.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;
}
}
}