Esempio n. 1
0
        //============================================================================*
        // CreateShareFile()
        //============================================================================*

        private void CreateShareFile()
        {
            //----------------------------------------------------------------------------*
            // Gather all the needed info to store the loads to be shared
            //----------------------------------------------------------------------------*

            cManufacturerList ShareManufacturerList = new cManufacturerList();
            cCaliberList      ShareCaliberList      = new cCaliberList();
            cBulletList       ShareBulletList       = new cBulletList();
            cCaseList         ShareCaseList         = new cCaseList();
            cPowderList       SharePowderList       = new cPowderList();
            cPrimerList       SharePrimerList       = new cPrimerList();

            cLoadList ShareLoadList = new cLoadList();

            foreach (ListViewItem Item in m_LoadDataListView.CheckedItems)
            {
                cLoad Load = (cLoad)Item.Tag;

                if (Load != null && Load.Bullet != null && Load.Case != null && Load.Powder != null && Load.Primer != null)
                {
                    foreach (cBulletCaliber BulletCaliber in Load.Bullet.BulletCaliberList)
                    {
                        ShareCaliberList.AddCaliber(BulletCaliber.Caliber);
                    }

                    ShareManufacturerList.AddManufacturer(Load.Bullet.Manufacturer);
                    ShareBulletList.AddBullet(Load.Bullet);

                    ShareManufacturerList.AddManufacturer(Load.Case.Manufacturer);
                    ShareCaseList.AddCase(Load.Case);

                    ShareManufacturerList.AddManufacturer(Load.Powder.Manufacturer);
                    SharePowderList.AddPowder(Load.Powder);

                    ShareManufacturerList.AddManufacturer(Load.Primer.Manufacturer);
                    SharePrimerList.AddPrimer(Load.Primer);

                    ShareLoadList.Add(Load);
                }
            }

            //----------------------------------------------------------------------------*
            // Now create a cRWXMLDocument and export the load data to it
            //----------------------------------------------------------------------------*

            cRWXMLDocument XMLDocument = new cRWXMLDocument(m_DataFiles);

            XmlElement MainElement = XMLDocument.CreateElement("Body");

            XMLDocument.AppendChild(MainElement);

            XmlText XMLTextElement = XMLDocument.CreateTextNode(String.Format("{0} Load Data Share File Export", Application.ProductName));

            MainElement.AppendChild(XMLTextElement);

            ShareManufacturerList.Export(XMLDocument, MainElement);
            ShareBulletList.Export(XMLDocument, MainElement, false);
            ShareCaliberList.Export(XMLDocument, MainElement);
            ShareCaseList.Export(XMLDocument, MainElement, false);
            SharePowderList.Export(XMLDocument, MainElement, false);
            SharePrimerList.Export(XMLDocument, MainElement, false);

            ShareLoadList.Export(XMLDocument, MainElement);

            //----------------------------------------------------------------------------*
            // Save the Exported XML Share File
            //----------------------------------------------------------------------------*

            SaveFileDialog SaveDialog = new SaveFileDialog();

            SaveDialog.AddExtension     = true;
            SaveDialog.CheckPathExists  = true;
            SaveDialog.DefaultExt       = "xml";
            SaveDialog.FileName         = String.Format("{0} Load Data Share File - {1}{2}{3}", Application.ProductName, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            SaveDialog.Filter           = "XML Files {*.xml)|*.xml";
            SaveDialog.InitialDirectory = Path.Combine(m_DataFiles.GetDataPath(), "Share");
            SaveDialog.OverwritePrompt  = true;
            SaveDialog.Title            = String.Format("Export Load Data");
            SaveDialog.ValidateNames    = true;

            if (SaveDialog.ShowDialog() == DialogResult.OK)
            {
                XMLDocument.Save(SaveDialog.OpenFile());
            }
        }