Example #1
0
        /// <summary>
        /// Process contact node.
        /// </summary>
        /// <param name="contact">The contact node.</param>
        /// <returns>The contact information of employee.</returns>
        private String ProcessContact(XPathNavigator contact)
        {
            StringBuilder currentEmployee = new StringBuilder();

            if (contact != null)
            {
                String phone   = HString.CsvSafeTrim(HXml.SelectNodeValue(contact, "phone"));
                String email   = HString.CsvSafeTrim(HXml.SelectNodeValue(contact, "email"));
                String address = this.ProcessAddress(contact.SelectSingleNode("address"));
                currentEmployee.AppendFormat("{0},{1},{2}", address, phone, email);
            }

            return(currentEmployee.ToString());
        }
Example #2
0
        /// <summary>
        /// Process address node.
        /// </summary>
        /// <param name="address">The address node.</param>
        /// <returns>The address of employee.</returns>
        private String ProcessAddress(XPathNavigator address)
        {
            StringBuilder currentEmployee = new StringBuilder();

            if (address != null)
            {
                String state  = HString.CsvSafeTrim(HXml.SelectNodeValue(address, "state"));
                String city   = HString.CsvSafeTrim(HXml.SelectNodeValue(address, "city"));
                String street = HString.CsvSafeTrim(HXml.SelectNodeValue(address, "street"));
                String zip    = HString.CsvSafeTrim(HXml.SelectNodeValue(address, "zip"));
                currentEmployee.AppendFormat("{0},{1},{2},{3}", state, city, street, zip);
            }

            return(currentEmployee.ToString());
        }
Example #3
0
        /// <summary>
        /// Create CSV for each employee.
        /// </summary>
        /// <param name="employee">The employee node.</param>
        /// <param name="transform">The CSV string.</param>
        private void TransformEmployee(XPathNavigator employee, ref StringBuilder transform)
        {
            StringBuilder currentEmployee = new StringBuilder();
            String        guid            = Guid.NewGuid().ToString();
            String        id          = HString.CsvSafeTrim(HXml.SelectNodeValue(employee, "id"));
            String        firstName   = HString.CsvSafeTrim(HXml.SelectNodeValue(employee, "first-name"));
            String        lastName    = HString.CsvSafeTrim(HXml.SelectNodeValue(employee, "last-name"));
            String        title       = HString.CsvSafeTrim(HXml.SelectNodeValue(employee, "title"));
            String        dateOfBirth = HString.CsvSafeTrim(HXml.SelectNodeValue(employee, "date-of-birth"));
            String        contact     = this.ProcessContact(employee.SelectSingleNode("contact"));

            // Set CSV line for this employee.
            currentEmployee.AppendFormat("{0},{1},{2} {3},{4},{5},{6}", guid, id, firstName, lastName, title, dateOfBirth, contact);

            // Append to current transform data.
            transform.AppendLine(currentEmployee.ToString());
        }
Example #4
0
        /// <summary>
        /// Output html to display calendar grid.
        /// </summary>
        /// <param name="displayMonth">The month to display.</param>
        public void LoadCalendar(DateTime displayMonth)
        {
            // Create the xml for the indicated month.
            XmlReader inputXml = HXml.GetXmlReader(this.GetCalendarXml(displayMonth));

            // Set the xslt stylesheet for this transform.
            XslCompiledTransform transformXml = HXml.GetXslt(Server.MapPath("~/CalendarXSLT/Calendar.xslt"));

            // Extend functionality of xslt stylesheet using "HDateTime" utility object.
            XsltArgumentList args = new XsltArgumentList();

            args.AddExtensionObject("urn:dt", new HDateTime());

            // Transform the month xml based on xslt style sheet and save it to a string writer.
            StringWriter writer = HXml.Transform(inputXml, transformXml, args);

            // Output the string, which will be html, to the page.
            this.divCalendar.InnerHtml = writer.ToString();
        }
Example #5
0
        /// <summary>
        /// An employee loaded from the database.
        /// </summary>
        /// <param name="dr">The data row to populate the Employee object.</param>
        public Employee(DataRow dr)
        {
            String employeeXml = HString.SafeTrim(dr["employee_xml"]);

            if (!String.IsNullOrEmpty(employeeXml))
            {
                // NEW WAY

                Employee employee = HXml.DeserializeFromXml <Employee>(employeeXml);
                if (employee != null)
                {
                    this.Guid        = employee.Guid;
                    this.FirstName   = employee.FirstName;
                    this.LastName    = employee.LastName;
                    this.Email       = employee.Email;
                    this.Phone       = employee.Phone;
                    this.State       = employee.State;
                    this.City        = employee.City;
                    this.Street      = employee.Street;
                    this.Zip         = employee.Zip;
                    this.ObjectState = ObjectState.Unchanged;
                }
            }
            else
            {
                // OLD WAY

                this.Guid        = Guid.Parse(HString.SafeTrim(dr["employee_master_guid"]));
                this.FirstName   = HString.SafeTrim(dr["employee_first_name"]);
                this.LastName    = HString.SafeTrim(dr["employee_last_name"]);
                this.Email       = HString.SafeTrim(dr["employee_email"]);
                this.Phone       = HString.SafeTrim(dr["employee_phone"]);
                this.State       = HString.SafeTrim(dr["employee_state"]);
                this.City        = HString.SafeTrim(dr["employee_city"]);
                this.Street      = HString.SafeTrim(dr["employee_street"]);
                this.Zip         = HString.SafeTrim(dr["employee_zip"]);
                this.ObjectState = ObjectState.Unchanged;
            }

            this.UnchangedEmployee = this;
        }
Example #6
0
        /// <summary>
        /// Creates the xml containing the calendar month data.
        /// </summary>
        /// <param name="dt">The month that will be translated into xml.</param>
        /// <returns>A memory stream of the created xml.</returns>
        public MemoryStream GetCalendarXml(DateTime dt)
        {
            // Create xml writer.
            MemoryStream ms  = new MemoryStream();
            XmlWriter    xml = HXml.GetXmlWriterFragment(ms);

            // Get holidays for the month.
            Dictionary <DateTime, String> holidays = HDateTime.GetHolidaysInMonth(dt);

            // Set the first of the month.
            DateTime startofMonth = HDateTime.FirstOfMonth(dt);

            // Start <year>
            xml.WriteStartElement("year");
            xml.WriteAttributeString("value", dt.Year.ToString());

            // Start <month>
            xml.WriteStartElement("month");
            xml.WriteAttributeString("value", dt.Month.ToString());

            // Loop through all the weeks in the month
            for (int i = 0; i < HDateTime.GetNumberOfWeeks(startofMonth, DayOfWeek.Sunday); i++)
            {
                // Set the current day to be the first day in the week, where the first day is a Sunday.
                DateTime currentDay = HDateTime.FirstOfWeek(startofMonth.AddDays(7 * i), DayOfWeek.Sunday);

                if (i == 0)
                {
                    // If this is the beginning of the loop, the first day should always be the first of the current month, which may not be a Sunday.
                    currentDay = startofMonth;
                }

                // Start <week>
                xml.WriteStartElement("week");

                // Loop through each day in the week until Saturday, which will indicate that tomorrow is the start of a new week.
                DayOfWeek nextDay = DayOfWeek.Monday;
                while (nextDay != DayOfWeek.Sunday && currentDay.Month != startofMonth.AddMonths(1).Month)
                {
                    // Start <currentDay.DayOfWeek>
                    xml.WriteStartElement(currentDay.DayOfWeek.ToString().ToLower());
                    xml.WriteAttributeString("day", currentDay.Day.ToString());

                    if (currentDay.Date.Equals(DateTime.Now.Date))
                    {
                        // This is today's date.
                        xml.WriteAttributeString("today", "true");
                    }

                    // Check if this day is a holiday.
                    foreach (KeyValuePair <DateTime, String> holiday in holidays)
                    {
                        if (holiday.Key.Date.Equals(currentDay.Date))
                        {
                            // Add the holiday to this day.
                            xml.WriteStartElement("event");
                            xml.WriteValue(holiday.Value);
                            xml.WriteEndElement();
                        }
                    }

                    // End <currentDay.DayOfWeek>
                    xml.WriteEndElement();

                    // Increment the day.
                    currentDay = currentDay.AddDays(1);
                    nextDay    = currentDay.DayOfWeek;
                }

                // End <week>
                xml.WriteEndElement();
            }

            // End <month>
            xml.WriteEndElement();

            // End <year>
            xml.WriteEndElement();

            // Close the writer.
            xml.Flush();
            xml.Close();

            // Set memory stream position back to the beginning.
            ms.Position = 0;

            return(ms);
        }