Пример #1
0
        private void ExportFooter(int departmentId, DateTime startDate, DateTime endDate)
        {
            string result = "</dataroot></root>";

            if (_writer != null)
            {
                _writer.Write(result);
                _writer.Flush();
            }

            XMLTicketExport.LastDownload(departmentId, startDate, endDate);
        }
Пример #2
0
        public void Export(int departmentId, DateTime startDate, DateTime endDate, int lastTicketId, int numberOfTicketToReturn)
        {
            string crLf   = new string(new[] { (char)13, (char)10 });
            string result = string.Empty;

            int lastTId = lastTicketId;

            ExportHeader();

            while (!(lastTId < 0))
            {
                DataTable tickets = XMLTicketExport.SelectTickets(departmentId, startDate, endDate, lastTId, numberOfTicketToReturn);
                if (tickets != null)
                {
                    if (tickets.Rows.Count == 0)
                    {
                        lastTId = -1;
                    }

                    foreach (DataRow drTicket in tickets.Rows)
                    {
                        lastTId = drTicket.IsNull("TicketId") ? -1 : (int)drTicket["TicketId"];

                        result = "<Tickets>" + crLf;

                        DataTable dtStructure = _structure.GetDataTable();

                        foreach (DataRow drStructure in dtStructure.Rows)
                        {
                            if (!bool.Parse(drStructure["IsUse"].ToString()))
                            {
                                continue;
                            }

                            string fieldType   = drStructure["Type"].ToString();
                            bool   fieldCustom = bool.Parse(drStructure["IsCustom"].ToString());
                            bool   isCdata     = bool.Parse(drStructure["IsUseCDATA"].ToString());

                            string fieldValue = String.Empty;
                            string fieldName  = drStructure["Name"].ToString();

                            if (!fieldCustom)
                            {
                                if (!drTicket.Table.Columns.Contains(fieldName))
                                {
                                    continue;
                                }

                                fieldValue = drTicket[fieldName].ToString();

                                if (!string.IsNullOrEmpty(fieldValue))
                                {
                                    switch (fieldType)
                                    {
                                    case "datetime":
                                        try
                                        {
                                            result += "<" + drStructure["Name"] + ">" + Functions.DB2UserDateTime(DateTime.Parse(fieldValue)).ToString("yyyy-MM-ddTHH:mm:00") + "</" + drStructure["Name"] + ">" + crLf;
                                        }
                                        catch { }
                                        break;

                                    case "currency":
                                        try
                                        {
                                            double dblValue = double.Parse(drTicket[fieldName].ToString());
                                            fieldValue = dblValue.ToString();
                                            result    += "<" + drStructure["Name"] + ">" + fieldValue + "</" + drStructure["Name"] + ">" + crLf;
                                        }
                                        catch { }
                                        break;

                                    default:
                                        if (!isCdata)
                                        {
                                            result += "<" + drStructure["Name"] + ">" + XMLTicketStructure.EscapeFieldName(fieldValue) + "</" + drStructure["Name"] + ">" + crLf;
                                        }
                                        else
                                        {
                                            result    += "<" + drStructure["Name"] + "><![CDATA[";
                                            fieldValue = fieldValue.Replace("<br>", crLf);
                                            result    += fieldValue;
                                            result    += "]]></" + drStructure["Name"] + ">";
                                            result    += crLf;
                                        }
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                switch (fieldName)
                                {
                                case "TicketPosts":
                                {
                                    Ticket.LogCollection ticketPosts = new Ticket.LogCollection(departmentId, (int)drTicket["TicketId"]);
                                    result    += "<" + drStructure["Name"] + "><![CDATA[";
                                    fieldValue = string.Empty;
                                    foreach (Ticket.LogEntry ticketPost in ticketPosts)
                                    {
                                        if (!string.IsNullOrEmpty(fieldValue))
                                        {
                                            result += "\n\n================================================================================================\n";
                                        }

                                        fieldValue  = "********** ";
                                        fieldValue += Functions.DisplayDateTime(ticketPost.CreatedDate, true);
                                        fieldValue += "\t\t" + ticketPost.LogType + "\t\t\t" + ticketPost.UserLastName + ", " + ticketPost.UserFirstName + " **********\n\n" + ticketPost.LogNote;
                                        fieldValue  = fieldValue.Replace("<br>", crLf);
                                        result     += fieldValue;
                                    }
                                    result += "]]></" + drStructure["Name"] + ">";
                                    result += crLf;
                                }
                                break;

                                //case "Assets":
                                //    DataTable dtAssets = Tickets.SelectAssets(departmentId, lastTId);
                                //    if (dtAssets != null && dtAssets.Rows.Count > 0)
                                //    {
                                //        result += "<" + drStructure["Name"] + "><![CDATA[";
                                //        fieldValue = string.Empty;
                                //        foreach (DataRow drAsset in dtAssets.Rows)
                                //        {
                                //            fieldValue += XMLTicketStructure.EscapeFieldName(drAsset["Name"].ToString()) + ";";
                                //            fieldValue += XMLTicketStructure.EscapeFieldName(drAsset["SerialNumber"].ToString()) + ";";
                                //            fieldValue += XMLTicketStructure.EscapeFieldName(drAsset["AssetTypeName"].ToString()) + ";";
                                //            fieldValue += XMLTicketStructure.EscapeFieldName(drAsset["AssetMakeName"].ToString()) + ";";
                                //            fieldValue += XMLTicketStructure.EscapeFieldName(drAsset["AssetModelName"].ToString()) + crLf;
                                //        }
                                //        fieldValue = fieldValue.TrimEnd((char)10).TrimEnd((char)13);
                                //        result += fieldValue + "]]></" + drStructure["Name"] + ">"+crLf;
                                //    }
                                //    break;
                                default:
                                    if (drTicket.Table.Columns.Contains("CustomXML") && !drTicket.IsNull("CustomXML"))
                                    {
                                        string customXML = drTicket["CustomXML"].ToString();
                                        if (!string.IsNullOrEmpty(customXML))
                                        {
                                            try
                                            {
                                                XmlDocument xmlDocument = new XmlDocument();
                                                xmlDocument.LoadXml(customXML);

                                                XmlNode rootNode = xmlDocument.DocumentElement;
                                                if (rootNode != null)
                                                {
                                                    string  xpath = "field[@id='" + drStructure["CustomId"] + "']/value";
                                                    XmlNode node  = rootNode.SelectSingleNode(xpath);

                                                    if (node != null)
                                                    {
                                                        if (!string.IsNullOrEmpty(node.InnerText))
                                                        {
                                                            result += "<" + fieldName + "><![CDATA[" + node.InnerText + "]]></" + fieldName + ">" + crLf;
                                                        }
                                                    }
                                                }
                                            }
                                            catch { }
                                        }
                                    }
                                    break;
                                }
                            }
                        }

                        result += "</Tickets>" + crLf;

                        if (result != ("<Tickets>" + crLf + "</Tickets>" + crLf) && _writer != null)
                        {
                            _writer.Write(result);
                            _writer.Flush();
                        }
                    }
                }
                else
                {
                    lastTId = -1;
                }
            }

            ExportFooter(departmentId, startDate, endDate);
        }