Ejemplo n.º 1
0
 public static void Update(string path, QuaTrinh quaTrinh)
 {
     if (File.Exists(path))
     {
         List <string> rs    = new List <string>();
         var           lines = File.ReadAllLines(path);
         foreach (var line in lines)
         {
             var item = QuaTrinh.Parse(line);
             if (item.ID == quaTrinh.ID)
             {
                 rs.Add(quaTrinh.Parse());
             }
             else
             {
                 rs.Add(line);
             }
         }
         File.WriteAllLines(path, rs);
     }
     else
     {
         throw new Exception("File dữ liệu không tồn tại");
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Thêm mới một quá trình học tập
 /// </summary>
 /// <param name="path">path</param>
 /// <param name="quaTrinh">Quatrinh</param>
 public static void Add(string path, QuaTrinh quaTrinh)
 {
     if (File.Exists(path))
     {
         var qt = QuaTrinh.Parse(quaTrinh);
         File.AppendAllText(path, qt);
     }
     else
     {
         throw new Exception("File dữ liệu không tồn tại");
     }
 }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (quaTrinhHocTap != null)
            {
                // xử lý sửa thông tin
                int      from     = int.Parse(nudFromYear.Value.ToString());
                int      to       = int.Parse(nudToYear.Value.ToString());
                string   school   = txtAddress.Text;
                QuaTrinh quaTrinh = new QuaTrinh
                {
                    ID        = quaTrinhHocTap.ID,
                    YearFrom  = from,
                    YearTo    = to,
                    Address   = school,
                    idStudent = idSinhVien
                };
                QuaTrinhService.Update(pathQuaTrinh, quaTrinh);
                if (MessageBox.Show("Đã Sửa thành công", "Thông báo", MessageBoxButtons.OK) == DialogResult.OK)
                {
                    this.Close();
                }
            }
            else
            {
                // xử lý thêm mới
                int    from   = int.Parse(nudFromYear.Value.ToString());
                int    to     = int.Parse(nudToYear.Value.ToString());
                string school = txtAddress.Text;

                /*
                 * Guid.NewGuid().ToString()
                 * tạo id với 32 kí tự
                 */

                int      id       = QuaTrinhService.GetIdMax(pathQuaTrinh);
                QuaTrinh quaTrinh = new QuaTrinh
                {
                    ID        = (id + 1).ToString(),
                    YearFrom  = from,
                    YearTo    = to,
                    Address   = school,
                    idStudent = idSinhVien
                };
                QuaTrinhService.Add(pathQuaTrinh, quaTrinh);
                if (MessageBox.Show("Đã Thêm thành công", "Thông báo", MessageBoxButtons.OK) == DialogResult.OK)
                {
                    this.Close();
                }
            }
        }
Ejemplo n.º 4
0
        public static int GetIdMax(string path)
        {
            int c     = 0;
            var lines = File.ReadAllLines(path);

            foreach (var line in lines)
            {
                var item = QuaTrinh.Parse(line);
                if (int.Parse(item.ID) > c && item != null)
                {
                    c = int.Parse(item.ID);
                }
            }
            return(c);
        }
Ejemplo n.º 5
0
 public frmAddQuaTrinh(QuaTrinh quaTrinh, string idSv)
 {
     InitializeComponent();
     pathQuaTrinh   = Application.StartupPath + @"\Data\quatrinh.txt";
     idSinhVien     = idSv;
     quaTrinhHocTap = quaTrinh;
     if (quaTrinh != null)
     {
         this.Text         = "Cập nhật thông tin";
         btnThem.Text      = "Cập nhật";
         nudFromYear.Value = quaTrinh.YearFrom;
         nudToYear.Value   = quaTrinh.YearTo;
         txtAddress.Text   = quaTrinh.Address;
     }
     else
     {
         this.Text    = "Thêm quá trình học tập";
         btnThem.Text = "Thêm";
     }
 }
Ejemplo n.º 6
0
        public static List <QuaTrinh> getListQuaTrinh(string idSinhVien)
        {
            List <QuaTrinh> quaTrinhs = new List <QuaTrinh>();
            int             t         = 1;

            for (int i = 2000; i < 2020; i++)
            {
                QuaTrinh qt = new QuaTrinh
                {
                    ID        = t.ToString(),
                    YearFrom  = i,
                    YearTo    = i + 2,
                    Address   = "Hà Nội",
                    idStudent = idSinhVien
                };
                quaTrinhs.Add(qt);
                t++;
            }
            return(quaTrinhs);
        }
Ejemplo n.º 7
0
 public frmQuaTrinhHocTapChiTiet(QuaTrinh history = null, string maSinhVien = null, string pathHistoryFile = null)
 {
     InitializeComponent();
     this.history    = history;
     this.maSinhVien = maSinhVien;
     this.pathLearningHistoryDataFile = pathHistoryFile;
     if (history != null)
     {
         //Chỉnh Sửa
         this.Text       = "Chỉnh sửa quá trình học tập";
         numTuNam.Value  = history.YearFrom;
         numDenNam.Value = history.YearTo;
         txtNoiHoc.Text  = history.Address;
     }
     else
     {
         //Thêm mới
         this.Text = "Thêm mới quá trình học tập";
     }
 }
Ejemplo n.º 8
0
 public static List <QuaTrinh> getListQuaTrinh(string path, string idSinhVien)
 {
     if (File.Exists(path))
     {
         List <QuaTrinh> quaTrinhs = new List <QuaTrinh>();
         var             lines     = File.ReadAllLines(path);
         int             t         = 1;
         foreach (var l in lines)
         {
             var quatrinh = QuaTrinh.Parse(l);
             if (quatrinh.idStudent == idSinhVien)
             {
                 quaTrinhs.Add(quatrinh);
             }
         }
         return(quaTrinhs);
     }
     else
     {
         return(null);
     }
 }