예제 #1
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());
        }
예제 #2
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            int i;
            PersonAttributeCollection attributes;
            CheckBox cb;
            Literal  lt;

            //
            // Deal with redirects.
            //
            if (!Page.IsPostBack)
            {
                iRedirect.Value = string.Empty;
                if (Request.QueryString["requestpage"] != null)
                {
                    iRedirect.Value = string.Format("default.aspx?page={0}", Request.QueryString["requestpage"]);
                }
                if (iRedirect.Value == string.Empty && Request.QueryString["requestUrl"] != null)
                {
                    iRedirect.Value = Request.QueryString["requestUrl"];
                }
                if (iRedirect.Value == string.Empty)
                {
                    iRedirect.Value = string.Format("default.aspx?page={0}", RedirectPageIDSetting);
                }
            }

            //
            // Walk all the person attributes for the given group and add the
            // appropriate field types to the page. If the user already has
            // a value in the type then put that value in so they can see what
            // they have already entered.
            //
            attributes = new PersonAttributeCollection();
            attributes.LoadByGroup(new AttributeGroup(Convert.ToInt32(AttributeGroupSetting)), CurrentPerson.PersonID);

            // Sort them
            var sortedAttributes = from attribute in attributes orderby attribute.AttributeOrder select attribute;

            foreach (var attribute in sortedAttributes)
            {
                if (attribute.AttributeType == DataType.YesNo)
                {
                    cb         = new CheckBox();
                    cb.Checked = (attribute.IntValue == 1 ? true : false);
                    SetFromAttributeAndAdd(cb, attribute);
                }
                else if (attribute.AttributeType == DataType.String)
                {
                    TextBox tb = new TextBox();
                    tb.Text = HttpUtility.HtmlDecode(attribute.StringValue);
                    SetFromAttributeAndAdd(tb, attribute);
                }
                lt      = new Literal();
                lt.Text = "<br />";
                phAttributes.Controls.Add(lt);
            }

            //
            // Add in a "none of the above" option if requested. This does
            // not do anything on submit, but resolves any "I changed my mind
            // how do I get out" questions.
            //
            if (NoneAboveSetting != false)
            {
                cb      = new CheckBox();
                cb.ID   = "-1";
                cb.Text = "None of the above";
                phAttributes.Controls.Add(cb);
            }
        }