public void editar_elemento(string elemento, int diferencia) { //Editamos en el programa Principal pp = Application.OpenForms.OfType <Principal>().SingleOrDefault(); List <string> elementos = new List <string>(); for (int a = 0; a < pp.elementos.Count; a++) { elementos.Add(pp.elementos[a]); } pp.elementos.Clear(); foreach (string i in elementos) { string[] argumentos = i.Split('|'); if (!es_vacio(argumentos[0])) { if (argumentos[0] == pp.vehiculo[0, 0] && argumentos[1] == elemento) { if (diferencia == 0) { pp.elementos.Add(argumentos[0] + "|" + argumentos[1] + "|" + argumentos[2] + "|" + argumentos[2]); } else if (diferencia < Convert.ToInt32(argumentos[2]) - Convert.ToInt32(argumentos[3])) { int proximo_cambio = Convert.ToInt32(argumentos[2]) - diferencia; pp.elementos.Add(argumentos[0] + "|" + argumentos[1] + "|" + argumentos[2] + "|" + proximo_cambio); } else { pp.elementos.Add(argumentos[0] + "|" + argumentos[1] + "|" + argumentos[2] + "|" + argumentos[3].Split('\r')[0]); } } else { pp.elementos.Add(i.Split('\r')[0]); } } } //editamos en el documento TextReader elementor = new StreamReader("elementos.txt"); string texto_completo = elementor.ReadToEnd(); elementor.Close(); string[] lineas = texto_completo.Split('\n'); int posicion = 65156165; for (int a = 0; a < lineas.Length; a++) { string[] argumentos = lineas[a].Split('|'); if (!es_vacio(argumentos[0])) { if (argumentos[0] == pp.vehiculo[0, 0] && argumentos[1] == elemento) { posicion = a; break; } } } TextWriter elementow = new StreamWriter("elementos.txt"); for (int a = 0; a < lineas.Length; a++) { string[] argumentos = lineas[a].Split('|'); if (!es_vacio(argumentos[0])) { if (posicion == a) { if (diferencia == 0) { elementow.WriteLine(argumentos[0] + "|" + argumentos[1] + "|" + argumentos[2] + "|" + argumentos[2]); } else if (diferencia < Convert.ToInt32(argumentos[2]) - Convert.ToInt32(argumentos[3])) { int proximo_cambio = Convert.ToInt32(argumentos[2]) - diferencia; elementow.WriteLine(argumentos[0] + "|" + argumentos[1] + "|" + argumentos[2] + "|" + proximo_cambio); } else { elementow.WriteLine(argumentos[0] + "|" + argumentos[1] + "|" + argumentos[2] + "|" + argumentos[3].Split('\r')[0]); } } else { elementow.WriteLine(lineas[a].Split('\r')[0]); } } } elementow.Close(); }
private void button1_Click(object sender, EventArgs e) { Principal pp = Application.OpenForms.OfType <Principal>().SingleOrDefault(); TextReader elementosrr = new StreamReader("elementos.txt"); string[] lineasele = elementosrr.ReadToEnd().Split('\n'); List <string> elenuevo = new List <string>(); int existe = 0; elementosrr.Close(); int con = 0; foreach (string ss in lineasele) { if (ss != "" && ss != " " && ss != "\r") { string[] ss2 = ss.Split('|'); if (textBox3.Text.ToUpper() == ss2[1]) { con++; } } } if (con == 0 || comboBox1.Text == textBox3.Text.ToUpper()) { if (textBox3.Text.ToUpper() != "" && comboBox1.Text != "") { foreach (string i in lineasele) { if (i != "" && i != "\r") { string[] argumentos = i.Split('|'); if (argumentos[0] == pp.vehiculo[0, 0] && argumentos[1] == comboBox1.Text) { elenuevo.Add(argumentos[0] + "|" + textBox3.Text.ToUpper() + "|" + numericUpDown1.Value + "|" + argumentos[3].Split('\r')[0]); MessageBox.Show("Se ha modificado el elemento correctamente", "Modificar Elemento", MessageBoxButtons.OK, MessageBoxIcon.Information); existe = 1; } else { elenuevo.Add(i); } } } TextWriter elemew = new StreamWriter("elementos.txt"); foreach (string i in elenuevo) { elemew.WriteLine(i.Split('\r')[0]); } elemew.Close(); pp.elementos.Clear(); TextReader el = new StreamReader("elementos.txt"); string[] filas = el.ReadToEnd().Split('\n'); el.Close(); foreach (string i in filas) { if (i != "" && i != "\r") { string[] j = i.Split('|'); if (j[0] == pp.vehiculo[0, 0]) { pp.elementos.Add(i); } } } if (existe != 0) { //REINICIO comboBox1.Items.Clear(); comboBox1.Text = textBox3.Text.ToUpper(); label13.Text = "Elementos\nNombre // Cambio cada"; string[,] vehiculo; List <string> elementos; vehiculo = pp.vehiculo; elementos = pp.elementos; if (elementos.Count != 0) { foreach (string i in elementos) { string[] filas2 = i.Split('|'); if (i != "") { comboBox1.Items.Add(filas2[1]); } } } foreach (string i in elementos) { if (i != "" && i != "\r") { string[] argumentos = i.Split('|'); label13.Text = label13.Text + "\n" + argumentos[1] + "//" + argumentos[2] + " Km"; } } } else { MessageBox.Show("Seleccione un elemento válido a editar en la caja de selección", "Modificar elemento", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("No puede dejar vacío el nombre", "Modificar Elemento", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Ya existe un elemento con ese nombre", "Modificar elemento", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public void Abrir_ingresar() { Principal principal = Application.OpenForms.OfType <Principal>().SingleOrDefault(); string ruta = "vehiculos.txt"; camiones = new StreamReader(ruta); texto_Completo = camiones.ReadToEnd(); lineas = texto_Completo.Split('\n'); matriz_camion = new string[lineas.Length, 8]; int yy = 0; for (int a = 0; a < lineas.Length; a++) { string[] segmentos = lineas[a].Split('|'); for (int b = 0; b < segmentos.Length; b++) { matriz_camion[a, b] = segmentos[b]; } int count = 0; foreach (char h in segmentos[0]) { if (h != ' ') { count = 1; break; } } if (segmentos[0] == comboBox1.Text) { yy = 1; break; } } camiones.Close(); if (yy == 1) { principal.placas = comboBox1.Text; if (principal.panel1.Controls.Count > 0) { principal.panel1.Controls.RemoveAt(0); } Contenedor_controles controles = new Contenedor_controles(); controles.TopLevel = false; controles.Dock = DockStyle.Fill; principal.panel1.Controls.Add(controles); principal.panel1.Tag = controles; principal.MaximizeBox = false; int ancho = controles.Size.Width; int alto = controles.Size.Height; principal.Size = new Size(ancho, alto + 35); int deskHeight = Screen.PrimaryScreen.Bounds.Height; int deskWidth = Screen.PrimaryScreen.Bounds.Width; principal.Location = new Point((deskWidth - principal.Width) / 2, ((deskHeight - principal.Height) / 2) - 20); //principal.Location = Screen.PrimaryScreen.WorkingArea.Location; //principal.Size = Screen.PrimaryScreen.WorkingArea.Size; controles.Show(); } else { MessageBox.Show("El vehículo relacionado a esa placa no existe", "Ingreso", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button1_Click(object sender, EventArgs e) { string comentario = textBox4.Text; string kilometraje = Convert.ToString(numericUpDown1.Value); Principal pp = Application.OpenForms.OfType <Principal>().SingleOrDefault(); int diferencia = Convert.ToInt32(numericUpDown1.Value) - Convert.ToInt32(pp.vehiculo[0, 4]); int count = 0; int posicion = 0; TextReader vehiculos = new StreamReader("vehiculos.txt"); string[] lineas = vehiculos.ReadToEnd().Split('\n'); vehiculos.Close(); foreach (string i in lineas) { string[] argumentos = i.Split('|'); if (argumentos[0] == pp.vehiculo[0, 0] && argumentos[1] == pp.vehiculo[0, 1] && argumentos[2] == pp.vehiculo[0, 2] && argumentos[3] == pp.vehiculo[0, 3] && argumentos[4] == pp.vehiculo[0, 4] && argumentos[5] == pp.vehiculo[0, 5] && argumentos[6] == pp.vehiculo[0, 6] && argumentos[7] == pp.vehiculo[0, 7]) { count = 1; break; } posicion++; } string tt = ""; int count2 = 0; if (count == 1) { TextWriter vehiculosw = new StreamWriter("vehiculos.txt"); foreach (string i in lineas) { if (i != "" && i != "\r") { if (count2 != posicion) { vehiculosw.WriteLine(i.Split('\r')[0]); } else { string[] jjj = i.Split('|'); jjj[6] = comentario; jjj[4] = kilometraje; vehiculosw.WriteLine(jjj[0] + "|" + jjj[1] + "|" + jjj[2] + "|" + jjj[3] + "|" + jjj[4] + "|" + jjj[5] + "|" + jjj[6] + "|" + jjj[7].Split('\r')[0]); } } count2++; } vehiculosw.Close(); } TextReader elementosrr = new StreamReader("elementos.txt"); string[] lineasele = elementosrr.ReadToEnd().Split('\n'); List <string> elenuevo = new List <string>(); elementosrr.Close(); foreach (string i in lineasele) { if (i != "" && i != "\r") { string[] argumentos = i.Split('|'); if (argumentos[0] == pp.vehiculo[0, 0]) { argumentos[3] = Convert.ToString(Convert.ToInt32(argumentos[3]) - diferencia); elenuevo.Add(argumentos[0] + "|" + argumentos[1] + "|" + argumentos[2] + "|" + argumentos[3].Split('\r')[0]); } else { elenuevo.Add(i); } } } TextWriter elemew = new StreamWriter("elementos.txt"); foreach (string i in elenuevo) { elemew.WriteLine(i.Split('\r')[0]); } elemew.Close(); pp.elementos.Clear(); TextReader el = new StreamReader("elementos.txt"); string[] filas = el.ReadToEnd().Split('\n'); el.Close(); foreach (string i in filas) { if (i != "" && i != "\r") { string[] j = i.Split('|'); if (j[0] == pp.placas) { pp.elementos.Add(i); } } } pp.vehiculo[0, 6] = comentario; pp.vehiculo[0, 4] = kilometraje; //REINICIO string[,] vehiculo; List <string> elementos; Principal pp4 = Application.OpenForms.OfType <Principal>().SingleOrDefault(); vehiculo = pp4.vehiculo; elementos = pp4.elementos; label7.Text = vehiculo[0, 0]; label8.Text = vehiculo[0, 1]; label10.Text = vehiculo[0, 2]; label9.Text = vehiculo[0, 3]; numericUpDown1.Value = Convert.ToInt32(vehiculo[0, 4]); label14.Text = vehiculo[0, 5] + "$"; textBox4.Text = vehiculo[0, 6]; if (elementos.Count == 0) { label15.Text = "No existen elementos aún"; } else { string[,] valores = new string[elementos.Count, 4]; for (int a = 0; a < elementos.Count; a++) { string[] hola = elementos[a].Split('|'); int o = 0; foreach (string h in hola) { valores[a, o] = h; o++; } } string t1, t2, t3, t0; for (int a = 1; a < elementos.Count; a++) { for (int b = elementos.Count - 1; b >= a; b--) { if (Convert.ToInt32(valores[b - 1, 3]) > Convert.ToInt32(valores[b, 3])) { t0 = valores[b - 1, 0]; t1 = valores[b - 1, 1]; t2 = valores[b - 1, 2]; t3 = valores[b - 1, 3]; valores[b - 1, 0] = valores[b, 0]; valores[b - 1, 1] = valores[b, 1]; valores[b - 1, 2] = valores[b, 2]; valores[b - 1, 3] = valores[b, 3]; valores[b, 0] = t0; valores[b, 1] = t1; valores[b, 2] = t2; valores[b, 3] = t3; } } } label15.Text = ""; for (int b = 0; b < elementos.Count; b++) { label15.Text = label15.Text + "Es necesario hacer el cambio de " + valores[b, 1] + " dentro de " + valores[b, 3].Split('\r')[0] + " Km" + "\n"; } } label1.Text = "Se ha cambiado el kilometraje\ny se guardo el comentario"; }
public Control() { InitializeComponent(); string[,] vehiculo; List <string> elementos; Principal pp = Application.OpenForms.OfType <Principal>().SingleOrDefault(); vehiculo = pp.vehiculo; elementos = pp.elementos; label7.Text = vehiculo[0, 0]; label8.Text = vehiculo[0, 1]; label10.Text = vehiculo[0, 2]; label9.Text = vehiculo[0, 3]; numericUpDown1.Value = Convert.ToInt32(vehiculo[0, 4]); label14.Text = vehiculo[0, 5] + "$"; textBox4.Text = vehiculo[0, 6]; if (elementos.Count == 0) { label15.Text = "No existen elementos aún"; } else { string[,] valores = new string[elementos.Count, 4]; for (int a = 0; a < elementos.Count; a++) { string[] hola = elementos[a].Split('|'); int o = 0; foreach (string h in hola) { valores[a, o] = h; o++; } } string t1, t2, t3, t0; for (int a = 1; a < elementos.Count; a++) { for (int b = elementos.Count - 1; b >= a; b--) { if (Convert.ToInt32(valores[b - 1, 3]) > Convert.ToInt32(valores[b, 3])) { t0 = valores[b - 1, 0]; t1 = valores[b - 1, 1]; t2 = valores[b - 1, 2]; t3 = valores[b - 1, 3]; valores[b - 1, 0] = valores[b, 0]; valores[b - 1, 1] = valores[b, 1]; valores[b - 1, 2] = valores[b, 2]; valores[b - 1, 3] = valores[b, 3]; valores[b, 0] = t0; valores[b, 1] = t1; valores[b, 2] = t2; valores[b, 3] = t3; } } } label15.Text = ""; for (int b = 0; b < elementos.Count; b++) { label15.Text = label15.Text + "Es necesario hacer el cambio de " + valores[b, 1] + " dentro de " + valores[b, 3].Split('\r')[0] + " Km" + "\n"; } } }
private void button2_Click_1(object sender, EventArgs e) { if (count == 1) { if (!File.Exists("vehiculos.txt")) { TextWriter vehiculos = new StreamWriter("vehiculos.txt"); vehiculos.WriteLine(vehiculo); vehiculos.Close(); } else { Principal principal = Application.OpenForms.OfType <Principal>().SingleOrDefault(); int count2 = 0; TextReader vehiculos = new StreamReader("vehiculos.txt"); string[] lineas = vehiculos.ReadToEnd().Split('\n'); vehiculos.Close(); foreach (string i in lineas) { string[] argumentos = i.Split('|'); if (argumentos[0] == principal.placas) { count2 = 1; } } if (count2 != 1) { TextReader vehiculosr = new StreamReader("vehiculos.txt"); string texto = vehiculosr.ReadToEnd(); vehiculosr.Close(); TextWriter vehiculosw = new StreamWriter("vehiculos.txt"); vehiculosw.WriteLine(texto + vehiculo); vehiculosw.Close(); TextReader vehiculosr2 = new StreamReader("vehiculos.txt"); string texto1 = vehiculosr2.ReadToEnd(); vehiculosr2.Close(); } else { MessageBox.Show("La placa que ingreso ya existe en otro vehículo, cambie la placa y de clic en ingresar nuevamente", "Ingreso de Datos", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (countele == 1) { if (!File.Exists("elementos.txt")) { TextWriter elemento = new StreamWriter("elementos.txt"); foreach (string i in elementos) { elemento.WriteLine(placa_general.ToUpper() + "|" + i); } elemento.Close(); } else { TextReader elementosr = new StreamReader("elementos.txt"); string texto2 = elementosr.ReadToEnd(); elementosr.Close(); TextWriter elementosw = new StreamWriter("elementos.txt"); elementosw.Write(texto2); foreach (string i in elementos) { elementosw.WriteLine(placa_general + "|" + i); //doc = doc + placa_general + "|" + i+"\n"; } elementosw.Close(); } } else { if (!File.Exists("elementos.txt")) { TextWriter elemento = new StreamWriter("elementos.txt"); elemento.WriteLine(""); elemento.Close(); } } Abrir_ingresar(); } else { MessageBox.Show("No ha ingresado nada aún", "Agregar Vehículo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void button1_Click_1(object sender, EventArgs e) { if (textBox1.Text != "" && comboBox2.Text != "" && textBox1.Text != "" && textBox2.Text != "") { if (File.Exists("vehiculos.txt")) { int count2 = 0; TextReader vehiculos = new StreamReader("vehiculos.txt"); string[] lineas = vehiculos.ReadToEnd().Split('\n'); vehiculos.Close(); foreach (string i in lineas) { string[] argumentos = i.Split('|'); if (argumentos[0] == textBox1.Text.ToUpper()) { count2 = 1; } } if (count2 != 1) { Principal principal = Application.OpenForms.OfType <Principal>().SingleOrDefault(); principal.placas = textBox1.Text.ToUpper(); placa_general = textBox1.Text.ToUpper(); Mostrar_datos_en_label(label11); string comentario = textBox4.Text; if (textBox4.Text == "") { comentario = "sin comentario"; } vehiculo = textBox1.Text.ToUpper() + "|" + comboBox1.Text.ToUpper() + "|" + textBox2.Text.ToUpper() + "|" + comboBox2.Text.ToUpper() + "|" + numericUpDown1.Value + "|0|" + comentario + "|"; count = 1; if (textBox3.Text != "") { int con = 0; foreach (string ss in elementos) { string[] ss2 = ss.Split('|'); if (textBox3.Text.ToUpper() == Convert.ToString(ss2[0])) { con++; } } if (con == 0) { Mostrar_elementos_en_label(label13); elementos.Add(textBox3.Text.ToUpper() + "|" + numericUpDown2.Value + "|" + numericUpDown3.Value); label17.Text = "Se ingresó el vehículo y el elemento"; countele = 1; } else { if (count == 1) { MessageBox.Show("Solo se ingresó el vehículo", "Ingreso de Datos", MessageBoxButtons.OK, MessageBoxIcon.Warning); } MessageBox.Show("Ya existe un elemento con ese nombre", "Ingreso de Elementos", MessageBoxButtons.OK, MessageBoxIcon.Warning); label17.Text = ""; } } } else { MessageBox.Show("Ya existe un vehículo con esa placa", "Ingreso de Datos", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { Principal principal = Application.OpenForms.OfType <Principal>().SingleOrDefault(); principal.placas = textBox1.Text.ToUpper(); placa_general = textBox1.Text.ToUpper(); Mostrar_datos_en_label(label11); string comentario = textBox4.Text; if (textBox4.Text == "") { comentario = "sin comentario"; } vehiculo = textBox1.Text.ToUpper() + "|" + comboBox1.Text.ToUpper() + "|" + textBox2.Text.ToUpper() + "|" + comboBox2.Text.ToUpper() + "|" + numericUpDown1.Value + "|0|" + comentario + "|"; count = 1; if (textBox3.Text != "") { int con = 0; foreach (string ss in elementos) { string[] ss2 = ss.Split('|'); if (textBox3.Text.ToUpper() == Convert.ToString(ss2[0])) { con++; } } if (con == 0) { Mostrar_elementos_en_label(label13); elementos.Add(textBox3.Text.ToUpper() + "|" + numericUpDown2.Value + "|" + numericUpDown3.Value); label17.Text = "Se ingresó el vehículo y el elemento"; countele = 1; } else { if (count == 1) { MessageBox.Show("Solo se ingresó el vehículo", "Ingreso de Datos", MessageBoxButtons.OK, MessageBoxIcon.Warning); } MessageBox.Show("Ya existe un elemento con ese nombre", "Ingreso de Elementos", MessageBoxButtons.OK, MessageBoxIcon.Warning); label17.Text = ""; } } } } else { MessageBox.Show("Debe ingresar todos los datos para el vehículo", "Ingreso de Datos", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }