Visual CSharp .NET - no guarda los cambios del check box

 
Vista:
Imágen de perfil de Mayck
Val: 23
Ha mantenido su posición en Visual CSharp .NET (en relación al último mes)
Gráfica de Visual CSharp .NET

no guarda los cambios del check box

Publicado por Mayck (6 intervenciones) el 29/12/2017 02:29:56
buenas noches, este codigo esta hecho en wpf, con el lenguaje de c#, es una alarma con reconocimiento de voz,
hasta aqui todo funciona bien, excepto; que no guarda los cambios del check box, y le cargo los archivos de musica, ya sea en wav, o mp3, ni videos tampoco, si alguien puede ayudarme lo agradeceria, porque no me reproduce la musica cuando cumple la hora programada, gracias a quien pueda ayudarme

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
{
    /// <summary>
    /// Lógica de interacción para Alarma.xaml
    /// </summary>
    public partial class Alarma : Window
    {
        DispatcherTimer LaHora;
        SpeechSynthesizer AVGemma = new SpeechSynthesizer();
 
        public Alarma()
        {
            InitializeComponent();
            AVGemma.SpeakAsync("Esta es la ventana para configurar su Alarma, puede elegir el día, la hora, la fecha y la música preferida para su Alarma");
            ConfigTiempo();
            ValoresIniciales();
        }
 
        void ConfigTiempo()
        {
            LaHora = new DispatcherTimer
            {
                Interval = new TimeSpan(1000)
            };
            LaHora.Tick += LaHora_Tick;
            LaHora.Start();
        }
 
        private void LaHora_Tick(object sender, EventArgs e)
        {
            DateTime Tiempo = DateTime.Now;
            LblHora.Content = Tiempo.ToString("h:mm:ss tt", new CultureInfo("en-US"));
           // string horaActual = Tiempo.ToString("h:mm:ss tt", new CultureInfo("en-US"));
        }
 
        static public void SaveAlarmaData(string hora)
        {
            Settings.Default.tHora = hora.Split(':')[0];
            Settings.Default.tMinutos = hora.Split(' ')[0].Split(':')[1];
            Settings.Default.tPeriodo = hora.Split(' ')[1];
 
            Settings.Default.ALunes = true;
            Settings.Default.AMartes = true;
            Settings.Default.AMiercoles = true;
            Settings.Default.AJueves = true;
            Settings.Default.AViernes = true;
            Settings.Default.ASabado = true;
            Settings.Default.ADomingo = true;
 
        }
 
        static public void CheckAlarma() // compara la Alarma
        {
 
            DateTime now = DateTime.Now;
            string hora = now.ToString("h:mm tt", new CultureInfo("en-US"));
            string hora2 = now.ToString("h:mm:ss tt", new CultureInfo("en-US"));
 
 
            string dia = DateTime.Today.ToString("dddd");
            string[] partesHora = hora.Split(':');
 
            if ((dia == "Lunes" && Settings.Default.ALunes) || (dia == "Martes" && Settings.Default.AMartes) || (dia == "Miercoles" && Settings.Default.AMiercoles) || (dia == "Jueves" && Settings.Default.AJueves) || (dia == "Viernes" && Settings.Default.AViernes) || (dia == "Sabado" && Settings.Default.ASabado) || (dia == "Domingo" && Settings.Default.ADomingo))
            {
                if (Settings.Default.tHora == partesHora[0])
                {
                    if (Settings.Default.tMinutos == partesHora[1].Split(' ')[0])
                    {
                        if (hora2.Split(':')[2].Split(' ')[0] == "00")
                        {
                            if (Settings.Default.tPeriodo.ToLower() == hora.Split(' ')[1].ToLower())
                            {
                                try
                                {
                                    Process.Start(Settings.Default.tRuta);
                                }
                                catch (Exception )
                                {
 
                                    MessageBox.Show("Debe agregar un archivo de música");
                                }
                            }
                        }
                    }
                }
            }
        }
 
        void ValoresIniciales()
        {
            CbPeriodo.Items.Add("AM");
            CbPeriodo.Items.Add("PM");
 
            for (int i = 0; i < 13; i++)
            {
                CbHora.Items.Add(i);
            }
 
            for (int i = 0; i < 10; i++)
 
            {
               CbMinuto.Items.Add("0" + i);
            }
 
            for (int i = 10; i < 60; i++)
            {
                CbMinuto.Items.Add(i);
            }
 
            CbHora.Text = Settings.Default.tHora;
            CbMinuto.Text = Settings.Default.tMinutos;
            CbPeriodo.Text = Settings.Default.tPeriodo;
            TxtRuta.Text = Settings.Default.tRuta;
        }
 
        private void BtnMinimizar_Click(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Minimized;
        } // minimizar ventana
 
        private void BtnCerrar_Click(object sender, RoutedEventArgs e)
        {
            MainWindow mn = new MainWindow();
            mn.Show();
            AVGemma.SpeakAsyncCancelAll();
            Close();
        } // cerrar la ventana
 
        private void BtnBuscar_Click(object sender, RoutedEventArgs e)
        {
            windowForm.OpenFileDialog ofd = new windowForm.OpenFileDialog
            {
                Filter = "Archivos de música(mp3, mp4, wav, wma)|*.MP3; *.MP4; *.WAV; *.WMA" + "|Todos los Archivos|*.*",
                Title = "Abrir"
            };
            if (ofd.ShowDialog().ToString().Equals("OK"))
            {
                TxtRuta.Text = ofd.FileName;
                Settings.Default.tRuta = TxtRuta.Text;
                Settings.Default.Save();
            }
 
            ofd.Dispose();
        } // busca los archivos requeridos
 
        private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DragMove();
        } // mueve la ventana
 
        private void CbHora_DropDownClosed(object sender, EventArgs e)
        {
            Settings.Default.tHora = CbHora.Text;
            Settings.Default.Save();
        }
 
        private void CbMinuto_DropDownClosed(object sender, EventArgs e)
        {
            Settings.Default.tMinutos = CbMinuto.Text;
            Settings.Default.Save();
        }
 
        private void CbPeriodo_DropDownClosed(object sender, EventArgs e)
        {
            Settings.Default.tPeriodo = CbPeriodo.Text;
            Settings.Default.Save();
        }
 
 
        #region guarda los valoresde los dias de la semana
 
        private void CbLun_Checked(object sender, RoutedEventArgs e)
        {
            Settings.Default.ALunes = CbLun.IsChecked.HasValue ? CbLun.IsChecked.HasValue : false;
            Settings.Default.Save();
        }
 
        private void CbLun_Unchecked(object sender, RoutedEventArgs e)
        {
            Settings.Default.ALunes = CbLun.IsChecked.HasValue ? CbLun.IsChecked.HasValue : false;
            Settings.Default.Save();
        }
 
        private void CbMar_Checked(object sender, RoutedEventArgs e)
        {
            Settings.Default.AMartes = CbMar.IsChecked.HasValue ? CbMar.IsChecked.HasValue : false;
            Settings.Default.Save();
        }
 
        private void CbMar_Unchecked(object sender, RoutedEventArgs e)
        {
            Settings.Default.AMartes = CbMar.IsChecked.HasValue ? CbMar.IsChecked.HasValue : false;
            Settings.Default.Save();
        }
 
 
        private void CbMie_Checked(object sender, RoutedEventArgs e)
        {
            Settings.Default.AMiercoles = CbMie.IsChecked.HasValue ? CbMie.IsChecked.HasValue : false;
            Settings.Default.Save();
        }
 
        private void CbMie_Unchecked(object sender, RoutedEventArgs e)
        {
            Settings.Default.AMiercoles = CbMie.IsChecked.HasValue ? CbMie.IsChecked.HasValue : false;
            Settings.Default.Save();
        }
 
        private void CbJue_Checked(object sender, RoutedEventArgs e)
        {
            Settings.Default.AJueves = CbJue.IsChecked.HasValue ? CbJue.IsChecked.HasValue : false;
            Settings.Default.Save();
        }
 
        private void CbJue_Unchecked(object sender, RoutedEventArgs e)
        {
            Settings.Default.AJueves = CbJue.IsChecked.HasValue ? CbJue.IsChecked.HasValue : false;
            Settings.Default.Save();
        }
 
        private void CbVie_Checked(object sender, RoutedEventArgs e)
        {
            Settings.Default.AViernes = CbVie.IsChecked.HasValue ? CbVie.IsChecked.HasValue : false;
            Settings.Default.Save();
        }
 
        private void CbVie_Unchecked(object sender, RoutedEventArgs e)
        {
            Settings.Default.AViernes = CbVie.IsChecked.HasValue ? CbVie.IsChecked.HasValue : false;
            Settings.Default.Save();
        }
 
        private void CbSab_Checked(object sender, RoutedEventArgs e)
        {
            Settings.Default.ASabado = CbSab.IsChecked.HasValue ? CbSab.IsChecked.HasValue : false;
            Settings.Default.Save();
        }
 
        private void CbSab_Unchecked(object sender, RoutedEventArgs e)
        {
            Settings.Default.ASabado = CbSab.IsChecked.HasValue ? CbSab.IsChecked.HasValue : false;
            Settings.Default.Save();
        }
 
        private void CbDom_Checked(object sender, RoutedEventArgs e)
        {
            Settings.Default.ADomingo = CbDom.IsChecked.HasValue ? CbDom.IsChecked.HasValue : false;
            Settings.Default.Save();
        }
 
        private void CbDom_Unchecked(object sender, RoutedEventArgs e)
        {
            Settings.Default.ADomingo = CbDom.IsChecked.HasValue ? CbDom.IsChecked.HasValue : false;
            Settings.Default.Save();
        }
 
        #endregion
 
    }
}
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Speech.Synthesis;
using System.Windows.Threading;
using System.Globalization;
using AVGemmaFinal.Properties;
using windowForm = System.Windows.Forms;
using System.Diagnostics;

ovbio los system estan arriba pero los agregue abajo solo para que vean lo que tengo agregado.
Captura-de-pantalla-27
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 31
Ha mantenido su posición en Visual CSharp .NET (en relación al último mes)
Gráfica de Visual CSharp .NET

no guarda los cambios del check box

Publicado por Miguel (16 intervenciones) el 29/12/2017 08:20:48
En los eventos Checked/Unchecked de los checkBox no estás guardando correctamente el valor, puedes usar el evento CheckedChanged:

1
2
3
4
5
6
// capturar cambio de estado del checkBox para el día lunes
private void CbLun_CheckedChanged(object sender, RoutedEventArgs e)
{
    Settings.Default.ALunes = (CbLun.IsChecked == true);
    Settings.Default.Save();
}

PD: cuando se compila la solución (se crea otro ejecutable) es posible que se pierdan las configuraciones.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Mayck
Val: 23
Ha mantenido su posición en Visual CSharp .NET (en relación al último mes)
Gráfica de Visual CSharp .NET

no guarda los cambios del check box

Publicado por Mayck (6 intervenciones) el 29/12/2017 14:03:00
sabe tengo otro problema con su ayuda y es que lo hice pero no me lo acepta porque no tengo el valor checkedChange en mi visual, y no entiendo solo tengo el checked y el unchecked y lo hice como ud me aconcejo pero como le hago la referencia a mi interfaz, gracias por su comprencion, aqui le mando una fotico con el hecho.
Captura-de-pantalla-29
Captura-de-pantalla-30
Captura-de-pantalla-31

ok eso es lo que tengo hecho.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 31
Ha mantenido su posición en Visual CSharp .NET (en relación al último mes)
Gráfica de Visual CSharp .NET

no guarda los cambios del check box

Publicado por Miguel (16 intervenciones) el 29/12/2017 14:34:04
Umm, si, acá en WPF tienes que usar los eventos Checked/Unchecked. Solo modifica las líneas donde cambias la configuración:

1
2
3
4
5
6
7
8
9
10
11
12
//
private void CbLun_Checked(object sender, RoutedEventArgs e)
{
    Settings.Default.ALunes = (CbLun.IsChecked == true); // línea a modificar
    Settings.Default.Save();
}
 
private void CbLun_Unchecked(object sender, RoutedEventArgs e)
{
    Settings.Default.ALunes = (CbLun.IsChecked == true); // línea a modificar
    Settings.Default.Save();
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Mayck
Val: 23
Ha mantenido su posición en Visual CSharp .NET (en relación al último mes)
Gráfica de Visual CSharp .NET

no guarda los cambios del check box

Publicado por Mayck (6 intervenciones) el 29/12/2017 16:12:00
desafortunadamente sigue sin guardar los cambios, aun con el codigo que me regalaron, pero debo aclarar q lo hice solo en lunes y no en todos, sera que debe ser en todos para que funcione
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar