Exemple #1
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.";
                }
            }
        }
    }
Exemple #2
0
    protected void btnUpdateDog_Click(object sender, EventArgs e)
    {
        SaveFormFields();
        StoreCommon();

        if (ValidDog(true))
        {
            MembershipUser userInfo = Membership.GetUser();
            Guid user_ID = (Guid)userInfo.ProviderUserKey;

            Guid dog_ID = new Guid(Dog_ID);
            Dogs dog = new Dogs(dog_ID);
            if (HasChanges(dog))
            {
                dog.Dog_KC_Name = txtKCName.Text;
                dog.Dog_Pet_Name = txtPetName.Text;
                dog.Dog_Breed_ID = Int32.Parse(lstDogBreeds.SelectedValue);
                dog.Dog_Gender_ID = Int32.Parse(lstGender.SelectedValue);
                if (dog.Reg_No != Reg_No && !string.IsNullOrEmpty(Reg_No))
                    dog.Reg_No = Reg_No;
                if (!string.IsNullOrEmpty(Date_Of_Birth))
                {
                    if (dog.Date_Of_Birth.ToString() != Date_Of_Birth && !string.IsNullOrEmpty(Date_Of_Birth))
                        dog.Date_Of_Birth = DateTime.Parse(Date_Of_Birth);
                    dog.Year_Of_Birth = short.Parse(DateTime.Parse(Date_Of_Birth).ToString("yyyy"));
                }

                bool valid = dog.Update_Dog(dog_ID, user_ID);

                if (valid)
                {
                    Dog_ID = dog_ID.ToString();
                    Common.Dog_ID = Dog_ID;
                    MessageLabel.Text = "Dog was updated successfully";
                    //ClearEntryFields();
                    if (!string.IsNullOrEmpty(btnReturn.PostBackUrl))
                        DivReturn.Visible = true;

                    divAddDog.Visible = false;
                    divNewDog.Visible = true;
                    divUpdateDog.Visible = true;
                    PopulateDogGridView(null, 1);
                    StoreCommon();
                }
                else
                {
                    divAddDog.Visible = false;
                    divNewDog.Visible = true;
                    divUpdateDog.Visible = true;
                }
            }
            else
            {
                MessageLabel.Text = "Update cancelled as no changes have been made.";
                divAddDog.Visible = false;
                divNewDog.Visible = true;
                divUpdateDog.Visible = true;
            }
        }
    }