public ActionResult Edit([Bind(Include = "MaDB,TenDB,TenHLV,DiaChi,TieuSu,SoCauThu,MaSVD,MaCT")] DOIBONG dOIBONG) { if (ModelState.IsValid) { db.Entry(dOIBONG).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaDB = new SelectList(db.BANGTONGKET, "DoiBong", "DoiBong", dOIBONG.MaDB); ViewBag.MaCT = new SelectList(db.CAUTHU, "MaCT", "HoTen", dOIBONG.MaCT); ViewBag.MaSVD = new SelectList(db.SANVANDONG, "MaSVD", "TenSVD", dOIBONG.MaSVD); return(View(dOIBONG)); }
// GET: DoiBong/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DOIBONG dOIBONG = db.DOIBONGs.Find(id); if (dOIBONG == null) { return(HttpNotFound()); } return(View(dOIBONG)); }
// Kiêm tra trong database đã có tên đội bóng a_TenDoiBong chưa? // Nếu có thì trả true, ngược lại trả false public static bool KiemTraTenDoiBongTrung(string a_TenDoiBong) { using (MyDatabaseQLDBDataContext db = new MyDatabaseQLDBDataContext()) { DOIBONG team = (from c in db.DOIBONGs where c.TENDOIBONG == a_TenDoiBong select c).FirstOrDefault(); if (team == null) { return(false); } } return(true); }
// GET: DoiBong/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DOIBONG dOIBONG = db.DOIBONGs.Find(id); if (dOIBONG == null) { return(HttpNotFound()); } ViewBag.MaSan = new SelectList(db.SANs, "MaSan", "TenSan", dOIBONG.MaSan); return(View(dOIBONG)); }
// GET: DOIBONGs/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DOIBONG dOIBONG = db.DOIBONG.Find(id); if (dOIBONG == null) { return(HttpNotFound()); } ViewBag.MaDB = new SelectList(db.BANGTONGKET, "DoiBong", "DoiBong", dOIBONG.MaDB); ViewBag.MaCT = new SelectList(db.CAUTHU, "MaCT", "HoTen", dOIBONG.MaCT); ViewBag.MaSVD = new SelectList(db.SANVANDONG, "MaSVD", "TenSVD", dOIBONG.MaSVD); return(View(dOIBONG)); }
private void btnXoa_Click(object sender, EventArgs e) { QLGVDBDQGEntities qlbddel = new QLGVDBDQGEntities(); string madoibong = tBmaDB.Text; DOIBONG DB = qlbddel.DOIBONGs.Where(db => db.MaDB == madoibong).SingleOrDefault(); if (DB != null) { qlbddel.DOIBONGs.Remove(DB); qlbddel.SaveChanges(); MessageBox.Show("Đã xóa", "Thông báo"); xemdulieu(); } else { MessageBox.Show("Có lỗi xảy ra...", "Lỗi"); } }
//Lấy danh sách đội bóng public static List <DOIBONG> DanhSachDB() { List <DOIBONG> dsdb = new List <DOIBONG>(); using (MyDatabaseQLDBDataContext db = new MyDatabaseQLDBDataContext()) { var Query = from n in db.DOIBONGs select n; foreach (var n in Query) { DOIBONG doibong = new DOIBONG(); doibong.MADB = n.MADB; doibong.TENDOIBONG = n.TENDOIBONG; doibong.TENSANNHA = n.TENSANNHA; dsdb.Add(doibong); } } return(dsdb); }
private void btnSua_Click(object sender, EventArgs e) { QLGVDBDQGEntities qlbdedit = new QLGVDBDQGEntities(); string madoibong = tBmaDB.Text; DOIBONG DB = qlbdedit.DOIBONGs.Where(db => db.MaDB == madoibong).SingleOrDefault(); if (DB != null) { DB.MaDB = Convert.ToString(tBmaDB.Text); DB.TenDB = Convert.ToString(tBtenDB.Text); DB.SanNha = Convert.ToString(tBsanNha.Text); qlbdedit.SaveChanges(); MessageBox.Show("Đã sửa", "Thông báo"); xemdulieu(); } else { MessageBox.Show("Có lỗi xảy ra...", "Lỗi"); } }
private void khoiTaoDoiBongButton_Click(object sender, EventArgs e) { //TODO: validate input //adding all player record from temporary player table and team info to database // Kiểm tra validate if (ValidateChildren(ValidationConstraints.ImmediateChildren | ValidationConstraints.Enabled)) { if (sanNhaComboBox.SelectedIndex == 0 || sanNhaComboBox.SelectedValue == null) { MessageBox.Show("Hãy chọn sân nhà thi đấu!"); return; } try { SANTHIDAU santhidau1; Database.SanThiDau_DAO.selectSanThiDau(sanNhaComboBox.SelectedValue.ToString(), out santhidau1); if ((!santhidau1.MaDoiNha.Equals("")) && (!santhidau1.MaDoiNha.Equals(selectedTeamId))) { var result = MessageBox.Show("Sân bạn chọn là sân nhà của một đội khác. Nếu tiếp tục, sân đã chọn sẽ không còn là sân nhà của đội bóng đó. Tiếp tục?", "Xác nhận", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } } DOIBONG doiBong = new DOIBONG() { TenDoi = tenDoiTextBox.Text, MaMuaGiai = GlobalState.selectedSeasonId }; if (selectedTeamId.Equals("")) { //insert team Database.DoiBong_DAO.createDoiBong(doiBong); //retrive newly created id doiBong.MaDoi = Database.DoiBong_DAO.queryMaDoiBong(tenDoiTextBox.Text, GlobalState.selectedSeasonId); //update home stadium //Console.WriteLine(sanNhaComboBox.SelectedValue.ToString()); SANTHIDAU santhidau = new SANTHIDAU() { MaSanThiDau = sanNhaComboBox.SelectedValue.ToString(), TenSanThiDau = santhidau1.TenSanThiDau, DonViSoHuu = santhidau1.DonViSoHuu, MaDoiNha = doiBong.MaDoi, }; Database.SanThiDau_DAO.updateSanThiDau(santhidau); KETQUADOIBONG kq = new KETQUADOIBONG(doiBong.MaDoi); Database.KetQuaDoiBong_DAO.createKetQuaDoiBong(kq); } else { doiBong.MaDoi = selectedTeamId; Database.DoiBong_DAO.updateDoiBong(doiBong); SANTHIDAU santhidau = new SANTHIDAU() { MaSanThiDau = sanNhaComboBox.SelectedValue.ToString(), TenSanThiDau = santhidau1.TenSanThiDau, DonViSoHuu = santhidau1.DonViSoHuu, MaDoiNha = selectedTeamId, }; Database.SanThiDau_DAO.updateSanThiDau(santhidau); } foreach (DataGridViewRow it_row in danhSachCauThuData.Rows) { CAUTHU cauthu = new CAUTHU() { TenCauThu = it_row.Cells[3].Value.ToString(), NgaySinh = DateTime.Parse(it_row.Cells[4].Value.ToString()), MaLoaiCauThu = Database.LoaiCauThu_DAO.queryMaLoaiCauThu(it_row.Cells[5].Value.ToString(), GlobalState.selectedSeasonId), GhiChu = it_row.Cells[6].Value.ToString(), MaDoi = doiBong.MaDoi, SoBanThang = 0, SoAo = Int16.Parse(it_row.Cells[1].Value.ToString()) }; Database.CauThu_DAO.createCauThu(cauthu); } //TODO: run stored procedure to check for minimum player count string res = Database.DoiBong_DAO.checkSoCauThuToiThieu(doiBong.MaDoi); if (!res.Equals("Thỏa điều kiện số cầu thủ tối thiểu")) { MessageBox.Show(res, "Thông báo"); } //create new team result record MessageBox.Show("Thêm thành công", "Thông báo"); //TODO: close form on saving surpressDiscardPrompt = true; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi xảy ra"); } } }