// Form for updating an exisiting quote
        public QuoteFormViewModel(BaseViewModel parent, int quoteId, Boolean updating)
        {
            this.parent = parent;
            // will be set to true
            this.updating = updating;
            btnText       = "Update Quote";

            // Get the quote
            this.quote      = QuoteModel.getQuote(quoteId);
            this.customerId = quote.customer.customerId;

            // Get the customer the quote is being issued for
            customer = CustomerModel.getCustomer(customerId);

            // Set visibility of business textblocks
            if (customer.companyName == null || customer.vatNo == null)
            {
                isBusinessCustomer = "Collapsed";
            }
            else
            {
                isBusinessCustomer = "Visible";
            }

            // Get all materials
            materialList = MaterialModel.getMaterialList();
            // Keep a copy of the material list for filtering
            originalMaterialList = new ObservableCollection <MaterialModel>(materialList);

            // Get the quote materials that have been generated for this quote
            quoteMaterialList = QuoteMaterialModel.getQuoteMaterialList(quoteId);

            // Update the total quote cost
            updateTotalQuoteCosts();
        }
 // Adds a material to form
 public void addMaterial(int materialId)
 {
     // Set as selected material
     selectedMaterial = MaterialModel.getMaterial(materialId);
     // Create a new blank quote material
     quoteMaterial = new QuoteMaterialModel(quote.quoteId, materialId, selectedMaterial.pricePerUnit, selectedMaterial.isService);
 }
        // Either adds a new material to the quote
        // or updates and existing material
        public void addOrUpdateQuoteMaterial()
        {
            // Force all properties to be validated
            quoteMaterial.validateAllProps();

            if (selectedMaterial != null && quoteMaterial != null && !quoteMaterial.HasErrors)
            {
                // this is a newly added material
                if (quoteMaterial.listIndex == null)
                {
                    // Add to list
                    quoteMaterialList.Add(quoteMaterial);
                    // Set's its list index
                    quoteMaterial.listIndex = quoteMaterialList.IndexOf(quoteMaterial);
                }
                // This is an existing material
                else
                {
                    quoteMaterialList[quoteMaterial.listIndex.Value] = quoteMaterial;
                }

                // Set the button back  to it's original text
                addOrUpdateQuoteMaterialBtn = "Add to Quote";
                NotifyPropertyChanged("addOrUpdateQuoteMaterialBtn");

                // Update the total again
                updateTotalQuoteCosts();
                // Initialize a new material
                quoteMaterial = new QuoteMaterialModel(quote.quoteId, selectedMaterial.materialId, selectedMaterial.pricePerUnit, selectedMaterial.isService);
            }
            else
            {
                MessageBox.Show("Material Form has Errors");
            }
        }
        // Saves a quote
        public void saveQuote()
        {
            if (materialList.Count > 0)
            {
                quote.validateAllProps();

                // If thw quote has errors
                if (!quote.HasErrors)
                {
                    // update or insert
                    if (updating)
                    {
                        quote.updateQuote();
                    }
                    else
                    {
                        quote.insertQuote();
                    }

                    foreach (QuoteMaterialModel quoteMat in quoteMaterialList)
                    {
                        if (!quoteMat.HasErrors)
                        {
                            if (quoteMat.quoteMaterialId != 0)
                            {
                                quoteMat.updateMaterial();
                            }
                            else
                            {
                                quoteMat.insertMaterial();
                            }
                        }
                    }

                    foreach (QuoteMaterialModel quoteMat in removedQuoteMaterialList)
                    {
                        QuoteMaterialModel.delete(quoteMat.quoteMaterialId.Value);
                    }

                    MessageBox.Show("Quote Saved");
                }
                else
                {
                    MessageBox.Show("Quote has errors");
                }
            }
            else
            {
                MessageBox.Show("Add at least one material to the quote");
            }
        }
        public QuotePrint(QuoteModel quote)
        {
            InitializeComponent();

            viewQuotePrint.DataContext = this;

            quoteMaterialList = QuoteMaterialModel.getQuoteMaterialList(quote.quoteId);

            customer = CustomerModel.getCustomer(quote.customer.customerId);

            setting = SettingModel.getSetting();

            this.quote = quote;
        }