Ejemplo n.º 1
0
        private void btnSaveSettings_Click(object sender, RoutedEventArgs e)
        {
            BrewingData brewingData = new BrewingData();
            DataTable   datatable   = new DataTable();


            brewingData.MashInHltTemperature = double.Parse(TxtMashInHltTemp.Text.Replace(',', '.'), CultureInfo.InvariantCulture);

            brewingData.MashInTemperature = double.Parse(TxtMashInTemp.Text.Replace(',', '.'), CultureInfo.InvariantCulture);

            brewingData.MashInVolume = double.Parse(TxtMashInVolume.Text.Replace(',', '.'), CultureInfo.InvariantCulture);

            brewingData.MashStep1Temperature = double.Parse(TxtMashStep1Temperature.Text.Replace(',', '.'), CultureInfo.InvariantCulture);

            brewingData.MashStep1Time = int.Parse(TxtMashStep1Time.Text.Replace(',', '.'), CultureInfo.InvariantCulture);

            brewingData.MashStep2Temperature = double.Parse(TxtMashStep2Temperature.Text.Replace(',', '.'), CultureInfo.InvariantCulture);

            brewingData.MashStep2Time = int.Parse(TxtMashStep2Time.Text.Replace(',', '.'), CultureInfo.InvariantCulture);

            brewingData.MashStep3Temperature = double.Parse(TxtMashStep3Temperature.Text.Replace(',', '.'), CultureInfo.InvariantCulture);

            brewingData.MashStep3Time = int.Parse(TxtMashStep3Time.Text.Replace(',', '.'), CultureInfo.InvariantCulture);

            brewingData.SpargeTemperature = double.Parse(TxtSpargeTemperature.Text.Replace(',', '.'), CultureInfo.InvariantCulture);

            brewingData.SpargeVolume = double.Parse(TxtSpargeVolume.Text.Replace(',', '.'), CultureInfo.InvariantCulture);

            brewingData.BoilTime = int.Parse(TxtBoilTime.Text.Replace(',', '.'), CultureInfo.InvariantCulture);


            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName   = "BrewSession " + DateTime.Now.ToString("d M yyyy"); // Default file name
            dlg.DefaultExt = ".brewdata";                                        // Default file extension
            dlg.Filter     = "Text documents (.brewdata)|*.brewdata";            // Filter files by extension

            // Show save file dialog box
            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                // Save document
                string        filename       = dlg.FileName;
                XmlSerializer xmlSerilalizer = new XmlSerializer(typeof(BrewingData));

                using (TextWriter writer = new StreamWriter(filename))
                {
                    xmlSerilalizer.Serialize(writer, brewingData);
                }
            }
        }
Ejemplo n.º 2
0
 private void SetBrewingData(BrewingData data)
 {
     try
     {
         TxtMashInTemp.Text           = data.MashInTemperature.ToString();
         TxtMashInHltTemp.Text        = data.MashInHltTemperature.ToString();
         TxtMashInVolume.Text         = data.MashInVolume.ToString();
         TxtMashStep1Temperature.Text = data.MashStep1Temperature.ToString();
         TxtMashStep1Time.Text        = data.MashStep1Time.ToString();
         TxtMashStep2Temperature.Text = data.MashStep2Temperature.ToString();
         TxtMashStep2Time.Text        = data.MashStep2Time.ToString();
         TxtMashStep3Temperature.Text = data.MashStep3Temperature.ToString();
         TxtMashStep3Time.Text        = data.MashStep3Time.ToString();
         TxtSpargeTemperature.Text    = data.SpargeTemperature.ToString();
         TxtSpargeVolume.Text         = data.SpargeVolume.ToString();
         TxtBoilTime.Text             = data.BoilTime.ToString();
     }
     catch
     {}
 }
Ejemplo n.º 3
0
        private void btnGetSettings_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.DefaultExt = ".brewdata";                             // Default file extension
            dlg.Filter     = "Text documents (.brewdata)|*.brewdata"; // Filter files by extension

            // Show save file dialog box
            Nullable <bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                BrewingData returnBrewingData = new BrewingData();
                string      filename          = dlg.FileName;
                try
                {
                    XmlSerializer xmlSerilalizer = new XmlSerializer(typeof(BrewingData));

                    using (TextReader reader = new StreamReader(filename))
                    {
                        var obj = xmlSerilalizer.Deserialize(reader);
                        returnBrewingData = obj as BrewingData;
                    }
                }
                catch (Exception)
                {
                    returnBrewingData = ReadJasonBrewingData(filename);
                }

                finally
                {
                    SetBrewingData(returnBrewingData);
                }
            }

            //var brewData = brewingData.ReadData();
            //SetBrewingData(brewData);
        }
Ejemplo n.º 4
0
        private BrewingData ReadJasonBrewingData(string filePath)
        {
            BrewingData returnBrewingData = new BrewingData();
            string      file     = System.IO.File.ReadAllText(filePath);
            dynamic     fileData = JsonConvert.DeserializeObject(file);

            returnBrewingData.MashInTemperature    = fileData.MashInTemperature;
            returnBrewingData.MashInHltTemperature = fileData.MashInHltTemperature;
            returnBrewingData.MashInVolume         = fileData.MashInVolume;
            returnBrewingData.MashStep1Temperature = fileData.MashStep1Temperature;
            returnBrewingData.MashStep1Time        = fileData.MashStep1Time;
            returnBrewingData.MashStep2Temperature = fileData.MashStep2Temperature;
            returnBrewingData.MashStep2Time        = fileData.MashStep2Time;
            returnBrewingData.MashStep3Temperature = fileData.MashStep3Temperature;
            returnBrewingData.MashStep3Time        = fileData.MashStep3Time;
            returnBrewingData.MashStep4Temperature = fileData.MashStep4Temperature;
            returnBrewingData.MashStep4Time        = fileData.MashStep4Time;
            returnBrewingData.SpargeTemperature    = fileData.SpargeTemperature;
            returnBrewingData.SpargeVolume         = fileData.SpargeVolume;
            returnBrewingData.BoilTime             = fileData.BoilTime;

            return(returnBrewingData);
        }