private void ins_items() { System.Data.DataTable dt = d.get_data(sql).Tables[0]; string ten; if (bSothe) { decimal id = 0; foreach (DataRow r in dt.Select("loai=0", "id")) { if (id != decimal.Parse(r["id"].ToString())) { id = decimal.Parse(r["id"].ToString()); r1 = dtso.NewRow(); r1["id"] = r["id"].ToString(); r1["ngay"] = r["ngay"].ToString(); r1["sothe"] = r["sothe"].ToString(); r1["hoten"] = r["hoten"].ToString(); r1["congkham"] = d.Congkham(i_nhom); dtso.Rows.Add(r1); soluot += 1; } } } int isophieu = 0; foreach (DataRow r in dt.Rows) { if (bSothe) { sql = "sothe='" + r["sothe"].ToString() + "' and hoten='" + r["hoten"].ToString() + "'"; } else { sql = "mabn='" + r["mabn"].ToString() + "' and hoten='" + r["hoten"].ToString() + "'"; } r1 = d.getrowbyid(ds.Tables[0], sql); ten = (r["loai"].ToString() == "0")?"thuoc":"cls"; if (r1 == null) { // isophieu = d.get_sophieu_bhyt_userid(tu.Text, den.Text, r["mabn"].ToString(), decimal.Parse(r["mavaovien"].ToString()), r["ngayduyet"].ToString(), int.Parse(madoituong.SelectedValue.ToString())); // r2 = ds.Tables[0].NewRow(); r2["sothe"] = r["sothe"].ToString(); if (r["sothe"].ToString().Trim().Length > 4) { r2["stt"] = (r["sothe"].ToString().Substring(2, 2) == s_thetrongtinh)?0:1; r2["sothe1"] = r["sothe"].ToString().Substring(0, 2); r2["sothe2"] = r["sothe"].ToString().Substring(2, 2); r2["sothe3"] = r["sothe"].ToString().Substring(4); } r2["mabn"] = r["mabn"].ToString(); r2["hoten"] = r["hoten"].ToString(); r2["thuoc"] = 0; r2["cls"] = 0; r2[ten] = r["sotien"].ToString(); r2["congkham"] = 0; r2["sophieu"] = isophieu; r2["tongcong"] = decimal.Parse(r["sotien"].ToString()) + decimal.Parse(r["congkham"].ToString()); ds.Tables[0].Rows.Add(r2); } else { dr = ds.Tables[0].Select(sql); if (dr.Length > 0) { dr[0][ten] = decimal.Parse(dr[0][ten].ToString()) + decimal.Parse(r["sotien"].ToString()); dr[0]["tongcong"] = decimal.Parse(dr[0]["tongcong"].ToString()) + decimal.Parse(r["sotien"].ToString()); } } } if (bSothe) { foreach (DataRow r in ds.Tables[0].Rows) { if (bSothe) { sql = "sothe='" + r["sothe"].ToString() + "' and hoten='" + r["hoten"].ToString() + "'"; } else { sql = "mabn='" + r["mabn"].ToString() + "' and hoten='" + r["hoten"].ToString() + "'"; } r["soluot"] = dtso.Select(sql).Length.ToString(); r["congkham"] = decimal.Parse(r["soluot"].ToString()) * d.Congkham(i_nhom); r["tongcong"] = decimal.Parse(r["thuoc"].ToString()) + decimal.Parse(r["cls"].ToString()) + decimal.Parse(r["congkham"].ToString()); dthuoc += decimal.Parse(r["thuoc"].ToString()); dcls += decimal.Parse(r["cls"].ToString()); } } ds.AcceptChanges(); }