private void LerRegras() { int op; Console.WriteLine("Insira o estado atual: "); do { var regra = new Regra(); Console.WriteLine("Escreva o estado inicial da regra:"); var estado = Console.ReadLine(); regra.EstadoAtual = Estados.FirstOrDefault(e => e.Nome == estado); Console.WriteLine("Escreva o identificador da regra:"); regra.Identificador = Convert.ToChar(Console.ReadLine() ?? throw new InvalidOperationException()); Console.WriteLine("Escreva o proximo estado da regra:"); estado = Console.ReadLine(); regra.ProximoEstado = Estados.FirstOrDefault(e => e.Nome == estado); Regras.Add(regra); if (Regras.Any(r => r == regra)) { Console.WriteLine("A regra ja existe"); } Console.WriteLine("Deseja realizar novamente? 1- Sim 0- Não"); op = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("\n\n" + MostrarRegras()); } while (op == 1); }
private void txtpaicodi_Leave(object sender, EventArgs e) { if (String.IsNullOrEmpty(txtmuncodi.Text)) { return; } var dr = MunicipioDao.GetById(int.Parse(txtmuncodi.Text)); if (dr.Read()) { txtmuncodi.Text = dr["MUNCODI"].ToString(); txtmunnome.Text = dr["MUNNOME"].ToString(); cblest.SelectedItem = Estados.FirstOrDefault(q => q.Split('-')[0].Trim() == dr["ESTCODI"].ToString()); edicao = true; } else { edicao = false; if ((MessageBox.Show("Registro não encontrado \n deseja cadastra-lo?", "Cadastro", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)) { limpar(); } else { txtmunnome.Text = ""; txtmunnome.Focus(); } } }
private void LerEstados() { int op; Console.WriteLine("Insira o(s) estado(s): "); do { var estado = new Estado(); Console.WriteLine("Escreva o nome do estado:"); estado.Nome = Console.ReadLine(); Console.WriteLine("Esse estado é inicial? 1- Sim 0- Não"); estado.Inicial = Convert.ToBoolean(int.Parse(Console.ReadLine() ?? throw new InvalidOperationException())); Console.WriteLine("Esse estado é final? 1- Sim 0- Não"); estado.Final = Convert.ToBoolean(int.Parse(Console.ReadLine() ?? throw new InvalidOperationException())); Estados.Add(estado); var e = Estados.FirstOrDefault(e => e.Nome == estado.Nome); if (e != default) { Console.WriteLine($"O estado {e.Nome} ja existe"); } Console.WriteLine("Deseja continuar inserindo? 1- Sim 0- Não"); op = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("\n\n" + MostrarEstados()); } while (op == 1); }
private void dvgmunicipio_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } txtmuncodi.Text = dvgmunicipio.Rows[e.RowIndex].Cells["MUNCODI"].Value.ToString(); txtpaicodi_Leave(null, null); tbcmunicipio.SelectedIndex = 1; txtmunnome.Focus(); edicao = true; cblest.SelectedItem = Estados.FirstOrDefault(q => q.Split('-')[0].Trim() == dvgmunicipio.Rows[e.RowIndex].Cells["ESTCODI"].Value.ToString()); }