Example #1
0
        /// <summary>
        /// Новый список
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ElementsProject.Elements.Count == 0)
            {
                var saveFileDialog = new SaveFileDialog();
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    _fileName = saveFileDialog.FileName;
                    Text      = _fileName.Substring(_fileName.LastIndexOf("\\") + 1) + @" - SPO Laboratory Works";
                }
                else
                {
                    return;
                }
                return;
            }
            var resultNewElement = MessageBox.Show(@"Do you want to save this file?", @"New file",
                                                   MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            switch (resultNewElement)
            {
            case DialogResult.Yes:
            {
                ElementsProject.AngularFrequency = Convert.ToDouble(textBoxAngularFrequency.Text);
                ElementsProject.FileName         = _fileName;
                _serializeElement.Serilization(ElementsProject);
                ElementsProject.Elements.Clear();
                elementDataGridView.Rows.Clear();
                textBoxAngularFrequency.Text = "";
                _fileName = "C:\\Users\\User\\Documents\\New List";
                Text      = FileNameGenerate.GenerateFileName(_fileName);
                break;
            }

            case DialogResult.No:
            {
                ElementsProject.Elements.Clear();
                elementDataGridView.Rows.Clear();
                textBoxAngularFrequency.Text = "";
                _fileName = "C:\\Users\\User\\Documents\\New List";
                Text      = FileNameGenerate.GenerateFileName(_fileName);
                break;
            }

            case DialogResult.Abort:
            {
                break;
            }
            }
            _saveFile = false;
        }
Example #2
0
        /// <summary>
        /// Главная форма
        /// </summary>
        public ElementListForm(string[] args)
        {
            InitializeComponent();

            if (args.Length > 0)
            {
                using (var fs = new FileStream(args[0], FileMode.OpenOrCreate))
                {
                    var elementsProject = (ElementsProject)formatter.Deserialize(fs);

                    ElementsProject = elementsProject;

                    textBoxAngularFrequency.Text = ElementsProject.AngularFrequency.ToString();
                    _fileName = ElementsProject.FileName;
                    Text      = _fileName.Substring(_fileName.LastIndexOf("\\") + 1) + @" - SPO Laboratory Works";

                    for (int i = 0; i < ElementsProject.Elements.Count; i++)
                    {
                        elementDataGridView.Rows.Add(ElementsProject.Elements[i].Name, ElementsProject.Elements[i].Value,
                                                     ElementsProject.Elements[i].GetImpedance(Convert.ToDouble(textBoxAngularFrequency.Text)));
                    }
                }
            }


            Text      = _fileName;
            _elements = new List <IElement>();
#if !DEBUG
            buttonRandom.Visible = false;
#endif
            Text                             = FileNameGenerate.GenerateFileName(_fileName);
            ElementsProject                  = new ElementsProject();
            ElementsProject.Elements         = _elements;
            ElementsProject.AngularFrequency = Convert.ToDouble(textBoxAngularFrequency.Text);
            ElementsProject.FileName         = _fileName;
        }