Example #1
0
        internal void Leer(string fileName)
        {
            string Linea;

            try
            {
                StreamReader reader = new StreamReader(fileName);
                Linea             = reader.ReadLine();
                _Nombre           = Linea.Substring(Linea.IndexOf('=') + 1, Linea.Length - Linea.IndexOf('=') - 1);
                _Archivo          = fileName;
                Linea             = reader.ReadLine();
                _NroRestricciones = int.Parse(Linea.Substring(Linea.IndexOf('=') + 1, Linea.Length - Linea.IndexOf('=') - 1));
                Linea             = reader.ReadLine();
                _NroVariables     = int.Parse(Linea.Substring(Linea.IndexOf('=') + 1, Linea.Length - Linea.IndexOf('=') - 1));
                //Validar c
                Linea = reader.ReadLine();

                Linea = reader.ReadLine();
                string[] c = Linea.Split(',');
                _c = new double[_NroVariables];
                for (int i = 0; i < _NroVariables; i++)
                {
                    _c[i] = double.Parse(c[i]);
                }
                //Validar b
                Linea = reader.ReadLine();
                _b    = new double[_NroRestricciones];
                Linea = reader.ReadLine();
                string[] b = Linea.Split(',');
                for (int i = 0; i < _NroRestricciones; i++)
                {
                    _b[i] = double.Parse(b[i]);
                }
                //Validar A
                Linea = reader.ReadLine();
                _A    = new double[_NroRestricciones, _NroVariables];
                for (int i = 0; i < _NroRestricciones; i++)
                {
                    Linea = reader.ReadLine();
                    string[] Av = Linea.Split(',');
                    for (int j = 0; j < _NroVariables; j++)
                    {
                        _A[i, j] = double.Parse(Av[j]);
                    }
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error al cargar archivo", "Atención", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Example #2
0
            private static string AlineaTexto(string Texto, int Tamaño, bool Justificar, string NamePrinter)
            {
                string Todo, Linea, Parte, TextoReal;
                int    Desde, Hasta, Previo, Posicion, Intro;
                bool   Insertar, HayBlancos;

                char[] charsToTrim = { ' ' };
                Todo = Texto.Trim(charsToTrim) + " ";

                // si no biene datos regresamos espacio
                if (Texto.Length == 0)
                {
                    return("");
                }


                TieneIntros :;
                TextoReal = "";

                Intro = Todo.IndexOf('/');

                if (Intro >= 0)
                {
                    Parte = LeftRightMid.Left(Todo, Intro - 1);
                    Todo  = LeftRightMid.Mid(Todo, Intro + 2, Todo.Length - (Intro + 2));
                    Linea = Parte + "\n" + Todo;
                    RawPrinterHelper.SendStringToPrinter(NamePrinter, Linea); // imprime texto
                    goto TieneIntros;
                }

                Previo = 1;
                do
                {
                    if (Todo.IndexOf(" ", 0) < 0)
                    {
                        TextoReal = TextoReal + Todo + "\n";
                    }
                    Desde = 1;
                    MasAun :;
                    Hasta = Todo.IndexOf(' ', Desde) + 1;

                    if (LeftRightMid.Left(Todo, Hasta).Length < Tamaño)
                    {
                        Previo = Hasta;       //'El último corte que encaja en el ancho
                        Desde  = Hasta + 1;
                        if (Hasta < Todo.Length)
                        {
                            goto MasAun;
                        }
                    }

                    char[] espacio = { ' ' };
                    Linea = (LeftRightMid.Left(Todo, Previo - 1).Trim(espacio));
                    Todo  = LeftRightMid.Mid(Todo, Previo, Todo.Length - (Previo));

                    //si no quiere justicicar saltamo
                    if (Justificar == false)
                    {
                        goto ExitWile;
                    }
                    Ajustar :;

                    Posicion = 1;
                    if (Linea.IndexOf(' ') >= 0)
                    {
                        HayBlancos = true;
                    }
                    else
                    {
                        HayBlancos = false;
                    }

                    Insertar = false;

                    do
                    {
                        string buscar = LeftRightMid.Mid(Linea, Posicion - 1, 1);
                        if (buscar.IndexOf(" ", 0) < 0)
                        {
                            Insertar = true;
                        }
                        else
                        {
                            if (Insertar == true)
                            {
                                Linea    = LeftRightMid.Left(Linea, Posicion) + " " + LeftRightMid.Mid(Linea, Posicion, (Linea.Length - Posicion));
                                Insertar = false;
                            }
                        }
                        Posicion = Posicion + 1;
                    } while (!((HayBlancos == false) || (Linea.Length >= Tamaño) || (Posicion == Linea.Length)));

                    if (Linea.Length < Tamaño && HayBlancos && Todo.Length > 0)
                    {
                        goto Ajustar;
                    }
                    ExitWile :;
                    Linea += "\n";
                    RawPrinterHelper.SendStringToPrinter(NamePrinter, Linea); // imprime texto
                } while (Todo.IndexOf(" ", 0) >= 0);
                return(TextoReal);
            }