public List<DogSires> GetDogSiresByDog_ID(Guid dog_ID) { List<DogSires> dogSireList = new List<DogSires>(); DogSiresBL dogSires = new DogSiresBL(); lnkDogSires = dogSires.GetDog_SireByDog_ID(dog_ID); if (lnkDogSires != null && lnkDogSires.Count > 0) { foreach (sss.lnkDog_SiresRow row in lnkDogSires) { DogSires dogSire = new DogSires(row.Dog_Sire_ID); dogSireList.Add(dogSire); } } return dogSireList; }
public List <DogSires> GetDogSiresBySire_ID(Guid sire_ID) { List <DogSires> dogSireList = new List <DogSires>(); DogSiresBL dogSires = new DogSiresBL(_connString); lnkDogSires = dogSires.GetDog_SiresBySire_ID(sire_ID); if (lnkDogSires != null && lnkDogSires.Rows.Count > 0) { foreach (DataRow row in lnkDogSires.Rows) { DogSires dogSire = new DogSires(_connString, Utils.DBNullToGuid(row["Dog_Sire_ID"])); dogSireList.Add(dogSire); } } return(dogSireList); }
private void PopulateDog() { Guid current_dog_ID = new Guid(Current_Dog_ID); Dogs dog = new Dogs(current_dog_ID); txtKCName.Text = dog.Dog_KC_Name; txtPetName.Text = dog.Dog_Pet_Name; lblNLWU.Text = string.Format("Tick this box if {0} is no longer with us.", dog.Dog_Pet_Name); if (dog.Dog_Breed_ID != null) { int dog_Breed_ID = Int32.Parse(dog.Dog_Breed_ID.ToString()); DogBreeds dogBreeds = new DogBreeds(dog_Breed_ID); txtDogBreed.Text = dogBreeds.Description; } if (dog.Dog_Gender_ID != null) { int dog_Gender_ID = Int32.Parse(dog.Dog_Gender_ID.ToString()); DogGender dogGender = new DogGender(dog_Gender_ID); txtDogGender.Text = dogGender.Description; } if (dog.Reg_No != null) { Reg_No = dog.Reg_No.ToString(); Common.Reg_No = Reg_No; txtRegNo.Text = Reg_No; } if (dog.Date_Of_Birth != null) { string format = "yyyy-MM-dd"; Date_Of_Birth = DateTime.Parse(dog.Date_Of_Birth.ToString()).ToString(format); Common.Date_Of_Birth = Date_Of_Birth; txtDogDOB.Text = Date_Of_Birth; } if (dog.Merit_Points != null) { Merit_Points = dog.Merit_Points.ToString(); Common.Merit_Points = Merit_Points; txtMeritPoints.Text = Merit_Points; } else { Merit_Points = "0"; Common.Merit_Points = Merit_Points; txtMeritPoints.Text = Merit_Points; } if (dog.NLWU != null) { NLWU = (bool)dog.NLWU; Common.NLWU = NLWU; chkNLWU.Checked = NLWU; } DogDams dogDams = new DogDams(); List<DogDams> lnkDogDams; lnkDogDams = dogDams.GetDogDamsByDog_ID(dog.Dog_ID); if (lnkDogDams.Count != 0) { Dam_ID = lnkDogDams[0].Dam_ID.ToString(); Common.Dam_ID = Dam_ID; PopulateDam(); } DogSires dogSires = new DogSires(); List<DogSires> lnkDogSires; lnkDogSires = dogSires.GetDogSiresByDog_ID(dog.Dog_ID); if (lnkDogSires.Count != 0) { Sire_ID = lnkDogSires[0].Sire_ID.ToString(); Common.Sire_ID = Sire_ID; PopulateSire(); } }
private bool HasSireChanges() { bool Changed = false; if (!string.IsNullOrEmpty(Current_Dog_ID)) { Guid dog_ID = new Guid(Current_Dog_ID); DogSires dogSire = new DogSires(); List<DogSires> lnkDogSires; lnkDogSires = dogSire.GetDogSiresByDog_ID(dog_ID); if (lnkDogSires.Count != 0) { string sire_ID; sire_ID = lnkDogSires[0].Sire_ID.ToString(); if (sire_ID != Sire_ID) Changed = true; } else if (!string.IsNullOrEmpty(Sire_ID)) { Changed = true; } } return Changed; }
protected void btnSaveDog_Click(object sender, EventArgs e) { SaveFormFields(); StoreCommon(); MembershipUser userInfo = Membership.GetUser(); Guid user_ID = (Guid)userInfo.ProviderUserKey; bool Changed = false; string petName=null; bool DogChanges = false; bool DogSuccess = false; bool OwnerChanges = false; bool OwnerSuccess = false; bool BreederChanges = false; bool BreederSuccess = false; if (!string.IsNullOrEmpty(Current_Dog_ID)) { Guid dog_ID = new Guid(Current_Dog_ID); Dogs dog = new Dogs(dog_ID); petName=dog.Dog_Pet_Name; if (ValidDog()) { if (HasDogChanges()) { DogChanges = true; if (dog.Merit_Points.ToString() != Merit_Points && !string.IsNullOrEmpty(Merit_Points)) dog.Merit_Points = short.Parse(Merit_Points); if (dog.NLWU == null && NLWU) dog.NLWU = NLWU; if (dog.NLWU != null) { if ((bool)dog.NLWU != NLWU) dog.NLWU = null; } DogSuccess = dog.Update_Dog(dog_ID, user_ID); if (!DogSuccess) MessageLabel.Text += " Update_Dog Failed!"; if (!string.IsNullOrEmpty(btnReturn.PostBackUrl)) DivReturn.Visible = true; } else DogSuccess = true; List<DogOwners> lnkDogOwners; DogOwners dogOwners = new DogOwners(); lnkDogOwners = dogOwners.GetDogOwnersByDog_ID(dog_ID); bool insertOK = true; bool deleteOK = true; switch (HasOwnerChanges()) { case Constants.DATA_NO_CHANGE: OwnerSuccess = true; break; case Constants.DATA_INSERTED: OwnerChanges = true; insertOK = InsertDogOwners(dog_ID, user_ID); if (insertOK) OwnerSuccess = true; else MessageLabel.Text = "Insert_Dog_Owners Failed"; break; case Constants.DATA_DELETED: OwnerChanges = true; deleteOK = DeleteDogOwners(dog_ID, user_ID); if (deleteOK) OwnerSuccess = true; else MessageLabel.Text = "Delete_Dog_Owners Failed"; break; case Constants.DATA_INSERTED_AND_DELETED: OwnerChanges = true; insertOK = InsertDogOwners(dog_ID, user_ID); deleteOK = DeleteDogOwners(dog_ID, user_ID); if (insertOK && deleteOK) OwnerSuccess = true; else { MessageLabel.Text = string.Empty; if (!insertOK) MessageLabel.Text = "Insert_Dog_Owners Failed"; if (!deleteOK) MessageLabel.Text += "Delete_Dog_Owners Failed"; } break; default: break; } List<DogBreeders> lnkDogBreeders; DogBreeders dogBreeders = new DogBreeders(); lnkDogBreeders = dogBreeders.GetDogBreedersByDog_ID(dog_ID); insertOK = true; deleteOK = true; switch (HasBreederChanges()) { case Constants.DATA_NO_CHANGE: BreederSuccess = true; break; case Constants.DATA_INSERTED: BreederChanges = true; insertOK = InsertDogBreeders(dog_ID, user_ID); if (insertOK) BreederSuccess = true; else MessageLabel.Text = "Insert_Dog_Breeders Failed"; break; case Constants.DATA_DELETED: BreederChanges = true; deleteOK = DeleteDogBreeders(dog_ID, user_ID); if (deleteOK) BreederSuccess = true; else MessageLabel.Text = "Delete_Dog_Breeders Failed"; break; case Constants.DATA_INSERTED_AND_DELETED: BreederChanges = true; insertOK = InsertDogBreeders(dog_ID, user_ID); deleteOK = DeleteDogBreeders(dog_ID, user_ID); if (insertOK && deleteOK) BreederSuccess = true; else { MessageLabel.Text = string.Empty; if (!insertOK) MessageLabel.Text = "Insert_Dog_Breeders Failed"; if (!deleteOK) MessageLabel.Text += "Delete_Dog_Breeders Failed"; } break; default: break; } if (HasDamChanges()) { DogDams dogDam = new DogDams(); List<DogDams> lnkDogDams; lnkDogDams = dogDam.GetDogDamsByDog_ID(dog_ID); if (lnkDogDams.Count == 0) { DogDams newDogDams = new DogDams(); newDogDams.Dog_ID = dog_ID; newDogDams.Dam_ID = new Guid(Dam_ID); Guid? dog_Dam_ID = newDogDams.Insert_Dog_Dams(user_ID); } else { Guid dog_Dam_ID = lnkDogDams[0].Dog_Dam_ID; DogDams newDogDams = new DogDams(dog_Dam_ID); newDogDams.Dam_ID = new Guid(Dam_ID); newDogDams.Update_Dog_Dams(dog_Dam_ID, user_ID); } Changed = true; } if (HasSireChanges()) { DogSires dogSire = new DogSires(); List<DogSires> lnkDogSires; lnkDogSires = dogSire.GetDogSiresByDog_ID(dog_ID); if (lnkDogSires.Count == 0) { DogSires newDogSires = new DogSires(); newDogSires.Dog_ID = dog_ID; newDogSires.Sire_ID = new Guid(Sire_ID); Guid? dog_Sire_ID = newDogSires.Insert_Dog_Sire(user_ID); } else { Guid dog_Sire_ID = lnkDogSires[0].Dog_Sire_ID; DogSires newDogSires = new DogSires(dog_Sire_ID); newDogSires.Sire_ID = new Guid(Sire_ID); newDogSires.Update_Dog_Sire(dog_Sire_ID, user_ID); } Changed = true; } if (OwnerChanges || BreederChanges || DogChanges) Changed = true; if (OwnerChanges && !OwnerSuccess) MessageLabel.Text += " Error with Owner Changes!"; if (BreederChanges && !BreederSuccess) MessageLabel.Text += " Error with Breeder Changes!"; if (DogChanges && !DogSuccess) MessageLabel.Text += " Error with Dog Changes!"; if (Changed) { if (OwnerSuccess && BreederSuccess && DogSuccess) { MessageLabel.Text = string.Format("{0} was updated successfully.", petName); PopulateDog(); } else { MessageLabel.Text = string.Format("{0}{1}", "Problem!", MessageLabel.Text); } } else { MessageLabel.Text = "Update cancelled as no changes have been made."; } } } }