Ejemplo n.º 1
0
        Celije tCell; // trenutno aktivni skup celija

        #endregion Fields

        #region Constructors

        public Form1()
        {
            InitializeComponent();

            gridovi.Add(new DataGridView());
            tGrid = gridovi[0];
            tabControl1.KeyDown += new KeyEventHandler(delete);
            tabControl1.TabPages[0].Controls.Add(gridovi[0]);
            tabControl1.Selected += new TabControlEventHandler(promjenaTaba);
            gridovi[0].BorderStyle = BorderStyle.None;
            tabControl1.TabPages[0].BorderStyle = BorderStyle.None;
            gridovi[0].CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.tablica_CellClick);
            gridovi[0].CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.tablica_CellValueChanged);
            gridovi[0].CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.tablica_CellEndEdit);
            gridovi[0].SelectionChanged += new EventHandler(this.tablica_SelectionChanged);
            gridovi[0].CellEnter += new DataGridViewCellEventHandler(this.tablica_CellEnter);

            gridovi[0].RowsAdded += new DataGridViewRowsAddedEventHandler(tablica_RowsAdded);

            Celije noviTab = new Celije();
            ListaCelija.Add(noviTab);
            tCell = ListaCelija[0];

            gridovi[0].Dock = DockStyle.Fill;
            tabControl1.TabPages[0].Text = "Sheet1";
            gridovi[0].RowHeadersWidth = 60;
            gridovi[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight;

            for (int i = 65; i <= 90; i++)
            {
                DataGridViewColumn newCol = new DataGridViewColumn();
                newCol.HeaderText = Convert.ToChar(i).ToString();
                newCol.Visible = true;
                newCol.Width = 100;
                DataGridViewCell cell = new DataGridViewTextBoxCell();

                newCol.CellTemplate = cell;
                gridovi[0].Columns.Add(newCol);
            }
            string[] red = { };
            for (int i = 1; i < 100; i++)
            {
                gridovi[0].Rows.Add(red);
                gridovi[0].Rows[i - 1].HeaderCell.Value = i.ToString();
            }
            broj_gridova++;

            gridovi[0].TabIndex = 0;
            gridovi[0].CurrentCell = gridovi[0][0, 0];

            toolStripTextBox1.Anchor = AnchorStyles.Right;
            toolStripTextBox1.Dock = DockStyle.Fill;
        }
Ejemplo n.º 2
0
        //novi tab
        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            string s = "Sheet" + (broj_gridova + 1);
            TabPage newPage = new TabPage(s);
            tabControl1.TabPages.Add(newPage);
            gridovi.Add(new DataGridView());

            gridovi[broj_gridova].RowHeadersWidth = 60;
            tabControl1.TabPages[broj_gridova].Controls.Add(gridovi[broj_gridova]);
            gridovi[broj_gridova].BorderStyle = BorderStyle.None;
            gridovi[broj_gridova].CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.tablica_CellClick);
            gridovi[broj_gridova].CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.tablica_CellEndEdit);
            gridovi[broj_gridova].CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.tablica_CellValueChanged);
            gridovi[broj_gridova].SelectionChanged += new EventHandler(this.tablica_SelectionChanged);
            gridovi[broj_gridova].CellEnter += new DataGridViewCellEventHandler(this.tablica_CellEnter);
            gridovi[broj_gridova].RowsAdded += new DataGridViewRowsAddedEventHandler(tablica_RowsAdded);

            Celije noviTab = new Celije();
            ListaCelija.Add(noviTab);

            gridovi[broj_gridova].Dock = DockStyle.Fill;
            for (int i = 65; i <= 90; i++)
            {
                DataGridViewColumn newCol = new DataGridViewColumn();
                newCol.HeaderText = Convert.ToChar(i).ToString();
                newCol.Visible = true;
                newCol.Width = 100;
                DataGridViewCell cell = new DataGridViewTextBoxCell();
                newCol.CellTemplate = cell;
                gridovi[broj_gridova].Columns.Add(newCol);
            }
            string[] red = { };
            for (int i = 1; i < 100; i++)
            {
                gridovi[broj_gridova].Rows.Add(red);
                gridovi[broj_gridova].Rows[i - 1].HeaderCell.Value = i.ToString();
            }

            broj_gridova++;
        }
Ejemplo n.º 3
0
 public void promjenaTaba(object o, EventArgs e)
 {
     TabControl tab = (TabControl)o;
     if (tab.SelectedIndex >= 0)
     {
         tGrid = gridovi[tab.SelectedIndex];
         tCell = ListaCelija[tab.SelectedIndex];
     }
 }
Ejemplo n.º 4
0
 public void PostaviOvisnosti(Celije cells, string s)
 {
     s = s.ToLower();
     if (s != "")
     {
         string[] celije = s.Split(';');
         foreach (string koo in celije)
         {
             string slovo, broj;
             slovo = Regex.Match(koo, @"[a-z]+").Value;
             broj = Regex.Match(koo, "[0-9]+").Value;
             int c = slovo[0] - 97;
             int r = Convert.ToInt32(broj) - 1;
             KeyValuePair<int, int> i = new KeyValuePair<int, int>(r, c);
             //KeyValuePair<int, int> ova = new KeyValuePair<int, int>(red, stupac);
             if (cells.sveCelije.ContainsKey(i))
             {
                 uFormuli.Add(cells.sveCelije[i]);
             }
             else
             {
                 cells.Dodaj(r, c);
                 uFormuli.Add(cells.sveCelije[i]);
             }
         }
     }
 }
Ejemplo n.º 5
0
        public void evaluateFormula(Celije tCell, Funkcije fje)
        {
            if (this.formula == "")
                return;
            string formula;
            formula = this.formula.ToLower();

            // zamjenjujem oznake celija konkretnim vrijednostima
            // PRETPOSTAVKA: nema razmaka nije dosega
            formula = formula.Replace(" ", "");
            formula = formula.Replace("\r\n", "");

            while (true)
            {
                Match m = Regex.Match(formula, @"[a-z]+[0-9]+:[a-z]+[0-9]+");
                string slovo, broj;
                if (m.Success)
                {
                    string rep = "";
                    string sa = m.Value;
                    string[] oddo = sa.Split(':');
                    slovo = Regex.Match(oddo[0], @"[a-z]+").Value;
                    broj = Regex.Match(oddo[0], "[0-9]+").Value;
                    int c1 = slovo[0] - 97;
                    int r1 = Convert.ToInt32(broj);

                    slovo = Regex.Match(oddo[1], @"[a-z]+").Value;
                    broj = Regex.Match(oddo[1], "[0-9]+").Value;
                    int c2 = slovo[0] - 97;
                    int r2 = Convert.ToInt32(broj);

                    if (c1 == c2 && r1 != r2)
                    {
                        for (int i = r1; i <= r2; i++)
                        {
                            rep += Char.ConvertFromUtf32(c1 + 65) + i.ToString() + ";";

                        }
                    }
                    else if (r1 == r2 && c1 != c2)
                    {
                        for (int i = c1; i <= c2; i++)
                        {
                            rep += Char.ConvertFromUtf32(i + 65) + r1.ToString() + ";";
                        }
                    }
                    else
                    {
                        for (int i = r1; i <= r2; i++)
                            for (int j = c1; j <= c2; j++)
                            {
                                rep += Char.ConvertFromUtf32(j + 65) + i.ToString() + ";";
                            }
                    }
                    rep = rep.TrimEnd(';');
                    formula = formula.Replace(sa, rep);
                }
                else
                {
                    break;
                }
            }

            formula = formula.ToLower();
            while (true)
            {
                Match m = Regex.Match(formula, @"[a-z]+[0-9]+");
                if (m.Success)
                {
                    string cel = m.Value;
                    string slovo = Regex.Match(cel, @"[a-z]+").Value;
                    string broj = Regex.Match(cel, "[0-9]+").Value;
                    int c1 = slovo[0] - 97;
                    int r1 = Convert.ToInt32(broj) - 1;
                    KeyValuePair<int, int> koo = new KeyValuePair<int, int>(r1, c1);

                    if (tCell.sveCelije.ContainsKey(koo) && tCell.sveCelije[koo].Numerical)
                    {
                        string arg = tCell.sveCelije[koo].sadrzaj;
                        double d = double.Parse(arg);
                        if (d < 0)
                        {
                            arg = "(0" + arg+")";
                        }
                        formula = formula.Replace(cel, arg);
                        if (tCell.sveCelije[koo].uFormuli.Contains(this) == false)
                            tCell.sveCelije[koo].uFormuli.Add(this);
                    }
                    else
                    {
                        formula = formula.Replace(cel, "");
                        if (tCell.sveCelije.ContainsKey(koo) == false)
                        {
                            tCell.Dodaj(r1, c1);
                            tCell.sveCelije[koo].uFormuli.Add(this);
                        }
                        else
                        {
                            if (tCell.sveCelije[koo].uFormuli.Contains(this) == false)
                                tCell.sveCelije[koo].uFormuli.Add(this);
                        }
                        Sadrzaj = "NaN";
                        return;
                    }

                }
                else
                {
                    break;
                }
            }

            // razdvajam formulu na tokene

            List<Token> listaTokena = new List<Token>();
            string s = formula.TrimStart('=');
            string function_token = "";
            string zagrada_token = "";
            string separator_token = "";
            string celija_token = "";
            string op_token = "";
            Queue<Token> q = new Queue<Token>();
            Stack<Token> st = new Stack<Token>();
            while (s != "")
            {
                Match m1 = Regex.Match(s, @"^\s*[a-zA-Z]+\s*");
                Match m2 = Regex.Match(s, @"^[)(]");
                Match m3 = Regex.Match(s, @"^;");
                Match m4 = Regex.Match(s, @"^[0-9.,]+");
                Match m5 = Regex.Match(s, @"^[\+\-\*\/\^]");
                if (m1.Success) // FUNKCIJA
                {
                    function_token = m1.Value;
                    s = s.Substring(function_token.Length, s.Length - function_token.Length);
                    listaTokena.Add(new Token("funk", function_token));
                    //continue;
                }

                else if (m2.Success) // ZAGRADA
                {
                    zagrada_token = m2.Value;
                    s = s.Substring(zagrada_token.Length, s.Length - zagrada_token.Length);
                    listaTokena.Add(new Token("zagr", zagrada_token));
                    //continue;
                }

                else if (m3.Success) // SEPARATOR
                {
                    separator_token = m3.Value;
                    s = s.Substring(separator_token.Length, s.Length - separator_token.Length);
                    listaTokena.Add(new Token("sepa", separator_token));
                    //continue;
                }

                else if (m4.Success)
                {
                    celija_token = m4.Value;
                    s = s.Substring(celija_token.Length, s.Length - celija_token.Length);
                    listaTokena.Add(new Token("broj", celija_token));
                    //continue;
                }

                else if (m5.Success) // FUNKCIJA
                {
                    op_token = m5.Value;
                    //st.Push(function_token);
                    s = s.Substring(op_token.Length, s.Length - op_token.Length);
                    Token op = new Token("oper", op_token);
                    op.brArg = 2;
                    if (op_token == "+")
                    {
                        op.prioritet = 0;
                        op.asoc = "L";
                    }
                    else if (op_token == "-")
                    {
                        op.prioritet = 0;
                        op.asoc = "L";
                    }
                    else if (op_token == "*")
                    {
                        op.prioritet = 1;
                        op.asoc = "L";
                    }
                    else if (op_token == "/")
                    {
                        op.prioritet = 1;
                        op.asoc = "L";
                    }
                    else if (op_token == "^")
                    {
                        op.prioritet = 2;
                        op.asoc = "D";
                    }
                    listaTokena.Add(op);
                    //continue;
                }
                else
                {
                    throw new Exception();
                }
            }

            // brojim argumente fja jer imaju varijabilan broj argumenata
            for (int i = 0; i < listaTokena.Count; i++)
            {
                if (listaTokena[i].tip == "funk")
                {
                    int smijemBrojat = -1;
                    for (int j = i + 1; j < listaTokena.Count; j++)
                    {
                        if (smijemBrojat == 0 && listaTokena[j].tip == "sepa")
                        {
                            listaTokena[i].brArg++;
                        }
                        if (listaTokena[j].value == "(")
                        {
                            smijemBrojat++;

                        }
                        if (listaTokena[j].value == ")")
                        {
                            smijemBrojat--;
                        }
                        if (smijemBrojat == -1)
                            break;
                    }
                }
            }

            // Shunting-yard

            foreach (Token t in listaTokena)
            {
                if (t.tip == "oper") // OPERATOR
                {

                    while (st.Count != 0 && st.Peek().tip == "oper" &&
                          ((t.asoc == "L" && t.prioritet <= st.Peek().prioritet) ||
                          (t.asoc == "R" && t.prioritet < st.Peek().prioritet)))
                    {
                        q.Enqueue(st.Pop());
                    }
                    st.Push(t);
                    continue;
                }
                if (t.tip == "funk") // FUNKCIJA
                {

                    st.Push(t);

                    continue;
                }

                if (t.tip == "zagr") // ZAGRADA
                {

                    if (t.value == "(")
                    {
                        st.Push(t);
                    }
                    else if (t.value == ")")
                    {
                        while (st.Peek().value != "(")
                        {
                            q.Enqueue(st.Pop());
                        }
                        st.Pop();

                        if (st.Count != 0 && st.Peek().tip == "funk")
                        {
                            q.Enqueue(st.Pop());
                        }
                    }

                    continue;
                }

                if (t.tip == "sepa") // SEPARATOR
                {

                    while (st.Peek().value != "(")
                    {
                        q.Enqueue(st.Pop());
                    }

                    continue;
                }

                if (t.tip == "broj")
                {

                    q.Enqueue(t);

                    continue;
                }
            }

            while (st.Count != 0)
            {
                q.Enqueue(st.Pop());
            }

            // racunanje izraza

            Stack<double> tmp = new Stack<double>();

            while (q.Count != 0)
            {
                List<double> arg = new List<double>();
                if (q.Peek().tip == "broj")
                {
                    tmp.Push(Double.Parse(q.Dequeue().value));
                    continue;
                }
                if (q.Peek().tip == "funk" || q.Peek().tip == "oper")
                {
                    for (int i = 0; i < q.Peek().brArg; i++)
                    {
                        if (tmp.Count != 0)
                            arg.Add(tmp.Pop());
                    }
                    tmp.Push(fje.SveFunkcije[q.Dequeue().value](arg));
                }
            }
            Sadrzaj = tmp.Pop().ToString();
        }
Ejemplo n.º 6
0
        public Grafovi(Form1 f, DataGridView grid, Celije celije)
        {
            this.ListaCelija = celije;
            this.f = f;
            // inicijaliziramo boje
            boje.Add(Color.FromArgb(62, 87, 145));
            boje.Add(Color.FromArgb(186, 61, 59));
            boje.Add(Color.FromArgb(74, 122, 69));
            boje.Add(Color.FromArgb(197, 97, 68));
            boje.Add(Color.FromArgb(111, 145, 62));
            boje.Add(Color.FromArgb(214, 154, 80));
            boje.Add(Color.FromArgb(203, 193, 76));

            // pomicanje
            graf.MouseDown += _MouseDown;
            graf.MouseMove += _MouseMove;
            graf.MouseUp += _MouseUp;

            graf.Size = new Size(430, 350);
            graf.BorderStyle = BorderStyle.FixedSingle;
            graf.Location = new Point(f.ClientSize.Width - 500 - brGrafova * 20, 50 + brGrafova * 20);
            graf.Parent = grid;
            graf.MouseClick += new MouseEventHandler(desniKlikMeni);
            graf.BringToFront();

            strip.Items.Add("Postavke");
            strip.Items.Add("Kopiraj");
            strip.Items.Add("Spremi u datoteku");
            strip.Items.Add("Izbrisi");

            strip.Items[0].Image = f.imageList1.Images[1];
            strip.Items[1].Image = f.imageList1.Images[2];
            strip.Items[2].Image = f.imageList1.Images[3];
            strip.Items[3].Image = f.imageList1.Images[0];

            strip.Items[0].Click += new EventHandler(izbor);
            strip.Items[1].Click += new EventHandler(kopiraj);
            strip.Items[2].Click += new EventHandler(spremi);
            strip.Items[3].Click += new EventHandler(zagasi);
               // graf.Controls.Add(strip);

            close.Size = new Size(16, 16);
            close.FlatStyle = FlatStyle.Flat;
            close.Parent = graf;
            close.Location = new Point(close.Parent.Width - 19, 1);
            close.Click += new EventHandler(zagasi);
            close.BackgroundImage = f.imageList1.Images[0];
            close.FlatAppearance.BorderSize = 0;
            foreach (DataGridViewCell c in grid.SelectedCells)
            {
                //double r;

                KeyValuePair<int, int> index = new KeyValuePair<int, int>(c.RowIndex, c.ColumnIndex);
                if (ListaCelija.sveCelije.ContainsKey(index))
                {
                    if (ListaCelija.sveCelije[index].Numerical == false)
                    {
                        Kategorije.Add(ListaCelija.sveCelije[index]);
                        //if (ListaCelija.sveCelije[index].stupac < prviStupac)
                            //prviStupac = ListaCelija.sveCelije[index].stupac;
                        continue;
                    }
                    vrijednosti.Add(Double.Parse(ListaCelija.sveCelije[index].Sadrzaj));
                    CelijeZaPlot.Add(ListaCelija.sveCelije[index]);
                    if (ListaCelija.sveCelije[index].stupac < prviStupac)
                        prviStupac = ListaCelija.sveCelije[index].stupac;
                }
            }
            CelijeZaPlot.Sort();
            brGrafova++;
        }