Example #1
0
        ///<summary>Inserts one ClaimAttach into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(ClaimAttach claimAttach, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                claimAttach.ClaimAttachNum = ReplicationServers.GetKey("claimattach", "ClaimAttachNum");
            }
            string command = "INSERT INTO claimattach (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "ClaimAttachNum,";
            }
            command += "ClaimNum,DisplayedFileName,ActualFileName) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(claimAttach.ClaimAttachNum) + ",";
            }
            command +=
                POut.Long(claimAttach.ClaimNum) + ","
                + "'" + POut.String(claimAttach.DisplayedFileName) + "',"
                + "'" + POut.String(claimAttach.ActualFileName) + "')";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                claimAttach.ClaimAttachNum = Db.NonQ(command, true);
            }
            return(claimAttach.ClaimAttachNum);
        }
Example #2
0
 ///<summary>Inserts one ClaimAttach into the database.  Provides option to use the existing priKey.</summary>
 internal static long Insert(ClaimAttach claimAttach,bool useExistingPK)
 {
     if(!useExistingPK && PrefC.RandomKeys) {
         claimAttach.ClaimAttachNum=ReplicationServers.GetKey("claimattach","ClaimAttachNum");
     }
     string command="INSERT INTO claimattach (";
     if(useExistingPK || PrefC.RandomKeys) {
         command+="ClaimAttachNum,";
     }
     command+="ClaimNum,DisplayedFileName,ActualFileName) VALUES(";
     if(useExistingPK || PrefC.RandomKeys) {
         command+=POut.Long(claimAttach.ClaimAttachNum)+",";
     }
     command+=
              POut.Long  (claimAttach.ClaimNum)+","
         +"'"+POut.String(claimAttach.DisplayedFileName)+"',"
         +"'"+POut.String(claimAttach.ActualFileName)+"')";
     if(useExistingPK || PrefC.RandomKeys) {
         Db.NonQ(command);
     }
     else {
         claimAttach.ClaimAttachNum=Db.NonQ(command,true);
     }
     return claimAttach.ClaimAttachNum;
 }
Example #3
0
 ///<summary>Inserts one ClaimAttach into the database.  Returns the new priKey.</summary>
 public static long Insert(ClaimAttach claimAttach)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         claimAttach.ClaimAttachNum = DbHelper.GetNextOracleKey("claimattach", "ClaimAttachNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(claimAttach, true));
             }
             catch (Oracle.DataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     claimAttach.ClaimAttachNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(claimAttach, false));
     }
 }
Example #4
0
        ///<summary>Inserts one ClaimAttach into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(ClaimAttach claimAttach, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO claimattach (";

            if (!useExistingPK && isRandomKeys)
            {
                claimAttach.ClaimAttachNum = ReplicationServers.GetKeyNoCache("claimattach", "ClaimAttachNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "ClaimAttachNum,";
            }
            command += "ClaimNum,DisplayedFileName,ActualFileName) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(claimAttach.ClaimAttachNum) + ",";
            }
            command +=
                POut.Long(claimAttach.ClaimNum) + ","
                + "'" + POut.String(claimAttach.DisplayedFileName) + "',"
                + "'" + POut.String(claimAttach.ActualFileName) + "')";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                claimAttach.ClaimAttachNum = Db.NonQ(command, true, "ClaimAttachNum", "claimAttach");
            }
            return(claimAttach.ClaimAttachNum);
        }
Example #5
0
 ///<summary>Inserts one ClaimAttach into the database.  Returns the new priKey.</summary>
 internal static long Insert(ClaimAttach claimAttach)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         claimAttach.ClaimAttachNum=DbHelper.GetNextOracleKey("claimattach","ClaimAttachNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(claimAttach,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     claimAttach.ClaimAttachNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(claimAttach,false);
     }
 }
        ///<summary>Creates the ClaimAttach objects for each item in the grid and associates it to the given claim.
        ///The parameter path should be the full path to the image and fileName should simply be the file name by itself.</summary>
        private ClaimAttach CreateClaimAttachment(string fileNameDisplay, string fileNameActual)
        {
            ClaimAttach claimAttachment = new ClaimAttach();

            claimAttachment.DisplayedFileName = fileNameDisplay;
            claimAttachment.ActualFileName    = fileNameActual;
            claimAttachment.ClaimNum          = _claimCur.ClaimNum;
            return(claimAttachment);
        }
Example #7
0
        ///<summary>Updates one ClaimAttach in the database.</summary>
        public static void Update(ClaimAttach claimAttach)
        {
            string command = "UPDATE claimattach SET "
                             + "ClaimNum         =  " + POut.Long(claimAttach.ClaimNum) + ", "
                             + "DisplayedFileName= '" + POut.String(claimAttach.DisplayedFileName) + "', "
                             + "ActualFileName   = '" + POut.String(claimAttach.ActualFileName) + "' "
                             + "WHERE ClaimAttachNum = " + POut.Long(claimAttach.ClaimAttachNum);

            Db.NonQ(command);
        }
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<ClaimAttach> TableToList(DataTable table){
			List<ClaimAttach> retVal=new List<ClaimAttach>();
			ClaimAttach claimAttach;
			for(int i=0;i<table.Rows.Count;i++) {
				claimAttach=new ClaimAttach();
				claimAttach.ClaimAttachNum   = PIn.Long  (table.Rows[i]["ClaimAttachNum"].ToString());
				claimAttach.ClaimNum         = PIn.Long  (table.Rows[i]["ClaimNum"].ToString());
				claimAttach.DisplayedFileName= PIn.String(table.Rows[i]["DisplayedFileName"].ToString());
				claimAttach.ActualFileName   = PIn.String(table.Rows[i]["ActualFileName"].ToString());
				retVal.Add(claimAttach);
			}
			return retVal;
		}
Example #9
0
 ///<summary>Inserts one ClaimAttach into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(ClaimAttach claimAttach)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(claimAttach, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             claimAttach.ClaimAttachNum = DbHelper.GetNextOracleKey("claimattach", "ClaimAttachNum");                  //Cacheless method
         }
         return(InsertNoCache(claimAttach, true));
     }
 }
Example #10
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <ClaimAttach> TableToList(DataTable table)
        {
            List <ClaimAttach> retVal = new List <ClaimAttach>();
            ClaimAttach        claimAttach;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                claimAttach = new ClaimAttach();
                claimAttach.ClaimAttachNum    = PIn.Long(table.Rows[i]["ClaimAttachNum"].ToString());
                claimAttach.ClaimNum          = PIn.Long(table.Rows[i]["ClaimNum"].ToString());
                claimAttach.DisplayedFileName = PIn.String(table.Rows[i]["DisplayedFileName"].ToString());
                claimAttach.ActualFileName    = PIn.String(table.Rows[i]["ActualFileName"].ToString());
                retVal.Add(claimAttach);
            }
            return(retVal);
        }
Example #11
0
 ///<summary>Returns true if Update(ClaimAttach,ClaimAttach) 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(ClaimAttach claimAttach, ClaimAttach oldClaimAttach)
 {
     if (claimAttach.ClaimNum != oldClaimAttach.ClaimNum)
     {
         return(true);
     }
     if (claimAttach.DisplayedFileName != oldClaimAttach.DisplayedFileName)
     {
         return(true);
     }
     if (claimAttach.ActualFileName != oldClaimAttach.ActualFileName)
     {
         return(true);
     }
     return(false);
 }
Example #12
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <ClaimAttach> TableToList(DataTable table)
        {
            List <ClaimAttach> retVal = new List <ClaimAttach>();
            ClaimAttach        claimAttach;

            foreach (DataRow row in table.Rows)
            {
                claimAttach = new ClaimAttach();
                claimAttach.ClaimAttachNum    = PIn.Long(row["ClaimAttachNum"].ToString());
                claimAttach.ClaimNum          = PIn.Long(row["ClaimNum"].ToString());
                claimAttach.DisplayedFileName = PIn.String(row["DisplayedFileName"].ToString());
                claimAttach.ActualFileName    = PIn.String(row["ActualFileName"].ToString());
                retVal.Add(claimAttach);
            }
            return(retVal);
        }
Example #13
0
        ///<summary>Updates one ClaimAttach 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(ClaimAttach claimAttach, ClaimAttach oldClaimAttach)
        {
            string command = "";

            if (claimAttach.ClaimNum != oldClaimAttach.ClaimNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ClaimNum = " + POut.Long(claimAttach.ClaimNum) + "";
            }
            if (claimAttach.DisplayedFileName != oldClaimAttach.DisplayedFileName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DisplayedFileName = '" + POut.String(claimAttach.DisplayedFileName) + "'";
            }
            if (claimAttach.ActualFileName != oldClaimAttach.ActualFileName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ActualFileName = '" + POut.String(claimAttach.ActualFileName) + "'";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE claimattach SET " + command
                      + " WHERE ClaimAttachNum = " + POut.Long(claimAttach.ClaimAttachNum);
            Db.NonQ(command);
            return(true);
        }
Example #14
0
        private void SaveAttachment()
        {
            Patient PatCur = Patients.GetPat(PatNum);

            //if(PatCur.ImageFolder=="") {
            //	MsgBox.Show(this,"Invalid patient image folder.");
            //	return;
            //}
            if (!PrefC.AtoZfolderUsed)
            {
                MsgBox.Show(this, "Error. Not using AtoZ images folder.");
                return;
            }
            string patfolder = ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath());
            //ODFileUtils.CombinePaths(
            //FormPath.GetPreferredImagePath(),PatCur.ImageFolder.Substring(0,1).ToUpper(),PatCur.ImageFolder);
            //if(!Directory.Exists(patfolder)) {
            //	MsgBox.Show(this,"Patient folder not found in AtoZ folder.");
            //	return;
            //}
            Document doc = Docs[gridMain.GetSelectedIndex()];

            if (!ImageHelper.HasImageExtension(doc.FileName))
            {
                MsgBox.Show(this, "Invalid file.  Only images may be attached, no other file format.");
                return;
            }
            string oldPath = ODFileUtils.CombinePaths(patfolder, doc.FileName);
            Random rnd     = new Random();
            string newName = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString()
                             + Path.GetExtension(oldPath);
            string attachPath = EmailMessages.GetEmailAttachPath();
            string newPath    = ODFileUtils.CombinePaths(attachPath, newName);

            try {
                if (ImageHelper.HasImageExtension(oldPath))
                {
                    if (doc.CropH != 0 ||
                        doc.CropW != 0 ||
                        doc.CropX != 0 ||
                        doc.CropY != 0 ||
                        doc.DegreesRotated != 0 ||
                        doc.IsFlipped ||
                        doc.WindowingMax != 0 ||
                        doc.WindowingMin != 0)
                    {
                        //this does result in a significantly larger images size if jpg.  A later optimization would recompress it.
                        Bitmap bitmapold = (Bitmap)Bitmap.FromFile(oldPath);
                        Bitmap bitmapnew = ImageHelper.ApplyDocumentSettingsToImage(doc, bitmapold, ImageSettingFlags.ALL);
                        bitmapnew.Save(newPath);
                    }
                    else
                    {
                        File.Copy(oldPath, newPath);
                    }
                }
                else
                {
                    File.Copy(oldPath, newPath);
                }
                ClaimAttachNew = new ClaimAttach();
                ClaimAttachNew.DisplayedFileName = Docs[gridMain.GetSelectedIndex()].FileName;
                ClaimAttachNew.ActualFileName    = newName;
                DialogResult = DialogResult.OK;
            }
            catch (FileNotFoundException ex) {
                MessageBox.Show(Lan.g(this, "File not found: ") + ex.Message);
                return;
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
		///<summary>Updates one ClaimAttach 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.</summary>
		public static void Update(ClaimAttach claimAttach,ClaimAttach oldClaimAttach){
			string command="";
			if(claimAttach.ClaimNum != oldClaimAttach.ClaimNum) {
				if(command!=""){ command+=",";}
				command+="ClaimNum = "+POut.Long(claimAttach.ClaimNum)+"";
			}
			if(claimAttach.DisplayedFileName != oldClaimAttach.DisplayedFileName) {
				if(command!=""){ command+=",";}
				command+="DisplayedFileName = '"+POut.String(claimAttach.DisplayedFileName)+"'";
			}
			if(claimAttach.ActualFileName != oldClaimAttach.ActualFileName) {
				if(command!=""){ command+=",";}
				command+="ActualFileName = '"+POut.String(claimAttach.ActualFileName)+"'";
			}
			if(command==""){
				return;
			}
			command="UPDATE claimattach SET "+command
				+" WHERE ClaimAttachNum = "+POut.Long(claimAttach.ClaimAttachNum);
			Db.NonQ(command);
		}
		///<summary>Updates one ClaimAttach in the database.</summary>
		public static void Update(ClaimAttach claimAttach){
			string command="UPDATE claimattach SET "
				+"ClaimNum         =  "+POut.Long  (claimAttach.ClaimNum)+", "
				+"DisplayedFileName= '"+POut.String(claimAttach.DisplayedFileName)+"', "
				+"ActualFileName   = '"+POut.String(claimAttach.ActualFileName)+"' "
				+"WHERE ClaimAttachNum = "+POut.Long(claimAttach.ClaimAttachNum);
			Db.NonQ(command);
		}
        private void SaveAttachment()
        {
            Patient PatCur = Patients.GetPat(PatNum);

            //if(PatCur.ImageFolder=="") {
            //	MsgBox.Show(this,"Invalid patient image folder.");
            //	return;
            //}
            if (PrefC.AtoZfolderUsed == DataStorageType.InDatabase)
            {
                MsgBox.Show(this, "Error. Not using AtoZ images folder.");
                return;
            }
            string patfolder = ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath());
            //ODFileUtils.CombinePaths(
            //FormPath.GetPreferredImagePath(),PatCur.ImageFolder.Substring(0,1).ToUpper(),PatCur.ImageFolder);
            //if(!Directory.Exists(patfolder)) {
            //	MsgBox.Show(this,"Patient folder not found in AtoZ folder.");
            //	return;
            //}
            Document doc = Docs[gridMain.GetSelectedIndex()];

            if (!ImageHelper.HasImageExtension(doc.FileName))
            {
                MsgBox.Show(this, "Invalid file.  Only images may be attached, no other file format.");
                return;
            }
            string oldPath = ODFileUtils.CombinePaths(patfolder, doc.FileName);
            Random rnd     = new Random();
            string newName = DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.TimeOfDay.Ticks.ToString() + rnd.Next(1000).ToString()
                             + Path.GetExtension(oldPath);
            string attachPath = EmailAttaches.GetAttachPath();
            string newPath    = ODFileUtils.CombinePaths(attachPath, newName);

            if (CloudStorage.IsCloudStorage)
            {
                oldPath = oldPath.Replace("\\", "/");
                newPath = newPath.Replace("\\", "/");
            }
            try {
                if (ImageHelper.HasImageExtension(oldPath))
                {
                    if (doc.CropH != 0 ||
                        doc.CropW != 0 ||
                        doc.CropX != 0 ||
                        doc.CropY != 0 ||
                        doc.DegreesRotated != 0 ||
                        doc.IsFlipped ||
                        doc.WindowingMax != 0 ||
                        doc.WindowingMin != 0 ||
                        CloudStorage.IsCloudStorage)
                    {
                        //this does result in a significantly larger images size if jpg.  A later optimization would recompress it.
                        Bitmap bitmapold = null;
                        if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)
                        {
                            bitmapold = (Bitmap)Bitmap.FromFile(oldPath);
                            Bitmap bitmapnew = ImageHelper.ApplyDocumentSettingsToImage(doc, bitmapold, ImageSettingFlags.ALL);
                            bitmapnew.Save(newPath);
                        }
                        else if (CloudStorage.IsCloudStorage)
                        {
                            //First, download the file.
                            FormProgress FormP = new FormProgress();
                            FormP.DisplayText          = "Downloading Image...";
                            FormP.NumberFormat         = "F";
                            FormP.NumberMultiplication = 1;
                            FormP.MaxVal = 100;                          //Doesn't matter what this value is as long as it is greater than 0
                            FormP.TickMS = 1000;
                            OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.DownloadAsync(patfolder
                                                                                                      , doc.FileName
                                                                                                      , new OpenDentalCloud.ProgressHandler(FormP.OnProgress));
                            FormP.ShowDialog();
                            if (FormP.DialogResult == DialogResult.Cancel)
                            {
                                state.DoCancel = true;
                                return;
                            }
                            //Successfully downloaded, now do stuff with state.FileContent
                            FormP                      = new FormProgress();
                            FormP.DisplayText          = "Uploading Image for Claim Attach...";
                            FormP.NumberFormat         = "F";
                            FormP.NumberMultiplication = 1;
                            FormP.MaxVal               = 100;            //Doesn't matter what this value is as long as it is greater than 0
                            FormP.TickMS               = 1000;
                            OpenDentalCloud.Core.TaskStateUpload state2 = CloudStorage.UploadAsync(attachPath
                                                                                                   , newName
                                                                                                   , state.FileContent
                                                                                                   , new OpenDentalCloud.ProgressHandler(FormP.OnProgress));
                            FormP.ShowDialog();
                            if (FormP.DialogResult == DialogResult.Cancel)
                            {
                                state2.DoCancel = true;
                                return;
                            }
                            //Upload was successful
                        }
                    }
                    else
                    {
                        File.Copy(oldPath, newPath);
                    }
                }
                else
                {
                    File.Copy(oldPath, newPath);
                }
                ClaimAttachNew = new ClaimAttach();
                ClaimAttachNew.DisplayedFileName = Docs[gridMain.GetSelectedIndex()].FileName;
                ClaimAttachNew.ActualFileName    = newName;
                DialogResult = DialogResult.OK;
            }
            catch (FileNotFoundException ex) {
                MessageBox.Show(Lan.g(this, "File not found: ") + ex.Message);
                return;
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
Example #18
0
 ///<summary>Inserts one ClaimAttach into the database.  Returns the new priKey.</summary>
 public static long Insert(ClaimAttach claimAttach)
 {
     return(Insert(claimAttach, false));
 }