示例#1
0
 private void LoadProductDataFromSettingsFile()
 {
     using (FileStream fs = new FileStream("product_settings.json", FileMode.Open))
     {
         var             jsonSerializer  = new DataContractJsonSerializer(typeof(ProductSettings));
         ProductSettings productSettings = jsonSerializer.ReadObject(fs) as ProductSettings;
         tbProductSettingsFile.Text = JsonConvert.SerializeObject(productSettings, Formatting.Indented);
     }
 }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (IsValidJson(tbProductSettingsFile.Text))
            {
                using (FileStream fs = new FileStream("product_settings.json", FileMode.Truncate))
                {
                    ProductSettings            productSettings = JsonConvert.DeserializeObject <ProductSettings>(tbProductSettingsFile.Text);
                    DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(ProductSettings));
                    js.WriteObject(fs, productSettings);
                }

                ctrlMaintenance.ProcessEvent();
                this.Close();
            }
            else
            {
                MessageBox.Show("Settings file must be a valid JSON!", "Invalid format", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void LoadProductDataFromSettingsFile()
        {
            using (FileStream fs = new FileStream("product_settings.json", FileMode.Open))
            {
                var             jsonSerializer  = new DataContractJsonSerializer(typeof(ProductSettings));
                ProductSettings productSettings = jsonSerializer.ReadObject(fs) as ProductSettings;

                comboBoxProductType.Items.Clear();
                comboBoxProductGroup.Items.Clear();

                foreach (string item in productSettings.productTypes)
                {
                    comboBoxProductType.Items.Add(item);
                }

                foreach (string item in productSettings.productGroups)
                {
                    comboBoxProductGroup.Items.Add(item);
                }
            }
        }