예제 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //Insert
     if (DataItem is GridInsertionObject)
     {
         address           = new CustomerContactAddress();
         btnInsert.Visible = true;
     }
     //Update
     else if (DataItem != null && DataItem.GetType() == typeof(CustomerContactAddress))
     {
         //Cast the DataItem as a Customer Contact and store it in contact
         address                      = (CustomerContactAddress)DataItem;
         btnUpdate.Visible            = true;
         rcbAddressType.SelectedValue = address.Type;
     }
 }
예제 #2
0
        private void RemoveAddress(CustomerContactAddress address)
        {
            //Grabs all the agreements that this address is assigned to as a technical contact
            var tContacts = siftaDB.Agreements.Where(p => p.CustomerTechnicalContact == address.CustomerContactAddressID);
            //Grabs all the agreements that this address is assigned to as a billing contact
            var bContacts = siftaDB.Agreements.Where(p => p.CustomerBillingContact == address.CustomerContactAddressID);

            //Removes them as a technical contact
            foreach (var c in tContacts)
            {
                c.CustomerTechnicalContact = null;
            }
            //Removes them as a billing contact
            foreach (var c in bContacts)
            {
                c.CustomerBillingContact = null;
            }
            //Delete the Address
            siftaDB.CustomerContactAddresses.DeleteOnSubmit(address);
        }
예제 #3
0
        protected void rgContacts_InsertCommand(object sender, GridCommandEventArgs e)
        {
            //grab the User control
            var uc = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);

            switch (e.Item.OwnerTableView.Name)
            {
            case "Contact":
                //Grab the controls from the user control
                #region Grab Contact Controls
                var rcbSalutation    = uc.FindControl("rcbSalutation") as RadComboBox;
                var rtbFirstName     = uc.FindControl("rtbFirstName") as RadTextBox;
                var rtbMiddleInitial = uc.FindControl("rtbMiddleInitial") as RadTextBox;
                var rtbLastName      = uc.FindControl("rtbLastName") as RadTextBox;
                var rtbTitle         = uc.FindControl("rtbTitle") as RadTextBox;
                var rtbPhoneWork     = uc.FindControl("rtbPhoneWork") as RadTextBox;
                var rtbPhoneMobile   = uc.FindControl("rtbPhoneMobile") as RadTextBox;
                var rtbPhoneFax      = uc.FindControl("rtbPhoneFax") as RadTextBox;
                var rtbEmail         = uc.FindControl("rtbEmail") as RadTextBox;
                var rtbRemarks       = uc.FindControl("rtbRemarks") as RadTextBox;
                #endregion
                //Create New Contact
                var customerContact = new CustomerContact()
                {
                    Salutation   = rcbSalutation.SelectedValue,
                    FirstName    = rtbFirstName.Text,
                    MiddleName   = rtbMiddleInitial.Text,
                    LastName     = rtbLastName.Text,
                    Title        = rtbTitle.Text,
                    PhoneWork    = rtbPhoneWork.Text.ToPhoneFormat(),
                    PhoneMobile  = rtbPhoneMobile.Text.ToPhoneFormat(),
                    PhoneFax     = rtbPhoneFax.Text.ToPhoneFormat(),
                    Email        = rtbEmail.Text,
                    Remarks      = rtbRemarks.Text,
                    CreatedBy    = user.ID,
                    ModifiedBy   = user.ID,
                    CreatedDate  = DateTime.Now,
                    ModifiedDate = DateTime.Now
                };
                //Add Contact to the customer
                customer.CustomerContacts.Add(customerContact);
                siftaDB.SubmitChanges();
                Session["NewContactID"] = customerContact.CustomerContactID;
                break;

            case "Address":
                //Grab the contact the address is being added to
                var contact = (GridDataItem)e.Item.OwnerTableView.ParentItem;
                //Grab the controls from the user control
                #region Grab Address Controls
                var rcbType      = uc.FindControl("rcbAddressType") as RadComboBox;
                var rtbStreetOne = uc.FindControl("rtbStreetOne") as RadTextBox;
                var rtbStreetTwo = uc.FindControl("rtbStreetTwo") as RadTextBox;
                var rtbCity      = uc.FindControl("rtbCity") as RadTextBox;
                var rtbState     = uc.FindControl("rtbState") as RadTextBox;
                var rtbZipCode   = uc.FindControl("rtbZipCode") as RadTextBox;
                #endregion
                //Create New Address with the values from the user control
                var address = new CustomerContactAddress()
                {
                    //Grabs the customer ID from the address tables parent
                    CustomerContactID = Convert.ToInt32(contact.OwnerTableView.DataKeyValues[contact.ItemIndex]["CustomerContactID"]),
                    Type      = rcbType.SelectedValue,
                    StreetOne = rtbStreetOne.Text,
                    StreetTwo = rtbStreetTwo.Text,
                    City      = rtbCity.Text,
                    State     = rtbState.Text,
                    ZipCode   = rtbZipCode.Text
                };
                //Add new address the Customer Contact Address table
                siftaDB.CustomerContactAddresses.InsertOnSubmit(address);
                //Submit Changes to the Database
                siftaDB.SubmitChanges();
                break;
            }
        }