//수정 public Form_AddVariable(VariableData selectedVar, Dictionary <string, EquationInformation> vardata, string selectedEquation) { InitializeComponent(); isModifyMode = true; m_dictionary_EquationInfomation = vardata; m_dictionary_Variable = new Dictionary <string, VariableData>(m_dictionary_EquationInfomation[selectedEquation].m_Dictionary_Equation); m_textbox_VarName.Text = selectedVar.Name; if (selectedVar is EquationVariable) { m_radio_variable_output.Checked = true; m_textbox_variable_Equation.Text = selectedVar.Equation; m_check_variable_hidden.Checked = selectedVar.IsHiddenVariable; m_radio_variable_input.Enabled = false; m_radio_variable_output.Enabled = false; } else { if (selectedVar.m_Dictionary_SwitchInfo == null) { selectedVar.m_Dictionary_SwitchInfo = new Dictionary <string, string>(); } m_dictionary_Case = new Dictionary <string, string>(selectedVar.m_Dictionary_SwitchInfo); m_radio_variable_input.Checked = true; m_radio_variable_input.Enabled = false; m_radio_variable_output.Enabled = false; if (selectedVar.IsCorrespond) { m_button_variable_correspond.Text = "설정해제"; m_textbox_variable_correspond.Text = selectedVar.CorrespontVarName; } if (selectedVar.m_checkOption == VariableData.CheckOption.None) { m_radio_no_check.Checked = true; } else if (selectedVar.m_checkOption == VariableData.CheckOption.MinMax) { m_radio_check_range.Checked = true; } else if (selectedVar.m_checkOption == VariableData.CheckOption.Case) { m_radio_check_switch.Checked = true; } else { m_radio_check_user.Checked = true; } m_textbox_check_min.Text = selectedVar.OptionMinValue.ToString("R"); m_textbox_check_max.Text = selectedVar.OptionMaxValue.ToString("R"); m_textbox_check_user.Text = selectedVar.CustomOptionString; m_dictionary_Case = new Dictionary <string, string>(selectedVar.m_Dictionary_SwitchInfo); } }
/// <summary> /// 변수 추가 버튼 클릭 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { Form_AddVariable addvarform = new Form_AddVariable(m_Dictionary_EquationInformation, m_selectedEquation); // 다이얼로그에서 설정된 값을 토대로 변수 생성. if (addvarform.ShowDialog( ) == DialogResult.OK) { // 폼에서 출력 변수를 선택 했다. if (addvarform.IsEquationVariable) { // 출력변수 만들고 등록. EquationVariable vdata = MakeNewEquationVar(addvarform.VariableName, addvarform.Equation); vdata.Equation = addvarform.Equation; vdata.IsHiddenVariable = addvarform.IsHiddenValue; listBox2.Items.Add(vdata.Name); m_Dictionary_VariableData.Add(vdata.Name, vdata); } // 입력 변수를 선택했다. else { VariableData vdata = MakeNewVar(addvarform.VariableName); vdata.IsCorrespond = addvarform.isCorrespond; // 출력변수 대입인지 체크. if (vdata.IsCorrespond) { vdata.CorrespontVarName = addvarform.CorrespondVarPath; } // Option 체크 설정. vdata.m_checkOption = addvarform.Option; if (addvarform.Option == VariableData.CheckOption.None) { } else if (addvarform.Option == VariableData.CheckOption.MinMax) { vdata.OptionMinValue = addvarform.CheckMinValue; vdata.OptionMaxValue = addvarform.CheckMaxValue; } else { vdata.CustomOptionString = addvarform.CustomOptionString; } listBox1.Items.Add(vdata.Name); m_Dictionary_VariableData.Add(vdata.Name, vdata); } } }
/// <summary> /// Min Max 체크 함수 /// </summary> /// <param name="vdata"></param> /// <returns></returns> private bool CheckMinMax(VariableData vdata) { double min, max; min = vdata.OptionMinValue; max = vdata.OptionMaxValue; if (vdata.Value < min) { return(false); } if (vdata.Value > max) { return(false); } return(true); }
private void listBox1_DoubleClick(object sender, EventArgs e) { if (listBox1.SelectedItem != null) { string selectedItem = listBox1.SelectedItem.ToString(); var selectedVariable = m_Dictionary_VariableData[selectedItem]; Form_AddVariable addvarform = new Form_AddVariable(selectedVariable, m_Dictionary_EquationInformation, m_selectedEquation); if (addvarform.ShowDialog() == DialogResult.OK) { VariableData newVariable = new VariableData(addvarform.VariableName); newVariable.IsCorrespond = addvarform.isCorrespond; if (newVariable.IsCorrespond) { newVariable.CorrespontVarName = addvarform.CorrespondVarPath; } newVariable.m_checkOption = addvarform.Option; newVariable.OptionMinValue = addvarform.CheckMinValue; newVariable.OptionMaxValue = addvarform.CheckMaxValue; newVariable.m_Dictionary_SwitchInfo = addvarform.CaseInfo; newVariable.CustomOptionString = addvarform.CustomOptionString; try { int index = listBox1.SelectedIndex; m_Dictionary_VariableData.Remove(selectedItem); m_Dictionary_VariableData.Add(newVariable.Name, newVariable); listBox1.Items.Remove(listBox1.SelectedItem); listBox1.Items.Insert(index, newVariable.Name); } catch (System.Exception ex) { newVariable.Name = listBox1.SelectedItem.ToString(); m_Dictionary_VariableData.Add(listBox1.SelectedItem.ToString(), newVariable); MessageBox.Show(ex.Message); } } } }
/// <summary> /// 사용자 조건문 체크 함수. /// </summary> /// <param name="vdata"></param> /// <returns></returns> private bool CheckCustom(VariableData vdata) { char[] c_splitter = { '\n' }; // 엔터 값으로 구분 string[] spl_strs = vdata.CustomOptionString.Split(c_splitter, StringSplitOptions.RemoveEmptyEntries); string[] splitter = { ">=", "<=", "==", ">", "<", "!=" }; foreach (string str in spl_strs) { string[] s = str.Split(splitter, StringSplitOptions.RemoveEmptyEntries); m_Term.Parse(s[0].Trim()); double left = m_Term.Value; m_Term.Parse(s[1].Trim()); double right = m_Term.Value; if (s.Length != 2) { return(false); } if (str.Contains(">=")) { if (!(left >= right)) { return(false); } } else if (str.Contains("<=")) { if (!(left <= right)) { return(false); } } else if (str.Contains("==")) { if (!(left == right)) { return(false); } } else if (str.Contains(">")) { if (!(left > right)) { return(false); } } else if (str.Contains("<")) { if (!(left < right)) { return(false); } } else if (str.Contains("!=")) { if (!(left != right)) { return(false); } } } return(true); }
private VariableData MakeNewVar(string name) { VariableData vdata = new VariableData(name); return(vdata); }