Example #1
0
        private void componentsData_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                string newName = componentsData.Rows[e.RowIndex].Cells[0].Value.ToString();
                double newW    = Double.Parse(componentsData.Rows[e.RowIndex].Cells[1].Value.ToString());

                Component newComponent = new Component(newName, newW);

                XmlFile xmlFile = new XmlFile();
                xmlFile.EditComponent(oldData, newComponent);
                MainForm.FillComponentNameComboBox(_mainForm.componentName);
            }
            catch (FormatException)
            {
                componentsData.Rows[e.RowIndex].Cells[0].Value = oldData.name;
                componentsData.Rows[e.RowIndex].Cells[1].Value = oldData.W;

                MessageBox.Show("Ячейка имеет неправильный формат",
                                "Ошибка",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
Example #2
0
        private void addUnknownComponentButton_Click(object sender, EventArgs e)
        {
            decimal scoreSum   = 0;
            int     scoreCount = 0;

            foreach (Control c in pointsGroup.Controls)
            {
                if (c.GetType() == typeof(NumericUpDown))
                {
                    if (Decimal.Parse(c.Text) != 0)
                    {
                        scoreSum += Decimal.Parse(c.Text);
                        scoreCount++;
                    }
                }
            }

            String newComponentName = unknownComponentName.Text;
            double newPercent       = (double)unknownComponentPercent.Value;
            bool   isHigher         = _mainForm.CheckPercentSum(newPercent);

            if (isHigher)
            {
                MessageBox.Show("Сумма состава больше 100%",
                                "Ошибка!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else
            {
                double newX   = (double)(scoreSum / scoreCount);
                double newZ   = 4 * newX / 3 - 0.33333333333333;
                double newLgW = 0;

                if (newZ > 1 && newZ < 2)
                {
                    newLgW = 4 - (4 / newZ);
                }
                if (newZ > 2 && newZ < 4)
                {
                    newLgW = newZ;
                }
                if (newZ > 4 && newZ < 5)
                {
                    newLgW = 2 + (4 / (6 - newZ));
                }

                double newW = Math.Pow(10, newLgW);

                _mainForm.compositionData.Rows.Add(newComponentName,
                                                   newPercent,
                                                   newW);

                XmlFile xmlFile = new XmlFile();
                xmlFile.AddComponent(newComponentName, newW);
                MainForm.FillComponentNameComboBox(_mainForm.componentName);

                _mainForm.CheckIsCanDelete();
                unknownComponentName.Text     = "";
                unknownComponentPercent.Value = 0;

                MessageBox.Show("X: " + newX + "\r\n" +
                                "Z: " + newZ + "\r\n" +
                                "lg(W): " + newLgW + "\r\n" +
                                "W: " + newW,
                                "Результаты вычислений",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.None);

                foreach (Control c in pointsGroup.Controls)
                {
                    if (c.GetType() == typeof(NumericUpDown))
                    {
                        c.Text = "0";
                    }
                }
            }
        }