private void mabn_Validated(object sender, System.EventArgs e) { int i = 0; string s_cont = "", s_sothe = "", s_denngay = "", s_tenbv = ""; long o_maql; hoten.Text = ""; l_maql = 0; l_idkhoa = 0; dsngay.Clear(); if (mabn.Text == "" || mabn.Text.Trim().Length < 3) { return; } if (mabn.Text.Trim().Length != 8) { mabn.Text = mabn.Text.Substring(0, 2) + mabn.Text.Substring(2).PadLeft(6, '0'); } if (b_ndot) { s_cont = "a.id=b.id(+)"; sql = "select c.hoten,c.namsinh,c.phai,c.sonha,c.thon,a.maql,a.id,a.giuong,to_char(sysdate,'dd/mm/yyyy') ngayvao,decode(b.ngay,null,to_char(sysdate,'dd/mm/yyyy'),to_char(b.ngay,'dd/mm/yyyy')) ngayra,a.makp,d.tenkp,nvl(b.chandoan,' ') chandoan,nvl(b.maicd,' ') maicd,nvl(e.tentt,' ') tentt,nvl(f.tenquan,' ') tenquan,nvl(g.tenpxa,' ') tenpxa,nvl(b.ketqua,0) as ketqua,nvl(b.ttlucrk,0) as ttlucrv,' ' as soluutru from nhapkhoa a,xuatkhoa b,btdbn c,btdkp_bv d,btdtt e,btdquan f,btdpxa g,benhandt h where " + s_cont + " and a.mabn=c.mabn and a.makp=d.makp and c.matt=e.matt(+) and c.maqu=f.maqu(+) and c.maphuongxa=g.maphuongxa(+) and a.maql=h.maql and a.mabn='" + mabn.Text + "' and h.loaiba=" + i_loaiba; if (s_makp != "") { sql += " and a.makp in (" + s_makp.Substring(0, s_makp.Length - 1) + ")"; } sql += " order by a.id desc"; } else { if (s_makp != "") { s_cont = "a.id=b.id(+)"; sql = "select c.hoten,c.namsinh,c.phai,c.sonha,c.thon,a.maql,a.id,a.giuong,to_char(sysdate,'dd/mm/yyyy') ngayvao,decode(b.ngay,null,to_char(sysdate,'dd/mm/yyyy'),to_char(b.ngay,'dd/mm/yyyy')) ngayra,a.makp,d.tenkp,nvl(b.chandoan,' ') chandoan,nvl(b.maicd,' ') maicd,nvl(e.tentt,' ') tentt,nvl(f.tenquan,' ') tenquan,nvl(g.tenpxa,' ') tenpxa,nvl(b.ketqua,0) as ketqua,nvl(b.ttlucrk,0) as ttlucrv,' ' as soluutru from nhapkhoa a,xuatkhoa b,btdbn c,btdkp_bv d,btdtt e,btdquan f,btdpxa g,benhandt h where " + s_cont + " and a.mabn=c.mabn and a.makp=d.makp and c.matt=e.matt(+) and c.maqu=f.maqu(+) and c.maphuongxa=g.maphuongxa(+) and a.maql=h.maql and a.makp in (" + s_makp.Substring(0, s_makp.Length - 1) + ") and a.mabn='" + mabn.Text + "' and h.loaiba=" + i_loaiba + " order by a.id desc"; } else { s_cont = "a.maql=b.maql(+)"; sql = "select c.hoten,c.namsinh,c.phai,c.sonha,c.thon,a.maql,0 id,' ' giuong,to_char(sysdate,'dd/mm/yyyy') ngayvao,decode(b.ngay,null,to_char(sysdate,'dd/mm/yyyy'),to_char(b.ngay,'dd/mm/yyyy')) ngayra,decode(b.makp,null,a.makp,b.makp) makp,decode(b.makp,null,h.tenkp,d.tenkp) tenkp,nvl(b.chandoan,' ') chandoan,nvl(b.maicd,' ') maicd,nvl(e.tentt,' ') tentt,nvl(f.tenquan,' ') tenquan,nvl(g.tenpxa,' ') tenpxa,nvl(b.ketqua,0) as ketqua,nvl(b.ttlucrv,0) as ttlucrv,b.soluutru from benhandt a,xuatvien b,btdbn c,btdkp_bv d,btdtt e,btdquan f,btdpxa g,btdkp_bv h where " + s_cont + " and a.mabn=c.mabn and b.makp=d.makp(+) and c.matt=e.matt(+) and c.maqu=f.maqu(+) and c.maphuongxa=g.maphuongxa(+) and a.makp=h.makp and a.mabn='" + mabn.Text + "' and a.loaiba=" + i_loaiba + " order by a.maql desc"; } } foreach (DataRow r in m.get_data(sql).Tables[0].Rows) { if (i == 0) { hoten.Text = r["hoten"].ToString(); namsinh.Text = r["namsinh"].ToString(); s_ngayvao = r["ngayvao"].ToString(); ngayra.Text = r["ngayra"].ToString(); diachi.Text = r["sonha"].ToString().Trim() + " " + r["thon"].ToString().Trim(); makp.Text = r["makp"].ToString(); tenkp.Text = r["tenkp"].ToString(); l_maql = long.Parse(r["maql"].ToString()); l_idkhoa = long.Parse(r["id"].ToString()); sothe.Text = m.get_sothe(l_maql).ToString(); } o_maql = long.Parse(r["maql"].ToString()); foreach (DataRow r1 in m.get_data("select a.sothe,to_char(a.denngay,'dd/mm/yyyy') denngay,b.tenbv from bhyt a,dmnoicapbhyt b where a.mabv=b.mabv and a.maql=" + o_maql).Tables[0].Rows) { s_sothe = r1["sothe"].ToString(); s_denngay = r1["denngay"].ToString(); s_tenbv = r1["tenbv"].ToString(); break; } m.updrec_ravien(dsngay, mabn.Text, o_maql, long.Parse(r["id"].ToString()), hoten.Text, r["namsinh"].ToString(), (r["phai"].ToString() == "0")?"Nam":"Nữ", r["sonha"].ToString().Trim() + " " + r["thon"].ToString().Trim() + ", " + r["tenpxa"].ToString().Trim() + ", " + r["tenquan"].ToString().Trim() + ", " + r["tentt"].ToString().Trim(), 0, "", s_sothe, s_denngay, m.get_noigioithieu(o_maql), s_tenbv, r["giuong"].ToString(), r["makp"].ToString(), r["tenkp"].ToString(), r["ngayvao"].ToString(), r["ngayra"].ToString(), r["chandoan"].ToString(), r["maicd"].ToString(), m.get_nguoinha(m.mmyy(r["ngayvao"].ToString()), mabn.Text, o_maql), 2, m.phuongphapdieutri(r["makp"].ToString()), m.ketquadieutri(int.Parse(r["ketqua"].ToString()), int.Parse(r["ttlucrv"].ToString())), r["soluutru"].ToString()); i++; } if (l_maql == 0) { MessageBox.Show(lan.Change_language_MessageText("Người bệnh này chưa hoàn tất thủ tục !"), LibMedi.AccessData.Msg); mabn.Focus(); } ngayvao.Text = s_ngayvao; if (sothe.Text != "") { maphu.SelectedIndex = d.get_maphu(l_maql); } maphu.Enabled = sothe.Text != ""; }