private void themVongDau_Click(object sender, EventArgs e) { if (ValidateChildren(ValidationConstraints.Enabled)) { if (tenVongDauTextBox.Text == "") { MessageBox.Show("Hãy đặt tên cho vòng đấu!"); } else { try { VONGDAU vongdau = new VONGDAU() { TenVongDau = tenVongDauTextBox.Text, MaMuaGiai = (string)muaGiaiComboBox.SelectedValue, }; Database.VongDau_DAO.createVongDau(vongdau); tenVongDauTextBox.Text = ""; xoaVongDau.Enabled = false; MessageBox.Show("Thêm thành công", "Thông báo"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi xảy ra"); } this.vongDauTableAdapter.Fill(this.quanLyGiaiVoDichDataSet.VongDau); } } }
public static void importVongDau(string filename) { Encoding encoding = Encoding.UTF8; string output = File.ReadAllText(filename, encoding); string[] stringSeparators = new string[] { "\n" }; List <string> lines = new List <string>(output.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries)); bool ignoreHeader = true; foreach (string line in lines) { if (ignoreHeader) { ignoreHeader = false; continue; } try { VONGDAU vongdau = new VONGDAU() { TenVongDau = line.Trim(), MaMuaGiai = GlobalState.selectedSeasonId, }; Database.VongDau_DAO.createVongDau(vongdau); } catch (Exception ex) { MessageBox.Show("Tại {" + line.Trim() + "} xảy ra lỗi: " + ex.Message, "Lỗi xảy ra"); } } }
public static void selectVongDau(string MaVongDau, out VONGDAU vongdau) { SqlConnection conn = DatabaseManager.Instance.getConnection(); string queryString = "SELECT TenVongDau, MaMuaGiai FROM VONGDAU WHERE MaVongDau = @MaVongDau"; SqlCommand command = new SqlCommand(queryString); vongdau = new VONGDAU() { TenVongDau = "", MaMuaGiai = "", }; try { command.Parameters.AddWithValue("@MaVongDau", MaVongDau); command.Connection = conn; SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { vongdau.TenVongDau = reader.GetString(0); vongdau.MaMuaGiai = reader.GetString(1); } reader.Close(); } catch (SqlException SQLex) { throw SQLex; } catch (Exception ex) { throw ex; } }
public static void updateVongDau(VONGDAU vongdau) { SqlConnection conn = DatabaseManager.Instance.getConnection(); string queryString = "UPDATE VONGDAU SET TenVongDau = @TenVongDau, MaMuaGiai = @MaMuaGiai WHERE MaVongDau = @MaVongDau"; SqlCommand command = new SqlCommand(queryString); try { command.Parameters.AddWithValue("@MaMuaGiai", vongdau.MaMuaGiai); command.Parameters.AddWithValue("@TenVongDau", vongdau.TenVongDau); command.Parameters.AddWithValue("@MaVongDau", vongdau.MaVongDau); command.Connection = conn; int res = command.ExecuteNonQuery(); if (res == 0) { throw new Exception("Cannot update Round!"); } } catch (SqlException SQLex) { throw SQLex; } catch (Exception ex) { throw ex; } }
//public static void createVongDau(string TenVongDau, string MaMuaGiai) public static void createVongDau(VONGDAU vongdau) { SqlConnection conn = DatabaseManager.Instance.getConnection(); string queryString = "INSERT INTO VONGDAU Values (NEWID(),@TenVongDau,@MaMuaGiai)"; SqlCommand command = new SqlCommand(queryString); try { command.Parameters.AddWithValue("@MaMuaGiai", vongdau.MaMuaGiai); command.Parameters.AddWithValue("@TenVongDau", vongdau.TenVongDau); command.Connection = conn; int res = command.ExecuteNonQuery(); if (res == 0) { throw new Exception("Cannot insert New Round!"); } } catch (SqlException SQLex) { throw SQLex; } catch (Exception ex) { throw ex; } }
public static string queryMaVongDau(VONGDAU vongdau) { SqlConnection conn = DatabaseManager.Instance.getConnection(); string queryString = "SELECT MaVongDau FROM VONGDAU WHERE TenVongDau = @TenVongDau AND MaMuaGiai = @MaMuaGiai"; SqlCommand command = new SqlCommand(queryString); string result = ""; try { command.Parameters.AddWithValue("@TenVongDau", vongdau.TenVongDau); command.Parameters.AddWithValue("@MaMuaGiai", vongdau.MaMuaGiai); command.Connection = conn; SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { if (!reader.IsDBNull(0)) { result = reader.GetString(0); } } reader.Close(); } catch (SqlException SQLex) { throw SQLex; } catch (Exception ex) { throw ex; } return(result); }
public ActionResult DeleteConfirmed(int id) { VONGDAU vONGDAU = db.VONGDAUs.Find(id); db.VONGDAUs.Remove(vONGDAU); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "IDVONGDAU,IDMTD,IDHT,TENVONGDAU")] VONGDAU vONGDAU) { if (ModelState.IsValid) { db.Entry(vONGDAU).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IDHT = new SelectList(db.HOITHAOs, "IDHT", "TENHT", vONGDAU.IDHT); ViewBag.IDMTD = new SelectList(db.MONTHIDAUs, "IDMTD", "TENMTD", vONGDAU.IDMTD); return(View(vONGDAU)); }
// GET: Admin/VONGDAUs/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VONGDAU vONGDAU = db.VONGDAUs.Find(id); if (vONGDAU == null) { return(HttpNotFound()); } return(View(vONGDAU)); }
// GET: Admin/VONGDAUs/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VONGDAU vONGDAU = db.VONGDAUs.Find(id); if (vONGDAU == null) { return(HttpNotFound()); } ViewBag.IDHT = new SelectList(db.HOITHAOs, "IDHT", "TENHT", vONGDAU.IDHT); ViewBag.IDMTD = new SelectList(db.MONTHIDAUs, "IDMTD", "TENMTD", vONGDAU.IDMTD); return(View(vONGDAU)); }
private void btnXoa_Click(object sender, EventArgs e) { QLGVDBDQGEntities qlbddel = new QLGVDBDQGEntities(); string mavongdau = tBmaVD.Text; VONGDAU VD = qlbddel.VONGDAUs.Where(vd => vd.MaVD == mavongdau).SingleOrDefault(); if (VD != null) { qlbddel.VONGDAUs.Remove(VD); qlbddel.SaveChanges(); MessageBox.Show("Đã xóa", "Thông báo"); xemdulieu(); } else { MessageBox.Show("Có lỗi xảy ra...", "Lỗi"); } }
private void btnSua_Click(object sender, EventArgs e) { QLGVDBDQGEntities qlbdedit = new QLGVDBDQGEntities(); string mavongdau = tBmaVD.Text; VONGDAU VD = qlbdedit.VONGDAUs.Where(vd => vd.MaVD == mavongdau).SingleOrDefault(); if (VD != null) { VD.MaVD = Convert.ToString(tBmaVD.Text); VD.TenVD = Convert.ToString(tBtenVD.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 btnThem_Click(object sender, EventArgs e) { QLGVDBDQGEntities qlbdadd = new QLGVDBDQGEntities(); string mavongdau = ""; VONGDAU VD = qlbdadd.VONGDAUs.Where(vd => vd.MaVD == mavongdau).SingleOrDefault(); if (VD == null) { VONGDAU item = new VONGDAU(); item.MaVD = Convert.ToString(tBmaVD.Text); item.TenVD = Convert.ToString(tBtenVD.Text); qlbdadd.VONGDAUs.Add(item); qlbdadd.SaveChanges(); MessageBox.Show("Đã nhập vào thành công", "Thông báo"); tBmaVD.Text = "VD"; tBtenVD.Text = ""; xemdulieu(); } else { MessageBox.Show("Vui lòng kiểm tra lại...", "Lỗi"); } }
private void capNhatButton_Click(object sender, EventArgs e) { if (ValidateChildren(ValidationConstraints.Enabled)) { try { VONGDAU vongdau = new VONGDAU() { MaVongDau = selectedRoundId, TenVongDau = tenVongTextBox.Text, MaMuaGiai = muaGiaiComboBox.SelectedValue.ToString(), }; Database.VongDau_DAO.updateVongDau(vongdau); MessageBox.Show("Cập nhật thông tin thành công", "Thông báo"); surpressDiscardPrompt = true; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi xảy ra"); } } }
// GET: Admin/VONGDAUs/Delete/5 public ActionResult Delete(int?id) { VONGDAU vONGDAU = db.VONGDAUs.Find(id); return(View(vONGDAU)); }
public static void importLichThiDau(string filename) { Encoding encoding = Encoding.UTF8; string output = File.ReadAllText(filename, encoding); string[] stringSeparators = new string[] { "\n" }; List <string> lines = new List <string>(output.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries)); bool ignoreHeader = true; foreach (string line in lines) { string[] compSeparators = new string[] { "," }; string[] component = line.Trim().Split(compSeparators, StringSplitOptions.RemoveEmptyEntries); if (ignoreHeader) { ignoreHeader = false; continue; } try { VONGDAU vongdau = new VONGDAU() { TenVongDau = component[0], MaMuaGiai = GlobalState.selectedSeasonId }; string maVongDau = Database.VongDau_DAO.queryMaVongDau(vongdau); if (maVongDau.Equals("")) { throw new Exception("Vòng đấu không tồn tại"); } string maDoiNha = Database.DoiBong_DAO.queryMaDoiBong(component[1], GlobalState.selectedSeasonId); if (maDoiNha.Equals("")) { throw new Exception("Đội bóng không tồn tại"); } string maDoiKhach = Database.DoiBong_DAO.queryMaDoiBong(component[2], GlobalState.selectedSeasonId); if (maDoiKhach.Equals("")) { throw new Exception("Đội bóng không tồn tại"); } string maSanThiDau = Database.SanThiDau_DAO.queryMaSanThiDau(component[5], GlobalState.selectedSeasonId); if (maSanThiDau.Equals("")) { throw new Exception("Sân thi đấu không tồn tại"); } TRANDAU trandau = new TRANDAU() { MaMuaGiai = GlobalState.selectedSeasonId, DoiChuNha = maDoiNha, DoiKhach = maDoiKhach, NgayThiDau = DateTime.Parse(component[3]), GioThiDau = DateTime.Parse(component[4]), MaSanThiDau = maSanThiDau, MaVongDau = maVongDau, }; Database.TranDau_DAO.createTranDau(trandau); } catch (Exception ex) { MessageBox.Show("Tại {" + line.Trim() + "} xảy ra lỗi: " + ex.Message, "Lỗi xảy ra"); } } }