Beispiel #1
0
 ///<summary>Inserts one DocumentMisc into the database.  Returns the new priKey.</summary>
 public static long Insert(DocumentMisc documentMisc)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         documentMisc.DocMiscNum = DbHelper.GetNextOracleKey("documentmisc", "DocMiscNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(documentMisc, true));
             }
             catch (Oracle.DataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     documentMisc.DocMiscNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(documentMisc, false));
     }
 }
Beispiel #2
0
		///<summary>Inserts one DocumentMisc into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(DocumentMisc documentMisc,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				documentMisc.DocMiscNum=ReplicationServers.GetKey("documentmisc","DocMiscNum");
			}
			string command="INSERT INTO documentmisc (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="DocMiscNum,";
			}
			command+="DateCreated,FileName,DocMiscType,RawBase64) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(documentMisc.DocMiscNum)+",";
			}
			command+=
				     POut.Date  (documentMisc.DateCreated)+","
				+"'"+POut.String(documentMisc.FileName)+"',"
				+    POut.Int   ((int)documentMisc.DocMiscType)+","
				+    DbHelper.ParamChar+"paramRawBase64)";
			if(documentMisc.RawBase64==null) {
				documentMisc.RawBase64="";
			}
			OdSqlParameter paramRawBase64=new OdSqlParameter("paramRawBase64",OdDbType.Text,documentMisc.RawBase64);
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command,paramRawBase64);
			}
			else {
				documentMisc.DocMiscNum=Db.NonQ(command,true,paramRawBase64);
			}
			return documentMisc.DocMiscNum;
		}
Beispiel #3
0
        ///<summary>Updates one DocumentMisc in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(DocumentMisc documentMisc, DocumentMisc oldDocumentMisc)
        {
            string command = "";

            if (documentMisc.DateCreated.Date != oldDocumentMisc.DateCreated.Date)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateCreated = " + POut.Date(documentMisc.DateCreated) + "";
            }
            if (documentMisc.FileName != oldDocumentMisc.FileName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FileName = '" + POut.String(documentMisc.FileName) + "'";
            }
            if (documentMisc.DocMiscType != oldDocumentMisc.DocMiscType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DocMiscType = " + POut.Int((int)documentMisc.DocMiscType) + "";
            }
            if (documentMisc.RawBase64 != oldDocumentMisc.RawBase64)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "RawBase64 = " + DbHelper.ParamChar + "paramRawBase64";
            }
            if (command == "")
            {
                return(false);
            }
            if (documentMisc.RawBase64 == null)
            {
                documentMisc.RawBase64 = "";
            }
            OdSqlParameter paramRawBase64 = new OdSqlParameter("paramRawBase64", OdDbType.Text, POut.StringParam(documentMisc.RawBase64));

            command = "UPDATE documentmisc SET " + command
                      + " WHERE DocMiscNum = " + POut.Long(documentMisc.DocMiscNum);
            Db.NonQ(command, paramRawBase64);
            return(true);
        }
Beispiel #4
0
        private void butRecopy_Click(object sender, EventArgs e)
        {
            Version versionCurrent = new Version(Application.ProductVersion);
            string  folderUpdate   = "";

            if (PrefC.AtoZfolderUsed)
            {
                folderUpdate = ODFileUtils.CombinePaths(ImageStore.GetPreferredAtoZpath(), "UpdateFiles");
            }
            else             //db
            {
                folderUpdate = ODFileUtils.CombinePaths(Path.GetTempPath(), "UpdateFiles");
                if (Directory.Exists(folderUpdate))
                {
                    Directory.Delete(folderUpdate, true);
                }
                DocumentMisc docmisc = DocumentMiscs.GetUpdateFilesZip();
                if (docmisc != null)
                {
                    byte[] rawBytes = Convert.FromBase64String(docmisc.RawBase64);
                    using (ZipFile unzipped = ZipFile.Read(rawBytes)) {
                        unzipped.ExtractAll(folderUpdate);
                    }
                }
            }
            //identify the ideal situation where everything is already in place and no copy is needed.
            if (Directory.Exists(folderUpdate))
            {
                string filePath = ODFileUtils.CombinePaths(folderUpdate, "Manifest.txt");
                if (File.Exists(filePath))
                {
                    string fileText = File.ReadAllText(filePath);
                    if (fileText == versionCurrent.ToString(3))
                    {
                        if (!MsgBox.Show(this, MsgBoxButtons.YesNo, "According to the information in UpdateFiles\\Manifest.txt, the UpdateFiles folder is current.  Recopy anyway?"))
                        {
                            return;
                        }
                    }
                }
            }
            Cursor = Cursors.WaitCursor;
            if (!PrefL.CopyFromHereToUpdateFiles(versionCurrent))
            {
                Cursor = Cursors.Default;
                return;
            }
            Cursor = Cursors.Default;
            MsgBox.Show(this, "Recopied.");
        }
Beispiel #5
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<DocumentMisc> TableToList(DataTable table){
			List<DocumentMisc> retVal=new List<DocumentMisc>();
			DocumentMisc documentMisc;
			for(int i=0;i<table.Rows.Count;i++) {
				documentMisc=new DocumentMisc();
				documentMisc.DocMiscNum = PIn.Long  (table.Rows[i]["DocMiscNum"].ToString());
				documentMisc.DateCreated= PIn.Date  (table.Rows[i]["DateCreated"].ToString());
				documentMisc.FileName   = PIn.String(table.Rows[i]["FileName"].ToString());
				documentMisc.DocMiscType= (OpenDentBusiness.DocumentMiscType)PIn.Int(table.Rows[i]["DocMiscType"].ToString());
				documentMisc.RawBase64  = PIn.String(table.Rows[i]["RawBase64"].ToString());
				retVal.Add(documentMisc);
			}
			return retVal;
		}
Beispiel #6
0
 ///<summary>Inserts one DocumentMisc into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(DocumentMisc documentMisc)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(documentMisc, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             documentMisc.DocMiscNum = DbHelper.GetNextOracleKey("documentmisc", "DocMiscNum");                  //Cacheless method
         }
         return(InsertNoCache(documentMisc, true));
     }
 }
Beispiel #7
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <DocumentMisc> TableToList(DataTable table)
        {
            List <DocumentMisc> retVal = new List <DocumentMisc>();
            DocumentMisc        documentMisc;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                documentMisc             = new DocumentMisc();
                documentMisc.DocMiscNum  = PIn.Long(table.Rows[i]["DocMiscNum"].ToString());
                documentMisc.DateCreated = PIn.Date(table.Rows[i]["DateCreated"].ToString());
                documentMisc.FileName    = PIn.String(table.Rows[i]["FileName"].ToString());
                documentMisc.DocMiscType = (DocumentMiscType)PIn.Int(table.Rows[i]["DocMiscType"].ToString());
                documentMisc.RawBase64   = PIn.String(table.Rows[i]["RawBase64"].ToString());
                retVal.Add(documentMisc);
            }
            return(retVal);
        }
Beispiel #8
0
        ///<summary>Updates one DocumentMisc in the database.</summary>
        public static void Update(DocumentMisc documentMisc)
        {
            string command = "UPDATE documentmisc SET "
                             + "DateCreated=  " + POut.Date(documentMisc.DateCreated) + ", "
                             + "FileName   = '" + POut.String(documentMisc.FileName) + "', "
                             + "DocMiscType=  " + POut.Int((int)documentMisc.DocMiscType) + ", "
                             + "RawBase64  =  " + DbHelper.ParamChar + "paramRawBase64 "
                             + "WHERE DocMiscNum = " + POut.Long(documentMisc.DocMiscNum);

            if (documentMisc.RawBase64 == null)
            {
                documentMisc.RawBase64 = "";
            }
            OdSqlParameter paramRawBase64 = new OdSqlParameter("paramRawBase64", OdDbType.Text, documentMisc.RawBase64);

            Db.NonQ(command, paramRawBase64);
        }
Beispiel #9
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <DocumentMisc> TableToList(DataTable table)
        {
            List <DocumentMisc> retVal = new List <DocumentMisc>();
            DocumentMisc        documentMisc;

            foreach (DataRow row in table.Rows)
            {
                documentMisc             = new DocumentMisc();
                documentMisc.DocMiscNum  = PIn.Long(row["DocMiscNum"].ToString());
                documentMisc.DateCreated = PIn.Date(row["DateCreated"].ToString());
                documentMisc.FileName    = PIn.String(row["FileName"].ToString());
                documentMisc.DocMiscType = (OpenDentBusiness.DocumentMiscType)PIn.Int(row["DocMiscType"].ToString());
                documentMisc.RawBase64   = PIn.String(row["RawBase64"].ToString());
                retVal.Add(documentMisc);
            }
            return(retVal);
        }
Beispiel #10
0
 ///<summary>Returns true if Update(DocumentMisc,DocumentMisc) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(DocumentMisc documentMisc, DocumentMisc oldDocumentMisc)
 {
     if (documentMisc.DateCreated.Date != oldDocumentMisc.DateCreated.Date)
     {
         return(true);
     }
     if (documentMisc.FileName != oldDocumentMisc.FileName)
     {
         return(true);
     }
     if (documentMisc.DocMiscType != oldDocumentMisc.DocMiscType)
     {
         return(true);
     }
     if (documentMisc.RawBase64 != oldDocumentMisc.RawBase64)
     {
         return(true);
     }
     return(false);
 }
Beispiel #11
0
        ///<summary>Inserts one DocumentMisc into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(DocumentMisc documentMisc, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO documentmisc (";

            if (!useExistingPK && isRandomKeys)
            {
                documentMisc.DocMiscNum = ReplicationServers.GetKeyNoCache("documentmisc", "DocMiscNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "DocMiscNum,";
            }
            command += "DateCreated,FileName,DocMiscType,RawBase64) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(documentMisc.DocMiscNum) + ",";
            }
            command +=
                POut.Date(documentMisc.DateCreated) + ","
                + "'" + POut.String(documentMisc.FileName) + "',"
                + POut.Int((int)documentMisc.DocMiscType) + ","
                + DbHelper.ParamChar + "paramRawBase64)";
            if (documentMisc.RawBase64 == null)
            {
                documentMisc.RawBase64 = "";
            }
            OdSqlParameter paramRawBase64 = new OdSqlParameter("paramRawBase64", OdDbType.Text, POut.StringParam(documentMisc.RawBase64));

            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command, paramRawBase64);
            }
            else
            {
                documentMisc.DocMiscNum = Db.NonQ(command, true, "DocMiscNum", "documentMisc", paramRawBase64);
            }
            return(documentMisc.DocMiscNum);
        }
Beispiel #12
0
		///<summary>Inserts one DocumentMisc into the database.  Returns the new priKey.</summary>
		public static long Insert(DocumentMisc documentMisc){
			if(DataConnection.DBtype==DatabaseType.Oracle) {
				documentMisc.DocMiscNum=DbHelper.GetNextOracleKey("documentmisc","DocMiscNum");
				int loopcount=0;
				while(loopcount<100){
					try {
						return Insert(documentMisc,true);
					}
					catch(Oracle.DataAccess.Client.OracleException ex){
						if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
							documentMisc.DocMiscNum++;
							loopcount++;
						}
						else{
							throw ex;
						}
					}
				}
				throw new ApplicationException("Insert failed.  Could not generate primary key.");
			}
			else {
				return Insert(documentMisc,false);
			}
		}
Beispiel #13
0
		///<summary>Updates one DocumentMisc in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
		public static bool Update(DocumentMisc documentMisc,DocumentMisc oldDocumentMisc){
			string command="";
			if(documentMisc.DateCreated != oldDocumentMisc.DateCreated) {
				if(command!=""){ command+=",";}
				command+="DateCreated = "+POut.Date(documentMisc.DateCreated)+"";
			}
			if(documentMisc.FileName != oldDocumentMisc.FileName) {
				if(command!=""){ command+=",";}
				command+="FileName = '"+POut.String(documentMisc.FileName)+"'";
			}
			if(documentMisc.DocMiscType != oldDocumentMisc.DocMiscType) {
				if(command!=""){ command+=",";}
				command+="DocMiscType = "+POut.Int   ((int)documentMisc.DocMiscType)+"";
			}
			if(documentMisc.RawBase64 != oldDocumentMisc.RawBase64) {
				if(command!=""){ command+=",";}
				command+="RawBase64 = "+DbHelper.ParamChar+"paramRawBase64";
			}
			if(command==""){
				return false;
			}
			if(documentMisc.RawBase64==null) {
				documentMisc.RawBase64="";
			}
			OdSqlParameter paramRawBase64=new OdSqlParameter("paramRawBase64",OdDbType.Text,documentMisc.RawBase64);
			command="UPDATE documentmisc SET "+command
				+" WHERE DocMiscNum = "+POut.Long(documentMisc.DocMiscNum);
			Db.NonQ(command,paramRawBase64);
			return true;
		}
Beispiel #14
0
		///<summary>Updates one DocumentMisc in the database.</summary>
		public static void Update(DocumentMisc documentMisc){
			string command="UPDATE documentmisc SET "
				+"DateCreated=  "+POut.Date  (documentMisc.DateCreated)+", "
				+"FileName   = '"+POut.String(documentMisc.FileName)+"', "
				+"DocMiscType=  "+POut.Int   ((int)documentMisc.DocMiscType)+", "
				+"RawBase64  =  "+DbHelper.ParamChar+"paramRawBase64 "
				+"WHERE DocMiscNum = "+POut.Long(documentMisc.DocMiscNum);
			if(documentMisc.RawBase64==null) {
				documentMisc.RawBase64="";
			}
			OdSqlParameter paramRawBase64=new OdSqlParameter("paramRawBase64",OdDbType.Text,documentMisc.RawBase64);
			Db.NonQ(command,paramRawBase64);
		}
Beispiel #15
0
 ///<summary>Inserts one DocumentMisc into the database.  Returns the new priKey.</summary>
 public static long Insert(DocumentMisc documentMisc)
 {
     return(Insert(documentMisc, false));
 }
Beispiel #16
0
        ///<summary>Called in two places.  Once from FormOpenDental.PrefsStartup, and also from FormBackups after a restore.</summary>
        public static bool CheckProgramVersion()
        {
            if (PrefC.GetBool(PrefName.UpdateWindowShowsClassicView))
            {
                return(CheckProgramVersionClassic());
            }
            Version storedVersion  = new Version(PrefC.GetString(PrefName.ProgramVersion));
            Version currentVersion = new Version(Application.ProductVersion);
            string  database       = "";

            //string command="";
            if (DataConnection.DBtype == DatabaseType.MySql)
            {
                database = MiscData.GetCurrentDatabase();
            }
            if (storedVersion < currentVersion)
            {
                //There are two different situations where this might happen.
                if (PrefC.GetString(PrefName.UpdateInProgressOnComputerName) == "")              //1. Just performed an update from this workstation on another database.
                //This is very common for admins when viewing slighly older databases.
                //There should be no annoying behavior here.  So do nothing.
                {
                                        #if !DEBUG
                    //Excluding this in debug allows us to view slightly older databases without accidentally altering them.
                    Prefs.UpdateString(PrefName.ProgramVersion, currentVersion.ToString());
                    Cache.Refresh(InvalidType.Prefs);
                                        #endif
                    return(true);
                }
                //and 2a. Just performed an update from this workstation on this database.
                //or 2b. Just performed an update from this workstation for multiple databases.
                //In both 2a and 2b, we already downloaded Setup file to correct location for this db, so skip 1 above.
                //This computer just performed an update, but none of the other computers has updated yet.
                //So attempt to stash all files that are in the Application directory.
                if (!CopyFromHereToUpdateFiles(currentVersion))
                {
                    Application.Exit();
                    return(false);
                }
                Prefs.UpdateString(PrefName.ProgramVersion, currentVersion.ToString());
                Prefs.UpdateString(PrefName.UpdateInProgressOnComputerName, "");               //now, other workstations will be allowed to update.
                Cache.Refresh(InvalidType.Prefs);
            }
            if (storedVersion > currentVersion)
            {
                //This is the update sequence for both a direct workstation, and for a ClientWeb workstation.
                string folderUpdate = "";
                if (PrefC.AtoZfolderUsed)
                {
                    folderUpdate = ODFileUtils.CombinePaths(ImageStore.GetPreferredAtoZpath(), "UpdateFiles");
                }
                else                  //images in db
                {
                    folderUpdate = ODFileUtils.CombinePaths(Path.GetTempPath(), "UpdateFiles");
                    if (Directory.Exists(folderUpdate))
                    {
                        Directory.Delete(folderUpdate, true);
                    }
                    DocumentMisc docmisc = DocumentMiscs.GetUpdateFilesZip();
                    if (docmisc != null)
                    {
                        byte[] rawBytes = Convert.FromBase64String(docmisc.RawBase64);
                        using (ZipFile unzipped = ZipFile.Read(rawBytes)) {
                            unzipped.ExtractAll(folderUpdate);
                        }
                    }
                }
                //look at the manifest to see if it's the version we need
                string manifestVersion = "";
                try {
                    manifestVersion = File.ReadAllText(ODFileUtils.CombinePaths(folderUpdate, "Manifest.txt"));
                }
                catch {
                    //fail silently
                }
                if (manifestVersion != storedVersion.ToString(3))               //manifest version is wrong
                //No point trying the Setup.exe because that's probably wrong too.
                //Just go straight to downloading and running the Setup.exe.
                {
                    string manpath = ODFileUtils.CombinePaths(folderUpdate, "Manifest.txt");
                    if (MessageBox.Show(Lan.g("Prefs", "The expected version information was not found in this file: ") + manpath + ".  "
                                        + Lan.g("Prefs", "There is probably a permission issue on that folder which should be fixed. ")
                                        + "\r\n\r\n" + Lan.g("Prefs", "The suggested solution is to return to the computer where the update was just run.  Go to Help | Update | Setup, and click the Recopy button.")
                                        + "\r\n\r\n" + Lan.g("Prefs", "If, instead, you click OK in this window, then a fresh Setup file will be downloaded and run."),
                                        "", MessageBoxButtons.OKCancel) != DialogResult.OK)     //they don't want to download again.
                    {
                        Application.Exit();
                        return(false);
                    }
                    DownloadAndRunSetup(storedVersion, currentVersion);
                    Application.Exit();
                    return(false);
                }
                //manifest version matches
                if (MessageBox.Show(Lan.g("Prefs", "Files will now be copied.") + "\r\n"
                                    + Lan.g("Prefs", "Workstation version will be updated from ") + currentVersion.ToString(3)
                                    + Lan.g("Prefs", " to ") + storedVersion.ToString(3),
                                    "", MessageBoxButtons.OKCancel)
                    != DialogResult.OK)                   //they don't want to update for some reason.
                {
                    Application.Exit();
                    return(false);
                }
                string tempDir = Path.GetTempPath();
                //copy UpdateFileCopier.exe to the temp directory
                File.Copy(ODFileUtils.CombinePaths(folderUpdate, "UpdateFileCopier.exe"), //source
                          ODFileUtils.CombinePaths(tempDir, "UpdateFileCopier.exe"),      //dest
                          true);                                                          //overwrite
                //wait a moment to make sure the file was copied
                Thread.Sleep(500);
                //launch UpdateFileCopier to copy all files to here.
                int    processId     = Process.GetCurrentProcess().Id;
                string appDir        = Application.StartupPath;
                string startFileName = ODFileUtils.CombinePaths(tempDir, "UpdateFileCopier.exe");
                string arguments     = "\"" + folderUpdate + "\""   //pass the source directory to the file copier.
                                       + " " + processId.ToString() //and the processId of Open Dental.
                                       + " \"" + appDir + "\"";     //and the directory where OD is running
                Process.Start(startFileName, arguments);
                Application.Exit();                                 //always exits, whether launch of setup worked or not
                return(false);
            }
            return(true);
        }