Exemplo n.º 1
0
        public DlgPageSetup()
        {
            this.CltPageSetup = new CLPageSetup();
            this.InitializeComponent();
            this.rdb_Portrait.Checked  = true;
            this.rdb_Zoom.Checked      = true;
            this.rdb_ListFirst.Checked = true;
            PrintDocument document = new PrintDocument();

            foreach (PaperSize size in document.PrinterSettings.PaperSizes)
            {
                this.cbb_PageSize.Items.Add(size.PaperName);
            }
            this.cbb_PageSize.Text = "A4";
            this.cbb_PaintQuality.SelectedIndex   = 1;
            this.cbb_Header.SelectedIndex         = 0;
            this.cbb_Footer.SelectedIndex         = 0;
            this.cbb_Postil.SelectedIndex         = 0;
            this.cbb_PrintWrongCell.SelectedIndex = 0;
            this.txb_Header.Clear();
            this.txb_Footer.Clear();
        }
Exemplo n.º 2
0
        public DlgPageSetup(string pageSetupScript)
        {
            this.CltPageSetup = new CLPageSetup();
            this.InitializeComponent();
            PrintDocument document = new PrintDocument();

            foreach (PaperSize size in document.PrinterSettings.PaperSizes)
            {
                this.cbb_PageSize.Items.Add(size.PaperName);
            }
            this.cbb_PageSize.Text = "A4";
            if (pageSetupScript == "")
            {
                this.InitializeComponent();
                this.rdb_Landscape.Checked            = true;
                this.rdb_Zoom.Checked                 = true;
                this.rdb_RowFirst.Checked             = true;
                this.cbb_PaintQuality.SelectedIndex   = 1;
                this.cbb_PaintQuality.Text            = "600 点/英寸";
                this.cbb_Header.SelectedIndex         = 0;
                this.cbb_Footer.SelectedIndex         = 0;
                this.cbb_Postil.SelectedIndex         = 0;
                this.cbb_PrintWrongCell.SelectedIndex = 0;
                this.txb_Header.Clear();
                this.txb_Footer.Clear();
            }
            else
            {
                XmlDocument doc = new XmlDocument();
                try {
                    doc.LoadXml(pageSetupScript);
                } catch {
                    this.rdb_ListFirst.Checked            = true;
                    this.cbb_PaintQuality.SelectedIndex   = 1;
                    this.cbb_Header.SelectedIndex         = 0;
                    this.cbb_Footer.SelectedIndex         = 0;
                    this.cbb_Postil.SelectedIndex         = 0;
                    this.cbb_PrintWrongCell.SelectedIndex = 0;
                    this.txb_Header.Clear();
                    this.txb_Footer.Clear();
                    return;
                }
                bool   blackAndWhite = this.GetBlackAndWhite(doc);
                double bottomMargin  = this.GetBottomMargin(doc);
                string centerFooter  = null;
                if (this.GetCenterFooter(doc) != "")
                {
                    centerFooter = this.GetCenterFooter(doc);
                }
                string centerHeader = null;
                if (this.GetCenterHeader(doc) != "")
                {
                    centerHeader = this.GetCenterHeader(doc);
                }
                bool   centerHorizontally = this.GetCenterHorizontally(doc);
                bool   centerVertically   = this.GetCenterVertically(doc);
                bool   draft           = this.GetDraft(doc);
                long   firstPageNumber = this.GetFirstPageNumber(doc);
                double footerMargin    = this.GetFooterMargin(doc);
                double headerMargin    = this.GetHeaderMargin(doc);
                string leftFooter      = null;
                if (this.GetLeftFooter(doc) != "")
                {
                    leftFooter = this.GetLeftFooter(doc);
                }
                string leftHeader = null;
                if (this.GetLeftHeader(doc) != "")
                {
                    leftHeader = this.GetLeftHeader(doc);
                }
                double leftMargin     = this.GetLeftMargin(doc);
                string order          = this.GetOrder(doc);
                string orientation    = this.GetOrientation(doc);
                string paperSize      = this.GetPaperSize(doc);
                bool   printGridlines = this.GetPrintGridlines(doc);
                bool   printHeadings  = this.GetPrintHeadings(doc);
                string rightFooter    = null;
                if (this.GetRightFooter(doc) != "")
                {
                    rightFooter = this.GetRightFooter(doc);
                }
                string rightHeader = null;
                if (this.GetRightHeader(doc) != "")
                {
                    rightHeader = this.GetRightHeader(doc);
                }
                double rightMargin    = this.GetRightMargin(doc);
                double topMargin      = this.GetTopMargin(doc);
                int    zoom           = this.GetZoom(doc);
                int    fitToPagesTall = this.GetFitToPagesTall(doc);
                int    fitToPagesWide = this.GetFitToPagesWide(doc);
                int    printQuality   = this.GetPrintQuality(doc);
                string printComments  = this.GetPrintComments(doc);
                string printErrors    = this.GetPrintErrors(doc);
                bool   shrinkToFit    = this.GetShrinkToFit(doc);
                this.ckb_SingleColor.Checked = blackAndWhite;
                this.npd_BottomMargin.Value  = (decimal)bottomMargin;
                string str12 = leftHeader + centerHeader + rightHeader;
                string str13 = null;
                switch (str12)
                {
                case "":
                    str13 = "(无)";
                    break;

                case "第 &P 页":
                    str13 = "第 1 页";
                    break;

                case "第 &P 页,共 &N 页":
                    str13 = "第 1 页,共 ?页";
                    break;

                case "&A":
                    str13 = "Sheet1";
                    break;

                case "Microsoft 机密&D第 &P 页":
                    str13 = "Microsoft 机密,2003-10-31,第 1 页";
                    break;

                case "&F":
                    str13 = "Book1";
                    break;

                case "&A第 &P 页":
                    str13 = "Sheet1,第 1 页";
                    break;

                case "&AMicrosoft 机密第 &P 页":
                    str13 = "Sheet1,Microsoft 机密,第 1 页";
                    break;

                case "&F 第 &P 页":
                    str13 = "Book1,第 1 页";
                    break;

                case "第 &P 页&A":
                    str13 = "第 1 页,Sheet1";
                    break;

                case "第 &P 页&F":
                    str13 = "第 1 页,Book1";
                    break;
                }
                this.cbb_Header.SelectedIndex = 0;
                for (int i = 0; i <= (this.cbb_Header.Items.Count - 1); i++)
                {
                    if (this.cbb_Header.GetItemText(this.cbb_Header.Items[i]) == str13)
                    {
                        this.cbb_Header.SelectedIndex = i;
                    }
                }
                if (this.cbb_Header.SelectedIndex != 0)
                {
                    this.txb_Header.Text = str13;
                }
                else
                {
                    this.txb_Header.Text = "(无)";
                }
                string str14 = leftFooter + centerFooter + rightFooter;
                string str15 = null;
                switch (str14)
                {
                case "":
                    str15 = "(无)";
                    break;

                case "第 &P 页":
                    str15 = "第 1 页";
                    break;

                case "第 &P 页,共 &N 页":
                    str15 = "第 1 页,共 ?页";
                    break;

                case "&A":
                    str15 = "Sheet1";
                    break;

                case "Microsoft 机密&D第 &P 页":
                    str15 = "Microsoft 机密,2003-10-31,第 1 页";
                    break;

                case "&F":
                    str15 = "Book1";
                    break;

                case "&A第 &P 页":
                    str15 = "Sheet1,第 1 页";
                    break;

                case "&AMicrosoft 机密第 &P 页":
                    str15 = "Sheet1,Microsoft 机密,第 1 页";
                    break;

                case "&F 第 &P 页":
                    str15 = "Book1,第 1 页";
                    break;

                case "第 &P 页&A":
                    str15 = "第 1 页,Sheet1";
                    break;

                case "第 &P 页&F":
                    str15 = "第 1 页,Book1";
                    break;
                }
                this.cbb_Footer.SelectedIndex = 0;
                for (int j = 0; j <= (this.cbb_Footer.Items.Count - 1); j++)
                {
                    if (this.cbb_Footer.GetItemText(this.cbb_Header.Items[j]) == str15)
                    {
                        this.cbb_Footer.SelectedIndex = j;
                    }
                }
                if (this.cbb_Footer.SelectedIndex != 0)
                {
                    this.txb_Footer.Text = str15;
                }
                else
                {
                    this.txb_Footer.Text = "(无)";
                }
                this.ckb_Level.Checked        = centerHorizontally;
                this.ckb_Vertical.Checked     = centerVertically;
                this.ckb_PrintAsDraft.Checked = draft;
                this.txb_StartPage.Text       = firstPageNumber.ToString();
                this.npd_FooterMargin.Value   = (decimal)footerMargin;
                this.npd_HeaderMargin.Value   = (decimal)headerMargin;
                this.npd_LeftMargin.Value     = (decimal)leftMargin;
                if (order == "xlDownThenOver")
                {
                    this.rdb_ListFirst.Checked = true;
                }
                if (order == "xlOverThenDown")
                {
                    this.rdb_RowFirst.Checked = true;
                }
                if (orientation == "xlPortrait")
                {
                    this.rdb_Portrait.Checked = true;
                }
                if (orientation == "xlLandscape")
                {
                    this.rdb_Landscape.Checked = true;
                }
                if (paperSize.StartsWith("xlPaper"))
                {
                    switch (paperSize)
                    {
                    case "xlPaperLetter":
                        paperSize = "Letter";
                        break;

                    case "xlPaperLegal":
                        paperSize = "Legal";
                        break;

                    case "xlPaperExecutive":
                        paperSize = "Executive";
                        break;

                    case "xlPaperA3":
                        paperSize = "A3";
                        break;

                    case "xlPaperA4":
                        paperSize = "A4";
                        break;

                    case "xlPaperA5":
                        paperSize = "A5";
                        break;

                    case "xlPaperB4":
                        paperSize = "B4(JIS)";
                        break;

                    case "xlPaperB5":
                        paperSize = "B5(JIS)";
                        break;

                    case "xlPaper11x17":
                        paperSize = "11x17";
                        break;

                    case "xlPaperEnvelope10":
                        paperSize = "Envelope #10";
                        break;

                    case "xlPaperEnvelopeDL":
                        paperSize = "Evenlope DL";
                        break;

                    case "xlPaperEnvelopeC5":
                        paperSize = "Evenlope C5";
                        break;

                    case "xlPaperEnvelopeB5":
                        paperSize = "Evenlope B5";
                        break;

                    case "xlPaperEnvelopeMonarch":
                        paperSize = "Evenlope Monarch";
                        break;

                    case "xlPaperEnvelopeC3":
                        paperSize = "大号明信片";
                        break;

                    case "xlPaperEnvelopePersonal":
                        paperSize = "明信片";
                        break;

                    case "xlPaperFolio":
                        paperSize = "8.5x13";
                        break;
                    }
                }
                if ((paperSize != "") && (paperSize != null))
                {
                    int index = this.cbb_PageSize.Items.IndexOf(paperSize);
                    if (index < 0)
                    {
                        MessageBox.Show("严重警告:当前的页面设置中的纸张大小“" + paperSize + "”和当前的打印机不兼容,请重新设置纸张大小或者默认打印机!");
                    }
                    else
                    {
                        this.cbb_PageSize.SelectedIndex = index;
                    }
                }
                this.ckb_GridLine.Checked  = printGridlines;
                this.ckb_RowList.Checked   = printHeadings;
                this.npd_RightMargin.Value = (decimal)rightMargin;
                this.npd_TopMargin.Value   = (decimal)topMargin;
                if (zoom != 100)
                {
                    this.npd_Zoom.Value = zoom;
                }
                if ((fitToPagesTall != 1) || (fitToPagesWide != 1))
                {
                    this.npd_PageHigh.Value  = fitToPagesTall;
                    this.npd_PageWidth.Value = fitToPagesWide;
                }
                if (this.NotZoomButFittoTallWide)
                {
                    this.rdb_Adjust.Checked = true;
                }
                else
                {
                    this.rdb_Zoom.Checked = true;
                }
                switch (printQuality)
                {
                case 0x4b0:
                    this.cbb_PaintQuality.SelectedIndex = 0;
                    break;

                case 600:
                    this.cbb_PaintQuality.SelectedIndex = 1;
                    break;

                case 0:
                    this.cbb_PaintQuality.SelectedIndex = 1;
                    break;
                }
                string str19 = printComments;
                if (str19 != null)
                {
                    if (str19 == "xlPrintInPlace")
                    {
                        this.cbb_Postil.SelectedIndex = 2;
                    }
                    else if (str19 == "xlPrintNoComments")
                    {
                        this.cbb_Postil.SelectedIndex = 0;
                    }
                    else if (str19 == "xlPrintSheetEnd")
                    {
                        this.cbb_Postil.SelectedIndex = 1;
                    }
                }
                if (printComments == "")
                {
                    this.cbb_Postil.SelectedIndex = 0;
                }
                string str20 = printErrors;
                if (str20 != null)
                {
                    if (str20 == "xlPrintErrorsBlank")
                    {
                        this.cbb_PrintWrongCell.SelectedIndex = 1;
                    }
                    else if (str20 == "xlPrintErrorsDash")
                    {
                        this.cbb_PrintWrongCell.SelectedIndex = 2;
                    }
                    else if (str20 == "xlPrintErrorsDisplayed")
                    {
                        this.cbb_PrintWrongCell.SelectedIndex = 0;
                    }
                    else if (str20 == "xlPrintErrorsNA")
                    {
                        this.cbb_PrintWrongCell.SelectedIndex = 3;
                    }
                }
                if (printErrors == "")
                {
                    this.cbb_PrintWrongCell.SelectedIndex = 0;
                }
                this.chk_ShrinkToFit.Checked = shrinkToFit;
            }
        }