public void Dequyvecay(DataTable tb, GainRatio gr, int ID_Parent, Attribute[] attributes, int count) { for (int i = 0; i < gr.at.values.Length; i++) { tb.DefaultView.RowFilter = "tinhhieuqua='Có' and " + gr.at.AttributeName + "='" + gr.at.values[i] + "'"; DataTable tb_C = tb.DefaultView.ToTable().Copy(); double C = tb_C.Rows.Count; tb.DefaultView.RowFilter = "tinhhieuqua='Không' and " + gr.at.AttributeName + "='" + gr.at.values[i] + "'"; DataTable tb_K = tb.DefaultView.ToTable().Copy(); double KK = tb_K.Rows.Count; if (C > 0 && KK <= 0) { // foreach (DataRow rowc in tb_C.Rows){ DataRow row = GetRow(this.tbTree.Rows.Count + 1, ID_Parent, gr.at.values[i], "Có", gr, tb_C.Rows[0]["MaSP"].ToString()); this.tbTree.Rows.Add(row); // } } else if (KK > 0 && C <= 0) { //foreach (DataRow rowk in tb_K.Rows) //{ DataRow row = GetRow(this.tbTree.Rows.Count + 1, ID_Parent, gr.at.values[i], "Không", gr, tb_K.Rows[0]["MaSP"].ToString()); this.tbTree.Rows.Add(row); // } } if (C > 0 && KK > 0) { tb.DefaultView.RowFilter = gr.at.AttributeName + "='" + gr.at.values[i] + "'"; DataTable tb1 = tb.DefaultView.ToTable().Copy(); Attribute[] attributes1 = this.delete(attributes, gr.at.AttributeName); if (attributes1.Length > 0) { List <GainRatio> arr_GainRatio1 = GetGainRatio(attributes1, tb1); int count_child = this.tbTree.Rows.Count + 1; count = this.tbTree.Rows.Count + 1; DataRow row = GetRow(this.tbTree.Rows.Count + 1, ID_Parent, gr.at.values[i], DBNull.Value, gr, tb1.Rows[0]["MaSP"].ToString()); this.tbTree.Rows.Add(row); Dequyvecay(tb1, arr_GainRatio1[0], count_child, attributes1, count); } } } }
public List <GainRatio> GetGainRatio(Attribute[] attributes, DataTable tb) { List <GainRatio> arr_GainRatio = new List <GainRatio>(); for (int i = 0; i < attributes.Length; i++) { GainRatio GR = new GainRatio(this.GainRation(attributes[i], tb), attributes[i]); arr_GainRatio.Add(GR); } for (int i = 0; i < arr_GainRatio.Count - 1; i++) { for (int j = i + 1; j < arr_GainRatio.Count; j++) { if ((arr_GainRatio[j]).value > (arr_GainRatio[i]).value) { GainRatio temp = arr_GainRatio[i]; arr_GainRatio[i] = arr_GainRatio[j]; arr_GainRatio[j] = temp; } } } return(arr_GainRatio); }
private DataRow GetRow(int count, object Parent_ID, object value, object tinhhieuqua, GainRatio gar, String MaSP) { DataRow row = this.tbTree.NewRow(); row["ID"] = count; switch (gar.at.AttributeName) { case "SoThich": row["SoThich"] = value;//gar.at.mlable; row["GioiTinh"] = DBNull.Value; row["Tuoi"] = DBNull.Value; row["Thunhap"] = DBNull.Value; row["TinhHieuQua"] = tinhhieuqua; row["Parent_ID"] = Parent_ID; row["MaSP"] = MaSP; break; case "GioiTinh": row["SoThich"] = DBNull.Value; row["GioiTinh"] = value; //gar.at.mlable; row["Tuoi"] = DBNull.Value; row["Thunhap"] = DBNull.Value; row["TinhHieuQua"] = tinhhieuqua; row["Parent_ID"] = Parent_ID; row["MaSP"] = MaSP; break; case "Tuoi": row["SoThich"] = DBNull.Value; row["GioiTinh"] = DBNull.Value; row["Tuoi"] = value;//gar.at.mlable; row["Thunhap"] = DBNull.Value; row["TinhHieuQua"] = tinhhieuqua; row["Parent_ID"] = Parent_ID; row["MaSP"] = MaSP; break; case "Thunhap": row["SoThich"] = DBNull.Value; row["GioiTinh"] = DBNull.Value; row["Tuoi"] = DBNull.Value;//gar.at.mlable; row["Thunhap"] = value; row["TinhHieuQua"] = tinhhieuqua; row["Parent_ID"] = Parent_ID; row["MaSP"] = MaSP; break; } return(row); }