Beispiel #1
0
        public static void selectChiTietThayNguoi(string MaThayNguoi, out CHITIETTHAYNGUOI thaynguoi)
        {
            SqlConnection conn        = DatabaseManager.Instance.getConnection();
            string        queryString = "SELECT MaCauThuVaoSan, MaCauThuRaSan, ThoiDiem FROM CHITIETTHAYNGUOI WHERE MaThayNguoi = @MaThayNguoi";
            SqlCommand    command     = new SqlCommand(queryString);

            thaynguoi = new CHITIETTHAYNGUOI()
            {
                MaThayNguoi = MaThayNguoi
            };
            try
            {
                command.Parameters.AddWithValue("@MaThayNguoi", MaThayNguoi);
                command.Connection = conn;
                SqlDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    thaynguoi.MaCauThuVaoSan = reader.GetString(0);
                    thaynguoi.MaCauThuRaSan  = reader.GetString(1);
                    thaynguoi.ThoiDiem       = reader.GetTimeSpan(2);
                }
                reader.Close();
            }
            catch (SqlException SQLex)
            {
                throw SQLex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        public static void updateChiTietThayNguoi(CHITIETTHAYNGUOI thaynguoi)
        {
            string        ThoiDiem    = thaynguoi.ThoiDiem.ToString("c");
            SqlConnection conn        = DatabaseManager.Instance.getConnection();
            string        queryString = "UPDATE CHITIETTHAYNGUOI SET MaCauThuVaoSan = @MaCauThuVaoSan, MaCauThuRaSan = @MaCauThuRaSan, ThoiDiem = @ThoiDiem, MaTranDau = @MaTranDau WHERE MaThayNguoi = @MaThayNguoi";
            SqlCommand    command     = new SqlCommand(queryString);

            try
            {
                command.Parameters.AddWithValue("@MaThayNguoi", thaynguoi.MaThayNguoi);
                command.Parameters.AddWithValue("@MaCauThuVaoSan", thaynguoi.MaCauThuVaoSan);
                command.Parameters.AddWithValue("@MaCauThuRaSan", thaynguoi.MaCauThuRaSan);
                command.Parameters.AddWithValue("@ThoiDiem", ThoiDiem);
                command.Parameters.AddWithValue("@MaTranDau", thaynguoi.MaTranDau);
                command.Connection = conn;
                int res = command.ExecuteNonQuery();
                if (res == 0)
                {
                    throw new Exception();
                }
            }
            catch (SqlException SQLex)
            {
                throw SQLex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void themThayNguoi_Click(object sender, EventArgs e)
        {
            int      minutes = Int16.Parse(phutThayNguoi.Value.ToString());
            int      second  = Int16.Parse(giayThayNguoi.Value.ToString());
            TimeSpan time    = new TimeSpan(0, minutes, second);

            string timeString = time.ToString();

            bool checkComboBox  = (doiThayNguoiComboBox.Text == "");
            bool checkTimeEvent = checkTime(timeString, dataGridView6, 5);

            if (checkComboBox && checkTimeEvent)
            {
                MessageBox.Show("Hãy chọn đội bóng!");
            }
            else
            if ((!checkTimeEvent && checkComboBox) || (!checkComboBox && !checkTimeEvent))
            {
                MessageBox.Show("Thời điểm đã trùng");
            }
            else
            {
                try
                {
                    //Console.WriteLine(cauThuVaoSanComboBox.SelectedValue.ToString());
                    //Console.WriteLine(cauThuRaSanComboBox.SelectedValue.ToString());
                    CHITIETTHAYNGUOI thaynguoi = new CHITIETTHAYNGUOI()
                    {
                        MaCauThuVaoSan = cauThuVaoSanComboBox.SelectedValue.ToString(),
                        MaCauThuRaSan  = cauThuRaSanComboBox.SelectedValue.ToString(),
                        ThoiDiem       = new TimeSpan(0, Int16.Parse(phutThayNguoi.Value.ToString()), Int16.Parse(giayThayNguoi.Value.ToString())),
                        MaTranDau      = GlobalState.selectedMatchId
                    };

                    Database.ChiTietThayNguoi_DAO.createChiTietThayNguoi(thaynguoi);
                    this.thayNguoiExtTableAdapter.Fill(this.quanLyGiaiVoDichDataSet.ThayNguoiExt);
                    MessageBox.Show("Thêm thành công", "Thông báo");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Lỗi xảy ra");
                }
            }
        }
        private void suaThayNguoi_Click(object sender, EventArgs e)
        {
            if (suaThayNguoi.Text.Equals("Sửa"))
            {
                if (dataGridView6.SelectedCells.Count == 0 || dataGridView6.SelectedCells[0].RowIndex < 0)
                {
                    MessageBox.Show("Xin hãy chọn thông tin 1 thay người trong bảng để chỉnh sửa", "Thông báo");
                    return;
                }
                else
                {
                    //load change info into the fields
                    CHITIETTHAYNGUOI thaynguoi;
                    selectedChangeId = dataGridView6.SelectedCells[0].OwningRow.Cells[0].Value.ToString();
                    try
                    {
                        Database.ChiTietThayNguoi_DAO.selectChiTietThayNguoi(selectedChangeId, out thaynguoi);
                        cauThuVaoSanComboBox.SelectedValue = thaynguoi.MaCauThuVaoSan;
                        cauThuRaSanComboBox.SelectedValue  = thaynguoi.MaCauThuRaSan;
                        phutThayNguoi.Value = thaynguoi.ThoiDiem.Hours * 60 + thaynguoi.ThoiDiem.Minutes;
                        giayThayNguoi.Value = thaynguoi.ThoiDiem.Seconds;

                        xoaThayNguoi.Text = "Hủy";
                        suaThayNguoi.Text = "Lưu";

                        themThayNguoi.Enabled = false;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Lỗi xảy ra");
                    }
                }
            }
            else if (suaThayNguoi.Text.Equals("Lưu"))
            {
                //check for database inconsitency (if server wont handle)

                //update change info
                try
                {
                    CHITIETTHAYNGUOI thaynguoi = new CHITIETTHAYNGUOI()
                    {
                        MaThayNguoi    = selectedChangeId,
                        MaCauThuVaoSan = cauThuVaoSanComboBox.SelectedValue.ToString(),
                        MaCauThuRaSan  = cauThuRaSanComboBox.SelectedValue.ToString(),
                        ThoiDiem       = new TimeSpan(0, Int16.Parse(phutThayNguoi.Value.ToString()), Int16.Parse(giayThayNguoi.Value.ToString())),
                        MaTranDau      = GlobalState.selectedMatchId
                    };
                    Database.ChiTietThayNguoi_DAO.updateChiTietThayNguoi(thaynguoi);
                    MessageBox.Show("Cập nhật thành công", "Thông báo");
                    thayNguoiExtTableAdapter.Fill(quanLyGiaiVoDichDataSet.ThayNguoiExt);
                    selectedChangeId  = "";
                    xoaThayNguoi.Text = "Xóa";
                    suaThayNguoi.Text = "Sửa";

                    themThayNguoi.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Lỗi xảy ra");
                }
            }
        }