private void FrmPets_Load(object sender, EventArgs e) { edPET_RACA.Properties.DataSource = Racas.Get(); edPET_RACA.Properties.ValueMember = "PET_RACA_ID"; edPET_RACA.Properties.DisplayMember = "PET_RACA_NOME"; if (DonoTemp > 0) { edCLI_ID.EditValue = DonoTemp; edCLI_ID.ReadOnly = true; } if (TIPO == "A" || PETID != 0) { pet = Pets.Get(F.toInt(PETID)); edCLI_ID.EditValue = F.toInt(pet.CLI_ID); edPET_COR.EditValue = F.toString(pet.PET_COR); edPET_NAS.EditValue = Convert.ToDateTime(pet.PET_NAS); edPET_NOME.EditValue = F.toString(F.toString(pet.PET_NOME)); edPET_OBS.EditValue = F.toString(pet.PET_OBS); edPET_RACA.EditValue = F.toInt(pet.PET_RACA); edPET_IMAGEM.EditValue = F.toString(pet.PET_IMG); picPET_IMG.Image = pet.PET_IMAGEM; } }
// Method: Main // Purpose: // Restrictions: None static void Main(string[] args) { Pet thisPet = null; Dog dog = null; Cat cat = null; IDog iDog = null; ICat iCat = null; Pets pets = new Pets(); Random rand = new Random(); for (int i = 0; i < 50; i++) { //1 in 10 chance of adding an animal if (rand.Next(1, 11) == 1) { //50% chance of adding a dog if (rand.Next(0, 2) == 0) { Console.WriteLine("You bought a dog!"); Console.WriteLine("dog's name => "); string name = Console.ReadLine(); Console.WriteLine("license => "); string license = Console.ReadLine(); Console.WriteLine("age => "); string age = Console.ReadLine(); int nAge = Int32.Parse(age); dog = new Dog(license, name, nAge); } else { //else add a cat Console.WriteLine("You bought a cat!"); Console.WriteLine("cat's name => "); string name = Console.ReadLine(); Console.WriteLine("age => "); string age = Console.ReadLine(); cat = new Cat(); } } else { int random = rand.Next(pets.Count); try { thisPet = pets.petList[random]; } catch { continue; } //iDog = thisPet.GetType(); } } }
static void Main(string[] args) { Pet thisPet = null; Dog dog = null; Cat cat = null; IDog iDog = null; ICat iCat = null; Pets pets = new Pets(); Random rand = new Random(); tryAgain: for (int i = 0; i < 50; i++) { if (rand.Next(0, 11) == 1) { if (rand.Next(0, 2) == 0) { int age = 0; bool valid = false; Console.WriteLine("you bought a Dog!"); Console.WriteLine("What do you want your dog to be named?"); string Dname = Console.ReadLine(); Console.WriteLine("How old is " + Dname + "?"); do { string temp = Console.ReadLine(); try { age = Convert.ToInt32(temp); valid = true; } catch { Console.WriteLine("Please enter a number."); } } while (valid == false); valid = false; Console.WriteLine("what is " + Dname + "'s license number?"); string Dlicesnse = Console.ReadLine(); //dog = (Dog)thisPet; thisPet = new Dog(Dname, Dlicesnse, age); } else { bool valid = false; Console.WriteLine("you bought a Cat!"); Console.WriteLine("What do you want your Cat to be named?"); string Cname = Console.ReadLine(); Console.WriteLine("How old is " + Cname + "?"); do { try { int age = Convert.ToInt32(Console.ReadLine()); valid = true; } catch { Console.WriteLine("Please enter a number."); } } while (valid == false); valid = false; Console.WriteLine("what is " + Cname + "'s license number?"); string Clicense = Console.ReadLine(); thisPet = new Cat(); } } else { thisPet = pets[rand.Next(0, pets.count)]; if (thisPet == null) { goto tryAgain; } } if (thisPet.GetType() == typeof(Cat)) { iCat = (ICat)thisPet; int rando = rand.Next(0, 4); switch (rando) { case 0: iCat.Eat(); break; case 1: iCat.Play(); break; case 2: iCat.Purr(); break; case 3: iCat.Scratch(); break; default: Console.WriteLine("this fell through for some reason"); break; } } else { //thisPet = (Pet)iDog; int rando = rand.Next(0, 5); iDog = (IDog)thisPet; switch (rando) { case 0: iDog.Eat(); break; case 1: iDog.Play(); break; case 2: iDog.Bark(); break; case 3: iDog.NeedWalk(); break; case 4: iDog.GotoVet(); break; default: Console.WriteLine("this fell through for some reason"); break; } } } }
//Method: Main //Purpose: Getting pets to the list and then calling the activites //Output: Pet names and activities static void Main(string[] args) { Pet thisPet = null; Dog dog = null; Cat cat = null; IDog iDog = null; ICat iCat = null; Pets pets = new Pets(); Random rand = new Random(); int i = 0; for (i = 0; i < 50; i++) { start: // 1 in 10 chance of adding an animal if (rand.Next(1, 11) == 1) { // 50% chance of adding a dog if (rand.Next(0, 2) == 0) { Console.WriteLine("You bought a dog!"); Console.WriteLine("What do you want to name your dog?"); thisPet.Name = Console.ReadLine(); Console.WriteLine("How old do you want your dog to be?"); string a = Console.ReadLine(); thisPet.age = Convert.ToInt32(a); Console.WriteLine("What is your dog's license number?"); dog.license = Console.ReadLine(); thisPet = new Dog(dog.license, thisPet.Name, thisPet.age); } else { // else add a cat Console.WriteLine("You bought a cat!"); Console.WriteLine("What do you want to name your cat?"); thisPet.Name = Console.ReadLine(); Console.WriteLine("How old do you want your cat to be?"); string a = Console.ReadLine(); thisPet.age = Convert.ToInt32(a); thisPet = new Cat(thisPet.Name, thisPet.age); } } else { int num = rand.Next(0, pets.Count); thisPet = Pets.petList(num); //I didn't know how to iterate throuh a list if (thisPet == null) { goto start; } else { if (thisPet.GetType() = (Pet)iDog) // I didn't know how to use .GetType { thisPet = (Pet)iDog; //picking an activity int r = rand.Next(0, 4); if (r == 0) { dog.Eat(); } else if (r == 1) { dog.Play(); } else if (r == 2) { dog.Bark(); } else if (r == 3) { dog.NeedWalk(); } else { dog.GotoVet(); } } else { thisPet = (Pet)iCat; //picking an activity int r = rand.Next(0, 4); if (r == 0) { cat.Eat(); } else if (r == 1) { cat.Play(); } else if (r == 2) { cat.Purr(); } else if (r == 3) { cat.Scratch(); } else { cat.GotoVet(); } } } } } }
private void btnAdd_Click(object sender, EventArgs e) { if (F.toString(edPET_NOME.EditValue) == "") { F.Aviso("Informe o NOME do Pet"); edPET_NOME.Focus(); return; } if (F.toString(edPET_COR.EditValue) == "") { F.Aviso("Informe a COR do Pet"); edPET_COR.Focus(); return; } if (F.toString(edCLI_ID.EditValue) == "") { F.Aviso("Informe o DONO do Pet"); edCLI_ID.Focus(); return; } if (F.toString(edPET_NAS.EditValue) == "") { F.Aviso("Informe o NASCIMENTO do Pet"); edPET_NAS.Focus(); return; } if (F.toString(edPET_RACA.EditValue) == "") { F.Aviso("Informe a RAÇA do Pet"); edPET_RACA.Focus(); return; } pet = new Pets { PET_NOME = F.toString(edPET_NOME.EditValue), PET_RACA = F.toInt(edPET_RACA.EditValue), PET_OBS = F.toString(edPET_OBS.Text), PET_NAS = F.toString(edPET_NAS.EditValue), PET_COR = F.toString(edPET_COR.EditValue), CLI_ID = F.toInt(edCLI_ID.EditValue), PET_IMG = F.toString(edPET_IMAGEM.EditValue) }; bool result = false; string msg = ""; switch (TIPO) { case "C": if (Pets.Insert(pet)) { NewPet = pet; result = true; msg = "Pet Cadastrado com Sucesso!"; } break; case "A": pet.PET_ID = PETID; if (Pets.Update(pet)) { NewPet = pet; result = true; msg = "Pet Alterado com Sucesso!"; } break; case "M": NewPet = pet; result = true; break; } if (msg != "") { F.Aviso(result ? msg : "Erro ao completar ação!"); } if (result) { this.DialogResult = DialogResult.OK; this.Close(); } }
static void Main(string[] args) { // Create reference variables for pets and interfaces Pet thisPet = null; Dog dog = null; Cat cat = null; IDog iDog = null; ICat iCat = null; Pets pets = new Pets(); Random rand = new Random(); for (int i = 0; i < 50; i++) { start: // 1 in 10 chance of adding an animal if (rand.Next(1, 11) == 1) { // 50% chance of adding a dog if (rand.Next(0, 2) == 0) { // Upon winning the dog, initialize variables and ask for each of their values Console.WriteLine("Congratulations, you won a dog!"); string license = null; string name = null; int age = 0; Console.Write("What is its age? "); do { try { age = Int16.Parse(Console.ReadLine()); } catch { Console.Write("Please enter an integer: "); } } while (age <= 0); Console.WriteLine("What will you call it? "); try { name = Console.ReadLine(); } catch { } Console.WriteLine("Give it a license #: "); try { license = Console.ReadLine(); } catch { } // Create new dog passing values to its constructor, and add it to petList pets.Add(dog = new Dog(license, name, age)); Console.WriteLine("License: #" + license + ", Name: " + name + ", Age: " + age); } else { // else add a cat // Upon winning the dog, initialize variables and ask for each of their values Console.WriteLine("Congratulations, you won a cat!"); string name = null; int age = 0; Console.Write("What is its age? "); do { try { age = Int16.Parse(Console.ReadLine()); } catch { Console.Write("\r"); Console.Write("Please enter an integer: "); } } while (age <= 0); Console.WriteLine("What will you call it? "); try { name = Console.ReadLine(); } catch { } // Create new cat passing values to its constructor, and add it to petList pets.Add(cat = new Cat(name, age)); Console.WriteLine("Name: " + name + ", Age: " + age); } } else { try { // Get a random pet from petList and make it do something if (thisPet.GetType() == typeof(Cat)) { iCat = (ICat)thisPet; // make the cat do something random int nAction = rand.Next(0, 4); switch (nAction) { case 0: iCat.Eat(); break; case 1: iCat.Scratch(); break; case 2: iCat.Play(); break; case 3: iCat.Purr(); break; case 4: iDog.GotoVet(); break; } } // Get a random pet from petList and make it do something else if (thisPet.GetType() == typeof(Dog)) { iDog = (IDog)thisPet; // make the cat do something random int nAction = rand.Next(0, 4); switch (nAction) { case 0: iDog.Eat(); break; case 1: iDog.NeedWalk(); break; case 2: iCat.Play(); break; case 3: iDog.Bark(); break; case 4: iDog.GotoVet(); break; } } } catch { goto start; } } Console.WriteLine(i); } }
//Method: Main //Purpose: Create instances of pets static void Main(string[] args) { string name; int age; string license; Pet thisPet = null; Dog dog = null; Cat cat = null; IDog iDog = null; ICat iCat = null; Pets pets = new Pets(); Random rand = new Random(); for (int i = 0; i < 50; i++) { if (rand.Next(1, 11) == 1) { if (rand.Next(0, 2) == 0) { Console.WriteLine("You bought a dog!"); Console.Write("Dog's Name => "); name = Console.ReadLine(); Console.Write("Age => "); while (true) { try { age = int.Parse(Console.ReadLine()); break; } catch { Console.Write("Age => "); } } Console.Write("License => "); license = Console.ReadLine(); thisPet = new Dog(license, name, age); } else { Console.WriteLine("You bought a cat!"); Console.Write("Cat's Name => "); name = Console.ReadLine(); Console.Write("Age => "); while (true) { try { age = int.Parse(Console.ReadLine()); break; } catch { Console.Write("Age => "); } } cat = new Cat(); thisPet = cat; thisPet.Name = name; thisPet.age = age; } } else { thisPet = pets[rand.Next(0, pets.Count)]; } if (thisPet != null) { if (thisPet.GetType() == typeof(Cat)) { iCat = (ICat)thisPet; int choice = rand.Next(0, 4); if (choice == 0) { iCat.Eat(); } else if (choice == 1) { iCat.Play(); } else if (choice == 2) { iCat.Scratch(); } else { iCat.Purr(); } } else { iDog = (IDog)thisPet; int choice = rand.Next(0, 5); if (choice == 0) { iDog.Eat(); } else if (choice == 1) { iDog.Play(); } else if (choice == 2) { iDog.Bark(); } else if (choice == 3) { iDog.NeedWalk(); } else { iDog.GotoVet(); } } } } }
private void simpleButton1_Click(object sender, EventArgs e) { if (cliAltera != null) { Clientes clialt = new Clientes { CLI_ID = cliAltera.CLI_ID, CLI_RAZAO = F.toString(edCLI_RAZAO.EditValue), CLI_FANTASIA = F.toString(edCLI_FANTASIA.EditValue), CLI_CNPJ = F.toString(edCLI_CNPJ.EditValue), CLI_EMAIL = F.toString(edCLI_EMAIL.EditValue), CLI_DDDCEL = F.toString(edDDDCel.EditValue), CLI_CEL = F.toString(edCLI_CEL.EditValue), CLI_DDDTEL = F.toString(edDDDTel.EditValue), CLI_TEL = F.toString(edCLI_TEL.EditValue), CLI_PESTIPO = F.toString(rgCLI_PESTIPO.EditValue), CLI_CEP = F.toString(edCEP.EditValue), CLI_RUA = F.toString(edRua.EditValue), CLI_BAIRRO = F.toString(edBairro.EditValue), CLI_NUMERO = F.toString(edNumero.EditValue), CLI_NASC = F.toString(edCLI_NASC.EditValue), CID_ID = F.toInt(edCidade.EditValue), CLI_INSCRICAO = F.toString(edCLI_INSCRICAO.EditValue), CLI_IMG = F.toString(edCLI_IMG.EditValue) }; if (Clientes.Update(clialt)) { F.Aviso("Cliente Atualizado com sucesso!"); DialogResult = DialogResult.OK; Close(); return; } } if (F.toString(rgCLI_PESTIPO.EditValue) == "FIS") { if (F.toString(edCLI_RAZAO) == "") { F.Aviso("Por Favor, Informe o Nome do cliente."); edCLI_RAZAO.Focus(); return; } if (F.toString(edCLI_TEL.EditValue) == "" && F.toString(edCLI_CEL.EditValue) == "" && F.toString(edCLI_EMAIL.EditValue) == "") { F.Aviso("Por favor, informa ao menos uma forma de contato."); return; } if (F.toString(edDDDCel.EditValue) == "" && F.toString(edCLI_CEL.EditValue) != "") { F.Aviso("Por Favor, Informe o DDD do celular."); edDDDCel.Focus(); return; } if (F.toString(edDDDTel.EditValue) == "" && F.toString(edCLI_TEL.EditValue) != "") { F.Aviso("Por Favor, Informe o DDD do telefone."); edDDDTel.Focus(); return; } } if (F.toString(rgCLI_PESTIPO.EditValue) == "JUR") { if (F.toString(edCLI_RAZAO) == "") { F.Aviso("Por favor, Informe a Razão Social do cliente"); edCLI_RAZAO.Focus(); return; } if (F.toString(edCLI_FANTASIA.EditValue) == "") { F.Aviso("Por favor, informe o nome fantasia do cliente"); edCLI_FANTASIA.Focus(); return; } if (F.toString(edCLI_INSCRICAO) == "") { F.Aviso("Por Favor, informe a Inscrição Estadual do cliente"); edCLI_INSCRICAO.Focus(); return; } if (F.toString(edCLI_TEL.EditValue) == "" && F.toString(edCLI_CEL.EditValue) == "" && F.toString(edCLI_EMAIL.EditValue) == "") { F.Aviso("Por favor, informa ao menos uma forma de contato."); return; } if (F.toString(edDDDCel.EditValue) == "" && F.toString(edCLI_CEL.EditValue) != "") { F.Aviso("Por Favor, Informe o DDD do celular."); edDDDCel.Focus(); } if (F.toString(edDDDTel.EditValue) == "" && F.toString(edCLI_TEL.EditValue) != "") { F.Aviso("Por Favor, Informe o DDD do telefone."); edDDDTel.Focus(); return; } } if (F.toString(rgCLI_PESTIPO.EditValue) == "FOR") { if (F.toString(edCLI_RAZAO) == "") { F.Aviso("Por favor, Informe a Razão Social do Fornecedor"); edCLI_RAZAO.Focus(); return; } if (F.toString(edCLI_FANTASIA.EditValue) == "") { F.Aviso("Por favor, informe o nome fantasia do Fornecedor"); edCLI_FANTASIA.Focus(); return; } if (F.toString(edCLI_INSCRICAO) == "") { F.Aviso("Por Favor, informe a Inscrição Estadual do Fornecedor"); edCLI_INSCRICAO.Focus(); return; } if (F.toString(edCLI_TEL.EditValue) == "" && F.toString(edCLI_CEL.EditValue) == "" && F.toString(edCLI_EMAIL.EditValue) == "") { F.Aviso("Por favor, informa ao menos uma forma de contato."); return; } if (F.toString(edDDDCel.EditValue) == "" && F.toString(edCLI_CEL.EditValue) != "") { F.Aviso("Por Favor, Informe o DDD do celular."); edDDDCel.Focus(); return; } if (F.toString(edDDDTel.EditValue) == "" && F.toString(edCLI_TEL.EditValue) != "") { F.Aviso("Por Favor, Informe o DDD do telefone."); edDDDTel.Focus(); return; } } Clientes cliente = new Clientes { CLI_RAZAO = F.toString(edCLI_RAZAO.EditValue), CLI_FANTASIA = F.toString(edCLI_FANTASIA.EditValue), CLI_CNPJ = F.toString(edCLI_CNPJ.EditValue), CLI_EMAIL = F.toString(edCLI_EMAIL.EditValue), CLI_DDDCEL = F.toString(edDDDCel.EditValue), CLI_CEL = F.toString(edCLI_CEL.EditValue), CLI_DDDTEL = F.toString(edDDDTel.EditValue), CLI_TEL = F.toString(edCLI_TEL.EditValue), CLI_PESTIPO = F.toString(rgCLI_PESTIPO.EditValue), CLI_CEP = F.toString(edCEP.EditValue), CLI_RUA = F.toString(edRua.EditValue), CLI_BAIRRO = F.toString(edBairro.EditValue), CLI_NUMERO = F.toString(edNumero.EditValue), CLI_NASC = F.toString(edCLI_NASC.EditValue), CID_ID = F.toInt(edCidade.EditValue), CLI_INSCRICAO = F.toString(edCLI_INSCRICAO.EditValue), CLI_IMG = F.toString(edCLI_IMG.EditValue) }; if (Clientes.Insert(cliente)) { if (groupControl3.Enabled = F.toString(rgCLI_PESTIPO.EditValue) != "FOR") { foreach (Pets pet in pets) { Pets petAdd = new Pets { PET_COR = pet.PET_COR, PET_RACA = pet.PET_RACA, PET_OBS = pet.PET_OBS, PET_NOME = pet.PET_NOME, PET_NAS = pet.PET_NAS, PET_IMG = pet.PET_IMG, CLI_ID = cliente.CLI_ID, }; Pets.Insert(petAdd); } } F.Aviso("Cliente Cadastrado com Sucesso!"); DialogResult = DialogResult.OK; Close(); } else { F.Aviso("Erro ao Cadastrar Cliente"); } }