示例#1
0
        private void InitCollections()
        {
            controls = new ControlCollection(control.Controls);

            // These will be initialized as needed
            buttons   = null;
            labels    = null;
            textboxes = null;
            combos    = null;
        }
		private void InitCollections()
		{
			controls = new ControlCollection( control.Controls );
			
			// These will be initialized as needed
			buttons = null;
			labels = null;
			textboxes = null;
			combos = null;
		}
示例#3
0
        public void BuildReport(Window owner)
        {
            Stopwatch myTimer = new Stopwatch();

            if (string.IsNullOrEmpty(PrinterName) && string.IsNullOrWhiteSpace(PrinterName))
            {
                MessageBox.Show(owner, "Please select your printer name.", "Atention", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            FileStream stream = null;

            try
            {
                string txtTransactionno1 = "AN11160002";
                string filledBy          = "KIT WAS USED FROM DATE 05 / 01 / 2018   TO DATE @tMonth / @tDay / @tYear";
                string dataDir           = System.IO.Directory.GetCurrentDirectory();
                string fullFileName      = dataDir + @"\templates\";
                var    date       = System.DateTime.Now.ToString("MM-dd-yyyy");
                var    isOldExcel = FileName.EndsWith("xls");

                myTimer.Start();

                stream = new FileStream(fullFileName + FileName, FileMode.Open);

                // Instantiate LoadOptions specified by the LoadFormat.
                LoadOptions loadOptions1 = new LoadOptions(LoadFormat.Excel97To2003);

                // Create a Workbook object and opening the file from the stream
                Workbook wb = isOldExcel ? new Workbook(stream, loadOptions1) : new Workbook(stream);
                wb.Worksheets[0].PageSetup.Orientation = PageOrientationType.Landscape;

                TextBoxCollection textBoxes = wb.Worksheets[0].TextBoxes;
                textBoxes["txtTransactionno1"].Text        = txtTransactionno1;
                textBoxes["txtTransactionno1"].Font.IsBold = true;

                textBoxes["txthospitalname"].Text                 = "General Hospital";
                textBoxes["txthospitalname"].Fill.FillType        = FillType.Solid;
                textBoxes["txthospitalname"].Fill.SolidFill.Color = Color.White;

                textBoxes["txtsiteid"].Text                 = "San Diego, CA";
                textBoxes["txtsiteid"].Fill.FillType        = FillType.Solid;
                textBoxes["txtsiteid"].Fill.SolidFill.Color = Color.White;

                var picture = GenerateBarCode(txtTransactionno1, 247, 38);

                wb.Worksheets[0].Pictures.Add(8, 0, picture);

                textBoxes["txtLocation"].Text             = "LD1";
                textBoxes["txtLocation"].Font.IsBold      = true;
                textBoxes["txttransactionno"].Text        = txtTransactionno1;
                textBoxes["txttransactionno"].Font.IsBold = true;

                wb.Worksheets[0].Cells["B5"].Value = filledBy.Replace("@tMonth", date.Split('-')[0]).Replace("@tDay", date.Split('-')[1]).Replace("@tYear", date.Split('-')[2]);

                DataTable data = GetData();

                var column = 3;
                foreach (DataRow dr in data.Rows)
                {
                    //char columnChar = (char)column;
                    Cell header = wb.Worksheets[0].Cells[8, column];
                    Aspose.Cells.Style objstyle = header.GetStyle();

                    // Specify the angle of rotation of the text.
                    //objstyle.RotationAngle = 60;
                    objstyle.Font.Size = 10;
                    //objstyle.SetBorder(BorderType.LeftBorder, CellBorderType.Thin, Color.Black);
                    header.PutValue(dr[0]);
                    header.SetStyle(objstyle);

                    Cell cell = wb.Worksheets[0].Cells[9, column - 1];

                    cell.PutValue(dr[1]);
                    column += 4;
                }

                //Save the Shared Workbook
                if (isOldExcel)
                {
                    wb.Save(fullFileName + "report.xls", SaveFormat.Excel97To2003);
                }
                else
                {
                    wb.Save(fullFileName + "report.xlsx", SaveFormat.Xlsx);
                }

                myTimer.Stop();
                AddTimeElapsed(FileFormatExtension, myTimer.Elapsed.ToString());

                if (Convert2Pdf)
                {
                    wb.Save(fullFileName + "report.pdf", SaveFormat.Pdf);
                    System.Diagnostics.Process.Start(fullFileName + "report.pdf");
                    Convert2Pdf = false;
                }
                else
                {
                    MessageBox.Show(owner, string.Format("Report has been created successfully."), "Information", MessageBoxButton.OK, MessageBoxImage.Information);

                    ExcelViewer ev = new ExcelViewer(ConvertSheetToImage(wb.Worksheets[0]));
                    ev.Closed += (object sender, EventArgs e) =>
                    {
                        PrintFile(owner, fullFileName + (isOldExcel ? "report.xls" : "report.xlsx"));
                    };
                    ev.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(owner, string.Format("An error has occurred while creating document: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                if (!object.Equals(null, stream))
                {
                    stream.Close();
                }
            }
        }