/// <summary> Implements <see cref="IExcelApplication.DisplayException"/> </summary>
        public void DisplayException(string title, string message, Exception ex)
        {
            StringBuilder builder = new StringBuilder(message);

            if (string.IsNullOrEmpty(title))
            {
                title = "Etk";
            }

            Exception currentEx = ex;

            while (currentEx != null)
            {
                builder.AppendFormat("\n\r{0}", currentEx.Message);
                currentEx = currentEx.InnerException;
            }

            if (Application != null)
            {
                using (ExcelMainWindow mainWindow = new ExcelMainWindow(Application.Hwnd))
                {
                    MessageBox.Show(mainWindow, builder.ToString(), title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(builder.ToString(), title, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
        public static void AddRequest(ExcelInterop.Range caller)
        {
            using (ExcelMainWindow excelWindow = new ExcelMainWindow(caller.Application.Hwnd))
            {
                ExcelInterop.Range             firstOutputRange = caller.Offset[0, 1];
                WizardViewModel                viewModel        = WizardViewModel.CreateInstance(caller, firstOutputRange);
                DynamicRequestManagementWindow window           = new DynamicRequestManagementWindow(viewModel);

                WindowInteropHelper windowInteropHelper = new WindowInteropHelper(window);
                windowInteropHelper.Owner = excelWindow.Handle;

                window.DataContext = viewModel;
                window.ShowDialog();
            }
        }
Exemple #3
0
        /// <summary> Template creation</summary>
        /// <param name="caller">Range where to create the menu</param>
        public static void AddTemplate(ExcelInterop.Range caller)
        {
            using (ExcelMainWindow excelWindow = new ExcelMainWindow(caller.Application.Hwnd))
            {
                ExcelInterop.Range firstOutputRange = caller.Offset[0, 1];

                TemplateManagementViewModel viewModel = new TemplateManagementViewModel(null);
                TemplateManagementWindow    window    = new TemplateManagementWindow(viewModel);

                WindowInteropHelper windowInteropHelper = new WindowInteropHelper(window);
                windowInteropHelper.Owner = excelWindow.Handle;
                if (window.ShowDialog().GetValueOrDefault())
                {
                }
            }
        }
        /// <summary> Implements <see cref="IExcelApplication.DisplayMessageBox"/> </summary>
        public void DisplayMessageBox(string title, string message, MessageBoxIcon icon)
        {
            if (string.IsNullOrEmpty(title))
            {
                title = "ETK";
            }

            if (Application != null)
            {
                using (ExcelMainWindow mainWindow = new ExcelMainWindow(Application.Hwnd))
                {
                    MessageBox.Show(mainWindow, message, title, MessageBoxButtons.OK, icon);
                }
            }
            else
            {
                MessageBox.Show(message, title, MessageBoxButtons.OK, icon);
            }
        }
Exemple #5
0
        public ExcelSortAndFilterButton(ExcelTemplateView templateView)
        {
            this.View = templateView;
            ExcelInterop.Worksheet worksheet = null;
            ExcelInterop.Shapes    shapes    = null;
            ExcelInterop.Shape     shape     = null;
            try
            {
                worksheet  = View.ViewSheet;
                OwnerRange = View.FirstOutputCell;
                Name       = $"ExcelBtn{Interlocked.Increment(ref cpt)}";
                shapes     = worksheet.Shapes;

                shape = (ExcelInterop.Shape)shapes.AddOLEObject("Forms.CommandButton.1",
                                                                Type.Missing,
                                                                false,
                                                                false,
                                                                Type.Missing,
                                                                Type.Missing,
                                                                Type.Missing,
                                                                OwnerRange.Left,
                                                                OwnerRange.Top,
                                                                20,
                                                                20);

                shape.Name = Name;
                object s = worksheet.GetType().InvokeMember(Name, BindingFlags.GetProperty, null, worksheet, null);
                commandButton = s as ExcelForms.CommandButton;


                commandButton.FontName  = "Arial";
                commandButton.Font.Size = 8;
                commandButton.Caption   = "S/F";
                commandButton.ForeColor = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);

                commandButton.Click += () =>
                {
                    using (ExcelMainWindow excelWindow = new ExcelMainWindow(ETKExcel.ExcelApplication.Application.Hwnd))
                    {
                        //@@SortAndFilterManagement.DisplaySortAndFilterWindow(excelWindow, View);
                    }
                };
            }
            finally
            {
                if (shape != null)
                {
                    ExcelApplication.ReleaseComObject(shape);
                }
                if (shapes != null)
                {
                    ExcelApplication.ReleaseComObject(shapes);
                }
                if (worksheet != null)
                {
                    ExcelApplication.ReleaseComObject(worksheet);
                }

                shape     = null;
                shapes    = null;
                worksheet = null;
            }
        }