Esempio n. 1
0
        private string GetGroup(MassEmailSendArgs args)
        {
            string result = string.Empty;

            switch (args.Group)
            {
            case "community":
                result = string.Join(", ", CommunityUtility.GetCommunityNames(Combine(args.Values)));
                break;

            case "manager":
                result = Client.GetClient(args.Values.First()).DisplayName;
                break;

            case "tools":
                result = string.Join(", ", Resource.GetResources(args.Values).Select(x => x.ResourceName));
                break;

            case "lab":
                result = string.Join(", ", Room.GetPassbackRooms().Where(x => args.Values.Contains(x.AreaID)).Select(x => x.AreaName));
                break;

            default:     //privilege
                result = string.Join(", ", PrivUtility.GetPrivTypes((ClientPrivilege)Combine(args.Values)));
                break;
            }

            return(result);
        }
        public void CanStoreClientInfo()
        {
            DataSet dsClient            = DataUtility.GetClientDataSet(17);
            int     clientId            = 0;
            int     selectedClientOrgId = 0;

            DataUtility.StoreClientInfo(
                dtClient: dsClient.Tables["Client"],
                dtClientOrg: dsClient.Tables["ClientOrg"],
                dtClientAccount: dsClient.Tables["ClientAccount"],
                dtClientManager: dsClient.Tables["ClientManager"],
                dtAddress: dsClient.Tables["Address"],
                isNewClientEntry: true,
                addExistingClient: false,
                orgId: 17,
                username: "******" + DateTime.Now.Ticks.ToString(),
                lname: "user",
                fname: "test",
                mname: string.Empty,
                demCitizenId: 1,
                demEthnicId: 1,
                demRaceId: 1,
                demGenderId: 1,
                demDisabilityId: 1,
                privs: PrivUtility.CalculatePriv(ClientPrivilege.LabUser | ClientPrivilege.PhysicalAccess | ClientPrivilege.OnlineAccess),
                communities: 0,
                technicalInterestId: 1,
                roleId: 1,
                departmentId: 1,
                email: "*****@*****.**",
                phone: string.Empty,
                isManager: false,
                isFinManager: false,
                subsidyStartDate: DateTime.Now,
                newFacultyStartDate: DateTime.Now,
                clientId: ref clientId,
                clientOrgId: ref selectedClientOrgId,
                alertMsg: out string alertMsg,
                enableAccessError: out bool enableAccessError);
        }
Esempio n. 3
0
 protected override string GetGroupName()
 {
     return(string.Join(", ", PrivUtility.GetPrivTypes((ClientPrivilege)SelectedPrivileges)));
 }
Esempio n. 4
0
        public static void StoreClientInfo(DataTable dtClient, DataTable dtClientOrg, DataTable dtClientAccount, DataTable dtClientManager, DataTable dtAddress, bool isNewClientEntry, bool addExistingClient, int orgId, string username, string lname, string fname, string mname, int demCitizenId, int demEthnicId, int demRaceId, int demGenderId, int demDisabilityId, int privs, int communities, int technicalInterestId, int roleId, int departmentId, string email, string phone, bool isManager, bool isFinManager, DateTime subsidyStartDate, DateTime newFacultyStartDate, ref int clientId, ref int clientOrgId, out string alertMsg, out bool enableAccessError)
        {
            // add rows to Client, ClientSite and ClientOrg for new entries
            bool isNewClientOrgEntry = false;

            DataRow cdr;

            if (isNewClientEntry)
            {
                // add an entry to the client table
                cdr = dtClient.NewRow();
                cdr.SetField("DisplayName", string.Format("{0}, {1}", lname, fname)); // has to be done here
                clientId = cdr.Field <int>("ClientID");
            }
            else
            {
                // get the entry in the client table
                cdr = dtClient.Rows.Find(clientId);
            }

            // if entering new or modifying, update the fields
            if (!addExistingClient)
            {
                cdr.SetField("FName", fname);
                cdr.SetField("LName", lname);

                // strip period if entered
                if (mname.Length > 0)
                {
                    if (mname.EndsWith("."))
                    {
                        mname = mname.Remove(mname.Length - 1, 1);
                    }
                }
                cdr.SetField("MName", mname);

                cdr.SetField("UserName", username);

                //Encryption enc = new Encryption();
                //cdr.SetField("Password", enc.EncryptText(username));
                cdr.SetField("Password", DBNull.Value);
                cdr.SetField("PasswordHash", DBNull.Value);

                cdr.SetField("DemCitizenID", demCitizenId);
                cdr.SetField("DemEthnicID", demEthnicId);
                cdr.SetField("DemRaceID", demRaceId);
                cdr.SetField("DemGenderID", demGenderId);
                cdr.SetField("DemDisabilityID", demDisabilityId);

                // store Privs's
                cdr.SetField("Privs", privs);

                cdr.SetField("Communities", communities);

                cdr.SetField("TechnicalInterestID", technicalInterestId);
            }

            // next the ClientOrg table
            DataRow codr;

            DataRow[] codrs = dtClientOrg.Select(string.Format("ClientID = {0} AND OrgID = {1}", clientId, orgId));

            if (codrs.Length == 0) // need new row in clientOrg
            {
                isNewClientOrgEntry = true;
                codr = dtClientOrg.NewRow();
                codr.SetField("ClientID", clientId);
                codr.SetField("OrgID", orgId);
                codr.SetField("Active", true);
                codr.SetField("ClientAddressID", 0);
            }
            else
            {
                codr        = codrs[0];
                clientOrgId = codr.Field <int>("ClientOrgID");
                if (!codr.Field <bool>("Active"))
                {
                    codr.SetField("Active", true);
                }
            }

            codr.SetField("RoleID", roleId);
            codr.SetField("DepartmentID", departmentId);
            codr.SetField("Email", email);
            codr.SetField("Phone", phone);
            codr.SetField("IsManager", isManager);
            codr.SetField("IsFinManager", isFinManager);
            codr.SetField("SubsidyStartDate", subsidyStartDate);
            codr.SetField("NewFacultyStartDate", newFacultyStartDate);

            // find any address that need to be dealt with
            DataRow[] sdrs = dtAddress.Select("AddDelete IS NOT NULL");
            for (int i = 0; i < sdrs.Length; i++)
            {
                if (sdrs[i].Field <bool>("AddDelete")) // addr was added
                {
                    int addressId = 0;
                    if (sdrs[i]["AddressID"] != DBNull.Value)
                    {
                        addressId = sdrs[i].Field <int>("AddressID");
                    }
                    codr.SetField("ClientAddressID", addressId);
                    sdrs[i].SetField("AddDelete", DBNull.Value);
                }
                else
                {
                    codr.SetField("ClientAddressID", 0);
                    sdrs[i].Delete();
                }
            }

            if (isNewClientOrgEntry)
            {
                dtClientOrg.Rows.Add(codr);
            }

            // update rows in ClientManager as needed
            DataRow[] cmdrs = dtClientManager.Select("ClientOrgID = 0");
            for (int i = 0; i < cmdrs.Length; i++)
            {
                cmdrs[i].SetField("ClientOrgID", codr.Field <int>("ClientOrgID"));
            }

            // update rows in ClientAccount as needed
            DataRow[] cadrs = dtClientAccount.Select("ClientOrgID = 0");
            for (int i = 0; i < cadrs.Length; i++)
            {
                cadrs[i].SetField("ClientOrgID", codr.Field <int>("ClientOrgID"));
            }

            // done here after ClientAccount has been updated
            if (addExistingClient) // reenabling a client
            {
                cdr.SetField("EnableAccess", PrivUtility.HasPriv((ClientPrivilege)cdr.Field <int>("Privs"), ClientPrivilege.PhysicalAccess));
            }
            else
            {
                cdr.SetField("EnableAccess", PrivUtility.HasPriv((ClientPrivilege)privs, ClientPrivilege.PhysicalAccess));
            }

            alertMsg = string.Empty;
            // for clients who have Lab User Privs only, only allow access if s/he has an active account
            // if access is not enabled, show an alert
            if (cdr.Field <bool>("EnableAccess"))
            {
                if (!HasActiveAccount(cdr, dtClientOrg, dtClientAccount))
                {
                    cdr.SetField("EnableAccess", false);
                    alertMsg = "Store and physical access disabled for this client - no active accounts.";
                }
            }

            // if client has been disabled for a 'long time', do not enable access and alert user
            enableAccessError = false;
            if (addExistingClient && cdr.Field <bool>("EnableAccess"))
            {
                try
                {
                    int  cid    = cdr.Field <int>("ClientID");
                    bool result = DataCommand.Create()
                                  .Param("Action", "AllowReenable")
                                  .Param("ClientID", cid)
                                  .ExecuteScalar <bool>("NexWatch_Select").Value;
                    cdr.SetField("EnableAccess", result);
                }
                catch (Exception ex)
                {
                    enableAccessError = true;
                    alertMsg          = ex.Message;
                    return;
                }

                if (!cdr.Field <bool>("EnableAccess"))
                {
                    int p = cdr.Field <int>("Privs") - (int)ClientPrivilege.PhysicalAccess;
                    cdr.SetField("Privs", p);
                    alertMsg += "Note that this client has been inactive for so long that access is not automatically reenabled. Please see the Lab Manager.";
                }
            }

            if (isNewClientEntry)
            {
                dtClient.Rows.Add(cdr);
            }
        }
Esempio n. 5
0
        public bool IncludeOnMatrix(IClientAccountAssignment x)
        {
            bool res = Display(x) && PrivUtility.HasPriv(x.EmployeePrivs, PrivFilter);

            return(res);
        }