public static bool CheckDoc(this COMObject doc, IOrganization org) { // check transacted if (doc.MethodDouble("IsTransacted") == 0) { return(false); } // check firm selected switch (doc.GLOBAL.Connection.ConfigType) { case E1CConfigType.PUB: case E1CConfigType.Buch: COMObject firm = null; try { firm = doc.GetPropertyObject("Фирма"); if (firm.GetPropertyString("Код").Trim() != org.FirmCode) { return(false); } } finally { if (firm != null) { firm.Dispose(); } } return(true); default: return(true); } }
public TestResult DoTest() { Outlook.Application application = null; DateTime startTime = DateTime.Now; try { // start outlook application = new Outlook.Application(true); NetOffice.OutlookSecurity.Suppress.Enabled = true; // Get inbox Outlook._NameSpace outlookNS = application.GetNamespace("MAPI"); Outlook.MAPIFolder inboxFolder = outlookNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox); Outlook._Items items = inboxFolder.Items; COMObject item = null; int i = 1; do { if (null == item) { item = items.GetFirst() as COMObject; } // not every item is a mail item Outlook.MailItem mailItem = item as Outlook.MailItem; if (null != mailItem) { Console.WriteLine(mailItem.SenderName); } if (null != item) { item.Dispose(); } item = items.GetNext() as COMObject; i++; } while (null != item); return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, string.Format("{0} Inbox Items.", items.Count))); } catch (Exception exception) { return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "")); } finally { if (null != application) { if (!application.FromProxyService) { application.Quit(); } application.Dispose(); } } }
public TestResult DoTest() { Excel.Application application = null; DateTime startTime = DateTime.Now; try { application = new NetOffice.ExcelApi.Application(); application.Visible = true; application.DisplayAlerts = false; application.Workbooks.Add(); Excel.Worksheet sheet = application.Workbooks[1].Sheets[1] as Excel.Worksheet; Office.COMAddIn addin = (from a in application.COMAddIns where a.ProgId == "NOTestsMain.ExcelTestAddinCSharp" select a).FirstOrDefault(); if (null == addin || null == addin.Object) { return(new TestResult(false, DateTime.Now.Subtract(startTime), "NOTestsMain.ExcelTestAddinCSharp or addin.Object not found.", null, "")); } bool addinStatusOkay = false; string errorDescription = string.Empty; if (null != addin.Object) { COMObject addinProxy = new COMObject(addin.Object); addinStatusOkay = (bool)Invoker.Default.PropertyGet(addinProxy, "StatusOkay"); errorDescription = (string)Invoker.Default.PropertyGet(addinProxy, "StatusDescription"); addinProxy.Dispose(); } if (addinStatusOkay) { return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "")); } else { return(new TestResult(false, DateTime.Now.Subtract(startTime), string.Format("NOTestsMain.ExcelTestAddinCSharp Addin Status {0}", errorDescription), null, "")); } } catch (Exception exception) { return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "")); } finally { if (null != application) { application.Quit(); application.Dispose(); } } }
public void OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom) { try { if (null != _application) { _application.Dispose(); } } catch (Exception exception) { OfficeRegistry.LogErrorMessage(_hostApplicationName, _progId, "Error occured in OnDisconnection. ", exception); } }
public TestResult DoTest() { Word.Application application = null; DateTime startTime = DateTime.Now; try { application = new Word.Application(); application.Visible = true; application.DisplayAlerts = Word.Enums.WdAlertLevel.wdAlertsNone; application.Documents.Add(); Office.COMAddIn addin = (from a in application.COMAddIns where a.ProgId == "NOTestsMain.WordTestAddinCSharp" select a).FirstOrDefault(); if (null == addin || null == addin.Object) { return(new TestResult(false, DateTime.Now.Subtract(startTime), "NOTestsMain.WordTestAddinCSharp or addin.Object not found.", null, "")); } bool addinStatusOkay = false; string errorDescription = string.Empty; if (null != addin.Object) { COMObject addinProxy = new COMObject(addin.Object); addinStatusOkay = (bool)Invoker.Default.PropertyGet(addinProxy, "StatusOkay"); errorDescription = (string)Invoker.Default.PropertyGet(addinProxy, "StatusDescription"); addinProxy.Dispose(); } if (addinStatusOkay) { return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "")); } else { return(new TestResult(false, DateTime.Now.Subtract(startTime), string.Format("NOTestsMain.WordTestAddinCSharp Addin Status {0}", errorDescription), null, "")); } } catch (Exception exception) { return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "")); } finally { if (null != application) { application.Quit(WdSaveOptions.wdDoNotSaveChanges); application.Dispose(); } } }
/// <summary> /// Експорт податкових з 1С /// </summary> /// <param name="org"></param> /// <param name="period"></param> /// <param name="CallBack"></param> public static async Task <List <J1201010> > GetTAXES(IOrganization org, Connection con, Period period) { List <J1201010> taxes = new List <J1201010>(); GlobalObject1C77 global; try { global = GlobalObject1C77.GetConnection(con); } catch { return(taxes); } COMObject TaxDocs = global.CreateObject("Документ.НалоговаяНакладная"); var begin = period.Begin?.BeginOfDay() ?? DateTime.Now.BeginOfDay(); var end = period.End?.EndOfDay() ?? DateTime.Now.EndOfDay(); if (TaxDocs.MethodDouble("SelectDocuments", begin, end) == 1) { while (TaxDocs.MethodDouble("GetDocument") == 1) { COMObject CurrentDoc = TaxDocs.Method("CurrentDocument") as COMObject; try { if (CheckDoc(CurrentDoc, org)) { DateTime startDate = DateTime.Now; taxes.Add(GetFrom1C77(global, CurrentDoc, org)); TimeSpan time = DateTime.Now.Subtract(startDate); Trace.TraceInformation("Імпортована податкова №{0} від {1} (час виконання - {2})", CurrentDoc.GetPropertyString("DocNum"), CurrentDoc.GetPropertyDateTime("DocDate"), time.ToString("c")); } } catch (Exception e) { Trace.TraceError("Податкова {0} не завантажена.{1}", CurrentDoc.GetPropertyString("DocNum"), e.Message); } finally { CurrentDoc.Dispose(); } await Task.Delay(100); } } TaxDocs.Dispose(); global.Dispose(); return(taxes); }
private void ListInBoxFolder(Outlook.MAPIFolder inboxFolder) { // setup gui listView1.Items.Clear(); // we fetch the inbox folder items Outlook._Items items = inboxFolder.Items; COMObject item = null; int i = 1; do { if (null == item) { item = items.GetFirst() as COMObject; if (null == item) { break; } } // not every item is a mail item Outlook.MailItem mailItem = item as Outlook.MailItem; if (null != mailItem) { ListViewItem newItem = listView1.Items.Add(mailItem.SenderName); newItem.SubItems.Add(mailItem.Subject); } item.Dispose(); item = items.GetNext() as COMObject; i++; } while (null != item); // dipsose items and childs items.Dispose(); }
private void _excelApplication_SheetActivateEvent(COMObject Sh) { textBoxEvents.BeginInvoke(_updateDelegate, new object[] { "Event SheetActivate called." }); Sh.Dispose(); }
void ExcelApplication_SheetActivateEvent(COMObject Sh) { _sheetActivateEvent = true; Sh.Dispose(); }