Esempio n. 1
0
        private void btnSaveChanges_Click(object sender, RoutedEventArgs e)
        {
            System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(ddColor.Color);
            var dueDateColorData = converter.ConvertToString(ddColor.Color);

            System.ComponentModel.TypeConverter converter2 = System.ComponentModel.TypeDescriptor.GetConverter(ccMessage.Color);
            var messageTextColor = converter2.ConvertToString(ccMessage.Color);

            System.ComponentModel.TypeConverter converter3 = System.ComponentModel.TypeDescriptor.GetConverter(backgroundDueDate.Color);
            var BackgroundDueDateColor = converter3.ConvertToString(backgroundDueDate.Color);

            System.ComponentModel.TypeConverter converter4 = System.ComponentModel.TypeDescriptor.GetConverter(backgroundMessageColor.Color);
            var BackgroundMessageColor = converter4.ConvertToString(backgroundMessageColor.Color);

            string dueDate     = "";
            string companyLogo = "";

            if (dpDueDate.SelectedDate != null)
            {
                dueDate = dpDueDate.SelectedDate.Value.ToString();
            }

            if (!String.IsNullOrWhiteSpace(screenSettings.CompanyLogo))
            {
                companyLogo = screenSettings.CompanyLogo;
            }

            screenSettings = new ScreenSaverSettings()
            {
                Message                = txtMessage.Text,
                DueDateMessage         = txtDueDateMessage.Text,
                DueDate                = dueDate,
                CompanyLogo            = companyLogo,
                DueDateTextColor       = dueDateColorData,
                MessageTextColor       = messageTextColor,
                BackgroundDueDateColor = BackgroundDueDateColor,
                BackgroundMessageColor = BackgroundMessageColor
            };

            var json = Newtonsoft.Json.JsonConvert.SerializeObject(screenSettings);

            try
            {
                var sw = new StreamWriter(@"c:\screen\data.enigma");
                sw.Write(json);
                sw.Close();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "Unable to write to directory");
            }

            this.Close();
        }
Esempio n. 2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (File.Exists(@"c:\screen\data.enigma"))
            {
                string jsonData = "";

                try
                {
                    var reader = new StreamReader(@"c:\screen\data.enigma");
                    jsonData = reader.ReadToEnd();
                    reader.Close();
                } catch (Exception) { } // file may not exist

                if (!String.IsNullOrWhiteSpace(jsonData))
                {
                    var data = Newtonsoft.Json.JsonConvert.DeserializeObject <ScreenSaverSettings>(jsonData);
                    screenSettings = data;

                    if (!String.IsNullOrWhiteSpace(data.Message))
                    {
                        txtMessage.Text = data.Message;
                    }

                    if (!String.IsNullOrWhiteSpace(data.DueDateMessage))
                    {
                        txtDueDateMessage.Text = data.DueDateMessage;
                    }

                    if (!String.IsNullOrWhiteSpace(data.DueDate))
                    {
                        dpDueDate.SelectedDate = Convert.ToDateTime(data.DueDate);
                    }

                    if (!String.IsNullOrWhiteSpace(data.MessageTextColor))
                    {
                        ccMessage.Color = ConvertStringToColor(data.MessageTextColor);
                    }

                    if (!String.IsNullOrWhiteSpace(data.DueDateTextColor))
                    {
                        ddColor.Color = ConvertStringToColor(data.DueDateTextColor);
                    }

                    if (!String.IsNullOrWhiteSpace(data.BackgroundDueDateColor))
                    {
                        backgroundDueDate.Color = ConvertStringToColor(data.BackgroundDueDateColor);
                    }

                    if (!String.IsNullOrWhiteSpace(data.BackgroundMessageColor))
                    {
                        backgroundMessageColor.Color = ConvertStringToColor(data.BackgroundMessageColor);
                    }

                    if (!String.IsNullOrWhiteSpace(data.CompanyLogo))
                    {
                        imgCompanyLogo.Source = new BitmapImage(new Uri(data.CompanyLogo));
                    }
                }
            }
            else
            {
                screenSettings = new ScreenSaverSettings();
            }
        }