Beispiel #1
0
        /// <summary>
        /// Handles the "Save Current Format..." context menu click.
        /// Processes the save to the configuration file then re-loads the list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveNewFormat_Click(object sender, System.EventArgs e)
        {
            if (!Directory.Exists(Path.GetDirectoryName(this.savedFormatConfigFile)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(this.savedFormatConfigFile));
            }

            NewFormatForm frmNew = new NewFormatForm(this.rtbFormat.Text);

            if (DialogResult.OK == frmNew.ShowDialog())
            {
                Format frmt = new Format();
                frmt.Name      = frmNew.Description;
                frmt.Value     = frmNew.Format;
                frmt.Delimiter = ddDelimiter.Text;

                if (this.formats != null)
                {
                    ArrayList lst = new ArrayList(this.formats.Items);
                    lst.Add(frmt);
                    Format[] newlist = new Format[lst.Count];
                    lst.CopyTo(newlist);
                    this.formats.Items = newlist.ToList();
                }
                else
                {
                    this.formats = new StringManipulatorCfg();
                    this.formats.Items.Add(frmt);
                }

                System.Xml.XmlTextWriter tw = null;
                try
                {
                    XmlSerializer xmlS = new XmlSerializer(typeof(StringManipulatorCfg));
                    tw             = new System.Xml.XmlTextWriter(this.savedFormatConfigFile, Encoding.UTF8);
                    tw.Indentation = 4;
                    tw.Formatting  = System.Xml.Formatting.Indented;
                    xmlS.Serialize(tw, this.formats);
                    tw.Close();

                    LoadSavedFormats();
                }
                finally
                {
                    if (tw != null)
                    {
                        tw.Close();
                    }
                }
            }
        }
Beispiel #2
0
        private void UpdateSavedFormat_Click(object sender, EventArgs e)
        {
            NewFormatForm frmFormat = new NewFormatForm(rtbFormat.Text, this.CurrentFormat);

            if (DialogResult.OK == frmFormat.ShowDialog())
            {
                for (int i = 0; i < this.formats.Items.Count; i++)
                {
                    if (this.formats.Items[i].Name.Trim() == this.CurrentFormat)
                    {
                        this.formats.Items[i].Name      = frmFormat.Description;
                        this.formats.Items[i].Value     = frmFormat.Format;
                        this.formats.Items[i].Delimiter = ddDelimiter.Text;
                        this.CurrentFormat        = frmFormat.Description;
                        this.CurrentFormatChanged = false;

                        break;
                    }
                }
                System.Xml.XmlTextWriter tw = null;
                try
                {
                    XmlSerializer xmlS = new XmlSerializer(typeof(StringManipulatorCfg));
                    tw             = new System.Xml.XmlTextWriter(this.savedFormatConfigFile, Encoding.UTF8);
                    tw.Indentation = 4;
                    tw.Formatting  = System.Xml.Formatting.Indented;
                    xmlS.Serialize(tw, this.formats);
                    tw.Close();

                    LoadSavedFormats();
                }
                finally
                {
                    if (tw != null)
                    {
                        tw.Close();
                    }
                }
            }
        }