コード例 #1
0
 /// ------------------------------------------------------------------------------------
 public RecordCache(PaProject project)
 {
     _project           = project;
     _phoneticFieldName = _project.GetPhoneticField().Name;
     PhoneCache         = new PhoneCache(project);
     RecordCacheEntry.ResetCounter();
 }
コード例 #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Deserializes a PAXML file to a RecordCache instance.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static RecordCache Load(PaDataSource dataSource, PaProject project)
        {
            if (dataSource == null)
            {
                return(null);
            }

            string filename = dataSource.SourceFile;

            try
            {
                var paxmlcontent = XmlSerializationHelper.DeserializeFromFile <PaXMLContent>(filename);
                var cache        = (paxmlcontent == null ? null : paxmlcontent.Cache);

                if (cache == null)
                {
                    return(null);
                }

                cache._project           = project;
                cache._phoneticFieldName = project.GetPhoneticField().Name;
                string fwServer;
                string fwDBName;
                PaDataSource.GetPaXmlType(filename, out fwServer, out fwDBName);

                foreach (var entry in cache)
                {
                    entry.PostDeserializeProcess(dataSource, project);

                    if (entry.FieldValues.Count > 0 &&
                        (entry.WordEntries == null || entry.WordEntries.Count == 0))
                    {
                        entry.NeedsParsing = true;
                    }
                }

                return(cache);
            }
            catch (Exception e)
            {
                var msg = LocalizationManager.GetString("Miscellaneous.Messages.DataSourceReading.LoadingRecordCacheErrorMsg",
                                                        "The following error occurred while loading '{0}'",
                                                        "Message displayed when failing to load a PaXml file.");

                App.NotifyUserOfProblem(e, msg, filename);
                return(null);
            }
        }
コード例 #3
0
        /// ------------------------------------------------------------------------------------
        protected ExporterBase(PaProject project, string outputFileName,
                               OutputFormat outputFormat, DataGridView dgrid) : this(project)
        {
            m_outputFileName = outputFileName;
            m_outputFormat   = outputFormat;
            m_grid           = dgrid;

            var grid = m_grid as PaWordListGrid;
            if (grid == null)
            {
                return;
            }

            if (grid.Cache.IsMinimalPair || grid.Cache.IsSimilarEnvironment)
            {
                m_groupByColumn = grid.PhoneticColumn;
            }
            else if (grid.IsGroupedByField)
            {
                m_groupByColumn = grid.GroupByColumn;
            }

            m_isGridGrouped = (grid.Columns[0] is SilHierarchicalGridColumn && m_groupByColumn != null);

            if (m_isGridGrouped)
            {
                int groupByColIndex = m_groupByColumn.DisplayIndex;

                // Subtract on at the end to account for the column containing the
                // expand/collapse glyph. That doesn't count in the col. span.
                m_leftColSpanForGroupedList = (from x in m_grid.Columns.Cast <DataGridViewColumn>()
                                               where x.Visible && x.DisplayIndex < groupByColIndex
                                               select x).Count() - 1;

                m_rightColSpanForGroupedList = (from x in m_grid.Columns.Cast <DataGridViewColumn>()
                                                where x.Visible && x.DisplayIndex > groupByColIndex
                                                select x).Count();

                var field = project.GetPhoneticField();
                m_groupByField     = (grid.Cache.IsMinimalPair || grid.Cache.IsSimilarEnvironment ? field : ((PaWordListGrid)m_grid).GroupByField);
                m_groupedFieldName = ProcessHelper.MakeAlphaNumeric(m_groupByField.DisplayName);
            }
        }
コード例 #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// SortOptions constructor.
        /// </summary>
        /// <param name="initializeWithPhonetic">Indicates whether or not the new SortOptions
        /// object's SortInformationList should contain phonetic as the default field
        /// on which to sort.</param>
        /// <param name="project"></param>
        /// ------------------------------------------------------------------------------------
        public SortOptions(bool initializeWithPhonetic, PaProject project)
        {
            // Keeps track of the Before, Item, & After sorting order. Set the default
            // as follows.
            AdvSortOrder = new[] { 1, 0, 2 };

            // Keeps track of the R/L selections. Set the defaults as follows.
            AdvRlOptions = new[] { true, false, false };

            SortFields = new List <SortField>();

            // Default sort is by point of articulation and phonetic field.
            SortType = PhoneticSortType.POA;

            _project = project;

            if (initializeWithPhonetic && project != null)
            {
                SetPrimarySortField(project.GetPhoneticField(), false, true);
            }
        }
コード例 #5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Outputs a group heading row.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void OutputGroupHeading(object[] col)
        {
            // Print the group heading with the child row counts
            var shgrow = col[(int)ArrayDataType.SilHierarchicalGridRow] as SilHierarchicalGridRow;

            if (shgrow == null)
            {
                return;
            }

            // Get the font number and size for the group heading text.
            string groupFieldName = null;
            var    grid           = m_grid as PaWordListGrid;

            if (grid != null && grid.GroupByField != null)
            {
                groupFieldName = grid.GroupByField.Name;
            }
            else if (m_cache.IsMinimalPair || m_cache.IsSimilarEnvironment)
            {
                groupFieldName = m_project.GetPhoneticField().Name;
            }

            int fontNumber = (string.IsNullOrEmpty(groupFieldName) ? 0 : m_fontNumbers[groupFieldName]);
            int fontSize   = (string.IsNullOrEmpty(groupFieldName) ? 20 : m_fontSizes[groupFieldName]);

            if (m_exportFormat == ExportFormat.Table)
            {
                m_rtfBldr.Remove((m_rtfBldr.Length - @"\intbl".Length), @"\intbl".Length);
                m_rtfBldr.AppendLine(@"\trowd");
                m_rtfBldr.AppendFormat(kcell, (int)m_columnStartPoint);
                m_rtfBldr.AppendLine(@"\intbl");
            }
            else
            {
                // Make sure a group header starts a new paragraph.
                int len = 0;
                var rtf = m_rtfBldr.ToString();
                if (rtf.EndsWith(kline, StringComparison.Ordinal))
                {
                    len = kline.Length;
                }
                else if (rtf.EndsWith(kline + Environment.NewLine, StringComparison.Ordinal))
                {
                    len = kline.Length + Environment.NewLine.Length;
                }

                if (len > 0)
                {
                    m_rtfBldr.Remove(m_rtfBldr.Length - len, len);
                    m_rtfBldr.AppendLine(kparagraph);
                }
            }

            // By default, put 12 points of space between the
            // group heading and the row above it.
            int spaceB4GrpHdg = Properties.Settings.Default.RTFExportSpaceBeforeGroupHeading;

            m_rtfBldr.AppendFormat(@"\sb{0}\f{1} \fs{2}{{\b ", spaceB4GrpHdg, fontNumber, fontSize);
            m_rtfBldr.Append(col[(int)ArrayDataType.GroupingFieldName]);
            m_rtfBldr.Append("  ");
            m_rtfBldr.AppendFormat(shgrow.CountFormatStrings[0], shgrow.ChildCount);
            m_rtfBldr.Append("}");

            if (m_exportFormat == ExportFormat.Table)
            {
                m_rtfBldr.Append(@"\cell\row\trowd");
            }
            else
            {
                if (Properties.Settings.Default.RTFExportBorderUnderGroupHeading)
                {
                    m_rtfBldr.Append(@"\brdrb\brdrs\brdrw10\brsp20");
                }

                m_rtfBldr.Append(kparagraph);
            }

            m_rtfBldr.AppendLine();
            m_rtfBldr.Append(@"\sb0");

            if (m_cache.IsForSearchResults)
            {
                m_rtfBldr.AppendLine(m_tabFormatBldr.ToString());
            }

            m_rtfBldr.AppendLine(m_cellFormatBldr.ToString());
        }