Ejemplo n.º 1
0
        private void AddColumn_Click(object sender, EventArgs e)
        {
            DataGridViewColumn column = new DataGridViewColumn();
            DataGridViewCell   cell   = new DataGridViewTextBoxCell();

            column.CellTemplate = cell;
            int    k  = dataGridView.ColumnCount - 1;
            string n  = dataGridView.Columns[k].Name;
            string cc = "";

            if (n.Length == 1)
            {
                if (n == "Z")
                {
                    cc = "AA";
                }
                else
                {
                    int j = colonki.IndexOf(n[0]);
                    cc = colonki[j + 1].ToString();
                }
            }
            else
            {
                if (n[1] == 'Z')
                {
                    int j = colonki.IndexOf(n[0]);
                    cc = colonki[j + 1].ToString() + "A";
                }
                else
                {
                    int j = colonki.IndexOf(n[1]);
                    cc = n[0].ToString() + colonki[j + 1].ToString();
                }
            }
            column.HeaderText = cc;
            column.Name       = cc;
            dataGridView.Columns.Add(column);
            for (int row = 0; row < dataGridView.RowCount; row++)
            {
                string cell_name = cc + (row + 1).ToString();
                MyCell celll     = new MyCell();
                celll.Value = "0";
                celll.Exp   = "0";
                celll.Depends.Add("");
                if (!dictionary.ContainsKey(cell_name))
                {
                    dictionary.Add(cell_name, celll);
                }
                if (!dictionary2.ContainsKey(cell_name))
                {
                    dictionary2.Add(cell_name, null);
                }
                if (!dictionary3.ContainsKey(cell_name))
                {
                    dictionary3.Add(cell_name, null);
                }
            }
            RefreshCells();
        }
Ejemplo n.º 2
0
        private void AddRow()
        {
            DataGridViewRow row = new DataGridViewRow();

            dataGridView.Rows.Add(row);
            SetRowNum(dataGridView);
            for (int col = 0; col < dataGridView.ColumnCount; col++)
            {
                string cell_name = "";
                if (col < 26)
                {
                    cell_name = (char)(col + 65) + (dataGridView.RowCount + 1).ToString();
                }
                else
                {
                    cell_name  = ((char)(currCol / 25 + 64)).ToString();
                    cell_name += ((char)(currCol - currCol / 25 * 25 + 64)).ToString();
                    cell_name += (dataGridView.RowCount + 1).ToString();
                }
                MyCell cell = new MyCell();
                cell.Value = "0";
                cell.Exp   = "0";
                cell.Depends.Add("");
                if (!dictionary.ContainsKey(cell_name))
                {
                    dictionary.Add(cell_name, cell);
                }
                if (!dictionary2.ContainsKey(cell_name))
                {
                    dictionary2.Add(cell_name, null);
                }
                if (!dictionary3.ContainsKey(cell_name))
                {
                    dictionary3.Add(cell_name, null);
                }
                // MessageBox.Show(cell_name);
            }

            RefreshCells();
        }
Ejemplo n.º 3
0
        private void OpenFile_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Данные будут удалены", "Open file", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                Stream mystream = null;
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    if ((mystream = openFileDialog1.OpenFile()) != null)
                    {
                        using (mystream)
                        {
                            try
                            {
                                StreamReader sr  = new StreamReader(mystream);
                                string       scr = sr.ReadLine();
                                string       scc = sr.ReadLine();
                                int          cr  = Convert.ToInt32(scr);
                                int          cc  = Convert.ToInt32(scc);
                                for (int i = 0; i < cr; i++)
                                {
                                    for (int j = 0; j < cc; j++)
                                    {
                                        string name = "";
                                        if (j < 26)
                                        {
                                            name = (char)(j + 65) + (i + 1).ToString();
                                        }
                                        else
                                        {
                                            name  = ((char)(j / 25 + 64)).ToString();
                                            name += ((char)(j - j / 25 * 25 + 64)).ToString();
                                            name += (i + 1).ToString();
                                        }

                                        if (dictionary[name].Exp != "0")
                                        {
                                            //MessageBox.Show(name);
                                            dataGridView[j, i].Value = null;
                                            dictionary[name].Exp     = "0";
                                            dictionary2[name]        = "0";
                                            dictionary[name].Value   = "0";
                                            dictionary3[name]        = "0";
                                        }
                                    }
                                }

                                while (dataGridView.Rows.Count < cr)
                                {
                                    DataGridViewRow row = new DataGridViewRow();
                                    dataGridView.Rows.Add(row);
                                }
                                while (dataGridView.Columns.Count < cc)
                                {
                                    DataGridViewColumn column = new DataGridViewColumn();
                                    dataGridView.Columns.Add(column);
                                }

                                while (!sr.EndOfStream)
                                {
                                    string name = sr.ReadLine();

                                    int coll = 0, row = 0;
                                    if (colonki.Contains(name[0]))
                                    {
                                        if (colonki.Contains(name[1]))
                                        {
                                            coll = Convert.ToInt32(name[0]) - 65 + Convert.ToInt32(name[1]) - 65 + 26;
                                            string a = "";
                                            for (int k = 2; k < name.Length; k++)
                                            {
                                                a += name[k].ToString();
                                            }
                                            row = Convert.ToInt32(a) - 1;
                                        }
                                        else
                                        {
                                            coll = Convert.ToInt32(name[0]) - 65;
                                            string a = "";
                                            for (int k = 1; k < name.Length; k++)
                                            {
                                                a += name[k].ToString();
                                            }
                                            row = Convert.ToInt32(a) - 1;
                                        }
                                    }
                                    string exp = sr.ReadLine();
                                    string val = sr.ReadLine();
                                    string d3  = sr.ReadLine();
                                    dataGridView[coll, row].Value = val;
                                    if (!dictionary.ContainsKey(name))
                                    {
                                        MyCell cell = new MyCell();
                                        cell.Value = "0";
                                        cell.Exp   = "0";
                                        cell.Depends.Add("");
                                        dictionary.Add(name, cell);
                                        dictionary2.Add(name, "0");
                                        dictionary3.Add(name, "0");
                                    }
                                    dictionary[name].Exp   = exp;
                                    dictionary2[name]      = exp;
                                    dictionary[name].Value = val;
                                    dictionary3[name]      = d3;
                                }
                                sr.Close();
                            }
                            catch { }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public Dictionary <string, string> dictionary3 = new Dictionary <string, string>(); //выражение с подставленными вместо ссылок

        public Form1()
        {
            InitializeComponent();
            DataGridViewColumn A = new DataGridViewColumn();
            DataGridViewColumn B = new DataGridViewColumn();
            DataGridViewColumn C = new DataGridViewColumn();
            DataGridViewColumn D = new DataGridViewColumn();
            DataGridViewColumn E = new DataGridViewColumn();
            DataGridViewColumn F = new DataGridViewColumn();
            DataGridViewColumn G = new DataGridViewColumn();
            DataGridViewColumn H = new DataGridViewColumn();
            DataGridViewColumn I = new DataGridViewColumn();
            DataGridViewColumn J = new DataGridViewColumn();
            DataGridViewColumn K = new DataGridViewColumn();
            DataGridViewColumn L = new DataGridViewColumn();
            DataGridViewColumn M = new DataGridViewColumn();
            DataGridViewColumn N = new DataGridViewColumn();
            DataGridViewColumn O = new DataGridViewColumn();
            DataGridViewColumn P = new DataGridViewColumn();

            MyCell cellA = new MyCell(); A.CellTemplate = cellA;
            MyCell cellB = new MyCell(); B.CellTemplate = cellB;
            MyCell cellC = new MyCell(); C.CellTemplate = cellC;
            MyCell cellD = new MyCell(); D.CellTemplate = cellD;
            MyCell cellE = new MyCell(); E.CellTemplate = cellE;
            MyCell cellF = new MyCell(); F.CellTemplate = cellF;
            MyCell cellG = new MyCell(); G.CellTemplate = cellG;
            MyCell cellH = new MyCell(); H.CellTemplate = cellH;
            MyCell cellI = new MyCell(); I.CellTemplate = cellI;
            MyCell cellJ = new MyCell(); J.CellTemplate = cellJ;
            MyCell cellK = new MyCell(); K.CellTemplate = cellK;
            MyCell cellL = new MyCell(); L.CellTemplate = cellL;
            MyCell cellM = new MyCell(); M.CellTemplate = cellM;
            MyCell cellN = new MyCell(); N.CellTemplate = cellN;
            MyCell cellO = new MyCell(); O.CellTemplate = cellO;
            MyCell cellP = new MyCell(); P.CellTemplate = cellP;

            A.HeaderText = "A"; A.Name = "A";
            B.HeaderText = "B"; B.Name = "B";
            C.HeaderText = "C"; C.Name = "C";
            D.HeaderText = "D"; D.Name = "D";
            E.HeaderText = "E"; E.Name = "E";
            F.HeaderText = "F"; F.Name = "F";
            G.HeaderText = "G"; G.Name = "G";
            H.HeaderText = "H"; H.Name = "H";
            I.HeaderText = "I"; I.Name = "I";
            J.HeaderText = "J"; J.Name = "J";
            K.HeaderText = "K"; K.Name = "K";
            L.HeaderText = "L"; L.Name = "L";
            M.HeaderText = "M"; M.Name = "M";
            N.HeaderText = "N"; N.Name = "N";
            O.HeaderText = "O"; O.Name = "O";
            P.HeaderText = "P"; P.Name = "P";

            dataGridView.Columns.Add(A);
            dataGridView.Columns.Add(B);
            dataGridView.Columns.Add(C);
            dataGridView.Columns.Add(D);
            dataGridView.Columns.Add(E);
            dataGridView.Columns.Add(F);
            dataGridView.Columns.Add(G);
            dataGridView.Columns.Add(H);
            dataGridView.Columns.Add(I);
            dataGridView.Columns.Add(J);
            dataGridView.Columns.Add(K);
            dataGridView.Columns.Add(L);
            dataGridView.Columns.Add(M);
            dataGridView.Columns.Add(N);
            dataGridView.Columns.Add(O);
            dataGridView.Columns.Add(P);

            DataGridViewRow row = new DataGridViewRow();

            dataGridView.Rows.Add(row); dataGridView.Rows.Add(); dataGridView.Rows.Add();
            dataGridView.Rows.Add(); dataGridView.Rows.Add(); dataGridView.Rows.Add();
            dataGridView.Rows.Add(); dataGridView.Rows.Add(); dataGridView.Rows.Add();
            dataGridView.Rows.Add(); dataGridView.Rows.Add(); dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            dataGridView.Rows.Add();
            SetRowNum(dataGridView);

            for (int i = 0; i < 32; i++)
            {
                for (int j = 0; j < 32; j++)
                {
                    int    k         = j + 65;
                    string cell_name = (char)k + (i + 1).ToString();
                    //MessageBox.Show(cell_name);
                    MyCell cell = new MyCell();
                    cell.Value = "0";
                    cell.Exp   = "0";
                    cell.Depends.Add("");
                    dictionary.Add(cell_name, cell);
                }
            }
        }