Example #1
0
        private void DelLabel(XmlDocument doc, XmlNode nodelist)
        {
            if (nodelist == null)
            {
                return;
            }
            string nodefile = dir + nodelist["LabelCate"].InnerText + @"\" + nodelist["LabelName"].InnerText + ".label";

            if (File.Exists(nodefile))
            {
                FileSystemObject.Delete(nodefile, FsoMethod.File);
            }
            string filefolder = dir + nodelist["LabelCate"].InnerText;

            if (Directory.Exists(filefolder))
            {
                DataTable filelist = FileSystemObject.GetFileList(filefolder);
                if (filelist == null || filelist.Rows.Count < 1)
                {
                    FileSystemObject.Delete(filefolder, FsoMethod.Folder);
                }
            }
            nodelist.ParentNode.RemoveChild(nodelist);
            doc.Save(dirfilename);
        }
Example #2
0
        /// <summary>
        /// 更新xml标签
        /// </summary>
        public void UpdateLabelXML(M_Label label)
        {
            if (string.IsNullOrEmpty(label.LableName))
            {
                label.LableName = "随机命名" + DateTime.Now.ToString("yyyyMMdd") + "_" + function.GetRandomString(6);
            }
            ExistLabelDir(label);
            XmlDocument doc = new XmlDocument();

            doc.Load(dirfilename);
            XmlNode nodelist = doc.SelectSingleNode("//NewDataSet/Table[LabelName='" + label.LableName + "']");

            if (nodelist == null)
            {
                throw (new Exception("[" + label.LableName + "]不存在"));
            }
            string oldPath = (nodelist["LabelCate"].InnerText + "\\" + nodelist["LabelName"].InnerText).Replace(" ", "").ToLower();
            string newPath = (label.LabelCate + "\\" + label.LableName).ToLower();
            //--------------------
            DataTable labelDT = GetInfoFromModel(label);
            DataSet   newset  = new DataSet("NewDataSet");

            newset.Tables.Add(labelDT);
            string  filename = dir + label.LabelCate + @"\" + label.LableName + ".label";
            DataSet ds       = FileSystemObject.ReadXML(dirfilename, "NewDataSet");

            if (ds.Tables.Count <= 0)
            {
                ds.Tables.Add(new DataTable("Table"));
            }
            DataTable dsDT = ds.Tables[0];

            if (dsDT.Columns.Count > 0)
            {
                dsDT.DefaultView.RowFilter = "LabelName='" + label.LableName + "'";
            }
            dsDT = dsDT.DefaultView.ToTable();
            newset.WriteXml(filename);
            //newset.Tables.Add(filename);
            if (!newPath.Equals(oldPath))//修改了名称或类别
            {
                FileSystemObject.Delete(dir + oldPath + ".label", FsoMethod.File);
                string    oldfolder = dir + nodelist["LabelCate"].InnerText;
                DataTable filelist  = FileSystemObject.GetFileList(oldfolder);
                if (filelist == null || filelist.Rows.Count < 1)
                {
                    FileSystemObject.Delete(oldfolder, FsoMethod.Folder);
                }
            }
            nodelist["LabelName"].InnerText = label.LableName;
            nodelist["LabelCate"].InnerText = label.LabelCate;
            nodelist["LabelType"].InnerText = label.LableType.ToString();
            doc.Save(dirfilename);
        }