Пример #1
0
        public void hebingSingleNode(string xmlFilePath, string rootNodeName, storeFur stf)//仅仅用于库存xml
        {
            //搜索有无相同节点
            int         alreadyHave = 0;
            XmlDocument xd          = new XmlDocument();

            xd.Load(xmlFilePath);
            XmlNode     xn = xd.SelectSingleNode(rootNodeName);
            XmlNodeList xl = xn.ChildNodes;

            foreach (XmlNode xxn in xl)
            {
                if ((xxn.ChildNodes[0].InnerText == stf.variety) && (xxn.ChildNodes[1].InnerText == stf.number))//如已经存在记录
                {
                    xxn.ChildNodes[2].InnerText = Convert.ToString((float.Parse(stf.inprice) * (float)stf.shumu
                                                                    + float.Parse(xxn.ChildNodes[2].InnerText) * float.Parse(xxn.ChildNodes[6].InnerText))
                                                                   / ((float)stf.shumu + float.Parse(xxn.ChildNodes[6].InnerText))); //平均进价
                    xxn.ChildNodes[3].InnerText = stf.onprice;                                                                       //标价
                    xxn.ChildNodes[6].InnerText = Convert.ToString((float)stf.shumu + float.Parse(xxn.ChildNodes[6].InnerText));     //数目
                    alreadyHave = 1;
                    break;
                }
            }
            if (alreadyHave == 0)//如没有同类型记录,则添加一个项目
            {
                XmlNode    memberlist = xd.SelectSingleNode(rootNodeName);
                XmlElement element    = xd.CreateElement("furniture");
                element.SetAttribute("date", stf.date);
                XmlNode subnode = memberlist.AppendChild(element);

                element           = xd.CreateElement("variety");
                element.InnerText = stf.variety;
                subnode.AppendChild(element);

                element           = xd.CreateElement("number");
                element.InnerText = stf.number;
                subnode.AppendChild(element);

                element           = xd.CreateElement("inprice");
                element.InnerText = stf.inprice;
                subnode.AppendChild(element);

                element           = xd.CreateElement("onprice");
                element.InnerText = stf.onprice;
                subnode.AppendChild(element);

                element           = xd.CreateElement("outprice");
                element.InnerText = stf.outprice;
                subnode.AppendChild(element);

                element           = xd.CreateElement("date");
                element.InnerText = stf.date;
                subnode.AppendChild(element);

                element           = xd.CreateElement("shumu");
                element.InnerText = Convert.ToString(stf.shumu);
                subnode.AppendChild(element);
            }
            xd.Save(xmlFilePath);
        }
Пример #2
0
        public string fenliSingleNode(string xmlFilePath, string rootNodeName, storeFur stf)
        {
            //搜索有无相同节点
            int         alreadyHave = 0;
            XmlDocument xd          = new XmlDocument();

            xd.Load(xmlFilePath);
            XmlNode     xn = xd.SelectSingleNode(rootNodeName);
            XmlNodeList xl = xn.ChildNodes;

            foreach (XmlNode xxn in xl)
            {
                if ((xxn.ChildNodes[0].InnerText == stf.variety) && (xxn.ChildNodes[1].InnerText == stf.number))//如已经存在记录
                {
                    alreadyHave = 1;
                    int temperDX = int.Parse(xxn.ChildNodes[6].InnerText) - stf.shumu;
                    if (temperDX > 0)
                    {
                        stf.shumu    = temperDX;
                        stf.outprice = "不可用";
                        updateSingleNode(xmlFilePath, "store", xxn.ChildNodes[5].InnerText, stf);
                        return(Convert.ToString(temperDX));
                    }
                    else if (temperDX == 0)
                    {
                        stf.shumu = temperDX;
                        //updateSingleNode(xmlFilePath, "store", xxn.ChildNodes[5].InnerText, stf);
                        deleteSingleNode(xmlFilePath, "store", xxn.ChildNodes[5].InnerText);
                        return("succeedbut0");
                    }
                    else
                    {
                        return("fail<");
                    }
                }
            }
            if (alreadyHave == 0)
            {
                return("failNo");
            }
            else
            {
                return("");
            }
        }
Пример #3
0
        //搜索rootNodeName下所有节点
        public ArrayList searchAllNode(string xmlFilePath, string rootNodeName)
        {
            ArrayList   al = new ArrayList();
            XmlDocument xd = new XmlDocument();

            xd.Load(xmlFilePath);
            XmlNode     xn = xd.SelectSingleNode(rootNodeName);
            XmlNodeList xl = xn.ChildNodes;

            foreach (XmlNode xxn in xl)
            {
                string[] str = { xxn.ChildNodes[0].InnerText, xxn.ChildNodes[1].InnerText, xxn.ChildNodes[2].InnerText, xxn.ChildNodes[3].InnerText, xxn.ChildNodes[4].InnerText, xxn.ChildNodes[5].InnerText, xxn.ChildNodes[6].InnerText };
                storeFur stf = new storeFur(str);

                al.Add(stf);
            }
            return(al);
        }
Пример #4
0
        //搜索某一date属性的节点
        public storeFur searchSingleNode(string xmlFilePath, string rootNodeName, string str_single)
        {
            storeFur    stf = new storeFur();
            XmlDocument xd  = new XmlDocument();

            xd.Load(xmlFilePath);
            XmlNode     xn = xd.SelectSingleNode(rootNodeName);
            XmlNodeList xl = xn.ChildNodes;

            foreach (XmlNode xxn in xl)
            {
                if (xxn.Attributes[0].Value.ToString() == str_single)
                {
                    string[] str = { xxn.ChildNodes[0].InnerText, xxn.ChildNodes[1].InnerText, xxn.ChildNodes[2].InnerText, xxn.ChildNodes[3].InnerText, xxn.ChildNodes[4].InnerText, xxn.ChildNodes[5].InnerText, xxn.ChildNodes[6].InnerText };
                    stf.SetV(str);
                }
            }
            return(stf);
        }
Пример #5
0
        /// <summary>
        /// 增加节点属性
        /// </summary>
        /// <param name="xmlFilePath">文件路径</param>
        /// <param name="stf">家具类</param>
        public void AddFurElement(string xmlFilePath, storeFur stf, string rootNodeName)
        {
            XmlDocument myXmlDoc = new XmlDocument();

            myXmlDoc.Load(xmlFilePath);
            XmlNode    memberlist = myXmlDoc.SelectSingleNode(rootNodeName);
            XmlElement element    = myXmlDoc.CreateElement("furniture");

            element.SetAttribute("date", stf.date);
            XmlNode subnode = memberlist.AppendChild(element);

            element           = myXmlDoc.CreateElement("variety");
            element.InnerText = stf.variety;
            subnode.AppendChild(element);

            element           = myXmlDoc.CreateElement("number");
            element.InnerText = stf.number;
            subnode.AppendChild(element);

            element           = myXmlDoc.CreateElement("inprice");
            element.InnerText = stf.inprice;
            subnode.AppendChild(element);

            element           = myXmlDoc.CreateElement("onprice");
            element.InnerText = stf.onprice;
            subnode.AppendChild(element);

            element           = myXmlDoc.CreateElement("outprice");
            element.InnerText = stf.outprice;
            subnode.AppendChild(element);

            element           = myXmlDoc.CreateElement("date");
            element.InnerText = stf.date;
            subnode.AppendChild(element);

            element           = myXmlDoc.CreateElement("shumu");
            element.InnerText = Convert.ToString(stf.shumu);
            subnode.AppendChild(element);
            myXmlDoc.Save(xmlFilePath);
        }
Пример #6
0
 /// <summary>
 //更新某一节点
 /// </summary>
 /// <param name="xmlFilePath">文件路径</param>
 /// <param name="rootNodename">根节点名字</param>
 /// <param name="str_single">节点attribute值</param>
 /// <param name="stf">欲替代的storeFur值</param>
 public void updateSingleNode(string xmlFilePath, string rootNodeName, string str_single, storeFur stf)
 {
     deleteSingleNode(xmlFilePath, rootNodeName, str_single);
     AddFurElement(xmlFilePath, stf, rootNodeName);
 }