public bool saveEditedMaterial()
        {
            try
            {
                Material editedMaterial = ViewModelControlPanel.DBDataClass.Materials.Single(c => c.materialId == materialId);  // Get the correct material

                editedMaterial.name      = sName.sInput;
                editedMaterial.code      = sCode.sInput;
                editedMaterial.active    = active;
                editedMaterial.minLength = Int32.Parse(iMinLength.sInput);
                editedMaterial.range     = sRange.sInput;
                editedMaterial.imagePath = imagePath;


                // First delete all current items
                var deleteMaterialTypeQuery = from x in ViewModelControlPanel.DBDataClass.MaterialTypeMaterials
                                              where x.materialId == editedMaterial.materialId
                                              select x;

                foreach (var q in deleteMaterialTypeQuery)
                {
                    ViewModelControlPanel.DBDataClass.MaterialTypeMaterials.DeleteOnSubmit(q);
                }
                ViewModelControlPanel.DBDataClass.SubmitChanges();


                // Upload new values to database
                foreach (var obcMaterialType in this.obcMaterialType.ToList())
                {
                    MaterialTypeMaterial newMaterial_MaterialType = new MaterialTypeMaterial();

                    newMaterial_MaterialType.materialId     = editedMaterial.materialId;
                    newMaterial_MaterialType.materialTypeId = obcMaterialType.iSelectedvalueMaterialType;

                    ViewModelControlPanel.DBDataClass.MaterialTypeMaterials.InsertOnSubmit(newMaterial_MaterialType);
                }

                ViewModelControlPanel.DBDataClass.SubmitChanges();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public bool saveNewMaterial()
        {
            try
            {
                Material saveNewMaterial = new Material();                          // Create a new instance of Material

                saveNewMaterial.name      = sName.sInput;
                saveNewMaterial.code      = sCode.sInput;
                saveNewMaterial.active    = active;
                saveNewMaterial.minLength = Int32.Parse(iMinLength.sInput);
                saveNewMaterial.range     = sRange.sInput;
                saveNewMaterial.imagePath = imagePath;

                ViewModelControlPanel.DBDataClass.Materials.InsertOnSubmit(saveNewMaterial);     // Insert new Material
                ViewModelControlPanel.DBDataClass.SubmitChanges();

                // Upload MaterialIOPositions to database
                foreach (var obcMaterialType in this.obcMaterialType.ToList())
                {
                    MaterialTypeMaterial newMaterial_MaterialType = new MaterialTypeMaterial();

                    newMaterial_MaterialType.materialId     = saveNewMaterial.materialId;
                    newMaterial_MaterialType.materialTypeId = obcMaterialType.iSelectedvalueMaterialType;//materialTypeId;

                    ViewModelControlPanel.DBDataClass.MaterialTypeMaterials.InsertOnSubmit(newMaterial_MaterialType);
                }
                ViewModelControlPanel.DBDataClass.SubmitChanges();

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
        }