/// <summary>
        /// Procedimiento para comprobar la existencia del archivo de configuracion config.data
        /// Si no existe, se crea si o si ... >:)
        /// </summary>
        public static void configCheck()
        {
            // 1. COMPROBAR EXISTENCIA...
            // 2. SI NO ESTA.. CREARLO:
            // 3. PEDIR LOS DATOS Y GUARDARLOS A OBJETO DatosBase
            // 4. CON LOS DATOS EN EL OBJETO, LO PASAMOS POR EL FILEHELPER PARA GUARDARLO EN BINARIO
            // 5. SALIMOS...

            string pass;    // PARA GUARDAR LA CONTRASEÑA
            bool   salir;   // CONTROL DE SALIDA SI CREACION CORRECTA

            try
            {
                datosBaseBin = new DatosBase(); // REUSAMOS EL OBJETO DEL CONTROLADOR
                salir        = false;           // SETEAMOS SALIR A FALSE

                if (!File.Exists(rutabin))
                {
                    CH.cls();
                    CH.lcdColor("!> ATENCIÓN!!.. NO EXISTE EL FICHERO DE CONFIGURACION!!", ConsoleColor.Red);
                    CH.lcdColor("\ni> VAMOS A CREARLO AHORA... ALMA DEL AMOL HERRMOZO >:) \ni> Y NO TE EQUIVOQUES.... PUES EMPEZARAS DEL PRINCIPIO", ConsoleColor.DarkYellow);
                    do
                    {
                        try
                        {
                            CH.lcd("");
                            pass = CH.leerCadena("CONTRASEÑA DE ACCESO");
                            datosBaseBin.maxhoras        = CH.leerNumero("HORAS MÁXIMAS NOMINA");
                            datosBaseBin.horasbase       = CH.leerNumero("HORAS TOPE SAL. BASE");
                            datosBaseBin.maxeuxhora      = CH.leerCantidad("EUROS MAX. X HORA...");
                            datosBaseBin.preciojoranda   = CH.leerCantidad("PRECIO EUR. JORANDA.");
                            datosBaseBin.incrementoextra = CH.leerCantidad("IMCREMENTO H. EXTRA.");
                            datosBaseBin.impuestos       = CH.leerCantidad("% DE IMPUESTOS......");
                            FH.grabarValoresBinary(rutabin, pass, datosBaseBin.maxhoras, datosBaseBin.horasbase, datosBaseBin.maxeuxhora, datosBaseBin.preciojoranda, datosBaseBin.incrementoextra, datosBaseBin.impuestos);
                            FH.grabarValores(ruta, pass, datosBaseBin.maxhoras, datosBaseBin.horasbase, datosBaseBin.maxeuxhora, datosBaseBin.preciojoranda, datosBaseBin.incrementoextra, datosBaseBin.impuestos);
                            salir = true;
                        }
                        catch (Exception ex)
                        {
                            CH.lcdColor("!> ERROR: " + ex.Message, ConsoleColor.Red);
                            CH.pausa();
                        }
                    } while (!salir);
                }
                else
                {
                    CH.cls();
                    CH.lcdColor("!> FICHERO DE CONFIGURACION LOCALIZADO...", ConsoleColor.Green);
                    CH.pausa();
                }
            }
            catch (IOException ex)
            {
                CH.lcdColor("!> ERROR I/O: " + ex.Message, ConsoleColor.Red);
                CH.pausa();
            }
            //CH.pausa();
        }
        /// <summary>
        /// Método para logearse al sistema de administración de valores de configuración de la nómina por defecto
        /// </summary>
        public static bool logIn()
        {
            bool   logeado = false;
            string cadena  = "";
            string aux     = "";

            string[]     pass_split = null;
            StreamReader sr;

            cadena = CH.leerCadena("INTRODUCE CONTRASEÑA DE ACCESO");

            if (File.Exists(ruta))
            {
                CH.lcdColor("i> ACCEDIENDO AL FICHERO DE CONFIGURACION...", ConsoleColor.Green);
                try
                {
                    //File.OpenText(ruta);
                    sr         = File.OpenText(ruta);
                    aux        = sr.ReadLine();
                    pass_split = aux.Split(':');
                    pass       = pass_split[1];
                    //CH.lcd("PASS:"******"i> LOGIN O.K.", ConsoleColor.Yellow);
                        CH.pausa();
                    }
                    else
                    {
                        CH.lcdColor("i> LOGIN K.O..", ConsoleColor.Red);
                    }
                }
                catch (Exception ex)
                {
                    CH.lcdColor(ex.Message, ConsoleColor.Red);
                }
            }
            else
            {
                CH.lcdColor("i> ERROR. NO SE ENCUENTRA EL FICHERO DE CONFIGURACION", ConsoleColor.Red);
            }
            return(logeado);
        }
        public static DatosBase cargarDatosBinary()
        {
            string pass;
            int    maxhoras, horasbase;
            float  maxeurxhora, preciojornada, incrementoextra, impuestos;

            DatosBase    datos = null;
            BinaryReader br    = null;
            FileStream   fr    = null;

            try
            {
                datos = new DatosBase();
                fr    = File.Open(rutabin, FileMode.Open, FileAccess.Read);
                br    = new BinaryReader(fr);

                pass            = br.ReadString().Trim();
                maxhoras        = br.ReadInt32();
                horasbase       = br.ReadInt32();
                maxeurxhora     = br.ReadSingle();
                preciojornada   = br.ReadSingle();
                incrementoextra = br.ReadSingle();
                impuestos       = br.ReadSingle();

                datos.maxhoras        = maxhoras;
                datos.horasbase       = horasbase;
                datos.maxeuxhora      = maxeurxhora;
                datos.preciojoranda   = preciojornada;
                datos.incrementoextra = incrementoextra;
                datos.impuestos       = impuestos;
            }
            catch (Exception ex)
            {
                CH.lcdColor("!> ERROR: " + ex.Message, ConsoleColor.Red);
                CH.pausa();
            }
            finally
            {
                br.Dispose();
            }

            //Console.WriteLine("{0} | {1} | {2} | {3} | {4}",pass,maxhoras,maxeurxhora,preciojornada,factorextra);
            //CH.pausa();
            return(datos);
        }
        /// <summary>
        /// Función para obtener los datos base del fichero de texto y volcarlos a un objeto tipo DatosBase con los datos de config.
        /// </summary>
        public static DatosBase cargarDatos()
        {
            //string pass;
            int   maxhoras, horasbase;
            float maxeurxhora, preciojornada, incrementoextra, impuestos;

            string linea = null;

            string[]     tokens = null;
            DatosBase    datos  = null;;
            StreamReader sr     = null;;

            try
            {
                datos = new DatosBase();
                sr    = File.OpenText(ruta);
                linea = sr.ReadLine();

                /* NO GUARDAMOS LA PASSS EN EL OBJETO!!
                 * tokens = linea.Split(':');
                 * pass = tokens[1];
                 */
                linea  = sr.ReadLine();
                tokens = linea.Split(':');
                Int32.TryParse(tokens[1], out maxhoras);
                datos.maxhoras = maxhoras;

                linea  = sr.ReadLine();
                tokens = linea.Split(':');
                Int32.TryParse(tokens[1], out horasbase);
                datos.horasbase = horasbase;

                linea  = sr.ReadLine();
                tokens = linea.Split(':');
                Single.TryParse(tokens[1], out maxeurxhora);
                datos.maxeuxhora = maxeurxhora;

                linea  = sr.ReadLine();
                tokens = linea.Split(':');
                Single.TryParse(tokens[1], out preciojornada);
                datos.preciojoranda = preciojornada;

                linea  = sr.ReadLine();
                tokens = linea.Split(':');
                Single.TryParse(tokens[1], out incrementoextra);
                datos.incrementoextra = incrementoextra;

                linea  = sr.ReadLine();
                tokens = linea.Split(':');
                Single.TryParse(tokens[1], out impuestos);
                datos.impuestos = impuestos;
            }
            catch (Exception ex)
            {
                CH.lcdColor("ERROR: " + ex.Message, ConsoleColor.Red);
                CH.pausa();
            }
            finally
            {
                sr.Dispose();
            }

            //Console.WriteLine("{0} | {1} | {2} | {3} | {4}",pass,maxhoras,maxeurxhora,preciojornada,factorextra);
            //CH.pausa();
            return(datos);
        }
Example #5
0
 /// <summary>
 /// Converts the type of the value to.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="targetType">Type of the target.</param>
 /// <returns></returns>
 protected object ConvertValueToType(object value, Type targetType)
 {
     return(DatosBase.ConvertValueToType(value, targetType));
 }