コード例 #1
0
        //获取信息列表
        public static List <personinfo> getpersoninfolist(personinfo param)
        {
            List <personinfo> personlist = new List <personinfo>();
            XElement          xml        = XElement.Load(_basePath);
            var personvar = xml.Descendants("person");

            if (param.personid != 0)
            {
                personvar = xml.Descendants("person").Where(a => a.Attribute("personid").Value
                                                            == param.personid.ToString());
            }
            else if (!string.IsNullOrEmpty(param.Name))
            {
                personvar = xml.Descendants("person").Where(a => a.Element("name").Value
                                                            == param.Name);
            }
            personlist = (from person in personvar
                          select new personinfo
            {
                personid = Int32.Parse(person.Attribute("personid").Value),
                Name = person.Element("name").Value,
                Age = Int32.Parse(person.Element("age").Value),
                Tel = person.Element("tel").Value,
                Job = person.Element("job").Value,
                Adr = person.Element("adr").Value,
            }).ToList();
            return(personlist);
        }
コード例 #2
0
        private void BtnSelect_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == string.Empty)      //若未选择查询方式,则打印所有人员信息
            {
                dataGridView1.DataSource = personinfoBLL.getallpersoninfo();
                initheadtitle();
            }
            else
            {
                if (textBox1.Text != string.Empty)
                {
                    personinfo studentsearch = new personinfo();
                    switch (comboBox1.SelectedIndex)
                    {
                    case 0: studentsearch.personid = Int32.Parse(textBox1.Text); break;

                    case 1: studentsearch.Name = textBox1.Text; break;
                    }
                    dataGridView1.DataSource = personinfoBLL.getpersoninfolist(studentsearch);
                    initheadtitle();
                }
                else
                {
                    MessageBox.Show("请输入要查询的" + comboBox1.Text);
                }
            }
        }
コード例 #3
0
        public void initcontrol()       //将需要修改的行中的数据读取到输入框中
        {
            personinfo personinfo = personinfoBLL.getpersoninfo(personid_edit);

            if (personinfo != null)
            {
                textNo.Text   = personinfo.personid.ToString();
                textName.Text = personinfo.Name;
                textAge.Text  = personinfo.Age.ToString();
                textTel.Text  = personinfo.Tel;
                textJob.Text  = personinfo.Job;
                textAdr.Text  = personinfo.Adr;
            }
        }
コード例 #4
0
ファイル: Form_Add.cs プロジェクト: yuanshuai9312/XMLCsharp
        private void btnOK_Click(object sender, EventArgs e)
        {
            personinfo personinfo = new personinfo();               //新建一个personinfo对象,读取textBox中的值

            personinfo.personid = Int32.Parse(textNo.Text);
            personinfo.Name     = textName.Text;
            personinfo.Age      = Int32.Parse(textAge.Text);
            personinfo.Tel      = textTel.Text;
            personinfo.Job      = textJob.Text;
            personinfo.Adr      = textAdr.Text;
            if (personinfoBLL.Addpersoninfo(personinfo))
            {
                MessageBox.Show("添加成功!");
            }
        }
コード例 #5
0
        //更新按钮
        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            personinfo personinfo = personinfoBLL.getpersoninfo(personid_edit);

            personinfo.personid = Int32.Parse(textNo.Text);
            personinfo.Name     = textName.Text;
            personinfo.Age      = Int32.Parse(textAge.Text);
            personinfo.Tel      = textTel.Text;
            personinfo.Job      = textJob.Text;
            personinfo.Adr      = textAdr.Text;
            if (personinfoBLL.UpdatePersoninfo(personinfo))
            {
                MessageBox.Show("修改成功!");
            }
        }
コード例 #6
0
        //增加人员信息
        public static bool Addpersoninfo(personinfo param)
        {
            XElement xml       = XElement.Load(_basePath);
            XElement personXml = new XElement("person");

            personXml.Add(new XAttribute("personid", param.personid));
            personXml.Add(new XElement("name", param.Name));
            personXml.Add(new XElement("age", param.Age.ToString()));
            personXml.Add(new XElement("tel", param.Tel));
            personXml.Add(new XElement("job", param.Job));
            personXml.Add(new XElement("adr", param.Adr));
            xml.Add(personXml);
            xml.Save(_basePath);
            return(true);
        }
コード例 #7
0
        //根据姓名查询
        public static personinfo getpersoninfo(string name)
        {
            personinfo personinfo = new personinfo();
            XElement   xml        = XElement.Load(_basePath);

            personinfo = (from person in xml.Descendants("person")
                          where person.Attribute("name").Value == name
                          select new personinfo
            {
                personid = Int32.Parse(person.Attribute("personid").Value),
                Name = person.Element("name").Value,
                Age = Int32.Parse(person.Element("age").Value),
                Tel = person.Element("tel").Value,
                Job = person.Element("job").Value,
                Adr = person.Element("adr").Value,
            }).Single();
            return(personinfo);
        }
コード例 #8
0
        //修改人员信息
        public static bool UpdatePersoninfo(personinfo param)
        {
            bool result = false;

            if (param.personid > 0)
            {
                XElement xml       = XElement.Load(_basePath);
                XElement personxml = (from db in xml.Descendants("person")
                                      where db.Attribute("personid").Value == param.personid.ToString()
                                      select db).Single();
                personxml.SetElementValue("name", param.Name);
                personxml.SetElementValue("age", param.Age.ToString());
                personxml.SetElementValue("tel", param.Tel);
                personxml.SetElementValue("job", param.Job);
                personxml.SetElementValue("adr", param.Adr);
                xml.Save(_basePath);
                result = true;
            }
            return(result);
        }