Esempio n. 1
0
        private void btnXacNhan_Click(object sender, EventArgs e)
        {
            QLGVDBDQGEntities qlbdadd   = new QLGVDBDQGEntities();
            QLGVDBDQGEntities qlbdadd1  = new QLGVDBDQGEntities();
            string            madoibong = "";
            DOIBONG           DB        = qlbdadd.DOIBONGs.Where(db => db.MaDB == madoibong).SingleOrDefault();

            if (DB == null)
            {
                DOIBONG     item  = new DOIBONG();
                BANGXEPHANG item1 = new BANGXEPHANG();
                item.MaDB    = Convert.ToString(tBmaDB.Text);
                item.TenDB   = Convert.ToString(tBtenDB.Text);
                item.SanNha  = Convert.ToString(tBsanNha.Text);
                item1.MaDB   = item.MaDB;
                item1.Thang  = 0;
                item1.Hoa    = 0;
                item1.Thua   = 0;
                item1.HieuSo = 0;
                item1.Diem   = 0;
                qlbdadd.DOIBONGs.Add(item);
                qlbdadd1.BANGXEPHANGs.Add(item1);
                qlbdadd.SaveChanges();
                qlbdadd1.SaveChanges();
                MessageBox.Show("Đã nhập vào thành công", "Thông báo");
                tBmaDB.Text   = "DB";
                tBtenDB.Text  = "";
                tBsanNha.Text = "";
                ql.xemdulieu();
            }
            else
            {
                MessageBox.Show("Vui lòng kiểm tra lại....", "Lỗi");
            }
        }
        public static void updateXepHang(BANGXEPHANG xh)
        {
            SqlConnection conn        = DatabaseManager.Instance.getConnection();
            string        queryString = "UPDATE BANGXEPHANG SET XepHang = @XepHang WHERE MaDoi = @MaDoi AND Ngay = @Ngay";
            SqlCommand    command     = new SqlCommand(queryString);

            int[] tbRes = { 0, 0 };
            try
            {
                //command.Parameters.AddWithValue("@MaMuaThucHien", MaMuaGiai);
                command.Parameters.AddWithValue("@MaDoi", xh.MaDoi);
                command.Parameters.AddWithValue("@Ngay", xh.Ngay.ToString("yyyy-MM-dd"));
                command.Parameters.AddWithValue("@XepHang", xh.XepHang);
                command.Connection = conn;
                int res = command.ExecuteNonQuery();
                if (res == 0)
                {
                    throw new Exception();
                }
            }
            catch (SqlException SQLex)
            {
                throw SQLex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
        private void btnXacNhan_Click(object sender, EventArgs e)
        {
            string       maketqua = "";
            KETQUATHIDAU KQ       = qlbd.KETQUATHIDAUs.Where(kq => kq.MaKQ == maketqua).SingleOrDefault();

            if (KQ == null)
            {
                KETQUATHIDAU item = new KETQUATHIDAU();
                item.MaKQ   = tBmaKetQua.Text;
                item.BTDoi1 = Convert.ToInt32(tBtiSoDoi1.Text);
                item.BTDoi2 = Convert.ToInt32(tBtiSoDoi2.Text);
                item.MaTD   = ((LICHTHIDAU)cBmaTD.SelectedValue).MaTD;
                qlbd.KETQUATHIDAUs.Add(item);
                qlbd.SaveChanges();
                MessageBox.Show("Đã nhập vào thành công", "Thông báo");
                tBmaKetQua.Text = "KQ";
                tBtiSoDoi1.Text = "";
                tBtiSoDoi2.Text = "";
                kqtd.xemdulieu();
                BangXepHang xh = new BangXepHang();

                BANGXEPHANG BXH = qlbd1.BANGXEPHANGs.Where(bxh => bxh.DOIBONG.TenDB == tBdoi1.Text).Single();
                {
                    if (BXH != null)
                    {
                        if (item.BTDoi1 > item.BTDoi2)
                        {
                            BXH.Thang  += 1;
                            BXH.Thua   += 0;
                            BXH.Hoa    += 0;
                            BXH.HieuSo += item.BTDoi1 - item.BTDoi2;
                            BXH.Diem   += 3;
                            qlbd1.SaveChanges();
                            xh.xemdulieu();
                        }
                        else if (item.BTDoi1 < item.BTDoi2)
                        {
                            BXH.Thang  += 0;
                            BXH.Thua   += 1;
                            BXH.Hoa    += 0;
                            BXH.HieuSo += item.BTDoi1 - item.BTDoi2;
                            BXH.Diem   += 0;
                            qlbd1.SaveChanges();
                            xh.xemdulieu();
                        }
                        else if (item.BTDoi1 == item.BTDoi2)
                        {
                            BXH.Thang  += 0;
                            BXH.Thua   += 0;
                            BXH.Hoa    += 1;
                            BXH.HieuSo += item.BTDoi1 - item.BTDoi2;
                            BXH.Diem   += 1;
                            qlbd1.SaveChanges();
                            xh.xemdulieu();
                        }
                    }
                }
                BANGXEPHANG BXH1 = qlbd2.BANGXEPHANGs.Where(bxh => bxh.DOIBONG.TenDB == tBdoi2.Text).Single();
                {
                    if (BXH1 != null)
                    {
                        if (item.BTDoi1 < item.BTDoi2)
                        {
                            BXH1.Thang  += 1;
                            BXH1.Thua   += 0;
                            BXH1.Hoa    += 0;
                            BXH1.HieuSo += item.BTDoi2 - item.BTDoi1;
                            BXH1.Diem   += 3;
                            qlbd2.SaveChanges();
                            xh.xemdulieu();
                        }
                        else if (item.BTDoi1 > item.BTDoi2)
                        {
                            BXH1.Thang  += 0;
                            BXH1.Thua   += 1;
                            BXH1.Hoa    += 0;
                            BXH1.HieuSo += item.BTDoi2 - item.BTDoi1;
                            BXH1.Diem   += 0;
                            qlbd2.SaveChanges();
                            xh.xemdulieu();
                        }
                        else if (item.BTDoi1 == item.BTDoi1)
                        {
                            BXH1.Thang  += 0;
                            BXH1.Thua   += 0;
                            BXH1.Hoa    += 1;
                            BXH1.HieuSo += item.BTDoi1 - item.BTDoi2;
                            BXH1.Diem   += 1;
                            qlbd2.SaveChanges();
                            xh.xemdulieu();
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Có lỗi xảy ra...", "Lỗi");
            }
        }
Esempio n. 4
0
        private void BangXepHang_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'quanLyGiaiVoDichDataSet.MuaGiaiAllowNull' table. You can move, or remove it, as needed.
            this.muaGiaiAllowNullTableAdapter.Fill(this.quanLyGiaiVoDichDataSet.MuaGiaiAllowNull);
            // TODO: This line of code loads data into the 'quanLyGiaiVoDichDataSet.BangXepHangExt' table. You can move, or remove it, as needed.
            this.bangXepHangExtTableAdapter.Fill(this.quanLyGiaiVoDichDataSet.BangXepHangExt);

            muaGiaiComboBox.SelectedValue = GlobalState.selectedSeasonId;
            DialogResult res = MessageBox.Show("Bạn có muốn thực hiện lưu kết quả hiện tại thành bảng xếp hạng của ngày hôm nay?", "Lưu kết quả", MessageBoxButtons.YesNo);

            if (res == DialogResult.Yes)
            {
                try
                {
                    Database.BangXepHang_DAO.updateBXH(GlobalState.selectedSeasonId);
                    this.bangXepHangExtTableAdapter.Fill(this.quanLyGiaiVoDichDataSet.BangXepHangExt);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Lỗi xảy ra");
                }
            }
            DateTime filterDate = thoiGianPicker.Value;

            this.bangXepHangExtBindingSource.Filter = "MaMuaGiai = '" + GlobalState.selectedSeasonId + "' AND Ngay = #" + filterDate.ToString("yyyy-MM-dd") + "#";
            this.bangXepHangExtBindingSource.Sort   = "XepHang asc";

            List <string> MaDoiDongHang = new List <string>();
            int           origin_place  = 0;

            //Check for team with same rank number and try to apply tiebreaker
            for (int i = 0; i < bangXepHangData.Rows.Count; i++)
            {
                if (MaDoiDongHang.Count == 0)
                {
                    MaDoiDongHang.Add(bangXepHangData.Rows[i].Cells[8].Value.ToString());
                    origin_place = Int16.Parse(bangXepHangData.Rows[i].Cells[0].Value.ToString());
                }
                if (i == 0)
                {
                    continue;
                }
                //prevent out of range indexing
                if (bangXepHangData.Rows[i].Cells[0].Value.ToString().Equals(bangXepHangData.Rows[i - 1].Cells[0].Value.ToString()))
                {
                    MaDoiDongHang.Add(bangXepHangData.Rows[i].Cells[8].Value.ToString());
                }
                else
                {
                    if (MaDoiDongHang.Count >= 2)
                    {
                        //if there are more than 2 team with the same ranking, try to resolve using tiebreaker rule, outputting their respective leaderboard priority
                        List <helper.MutablePair <String, int> > tbRes = Database.BangXepHang_DAO.tieBreaker(MaDoiDongHang);
                        //iterate through the list, if one's priority value is different from the one above it, update its rank according to the first previously same-rank entry's current rank
                        int current_pr    = -1;
                        int current_place = origin_place;
                        for (int j = 0; j < tbRes.Count; j++)
                        {
                            if (current_pr != tbRes[j].Second)
                            {
                                current_pr    = tbRes[j].Second;
                                current_place = origin_place + j;
                            }
                            BANGXEPHANG xh = new BANGXEPHANG()
                            {
                                MaDoi   = tbRes[j].First,
                                Ngay    = thoiGianPicker.Value,
                                XepHang = current_place
                            };
                            Database.BangXepHang_DAO.updateXepHang(xh);
                        }
                    }
                    MaDoiDongHang.Clear();
                }
                //if we reached the end of the leaderboard, resolve whatever left in the same-rank list
                if (i == bangXepHangData.Rows.Count)
                {
                    if (MaDoiDongHang.Count >= 2)
                    {
                        //if there are more than 2 team with the same ranking, try to resolve using tiebreaker rule, outputting their respective leaderboard priority
                        List <helper.MutablePair <String, int> > tbRes = Database.BangXepHang_DAO.tieBreaker(MaDoiDongHang);
                        //iterate through the list, if one's priority value is different from the one above it, update its rank according to the first previously same-rank entry's current rank
                        int current_pr    = -1;
                        int current_place = origin_place;
                        for (int j = 0; j < tbRes.Count; j++)
                        {
                            if (current_pr != tbRes[j].Second)
                            {
                                current_pr    = tbRes[j].Second;
                                current_place = origin_place + j;
                            }
                            BANGXEPHANG xh = new BANGXEPHANG()
                            {
                                MaDoi   = tbRes[j].First,
                                Ngay    = thoiGianPicker.Value,
                                XepHang = current_place
                            };
                            Database.BangXepHang_DAO.updateXepHang(xh);
                        }
                    }
                    MaDoiDongHang.Clear();
                }
            }
            this.bangXepHangExtTableAdapter.Fill(this.quanLyGiaiVoDichDataSet.BangXepHangExt);
            foreach (DataGridViewColumn column in bangXepHangData.Columns)
            {
                column.SortMode = DataGridViewColumnSortMode.NotSortable;
            }
        }