public static void selectLoaiBanThang(string MaLoaiBanThang, out LOAIBANTHANG loaibt)
        {
            SqlConnection conn        = DatabaseManager.Instance.getConnection();
            string        queryString = "SELECT MaMuaGiai, TenLoaiBanThang, TinhBanChoCauThu FROM LOAIBANTHANG WHERE MaLoaiBanThang = @MaLoaiBanThang";
            SqlCommand    command     = new SqlCommand(queryString);

            loaibt = new LOAIBANTHANG()
            {
                MaLoaiBanThang = MaLoaiBanThang
            };
            try
            {
                command.Parameters.AddWithValue("@MaLoaiBanThang", MaLoaiBanThang);
                command.Connection = conn;
                SqlDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    loaibt.MaMuaGiai        = reader.GetString(0);
                    loaibt.TenLoaiBanThang  = reader.GetString(1);
                    loaibt.TinhBanChoCauThu = reader.GetBoolean(2);
                }
                reader.Close();
            }
            catch (SqlException SQLex)
            {
                throw SQLex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static void updateLoaiBanThang(LOAIBANTHANG loaibt)
        {
            SqlConnection conn        = DatabaseManager.Instance.getConnection();
            string        queryString = "UPDATE LOAIBANTHANG SET TenLoaiBanThang = @TenLoaiBanThang, TinhBanChoCauThu = @TinhBanChoCauThu WHERE MaLoaiBanThang = @MaLoaiBanThang";
            SqlCommand    command     = new SqlCommand(queryString);

            try
            {
                command.Parameters.AddWithValue("@MaLoaiBanThang", loaibt.MaLoaiBanThang);
                command.Parameters.AddWithValue("@TenLoaiBanThang", loaibt.TenLoaiBanThang);
                command.Parameters.AddWithValue("@TinhBanChoCauThu", loaibt.TinhBanChoCauThu);
                command.Connection = conn;
                int res = command.ExecuteNonQuery();
                if (res == 0)
                {
                    throw new Exception();
                }
            }
            catch (SqlException SQLex)
            {
                throw SQLex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static void createLoaiBanThang(LOAIBANTHANG loaibt)
        {
            SqlConnection conn        = DatabaseManager.Instance.getConnection();
            string        queryString = "INSERT INTO LOAIBANTHANG Values (NEWID(),@MaMuaGiai,@TenLoaiBanThang,@TinhBanChoCauThu)";
            SqlCommand    command     = new SqlCommand(queryString);

            try
            {
                command.Parameters.AddWithValue("@MaMuaGiai", loaibt.MaMuaGiai);
                command.Parameters.AddWithValue("@TenLoaiBanThang", loaibt.TenLoaiBanThang);
                command.Parameters.AddWithValue("@TinhBanChoCauThu", loaibt.TinhBanChoCauThu);
                command.Connection = conn;
                int res = command.ExecuteNonQuery();
                if (res == 0)
                {
                    throw new Exception();
                }
            }
            catch (SqlException SQLex)
            {
                throw SQLex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 //Xóa loai ban thang
 public static void XoaLoaiBanThang(char mabt)
 {
     using (MyDatabaseQLDBDataContext db = new MyDatabaseQLDBDataContext())
     {
         LOAIBANTHANG lbt = (from n in db.LOAIBANTHANGs
                             where n.MABT == mabt
                             select n).FirstOrDefault();
         if (lbt != null)
         {
             db.LOAIBANTHANGs.DeleteOnSubmit(lbt);
             db.SubmitChanges();
         }
     }
 }
Esempio n. 5
0
        private void ThemButton_Click(object sender, EventArgs e)
        {
            //myData(textBox.Text);
            //textBox.Text = "";

            //check for label text to determine where should the form submit its data
            if (themDanhSachGroupBox.Text.Equals("Thêm Loại Bàn Thắng"))
            {
                try
                {
                    LOAIBANTHANG loaibt = new LOAIBANTHANG()
                    {
                        MaMuaGiai        = GlobalState.selectedSeasonId,
                        TenLoaiBanThang  = textBox.Text,
                        TinhBanChoCauThu = checkBox.Checked
                    };
                    Database.LoaiBanThang_DAO.createLoaiBanThang(loaibt);
                    MessageBox.Show("Thêm thành công", "Thông báo");
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Lỗi xảy ra");
                }
            }
            else if (themDanhSachGroupBox.Text.Equals("Thêm Loại Cầu Thủ"))
            {
                try
                {
                    LOAICAUTHU loaict = new LOAICAUTHU()
                    {
                        MaMuaGiai       = GlobalState.selectedSeasonId,
                        TenLoaiCauThu   = textBox.Text,
                        CauThuNuocNgoai = checkBox.Checked
                    };
                    Database.LoaiCauThu_DAO.createLoaiCauThu(loaict);
                    MessageBox.Show("Thêm thành công", "Thông báo");
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Lỗi xảy ra");
                }
            }
        }