public void loadViewQTHT()
        {
            bdsQTHT.DataSource          = null;
            dtgQTHT.AutoGenerateColumns = false;
            var lsQTHT = QTHTService.getQTHT(qthtPathFile);

            if (lsQTHT != null)
            {
                bdsQTHT.DataSource = lsQTHT;
            }
            else
            {
                throw new Exception("QTHT không tồn tại!");
            }
            dtgQTHT.DataSource = bdsQTHT;
            //lblContact.Text = string.Format("Tổng contact: {0} mục", lsContactSort.Count());
        }
示例#2
0
 private void btnDongY_Click_1(object sender, EventArgs e)
 {
     if (qtht != null)
     {
         var tunam  = (int)numTuNam.Value;
         var dennam = (int)numDenNam.Value;
         var noihoc = txtNoiHoc.Text;
         QTHTService.Update(qtht.ID, pathQTHT, tunam, dennam, noihoc);
     }
     else
     {
         var tunam  = (int)numTuNam.Value;
         var dennam = (int)numDenNam.Value;
         var noihoc = txtNoiHoc.Text;
         QTHTService.Add(pathQTHT, tunam, dennam, noihoc);
     }
     MessageBox.Show("Đã cập nhật dữ liệu thành công");
     DialogResult = DialogResult.OK;
 }
        public frmThongTinSinhVien(string idStudent)
        {
            InitializeComponent();
            picAnhDaiDien.AllowDrop = true;
            anhDaiDienPathDirectory = Application.StartupPath + @"\AnhDaiDien";
            anhDaiDienPathFile      = anhDaiDienPathDirectory + @"\avatar.png";
            studentPathFile         = Application.StartupPath + @"\Data\student_data.txt";
            qthtPathFile            = Application.StartupPath + @"\Data\quatrinhhoctap.txt";
            loadViewQTHT();
            if (File.Exists(anhDaiDienPathFile))
            {
                FileStream fileStream = new FileStream(anhDaiDienPathFile, FileMode.Open, FileAccess.Read);
                picAnhDaiDien.Image = Image.FromStream(fileStream);
            }
            //var student = StudentService.getStudent(idStudent);
            var student = StudentService.getStudent(studentPathFile, idStudent);

            if (student == null)
            {
                throw new Exception("Lỗi rồi!");
            }
            else
            {
                txtMaSV.Text        = student.ID;
                txtHoTen.Text       = student.FullName;
                txtNgaySinh.Value   = student.DateOfBirth;
                txtNoiSinh.Text     = student.PlaceOfBirth;
                txtGioiTinh.Checked = student.Gender == Model.GENDER.Male;

                //student.qtht1 = QTHTService.getQTHT(idStudent);
                student.qtht1 = QTHTService.getQTHT(qthtPathFile, idStudent);

                bdsQTHT.DataSource = student.qtht1;
                //không cho tự tạo colum
                dtgQTHT.AutoGenerateColumns = false;
                dtgQTHT.DataSource          = bdsQTHT;
                lblMuc.Text = string.Format("{0} mục", student.qtht1.Count());
            }
        }
        /* private void btnXoa_Click(object sender, EventArgs e)
         * {
         *   var rs = MessageBox.Show("Bạn có thực sự muốn xóa hay không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
         *   if(rs== DialogResult.OK)
         *   {
         *       var history = (QTHT)bdsQTHT.Current;
         *       List<QTHT> h1 = (List<QTHT>) bdsQTHT.DataSource;//ép kiểu
         *       h1.Remove(history);
         *       bdsQTHT.DataSource = h1;
         *       bdsQTHT.ResetBindings(true);
         *       String xoa = history.ID + "#" + history.FromYear + "#" + history.ToYear + "#" + history.SchoolName;
         *       var Lines = File.ReadAllLines(qthtPathFile);
         *       var newLines = Lines.Where(line => !line.Contains(xoa));
         *       File.WriteAllLines(qthtPathFile, newLines);
         *       //Khai báo ô được chọn
         *       //int rowIndex = dtgQTHT.CurrentCell.RowIndex;
         *       //Xóa ô
         *       //dtgQTHT.Rows.RemoveAt(rowIndex);
         *       MessageBox.Show("Đã xóa thành công!");
         *   }
         *   else
         *   {
         *       MessageBox.Show("Xóa thất bại!");
         *   }
         * }*/
        private void btnXoa_Click(object sender, EventArgs e)
        {
            var history = bdsQTHT.Current as QTHT;

            if (history != null)
            {
                var rs = MessageBox.Show("Bạn có thực sự muốn xóa hay không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (rs == DialogResult.OK)
                {
                    QTHTService.Remove(qthtPathFile, history);
                    bdsQTHT.RemoveCurrent();
                    //Khai báo ô được chọn
                    //int rowIndex = dtgQTHT.CurrentCell.RowIndex;
                    //Xóa ô
                    //dtgQTHT.Rows.RemoveAt(rowIndex);
                    MessageBox.Show("Đã xóa thành công!");
                }
                else
                {
                    MessageBox.Show("Xóa thất bại!");
                }
            }
        }