void CarregarDados() { if (File.Exists("Pistolas.txt")) { Stream stream = File.Open("Pistolas.txt", FileMode.Open); StreamReader leitor = new StreamReader(stream); string linha = leitor.ReadLine(); while (linha != null) { string[] dados = linha.Split('|'); string n = dados[0]; string t = dados[1]; float c = float.Parse(dados[2]); int q = Int32.Parse(dados[3]); //int s = Int32.Parse(dados[4]); bool ts = false; //if(s == 1) //{ // ts = true; //} Pistola p = new Pistola(n, t, c, q, ts); pistolas.Add(p); linha = leitor.ReadLine(); } leitor.Close(); stream.Close(); } }
//void CarregarComboBox() //{ // foreach (Pistola p in pistolas) // { // cbx.Items.Add(p); // } private void btnCadastrar_Click(object sender, EventArgs e) { if (cbxTipoArma.Text == "Pistola") { ObterDados(); Pistola p = new Pistola(nome, tipo, calibre, qtd, silenciador); pistolas.Add(p); LimparDados(); } //if (clicou) //{ //var pis = pistolas.Single(p => p.Nome == pistolaAnterior); //var pistola = pistolas.Any(p => p.Nome == nome); //if (pistola == true) //{ // MessageBox.Show("Pistola já cadastrada!"); //} // pis.Nome = nome; // pis.Tipo = tipo; // pis.Calibre = calibre; // pis.Qtd = qtd; // pis.Silenciador = silenciador; // MessageBox.Show("Pistola editada com sucesso!"); // clicou = false; // } //else //{ // var pis = pistolas.Any(p => p.Nome == nome); // if (pis == false) // { // Pistola pistola = new Pistola(nome,tipo,calibre,qtd,silenciador); // pistolas.Add(pistola); // MessageBox.Show("Pistola cadastrada com sucesso!"); // } //} }