private void btnTimKiem_Click(object sender, EventArgs e) { DAO.OpenConnection(); if ((txtTenCT.Text == "") && (cmbMaDoi.Text == "") && (txtSobanthang.Text == "")) { MessageBox.Show("Hãy nhập điều kiện tìm kiếm!!!"); return; } string sql = "select * from cauthu where 1=1"; if (txtTenCT.Text != "") { sql = sql + " and tencauthu = N'" + txtTenCT.Text + "'"; } if (cmbMaDoi.Text != "") { sql = sql + " and madoi = '" + cmbMaDoi.SelectedValue + "'"; } if (txtSobanthang.Text != "") { sql = sql + " and sobanthang = " + txtSobanthang.Text; } SqlDataAdapter adapter = new SqlDataAdapter(sql, DAO.conn); DataTable table = new DataTable(); adapter.Fill(table); if (table.Rows.Count == 0) { MessageBox.Show("Không có bản ghi thỏa mãn điều kiện!!!"); } else { MessageBox.Show("Có " + table.Rows.Count + " bản ghi thỏa mãn điều kiện!!!"); } GridViewCauThu.DataSource = table; SqlCommand cmd = new SqlCommand(sql, DAO.conn) { CommandText = sql, Connection = DAO.conn }; cmd.ExecuteNonQuery(); DAO.CloseConnetion(); }
private void LoadDataToGrivew() { try { DAO.OpenConnection(); string sql = "select * from capnhatĐB"; SqlDataAdapter myAdapter = new SqlDataAdapter(sql, DAO.conn); DataTable capnhatĐB = new DataTable(); myAdapter.Fill(capnhatĐB); GridViewCapNhatĐB.DataSource = capnhatĐB; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { DAO.CloseConnetion(); } }
private void LoadDataToGrivew() { try { DAO.OpenConnection(); string sql = "select * from trandau"; SqlDataAdapter myAdapter = new SqlDataAdapter(sql, DAO.conn); DataTable trandau = new DataTable(); myAdapter.Fill(trandau); GridViewTranDau.DataSource = trandau; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { DAO.CloseConnetion(); } }
private void LoadDataToGridView() { //mở kết nối try { DAO.OpenConnection(); string sql = "select * from trandau_cauthu"; SqlDataAdapter adapt = new SqlDataAdapter(sql, DAO.conn); DataTable trandau_cauthu = new DataTable(); adapt.Fill(trandau_cauthu); GridViewTrandau_Cauthu.DataSource = trandau_cauthu; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { DAO.CloseConnetion(); } }
private void FrmTranDau_Load(object sender, EventArgs e) { DAO.OpenConnection(); LoadDataToGrivew(); DAO.FillDataToCombo("select madoikhach from trandau", cmbMaDoiKhach, "madoikhach", "madoikhach"); cmbMaDoiKhach.SelectedIndex = -1; DAO.FillDataToCombo("select madoinha from trandau", cmbMaDoiNha, "madoinha", "madoinha"); cmbMaDoiNha.SelectedIndex = -1; txtBanThangDN.Text = "0"; txtbanthuaĐN.Text = "0"; txtTheDoDN.Text = "0"; txtthevangĐN.Text = "0"; txtthedoĐK.Text = "0"; txtthevangĐK.Text = "0"; txtbanthuaĐN.ReadOnly = true; txtthevangĐN.ReadOnly = true; txtthedoĐK.ReadOnly = true; txtthevangĐK.ReadOnly = true; DAO.CloseConnetion(); }
private void FrmBaoCaoTranDau_Load(object sender, EventArgs e) { DAO.OpenConnection(); //GridViewBCtrandau.DataSource = null; DAO.CloseConnetion(); }
private void FrmCapNhatTĐ_Load(object sender, EventArgs e) { DAO.OpenConnection(); LoadDataToGrivew(); DAO.CloseConnetion(); }
private void FrmLogin_Load(object sender, EventArgs e) { DAO.OpenConnection(); }
private void FrmTrandau_Banthang_Load(object sender, EventArgs e) { DAO.OpenConnection(); LoadDataToGrivew(); DAO.CloseConnetion(); }
private void FrmBC_CTnhieuBT_Load(object sender, EventArgs e) { DAO.OpenConnection(); GridViewBC_CTnhieuBT.DataSource = null; DAO.CloseConnetion(); }
private void btnLuu_Click(object sender, EventArgs e) { DAO.OpenConnection(); string sql; if (cmbMaDoi.Text.Length == 0) { MessageBox.Show("Ban chua nhap ma doi"); cmbMaDoi.Focus(); return; } if (txtMaSan.Text == "") { MessageBox.Show("Ban chua nhap ma san"); txtMaSan.Focus(); return; } if (txtTenDoi.Text == "") { MessageBox.Show("Ban chua nhap ten doi"); txtTenDoi.Focus(); return; } if (txtHLV.Text == "") { MessageBox.Show("Ban chua nhap ten HLV"); txtHLV.Focus(); return; } if (txtMaTinh.Text == "") { MessageBox.Show("Ban chua nhap ma tinh"); txtMaTinh.Focus(); return; } /*if (txtLogo.Text.Trim().Length == 0) * { * MessageBox.Show("Ban chua nhap Logo"); * txtLogo.Focus(); * return; * }*/ /*if (txtLogo.Text == "") * { * MessageBox.Show("Bạn cần nhập logo!"); * txtLogo.Focus(); * return; * }*/ sql = "Select madoi from doibong where madoi = '" + cmbMaDoi.Text + " ' "; if (DAO.checkKeyExit(sql)) { MessageBox.Show("Ma doi da ton tai"); cmbMaDoi.Focus(); cmbMaDoi.Text = ""; return; } else { sql = "insert into doibong (madoi,tendoi,masan,HLV,matinh,diem,sobanthang,sobanthua,soluongcauthu) " + "values (' " + cmbMaDoi.Text + "', N'" + txtTenDoi.Text.Trim() + "', N'" + txtMaSan.Text.Trim() + "' , N'" + txtHLV.Text.Trim() + "', N'" + txtMaTinh.Text.Trim() + "',null,null,null,null)"; /*txtLogo.Text + "', N'" + ")"*/ MessageBox.Show(sql); DAO.LoadDataToTable(sql); DAO.CloseConnetion(); LoadDataToGriview(); } }
private void btnLuu_Click(object sender, EventArgs e) { DAO.OpenConnection(); string sql; if (txtMaCT.Text == "") { MessageBox.Show("bạn chưa nhập mã cầu thủ"); txtMaCT.Focus(); return; } if (cmbMaDoi.Text == "") { MessageBox.Show("bạn chưa chọn mã đội"); cmbMaDoi.Focus(); return; } if (txtTenCT.Text == "") { MessageBox.Show("bạn chưa nhập tên cầu thủ"); txtTenCT.Focus(); return; } if (txtViTri.Text == "") { MessageBox.Show("bạn chưa nhập vị trí của cầu thủ"); txtViTri.Focus(); return; } if (txtNgaySinh.Text == "") { MessageBox.Show("bạn chưa nhập ngày sinh"); txtNgaySinh.Focus(); return; } if (txtSoAo.Text == "") { MessageBox.Show("bạn chưa nhập số áo"); txtSoAo.Focus(); return; } if (txtMaQuocTich.Text == "") { MessageBox.Show("bạn chưa nhập mã quốc tịch"); txtMaQuocTich.Focus(); return; } /*if (txtAnh.Text == "") * { * MessageBox.Show("bạn chưa chọn ảnh minh họa"); * txtAnh.Focus(); * return; * }*/ sql = "select * from cauthu where macauthu = '" + txtMaCT.Text.Trim() + "'"; if (DAO.checkKeyExit(sql)) { MessageBox.Show("mã cầu thủ đã tồn tại"); txtMaCT.Focus(); return; } else { sql = " insert into cauthu (macauthu,madoi,tencauthu,vitri,ngaysinh,soao,sobanthang,sothevang,sothedo,maquoctich,solanrasan) " + " values('" + txtMaCT.Text.Trim() + "',N'" + cmbMaDoi.SelectedValue + "',N'" + txtTenCT.Text.Trim() + "',N'" + txtViTri.Text.Trim() + "',N'" + txtNgaySinh.Text.Trim() + "',N'" + txtSoAo.Text.Trim() + "',null,null,null,'" + txtMaQuocTich.Text.Trim() + "',null)"; MessageBox.Show(sql); DAO.LoadDataToTable(sql); DAO.CloseConnetion(); LoadDataToGrivew(); } }