private void buttonAdd_Click(object sender, EventArgs e) { var SympForm = new SymptomEditing(); SympForm.Owner = this; SympForm.ShowDialog(); }
private void buttonCorrect_Click(object sender, EventArgs e) { if (dataGridViewSymptoms.SelectedCells.Count > 0) { var i = dataGridViewSymptoms.SelectedCells[0].RowIndex; var SympForm = new SymptomEditing( new Symptom(Convert.ToInt32(dataGridViewSymptoms.Rows[i].Cells[0].Value), Convert.ToString(dataGridViewSymptoms.Rows[i].Cells[1].Value), Convert.ToDouble(dataGridViewSymptoms.Rows[i].Cells[2].Value), Convert.ToDouble(dataGridViewSymptoms.Rows[i].Cells[3].Value))); SympForm.Owner = this; SympForm.ShowDialog(); } else { MessageBox.Show("Ничего не выделено для редактирования!", "Объект не выделен", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void buttonOk_Click(object sender, EventArgs e) { FuzzyVariable newFuzzy; if (prototypeFuzzy != null) { newFuzzy = new FuzzyVariable(prototypeFuzzy.ID, parentSymptom.ID, textBoxName.Text, buttonColor.BackColor); } else { newFuzzy = new FuzzyVariable(-1, parentSymptom.ID, textBoxName.Text, buttonColor.BackColor); } newFuzzy.Type = (TypeMFuncEnum)comboBoxType.SelectedIndex; newFuzzy.Bound = (BoundaryTypeEnum)comboBoxBound.SelectedIndex; newFuzzy.GaussParam = new GaussMFuncParams(double.Parse(textBoxGC.Text), double.Parse(textBoxSigma.Text)); newFuzzy.TrianglParam = new TriangulareMFuncParams(double.Parse(textBoxTrianglA.Text), double.Parse(textBoxTrianglB.Text), double.Parse(textBoxTrianglC.Text)); newFuzzy.TrapezParam = new TrapezoidalMFuncParams(double.Parse(textBoxTrapA.Text), double.Parse(textBoxTrapB.Text), double.Parse(textBoxTrapC.Text), double.Parse(textBoxTrapD.Text)); if (prototypeFuzzy != null) { newFuzzy.GaussParam.ID = prototypeFuzzy.GaussParam.ID; newFuzzy.TrianglParam.ID = prototypeFuzzy.TrianglParam.ID; newFuzzy.TrapezParam.ID = prototypeFuzzy.TrapezParam.ID; } if (newFuzzy.CheckData()) { switch (newFuzzy.Type) { case TypeMFuncEnum.GAUSS: if ((prototypeFuzzy != null) && (prototypeFuzzy.GaussParam.ID >= 0)) { newFuzzy.GaussParam.ID = prototypeFuzzy.GaussParam.ID; DatabaseManager.Instance.UpdateMF(newFuzzy.GaussParam); } else { newFuzzy.GaussParam.ID = DatabaseManager.Instance.InsertMF(newFuzzy.GaussParam); //newFuzzy.IdGaussian = DatabaseManager.Instance.InsertMF(double.Parse(textBoxGC.Text), // double.Parse(textBoxSigma.Text)); } break; case TypeMFuncEnum.TRIANGULARE: if ((prototypeFuzzy != null) && (prototypeFuzzy.TrianglParam.ID >= 0)) { newFuzzy.TrianglParam.ID = prototypeFuzzy.TrianglParam.ID; DatabaseManager.Instance.UpdateMF(newFuzzy.TrianglParam); } else { newFuzzy.TrianglParam.ID = DatabaseManager.Instance.InsertMF(newFuzzy.TrianglParam); //newFuzzy.IdTriangulare = DatabaseManager.Instance.InsertMF(double.Parse(textBoxTrianglA.Text), // double.Parse(textBoxTrianglB.Text), // double.Parse(textBoxTrianglC.Text)); } break; case TypeMFuncEnum.TRAPEZOIDAL: if ((prototypeFuzzy != null) && (prototypeFuzzy.TrapezParam.ID >= 0)) { newFuzzy.TrapezParam.ID = prototypeFuzzy.TrapezParam.ID; DatabaseManager.Instance.UpdateMF(newFuzzy.TrapezParam); } else { newFuzzy.TrapezParam.ID = DatabaseManager.Instance.InsertMF(newFuzzy.TrapezParam); //newFuzzy.IdTrapezoidal = DatabaseManager.Instance.InsertMF(double.Parse(textBoxTrapA.Text), // double.Parse(textBoxTrapB.Text), // double.Parse(textBoxTrapC.Text), // double.Parse(textBoxTrapD.Text)); } break; default: break; } SymptomEditing parent = this.Owner as SymptomEditing; int i = -1; if (prototypeFuzzy != null) { prototypeFuzzy = newFuzzy; DatabaseManager.Instance.UpdateFuzzyVar(prototypeFuzzy); i = parent.dataGridViewFuzzyVar.SelectedCells[0].RowIndex; parent.dataGridViewFuzzyVar.Rows[i].Cells[0].Value = prototypeFuzzy.ID.ToString(); parent.dataGridViewFuzzyVar.Rows[i].Cells[1].Value = prototypeFuzzy.Name; parent.FuzzyList.Find(x => x.ID == prototypeFuzzy.ID).Set(prototypeFuzzy); } else { prototypeFuzzy = newFuzzy; prototypeFuzzy.ID = DatabaseManager.Instance.InsertFuzzyVar(prototypeFuzzy); string[] row = new string[] { prototypeFuzzy.ID.ToString(), prototypeFuzzy.Name }; i = parent.dataGridViewFuzzyVar.Rows.Add(row); parent.FuzzyList.Add(prototypeFuzzy); } // TO DO: Хранить в свойстве класса, а не локально parent.dataGridViewFuzzyVar.Rows[i].Cells[2].Value = ((int)prototypeFuzzy.Type).ToString(); parent.dataGridViewFuzzyVar.Rows[i].Cells[3].Value = DatabaseManager.Instance.GetTypeMFunc((long)prototypeFuzzy.Type).Name; parent.dataGridViewFuzzyVar.Rows[i].Cells[4].Value = ((int)prototypeFuzzy.Bound).ToString(); parent.dataGridViewFuzzyVar.Rows[i].Cells[5].Value = DatabaseManager.Instance.GetBoundaryType((long)prototypeFuzzy.Bound).Name; var buttonColor = parent.dataGridViewFuzzyVar.Rows[i].Cells[6] as DataGridViewButtonCell; buttonColor.FlatStyle = FlatStyle.Flat; buttonColor.Style.BackColor = prototypeFuzzy.ColorLine; parent.dataGridViewFuzzyVar.Rows[i].Cells[7].Value = prototypeFuzzy.TrapezParam.ID.ToString(); parent.dataGridViewFuzzyVar.Rows[i].Cells[8].Value = prototypeFuzzy.TrapezParam.ID.ToString(); parent.dataGridViewFuzzyVar.Rows[i].Cells[9].Value = prototypeFuzzy.GaussParam.ID.ToString(); this.Close(); } else { MessageBox.Show(String.Format("Запись не добавлена в базу данных по причине: {0}", newFuzzy.LastTrouble), "Запись не добавлена / не отредактирована", MessageBoxButtons.OK, MessageBoxIcon.Error); } }