Exemplo n.º 1
0
 private void btClean_Click()
 {
     try{
         var activesheet = (Excel.Worksheet)_excelapp.ActiveSheet;
         if (!_parser.checkTablePresent(activesheet))
         {
             return;
         }
         using (var lForm = new FrmDelete(_excelapp.Hwnd)) {
             lForm.Reports            = _parser.GetReportsList(activesheet.ListObjects[1]);
             lForm.AssociatedInstance = _settings.GetWorksheetParam("DelInstance", "SPECIFIED");
             if (lForm.ShowDialog() != DialogResult.OK)
             {
                 return;
             }
             var reports = _parser.ParseListObjectToReports(activesheet.ListObjects[1], true);
             _settings.SetWorksheetParam("DelInstance", lForm.AssociatedInstance);
             var scheduler = new SchedulerManager(_session);
             var runner    = new FrmRunner(_session.Logger, scheduler.Cancel);
             var exitcode  = runner.Execute(() =>
                                            scheduler.DeleteReportsInstance(ref reports, lForm.AssociatedInstance)
                                            );
             if (exitcode == ExitCode.FAILED || exitcode == ExitCode.CANCELED)
             {
                 return;
             }
             _parser.UpdateListObjectStatus(activesheet.ListObjects[1], reports);
         }
     } catch (Exception ex) { new BusinessObjectsUtils.FrmException(_excelapp.Hwnd, ex).ShowDialog(); }
 }
Exemplo n.º 2
0
        private void btGetList_Click()
        {
            try{
                var scheduler = new SchedulerManager(_session);
                using (var lForm = new FrmGetList(_excelapp.Hwnd, scheduler.EnumFolders, scheduler.EnumReports)) {
                    lForm.ReportsPath        = _settings.GetWorksheetParam("ReportsPath", "");
                    lForm.AssociatedInstance = _settings.GetWorksheetParam("AssociatedInstance", "");
                    lForm.IncludePrompts     = _settings.GetWorksheetParam("IncludePrompts", false);
                    if (lForm.ShowDialog() == DialogResult.OK)
                    {
                        _settings.SetWorksheetParam("ReportsPath", lForm.ReportsPath);
                        _settings.SetWorksheetParam("AssociatedInstance", lForm.AssociatedInstance);
                        _settings.SetWorksheetParam("IncludePrompts", lForm.IncludePrompts);
                        var      runner   = new FrmRunner(_session.Logger, scheduler.Cancel);
                        Report[] reports  = null;
                        var      exitcode = runner.Execute(() =>
                                                           scheduler.GetReports(lForm.ReportsPath, lForm.IncludePrompts, lForm.AssociatedInstance, out reports)
                                                           );
                        if (exitcode == ExitCode.FAILED || exitcode == ExitCode.CANCELED)
                        {
                            return;
                        }
                        var worksheet = (Excel.Worksheet)_excelapp.ActiveSheet;
                        SwitchExcelToIdle(_excelapp, false);

                        worksheet.Cells.EntireColumn.Hidden = false;
                        worksheet.Cells.EntireRow.Hidden    = false;
                        foreach (Excel.ListObject lo in worksheet.ListObjects)
                        {
                            lo.Delete();
                        }

                        var data       = _parser.ParseReportsToDataArray(reports);
                        var title      = _parser.ParseReportsToTitleArray(reports);
                        var nbRow      = data.GetLength(0);
                        var nbCol      = title.GetLength(1);
                        var listobject = worksheet.ListObjects.Add(Excel.XlListObjectSourceType.xlSrcRange, worksheet.Cells.Resize[Math.Max(nbRow + 1, 2), nbCol], Type.Missing, Excel.XlYesNoGuess.xlYes);
                        listobject.HeaderRowRange.Value = title;
                        if (nbRow > 0)
                        {
                            listobject.DataBodyRange.NumberFormat = "@";
                            _parser.FormatListObject(listobject);
                            listobject.DataBodyRange.Value    = data;
                            listobject.DataBodyRange.WrapText = false;
                            _parser.AddPromptsNameAsComment(listobject, reports);
                        }
                        SwitchExcelToIdle(_excelapp, true);
                    }
                }
            } catch (Exception ex) { new BusinessObjectsUtils.FrmException(_excelapp.Hwnd, ex).ShowDialog(); }
        }
Exemplo n.º 3
0
 private void btLogin_Click()
 {
     try{
         if (!IsLoggedIn)
         {
             _session = new SessionManager();
             using (var lForm = new FrmLogin(_excelapp.Hwnd)) {
                 var logdata = new LoginData()
                 {
                     Url      = _settings.GetWorkbookParam("Url", ""),
                     Version  = _settings.GetWorkbookParam("Version", 0),
                     AuthType = _settings.GetWorkbookParam("AuthType", ""),
                     Domain   = _settings.GetWorkbookParam("Domain", ""),
                     Login    = _settings.GetWorkbookParam("Login", ""),
                     Password = _settings.GetWorkbookParam("Password", ""),
                     Proxy    = new Proxy {
                         Host     = _settings.GetWorkbookParam("ProxyHost", ""),
                         Port     = _settings.GetWorkbookParam("ProxyPort", 0),
                         User     = _settings.GetWorkbookParam("ProxyUser", ""),
                         Password = _settings.GetWorkbookParam("ProxyPassword", ""),
                     }
                 };
                 try {
                     lForm.LogHistory = (Dictionary <string, LoginData>)_settings.LoadFromFile("credentials");
                 } catch { }
                 lForm.LoginData = logdata;
                 while (lForm.ShowDialog() == DialogResult.OK)
                 {
                     var runner   = new FrmRunner(_session.Logger, _session.Cancel);
                     var exitcode = runner.Execute(() => _session.Login(lForm.LoginData));
                     if (exitcode == ExitCode.CANCELED)
                     {
                         return;
                     }
                     if (exitcode == ExitCode.SUCCEED)
                     {
                         IsLoggedIn = true;
                         OnLogInOut();
                         _settings.SaveToFile("credentials", lForm.LogHistory);
                         logdata = lForm.LoginData;
                         _settings.SetWorkbookParam("Url", logdata.Url);
                         _settings.SetWorkbookParam("Version", logdata.Version);
                         _settings.SetWorkbookParam("AuthType", logdata.AuthType);
                         _settings.SetWorkbookParam("Domain", logdata.Domain);
                         _settings.SetWorkbookParam("Login", logdata.Login);
                         _settings.SetWorkbookParam("Password", logdata.Password);
                         if (logdata.Proxy != null)
                         {
                             _settings.SetWorkbookParam("ProxyHost", logdata.Proxy.Host);
                             _settings.SetWorkbookParam("ProxyPort", logdata.Proxy.Port);
                             _settings.SetWorkbookParam("ProxyUser", logdata.Proxy.User);
                             _settings.SetWorkbookParam("ProxyPassword", logdata.Proxy.Password);
                         }
                         return;
                     }
                     ;
                 }
             }
         }
         else
         {
             _session.Logout();
             IsLoggedIn = false;
             OnLogInOut();
         }
     } catch (Exception ex) { new BusinessObjectsUtils.FrmException(_excelapp.Hwnd, ex).ShowDialog(); }
 }
Exemplo n.º 4
0
 private void btSchedule_Click()
 {
     try{
         var activesheet = (Excel.Worksheet)_excelapp.ActiveSheet;
         if (!_parser.checkTablePresent(activesheet))
         {
             return;
         }
         using (var lForm = new FrmSchedule(_excelapp.Hwnd)) {
             lForm.Reports     = _parser.GetReportsList(activesheet.ListObjects[1]);
             lForm.Destination = _settings.GetWorksheetParam("Destination", "");
             lForm.Format      = _settings.GetWorksheetParam("Format", "");
             lForm.NotifEmail  = _settings.GetWorksheetParam("NotifEmail", "");
             if (lForm.ShowDialog() != DialogResult.OK)
             {
                 return;
             }
             var reports = _parser.ParseListObjectToReports(activesheet.ListObjects[1], true);
             if (lForm.Schedule)
             {
                 _settings.SetWorksheetParam("Destination", lForm.Destination);
                 _settings.SetWorksheetParam("Format", lForm.Format);
                 _settings.SetWorksheetParam("NotifEmail", lForm.NotifEmail);
                 var scheduler = new SchedulerManager(_session);
                 var runner    = new FrmRunner(_session.Logger, scheduler.Cancel);
                 var exitcode  = runner.Execute(() =>
                                                scheduler.ScheduleReports(
                                                    ref reports,
                                                    lForm.WithPrompts,
                                                    lForm.Date,
                                                    lForm.Destination,
                                                    lForm.Format,
                                                    lForm.WaitEnd,
                                                    lForm.CleanEnd,
                                                    lForm.NotifEmail
                                                    )
                                                );
                 if (exitcode == ExitCode.FAILED || exitcode == ExitCode.CANCELED)
                 {
                     return;
                 }
                 _parser.UpdateListObjectStatus(activesheet.ListObjects[1], reports);
             }
             else if (lForm.CreateXML)
             {
                 string lFilename = String.Empty;
                 using (SaveFileDialog saveDialog = new SaveFileDialog()) {
                     saveDialog.Filter = "XML FIle|*.xml";
                     saveDialog.Title  = "Save XML File";
                     saveDialog.ShowDialog();
                     lFilename = saveDialog.FileName;
                 }
                 if (lFilename != String.Empty)
                 {
                     try {
                         Application.UseWaitCursor = true;
                         PlanSchedule schedulerplan = new PlanSchedule {
                             Credentials = this._session.Credentials,
                             WithPrompts = lForm.WithPrompts,
                             Destination = lForm.Destination,
                             Format      = lForm.Format,
                             WaitEnd     = lForm.WaitEnd,
                             CleanEnd    = lForm.CleanEnd,
                             NotifEmail  = lForm.NotifEmail,
                             Reports     = reports
                         };
                         schedulerplan.ParseToXml(lFilename);
                         MsgBox.Show("Command line :", "\"" + Func.GetRunnerPath() + "\" \"" + lFilename + "\" \"" + lFilename.Replace(".xml", ".log") + "\"");
                     } catch { throw; } finally {
                         Application.UseWaitCursor = false;
                     }
                 }
             }
         }
     } catch (Exception ex) { new BusinessObjectsUtils.FrmException(_excelapp.Hwnd, ex).ShowDialog(); }
 }