Ejemplo n.º 1
0
        // Открыть
        private void OpenItem_Click(object sender, EventArgs e)
        {
            var serializer = new Newtonsoft.Json.JsonSerializer
            {
                TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto
            };
            var openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Figure |*.myfile";
            if (openFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            var fileName = openFileDialog.FileName;

            using (StreamReader streamReader = new StreamReader(fileName))
            {
                using (Newtonsoft.Json.JsonReader jreader = new Newtonsoft.Json.JsonTextReader(streamReader))
                {
                    ListFigure.List = serializer.Deserialize <List <IFigure> >(jreader);
                }
                for (int i = 0; i < ListFigure.List.Count; i++)
                {
                    var figure = ListFigure.List[i];
                    var row    = _tablefigure.NewRow();
                    row[0] = figure.ToString();
                    row[1] = figure.CalculateVolume();
                    row[2] = figure.X;
                    row[3] = figure.Y;
                    row[4] = figure.Z;
                    _tablefigure.Rows.Add(row);
                }
                TableFigure.Update();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Обработчик кнопки "Изменить данные"
        /// </summary>
        private void изменитьДанныеToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Изменить обьект?", "Изменение обьекта", MessageBoxButtons.YesNo,
                                                  MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                if (TableFigure.CurrentRow != null)
                {
                    foreach (DataGridViewCell cell in TableFigure.SelectedCells)
                    {
                        var     figureForm = new FigureForm();
                        var     a          = TableFigure.SelectedCells[0].RowIndex;
                        IFigure figure     = ListFigure.List[a];
                        if (figureForm.ShowDialog() == DialogResult.OK)
                        {
                            TableFigure.Rows.RemoveAt(cell.RowIndex);

                            ListFigure.List.Add(figure);
                            var row = _tablefigure.NewRow();
                            row[0] = figure.ToString();
                            row[1] = figure.CalculateVolume();
                            row[2] = figure.X;
                            row[3] = figure.Y;
                            row[4] = figure.Z;

                            _tablefigure.Rows.Add(row);
                            TableFigure.Update();
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void ButtonModify_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Изменить обьект?", "Изменение обьекта", MessageBoxButtons.YesNo,
                                                  MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                if (TableFigure.CurrentRow != null)
                {
                    foreach (DataGridViewCell cell in TableFigure.SelectedCells)
                    {
                        FigureForm f      = new FigureForm();
                        var        a      = TableFigure.SelectedCells[0].RowIndex;
                        IFigure    figure = ListFigure.List[a];
                        f.ShowDialog();
                        if (f.DialogResult == DialogResult.OK)
                        {
                            TableFigure.Rows.RemoveAt(cell.RowIndex);

                            figure = f.Figures;
                            ListFigure.List.Add(figure);
                            var row = _tablefigure.NewRow();
                            row[0] = figure.Name;
                            row[1] = figure.CalculateVolume();

                            _tablefigure.Rows.Add(row);
                            TableFigure.Update();
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void добавитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var newRow = _tablefigure.NewRow();

            newRow["X"]    = 3.0;
            newRow["Y"]    = 5.0;
            newRow["Name"] = "Шар";
            _tablefigure.Rows.Add(newRow);
            TableFigure.Update();
        }
Ejemplo n.º 5
0
        // Создание строк
        private void ButtonCreate_Click(object sender, EventArgs e)
        {
            var figureForm = new FigureForm();

            if (figureForm.ShowDialog() == DialogResult.OK)
            //добавить фигуру в таблицу
            {
                var figure = figureForm.Figure;
                ListFigure.List.Add(figure);
                var row = _tablefigure.NewRow();
                row[0] = figure.ToString();
                row[1] = figure.CalculateVolume();
                row[2] = figure.X;
                row[3] = figure.Y;
                row[4] = figure.Z;
                _tablefigure.Rows.Add(row);
                TableFigure.Update();
            }
        }