private void LoadSettings()
        {
            app = Application.Current as App;
            DB = DentalSmileDBFactory.GetInstance();

                //if (Smile.INSTALL)
            if(!DB.TestConnectionString())
            {
                SettingsDB dbForm = new SettingsDB();
                dbForm.ShowDialog();
                DB = DentalSmileDBFactory.GetInstance();
            }

            //detect if Admin  is NULL
            if (DB.selectDefaultAdmin() == null)
            {
                AdminPasswordDialog dlg = new AdminPasswordDialog();
                dlg.ShowDialog();
            }

            Smile.Phases = DB.SelectAllPhases();
            
            if (App.user == null)
            {
                //ChangePasswordDialog dlg = new ChangePasswordDialog();
                LoginDialog dlg = new LoginDialog();
                dlg.ShowDialog();
            }

        }
 public static DentalSmileDB GetInstance()
 {
     if (db == null)
     {
         db = createIntance();
     }
     return db;
 }
 internal static void ReInstantiate()
 {
     db = createIntance();
 }
 public DentistForm()
 {
     InitializeComponent();
     dbConnect = new DentalSmileDB();
 }
        private void handleManipulationData(Treatment treatment, SmileFile file, bool duplicate)
        {
            DB = DentalSmileDBFactory.GetInstance();
            app = Application.Current as App;
            if (App.patient == null) App.patient = new Patient();
            Patient = App.patient;

            if (treatment == null)
            {
                Treatment = new Treatment();
            }
            else
            {
                Treatment = treatment;
                if (duplicate)
                {
                    Treatment.Id = null;
                }
                Treatment.RefId = treatment.Id;
            }
            //if (file != null) SmileFile = file;

            if (file.Type == Smile.MANIPULATION)
            {
                //Load Jaw
                LoadJawFile(file.GetFile);
            }
            else if (file.Type == Smile.SCANNING)
            {
                //Load Raw
                LoadRawFile(file.GetFile);
            }

            SmileFile = new SmileFile();
            SmileFile.RefId = file.Id;

            ViewZoomExtents();
        }
//        public MainViewModel(IFileDialogService fds, HelixViewport3D hv, ModelVisual3D rootModel)
        public MainViewModel(IFileDialogService fds, HelixViewport3D hv, MainWindow window)
        {
            Expansion = 1;
            FileDialogService = fds;
            HelixView = hv;
            FileOpenCommand = new DelegateCommand(FileOpen);
            FileOpenRawCommand = new DelegateCommand(FileOpenRaw);
            FileExportCommand = new DelegateCommand(FileExport);
            FileExportRawCommand = new DelegateCommand(FileExportRaw);
            FileExitCommand = new DelegateCommand(FileExit);
            ViewZoomExtentsCommand = new DelegateCommand(ViewZoomExtents);
            EditCopyXamlCommand = new DelegateCommand(CopyXaml);
            EditClearAreaCommand = new DelegateCommand(ClearArea);
            FileExportStlCommand = new DelegateCommand(StlFileExport);            


            ApplicationTitle = "Dental.Smile - 3D Viewer";

            ModelToBaseMarker = new Dictionary<Model3D, BaseMarker>();
            OriginalMaterial = new Dictionary<Model3D, Material>();

            //Elements = new List<VisualElement>();
            //foreach (var c in hv.Children) Elements.Add(new VisualElement(c));

            DB = DentalSmileDBFactory.GetInstance();
            Treatment = new Treatment();
            SmileFile = new SmileFile();
            Patient = new Patient();
            JawVisual = new JawVisual3D(Patient);
            RootVisual = window.vmodel;
            app = Application.Current as App;

            RootVisual.Children.Add(JawVisual);
            this.window = window;

        }