コード例 #1
0
ファイル: MainView.cs プロジェクト: zimnismoboy34/YmsBms
        private void addBatteryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var newBatteryView = new NewBatteryView();
            var dialogResult   = newBatteryView.ShowDialog(this);

            if (dialogResult == DialogResult.OK)
            {
                AddBatteries(newBatteryView.Address, newBatteryView.IsPartOfCluster);
            }
        }
コード例 #2
0
        private void addBatteryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var newBatteryView = new NewBatteryView();
            var dialogResult   = newBatteryView.ShowDialog(this);

            if (dialogResult == DialogResult.OK)
            {
                if (!SharedData.Default.BatteryPackContainer.ContainsKey(newBatteryView.Address.ToString()))
                {
                    var viewModel = new BatteryStatViewModel(WindowsFormsSynchronizationContext.Current)
                    {
                        IsPartOfCluster = newBatteryView.IsPartOfCluster
                    };
                    viewModel.Address = newBatteryView.Address.ToString();
                    SharedData.Default.BatteryPackContainer.TryAdd(
                        newBatteryView.Address.ToString(),
                        viewModel);

                    if (!viewModel.IsPartOfCluster)
                    {
                        var statUC = new BatteryStats(newBatteryView.Address.ToString(), viewModel);
                        this.flowLayoutPanel1.Controls.Add(statUC);
                    }

                    //toolStripLabel1.Text = string.Format("Battery added : {0}", viewModel.Address);
                }
                else
                {
                    if (!newBatteryView.IsPartOfCluster)
                    {
                        BatteryStatViewModel viewModel;
                        bool succeeded = SharedData.Default.BatteryPackContainer.TryGetValue(newBatteryView.Address.ToString(), out viewModel);
                        if (succeeded)
                        {
                            viewModel.IsPartOfCluster = newBatteryView.IsPartOfCluster;
                            var statUC = new BatteryStats(newBatteryView.Address.ToString(), viewModel);
                            this.flowLayoutPanel1.Controls.Add(statUC);
                        }
                    }
                }

                treeView1.Nodes.Add(newBatteryView.Address.ToString(), string.Format("Battery : {0}", newBatteryView.Address), 0);
                logger.Info(string.Format("Added Battery : {0}", newBatteryView.Address));
            }
        }