예제 #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;
        }