示例#1
0
        /// <summary>Export the current code lookup list to a file</summary>
        private void ExportCodeLookupList()
        {
            // Prompt for the file to save
            var dg = new SaveFileDialog {
                Title = "Export code lookup list", Filter = Constants.XmlOrCsvFileFilter
            };

            if (dg.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            try
            {
                string extn = Path.GetExtension(dg.FileName);
                extn = extn != null?extn.Trim(new[] { '.' }) : "";

                // If a csv file is being saved, write out csv
                if (string.CompareOrdinal(extn, "csv") == 0)
                {
                    // Create a CSV object
                    var csv = new CSVData {
                        AutoSize = true
                    };
                    csv.Reserve(Values.Count, 2);
                    foreach (var c in Values)
                    {
                        CSVData.Row row = new CSVData.Row();
                        row.Add(c.Key);
                        row.Add(c.Value);
                        csv.Add(row);
                    }
                    csv.Save(dg.FileName);
                }
                // Otherwise write out xml
                else
                {
                    XDocument doc = new XDocument(new XElement(XmlTag.Root));
                    if (doc.Root == null)
                    {
                        throw new Exception("Failed to create root xml node");
                    }
                    var codes = new XElement(XmlTag.CodeValues);
                    foreach (var v in Values)
                    {
                        codes.Add(new XElement(XmlTag.CodeValue,
                                               new XElement(XmlTag.Code, v.Key),
                                               new XElement(XmlTag.Value, v.Value)
                                               ));
                    }
                    doc.Root.Add(codes);
                    doc.Save(dg.FileName, SaveOptions.None);
                }
            }
            catch (Exception ex)
            {
                Misc.ShowMessage(this, "Export failed.", "Export Failed", MessageBoxIcon.Error, ex);
            }
        }
示例#2
0
        public void DumpCompounds()
        {
            var csv    = new CSVData();
            var header = new CSVData.Row();

            header.Add("Scientific Name").Add("Symbolic Name").Add("Enthalpy").Add("Ionicity").Add("Melting Point").Add("Boiling Point").Add("Strength").Add("Density");
            csv.Add(header);
            foreach (var c in m_compounds)
            {
                var row = new CSVData.Row();
                row.Add(c.ScientificName).Add(c.SymbolicName).Add(c.Enthalpy).Add(c.Ionicity).Add(c.MeltingPoint).Add(c.BoilingPoint).Add(c.Strength).Add(c.Density(0, 0));
                csv.Add(row);
            }
            csv.Save(@"d:\deleteme\compounds.csv");
        }
示例#3
0
        public void DumpElements()
        {
            var csv    = new CSVData();
            var header = new Rylogic.Container.CSVData.Row();

            header.Add("Name").Add("AtomicNumber").Add("ValenceElectrons").Add("ValenceHoles").Add("ValenceOrbitalRadius").Add("MolarMass").Add("Electronegativity").Add("Melting Point").Add("Boiling Point").Add("SolidDensity");
            csv.Add(header);
            foreach (var e in m_elements)
            {
                var row = new CSVData.Row();
                row.Add(e.Name.Fullname).Add(e.AtomicNumber).Add(e.ValenceElectrons).Add(e.ValenceHoles).Add(e.ValenceOrbitalRadius).Add(e.MolarMass).Add(e.Electronegativity).Add(e.MeltingPoint).Add(e.BoilingPoint).Add(e.SolidDensity);
                csv.Add(row);
            }
            csv.Save(@"d:\deleteme\elements.csv");
        }