protected void lnkRemove_Click(object sender, EventArgs e)
        {
            string id = ((LinkButton)sender).CommandArgument;
            CRM_CalendarPerHead calPerHead = db.CRM_CalendarPerHeads.Single(s => s.ID.ToString() == id);

            db.CRM_CalendarPerHeads.DeleteOnSubmit(calPerHead);
            db.SubmitChanges();

            ReloadCalPerHead();
        }
        protected void rptCustomersPerHead_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            CRM_CalendarPerHead calPerHead = (CRM_CalendarPerHead)e.Item.DataItem;

            Label      lblName          = (Label)e.Item.FindControl("lblName");
            TextBox    txtPrice         = (TextBox)e.Item.FindControl("txtPrice");
            TextBox    txtPlusChildren  = (TextBox)e.Item.FindControl("txtPlusChildren");
            TextBox    txtChildrenPrice = (TextBox)e.Item.FindControl("txtChildrenPrice");
            LinkButton lnkRemove        = (LinkButton)e.Item.FindControl("lnkRemove");

            lblName.Text              = ContactManager.GetIContactByReference(calPerHead.TargetReference).Fullname;
            txtPrice.Text             = calPerHead.Price.ToString("N2");
            txtPlusChildren.Text      = calPerHead.PlusChildren.ToString();
            txtChildrenPrice.Text     = calPerHead.ChildrenPrice.ToString("N2");
            lnkRemove.CommandArgument = calPerHead.ID.ToString();
        }
        protected void lnkSelectCustomer_Click(object sender, EventArgs e)
        {
            decimal defaultPrice = 0M;

            Decimal.TryParse(txtPriceAgreed.Text, out defaultPrice);

            CRM_CalendarPerHead calHead = new CRM_CalendarPerHead()
            {
                ChildrenPrice   = 0,
                CRM_CalendarID  = Entity.ID,
                PlusChildren    = 0,
                Price           = defaultPrice,
                TargetReference = ucAddCustomer.SelectedID
            };

            db.CRM_CalendarPerHeads.InsertOnSubmit(calHead);
            db.SubmitChanges();

            ReloadCalPerHead();
        }
        protected void SaveRecord(bool newRecord)
        {
            // new record / exiting record //

            object oldEntity = Entity.ShallowCopy();

            Entity.PriceAgreed      = Convert.ToDecimal(txtPriceAgreed.Text);
            Entity.PriceType        = Convert.ToByte(ddlPriceType.SelectedValue);
            Entity.InvoiceFirstname = txtFirstname.Text;
            Entity.InvoiceLastname  = txtLastname.Text;
            Entity.InvoiceTitle     = ddlTitles.SelectedValue;
            Entity.PONumber         = txtPONumber.Text;
            if (txtDatePaid.Text.Length != 0)
            {
                Entity.DatePaid = txtDatePaid.Value;
            }

            db.SubmitChanges();

            if (oldEntity != null)
            {
                CRM.Code.History.History.RecordLinqUpdate(db, AdminUser, oldEntity, Entity);
                db.SubmitChanges();
            }

            if (Entity.InvoiceAddressID == null)
            {
                Entity.CRM_Address = (CRM_Address)ucAddress.Save(new CRM_Address());
            }
            else
            {
                Entity.CRM_Address = (CRM_Address)ucAddress.Save((IAddress)db.CRM_Addresses.Single(c => c.ID == Entity.InvoiceAddressID));
            }


            db.SubmitChanges();

            foreach (RepeaterItem item in rptCustomersPerHead.Items)
            {
                TextBox    txtPrice         = (TextBox)item.FindControl("txtPrice");
                TextBox    txtPlusChildren  = (TextBox)item.FindControl("txtPlusChildren");
                TextBox    txtChildrenPrice = (TextBox)item.FindControl("txtChildrenPrice");
                LinkButton lnkRemove        = (LinkButton)item.FindControl("lnkRemove");
                string     id = lnkRemove.CommandArgument;

                CRM_CalendarPerHead calPerHead = db.CRM_CalendarPerHeads.Single(c => c.ID.ToString() == id);

                decimal price         = calPerHead.Price;
                int     plusChildren  = calPerHead.PlusChildren;
                decimal childrenPrice = calPerHead.ChildrenPrice;

                bool okPrice         = Decimal.TryParse(txtPrice.Text, out price);
                bool okChildren      = Int32.TryParse(txtPlusChildren.Text, out plusChildren);
                bool okChildrenPrice = Decimal.TryParse(txtChildrenPrice.Text, out childrenPrice);

                calPerHead.Price         = price;
                calPerHead.PlusChildren  = plusChildren;
                calPerHead.ChildrenPrice = childrenPrice;
                db.SubmitChanges();
            }
        }