private void btn_add_Click(object sender, EventArgs e)
        {
            studentinfo studentinfo = new studentinfo();

            studentinfo.studentid = Int32.Parse(txt_studengid.Text);
            studentinfo.Name      = txt_name.Text;
            if (rb_man.Checked)
            {
                studentinfo.sex = "男";
            }
            else if (rb_woman.Checked)
            {
                studentinfo.sex = "女";
            }
            studentinfo.Age         = Int32.Parse(txt_age.Text);
            studentinfo.Birthdate   = DateTime.Parse(dt_birthdate.Text);
            studentinfo.Phone       = txt_phone.Text;
            studentinfo.Email       = txt_email.Text;
            studentinfo.Homeaddress = txt_homeaddress.Text;
            studentinfo.Profession  = txt_profession.Text;
            if (studentinfoBLL.Addstudentinfo(studentinfo))
            {
                MessageBox.Show("添加成功!");
            }
        }
Esempio n. 2
0
        private void btn_update_Click(object sender, EventArgs e)
        {
            studentinfo studentinfo = studentinfoBLL.getstudentinfo(studentid_edit);

            studentinfo.studentid = Int32.Parse(txt_stuengid.Text);
            studentinfo.Name      = txt_name.Text;
            if (rb_man.Checked)
            {
                studentinfo.sex = "Man";
            }
            else if (rb_woman.Checked)
            {
                studentinfo.sex = "Woman";
            }
            studentinfo.Age         = Int32.Parse(txt_age.Text);
            studentinfo.Birthdate   = DateTime.Parse(dt_birthdate.Text);
            studentinfo.Phone       = txt_phone.Text;
            studentinfo.Email       = txt_email.Text;
            studentinfo.Homeaddress = txt_familyaddress.Text;
            studentinfo.Profession  = txt_profession.Text;
            if (studentinfoBLL.UpdateStudentinfo(studentinfo))
            {
                MessageBox.Show("Information has been updated!");
            }
        }
        //获取列表
        public static List <studentinfo> getstudentinfolist(studentinfo param)
        {
            List <studentinfo> studentlist = new List <studentinfo>();
            XElement           xml         = XElement.Load(_basePath);
            var studentvar = xml.Descendants("student");

            if (param.studentid != 0)
            {
                studentvar = xml.Descendants("student").Where(a => a.Attribute("studentid").Value
                                                              == param.studentid.ToString());
            }
            else if (!string.IsNullOrEmpty(param.Name))
            {
                studentvar = xml.Descendants("student").Where(a => a.Attribute("studentid").Value
                                                              == param.Name);
            }
            studentlist = (from student in studentvar
                           select new studentinfo
            {
                studentid = Int32.Parse(student.Attribute("studentid").Value),
                Name = student.Element("name").Value,
                Age = Int32.Parse(student.Element("age").Value),
                sex = student.Element("sex").Value,
                Birthdate = DateTime.Parse(student.Element("birthdate").Value),
                Phone = student.Element("phone").Value,
                Homeaddress = student.Element("homeaddress").Value,
                Email = student.Element("email").Value,
                Profession = student.Element("profession").Value
            }).ToList();
            return(studentlist);
        }
Esempio n. 4
0
        public void initcontrol()
        {
            studentinfo studentinfo = studentinfoBLL.getstudentinfo(studentid_edit);

            if (studentinfo != null)
            {
                txt_stuengid.Text = studentinfo.studentid.ToString();
                txt_name.Text     = studentinfo.Name;
                if (studentinfo.sex == "Man")
                {
                    rb_man.Checked   = true;
                    rb_woman.Checked = false;
                }
                else
                {
                    rb_woman.Checked = true;
                    rb_man.Checked   = false;
                }
                txt_age.Text           = studentinfo.Age.ToString();
                dt_birthdate.Text      = studentinfo.Birthdate.ToString();
                txt_phone.Text         = studentinfo.Phone;
                txt_email.Text         = studentinfo.Email;
                txt_familyaddress.Text = studentinfo.Homeaddress;
                txt_profession.Text    = studentinfo.Profession;
            }
        }
Esempio n. 5
0
        private void btn_search_Click(object sender, EventArgs e)
        {
            if (cb_search.Text == string.Empty)
            {
                dataGridView1.DataSource = studentinfoBLL.getallstudentinfo();
                initheadtitle();
            }
            else
            {
                if (txt_searchtxt.Text != string.Empty)
                {
                    studentinfo studentsearch = new studentinfo();
                    switch (cb_search.SelectedIndex)
                    {
                    case 0: studentsearch.studentid = Int32.Parse(txt_searchtxt.Text); break;

                    case 1: studentsearch.Name = txt_searchtxt.Text; break;
                    }
                    dataGridView1.DataSource = studentinfoBLL.getstudentinfolist(studentsearch);
                    initheadtitle();
                }
                else
                {
                    MessageBox.Show("请输入要查询的" + cb_search.Text);
                }
            }
        }
        //增加学生信息
        public static bool Addstudentinfo(studentinfo param)
        {
            XElement xml        = XElement.Load(_basePath);
            XElement studentXml = new XElement("student");

            studentXml.Add(new XAttribute("studentid", param.studentid));
            studentXml.Add(new XElement("name", param.Name));
            studentXml.Add(new XElement("sex", param.sex));
            studentXml.Add(new XElement("age", param.Age.ToString()));
            studentXml.Add(new XElement("birthdate", param.Birthdate.ToString("yyyy-MM-dd")));
            studentXml.Add(new XElement("phone", param.Phone));
            studentXml.Add(new XElement("homeaddress", param.Homeaddress));
            studentXml.Add(new XElement("email", param.Email));
            studentXml.Add(new XElement("profession", param.Profession));
            xml.Add(studentXml);
            xml.Save(_basePath);
            return(true);
        }
Esempio n. 7
0
 private void toolStripMenuItem_views_Click(object sender, EventArgs e)
 {
     if (dataGridView1.SelectedRows.Count == 1)
     {
         int selectrow = Int32.Parse(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex]
                                     .Cells[0].Value.ToString());
         studentinfo studentinfo = studentinfoBLL.getstudentinfo(selectrow);
         //this.Hide();
         Form1 form1 = new Form1();
         form1.passed_save_dir = studentinfo.Profession;
         //form1.Closed += (s, args) => this.Close();
         form1.Show();
     }
     else
     {
         MessageBox.Show("Please select one row!");
     }
 }
Esempio n. 8
0
        //删除信息
        public static bool Deletestudentinfo(int studentid)
        {
            bool result = false;

            if (studentid > 0)
            {
                XElement xml        = XElement.Load(_basePath);
                XElement studentxml = (from db in xml.Descendants("student")
                                       where db.Attribute("studentid").Value == studentid.ToString()
                                       select db).Single();
                studentinfo Studentinfo = getstudentinfo(studentid);
                studentxml.Remove();
                xml.Save(_basePath);
                result = true;

                DeleteDirectory(Studentinfo.Profession);
            }
            return(result);
        }
        //根据姓名查询
        public static studentinfo getstudentinfo(string name)
        {
            studentinfo Studentinfo = new studentinfo();
            XElement    xml         = XElement.Load(_basePath);

            Studentinfo = (from student in xml.Descendants("student")
                           where student.Attribute("name").Value == name
                           select new studentinfo
            {
                studentid = Int32.Parse(student.Attribute("studentid").Value),
                Name = student.Element("name").Value,
                Age = Int32.Parse(student.Element("age").Value),
                sex = student.Element("sex").Value,
                Birthdate = DateTime.Parse(student.Element("birthdate").Value),
                Phone = student.Element("phone").Value,
                Homeaddress = student.Element("homeaddress").Value,
                Email = student.Element("email").Value,
                Profession = student.Element("profession").Value
            }).Single();
            return(Studentinfo);
        }
Esempio n. 10
0
        private void toolStripButton_openDir_Click(object sender, EventArgs e)
        {
            try
            {
                if (dataGridView1.SelectedRows.Count == 1)
                {
                    int selectrow = Int32.Parse(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex]
                                                .Cells[0].Value.ToString());
                    studentinfo studentinfo = studentinfoBLL.getstudentinfo(selectrow);


                    Process.Start(studentinfo.Profession);
                }
                else
                {
                    MessageBox.Show("Please select one row!");
                }
            }
            catch (Exception ex) {
                MessageBox.Show("Target Folder has been deleted");
            }
        }
        //修改学生信息
        public static bool UpdateStudentinfo(studentinfo param)
        {
            bool result = false;

            if (param.studentid > 0)
            {
                XElement xml        = XElement.Load(_basePath);
                XElement studentxml = (from db in xml.Descendants("student")
                                       where db.Attribute("studentid").Value == param.studentid.ToString()
                                       select db).Single();
                studentxml.SetElementValue("name", param.Name);
                studentxml.SetElementValue("sex", param.sex);
                studentxml.SetElementValue("age", param.Age.ToString());
                studentxml.SetElementValue("birthdate", param.Birthdate.ToString("yyyy-MM-dd"));
                studentxml.SetElementValue("phone", param.Phone);
                studentxml.SetElementValue("homeaddress", param.Homeaddress);
                studentxml.SetElementValue("email", param.Email);
                studentxml.SetElementValue("profession", param.Profession);
                xml.Save(_basePath);
                result = true;
            }
            return(result);
        }
Esempio n. 12
0
        private void btn_add_Click(object sender, EventArgs e)
        {
            studentinfo studentinfo = new studentinfo();

            try
            {
                int      Input_ID   = Int32.Parse(txt_studengid.Text);
                XElement xml        = XElement.Load(_basePath);
                var      studentvar = xml.Descendants("student");
                if (Input_ID != 0)
                {
                    studentvar = xml.Descendants("student").Where(a => a.Attribute("studentid").Value
                                                                  == Input_ID.ToString());
                }
                if (studentvar.ToList().Count > 0)
                {
                    throw new System.ArgumentException("Id is unique", "original");
                }
                else
                {
                    studentinfo.studentid = Int32.Parse(txt_studengid.Text);
                }



                studentinfo.Name = txt_name.Text;
                if (rb_man.Checked)
                {
                    studentinfo.sex = "Man";
                }
                else if (rb_woman.Checked)
                {
                    studentinfo.sex = "Woman";
                }

                studentinfo.Age         = Int32.Parse(txt_age.Text);
                studentinfo.Birthdate   = DateTime.Parse(dt_birthdate.Text);
                studentinfo.Phone       = txt_phone.Text;
                studentinfo.Email       = txt_email.Text;
                studentinfo.Homeaddress = txt_homeaddress.Text;
                saved_path = "C://Users//hpsin//Desktop//Data//" + studentinfo.studentid + "_" + studentinfo.Name;
                //if (txt_profession.Text == "")
                //{

                //    throw new Exception();
                //}
                //else {
                studentinfo.Profession = saved_path;
                //}


                System.IO.Directory.CreateDirectory(saved_path);



                if (studentinfoBLL.Addstudentinfo(studentinfo))
                {
                    MessageBox.Show("Add successfully, data will be saved in: " + saved_path);
                }
            }

            catch (System.ArgumentException ae) {
                MessageBox.Show("Patient ID has been registered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
            }
            catch (FormatException format) {
                MessageBox.Show("Patient ID or age should be a number!");
            }
            catch (Exception exception)
            {
                MessageBox.Show("Please complete all items!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
            }
        }