Exemplo n.º 1
0
        public object Visit(IntermediateCellData n)
        {
            var root = new XElement("IntermediateCellData");
            if (n.Location != null) root.Add(new XElement("Location", n.Location));
            if (n.Content != null) root.Add(new XElement("Content", n.Content));
            if (n.CellType != null) root.Add(new XElement("CellType", n.CellType));
            root.Add(new XElement("differenceUp", n.DifferenceUp));
            root.Add(new XElement("differenceDown", n.DifferenceDown));

            return root;
        }
Exemplo n.º 2
0
        public void Start(Core.WorkbookModel wb)
        {
            if (this.newScenario != null)
            {
                return;
            }
            lock (syncScenario)
            {
                if (this.newScenario != null)
                {
                    return;
                }
                this.newScenario = new Scenario()
                {
                    Title       = "Untiteled Scenario - " + DateTime.Now.ToString(),
                    CrationDate = DateTime.Now,
                    Author      = this.GetDocumentProperty(wb, "Last Author")
                };
            }
            this.workbook = wb.Workbook;

            var workingList = wb.InputCells.Union(wb.IntermediateCells).Union(wb.OutputCells).ToList();

            //sort working list column first
            #region sort

            workingList.Sort(delegate(Core.Cell x, Core.Cell y)
            {
                //sort by worksheet
                var xSheet = workbook.Sheets[Cells.CellManager.Instance.ParseWorksheetName(x.Location)] as Worksheet;
                var ySheet = workbook.Sheets[Cells.CellManager.Instance.ParseWorksheetName(x.Location)] as Worksheet;

                if (xSheet.Index < ySheet.Index)
                {
                    return(-1);
                }
                else if (xSheet.Index > ySheet.Index)
                {
                    return(1);
                }
                else
                {
                    //sort by column
                    var xRange = xSheet.Range[Cells.CellManager.Instance.ParseCellLocation(x.Location)];
                    var yRange = ySheet.Range[Cells.CellManager.Instance.ParseCellLocation(y.Location)];

                    if (xRange.Column < yRange.Column)
                    {
                        return(-1);
                    }
                    else if (xRange.Column > yRange.Column)
                    {
                        return(1);
                    }
                    else
                    {
                        //sort by row
                        if (xRange.Row < yRange.Row)
                        {
                            return(-1);
                        }
                        else if (xRange.Row > yRange.Row)
                        {
                            return(1);
                        }
                        else
                        {
                            return(0);
                        }
                    }
                }
            });

            #endregion

            CreateScenarioDataFieldContainer containerFirst  = null;
            CreateScenarioDataFieldContainer containerBefore = null;
            foreach (var c in workingList)
            {
                //create cell data
                CellData cellData;

                #region create cell data
                if (c is Cells.InputCell)
                {
                    cellData             = new InputCellData();
                    cellData.Location    = c.Location;
                    cellData.SifLocation = c.SifLocation;
                    newScenario.Inputs.Add(cellData as InputCellData);
                }
                else if (c is Cells.IntermediateCell)
                {
                    cellData             = new IntermediateCellData();
                    cellData.Location    = c.Location;
                    cellData.SifLocation = c.SifLocation;
                    newScenario.Intermediates.Add(cellData as IntermediateCellData);
                }
                else if (c is Cells.OutputCell)
                {
                    cellData             = new ResultCellData();
                    cellData.Location    = c.Location;
                    cellData.SifLocation = c.SifLocation;
                    newScenario.Results.Add(cellData as ResultCellData);
                }
                else
                {
                    //abort
                    lock (syncScenario)
                    {
                        //clear this object
                        this.containers.Clear();
                        this.workbook    = null;
                        this.newScenario = null;

                        return;
                    }
                }

                #endregion

                //get worksheet
                var currentWorksheet = workbook.Sheets[Cells.CellManager.Instance.ParseWorksheetName(c.Location)] as Worksheet;
                var vsto             = Globals.Factory.GetVstoObject(currentWorksheet);

                //create container
                var container = new CreateScenarioDataFieldContainer();
                container.createScenarioDataField.DataContext = cellData;
                containers.Add(container);

                //register for focus handling
                #region focus handling

                if (c == workingList.First())
                {
                    containerFirst = container;
                }
                else if (containerBefore != null)
                {
                    containerBefore.createScenarioDataField.RegisterNextFocusField(container.createScenarioDataField);
                }
                containerBefore = container;

                #endregion

                //create control
                var control = vsto.Controls.AddControl(
                    container,
                    currentWorksheet.Range[Cells.CellManager.Instance.ParseCellLocation(c.Location)],
                    Guid.NewGuid().ToString());
                control.Placement = Microsoft.Office.Interop.Excel.XlPlacement.xlMove;
            }

            //set focus to first control
            if (containerFirst != null)
            {
                containerFirst.createScenarioDataField.SetFocus();
            }
        }
Exemplo n.º 3
0
        public void Start(Core.WorkbookModel wb)
        {
            if (this.newScenario != null) return;
            lock (syncScenario)
            {
                if (this.newScenario != null) return;
                this.newScenario = new Scenario()
                    {
                        Title = "Untiteled Scenario - " + DateTime.Now.ToString(),
                        CrationDate = DateTime.Now,
                        Author = this.GetDocumentProperty(wb, "Last Author")
                    };

            }
            this.workbook = wb.Workbook;

            var workingList = wb.InputCells.Union(wb.IntermediateCells).Union(wb.OutputCells).ToList();

            //sort working list column first
            #region sort

            workingList.Sort(delegate(Core.Cell x, Core.Cell y)
            {
                //sort by worksheet
                var xSheet = workbook.Sheets[Cells.CellManager.Instance.ParseWorksheetName(x.Location)] as Worksheet;
                var ySheet = workbook.Sheets[Cells.CellManager.Instance.ParseWorksheetName(x.Location)] as Worksheet;

                if (xSheet.Index < ySheet.Index)
                {
                    return -1;
                }
                else if (xSheet.Index > ySheet.Index)
                {
                    return 1;
                }
                else
                {
                    //sort by column
                    var xRange = xSheet.Range[Cells.CellManager.Instance.ParseCellLocation(x.Location)];
                    var yRange = ySheet.Range[Cells.CellManager.Instance.ParseCellLocation(y.Location)];

                    if (xRange.Column < yRange.Column)
                    {
                        return -1;
                    }
                    else if (xRange.Column > yRange.Column)
                    {
                        return 1;
                    }
                    else
                    {
                        //sort by row
                        if (xRange.Row < yRange.Row)
                        {
                            return -1;
                        }
                        else if (xRange.Row > yRange.Row)
                        {
                            return 1;
                        }
                        else
                        {
                            return 0;
                        }
                    }
                }

            });

            #endregion

            CreateScenarioDataFieldContainer containerFirst = null;
            CreateScenarioDataFieldContainer containerBefore = null;
            foreach (var c in workingList)
            {
                //create cell data
                CellData cellData;

                #region create cell data
                if (c is Cells.InputCell)
                {
                    cellData = new InputCellData();
                    cellData.Location = c.Location;
                    cellData.SifLocation = c.SifLocation;
                    newScenario.Inputs.Add(cellData as InputCellData);
                }
                else if (c is Cells.IntermediateCell)
                {
                    cellData = new IntermediateCellData();
                    cellData.Location = c.Location;
                    cellData.SifLocation = c.SifLocation;
                    newScenario.Intermediates.Add(cellData as IntermediateCellData);
                }
                else if (c is Cells.OutputCell)
                {
                    cellData = new ResultCellData();
                    cellData.Location = c.Location;
                    cellData.SifLocation = c.SifLocation;
                    newScenario.Results.Add(cellData as ResultCellData);
                }
                else
                {
                    //abort
                    lock (syncScenario)
                    {
                        //clear this object
                        this.containers.Clear();
                        this.workbook = null;
                        this.newScenario = null;

                        return;
                    }
                }

                #endregion

                //get worksheet
                var currentWorksheet = workbook.Sheets[Cells.CellManager.Instance.ParseWorksheetName(c.Location)] as Worksheet;
                var vsto = Globals.Factory.GetVstoObject(currentWorksheet);

                //create container
                var container = new CreateScenarioDataFieldContainer();
                container.createScenarioDataField.DataContext = cellData;
                containers.Add(container);

                //register for focus handling
                #region focus handling

                if (c == workingList.First())
                {
                    containerFirst = container;
                }
                else if (containerBefore != null)
                {
                    containerBefore.createScenarioDataField.RegisterNextFocusField(container.createScenarioDataField);
                }
                containerBefore = container;

                #endregion

                //create control
                var control = vsto.Controls.AddControl(
                    container,
                    currentWorksheet.Range[Cells.CellManager.Instance.ParseCellLocation(c.Location)],
                    Guid.NewGuid().ToString());
                control.Placement = Microsoft.Office.Interop.Excel.XlPlacement.xlMove;
            }

            //set focus to first control
            if (containerFirst != null)
            {
                containerFirst.createScenarioDataField.SetFocus();
            }

        }