C#物资管理系统_第1页
C#物资管理系统_第2页
C#物资管理系统_第3页
C#物资管理系统_第4页
C#物资管理系统_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、用Xml存储的c#物资管理系统using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Xml;using System.IO;namespace物资库存管理系统public partial class WuZi : Formpublic WuZi()InitializeComponent();private vo

2、id btnC_Click(object sender, EventArgs e) /库存创建string id = textBox1.Text;string name = textBox2.Text;string size = textBox3.Text;string species = textBox4.Text;string unit = textBox5.Text;string number = textBox6.Text;XmlTextWriter doc = new XmlTextWriter(goods.xml”, null);doc.Formatting = Formattin

3、g.Indented; /使用自动缩进便于阅读 doc.WriteStartElement(huowu);doc.WriteStartElement(goods);doc.WriteAttributeString(id”, id);doc.WriteElementString(name”,name);doc.WriteElementString(size”,size);doc.WriteElementString(species”, species);doc.WriteElementString(unit”,unit);doc.WriteElementString(number”,number

4、);doc.WriteEndElement();doc.Close();private void btnAdd_Click(object sender, EventArgs e)库存添加 string id = textBoxl.Text;string name = textBox2.Text;string size = textBox3.Text;string species = textBox4.Text;string unit = textBox5.Text;string number = textBox6.Text;XmlDocument doc = new XmlDocument()

5、;doc.Load(goods.xml);/加载xml文件,路径未指定时默认在当前项目环境下XmlNode root = doc.SelectSingleNode(huowu); 选择要添加子节点的节点XmlElement stu = doc.CreateElement(goods);创建一个具有指定名称的子节点stu.SetAttribute(id”, id);XmlElement xmlsubl = doc.CreateElement(name);xmlsubl.InnerText = name;stu.AppendChild(xmlsubl);XmlElement xmlsub2 = d

6、oc.CreateElement(size);xmlsub2.InnerText = size;stu.AppendChild(xmlsub2);XmlElement xmlsub3 = doc.CreateElement(species);xmlsub3.InnerText = species;stu.AppendChild(xmlsub3);XmlElement xmlsub4 = doc.CreateElement(unit);xmlsub4.InnerText = unit;stu.AppendChild(xmlsub4);XmlElement xmlsub5 = doc.Create

7、Element(number);xmlsub5.InnerText = number;stu.AppendChild(xmlsub5);root.AppendChild(stu);/将创建的item子节点添加到it ems节点的尾部doc.Save(goods.xml);/保存xml 文件,private void btnUpdate_Click(object sender, EventArgs e)库存修改string id = textBoxl.Text;string name = textBox2.Text;string size = textBox3.Text;string speci

8、es = textBox4.Text;string unit = textBox5.Text;string number = textBox6.Text;XmlDocument doc = new XmlDocument();doc.Load(goods.xml);XmlNodeList list = doc.SelectSingleNode(huowu).ChildNodes;获得根节点下的所有子节点/遍历所有子节点int x = 0;foreach (XmlNode node in list)类型XmlElement xe = (XmlElement)node;/将子节点类型转换为 Xml

9、Elementif (xe.GetAttribute(id) = id)x = 1;xe.SetAttribute(id”, id);如果下面有子节点在下走XmlNodeList nls = xe.ChildNodes;继续获取xe子节点的所有子节点foreach (XmlNode xn in nls)/遍历XmlElement xe2 = (XmlElement)xn; 转换类型if (xe2.Name = name)如果找到xe2.InnerText = name;则修改if (xe2.Name = size)xe2.InnerText = size;if (xe2.Name = spec

10、ies)xe2.InnerText = species;if (xe2.Name = unit)xe2.InnerText = unit;if (xe2.Name = number)xe2.InnerText = number;break;doc.Save(goods.xml);if (x = 0)MessageBox.Show(无此物品,请重新输入);private void btnSelect_Click(object sender, EventArgs e) 库存查询 string id = textBox1.Text;XmlDocument doc = new XmlDocument(

11、);doc.Load(goods.xml);XmlNode list = doc.SelectSingleNode(huowu);XmlNodeList xnl = list.ChildNodes;int x = 0;foreach (XmlNode node in xnl)XmlElement stu = (XmlElement)node;if (stu.GetAttribute(id) = id)x = 1;XmlNodeList st = stu.ChildNodes;foreach (XmlNode st1 in st)if (st1.Name = name)textBox2.Text

12、 = st1.InnerText;if (st1.Name = size)textBox3.Text = st1.InnerText;if (st1.Name = species)textBox4.Text = st1.InnerText;if (st1.Name = unit)textBox5.Text = st1.InnerText;if (st1.Name = number)textBox6.Text = st1.InnerText;break;if (x = 0)MessageBox.Show(无此货物,请重新输入);textBox1.Text =;textBox2.Text =;te

13、xtBox3.Text =;textBox4.Text =;textBox5.Text =;textBox6.Text =;doc.Save(goods.xml);private void btnBrowse_Click(object sender, EventArgs e) 库存浏览XmlDocument doc = new XmlDocument();doc.Load(goods.xml);XmlNode list = doc.SelectSingleNode(huowu);XmlNodeList xnl = list.ChildNodes;lblshow.Text =”;lblshow.

14、Text +=总库存:n;foreach (XmlNode node in xnl)XmlElement stu = (XmlElement)node;XmlNodeList st = stu.ChildNodes;if (stu.GetAttribute(id) != null)string id = stu.GetAttribute(id);foreach (XmlNode st1 in st)if (st1.Name = name)lblshow.Text+=物资编号:+id+,物资名称:+ st1.InnerText;if (st1.Name = size)lblshow.Text +

15、=,规格型号:+ st1.InnerText;if (st1.Name = species)lblshow.Text +=,种类:+ st1.InnerText;if (st1.Name = unit)lblshow.Text +=,计量单位:+ st1.InnerText;if (st1.Name = number)lblshow.Text +=,数量:+ st1.InnerText + n;doc.Save(goods.xml);private void button4_Click(object sender, EventArgs e)出库输入string id = textBox1.Te

16、xt;string name = textBox2.Text;string size = textBox3.Text;string species = textBox4.Text;string unit = textBox5.Text;string number = textBox6.Text;XmlDocument doc = new XmlDocument();doc.Load(outgoods.xml);/加载xml文件,路径未指定时默认在当前项目环境下XmlNode root = doc.SelectSingleNode(huowu); 选择要添加子节点的节点XmlElement st

17、u = doc.CreateElement(goods);创建一个具有指定名称的子节点stu.SetAttribute(id”, id);XmlElement xmlsubl = doc.CreateElement(name);xmlsubl.InnerText = name;stu.AppendChild(xmlsubl);XmlElement xmlsub2 = doc.CreateElement(size);xmlsub2.InnerText = size;stu.AppendChild(xmlsub2);XmlElement xmlsub3 = doc.CreateElement(sp

18、ecies);xmlsub3.InnerText = species;stu.AppendChild(xmlsub3);XmlElement xmlsub4 = doc.CreateElement(unit);xmlsub4.InnerText = unit;stu.AppendChild(xmlsub4);XmlElement xmlsub5 = doc.CreateElement(number);xmlsub5.InnerText = number;stu.AppendChild(xmlsub5);root.AppendChild(stu);/将创建的item子节点添加到it ems节点的

19、尾部doc.Save(outgoods.xml);/保存xml 文件,出库时从总库中减去XmlDocument docl = new XmlDocument();doc1.Load(goods.xml);XmlNodeList list = doc1.SelectSingleNode(huowu).ChildNodes;获得根节点下的所有子节点/遍历所有子节点int x = 0;foreach (XmlNode node in list)if (xe.GetAttribute(id) = id)x = 1;xe.SetAttribute(id”, id);如果下面有子节点在下走XmlNodeL

20、ist nls = xe.ChildNodes;继续获取xe子节点的所有子节点foreach (XmlNode xn in nls)/遍历XmlElement xe2 = (XmlElement)xn; 转换类型if (xe2.Name = number)xe2.InnerText=Convert.ToString(Convert.ToInt32(xe2.InnerText) - Convert.ToInt32(number); break;doc1.Save(goods.xml);private void button5_Click(object sender, EventArgs e) 出

21、库查询string id = textBox1.Text;XmlDocument doc = new XmlDocument();doc.Load(outgoods.xml);XmlNode list = doc.SelectSingleNode(huowu);XmlNodeList xnl = list.ChildNodes;int x = 0;foreach (XmlNode node in xnl)XmlElement stu = (XmlElement)node;if (stu.GetAttribute(id) = id)x = 1;XmlNodeList st = stu.Child

22、Nodes;foreach (XmlNode st1 in st) if (st1.Name = name)textBox2.Text = st1.InnerText;if (st1.Name = size)textBox3.Text = st1.InnerText;if (st1.Name = species)textBox4.Text = stl.InnerText;if (stl.Name = unit) textBox5.Text = st1.InnerText;if (st1.Name = number) textBox6.Text = st1.InnerText;break;if

23、(x = 0)MessageBox.Show(无此货物,请重新输入);textBox1.Text =;textBox2.Text =;textBox3.Text =;textBox4.Text =;textBox5.Text =;textBox6.Text =;doc.Save(outgoods.xml);private void button6_Click(object sender, EventArgs e) 出库修改string id = textBox1.Text;string name = textBox2.Text;string size = textBox3.Text;strin

24、g species = textBox4.Text;string unit = textBox5.Text;string number = textBox6.Text;XmlDocument doc = new XmlDocument();doc.Load(outgoods.xml);XmlNodeList list = doc.SelectSingleNode(huowu).ChildNodes;获得根节点下的所有子节点/遍历所有子节点int x = 0;foreach (XmlNode node in list)XmlElement xe = (XmlElement)node;/将子节点类

25、型转换为 XmlElement类型if (xe.GetAttribute(id) = id)x = 1;xe.SetAttribute(id, id);如果下面有子节点在下走XmlNodeList nls = xe.ChildNodes;继续获取xe子节点的所有子节点foreach (XmlNode xn in nls)/遍历XmlElement xe2 = (XmlElement)xn; 转换类型if (xe2.Name = name)如果找到xe2.InnerText = name;则修改if (xe2.Name = size) xe2.InnerText = size;if (xe2.N

26、ame = species)xe2.InnerText = species;if (xe2.Name = unit) xe2.InnerText = unit;if (xe2.Name = number) xe2.InnerText = number;break;doc.Save(outgoods.xml);if (x = 0)MessageBox.Show(无此物品,请重新输入);private void button2_Click(object sender, EventArgs e)/入库查询string id = textBox1.Text;XmlDocument doc = new

27、XmlDocument();doc.Load(ingoods.xml);XmlNode list = doc.SelectSingleNode(huowu);XmlNodeList xnl = list.ChildNodes;int x = 0;foreach (XmlNode node in xnl)XmlElement stu = (XmlElement)node;if (stu.GetAttribute(id) = id)x = 1;XmlNodeList st = stu.ChildNodes;foreach (XmlNode st1 in st)if (st1.Name = name

28、)textBox2.Text = stl.InnerText;if (stl.Name = size) textBox3.Text = st1.InnerText;if (st1.Name = species) textBox4.Text = st1.InnerText;if (st1.Name = unit) textBox5.Text = st1.InnerText;if (st1.Name = number) textBox6.Text = st1.InnerText;break;if (x = 0)MessageBox.Show(无此货物,请重新输入);textBox1.Text =;

29、textBox2.Text =;textBox3.Text =;textBox4.Text =;textBox5.Text =;textBox6.Text =;doc.Save(ingoods.xml);private void button3_Click(object sender, EventArgs e)/入库修改string id = textBox1.Text;string name = textBox2.Text;string size = textBox3.Text;string species = textBox4.Text;string unit = textBox5.Tex

30、t;string number = textBox6.Text;XmlDocument doc = new XmlDocument();doc.Load(ingoods.xml);XmlNodeList list = doc.SelectSingleNode(huowu).ChildNodes;获得根节点下的所有子节点/遍历所有子节点int x = 0;foreach (XmlNode node in list)if (xe.GetAttribute(id) = id)x = 1;xe.SetAttribute(id”, id);如果下面有子节点在下走XmlNodeList nls = xe.

31、ChildNodes;继续获取xe子节点的所有子节点foreach (XmlNode xn in nls)/遍历XmlElement xe2 = (XmlElement)xn; 转换类型if (xe2.Name = name)如果找到xe2.InnerText = name;则修改if (xe2.Name = size) xe2.InnerText = size;if (xe2.Name = species)xe2.InnerText = species;if (xe2.Name = unit) xe2.InnerText = unit;if (xe2.Name = number) xe2.I

32、nnerText = number;break;doc.Save(ingoods.xml);if (x = 0)MessageBox.Show(无此物品,请重新输入);private void button1_Click(object sender, EventArgs e)/入库输入string id = textBox1.Text;string name = textBox2.Text;string size = textBox3.Text;string species = textBox4.Text;string unit = textBox5.Text;string number =

33、textBox6.Text;XmlDocument doc = new XmlDocument();doc.Load(ingoods.xml);/加载xml文件,路径未指定时默认在当前项目环境下XmlNode root = doc.SelectSingleNode(huowu); 选择要添加子节点的节点XmlElement stu = doc.CreateElement(goods);创建一个具有指定名称的子节点stu.SetAttribute(id”, id);XmlElement xmlsubl = doc.CreateElement(name);xmlsubl.InnerText = n

34、ame;stu.AppendChild(xmlsub1);XmlElement xmlsub2 = doc.CreateElement(size);xmlsub2.InnerText = size;stu.AppendChild(xmlsub2);XmlElement xmlsub3 = doc.CreateElement(species);xmlsub3.InnerText = species;stu.AppendChild(xmlsub3);XmlElement xmlsub4 = doc.CreateElement(unit);xmlsub4.InnerText = unit;stu.A

35、ppendChild(xmlsub4);XmlElement xmlsub5 = doc.CreateElement(number);xmlsub5.InnerText = number;stu.AppendChild(xmlsub5);root.AppendChild(stu);/将创建的item子节点添加到it ems节点的尾部doc.Save(ingoods.xml);/保存xml 文件,/入库时从总库中加上XmlDocument doc1 = new XmlDocument();doc1.Load(goods.xml);XmlNodeList list = doc1.SelectSin

36、gleNode(huowu).ChildNodes;获得根节点下的所有子节点/遍历所有子节点int x = 0;foreach (XmlNode node in list)XmlElement xe = (XmlElement)node;/将子节点类型转换为 XmlElement类型if (xe.GetAttribute(id) = id)x = 1;xe.SetAttribute(id”, id);如果下面有子节点在下走XmlNodeList nls = xe.ChildNodes;继续获取xe子节点的所有子节点foreach (XmlNode xn in nls)/遍历XmlElement

37、 xe2 = (XmlElement)xn; 转换类型if (xe2.Name = number)xe2.InnerText =Convert.ToString(Convert.ToInt32(xe2.InnerText) + Convert.ToInt32(number); break;if (x = 0)XmlNode root1 = doc1.SelectSingleNode(huowu); 选择要添加子节点 的节点XmlElement stu1 = doc1.CreateElement(goods);创建一个具有指定名称的子节点stu1.SetAttribute(id, id);Xml

38、Element xmlsub11 = doc1.CreateElement(name);xmlsub11.InnerText = name;stu1.AppendChild(xmlsub11);XmlElement xmlsub12 = doc1.CreateElement(size);xmlsub12.InnerText = size;stu1.AppendChild(xmlsub12);XmlElement xmlsub13 = doc1.CreateElement(species);xmlsub13.InnerText = species;stu1.AppendChild(xmlsub1

39、3);XmlElement xmlsub14 = doc1.CreateElement(unit);xmlsub14.InnerText = unit;stu1.AppendChild(xmlsub14);XmlElement xmlsub15 = doc1.CreateElement(number);xmlsub15.InnerText = number;stu1.AppendChild(xmlsub15);root1.AppendChild(stu1);/将创建的 item子节点添加 Uitems 节点的尾部doc1.Save(goods.xml);private void button7

40、_Click(object sender, EventArgs e)/入库创建string id = textBox1.Text;string name = textBox2.Text;string size = textBox3.Text;string species = textBox4.Text;string unit = textBox5.Text;string number = textBox6.Text;XmlTextWriter doc = new XmlTextWriter(ingoods.xml”, null);doc.Formatting = Formatting.Inde

41、nted; /使用自动缩进便于阅读doc.WriteStartElement(huowu);doc.WriteStartElement(goods);doc.WriteAttributeString(id”, id);doc.WriteElementString(name”, name);doc.WriteElementString(size”, size);doc.WriteElementString(species”, species);doc.WriteElementString(unit”, unit);doc.WriteElementString(number”, number);d

42、oc.WriteEndElement();doc.Close();/入库时从总库中加上XmlDocument doc1 = new XmlDocument();doc1.Load(goods.xml);XmlNodeList list = doc1.SelectSingleNode(huowu).ChildNodes;获得根节点下的所有子节点/遍历所有子节点int x = 0;foreach (XmlNode node in list)类型XmlElement xe = (XmlElement)node;/将子节点类型转换为 XmlElementif (xe.GetAttribute(id)

43、= id)x = 1;xe.SetAttribute(id”, id);如果下面有子节点在下走XmlNodeList nls = xe.ChildNodes;继续获取xe子节点的所有子节点foreach (XmlNode xn in nls)/遍历XmlElement xe2 = (XmlElement)xn; 转换类型if (xe2.Name = number)xe2.InnerText =Convert.ToString(Convert.ToInt32(xe2.InnerText) + Convert.ToInt32(number); break;if (x = 0)XmlNode roo

44、t1 = doc1.SelectSingleNode(huowu); 选择要添加子节点 的节点XmlElement stu1 = doc1.CreateElement(goods);创建一个具有指定名称的子节点stu1.SetAttribute(id, id);XmlElement xmlsub1 = doc1.CreateElement(name);xmlsub1.InnerText = name;stu1.AppendChild(xmlsub1);XmlElement xmlsub2 = doc1.CreateElement(size);xmlsub2.InnerText = size;s

45、tu1.AppendChild(xmlsub2);XmlElement xmlsub3 = doc1.CreateElement(species);xmlsub3.InnerText = species;stu1.AppendChild(xmlsub3);XmlElement xmlsub4 = doc1.CreateElement(unit);xmlsub4.InnerText = unit;stu1.AppendChild(xmlsub4);XmlElement xmlsub5 = doc1.CreateElement(number);xmlsub5.InnerText = number;

46、stu1.AppendChild(xmlsub5);root1.AppendChild(stu1);/将创建的it em子节点添加到it ems节点的尾部doc1.Save(goods.xml);private void button8_Click(object sender, EventArgs e)出库创建string id = textBox1.Text;string name = textBox2.Text;string size = textBox3.Text;string species = textBox4.Text;string unit = textBox5.Text;str

47、ing number = textBox6.Text;XmlTextWriter doc = new XmlTextWriter(outgoods.xml”, null);doc.Formatting = Formatting.Indented; /使用自动缩进便于阅读 doc.WriteStartElement(huowu);doc.WriteStartElement(goods);doc.WriteAttributeString(id”, id);doc.WriteElementString(name”, name);doc.WriteElementString(size”, size);

48、doc.WriteElementString(species”, species);doc.WriteElementString(unit”, unit);doc.WriteElementString(number”, number);doc.WriteEndElement();doc.Close();出库时从总库中减去XmlDocument doc1 = new XmlDocument();doc1.Load(goods.xml);XmlNodeList list = doc1.SelectSingleNode(huowu).ChildNodes;获得根节点下的所有子节点/遍历所有子节点int x = 0;foreach (XmlNode node in list)类型XmlElement xe = (XmlElement)node;/将子节点类型转换为 XmlElementif (xe.GetAttribute(id) = id) x = 1;xe.SetAttribute(id”, id);如果下面有子节点在下走XmlNodeList nls = xe.ChildNodes;继续获取xe子节点的所有子节点foreach (XmlNode xn in nls)/遍历XmlElement xe2 = (XmlElement)xn;

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论