Example #1
0
        private void BtnLoadClick(object sender, RoutedEventArgs e)
        {
            // Create OpenFileDialog
            var dlg = new OpenFileDialog();

            // Set filter for file extension and default file extension
            dlg.DefaultExt = ".xp3";
            dlg.Filter     = "ConfiguraciĆ³n de la Experiencia 3 (.xp3)|*.xp3";

            // Display OpenFileDialog by calling ShowDialog method
            bool?result = dlg.ShowDialog();

            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                // Open document
                string filename = dlg.FileName;

                //_exp1Class.CloseConnection();
                _exp3Class = null;

                _exp3Class = (Experiencia3)_fileSaver.DeSerializeExp3(filename);
                for (int i = 0; i < 10; i++)
                {
                    //aL ABRIR HAY QUE RESTABLECER LOS BINDINGS, VAYA UD. A SABER POR QUƉ
                    _gpuertas[i].NudBinding        = new Binding();
                    _gpuertas[i].NudBinding.Source = _exp3Class.Puertas[i];
                    _gpuertas[i].NudBinding.Path   = new PropertyPath("TamanoPuerta");
                    _gpuertas[i].NudBinding.Mode   = BindingMode.TwoWay;
                    _gpuertas[i].NUpDown.SetBinding(NumericUpDown.ValueProperty, _gpuertas[i].NudBinding);

                    _gpuertas[i].AbiertaBinding                    = new Binding();
                    _gpuertas[i].AbiertaBinding.Source             = _exp3Class.Puertas[i];
                    _gpuertas[i].AbiertaBinding.Path               = new PropertyPath("EstadoPuerta");
                    _gpuertas[i].AbiertaBinding.Mode               = BindingMode.TwoWay;
                    _gpuertas[i].AbiertaBinding.Converter          = _en;
                    _gpuertas[i].AbiertaBinding.ConverterParameter = PuertaExp3.DoorState.Abierta;
                    _gpuertas[i].BotonAbierta.SetBinding(ToggleButton.IsCheckedProperty, _gpuertas[i].AbiertaBinding);

                    _gpuertas[i].CerradaBinding        = new Binding();
                    _gpuertas[i].CerradaBinding.Source = _exp3Class.Puertas[i];
                    _gpuertas[i].CerradaBinding.Path   = new PropertyPath("EstadoPuerta");
                    _gpuertas[i].CerradaBinding.Mode   = BindingMode.TwoWay;
                    //Para bindear un radiobutton hay que hacer unb enumtobool converter
                    _gpuertas[i].CerradaBinding.Converter          = _en;
                    _gpuertas[i].CerradaBinding.ConverterParameter = PuertaExp3.DoorState.Cerrada;
                    _gpuertas[i].BotonCerrada.SetBinding(ToggleButton.IsCheckedProperty, _gpuertas[i].CerradaBinding);


                    _gpuertas[i].AutoBinding                    = new Binding();
                    _gpuertas[i].AutoBinding.Source             = _exp3Class.Puertas[i];
                    _gpuertas[i].AutoBinding.Path               = new PropertyPath("EstadoPuerta");
                    _gpuertas[i].AutoBinding.Mode               = BindingMode.TwoWay;
                    _gpuertas[i].AutoBinding.Converter          = _en;
                    _gpuertas[i].AutoBinding.ConverterParameter = PuertaExp3.DoorState.Auto;
                    _gpuertas[i].BotonAuto.SetBinding(ToggleButton.IsCheckedProperty, _gpuertas[i].AutoBinding);
                }
            }
        }
Example #2
0
        public void SerializeXp3(string filename, Experiencia3 objectToSerialize)
        {
            Stream stream     = File.Open(filename, FileMode.Create);
            var    bFormatter = new BinaryFormatter();

            bFormatter.Serialize(stream, objectToSerialize);
            stream.Close();
        }