示例#1
0
        static void Main(string[] args)
        {
            StudentDetails objStudent = new StudentDetails("Minh", 19);

            Console.WriteLine("Student name " + objStudent.studName);
            Console.WriteLine("Roll number " + objStudent.rollNumber);
        }
示例#2
0
文件: Program.cs 项目: hungdaycb00/C-
        static void Snippet10()
        {
            Students.StudentDetails st = new Students.StudentDetails();
            ScoreReport1            sc = new ScoreReport1();

            Console.WriteLine("Subject: " + sc.Subject);
            Console.WriteLine("Marks: " + sc.Marks);
        }
示例#3
0
 public void DeleteStudent(StudentDetails stud)
 {
     foreach (XElement elem in studentsList.Descendants("Student"))
     {
         if ((int)elem.Element(strStudentID) == stud.StudentID)
         {
             elem.Remove();
             studentsList.Save(file);
             break;
         }
     }
 }
示例#4
0
 public void DeleteStudent(StudentDetails stud)
 {
     List<StudentDetails> list = ReadToListFromJsonFile(path);
     foreach (StudentDetails student in list)
     {
         if (student.StudentID == stud.StudentID)
         {
             list.Remove(student);
             break;
         }
     }
     WriteListToJsonFile(list, path);
 }
示例#5
0
 public void DeleteStudent(StudentDetails stud)
 {
     //SqlConnection con = new SqlConnection(connectionString);
     string sql = "Delete Student Where studentID=" + stud.StudentID;
     SqlCommand cmd = new SqlCommand(sql, con);
     using (con)
     {
         con.Open();
         int numAff = cmd.ExecuteNonQuery();
     }
     string path = System.AppDomain.CurrentDomain.BaseDirectory + stud.Foto;
     if (File.Exists(path))
         File.Delete(path);
 }
示例#6
0
        public void ExportToJson()
        {
            IEnumerable<XElement> match = from student in studentsList.Descendants("Student")
                                          select student;

            List<StudentDetails> list = new List<StudentDetails>();
            foreach (XElement e in match.ToList())
            {
                StudentDetails st = new StudentDetails((int)e.Element(strStudentID), (string)e.Element(strFirstName), (string)e.Element(strSecondName), (string)e.Element(strDateOfBirth), (string)e.Element(strFoto));
                list.Add(st);
            }
            if (list != null)
                (new JsonStudentDB()).WriteListToJsonFile(list);
        }
示例#7
0
 public int InsertStudent(StudentDetails stud)
 {
     JavaScriptSerializer js = new JavaScriptSerializer();
     string JsonStudent = js.Serialize(stud);
     List<StudentDetails> list = ReadToListFromJsonFile(path);
     int max = 0;
     foreach (StudentDetails student in list)
     {
         if (student.StudentID > max)
             max = student.StudentID;
     }
     stud.StudentID = ++max;
     list.Add(stud);
     WriteListToJsonFile(list, path);
     AddFoto(stud);
     return 0;
 }
示例#8
0
        public int InsertStudent(StudentDetails stud)
        {
            string sql = "Insert Into Student (FirstName,SecondName,DateOfBirth) Values ('" + stud.FirstName + "','" + stud.SecondName + "','" + stud.DateOfBirth + "')";
            SqlCommand cmd = new SqlCommand(sql, con);
            int number;
            using (con)
            {
                con.Open();
                number = cmd.ExecuteNonQuery();
            }

            AddFoto(stud);
            return number;
        }
示例#9
0
        private void AddFoto(StudentDetails stud)
        {
            string pathToFoto = System.AppDomain.CurrentDomain.BaseDirectory + "\\Foto\\";
            if (File.Exists(pathToFoto + "Temp.jpg"))
            {
                con = new SqlConnection(connectionString);
                string sql = "select StudentID from Student Where FirstName='" + stud.FirstName + "' AND SecondName='" + stud.SecondName + "' AND DateOfBirth='" + stud.DateOfBirth + "'";
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataReader reader;
                int id = 0;
                using (con)
                {
                    con.Open();
                    reader = cmd.ExecuteReader();
                    if (reader != null)
                    {
                        reader.Read();
                        id = (int)reader["StudentID"];
                    }
                    //id = (string)cmd.ExecuteScalar();
                }

                if (File.Exists(pathToFoto + id + ".jpg"))
                    File.Delete(pathToFoto + id + ".jpg");
                File.Copy(pathToFoto + "Temp.jpg", pathToFoto + id + ".jpg");
                File.Delete(pathToFoto + "Temp.jpg");

                string foto = "";
                con = new SqlConnection(connectionString);
                if (File.Exists(pathToFoto + id + ".jpg"))
                    foto = @"\Foto\" + id + ".jpg";
                sql = "update Student Set Foto='" + foto + "' From Student Where studentID='" + id + "'";
                cmd = new SqlCommand(sql, con);
                using (con)
                {
                    con.Open();
                    cmd.ExecuteNonQuery();
                }
            }
        }
示例#10
0
 public void UpdateStudent(StudentDetails stud)
 {
     string sql = "";
     sql += "Update Student";
     sql += " Set firstName='" + stud.FirstName + "',secondName='" + stud.SecondName + "', dateOfBirth='" + stud.DateOfBirth + "'";
     sql += " From Student Where studentID='" + stud.StudentID+"'";
     SqlCommand cmd = new SqlCommand(sql, con);
     using (con)
     {
         con.Open();
         int numAff = cmd.ExecuteNonQuery();
     }
     AddFoto(stud);
 }
示例#11
0
        public void UpdateStudent(StudentDetails stud)
        {
            List<StudentDetails> list = ReadToListFromJsonFile(path);
            foreach (StudentDetails student in list)
            {
                if (student.StudentID == stud.StudentID)
                {
                    student.FirstName = stud.FirstName;
                    student.SecondName = stud.SecondName;
                    student.DateOfBirth = stud.DateOfBirth;
                }
            }

            WriteListToJsonFile(list, path);
            AddFoto(stud);
        }
示例#12
0
        private void AddFoto(StudentDetails stud)
        {
            string pathToFoto = System.AppDomain.CurrentDomain.BaseDirectory + "\\Foto\\";
            if (File.Exists(pathToFoto + "Temp.jpg"))
            {
                List<StudentDetails> list = ReadToListFromJsonFile(path);
                int id = 0;
                foreach (StudentDetails student in list)
                {
                    if (student.FirstName == stud.FirstName && student.SecondName == student.SecondName && stud.DateOfBirth == stud.DateOfBirth)
                        id = student.StudentID;
                }
                if (File.Exists(pathToFoto + id + ".jpg"))
                    File.Delete(pathToFoto + id + ".jpg");
                File.Copy(pathToFoto + "Temp.jpg", pathToFoto + id + ".jpg");
                File.Delete(pathToFoto + "Temp.jpg");

                string foto = "";
                if (File.Exists(pathToFoto + id + ".jpg"))
                    foto = @"\Foto\" + id + ".jpg";
                foreach (StudentDetails student in list)
                {
                    if (student.StudentID == id)
                        student.Foto = foto;
                }
                WriteListToJsonFile(list, path);
            }
        }
示例#13
0
        private void AddFoto(StudentDetails stud)
        {
            string pathToFoto = System.AppDomain.CurrentDomain.BaseDirectory + "\\Foto\\";
            if (File.Exists(pathToFoto + "Temp.jpg"))
            {
                int id = 0;
                foreach (XElement elem in studentsList.Descendants("Student"))
                {
                    if ((string)elem.Element(strFirstName) == stud.FirstName && (string)elem.Element(strSecondName) == stud.SecondName && (string)elem.Element(strDateOfBirth) == stud.DateOfBirth)
                    {
                        id = (int)elem.Element(strStudentID);
                    }
                }

                if (File.Exists(pathToFoto + id + ".jpg"))
                    File.Delete(pathToFoto + id + ".jpg");
                File.Copy(pathToFoto + "Temp.jpg", pathToFoto + id + ".jpg");
                File.Delete(pathToFoto + "Temp.jpg");

                string foto = "";
                if (File.Exists(pathToFoto + id + ".jpg"))
                    foto = @"\Foto\" + id + ".jpg";
                foreach (XElement elem in studentsList.Descendants("Student"))
                {
                    if ((int)elem.Element(strStudentID) == id)
                    {
                        elem.Element(strFoto).Value = foto;
                        studentsList.Save(file);
                    }
                }
            }
        }
示例#14
0
 public void UpdateStudent(StudentDetails stud)
 {
     foreach (XElement elem in studentsList.Descendants("Student"))
     {
         if ((int)elem.Element(strStudentID) == stud.StudentID)
         {
             elem.Element(strFirstName).Value = stud.FirstName;
             elem.Element(strSecondName).Value = stud.SecondName;
             elem.Element(strDateOfBirth).Value = stud.DateOfBirth;
             studentsList.Save(file);
         }
     }
     AddFoto(stud);
 }
示例#15
0
        public int InsertStudent(StudentDetails stud)
        {
            int maxId=0;
            if (studentsList.HasElements)
                maxId = studentsList.Elements("Student").Max(t => Int32.Parse(t.Element(strStudentID).Value));
            XElement track = new XElement("Student",
                new XElement(strStudentID, ++maxId),
                new XElement(strFirstName, stud.FirstName),
                new XElement(strSecondName, stud.SecondName),
                new XElement(strDateOfBirth, stud.DateOfBirth),
                new XElement(strFoto, ""));

            studentsList.Add(track);
            studentsList.Save(file);
            AddFoto(stud);
            return 0;
        }