Esempio n. 1
0
        protected override void WriteColumnHeader()
        {
            ReportSourceProfile profile = new ReportSourceProfile(_table);

            profile.AddExportColumn("編號");
            profile.AddExportColumn("借入產線");
            profile.AddExportColumn("員工編號");
            profile.AddExportColumn("員工姓名");
            profile.AddExportColumn("日期");
            profile.AddExportColumn("工作單號");
            if (_table.Columns.Contains("品號"))
            {
                profile.AddExportColumn("品號");
            }
            profile.AddExportColumn("非生產名稱").Name = "非生產";
            profile.AddExportColumn("工時");
            profile.AddExportColumn("數量").Name = "完成";
            if (_table.Columns.Contains("待驗數量"))
            {
                profile.AddExportColumn("待驗數量");
            }
            profile.AddExportColumn("備註");

            this.SheetAdapter.GetRange(1, profile.IndexOf("工作單號") + 1).EntireColumn.NumberFormat = "@";

            this.SheetAdapter.ReportProfile = profile;
            this.SheetAdapter.PasteColumns(_table, _columnHeaderRow, 1);
            base.WriteColumnHeader();
        }
Esempio n. 2
0
        protected override void AfterContentWritten()
        {
            ReportSourceProfile profile = this.SheetAdapter.ReportProfile;

            this.SheetAdapter.SetFormat(_columnHeaderRow + 1, profile.IndexOf("編號") + 1, "0");


            Range range = this.SheetAdapter.GetUsedRange(_columnHeaderRow + 1);

            this.SheetAdapter.SetBorder(range, XlBordersIndex.xlInsideHorizontal, XlLineStyle.xlDot, XlBorderWeight.xlThin);
            range.Borders[XlBordersIndex.xlInsideHorizontal].Color = -2565928;

            //設定列印格式
            this.Sheet.PageSetup.Orientation    = Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;
            this.Sheet.PageSetup.CenterFooter   = "第 &P 頁,共 &N 頁";
            this.Sheet.PageSetup.PrintTitleRows = this.SheetAdapter.GetRange(_columnHeaderRow, 1).EntireRow.get_Address(Missing, Missing, XlReferenceStyle.xlA1, Missing, Missing);
            this.Sheet.PageSetup.Zoom           = false;
            this.Sheet.PageSetup.FitToPagesWide = 1;
            this.Sheet.PageSetup.FitToPagesTall = false;

            //調整欄寬
            this.SheetAdapter.GetUsedRange(_columnHeaderRow).Columns.AutoFit();
            this.SheetAdapter.GetRange(1, profile.IndexOf("備註") + 1).ColumnWidth           = 24;
            this.SheetAdapter.GetRange(1, profile.IndexOf("備註") + 1).EntireColumn.WrapText = true;


            //顯示列印對話框
            PrintDialog printDialog = new PrintDialog();

            if (printDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    this.Workbook.PrintOut(Missing, Missing, printDialog.PrinterSettings.Copies, Missing, printDialog.PrinterSettings.PrinterName, Missing, Missing, Missing);
                }
                catch (Exception) { }
            }

            base.AfterContentWritten();

            this.Application.DisplayAlerts = false;
            this.Workbook.Close(Missing, Missing, Missing);
            //this.Application.Quit();
        }
Esempio n. 3
0
        protected override void BeforeExport()
        {
            // Create table
            CreateReportTable();

            // Get data form db
            OleDbConnection conn         = DbConnection.Instance;
            ConnectionState oriConnState = conn.State;

            if ((conn.State & ConnectionState.Open) != ConnectionState.Open)
            {
                conn.Open();
            }

            OleDbCommand cmd = new OleDbCommand();

            cmd.Connection  = conn;
            cmd.CommandText = "SELECT 單據日期, A.單號 as 工作單號, 客戶, 品號, 數量, 預計完成日, B.實際完成日, B.編號 as 序號 " +
                              "FROM 工作單 as A INNER JOIN 工作單品號 as B on A.單號 = B.單號";

            string whereTxt = null;

            if (_worksheetNo != null)
            {
                whereTxt = "A.單號 = ?";
                cmd.Parameters.Add(new OleDbParameter("單號", _worksheetNo));
            }
            else if (_useDate)
            {
                whereTxt = "A.單據日期 >= #" + _startDate.ToString("yyyy/MM/dd") + "# AND A.單據日期 <= #" + _endDate.ToString("yyyy/MM/dd") + "#";
            }

            if (whereTxt != null)
            {
                cmd.CommandText += " WHERE " + whereTxt;
            }

            cmd.CommandText += " ORDER by A.單號, B.編號, B.品號";

            OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);

            adapter.Fill(_table);

            // Fill the serial number ( 1.08.6 below only)

            /*
             * string currentSheet = null;
             * int sn = 1;
             * foreach (DataRow row in _table.Rows)
             * {
             * string sheet = (string)row["工作單號"];
             * if (sheet != currentSheet)
             * {
             * currentSheet = sheet;
             * sn = 1;
             * }
             * row["序號"] = sn++;
             * }
             */

            if (oriConnState == ConnectionState.Closed)
            {
                conn.Close();
            }
            // *****

            // Create profile
            ReportSourceProfile profile = new ReportSourceProfile();

            profile.ColumnHeaderHGrid = true;

            base.BeforeExport();
        }