Exemple #1
0
 private void button2_Click(object sender, EventArgs e)
 {
     // Kiểm tra validate
     if (ValidateChildren(ValidationConstraints.Enabled))
     {
         try
         {
             SANTHIDAU santhidau = new SANTHIDAU()
             {
                 TenSanThiDau = tenSanThiDauTextBox.Text,
                 MaMuaGiai    = (string)muaGiaiComboBox.SelectedValue,
                 DonViSoHuu   = tenDonViSoHuuTextBox.Text,
             };
             Database.SanThiDau_DAO.createSanThiDau(santhidau);
             xoaSanThiDau.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.sanThiDauExtTableAdapter.Fill(this.quanLyGiaiVoDichDataSet.SanThiDauExt);
         this.danhSachSanThiDauData.Update();
     }
 }
Exemple #2
0
        public static void updateSanThiDau(SANTHIDAU santhidau)
        {
            SqlConnection conn        = DatabaseManager.Instance.getConnection();
            string        queryString = "";

            queryString = "UPDATE SanThiDau SET TenSanThiDau = @TenSanThiDau, DonViSoHuu = @DonViQuanLi, MaDoiNha = @MaDoiNha WHERE MaSanThiDau = @MaSanThiDau";
            SqlCommand command = new SqlCommand(queryString);

            try
            {
                command.Parameters.AddWithValue("@TenSanThiDau", santhidau.TenSanThiDau);
                command.Parameters.AddWithValue("@MaSanThiDau", santhidau.MaSanThiDau);
                command.Parameters.AddWithValue("@DonViQuanLi", santhidau.DonViSoHuu);
                command.Parameters.AddWithValue("@MaDoiNha", santhidau.MaDoiNha);
                command.Connection = conn;
                int res = command.ExecuteNonQuery();
                if (res == 0)
                {
                    //res indicate number of row affected, if number is 0, no row is added and we know something gone wrong, throw exception
                    throw new Exception();
                }
            }
            catch (SqlException SQLex)
            {
                throw SQLex;
            }
            catch (Exception ex)
            {
                throw ex;
                //TODO: throw exception to higher level
            }
        }
        public static void importSanThiDau(string filename)
        {
            Encoding encoding = Encoding.UTF8;
            string   output   = File.ReadAllText(filename, encoding);

            string[]      lineSeparators = new string[] { "\n" };
            List <string> lines          = new List <string>(output.Split(lineSeparators, StringSplitOptions.RemoveEmptyEntries));

            bool ignoreHeader = true;

            foreach (string line in lines)
            {
                if (ignoreHeader)
                {
                    ignoreHeader = false;
                    continue;
                }
                string[] compSeparators = new string[] { "," };
                string[] component      = line.Split(compSeparators, StringSplitOptions.RemoveEmptyEntries);
                try
                {
                    SANTHIDAU santhidau = new SANTHIDAU()
                    {
                        TenSanThiDau = component[0],
                        MaMuaGiai    = GlobalState.selectedSeasonId,
                        DonViSoHuu   = component[1]
                    };
                    Database.SanThiDau_DAO.createSanThiDau(santhidau);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Tại {" + line.Trim() + "} xảy ra lỗi: " + ex.Message, "Lỗi xảy ra");
                }
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            SANTHIDAU sANTHIDAU = db.SANTHIDAUs.Find(id);

            db.SANTHIDAUs.Remove(sANTHIDAU);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "IDSTD,TENSTD,MOTA")] SANTHIDAU sANTHIDAU)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sANTHIDAU).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(sANTHIDAU));
 }
        public ActionResult Create([Bind(Include = "IDSTD,TENSTD,MOTA")] SANTHIDAU sANTHIDAU)
        {
            if (ModelState.IsValid)
            {
                db.SANTHIDAUs.Add(sANTHIDAU);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(sANTHIDAU));
        }
        // GET: Admin/SANTHIDAUs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SANTHIDAU sANTHIDAU = db.SANTHIDAUs.Find(id);

            if (sANTHIDAU == null)
            {
                return(HttpNotFound());
            }
            return(View(sANTHIDAU));
        }
 private void capNhatButton_Click(object sender, EventArgs e)
 {
     try
     {
         SANTHIDAU santhidau = new SANTHIDAU()
         {
             TenSanThiDau = tenSanThiDauTextBox.Text,
             DonViSoHuu   = tenDonViSoHuuTextBox.Text,
             MaSanThiDau  = selectedStadiumId,
         };
         Database.SanThiDau_DAO.updateSanThiDau2(santhidau);
         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");
     }
 }
Exemple #9
0
        //param:
        public static void createSanThiDau(SANTHIDAU santhidau)
        {
            santhidau.MaDoiNha = "";
            SqlConnection conn        = DatabaseManager.Instance.getConnection();
            string        queryString = "INSERT INTO SanThiDau(MaSanThiDau, TenSanThiDau, MaMuaGiai, DonViSoHuu) VALUES(NEWID(), @TenSanThiDau, @MaGiaiDau, @DonViQuanLi)";

            if (santhidau.MaDoiNha != "")
            {
                queryString = "INSERT INTO SanThiDau(MaSanThiDau, TenSanThiDau, MaMuaGiai, DonViSoHuu, MaDoiNha) VALUES(NEWID(), @TenSanThiDau, @MaGiaiDau, @DonViQuanLi, @MaDoiNha)";
            }
            SqlCommand command = new SqlCommand(queryString);

            try
            {
                command.Parameters.AddWithValue("@TenSanThiDau", santhidau.TenSanThiDau);
                command.Parameters.AddWithValue("@MaGiaiDau", santhidau.MaMuaGiai);
                command.Parameters.AddWithValue("@DonViQuanLi", santhidau.DonViSoHuu);
                if (santhidau.MaDoiNha != "")
                {
                    command.Parameters.AddWithValue("@MaDoiNha", santhidau.MaDoiNha);
                }
                command.Connection = conn;
                int res = command.ExecuteNonQuery();
                if (res == 0)
                {
                    //res indicate number of row affected, if number is 0, no row is added and we know something gone wrong, throw exception
                    throw new Exception();
                }
            }
            catch (SqlException SQLex)
            {
                throw SQLex;
            }
            catch (Exception ex)
            {
                throw ex;
                //TODO: throw exception to higher level
            }
        }
Exemple #10
0
        public static void selectSanThiDau(string MaSanThiDau, out SANTHIDAU santhidau)
        {
            SqlConnection conn = DatabaseManager.Instance.getConnection();

            santhidau = new SANTHIDAU()
            {
                TenSanThiDau = "",
                DonViSoHuu   = "",
                MaDoiNha     = "",
            };
            string     queryString = "SELECT TenSanThiDau, DonViSoHuu, MaDoiNha FROM SANTHIDAU WHERE MaSanThiDau = @MaSanThiDau";
            SqlCommand command     = new SqlCommand(queryString);

            try
            {
                command.Parameters.AddWithValue("@MaSanThiDau", MaSanThiDau);
                command.Connection = conn;
                SqlDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    santhidau.TenSanThiDau = reader.GetString(0);
                    santhidau.DonViSoHuu   = reader.GetString(1);
                    if (!reader.IsDBNull(2))
                    {
                        santhidau.MaDoiNha = reader.GetString(2);
                    }
                }
                reader.Close();
            }
            catch (SqlException SQLex)
            {
                throw SQLex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #11
0
        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");
                }
            }
        }