public void ExecuteInsertWorksheet(SpreadsheetModel spreadsheetModel)
		{
			System.Windows.Forms.TabPage newWSPage = new TabPage("Worksheet " +
					(MainForm.WorksheetsTabControl.Controls.Count + 1));

			MainForm.WorksheetsTabControl.Controls.Add(newWSPage);
			newWSPage.Location = new System.Drawing.Point(4, 22);
			newWSPage.Padding = new System.Windows.Forms.Padding(3);
			newWSPage.Size = mainForm.Size;
			newWSPage.TabIndex = 0;
			newWSPage.UseVisualStyleBackColor = true;
			SpreadsheetUserControl ws = new SpreadsheetUserControl();
			ws.Spreadsheet.SpreadsheetModel = spreadsheetModel;
			ws.Spreadsheet.KeyDown += new KeyEventHandler(SpreadsheetView_KeyDown);
			ws.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
									| System.Windows.Forms.AnchorStyles.Left)
									| System.Windows.Forms.AnchorStyles.Right)));
			ws.Location = new System.Drawing.Point(0, 0);
			ws.Name = "spreadsheetUserControl" +
					(MainForm.WorksheetsTabControl.Controls.Count + 1);
			ws.Size = newWSPage.Size;
			newWSPage.Controls.Add(ws);
			ws.Spreadsheet.RefreshView();
		}
		public void ExecuteCommand(object sender, EventArgs e, CommandType command)
		{
			if (command != CommandType.InsertWorksheet)
			{
				try
				{
					ActiveWS = (SpreadsheetUserControl)mainForm.WorksheetsTabControl.SelectedTab.Controls[0];
				}
				catch (Exception exc)
				{
				}
			}
			switch (command)
			{
				case CommandType.Exit:
					ExecuteExit();
					break;
				case CommandType.About:
					ExecuteAbout();
					break;
				case CommandType.Open:
					ExecuteOpen();
					break;
				case CommandType.Save:
					ExecuteSave();
					break;
				case CommandType.SaveAs:
					ExecuteSaveAs();
					break;
				case CommandType.New:
					ExecuteNew();
					break;
				case CommandType.Cut:
					ExecuteCut();
					break;
				case CommandType.Copy:
					ExecuteCopy();
					break;
				case CommandType.Paste:
					ExecutePaste();
					break;
				case CommandType.InsertBarGraph:
					ExecuteInsertBarGraph();
					break;
				case CommandType.InsertColumnGraph:
					ExecuteInsertColumnGraph();
					break;
				case CommandType.InsertLineGraph:
					ExecuteInsertLineGraph();
					break;
				case CommandType.InsertPieGraph:
					ExecuteInsertPieGraph();
					break;
				case CommandType.InsertScatterGraph:
					ExecuteInsertScatterGraph();
					break;
				case CommandType.FormatCells:
					ExecuteFormatCells((sender as ToolStripButton).Name);
					break;
				case CommandType.InsertWorksheet:
					ExecuteInsertWorksheet();
					break;
				case CommandType.SelectTextColor:
					ExecuteSelectTextColor((e as ColorEventArgs).Color);
					break;
				case CommandType.SelectCellColor:
					ExecuteSelectCellColor((e as ColorEventArgs).Color);
					break;
				case CommandType.ChangeFont:
					ExecuteChangeFont((e as FontEventArgs));
					break;
				case CommandType.DeleteActiveWS:
					ExecuteDeleteActiveWS();
					break;
				case CommandType.AssignFormula:
					ExecuteAssignFormula((TextBox)sender);
					break;
				default:
					break;
			}
		}
Example #3
0
        public string Parse(SpreadsheetUserControl activeWS,string Cell_String)
        {
            //Assign the current worksheet to reference
            this.activeWS = activeWS;
            //Saves the original cell function
            string Original_Cell_String = Cell_String.Substring(Cell_String.IndexOf(':') + 1);

            //Removes all empty spaces
            Cell_String = Cell_String.ToUpper().Replace(" ", "");

            //Sets the base cell that is being referenced
            Base_Cell = Cell_String.Substring(0, Cell_String.IndexOf(':'));

            {//Resets the cell's error state
                ArrayList atemp = BreakReference(Base_Cell);
                int r = (int)atemp[0];
                int c = (int)atemp[1];
                if (activeWS.Spreadsheet.SpreadsheetModel.Cells[r, c] != null)
                {
                    activeWS.Spreadsheet.SpreadsheetModel.Cells[r, c].Error = false;
                    activeWS.Spreadsheet.SpreadsheetModel.Cells[r, c].ErrorString = "";
                }
            }

            //removes the base cell reference
            Cell_String = Cell_String.Substring(Cell_String.IndexOf(':') + 1);

            //OutFile.WriteLine("---------- " + Base_Cell + ":" + Cell_String);
            //OutFile.WriteLine(Cell_String);

            ArrayList Send = new ArrayList();
            Send.Add(Base_Cell);

            if (Cell_String.Length == 0)
                Cell_String = " ";

            if (Cell_String[0].ToString() != "=")
            {
                //Sends the data to the dependency list
                Dependencies.NewStatement(Send);
                //OutFile.WriteLine("Cell is a string or empty");
                return Original_Cell_String;
            }

            ArrayList Parts = Tokenize(Cell_String);
            //PrintArrayList(Parts);

            Send = ReformatForDL(new ArrayList(Parts));
            Send.Insert(0, Base_Cell);
            //Sends the data to the dependency list
            Dependencies.NewStatement(Send);

            //Remove all shortcuts and references
            ArrayList temp = Reformat(Parts);
            //PrintArrayList(temp);

            //Call all respective methods
            string strtmp = Breaker(temp);

            //OutFile.WriteLine("----- " + strtmp);
            //OutFile.Flush();
            try
            {
                return Convert.ToDouble(strtmp).ToString();
            }
            catch
            {//If Breaker did not return a double
                //OutFile.WriteLine("ERROR - FORMATING ERROR");
                //OutFile.Flush();

                if (strtmp.Equals("NULL"))
                {//Sets the cell's error state
                    ArrayList atemp = BreakReference(Base_Cell);
                    int r = (int)atemp[0];
                    int c = (int)atemp[1];
                    if (activeWS.Spreadsheet.SpreadsheetModel.Cells[r, c] != null)
                    {
                        activeWS.Spreadsheet.SpreadsheetModel.Cells[r, c].Error = true;
                        if (!activeWS.Spreadsheet.SpreadsheetModel.Cells[r, c].ErrorString.Contains("ERROR"))
                            activeWS.Spreadsheet.SpreadsheetModel.Cells[r, c].ErrorString = "ERROR - FORMATING ERROR";
                    }
                }

                //ERROR: FORMATING ERROR
                return Original_Cell_String;
            }
        }