Exemple #1
0
 private void PopulateBreederList()
 {
     bool foundBreeder = false;
     Guid dog_ID = new Guid(Current_Dog_ID);
     List<DogBreeders> lnkDogBreeders;
     DogBreeders dogBreeders = new DogBreeders();
     lnkDogBreeders = dogBreeders.GetDogBreedersByDog_ID(dog_ID);
     foreach(DogBreeders row in lnkDogBreeders)
     {
         AddBreederToList(row.Breeder_ID.ToString());
         foundBreeder = true;
     }
     if (foundBreeder)
         divBreederList.Visible = true;
 }
Exemple #2
0
    private bool InsertDogBreeders(Guid dog_ID, Guid user_ID)
    {
        bool insertOK = true;
        for (int i = 0; i < Common.DogBreederList.Count; i++)
        {
            bool breederFound = false;
            List<DogBreeders> lnkDogBreeders;
            DogBreeders dogBreeders = new DogBreeders();
            lnkDogBreeders = dogBreeders.GetDogBreedersByDog_ID(dog_ID);
            foreach (DogBreeders row in lnkDogBreeders)
            {
                if (Common.DogBreederList[i].Person_ID == row.Breeder_ID)
                {
                    breederFound = true;
                }
            }
            if (!breederFound)
            {

                DogBreeders dogBreeder = new DogBreeders();
                dogBreeder.Dog_ID = dog_ID;
                dogBreeder.Breeder_ID = Common.DogBreederList[i].Person_ID;

                Guid? dog_Breeder_ID = dogBreeder.Insert_Dog_Breeder(user_ID);

                if (dog_Breeder_ID == null)
                    insertOK = false;

            }
        }
        return insertOK;
    }
Exemple #3
0
 private bool DeleteDogBreeders(Guid dog_ID, Guid user_ID)
 {
     bool deletedOK = false;
     List<DogBreeders> lnkDogBreeders;
     DogBreeders dogBreeders = new DogBreeders();
     lnkDogBreeders = dogBreeders.GetDogBreedersByDog_ID(dog_ID);
     foreach (DogBreeders row in lnkDogBreeders)
     {
         bool breederFound = false;
         for (int i = 0; i < Common.DogBreederList.Count; i++)
         {
             if (Common.DogBreederList[i].Person_ID == row.Breeder_ID)
             {
                 breederFound = true;
             }
         }
         if (!breederFound)
         {
             DogBreeders dogBreeder = new DogBreeders(row.Dog_Breeder_ID);
             dogBreeder.DeleteDogBreeder = true;
             deletedOK = dogBreeder.Update_Dog_Breeder(row.Dog_Breeder_ID, user_ID);
         }
     }
     return deletedOK;
 }
Exemple #4
0
    private short HasBreederChanges()
    {
        bool Changed = false;
        short del = Constants.DATA_NO_CHANGE;
        short ins = Constants.DATA_NO_CHANGE;
        List<DogBreeders> lnkDogBreeders;
        DogBreeders dogBreeders = new DogBreeders();
        Guid dog_ID = new Guid(Current_Dog_ID);
        lnkDogBreeders = dogBreeders.GetDogBreedersByDog_ID(dog_ID);
        foreach (DogBreeders dogBreedersRow in lnkDogBreeders)
        {
            bool foundBreeder = false;
            if (Common.DogBreederList != null && Common.DogBreederList.Count != 0)
            {
                for (int i = 0; i < Common.DogBreederList.Count; i++)
                {
                    if (Common.DogBreederList[i].Person_ID == dogBreedersRow.Breeder_ID)
                        //Dog in table still exists in list
                        foundBreeder = true;
                }
            }
            if (!foundBreeder)
                //Dog in table no longer exists in list (deleted)
                Changed = true;
        }
        if (Changed)
            del = Constants.DATA_DELETED;

        Changed = false;
        if (Common.DogBreederList != null && Common.DogBreederList.Count != 0)
        {
            for (int i = 0; i < Common.DogBreederList.Count; i++)
            {
                bool foundBreeder = false;
                foreach (DogBreeders dogBreedersRow in lnkDogBreeders)
                {
                    if (Common.DogBreederList[i].Person_ID == dogBreedersRow.Breeder_ID)
                        //Dog in List already exists in table
                        foundBreeder = true;
                }
                if (!foundBreeder)
                    //Dog in list does not exist in table (inserted)
                    Changed = true;
            }
        }
        else
        {
            if (lnkDogBreeders.Count > 0)
                Changed = true;
        }
        if (Changed)
            ins = Constants.DATA_INSERTED;

        return del += ins;
    }
Exemple #5
0
    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.";
                }
            }
        }
    }