예제 #1
0
 public void Execute(IExcelTemplateView view)
 {
     try
     {
         RealExecute(view);
     }
     catch (Exception ex)
     {
         StepsErrorMessages.Add(ex.ToString(null));
     }
     finally
     {
         Done = true;
         if (!StepsErrorMessages.Any())
         {
             Success = true;
             Errors  = null;
         }
         else
         {
             Success = false;
             Errors  = string.Join("\r\n", StepsErrorMessages.ToArray());
         }
     }
 }
예제 #2
0
 /// <summary> Implements <see cref="IExcelTemplateManager.RenderDataOnly"/> </summary>
 public void RenderDataOnly(IExcelTemplateView view)
 {
     if (view != null)
     {
         RenderDataOnly(new [] { view });
     }
 }
예제 #3
0
 /// <summary> Implements <see cref="IExcelTemplateManager.Clear"/> </summary>
 public void ClearView(IExcelTemplateView view)
 {
     if (view != null)
     {
         ClearViews(new [] { view });
     }
 }
예제 #4
0
 public static EtkView CreateInstance(IExcelTemplateView view)
 {
     if (view == null)
     {
         return(null);
     }
     return(new EtkView(view));
 }
예제 #5
0
        /// <summary> Create and render the dashboard view</summary>
        private void CreateAndRender()
        {
            view = ETKExcel.TemplateManager.AddView("Dashboard Templates", "Main", "Dashboard", "B1");
            // Inject the data source
            ExcelTestsManager testsManager = new ExcelTestsManager();

            view.SetDataSource(testsManager);
            // RenderView the dashboard
            ETKExcel.TemplateManager.Render(view);
        }
예제 #6
0
        /// <summary> Implements <see cref="IExcelTemplateManager.RemoveView"/> </summary>
        public void RemoveView(IExcelTemplateView view)
        {
            ExcelTemplateView excelView = view as ExcelTemplateView;

            if (excelView == null)
            {
                return;
            }

            RemoveViews(new IExcelTemplateView[] { view });
        }
예제 #7
0
        override protected void RealExecute(IExcelTemplateView view)
        {
            if (view.RenderedArea == null)
            {
                StepsErrorMessages.Add("Rendered area must not be null");
            }
            else
            {
                if (view.RenderedArea.Width != 3 || view.RenderedArea.Height != 10)
                {
                    StepsErrorMessages.Add("Rendered area must be 3*10");
                }

                if (view.RenderedRange[1, 1].Value != 1)
                {
                    StepsErrorMessages.Add("Cell [1, 1] must contains '1'");
                }
                if (view.RenderedRange[1, 2].Value != "Product 1")
                {
                    StepsErrorMessages.Add("Cell [1, 2] must contains 'Product 1'");
                }
                if (view.RenderedRange[1, 3].Value != 11.0)
                {
                    StepsErrorMessages.Add("Cell [1, 3] must contains '11.00'");
                }

                if (view.RenderedRange[5, 1].Value != 5)
                {
                    StepsErrorMessages.Add("Cell [5, 1] must contains '5'");
                }
                if (view.RenderedRange[5, 2].Value != "Product 5")
                {
                    StepsErrorMessages.Add("Cell [5, 2] must contains 'Product 5'");
                }
                if (view.RenderedRange[5, 3].Value != 55.0)
                {
                    StepsErrorMessages.Add("Cell [5, 3] must contains '55.00'");
                }

                if (view.RenderedRange[10, 1].Value != 10)
                {
                    StepsErrorMessages.Add("Cell [10, 1] must contains '10'");
                }
                if (view.RenderedRange[10, 2].Value != "Product 10")
                {
                    StepsErrorMessages.Add("Cell [10, 2] must contains 'Product 10'");
                }
                if (view.RenderedRange[10, 3].Value != 100.0)
                {
                    StepsErrorMessages.Add("Cell [10, 3] must contains '100.00'");
                }
            }
        }
예제 #8
0
        private void ShowCustomers()
        {
            if (mainCustomersView != null)
            {
                ETKExcel.TemplateManager.RemoveView(mainCustomersView);
            }

            mainCustomersView = ETKExcel.TemplateManager.AddView("TemplatesCustomers", "Main", "Customers", "B2");

            mainCustomersView.SetDataSource(CustomersManager.Customers);
            mainCustomersView.Render();
        }
예제 #9
0
        override protected void RealExecute(IExcelTemplateView view)
        {
            if (view.RenderedArea == null)
            {
                StepsErrorMessages.Add("Rendered area must not be null");
            }
            else
            {
                if (view.RenderedArea.Width != 4 || view.RenderedArea.Height != 4)
                {
                    StepsErrorMessages.Add("Rendered area must be 4*4");
                }

                if (view.RenderedRange[1, 1].Value != 1)
                {
                    StepsErrorMessages.Add("Cell [1, 1] must contains '1'");
                }
                if (view.RenderedRange[1, 2].Value != "First Shop")
                {
                    StepsErrorMessages.Add("Cell [1, 2] must contains 'First Shop'");
                }
                if (view.RenderedRange[1, 4].Value != "First Shop Reception Phone number")
                {
                    StepsErrorMessages.Add("Cell [1, 4] must contains 'First Shop Reception Phone number'");
                }

                if (view.RenderedRange[2, 1].Value != 2)
                {
                    StepsErrorMessages.Add("Cell [2, 1] must contains '2'");
                }
                if (view.RenderedRange[2, 2].Value != "Second Shop")
                {
                    StepsErrorMessages.Add("Cell [2, 2] must contains 'Second Shop'");
                }
                if (view.RenderedRange[2, 4].Value != "Second Shop Reception Phone number")
                {
                    StepsErrorMessages.Add("Cell [2, 4] must contains 'Second Shop Reception Phone number'");
                }

                if (view.RenderedRange[4, 1].Value != 4)
                {
                    StepsErrorMessages.Add("Cell [4, 1] must contains '4'");
                }
                if (view.RenderedRange[4, 2].Value != "Fourth Shop")
                {
                    StepsErrorMessages.Add("Cell [4, 2] must contains 'Fourth Shop'");
                }
                if (view.RenderedRange[4, 4].Value != "Fourth Shop Reception Phone number")
                {
                    StepsErrorMessages.Add("Cell [4, 4] must contains 'Fourth Shop Reception Phone number'");
                }
            }
        }
예제 #10
0
 public EtkView AddViewFromNames(string sheetTemplatePath, string templateName, string sheetDestinationName, string destinationRange, string clearingCell = null)
 {
     try
     {
         IExcelTemplateView view = ETKExcel.TemplateManager.AddView(sheetTemplatePath, templateName, sheetDestinationName, destinationRange, clearingCell);
         return(EtkView.CreateInstance(view));
     }
     catch (Exception ex)
     {
         ETKExcel.ExcelApplication.DisplayException(null, "'Add View from names' failed", ex);
         return(null);
     }
 }
예제 #11
0
        override protected void RealExecute(IExcelTemplateView view)
        {
            if (view.RenderedArea == null)
            {
                StepsErrorMessages.Add("Rendered area must not be null");
            }
            else
            {
                if (view.RenderedArea == null || view.RenderedArea.Width != 4 || view.RenderedArea.Height != 6)
                {
                    StepsErrorMessages.Add("Rendered area must be 4*6");
                }

                if (view.RenderedRange[1, 1].Value != "ID")
                {
                    StepsErrorMessages.Add("First cell must contains 'ID'");
                }

                if (view.RenderedRange[1, 4].Value != "Reception Phone Number")
                {
                    StepsErrorMessages.Add("Cells [1, 3] must contains 'Reception Phone Number'");
                }

                if (view.RenderedRange[2, 1].Value != 1)
                {
                    StepsErrorMessages.Add("Cells [2, 1] must contains '1'");
                }

                if (view.RenderedRange[2, 4].Value != "First Shop Reception Phone number")
                {
                    StepsErrorMessages.Add("Cells [2, 3] must contains 'First Shop Reception Phone number'");
                }

                if (view.RenderedRange[4, 2].Value != "Third Shop")
                {
                    StepsErrorMessages.Add("Cells [4, 2] must contains 'Third Shop'");
                }

                if (view.RenderedRange[4, 4].Value != "Third Shop Reception Phone number")
                {
                    StepsErrorMessages.Add("Cells [2, 3] must contains 'Third Shop Reception Phone number'");
                }

                if (view.RenderedRange[6, 1].Value != "Shops")
                {
                    StepsErrorMessages.Add("First cell of last row must contains 'Shops'");
                }
            }
        }
예제 #12
0
        private void ShowShares()
        {
            if (mainSharesView != null)
            {
                ETKExcel.TemplateManager.RemoveView(mainSharesView);
            }

            mainSharesView = ETKExcel.TemplateManager.AddView("TemplatesShares", "Main", "Shares", "B2");

            BasketManager basketManager = new BasketManager();

            mainSharesView.SetDataSource(basketManager);
            mainSharesView.Render();

            //mainSharesView.ViewSheetIsActivated += () => basketManager.StartChanging();
            mainSharesView.ViewSheetIsDeactivated += () => basketManager.StopChanging();
        }
예제 #13
0
 private EtkView(IExcelTemplateView excelView)
 {
     ExcelView = excelView;
 }
예제 #14
0
        /// <summary> Implements <see cref="IExcelTemplateManager.AddView"/> </summary>
        public IExcelTemplateView AddView(string sheetTemplatePath, string templateName, string sheetDestinationName, string destinationRange, string clearingCellName)
        {
            ExcelInterop.Workbooks workbooks        = null;
            ExcelInterop.Workbook  workbook         = null;
            ExcelInterop.Worksheet sheetContainer   = null;
            ExcelInterop.Worksheet sheetDestination = null;
            try
            {
                if (string.IsNullOrEmpty(sheetTemplatePath))
                {
                    throw new ArgumentNullException("the sheet container name is mandatory");
                }

                if (sheetDestinationName == null)
                {
                    throw new ArgumentNullException("Destination sheet name is mandatory");
                }

                string sheetTemplateName;
                if (sheetTemplatePath.Contains("|"))
                {
                    sheetTemplateName = sheetTemplatePath.Substring(sheetTemplatePath.LastIndexOf("|") + 1);
                    string workbookPath = sheetTemplatePath.Substring(sheetTemplatePath.LastIndexOf("|") - 1);
                    workbooks = ETKExcel.ExcelApplication.Application.Workbooks;
                    workbook  = workbooks.Open(workbookPath, true, true);
                }
                else
                {
                    sheetTemplateName = sheetTemplatePath;
                    workbook          = ETKExcel.ExcelApplication.Application.ActiveWorkbook;
                }


                sheetContainer = ETKExcel.ExcelApplication.GetWorkSheetFromName(workbook, sheetTemplateName);
                if (sheetContainer == null)
                {
                    throw new ArgumentException($"Cannot find the Destination sheet '{sheetTemplatePath}'");
                }
                sheetDestination = ETKExcel.ExcelApplication.GetWorkSheetFromName(workbook, sheetDestinationName);
                if (sheetDestination == null)
                {
                    throw new ArgumentException($"Cannot find the Destination sheet '{sheetDestinationName}'");
                }

                ExcelInterop.Range clearingCell = null;
                if (!string.IsNullOrEmpty(clearingCellName))
                {
                    clearingCell = ETKExcel.ExcelApplication.Application.Range[clearingCellName];
                    if (clearingCell == null)
                    {
                        throw new ArgumentException($"Cannot find the clearing cell '{clearingCellName}'. Please use the 'sheetname!rangeaddress' format");
                    }
                }

                ExcelInterop.Range destinationRangeRange = sheetDestination.Range[destinationRange];
                IExcelTemplateView view = AddView(sheetContainer, templateName, sheetDestination, destinationRangeRange, clearingCell);
                return(view);
            }
            catch (Exception ex)
            {
                string message = $"Sheet '{(sheetDestination != null ? sheetDestination.Name.EmptyIfNull() : string.Empty)}', cannot add the View from template '{sheetTemplatePath.EmptyIfNull()}.{templateName.EmptyIfNull()}'";
                Logger.Instance.LogException(LogType.Error, ex, message);
                throw new EtkException(message, ex);
            }
            finally
            {
                if (sheetContainer != null)
                {
                    ExcelApplication.ReleaseComObject(sheetContainer);
                    sheetContainer = null;
                }
                if (workbook != null)
                {
                    ExcelApplication.ReleaseComObject(workbook);
                    workbook = null;
                }
                if (workbooks != null)
                {
                    ExcelApplication.ReleaseComObject(workbooks);
                    workbooks = null;
                }
            }
        }
예제 #15
0
        override protected void RealExecute(IExcelTemplateView view)
        {
            ExcelTemplateView excelView = view as ExcelTemplateView;

            if (excelView.RenderedArea == null || excelView.Renderer == null)
            {
                StepsErrorMessages.Add("Rendered area must not be null");
                return;
            }

            // Header
            if (excelView.Renderer.HeaderPartRenderer == null || excelView.Renderer.HeaderPartRenderer.RenderedArea == null)
            {
                StepsErrorMessages.Add("Header rendered area must not be null");
            }
            else
            {
                if (excelView.Renderer.HeaderPartRenderer.Width != 4 || excelView.Renderer.HeaderPartRenderer.Height != 2)
                {
                    StepsErrorMessages.Add("Header rendered area must 2*1");
                }
                if (excelView.Renderer.HeaderPartRenderer.RenderedRange[1, 1].Value != "Shops")
                {
                    StepsErrorMessages.Add("Header Cell[1,1] must contains 'ID'");
                }
                if (excelView.Renderer.HeaderPartRenderer.RenderedRange[2, 1].Value != "ID")
                {
                    StepsErrorMessages.Add("Header Cell[2,1] must contains 'ID'");
                }
            }

            // Body
            if (excelView.Renderer.BodyPartRenderer == null || excelView.Renderer.BodyPartRenderer.RenderedArea == null)
            {
                StepsErrorMessages.Add("Body rendered area must not be null");
            }
            else
            {
                if (excelView.Renderer.BodyPartRenderer.Width != 4 || excelView.Renderer.BodyPartRenderer.Height != 4)
                {
                    StepsErrorMessages.Add("Body Rendered area must be 4*4");
                }
                if (excelView.Renderer.BodyPartRenderer.RenderedRange[1, 1].Value != 1)
                {
                    StepsErrorMessages.Add("Body First cell must contains '1'");
                }
                if (excelView.Renderer.BodyPartRenderer.RenderedRange[4, 4].Value != "Fourth Shop Reception Phone number")
                {
                    StepsErrorMessages.Add("Body Last cell must contains 'Fourth Shop Reception Phone number'");
                }
            }

            // Footer
            if (excelView.Renderer.FooterPartRenderer == null || excelView.Renderer.FooterPartRenderer.RenderedArea == null)
            {
                StepsErrorMessages.Add("Footer rendered area must not be null");
            }
            else
            {
                if (excelView.Renderer.FooterPartRenderer.Width != 4 || excelView.Renderer.HeaderPartRenderer.Height != 2)
                {
                    StepsErrorMessages.Add("Footer rendered area must 4*2");
                }
                if (excelView.Renderer.FooterPartRenderer.RenderedRange[1, 1].Value != "Footer")
                {
                    StepsErrorMessages.Add("Footer Cell[1,1] must contains 'Footer'");
                }
                if (excelView.Renderer.FooterPartRenderer.RenderedRange[2, 1].Value != "Shops")
                {
                    StepsErrorMessages.Add("Footer Cell[2,1] must contains 'Shops'");
                }
            }
        }
예제 #16
0
 override protected void RealExecute(IExcelTemplateView view)
 {
     ETKExcel.TemplateManager.Render(view);
 }
예제 #17
0
 abstract protected void RealExecute(IExcelTemplateView view);
예제 #18
0
        public object GDA(ExcelInterop.Range caller, string dataType, object[] parameters)
        {
            if (caller == null)
            {
                return(null);
            }

            if (ETKExcel.ExcelApplication.IsInEditMode())
            {
                return("#Edit Mode");
            }

            if (test == null)
            {
                IExcelTemplateView view = ETKExcel.TemplateManager.AddView("Templates Customer", "AllCustomers", caller.Worksheet.Name, caller.Address);
                test = new ExcelRequestDefinition("Test", "Ceci est un test", view as ExcelTemplateView);
                ExcelInterop.Comment comment = caller.Comment;
                if (comment != null)
                {
                    comment.Delete();
                }
                caller.Application.Application.Caller.AddComment(test.Description);
            }

            ExcelInterop.Range firstOutputCell = (caller as ExcelInterop.Range).Offset[++yOffset, ++xOffset];
            (test.View as ExcelTemplateView).FirstOutputCell = firstOutputCell;

            try
            {
                //if (parameters.Length < 2)
                //    return "#N/A";

                ETKExcel.TemplateManager.ClearView(test.View);

                ExcelApplication application = (ETKExcel.TemplateManager as ExcelTemplateManager).ExcelApplication;
                application.PostAsynchronousAction(() =>
                {
                    try
                    {
                        application.PostAsynchronousAction(() => (test.View as ExcelTemplateView).FirstOutputCell.Value2 = "#Retrieving Data");
                        Task task = new Task(() =>
                        {
                            //Thread.Sleep(5000);

                            test.View.SetDataSource(parameters[0]);
                            application.PostAsynchronousAction(() => test.View.FirstOutputCell.Value2 = string.Empty);
                            application.PostAsynchronousAction(() => ETKExcel.TemplateManager.Render(test.View));
                        });
                        task.Start();
                    }
                    catch (Exception ex)
                    {
                        string errorMessage = $"#ERR:{ex.Message}.{(ex.InnerException == null ? string.Empty : ex.InnerException.Message)}";
                        application.PostAsynchronousAction(() => (test.View as ExcelTemplateView).FirstOutputCell.Value2 = errorMessage);
                    }
                });
                return(test.Name);
            }
            catch (Exception ex)
            {
                return($"#ERR: {ex.Message}");
            }
        }
예제 #19
0
        override protected void RealExecute(IExcelTemplateView view)
        {
            if (view.RenderedArea == null)
            {
                StepsErrorMessages.Add("Rendered area must not be null");
            }
            else
            {
                if (view.RenderedArea == null || view.RenderedArea.Width != 4 || view.RenderedArea.Height != 8)
                {
                    StepsErrorMessages.Add("Rendered area must be 4*8");
                }

                if (view.RenderedRange[1, 1].Value != "Shops")
                {
                    StepsErrorMessages.Add("Cell[1,1] must contains 'Shops'");
                }

                if (view.RenderedRange[2, 1].Value != "ID")
                {
                    StepsErrorMessages.Add("Cell[2,1] must contains 'ID'");
                }
                if (view.RenderedRange[2, 2].Value != "Name")
                {
                    StepsErrorMessages.Add("Cell[2,2] must contains 'Address'");
                }
                if (view.RenderedRange[2, 3].Value != "Address")
                {
                    StepsErrorMessages.Add("Cell[2,3] must contains 'ID'");
                }
                if (view.RenderedRange[2, 4].Value != "Reception Phone Number")
                {
                    StepsErrorMessages.Add("Cell[2,4] must contains 'Reception Phone Number'");
                }

                if (view.RenderedRange[4, 1].Value != 2)
                {
                    StepsErrorMessages.Add("Cell[4,1] must contains '2'");
                }
                if (view.RenderedRange[4, 2].Value != "Second Shop")
                {
                    StepsErrorMessages.Add("Cell[4,2] must contains 'Second Shop'");
                }
                if (view.RenderedRange[4, 3].Value != "2 Shops Road ShopCity")
                {
                    StepsErrorMessages.Add("Cell[4,3] must contains '2 Shops Road ShopCity'");
                }
                if (view.RenderedRange[4, 4].Value != "Second Shop Reception Phone number")
                {
                    StepsErrorMessages.Add("Cell[4,4] must contains 'Second Shop Reception Phone number'");
                }

                if (view.RenderedRange[7, 1].Value != "Footer")
                {
                    StepsErrorMessages.Add("Cell[7,4] must contains 'Shops'");
                }
                if (view.RenderedRange[8, 1].Value != "Shops")
                {
                    StepsErrorMessages.Add("Cell[8,4] must contains 'Shops'");
                }
            }
        }