public Luat TimTheoMa(int ma) { // Lay danh sach cac menh de ve trai co ma luat can tim String queryVeTrai = "SELECT MaMenhDe FROM tbVeTrai WHERE MaLuat=" + ma; DataTable tbVeTrai = da.Read(queryVeTrai); if (tbVeTrai != null && tbVeTrai.Rows.Count > 0) { List <MenhDe> veTrai = new List <MenhDe>(); foreach (DataRow r in tbVeTrai.Rows) { int maMenhDe = int.Parse(r["MaMenhDe"].ToString()); MenhDe md = new MenhDe(); veTrai.Add(md.TimTheoMa(maMenhDe)); } String queryLuat = "SELECT * FROM tbLuat WHERE Ma=" + ma; DataTable tbLuat = da.Read(queryLuat); if (tbLuat != null && tbLuat.Rows.Count > 0) { Luat r = new Luat(); r.Ma = ma; r.Ten = tbLuat.Rows[0]["Ten"].ToString(); r.MoTa = tbLuat.Rows[0]["MoTa"].ToString(); r.VeTrai = veTrai; MenhDe md = new MenhDe(); int maMenhDeVePhai = int.Parse(tbLuat.Rows[0]["MaMenhDe"].ToString()); r.VePhai = md.TimTheoMa(maMenhDeVePhai); return(r); } } return(null); }
// Phương thức public SuyDienTien(List <MenhDe> tapSKDB, List <MenhDe> tapSKCT) { TapSKDaBiet = tapSKDB; TapSKCanTim = tapSKCT; Luat r = new Luat(); TapLuat = r.DocTatCa(); }
public Boolean SuyDienLai() { float nguong = 0.8f; if (Rank.Count == 0) { return(false); } int index = 0; float max = 0; for (int i = 0; i < Rank.Count; i++) { if (Rank[i] > max) { index = i; max = Rank[i]; } } if (Rank[index] < nguong) { return(false); } // Lay cac menh de chua biet o ve trai cua luat co Rank cao nhat va bo sung // vao tap su kien da biet Luat r = TapLuat[index]; foreach (MenhDe m in r.VeTrai) { if (!TapSKDaBiet.Contains(m)) { TapSKDaBiet.Add(m); } } TapSKDaBiet.Add(r.VePhai); TapLuat.Remove(r); Rank.RemoveAt(index); SuyDien(); return(true); }
public int Sua(int ma, String ten, String moTa, List <MenhDe> veTrai, MenhDe vePhai) { String queryLuat = "UPDATE tbLuat SET Ten=N'" + ten + "', MoTa=N'" + moTa + "', MaMenhDe=" + vePhai.Ma + " WHERE Ma=" + ma; int dem = da.Write(queryLuat); // Cap nhat cho ve trai // Buoc 1: Doc cac ve trai cu cua luat can cap nhat Luat r = new Luat(); r = r.TimTheoMa(ma); if (r != null) { List <MenhDe> veTraiCu = r.VeTrai; // Buoc 2: Doi chieu ve trai cu va ve trai moi de lap cac danh sach List <int> dsCapNhat = new List <int>(); List <int> dsThemMoi = new List <int>(); List <int> dsXoa = new List <int>(); foreach (MenhDe mdc in veTraiCu) { Boolean timThay = false; foreach (MenhDe mdm in veTrai) { if (mdc.Ma == mdm.Ma) { dsCapNhat.Add(mdc.Ma); timThay = true; break; } } if (!timThay) { dsXoa.Add(mdc.Ma); } } foreach (MenhDe mdm in veTrai) { Boolean timThay = false; foreach (MenhDe mdc in veTraiCu) { if (mdm.Ma == mdc.Ma) { timThay = true; break; } } if (!timThay) { dsThemMoi.Add(mdm.Ma); } } // Buoc 3: Thuc thi cac danh sach foreach (int maMenhDe in dsThemMoi) { String query = "INSERT INTO tbVeTrai(MaLuat, MaMenhDe) VALUES(" + ma + ", " + maMenhDe + ")"; da.Write(query); } foreach (int maMenhDe in dsXoa) { String query = "DELETE tbVeTrai WHERE MaMenhDe=" + maMenhDe; da.Write(query); } } return(dem); }