コード例 #1
0
        public void Delete(int id)
        {
            MyDatabaseData myDatabaseData = new MyDatabaseData();
            XmlDocument    doc            = new XmlDocument();

            doc.Load(dirPath + "MyDatabaseData.xml");
            XmlNode root = doc.SelectSingleNode("//Database");

            foreach (XmlNode node in root)
            {
                if (Convert.ToInt32(node.ChildNodes[0].InnerText) == id)
                {
                    myDatabaseData.Id = Convert.ToInt32(node.ChildNodes[0].InnerText);
                    myDatabaseData.OriginalFileName = node.ChildNodes[1].InnerText;
                    myDatabaseData.MyFileName       = node.ChildNodes[2].InnerText;
                    node.RemoveAll();
                    root.RemoveChild(node);
                    break;
                }
            }
            doc.Save(dirPath + "MyDatabaseData.xml");

            string targetFilePath    = System.IO.Path.Combine(dirPath, myDatabaseData.MyFileName);
            string targetXmlFilePath = System.IO.Path.Combine(dirPath, string.Format(@"{0}.xml", myDatabaseData.MyFileName));

            System.IO.File.Delete(targetFilePath);
            System.IO.File.Delete(targetXmlFilePath);
        }
コード例 #2
0
        public IEnumerable <MyDatabaseData> Get(string searchTerm)
        {
            List <MyDatabaseData> fileDataList = new List <MyDatabaseData>();

            XmlDocument doc = new XmlDocument();

            doc.Load(dirPath + "MyDatabaseData.xml");

            XmlNode databaseNode = doc.SelectSingleNode("//Database");

            foreach (XmlNode node in databaseNode)
            {
                MyDatabaseData myDatabaseData = new MyDatabaseData();
                if (node.ChildNodes[1].InnerText.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    myDatabaseData.Id = Convert.ToInt32(node.ChildNodes[0].InnerText);
                    myDatabaseData.OriginalFileName = node.ChildNodes[1].InnerText;
                    myDatabaseData.MyFileName       = node.ChildNodes[2].InnerText;
                    fileDataList.Add(myDatabaseData);
                }
            }


            //if ( !(searchTerm != null) )
            //{
            //    foreach ( XmlNode node in databaseNode )
            //    {
            //        MyDatabaseData myDatabaseData = new MyDatabaseData();
            //        myDatabaseData.Id = Convert.ToInt32( node.ChildNodes[0].InnerText );
            //        myDatabaseData.OriginalFileName = node.ChildNodes[1].InnerText;
            //        myDatabaseData.MyFileName = node.ChildNodes[2].InnerText;
            //        fileDataList.Add( myDatabaseData );
            //    }
            //}

            return(fileDataList);
        }