コード例 #1
0
        private bool Set_EnumValues()
        {
            SignalFormatProperties oBackupFormat = oCurrentFormat.Get_Clone();

            oCurrentFormat.Enums.Clear();

            foreach (DataGridViewRow oRow in Grid_Enum.Rows)
            {
                EnumerationValue sEnum = new EnumerationValue();

                int EnumVal;
                if (!(oRow.Cells[0].Value == null))
                {
                    if (int.TryParse(oRow.Cells[0].Value.ToString(), out EnumVal))
                    {
                        if (!(EnumValueExists(EnumVal)))
                        {
                            sEnum.Value = EnumVal;
                        }
                        else
                        {
                            oCurrentFormat = oBackupFormat.Get_Clone();
                            MessageBox.Show("Enumeration value '" + EnumVal.ToString() + "' is defined twice !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return(false);
                        }
                    }
                    else
                    {
                        oCurrentFormat = oBackupFormat.Get_Clone();
                        MessageBox.Show("An enumeration value must be a numerical value !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(false);
                    }
                }
                else
                {
                    oCurrentFormat = oBackupFormat.Get_Clone();
                    MessageBox.Show("An enumeration value cannot be empty !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }


                string EnumTxt;
                if (!(oRow.Cells[1].Value == null))
                {
                    EnumTxt = oRow.Cells[1].Value.ToString();
                    if (!(EnumTextExists(EnumTxt)))
                    {
                        sEnum.Text = EnumTxt;
                    }
                    else
                    {
                        oCurrentFormat = oBackupFormat.Get_Clone();
                        MessageBox.Show("Enumeration text '" + EnumTxt + "' is defined twice !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(false);
                    }
                }
                else
                {
                    oCurrentFormat = oBackupFormat.Get_Clone();
                    MessageBox.Show("An enumeration text cannot be empty !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                oCurrentFormat.Enums.Add(sEnum);
            }

            return(true);
        }