コード例 #1
0
 public StorageForm(TreeNode treeNode, StorageModel storageModel, bool isChanging)
 {
     InitializeComponent();
     _treeNode     = treeNode;
     _storageModel = storageModel;
     _isChanging   = isChanging;
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Mix2511/AnyTask
        private void сохранитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var sfd = new SaveFileDialog()
            {
                Filter = "Склад|*.storage"
            };

            if (sfd.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            var storage = new StorageModel()
            {
                Name     = textBox1.Text,
                Address  = textBox2.Text,
                Capacity = Convert.ToInt32(textBox3.Text),
                Items    = listBox1.Items.OfType <Items>().ToList(),
                Workers  = listBox2.Items.OfType <Workers>().ToList(),
            };

            switch (comboBox1.SelectedValue?.ToString())
            {
            case "A+":
                storage.StorageType = StorageType.Aplus;
                break;

            case "A":
                storage.StorageType = StorageType.A;
                break;

            case "B+":
                storage.StorageType = StorageType.Bplus;
                break;

            case "B":
                storage.StorageType = StorageType.B;
                break;

            case "C":
                storage.StorageType = StorageType.C;
                break;

            case "D":
                storage.StorageType = StorageType.D;
                break;

            default:
                storage.StorageType = StorageType.Aplus;
                break;
            }

            var xs   = new XmlSerializer(typeof(StorageModel));
            var file = File.Create(sfd.FileName);

            xs.Serialize(file, storage);
            file.Close();
        }
コード例 #3
0
 /// <summary>
 /// Импорт склада в программу и заполнение TreeView его разделами и продуктами.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void importToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         openFileDialog.InitialDirectory = FileController.StorageDirectory.FullName;
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             string       json         = FileController.Read(openFileDialog.FileName);
             StorageModel storageModel = StorageController.DeserializeStorage(json);
             NodeController.FillTreeView(treeView, storageModel);
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show($"Не получается импортировать склад!\n{exception.Message}", "Ошибка!",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
 }
コード例 #4
0
        /// <summary>
        /// Создание нового склада или изменение данного.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void actionStorageButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(nameTextBox.Text))
            {
                MessageBox.Show("Введите имя склада!");
                return;
            }

            if (_isChanging)
            {
                _treeNode.Text = nameTextBox.Text;
                StorageController.UpdateStorage(_storageModel, nameTextBox.Text);
            }
            else
            {
                StorageModel storageModel = StorageController.CreateStorage(nameTextBox.Text);
                NodeController.CreateNode(_treeView, storageModel);
            }

            this.Close();
        }