Пример #1
0
        public void AddFileConfiguration(LableFileConfiguration currentConfig)
        {
            var existingFileConfig = LabelFileCollection.Where(x => x.TxbFileName == currentConfig.TxbFileName).FirstOrDefault();

            if (existingFileConfig != null)
            {
                existingFileConfig.FileConfiguration = currentConfig.FileConfiguration;
            }
            else
            {
                LabelFileCollection.Add(currentConfig);
            }
        }
Пример #2
0
        private void btnSaveConfig_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(cbFilenames.Text))
                {
                    MessageBox.Show("Please enter a file name or select one of the file names from the Filename list");
                    return;
                }
                if (string.IsNullOrWhiteSpace(txtIpAddress.Text))
                {
                    MessageBox.Show("Please enter a valid IP address");
                    return;
                }
                if (!int.TryParse(txtPort.Text, out int portNumber) && portNumber > 0 && portNumber <= 65635)
                {
                    MessageBox.Show("please insert a valid port number");
                }
                else
                {
                    LableFileConfiguration config = new LableFileConfiguration();
                    config.TxbFileName              = cbFilenames.Text;
                    CurrentConfiguration.IpAddress  = txtIpAddress.Text;
                    CurrentConfiguration.PortNumber = portNumber;
                    for (int i = 0; i < grdKeyValuePairs.Rows.Count - 1; i++)
                    {
                        config.AddConfiguration(grdKeyValuePairs.Rows[i].Cells[0].Value?.ToString(), grdKeyValuePairs.Rows[i].Cells[1].Value?.ToString());
                    }

                    CurrentConfiguration.AddFileConfiguration(config);
                }

                string currentConfigSettings = JsonConvert.SerializeObject(CurrentConfiguration);

                File.WriteAllText(ConfigFileName, currentConfigSettings);

                if (!ComboBoxFileNames.Contains(cbFilenames.Text))
                {
                    ComboBoxFileNames.Add(cbFilenames.Text);
                    cbFilenames.Refresh();
                }

                MessageBox.Show("Saved Successfully");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }