Exemplo n.º 1
0
        public static ModuleConfiguration Load(string fileName)
        {
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException(fileName);
            }
            ModuleConfiguration c   = new ModuleConfiguration();
            XmlDocument         xml = new XmlDocument();

            xml.Load(fileName);
            c.LPTAddress = int.Parse(xml.SelectSingleNode("/configuration/lpt").Attributes["address"].Value, System.Globalization.NumberStyles.HexNumber);
            c.LCD1       = new LPTLCD(xml.SelectSingleNode("/configuration/lcds/lcd1/lcd"));
            c.LCD2       = new LPTLCD(xml.SelectSingleNode("/configuration/lcds/lcd2/lcd"));
            XmlNodeList nodes = xml.SelectNodes("/configuration/areas/area");

            if (nodes != null && nodes.Count > 0)
            {
                List <LPTLCDArea> areas = new List <LPTLCDArea>();
                LCDSet            s     = new LCDSet(new LCD[] { c.LCD1, c.LCD2 });
                foreach (XmlNode area in nodes)
                {
                    LPTLCDArea a = new LPTLCDArea(area, s);
                    areas.Add(a);
                }
                c.Areas = areas.ToArray();
            }
            return(c);
        }
Exemplo n.º 2
0
 private void dataGridView2_CellValueChanged(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex > -1 && e.ColumnIndex == tekst.Index)
     {
         LPTLCDArea area = dataGridView2.Rows[e.RowIndex].Tag as LPTLCDArea;
         if (area != null)
         {
             area.WriteText(Convert.ToString(dataGridView2.Rows[e.RowIndex].Cells[tekst.Index].Value));
         }
     }
 }
Exemplo n.º 3
0
        public AddEditLCDArea(ModuleConfiguration configuration, int areIndex)
        {
            InitializeComponent();
            _configuration = configuration;
            _areaIndex     = areIndex;

            foreach (Enum s in Enum.GetValues(typeof(Align)))
            {
                comboBox1.Items.Add(HomeSimCockpitX.LCD.Utils.AlignToString((Align)s));
            }

            foreach (Enum s in Enum.GetValues(typeof(Trim)))
            {
                comboBox2.Items.Add(HomeSimCockpitX.LCD.Utils.TrimToString((Trim)s));
            }

            foreach (Enum s in Enum.GetValues(typeof(Append)))
            {
                comboBox3.Items.Add(HomeSimCockpitX.LCD.Utils.AppendToString((Append)s));
            }

            if (_configuration.LCD1.Enabled)
            {
                comboBox4.Items.Add(_configuration.LCD1);
            }
            if (_configuration.LCD2.Enabled)
            {
                comboBox4.Items.Add(_configuration.LCD2);
            }

            if (areIndex < 0)
            {
                // dodanie nowego
                Text = "Dodaj nowy obszar";
                comboBox1.SelectedIndex = 0;
                comboBox2.SelectedIndex = 0;
                comboBox3.SelectedIndex = 0;
                //comboBox4.SelectedIndex = 0;
            }
            else
            {
                // edycja istniejącego
                LPTLCDArea area = (LPTLCDArea)configuration.Areas[areIndex];
                Text                   = "Edycja obszaru '" + area.ID + "'";
                textBox1.Text          = area.ID;
                textBox2.Text          = area.Description;
                comboBox1.SelectedItem = Utils.AlignToString(area.Align);
                comboBox2.SelectedItem = Utils.TrimToString(area.Trim);
                comboBox3.SelectedItem = Utils.AppendToString(area.Append);
                textBox3.Text          = area.AppendString;
                ShowCharacters();
            }
        }
Exemplo n.º 4
0
 void Button7Click(object sender, EventArgs e)
 {
     if (listView2.SelectedIndices.Count > 0)
     {
         LPTLCDArea area = Configuration.Areas[listView2.SelectedIndices[0]];
         if (MessageBox.Show(this, string.Format("Czy napewno chcesz usunąć obszar '{0}' ?", area.ID), "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
         {
             return;
         }
         List <LPTLCDArea> areas = new List <LPTLCDArea>();
         areas.AddRange(Configuration.Areas);
         areas.Remove(area);
         Configuration.Areas = areas.ToArray();
         ShowAreas();
     }
 }
Exemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            // sprawdzenie poprawności danych
            string id = textBox1.Text.Trim();

            textBox1.Text = id;
            if (id.Length == 0)
            {
                MessageBox.Show(this, "Identyfikator nie może być pusty.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                textBox1.Focus();
                return;
            }
            string description = textBox2.Text.Trim();

            textBox2.Text = description;

            if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show(this, "Nie wybrano rodzaju wyrównania.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                comboBox1.Focus();
                return;
            }
            Align align = Utils.StringToAlign(comboBox1.SelectedItem.ToString());

            if (comboBox2.SelectedIndex == -1)
            {
                MessageBox.Show(this, "Nie wybrano rodzaju przycięcia.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                comboBox2.Focus();
                return;
            }
            Trim trim = Utils.StringToTrim(comboBox2.SelectedItem.ToString());

            if (comboBox3.SelectedIndex == -1)
            {
                MessageBox.Show(this, "Nie wybrano rodzaju dołączenia.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                comboBox3.Focus();
                return;
            }
            Append append       = Utils.StringToAppend(comboBox3.SelectedItem.ToString());
            string appendString = textBox3.Text;

            if (append != Append.None && appendString.Length == 0)
            {
                MessageBox.Show(this, "Nie wpisano ciągu dołączanego.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                textBox3.Focus();
                return;
            }

            // sprawdzenie czy istnieje już obszar o takim id
            for (int i = 0; i < _configuration.Areas.Length; i++)
            {
                if (i == _areaIndex)
                {
                    continue;
                }
                if (_configuration.Areas[i].ID == id)
                {
                    MessageBox.Show(this, string.Format("Istnieje już obszar o identyfikatorze '{0}'.", id), "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    textBox1.Focus();
                    return;
                }
            }

            LPTLCDArea          area       = null;
            List <LCDCharacter> characters = new List <LCDCharacter>();

            if (_areaIndex > -1)
            {
                area = _configuration.Areas[_areaIndex];
                characters.AddRange(_configuration.Areas[_areaIndex].Characters);
            }
            else
            {
                area = new LPTLCDArea();
                List <LPTLCDArea> areas = new List <LPTLCDArea>();
                areas.AddRange(_configuration.Areas);
                areas.Add(area);
                _configuration.Areas = areas.ToArray();
                characters.AddRange(Array.ConvertAll <LPTLCDCharacter, LCDCharacter>(_characters.ToArray(), new Converter <LPTLCDCharacter, LCDCharacter>(LPTLCDCharacter.Convert)));
            }
            if (characters.Count == 0)
            {
                MessageBox.Show(this, "Obszar musi składać się co najmniej z jednego znaku.", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            area.Set(id, description, align, trim, append, appendString);

            area.Set(characters.ToArray());
            area.ArrangeCharacters();

            DialogResult = DialogResult.OK;
        }
Exemplo n.º 6
0
 internal ModuleConfiguration()
 {
     LPTAddress = 0x0378;
     Areas      = new LPTLCDArea[0];
 }