Beispiel #1
0
 //***************************************************************************
 // Class Constructors
 //
 public FormElementData()
 {
     this._children                    = new FormElementDataCollection(this);
     this._dependantKeys               = new RainstormStudios.Collections.ObjectCollection();
     this._answers                     = new FormElementDataAnswerCollection(this);
     this._style                       = new Style();
     this._font                        = this._style.Font;
     this._isDirty                     = false;
     this._hasLoadedAnswers            =
         this._hasLoadedChildren       =
             this._hasLoadedDependants = false;
 }
        //***************************************************************************
        // Private Methods
        //
        private void ExportMatchList()
        {
            string fn = string.Empty;

            RainstormStudios.Collections.StringCollection allGrps = new RainstormStudios.Collections.StringCollection();
            for (int i = 0; i < this._miCol.Count; i++)
            {
                for (int j = 0; j < this._miCol[i].Groups.Count; j++)
                {
                    allGrps.AddUnique(this._miCol[i].Groups[j].GroupName);
                }
            }

            using (frmExportMatchList frm = new frmExportMatchList(allGrps.ToArray()))
            {
                if (frm.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                using (SaveFileDialog dlg = new SaveFileDialog())
                {
                    dlg.DefaultExt      = ".txt";
                    dlg.Filter          = "Text Files|*.txt|All Files|*.*";
                    dlg.FilterIndex     = 0;
                    dlg.Title           = "Please Select Output File";
                    dlg.ValidateNames   = true;
                    dlg.OverwritePrompt = true;
                    if (dlg.ShowDialog(this) == DialogResult.OK)
                    {
                        fn = dlg.FileName;
                    }
                    else
                    {
                        // User canceled save file dialog.
                        return;
                    }
                }

                List <string> ExportedGroupList = frm.IncludedGroupNames;

                using (System.IO.FileStream fs = new System.IO.FileStream(fn, System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    using (System.IO.StreamWriter sr = new System.IO.StreamWriter(fs))
                    {
                        RainstormStudios.Collections.ObjectCollection
                            grpCol = new RainstormStudios.Collections.ObjectCollection();

                        int maxGrpNameLen = -1;

                        if (frm.IncludeMaster)
                        {
                            sr.WriteLine("[Matches]");
                        }
                        for (int i = 0; i < this._miCol.Count; i++)
                        {
                            MatchInfo mi = this._miCol[i];
                            if (frm.IncludeMaster)
                            {
                                sr.WriteLine(mi.Value);
                            }

                            if (frm.IncludeGroups)
                            {
                                if (maxGrpNameLen == -1)
                                {
                                    for (int j = 0; j < mi.Groups.Count; j++)
                                    {
                                        if (mi.Groups[j].GroupName.Length > maxGrpNameLen)
                                        {
                                            maxGrpNameLen = mi.Groups[j].GroupName.Length;
                                        }
                                    }
                                }

                                for (int j = 0; j < mi.Groups.Count; j++)
                                {
                                    string grpNm = mi.Groups[j].GroupName;
                                    if (!ExportedGroupList.Contains(grpNm))
                                    {
                                        continue;
                                    }

                                    if (frm.Mode == frmExportMatchList.ExportMode.NestedList)
                                    {
                                        sr.WriteLine("{0}: {1}", grpNm.PadRight(maxGrpNameLen + 2, ' '), mi.Groups[j].Value);
                                    }
                                    else if (frm.Mode == frmExportMatchList.ExportMode.SeparatedLists)
                                    {
                                        if (!grpCol.ContainsKey(grpNm))
                                        {
                                            grpCol.Add(new RainstormStudios.Collections.StringCollection(), grpNm);
                                        }

                                        ((RainstormStudios.Collections.StringCollection)grpCol[grpNm]).Add(mi.Groups[j].Value);
                                    }
                                }
                                if (frm.Mode == frmExportMatchList.ExportMode.NestedList)
                                {
                                    sr.WriteLine();
                                }
                            }
                        }

                        if (frm.IncludeGroups && frm.Mode == frmExportMatchList.ExportMode.SeparatedLists)
                        {
                            for (int k = 0; k < grpCol.Count; k++)
                            {
                                if (frm.IncludeMaster || k > 0)
                                {
                                    sr.WriteLine();
                                }
                                sr.WriteLine("[" + grpCol.GetKey(k) + "]");

                                RainstormStudios.Collections.StringCollection valCol = (RainstormStudios.Collections.StringCollection)grpCol[k];
                                for (int l = 0; l < valCol.Count; l++)
                                {
                                    sr.WriteLine(valCol[l]);
                                }
                            }
                        }
                    }
            }
            MessageBox.Show(this, "Export Complete!", "Success!");
        }