Пример #1
0
        ///<summary>Inserts one Cdcrec into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(Cdcrec cdcrec, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO cdcrec (";

            if (!useExistingPK && isRandomKeys)
            {
                cdcrec.CdcrecNum = ReplicationServers.GetKeyNoCache("cdcrec", "CdcrecNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "CdcrecNum,";
            }
            command += "CdcrecCode,HeirarchicalCode,Description) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(cdcrec.CdcrecNum) + ",";
            }
            command +=
                "'" + POut.String(cdcrec.CdcrecCode) + "',"
                + "'" + POut.String(cdcrec.HeirarchicalCode) + "',"
                + "'" + POut.String(cdcrec.Description) + "')";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                cdcrec.CdcrecNum = Db.NonQ(command, true, "CdcrecNum", "cdcrec");
            }
            return(cdcrec.CdcrecNum);
        }
Пример #2
0
        ///<summary>Inserts one Cdcrec into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(Cdcrec cdcrec, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                cdcrec.CdcrecNum = ReplicationServers.GetKey("cdcrec", "CdcrecNum");
            }
            string command = "INSERT INTO cdcrec (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "CdcrecNum,";
            }
            command += "CdcrecCode,HeirarchicalCode,Description) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(cdcrec.CdcrecNum) + ",";
            }
            command +=
                "'" + POut.String(cdcrec.CdcrecCode) + "',"
                + "'" + POut.String(cdcrec.HeirarchicalCode) + "',"
                + "'" + POut.String(cdcrec.Description) + "')";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                cdcrec.CdcrecNum = Db.NonQ(command, true, "CdcrecNum", "cdcrec");
            }
            return(cdcrec.CdcrecNum);
        }
Пример #3
0
 ///<summary>Inserts one Cdcrec into the database.  Returns the new priKey.</summary>
 public static long Insert(Cdcrec cdcrec)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         cdcrec.CdcrecNum = DbHelper.GetNextOracleKey("cdcrec", "CdcrecNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(cdcrec, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     cdcrec.CdcrecNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(cdcrec, false));
     }
 }
Пример #4
0
        ///<summary>Updates one Cdcrec in the database.</summary>
        public static void Update(Cdcrec cdcrec)
        {
            string command = "UPDATE cdcrec SET "
                             + "CdcrecCode      = '" + POut.String(cdcrec.CdcrecCode) + "', "
                             + "HeirarchicalCode= '" + POut.String(cdcrec.HeirarchicalCode) + "', "
                             + "Description     = '" + POut.String(cdcrec.Description) + "' "
                             + "WHERE CdcrecNum = " + POut.Long(cdcrec.CdcrecNum);

            Db.NonQ(command);
        }
Пример #5
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<Cdcrec> TableToList(DataTable table){
			List<Cdcrec> retVal=new List<Cdcrec>();
			Cdcrec cdcrec;
			for(int i=0;i<table.Rows.Count;i++) {
				cdcrec=new Cdcrec();
				cdcrec.CdcrecNum       = PIn.Long  (table.Rows[i]["CdcrecNum"].ToString());
				cdcrec.CdcrecCode      = PIn.String(table.Rows[i]["CdcrecCode"].ToString());
				cdcrec.HeirarchicalCode= PIn.String(table.Rows[i]["HeirarchicalCode"].ToString());
				cdcrec.Description     = PIn.String(table.Rows[i]["Description"].ToString());
				retVal.Add(cdcrec);
			}
			return retVal;
		}
Пример #6
0
        ///<summary>Fills the lists containing all races and all ethnicities from the database and fills the lists containing the races and ethnicities
        ///for the patient.</summary>
        private void FillRaceData()
        {
            List <Cdcrec> listCdcrecs = Cdcrecs.GetAll();

            _listAllRaces = listCdcrecs.FindAll(x => x.HeirarchicalCode.StartsWith("R") && x.HeirarchicalCode != "R")        //Race codes start with R.
                            .OrderBy(x => x.HeirarchicalCode).ToList();
            _listAllEthnicities = listCdcrecs.FindAll(x => x.HeirarchicalCode.StartsWith("E") && x.HeirarchicalCode != "E")  //Ethnicity codes start with E.
                                  .OrderBy(x => x.HeirarchicalCode).ToList();
            Cdcrec declinedSpecify = new Cdcrec {
                Description      = Lan.g(this, "DECLINED TO SPECIFY"),
                CdcrecCode       = PatientRace.DECLINE_SPECIFY_RACE_CODE,
                HeirarchicalCode = ""
            };

            _listAllRaces.Add(declinedSpecify);
            declinedSpecify = new Cdcrec {
                Description      = Lan.g(this, "DECLINED TO SPECIFY"),
                CdcrecCode       = PatientRace.DECLINE_SPECIFY_ETHNICITY_CODE,
                HeirarchicalCode = ""
            };
            _listAllEthnicities.Add(declinedSpecify);
            _listPatRaces       = new List <Cdcrec>();
            _listPatEthnicities = new List <Cdcrec>();
            foreach (PatientRace patRace in _listAllPatientRaces)
            {
                Cdcrec cdcrec = _listAllRaces.FirstOrDefault(x => x.CdcrecCode == patRace.CdcrecCode);
                if (cdcrec != null)
                {
                    _listPatRaces.Add(cdcrec);
                }
                cdcrec = _listAllEthnicities.FirstOrDefault(x => x.CdcrecCode == patRace.CdcrecCode);
                if (cdcrec != null)
                {
                    _listPatEthnicities.Add(cdcrec);
                }
                if (patRace.CdcrecCode == PatientRace.MULTI_RACE_CODE)
                {
                    cdcrec = new Cdcrec {
                        Description      = Lan.g(this, "MULTIRACIAL"),
                        CdcrecCode       = PatientRace.MULTI_RACE_CODE,
                        HeirarchicalCode = ""
                    };
                    _listPatRaces.Add(cdcrec);
                }
            }
            if (_listAllRaces.Count > 1 && _listAllEthnicities.Count > 1)             //Greater than 1 because we always add 'Declined to Specify'
            {
                labelNeedCodes.Visible = false;
                butImport.Visible      = false;
            }
        }
Пример #7
0
 ///<summary>Inserts one Cdcrec into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(Cdcrec cdcrec)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(cdcrec, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             cdcrec.CdcrecNum = DbHelper.GetNextOracleKey("cdcrec", "CdcrecNum");                  //Cacheless method
         }
         return(InsertNoCache(cdcrec, true));
     }
 }
Пример #8
0
 ///<summary>Returns true if Update(Cdcrec,Cdcrec) 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(Cdcrec cdcrec, Cdcrec oldCdcrec)
 {
     if (cdcrec.CdcrecCode != oldCdcrec.CdcrecCode)
     {
         return(true);
     }
     if (cdcrec.HeirarchicalCode != oldCdcrec.HeirarchicalCode)
     {
         return(true);
     }
     if (cdcrec.Description != oldCdcrec.Description)
     {
         return(true);
     }
     return(false);
 }
Пример #9
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <Cdcrec> TableToList(DataTable table)
        {
            List <Cdcrec> retVal = new List <Cdcrec>();
            Cdcrec        cdcrec;

            foreach (DataRow row in table.Rows)
            {
                cdcrec                  = new Cdcrec();
                cdcrec.CdcrecNum        = PIn.Long(row["CdcrecNum"].ToString());
                cdcrec.CdcrecCode       = PIn.String(row["CdcrecCode"].ToString());
                cdcrec.HeirarchicalCode = PIn.String(row["HeirarchicalCode"].ToString());
                cdcrec.Description      = PIn.String(row["Description"].ToString());
                retVal.Add(cdcrec);
            }
            return(retVal);
        }
Пример #10
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <Cdcrec> TableToList(DataTable table)
        {
            List <Cdcrec> retVal = new List <Cdcrec>();
            Cdcrec        cdcrec;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                cdcrec                  = new Cdcrec();
                cdcrec.CdcrecNum        = PIn.Long(table.Rows[i]["CdcrecNum"].ToString());
                cdcrec.CdcrecCode       = PIn.String(table.Rows[i]["CdcrecCode"].ToString());
                cdcrec.HeirarchicalCode = PIn.String(table.Rows[i]["HeirarchicalCode"].ToString());
                cdcrec.Description      = PIn.String(table.Rows[i]["Description"].ToString());
                retVal.Add(cdcrec);
            }
            return(retVal);
        }
Пример #11
0
 private void butRight_Click(object sender, EventArgs e)
 {
     //Remove the selected rows in the Race grid
     foreach (int selectedIndex in gridRace.SelectedIndices)
     {
         Cdcrec race = (Cdcrec)gridRace.Rows[selectedIndex].Tag;
         _listPatRaces.RemoveAll(x => x.CdcrecCode == race.CdcrecCode);
     }
     FillGrid(gridRace, _listPatRaces);
     //Remove the selected rows in the Ethnicities grid
     foreach (int selectedIndex in gridEthnicity.SelectedIndices)
     {
         Cdcrec ethnicity = (Cdcrec)gridEthnicity.Rows[selectedIndex].Tag;
         _listPatEthnicities.RemoveAll(x => x.CdcrecCode == ethnicity.CdcrecCode);
     }
     FillGrid(gridEthnicity, _listPatEthnicities);
 }
Пример #12
0
        ///<summary>Updates one Cdcrec 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(Cdcrec cdcrec, Cdcrec oldCdcrec)
        {
            string command = "";

            if (cdcrec.CdcrecCode != oldCdcrec.CdcrecCode)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "CdcrecCode = '" + POut.String(cdcrec.CdcrecCode) + "'";
            }
            if (cdcrec.HeirarchicalCode != oldCdcrec.HeirarchicalCode)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "HeirarchicalCode = '" + POut.String(cdcrec.HeirarchicalCode) + "'";
            }
            if (cdcrec.Description != oldCdcrec.Description)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Description = '" + POut.String(cdcrec.Description) + "'";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE cdcrec SET " + command
                      + " WHERE CdcrecNum = " + POut.Long(cdcrec.CdcrecNum);
            Db.NonQ(command);
            return(true);
        }
Пример #13
0
		///<summary>Inserts one Cdcrec into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(Cdcrec cdcrec,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				cdcrec.CdcrecNum=ReplicationServers.GetKey("cdcrec","CdcrecNum");
			}
			string command="INSERT INTO cdcrec (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="CdcrecNum,";
			}
			command+="CdcrecCode,HeirarchicalCode,Description) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(cdcrec.CdcrecNum)+",";
			}
			command+=
				 "'"+POut.String(cdcrec.CdcrecCode)+"',"
				+"'"+POut.String(cdcrec.HeirarchicalCode)+"',"
				+"'"+POut.String(cdcrec.Description)+"')";
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command);
			}
			else {
				cdcrec.CdcrecNum=Db.NonQ(command,true);
			}
			return cdcrec.CdcrecNum;
		}
Пример #14
0
		///<summary>Inserts one Cdcrec into the database.  Returns the new priKey.</summary>
		public static long Insert(Cdcrec cdcrec){
			if(DataConnection.DBtype==DatabaseType.Oracle) {
				cdcrec.CdcrecNum=DbHelper.GetNextOracleKey("cdcrec","CdcrecNum");
				int loopcount=0;
				while(loopcount<100){
					try {
						return Insert(cdcrec,true);
					}
					catch(Oracle.DataAccess.Client.OracleException ex){
						if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
							cdcrec.CdcrecNum++;
							loopcount++;
						}
						else{
							throw ex;
						}
					}
				}
				throw new ApplicationException("Insert failed.  Could not generate primary key.");
			}
			else {
				return Insert(cdcrec,false);
			}
		}
Пример #15
0
 ///<summary>Inserts one Cdcrec into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(Cdcrec cdcrec)
 {
     return(InsertNoCache(cdcrec, false));
 }
Пример #16
0
		///<summary>Updates one Cdcrec 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(Cdcrec cdcrec,Cdcrec oldCdcrec){
			string command="";
			if(cdcrec.CdcrecCode != oldCdcrec.CdcrecCode) {
				if(command!=""){ command+=",";}
				command+="CdcrecCode = '"+POut.String(cdcrec.CdcrecCode)+"'";
			}
			if(cdcrec.HeirarchicalCode != oldCdcrec.HeirarchicalCode) {
				if(command!=""){ command+=",";}
				command+="HeirarchicalCode = '"+POut.String(cdcrec.HeirarchicalCode)+"'";
			}
			if(cdcrec.Description != oldCdcrec.Description) {
				if(command!=""){ command+=",";}
				command+="Description = '"+POut.String(cdcrec.Description)+"'";
			}
			if(command==""){
				return false;
			}
			command="UPDATE cdcrec SET "+command
				+" WHERE CdcrecNum = "+POut.Long(cdcrec.CdcrecNum);
			Db.NonQ(command);
			return true;
		}
Пример #17
0
		///<summary>Updates one Cdcrec in the database.</summary>
		public static void Update(Cdcrec cdcrec){
			string command="UPDATE cdcrec SET "
				+"CdcrecCode      = '"+POut.String(cdcrec.CdcrecCode)+"', "
				+"HeirarchicalCode= '"+POut.String(cdcrec.HeirarchicalCode)+"', "
				+"Description     = '"+POut.String(cdcrec.Description)+"' "
				+"WHERE CdcrecNum = "+POut.Long(cdcrec.CdcrecNum);
			Db.NonQ(command);
		}
Пример #18
0
 ///<summary>Inserts one Cdcrec into the database.  Returns the new priKey.</summary>
 public static long Insert(Cdcrec cdcrec)
 {
     return(Insert(cdcrec, false));
 }