示例#1
0
        public int CompareTo(object obj)
        {
            StaffMember staff2        = (StaffMember)obj;
            int         compareResult = 0;

            // Compare Department
            compareResult = Department.Order.CompareTo(staff2.Department.Order);
            if (compareResult != 0)
            {
                return(compareResult);
            }

            // Compare Department Position
            compareResult = DepartmentPosition.Order.CompareTo(staff2.DepartmentPosition.Order);
            if (compareResult != 0)
            {
                return(compareResult);
            }

            // Compare Last Name
            compareResult = LastName.CompareTo(staff2.LastName);
            if (compareResult != 0)
            {
                return(compareResult);
            }

            // Compare First Name
            return(FirstName.CompareTo(staff2.FirstName));
        }
示例#2
0
        private string CreateStaffXML()
        {
            StringBuilder sbMessages = new StringBuilder();

            AttributeGroup StaffDetailsGroup = new AttributeGroup(StaffDetailsAttributeGroupID);

            Arena.Core.Attribute departmentAttribute = new Arena.Core.Attribute(DepartmentAttributeID);
            LookupType           departments         = new LookupType(Convert.ToInt32(departmentAttribute.TypeQualifier));

            List <StaffMember> staff  = new List <StaffMember>();
            PersonCollection   people = new PersonCollection();

            people.LoadStaffMembers();
            foreach (Person person in people)
            {
                string title              = string.Empty;
                Lookup department         = null;
                Lookup departmentPosition = null;

                PersonAttribute pa = (PersonAttribute)person.Attributes.FindByID(PositionAttributeID);
                if (pa != null)
                {
                    title = pa.StringValue;
                }

                pa = (PersonAttribute)person.Attributes.FindByID(DepartmentAttributeID);
                if (pa != null && pa.IntValue != -1)
                {
                    department = new Lookup(pa.IntValue);
                }

                pa = (PersonAttribute)person.Attributes.FindByID(DepartmentPositionAttributeID);
                if (pa != null && pa.IntValue != -1)
                {
                    departmentPosition = new Lookup(pa.IntValue);
                }

                if (department != null && departmentPosition != null)
                {
                    staff.Add(new StaffMember(
                                  person.PersonID,
                                  person.PersonGUID,
                                  person.NickName,
                                  person.LastName,
                                  person.Blob != null ? person.Blob.GUID : Guid.Empty,
                                  person.Emails.FirstActive,
                                  title,
                                  department,
                                  departmentPosition));
                }
            }

            staff.Sort();

            // Delete any existing department XML files in the staff folder
            DirectoryInfo staffFolder = new DirectoryInfo(Path.Combine(XMLFolderPath, "Staff"));

            if (staffFolder.Exists)
            {
                foreach (FileInfo fi in staffFolder.GetFiles())
                {
                    try
                    {
                        fi.Delete();
                    }
                    catch (System.Exception ex)
                    {
                        sbMessages.AppendFormat("Could not delete {0} file: {1}\n", fi.FullName, ex.Message);
                    }
                }
            }
            else
            {
                staffFolder.Create();
            }

            if (staff.Count > 0)
            {
                LookupCollection activeDepartments = new LookupCollection();

                Lookup      currentDepartment = new Lookup();
                XmlDocument xdoc           = null;
                XmlNode     departmentNode = null;

                foreach (StaffMember StaffMember in staff)
                {
                    if (currentDepartment.LookupID != StaffMember.Department.LookupID)
                    {
                        if (xdoc != null)
                        {
                            string path = Path.Combine(staffFolder.FullName, currentDepartment.Guid.ToString() + ".xml");
                            try
                            {
                                xdoc.Save(path);
                            }
                            catch (System.Exception ex)
                            {
                                sbMessages.AppendFormat("Could not save {0} file: {1}\n", path, ex.Message);
                            }
                        }

                        currentDepartment = StaffMember.Department;
                        activeDepartments.Add(currentDepartment);

                        xdoc           = new XmlDocument();
                        departmentNode = xdoc.CreateNode(XmlNodeType.Element, "department", xdoc.NamespaceURI);
                        XmlAttribute xattr = xdoc.CreateAttribute("", "name", xdoc.NamespaceURI);
                        xattr.Value = currentDepartment.Value;
                        departmentNode.Attributes.Append(xattr);
                        xdoc.AppendChild(departmentNode);
                    }

                    departmentNode.AppendChild(StaffMember.XMLNode(xdoc));

                    if (StaffMember.DepartmentPosition.Qualifier2 == "1")
                    {
                        XmlDocument xdocStaff  = new XmlDocument();
                        XmlNode     xnodeStaff = StaffMember.XMLNode(xdocStaff);
                        xdocStaff.AppendChild(xnodeStaff);

                        if (_assistantTypeID != -1)
                        {
                            RelationshipCollection relationships = new RelationshipCollection(StaffMember.ID);
                            foreach (Relationship relationship in relationships)
                            {
                                if (relationship.RelationshipTypeId == _assistantTypeID)
                                {
                                    XmlNode xnodeAssistant = xdocStaff.CreateNode(XmlNodeType.Element, "assistant", xdocStaff.NamespaceURI);

                                    XmlAttribute xattr = xdocStaff.CreateAttribute("", "fn", xdocStaff.NamespaceURI);
                                    xattr.Value = relationship.RelatedPerson.NickName;
                                    xnodeAssistant.Attributes.Append(xattr);

                                    xattr       = xdocStaff.CreateAttribute("", "ln", xdocStaff.NamespaceURI);
                                    xattr.Value = relationship.RelatedPerson.LastName;
                                    xnodeAssistant.Attributes.Append(xattr);

                                    xattr       = xdocStaff.CreateAttribute("", "email", xdocStaff.NamespaceURI);
                                    xattr.Value = relationship.RelatedPerson.Emails.FirstActive;
                                    xnodeAssistant.Attributes.Append(xattr);

                                    xnodeStaff.AppendChild(xnodeAssistant);

                                    break;
                                }
                            }
                        }

                        PersonAttributeCollection pAttributes = new PersonAttributeCollection();
                        pAttributes.LoadByGroup(StaffDetailsGroup, StaffMember.ID);
                        foreach (PersonAttribute pa in pAttributes)
                        {
                            if (pa.AttributeType == Arena.Enums.DataType.Document)
                            {
                                if (BioDocumentTypeID != -1 && pa.TypeQualifier == BioDocumentTypeID.ToString())
                                {
                                    Arena.Utility.ArenaDataBlob bioDoc = new Arena.Utility.ArenaDataBlob(pa.IntValue);
                                    if (bioDoc.FileExtension == "txt")
                                    {
                                        ASCIIEncoding enc = new ASCIIEncoding();
                                        string        bio = enc.GetString(bioDoc.ByteArray);

                                        if (bio != string.Empty)
                                        {
                                            XmlNode xnodeBio = xdocStaff.CreateNode(XmlNodeType.Element, "biography", xdocStaff.NamespaceURI);
                                            xnodeBio.AppendChild(xdocStaff.CreateCDataSection(bio));
                                            xnodeStaff.AppendChild(xnodeBio);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                XmlNode xnodeAttribute = xdocStaff.CreateNode(XmlNodeType.Element, "attribute", xdocStaff.NamespaceURI);

                                XmlAttribute xattr = xdocStaff.CreateAttribute("", "name", xdocStaff.NamespaceURI);
                                xattr.Value = pa.AttributeName;
                                xnodeAttribute.Attributes.Append(xattr);

                                xattr       = xdocStaff.CreateAttribute("", "value", xdocStaff.NamespaceURI);
                                xattr.Value = pa.ToString();
                                xnodeAttribute.Attributes.Append(xattr);

                                xnodeStaff.AppendChild(xnodeAttribute);
                            }
                        }

                        string path = Path.Combine(staffFolder.FullName, StaffMember.Guid.ToString() + ".xml");
                        try
                        {
                            xdocStaff.Save(path);
                        }
                        catch (System.Exception ex)
                        {
                            sbMessages.AppendFormat("Could not save {0} file: {1}\n", path, ex.Message);
                        }
                    }
                }

                if (xdoc != null)
                {
                    string path = Path.Combine(staffFolder.FullName, currentDepartment.Guid.ToString() + ".xml");
                    try
                    {
                        xdoc.Save(path);
                    }
                    catch (System.Exception ex)
                    {
                        sbMessages.AppendFormat("Could not save {0} file: {1}\n", path, ex.Message);
                    }
                }

                XmlDocument xdocDepartments  = new XmlDocument();
                XmlNode     xnodeDepartments = xdocDepartments.CreateNode(XmlNodeType.Element, "departments", xdocDepartments.NamespaceURI);
                xdocDepartments.AppendChild(xnodeDepartments);

                foreach (Lookup activeDepartment in activeDepartments)
                {
                    XmlNode xnodeDepartment = xdocDepartments.CreateNode(XmlNodeType.Element, "department", xdocDepartments.NamespaceURI);

                    XmlAttribute xattr = xdocDepartments.CreateAttribute("", "guid", xdocDepartments.NamespaceURI);
                    xattr.Value = activeDepartment.Guid.ToString();
                    xnodeDepartment.Attributes.Append(xattr);

                    xattr       = xdocDepartments.CreateAttribute("", "name", xdocDepartments.NamespaceURI);
                    xattr.Value = activeDepartment.Value;
                    xnodeDepartment.Attributes.Append(xattr);

                    XmlNode xnodeDeptDescription = xdocDepartments.CreateNode(XmlNodeType.Element, "description", xdocDepartments.NamespaceURI);
                    xnodeDeptDescription.InnerText = activeDepartment.Qualifier8;
                    xnodeDepartment.AppendChild(xnodeDeptDescription);

                    xnodeDepartments.AppendChild(xnodeDepartment);
                }

                try
                {
                    xdocDepartments.Save(Path.Combine(staffFolder.FullName, "departments.xml"));
                }
                catch (System.Exception ex)
                {
                    sbMessages.AppendFormat("Could not save {0} file: {1}\n", Path.Combine(staffFolder.FullName, "departments.xml"), ex.Message);
                }
            }

            return(sbMessages.ToString());
        }