Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public bool CloseConnection()
 {
     try {
         //close access database
         if (accessDB.IsConnected)
         {
             accessDB.Close();
         }
         Thread.Sleep(100);
         return(true);
     } catch (Exception ex) {
         System.Windows.MessageBox.Show(ex.ToString());
         return(false);
     }
 }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reports"></param>
        /// <returns></returns>
        public bool Print_Access_Report(params string[] reports)
        {
            try {
                //close access database
                if (accessDB.IsConnected)
                {
                    accessDB.Close();
                }
                Thread.Sleep(100);

                //init access file
                Access.Application oAccess = null;

                // Start a new instance of Access for Automation:
                oAccess         = new Access.Application();
                oAccess.Visible = false;

                // Open a database in exclusive mode:
                oAccess.OpenCurrentDatabase(Access_FileFullName);

                //print out report
                foreach (var report in reports)
                {
                    // Select the Employees report in the database window: //3
                    oAccess.DoCmd.SelectObject(
                        Access.AcObjectType.acReport, //ObjectType
                        report,                       //ObjectName
                        true                          //InDatabaseWindow
                        );
                    // Print 1 copies of the selected object:
                    oAccess.DoCmd.PrintOut(
                        Access.AcPrintRange.acPrintAll,  //PrintRange
                        System.Reflection.Missing.Value, //PageFrom
                        System.Reflection.Missing.Value, //PageTo
                        Access.AcPrintQuality.acHigh,    //PrintQuality
                        1,                               //Copies
                        false                            //CollateCopies
                        );
                }

                //quit and release resource
                oAccess.CloseCurrentDatabase();
                oAccess.Quit();

                Marshal.ReleaseComObject(oAccess);

                return(true);
            }
            catch {
                return(false);
            }
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="report_name"></param>
        /// <returns></returns>
        public bool Print_Access_Report(string report_name)
        {
            try {
                //close access database
                if (accessDB.IsConnected)
                {
                    accessDB.Close();
                }
                Thread.Sleep(100);

                //init access file
                Access.Application oAccess = null;

                // Start a new instance of Access for Automation:
                oAccess         = new Access.Application();
                oAccess.Visible = false;

                // Open a database in exclusive mode:
                oAccess.OpenCurrentDatabase(Access_FileFullName);

                //// Print preview a report named IMEI_SN_fPrint: //1
                //oAccess.DoCmd.OpenReport(
                //   "IMEI_SN_fPrint", //ReportName
                //   Access.AcView.acViewNormal, //View
                //   System.Reflection.Missing.Value, //FilterName
                //   System.Reflection.Missing.Value //WhereCondition
                //   );

                //// Print a report named IMEI_SN_fPrint: //2
                //oAccess.DoCmd.OpenReport(
                //   report_name, //ReportName
                //   Access.AcView.acViewNormal, //View
                //   System.Reflection.Missing.Value, //FilterName
                //   System.Reflection.Missing.Value //WhereCondition
                //   );


                // Select the Employees report in the database window: //3
                oAccess.DoCmd.SelectObject(
                    Access.AcObjectType.acReport, //ObjectType
                    report_name,                  //ObjectName
                    true                          //InDatabaseWindow
                    );

                // Print 1 copies of the selected object:
                oAccess.DoCmd.PrintOut(
                    Access.AcPrintRange.acPrintAll,  //PrintRange
                    System.Reflection.Missing.Value, //PageFrom
                    System.Reflection.Missing.Value, //PageTo
                    Access.AcPrintQuality.acHigh,    //PrintQuality
                    1,                               //Copies
                    false                            //CollateCopies
                    );

                oAccess.CloseCurrentDatabase();
                oAccess.Quit();

                Marshal.ReleaseComObject(oAccess);

                return(true);
            }
            catch (Exception ex) {
                System.Windows.MessageBox.Show(ex.ToString());
                return(false);
            }
        }