private void butOk_Click(object sender, System.EventArgs e) { bOk = true; bool bChieu_sang = ttb.bChieu_sang; if (bChieu_sang) { DataRow r1, r2; r2 = ttb.getrowbyid(dtphieu, "id=" + int.Parse(phieu.SelectedValue.ToString())); if (r2 != null) { if (r2["buoi"].ToString() == "0") { r1 = ttb.getrowbyid(dtkp, "id=" + int.Parse(makp.SelectedValue.ToString())); if (r1 != null) { if (ttb.get_ttngay(s_ngay, r1["makp"].ToString())) { MessageBox.Show("Ngày " + s_ngay + " viện phí đã in danh sách thu tiền\nYêu cầu chọn phiếu buổi chiều !", ttb.Msg); return; } } } } } if (makp.SelectedIndex == -1 || phieu.SelectedIndex == -1) { if (makp.SelectedIndex == -1) { makp.Focus(); } else { phieu.Focus(); } return; } i_makp = int.Parse(makp.SelectedValue.ToString()); i_phieu = int.Parse(phieu.SelectedValue.ToString()); string tenfile = (i_loai == 2 || bBuhaophi)?"ttb_bucstt":"ttb_xuatsdct"; sql = "select distinct a.mabn,a.maql from " + xxx + ".ttb_xuatsdll a," + xxx + "." + tenfile + " b where a.id=b.id and to_char(a.ngay,'dd/mm/yyyy')='" + s_ngay + "'"; sql += " and a.nhom=" + i_nhom + " and a.loai=" + i_loai + " and a.phieu=" + i_phieu + " and a.makhoa=" + i_makp; sql += " and a.thuoc=" + i_thuoc; if (bBuhaophi || i_loai == 4 || bThua || i_thuoc == 2) { sql += " and a.maql=0"; } else { sql += " and a.maql<>0"; } DataTable tmp = ttb.get_data(sql).Tables[0]; if (tmp.Rows.Count == 0) { MessageBox.Show("Không có số liệu !", ttb.Msg); makp.Focus(); return; } if (bKiemtra) { if (i_loai == 1 || (i_loai == 3 && i_thuoc == 1 && !bThua)) { bool bFound = false; DataRow r2; DataTable dthoten = new DataTable(); string s_ravien = ""; r2 = ttb.getrowbyid(dtkp, "id=" + int.Parse(makp.SelectedValue.ToString())); if (r2 != null) { sql = "select maql from " + user + ".xuatvien where makp='" + r2["makp"].ToString() + "'"; dthoten = ttb.get_data(sql).Tables[0]; bFound = true; } if (bFound) { foreach (DataRow r in tmp.Rows) { r2 = ttb.getrowbyid(dthoten, "maql=" + decimal.Parse(r["maql"].ToString())); if (r2 != null) { s_ravien += r["mabn"].ToString() + "\n"; } } } if (s_ravien != "") { MessageBox.Show("Người bệnh đã ra viện\n" + s_ravien + "không được thu hồi !", ttb.Msg); return; } } } Cursor = Cursors.WaitCursor; if (i_loai == 2 && ttb.bBucstt_tronso(i_nhom)) { sql = "select idduyet from " + xxx + ".ttb_ngayduyet where nhom=" + i_nhom + " and loai=" + i_loai + " and phieu=" + i_phieu + " and makp=" + i_makp + " and to_char(ngay,'dd/mm/yyyy')='" + s_ngay + "'"; if (s_makho != "") { sql += " and makho='" + s_makho + "'"; } foreach (DataRow r in ttb.get_data(sql).Tables[0].Rows) { sql = "select b.* from " + xxx + ".ttb_xtutrucll a," + user + ".ttb_treoduyet b where a.id=b.id and a.idduyet=" + decimal.Parse(r["idduyet"].ToString()); foreach (DataRow r1 in ttb.get_data(sql).Tables[0].Rows) { if (ttb.get_data("select a.* from " + xxx + ".ttb_xuatsdll a," + xxx + ".ttb_bucstt b where a.id=b.id and a.idduyet=" + decimal.Parse(r1["id"].ToString()) + " and b.sttduyet=" + int.Parse(r1["stt"].ToString())).Tables[0].Rows.Count == 0) { ttb.execute_data("update " + user + ".ttb_treoduyet set slthuc=0 where id=" + decimal.Parse(r1["id"].ToString()) + " and stt=" + int.Parse(r1["stt"].ToString())); } } } } ttb.upd_duyet(s_mmyy, i_makp, i_nhom, i_loai, i_phieu, s_ngay, s_makho); ttb.upd_theodoiduyet(s_mmyy, s_ngay, i_nhom, i_loai, i_makp, 1); sql = "select distinct a.id from " + xxx + ".ttb_xuatsdll a," + xxx + "." + tenfile + " b where a.id=b.id and to_char(a.ngay,'dd/mm/yyyy')='" + s_ngay + "'"; sql += " and a.nhom=" + i_nhom + " and a.loai=" + i_loai + " and a.phieu=" + i_phieu + " and a.makhoa=" + i_makp; sql += " and a.thuoc=" + i_thuoc; if (bBuhaophi || i_loai == 4 || bThua || i_thuoc == 2) { sql += " and a.maql=0"; } else { sql += " and a.maql<>0"; } foreach (DataRow r in ttb.get_data(sql).Tables[0].Rows) { ttb.del(s_mmyy, tenfile, decimal.Parse(r["id"].ToString()), dtll, i_loai, bBuhaophi, i_nhom, i_phieu, s_ngay, i_userid, false, s_ngay); } dtct.Clear(); sql = "select * from " + user + ".ttb_dmkho where nhom=" + i_nhom; if (s_makho != "") { sql += " and id in (" + s_makho.Substring(0, s_makho.Length - 1) + ")"; } foreach (DataRow r in ttb.get_data(sql).Tables[0].Rows) { ttb.execute_data("delete from " + xxx + ".ttb_daduyet where nhom=" + i_nhom + " and to_char(ngay,'dd/mm/yyyy')='" + s_ngay + "' and makp=" + i_makp + " and loai=" + i_loai + " and phieu=" + i_phieu + " and makho=" + int.Parse(r["id"].ToString())); } ttb.upd_tonkho(s_mmyy, i_nhom, 0); Cursor = Cursors.Default; if (ttb.bTinnhan(i_nhom)) { DataRow r = ttb.getrowbyid(dtkp, "id=" + int.Parse(makp.SelectedValue.ToString())); if (r != null) { if (r["computer"].ToString() != "") { ttb.netsend(ttb.sDomain(i_nhom), r["computer"].ToString().Trim(), s_noidung + " KHOA " + ttb.khongdau(makp.Text) + " PHIEU " + ttb.khongdau(phieu.Text) + " DA THU HOI !"); } } } // MessageBox.Show("Đã thu hồi xong.", "Thu hồi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Close(); }