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

            if (!useExistingPK && isRandomKeys)
            {
                alertSub.AlertSubNum = ReplicationServers.GetKeyNoCache("alertsub", "AlertSubNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "AlertSubNum,";
            }
            command += "UserNum,ClinicNum,Type,AlertCategoryNum) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(alertSub.AlertSubNum) + ",";
            }
            command +=
                POut.Long(alertSub.UserNum) + ","
                + POut.Long(alertSub.ClinicNum) + ","
                + POut.Int((int)alertSub.Type) + ","
                + POut.Long(alertSub.AlertCategoryNum) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                alertSub.AlertSubNum = Db.NonQ(command, true, "AlertSubNum", "alertSub");
            }
            return(alertSub.AlertSubNum);
        }
Exemple #2
0
 ///<summary>Inserts one AlertSub into the database.  Returns the new priKey.</summary>
 public static long Insert(AlertSub alertSub)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         alertSub.AlertSubNum = DbHelper.GetNextOracleKey("alertsub", "AlertSubNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(alertSub, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     alertSub.AlertSubNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(alertSub, false));
     }
 }
Exemple #3
0
        ///<summary>Inserts one AlertSub into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(AlertSub alertSub, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                alertSub.AlertSubNum = ReplicationServers.GetKey("alertsub", "AlertSubNum");
            }
            string command = "INSERT INTO alertsub (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "AlertSubNum,";
            }
            command += "UserNum,ClinicNum,Type,AlertCategoryNum) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(alertSub.AlertSubNum) + ",";
            }
            command +=
                POut.Long(alertSub.UserNum) + ","
                + POut.Long(alertSub.ClinicNum) + ","
                + POut.Int((int)alertSub.Type) + ","
                + POut.Long(alertSub.AlertCategoryNum) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                alertSub.AlertSubNum = Db.NonQ(command, true, "AlertSubNum", "alertSub");
            }
            return(alertSub.AlertSubNum);
        }
Exemple #4
0
        ///<summary>Updates one AlertSub in the database.</summary>
        public static void Update(AlertSub alertSub)
        {
            string command = "UPDATE alertsub SET "
                             + "UserNum         =  " + POut.Long(alertSub.UserNum) + ", "
                             + "ClinicNum       =  " + POut.Long(alertSub.ClinicNum) + ", "
                             + "Type            =  " + POut.Int((int)alertSub.Type) + ", "
                             + "AlertCategoryNum=  " + POut.Long(alertSub.AlertCategoryNum) + " "
                             + "WHERE AlertSubNum = " + POut.Long(alertSub.AlertSubNum);

            Db.NonQ(command);
        }
Exemple #5
0
        private void butOK_Click(object sender, EventArgs e)
        {
            if (textUserName.Text == "")
            {
                OpenDental.MessageBox.Show(this, "Please enter a username.");
                return;
            }
            if (listUserGroup.SelectedItems.Count == 0)
            {
                OpenDental.MessageBox.Show(this, "Every user must be associated to at least one User Group.");
                return;
            }
            List <AlertSub> listAlertSubsCur = new List <AlertSub>();

            foreach (int index in listAlertSubMulti.SelectedIndices)
            {
                AlertSub alertSub = new AlertSub();
                alertSub.ClinicNum = 0;
                alertSub.UserNum   = Security.CurUser.UserNum;
                alertSub.Type      = (AlertType)index;
                listAlertSubsCur.Add(alertSub);
            }
            AlertSubs.Sync(listAlertSubsCur, _listAlertSubsOld);
            UserCur.IsHidden = checkIsHidden.Checked;
            UserCur.UserName = textUserName.Text;
            if (UserCur.UserNum == Security.CurUser.UserNum)
            {
                Security.CurUser.UserName = textUserName.Text;
                //They changed their logged in user's information.  Update for when they sync then attempt to connect to remote DB.
            }
            UserCur.EmployeeNum        = 0;
            UserCur.ProvNum            = 0;
            UserCur.ClinicNum          = 0;
            UserCur.ClinicIsRestricted = false;
            try{
                if (UserCur.IsNew)
                {
                    //also updates the user's UserNumCEMT to be the user's usernum.
                    long userNum = Userods.Insert(UserCur, listUserGroup.SelectedItems.OfType <ODBoxItem <UserGroup> >().Select(x => x.Tag.UserGroupNum).ToList(), true);
                }
                else
                {
                    Userods.Update(UserCur, listUserGroup.SelectedItems.OfType <ODBoxItem <UserGroup> >().Select(x => x.Tag.UserGroupNum).ToList());
                }
            }
            catch (Exception ex) {
                OpenDental.MessageBox.Show(ex.Message);
                return;
            }
            Cache.Refresh(InvalidType.Security);
            DialogResult = DialogResult.OK;
        }
Exemple #6
0
 ///<summary>Inserts one AlertSub into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(AlertSub alertSub)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(alertSub, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             alertSub.AlertSubNum = DbHelper.GetNextOracleKey("alertsub", "AlertSubNum");                  //Cacheless method
         }
         return(InsertNoCache(alertSub, true));
     }
 }
Exemple #7
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <AlertSub> TableToList(DataTable table)
        {
            List <AlertSub> retVal = new List <AlertSub>();
            AlertSub        alertSub;

            foreach (DataRow row in table.Rows)
            {
                alertSub                  = new AlertSub();
                alertSub.AlertSubNum      = PIn.Long(row["AlertSubNum"].ToString());
                alertSub.UserNum          = PIn.Long(row["UserNum"].ToString());
                alertSub.ClinicNum        = PIn.Long(row["ClinicNum"].ToString());
                alertSub.Type             = (OpenDentBusiness.AlertType)PIn.Int(row["Type"].ToString());
                alertSub.AlertCategoryNum = PIn.Long(row["AlertCategoryNum"].ToString());
                retVal.Add(alertSub);
            }
            return(retVal);
        }
Exemple #8
0
        ///<summary>Updates one AlertSub 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(AlertSub alertSub, AlertSub oldAlertSub)
        {
            string command = "";

            if (alertSub.UserNum != oldAlertSub.UserNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "UserNum = " + POut.Long(alertSub.UserNum) + "";
            }
            if (alertSub.ClinicNum != oldAlertSub.ClinicNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ClinicNum = " + POut.Long(alertSub.ClinicNum) + "";
            }
            if (alertSub.Type != oldAlertSub.Type)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Type = " + POut.Int((int)alertSub.Type) + "";
            }
            if (alertSub.AlertCategoryNum != oldAlertSub.AlertCategoryNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "AlertCategoryNum = " + POut.Long(alertSub.AlertCategoryNum) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE alertsub SET " + command
                      + " WHERE AlertSubNum = " + POut.Long(alertSub.AlertSubNum);
            Db.NonQ(command);
            return(true);
        }
Exemple #9
0
 ///<summary>Returns true if Update(AlertSub,AlertSub) 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(AlertSub alertSub, AlertSub oldAlertSub)
 {
     if (alertSub.UserNum != oldAlertSub.UserNum)
     {
         return(true);
     }
     if (alertSub.ClinicNum != oldAlertSub.ClinicNum)
     {
         return(true);
     }
     if (alertSub.Type != oldAlertSub.Type)
     {
         return(true);
     }
     if (alertSub.AlertCategoryNum != oldAlertSub.AlertCategoryNum)
     {
         return(true);
     }
     return(false);
 }
 ///<summary>Inserts one AlertSub into the database.  Returns the new priKey.</summary>
 public static long Insert(AlertSub alertSub)
 {
     return(Insert(alertSub, false));
 }
 ///<summary>Inserts one AlertSub into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(AlertSub alertSub)
 {
     return(InsertNoCache(alertSub, false));
 }
        ///<summary>Function used by threads to connect to remote databases and sync user settings.</summary>
        private static void ConnectAndSyncUsers(ODThread odThread)
        {
            CentralConnection      connection          = (CentralConnection)odThread.Parameters[0];
            List <CentralUserData> listCentralUserData = (List <CentralUserData>)odThread.Parameters[1];
            string serverName = "";

            if (connection.ServiceURI != "")
            {
                serverName = connection.ServiceURI;
            }
            else
            {
                serverName = connection.ServerName + ", " + connection.DatabaseName;
            }
            if (!CentralConnectionHelper.UpdateCentralConnection(connection, false))            //No updating the cache since we're going to be connecting to multiple remote servers at the same time.
            {
                odThread.Tag = new List <string>()
                {
                    serverName + "\r\n", "", ""
                };
                connection.ConnectionStatus = "OFFLINE";
                return;
            }
            string remoteSyncCode = PrefC.GetStringNoCache(PrefName.CentralManagerSyncCode);

            if (remoteSyncCode != _syncCode)
            {
                if (remoteSyncCode == "")
                {
                    Prefs.UpdateStringNoCache(PrefName.CentralManagerSyncCode, _syncCode);                   //Lock in the sync code for the remote server.
                }
                else
                {
                    odThread.Tag = new List <string>()
                    {
                        serverName + "\r\n", "", remoteSyncCode
                    };
                    return;
                }
            }
            //Get remote users, usergroups, associated permissions, and alertsubs
            List <Userod> listRemoteUsers = Userods.GetUsersNoCache();

            #region Detect Conflicts
            //User conflicts
            bool   nameConflict  = false;
            string nameConflicts = "";
            for (int i = 0; i < _listCEMTUsers.Count; i++)
            {
                for (int j = 0; j < listRemoteUsers.Count; j++)
                {
                    if (listRemoteUsers[j].UserName == _listCEMTUsers[i].UserName && listRemoteUsers[j].UserNumCEMT == 0)                 //User doesn't belong to CEMT
                    {
                        nameConflicts += listRemoteUsers[j].UserName + " already exists in " + serverName + "\r\n";
                        nameConflict   = true;
                        break;
                    }
                }
            }
            if (nameConflict)
            {
                odThread.Tag = new List <string>()
                {
                    serverName + "\r\n", nameConflicts, ""
                };
                return;                //Skip on to the next connection.
            }
            #endregion Detect Conflicts
            List <UserGroup> listRemoteCEMTUserGroups = UserGroups.GetCEMTGroupsNoCache();
            List <UserGroup> listCEMTUserGroups       = new List <UserGroup>();
            List <AlertSub>  listRemoteAlertSubs      = AlertSubs.GetAll();
            List <Clinic>    listRemoteClinics        = Clinics.GetClinicsNoCache();
            List <AlertSub>  listAlertSubsToInsert    = new List <AlertSub>();
            for (int i = 0; i < listCentralUserData.Count; i++)
            {
                listCEMTUserGroups.Add(listCentralUserData[i].UserGroup.Copy());
            }
            //SyncUserGroups returns the list of UserGroups for deletion so it can be used after syncing Users and GroupPermissions.
            List <UserGroup> listRemoteCEMTUserGroupsForDeletion = CentralUserGroups.Sync(listCEMTUserGroups, listRemoteCEMTUserGroups);
            listRemoteCEMTUserGroups = UserGroups.GetCEMTGroupsNoCache();
            for (int i = 0; i < listCentralUserData.Count; i++)
            {
                List <GroupPermission> listGroupPerms = new List <GroupPermission>();
                for (int j = 0; j < listRemoteCEMTUserGroups.Count; j++)
                {
                    if (listCentralUserData[i].UserGroup.UserGroupNumCEMT == listRemoteCEMTUserGroups[j].UserGroupNumCEMT)
                    {
                        for (int k = 0; k < listCentralUserData[i].ListGroupPermissions.Count; k++)
                        {
                            listCentralUserData[i].ListGroupPermissions[k].UserGroupNum = listRemoteCEMTUserGroups[j].UserGroupNum;                          //fixing primary keys to be what's in remote db
                        }
                        listGroupPerms = GroupPermissions.GetPermsNoCache(listRemoteCEMTUserGroups[j].UserGroupNum);
                    }
                }
                CentralUserods.Sync(listCentralUserData[i].ListUsers, listRemoteUsers);
                CentralGroupPermissions.Sync(listCentralUserData[i].ListGroupPermissions, listGroupPerms);
            }
            //Sync usergroup attaches
            SyncUserGroupAttaches(listCentralUserData);
            for (int j = 0; j < listRemoteCEMTUserGroupsForDeletion.Count; j++)
            {
                UserGroups.DeleteNoCache(listRemoteCEMTUserGroupsForDeletion[j]);
            }
            if (_listAlertSubs.Count > 0)
            {
                listRemoteUsers = Userods.GetUsersNoCache();              //Refresh users so we can do alertsubs.
            }
            //For each AlertSub, make a copy of that AlertSub for each Clinic.
            foreach (AlertSub alertSub in _listAlertSubs)
            {
                foreach (Clinic clinic in listRemoteClinics)
                {
                    AlertSub alert = new AlertSub();
                    alert.ClinicNum = clinic.ClinicNum;
                    alert.Type      = alertSub.Type;
                    alert.UserNum   = listRemoteUsers.Find(x => x.UserName == _listCEMTUsers.Find(y => y.UserNum == alertSub.UserNum).UserName).UserNum;
                    listAlertSubsToInsert.Add(alert);
                }
            }
            AlertSubs.DeleteAndInsertForSuperUsers(_listCEMTUsers, listAlertSubsToInsert);
            //Refresh server's cache of userods
            Signalods.SetInvalidNoCache(InvalidType.Security);
            SecurityLogs.MakeLogEntryNoCache(Permissions.SecurityAdmin, 0, "Enterprise Management Tool synced users.");
            odThread.Tag = new List <string>()
            {
                "", "", ""
            };                                                       //No errors.
        }
Exemple #13
0
        public void AlertItems_GetUniqueAlerts_Addclinic()
        {
            //This test will check the funcionality of alert items which are marked to show in all clinics(AlertItem.ClinicNum==-1).
            //Expected behaviour is that a user subscribed to all alert categories, and all clinics(AlertSub.ClinicNum==-1),
            //will see the alert no matter which clinic they are in.
            //In addition, when a new clinic is added, the user will be able to see alerts in that new clinic without the need to reenter
            //FormUserEdit and select "All" again under clinics for alert subscriptions.
            //Clear AlertSub table.
            AlertSubT.ClearAlertSubTable();
            //Create Users
            Userod userAdmin  = UserodT.CreateUser();
            Userod userNormal = UserodT.CreateUser();
            //Create Clinics
            List <Clinic> listClinics = new List <Clinic>();

            for (int i = 0; i < 2; i++)
            {
                listClinics.Add(ClinicT.CreateClinic());
            }
            //Create AlertItems
            //First alert Item is an alert item for all clinics(ClinicNum==-1).
            CreateAlertItem(true);
            //Second AlertItem is an AlertItem for HQ(ClinicNum==0).
            CreateAlertItem(false);
            List <AlertCategory> listAlertCats   = AlertCategories.GetDeepCopy();
            List <AlertSub>      listAlertSubOld = new List <AlertSub>();
            List <AlertSub>      listAlertSubNew = new List <AlertSub>();

            foreach (AlertCategory alertCat in listAlertCats)
            {
                AlertSub alSub = new AlertSub(userAdmin.UserNum, -1, alertCat.AlertCategoryNum);
                listAlertSubNew.Add(alSub);
            }
            AlertSubs.Sync(listAlertSubNew, listAlertSubOld);
            //Check number of alerts which will display in headquarters clinic.
            //Call CheckUniqueAlerts for user subscribed to all alert categories
            List <List <AlertItem> > listUniqueAlertsAll = AlertItems.GetUniqueAlerts(userAdmin.UserNum, 0);
            List <List <AlertItem> > listUniqueAlertsOne = AlertItems.GetUniqueAlerts(userNormal.UserNum, 0);

            //Assert lists are correct
            //UserAdmin should see two alerts, one for the generic headquarters alert and one for the eConnector all clinics alert.
            Assert.AreEqual(2, listUniqueAlertsAll.Count());
            //UserNormal is not subscribed to any clinics or alert categories and should not see any alerts.
            Assert.AreEqual(0, listUniqueAlertsOne.Count());
            //Add clinic
            listClinics.Add(ClinicT.CreateClinic());
            //Check that alert for all clinics is included for userAdmin(subscribed to all clinics)
            listUniqueAlertsAll = AlertItems.GetUniqueAlerts(userAdmin.UserNum, listClinics.LastOrDefault().ClinicNum);
            Assert.AreEqual(1, listUniqueAlertsAll.Count());
            //Check new clinic for user who is not subscribed to all alerts.
            listUniqueAlertsOne = AlertItems.GetUniqueAlerts(userNormal.UserNum, listClinics.LastOrDefault().ClinicNum);
            Assert.AreEqual(0, listUniqueAlertsOne.Count());
            //Add new alert for new clinic only.
            CreateAlertItem(false, listClinics.LastOrDefault().ClinicNum);
            //Check that userAdmin sees new alert item in new clinic. Should have 2, one all clinic econnector alert and the new clinic specific alert.
            listUniqueAlertsAll = AlertItems.GetUniqueAlerts(userAdmin.UserNum, listClinics.LastOrDefault().ClinicNum);
            Assert.AreEqual(2, listUniqueAlertsAll.Count());
            //Check that userNormal sees no alerts in new clinic, as they are not subscribed to any alert categories, nor clinics.
            listUniqueAlertsOne = AlertItems.GetUniqueAlerts(userNormal.UserNum, listClinics.LastOrDefault().ClinicNum);
            Assert.AreEqual(0, listUniqueAlertsOne.Count());
        }