Exemplo n.º 1
0
 public bool AddCaHoc(CaHoc ca)
 {
     try
     {
         if (conn.State != ConnectionState.Open)
         {
             conn.Open();
         }
         SqlCommand cmd = new SqlCommand("CaHoc_Insert", conn);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.Add("@MaCa", SqlDbType.VarChar).Value       = ca._maca;
         cmd.Parameters.Add("@TenCa", SqlDbType.NVarChar).Value     = ca._tenca;
         cmd.Parameters.Add("@GioBatDau", SqlDbType.VarChar).Value  = ca._giobatdau;
         cmd.Parameters.Add("@GioKetThuc", SqlDbType.VarChar).Value = ca._gioketthuc;
         cmd.ExecuteNonQuery();
         conn.Close();
         return(true);
     }
     catch (Exception e)
     {
         conn.Close();
         Console.WriteLine(e);
         return(false);
     }
 }
Exemplo n.º 2
0
 private void btnSua_Click(object sender, EventArgs e)
 {
     if (dtgSuaCaHoc.RowCount > 0)
     {
         if (txtTenCa.Text == "" || dtpGioBatDau.Text == "" || dtpGioKetThuc.Text == "")
         {
             MessageBox.Show("Bạn còn thiếu thông tin nhập vào ! ", "LỖI", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         DateTime a = DateTime.Parse(dtpGioBatDau.Value.ToShortTimeString());
         DateTime b = DateTime.Parse(dtpGioKetThuc.Value.ToShortTimeString());
         if (a > b)
         {
             MessageBox.Show("Giờ bắt đầu học phải nhỏ hơn Giờ kết thúc ", "LỖI", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         _objcahoc = new CaHoc(dtgSuaCaHoc.CurrentRow.Cells[0].Value.ToString(), txtTenCa.Text, dtpGioBatDau.Text, dtpGioKetThuc.Text);
         if (_objcahocbus.EditCaHoc(_objcahoc))
         {
             LoadData();
             MessageBox.Show("Sửa Thành Công Ca Học ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             reset();
         }
         else
         {
             MessageBox.Show("Sửa Thất Bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     else
     {
         MessageBox.Show("Không có Ca học để sữa.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Exemplo n.º 3
0
 private void simpleButton1_Click(object sender, EventArgs e)
 {
     dgvContent.Enabled = false;
     ResetAllTextboxes();
     curClass = null;
     db.SaveChanges();
     BoundDataSource();
     dgvContent.Enabled = true;
 }
Exemplo n.º 4
0
        private void dgvContent_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.RowIndex >= dgvContent.RowCount)
            {
                return;
            }
            var classId = int.Parse(dgvContent.Rows[e.RowIndex].Cells[0].Value.ToString());

            curClass    = db.CaHocs.Where(ch => ch.Ma == classId).FirstOrDefault();
            tbTCH.Text  = curClass.Ten.ToString();
            tbTGBD.Text = curClass.ThoiGianBatDau.ToString();
            tbTGKT.Text = curClass.ThoiGianKetThuc.ToString();
        }
Exemplo n.º 5
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     if (curClass != null)
     {
         //db.CaHocs.Where(ch => ch.Ma == curClass.Ma).FirstOrDefault();
         //db.CaHocs.Where(ch => ch.Ten == curClass.Ten).FirstOrDefault();
         //db.CaHocs.Where(ch => ch.ThoiGianBatDau == curClass.ThoiGianBatDau).FirstOrDefault();
         //db.CaHocs.Where(ch => ch.ThoiGianKetThuc == curClass.ThoiGianKetThuc).FirstOrDefault();
         db.CaHocs.Remove(curClass);
         db.SaveChanges();
         curClass = null;
         BoundDataSource();
     }
 }
Exemplo n.º 6
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (dgvDSCaHoc.Rows.Count > 0)
            {
                for (int i = 0; i < dgvDSCaHoc.Rows.Count; i++)
                {
                    string maca, tenca, giobatdau, gioketthuc;
                    maca       = _objcahocbus.NextIDCaHoc();
                    tenca      = dgvDSCaHoc.Rows[i].Cells[1].Value.ToString();
                    giobatdau  = dgvDSCaHoc.Rows[i].Cells[2].Value.ToString();
                    gioketthuc = dgvDSCaHoc.Rows[i].Cells[3].Value.ToString();
                    _objcahoc  = new CaHoc(maca, tenca, giobatdau, gioketthuc);

                    if (_objcahocbus.AddCaHoc(_objcahoc))
                    {
                        dgvDSCaHoc.Rows.Remove(dgvDSCaHoc.Rows[i]);
                        i--;
                        LoadData();
                    }
                    else
                    {
                        string a = dgvDSCaHoc.Rows[i].Cells[0].Value.ToString();
                        MessageBox.Show("Lưu dòng " + a + " thất bại");
                    }
                }


                if (dgvDSCaHoc.Rows.Count == 0)
                {
                    MessageBox.Show("Lưu thành công");
                }

                txtTenCa.Text      = "";
                dtpGioBatDau.Text  = "";
                dtpGioKetThuc.Text = "";
            }
            else
            {
                MessageBox.Show("Không có dữ liệu để lưu ! ", "Thống báo ", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 7
0
 private void simpleButton2_Click(object sender, EventArgs e)
 {
     if (curClass == null)
     {
         CaHoc ch = new CaHoc()
         {
             Ten             = tbTCH.Text,
             ThoiGianBatDau  = TimeSpan.Parse(tbTGBD.Text),
             ThoiGianKetThuc = TimeSpan.Parse(tbTGKT.Text),
         };
         db.CaHocs.Add(ch);
     }
     else
     {
         curClass.Ten             = tbTCH.Text;
         curClass.ThoiGianBatDau  = TimeSpan.Parse(tbTGBD.Text);
         curClass.ThoiGianKetThuc = TimeSpan.Parse(tbTGKT.Text);
     }
     db.SaveChanges();
     BoundDataSource();
     dgvContent.Enabled = true;
 }
Exemplo n.º 8
0
 public bool EditCaHoc(CaHoc ch)
 {
     return(objCaHoc.EditCaHoc(ch));
 }
Exemplo n.º 9
0
 public bool AddCaHoc(CaHoc ch)
 {
     return(objCaHoc.AddCaHoc(ch));
 }