private void butOk_Click(object sender, System.EventArgs e) { if (!kiemtra()) { return; } s_makp = makp.SelectedValue.ToString(); s_ngay = ngay.Text; s_tenkp = makp.Text; string mmyy = m.mmyy(s_ngay); if (!m.bMmyy(mmyy)) { m.tao_schema(mmyy, i_userid); } m.close(); d.close(); System.GC.Collect(); this.Close(); }
private void butKetthuc_Click(object sender, System.EventArgs e) { d.close(); this.Close(); }
private void butKetthuc_Click(object sender, System.EventArgs e) { bPrinter = false; oRpt.Close(); oRpt.Dispose(); d.close(); this.Close(); }
private void butOk_Click(object sender, System.EventArgs e) { bOk = true; bool bChieu_sang = m.bChieu_sang; if (bChieu_sang) { DataRow r1, r2; r2 = d.getrowbyid(dtphieu, "id=" + int.Parse(phieu.SelectedValue.ToString())); if (r2 != null) { if (r2["buoi"].ToString() == "0") { r1 = d.getrowbyid(dtkp, "id=" + int.Parse(makp.SelectedValue.ToString())); if (r1 != null) { if (d.get_ttngay(s_ngay, r1["makp"].ToString())) { MessageBox.Show(lan.Change_language_MessageText("Ngày") + " " + s_ngay + " " + lan.Change_language_MessageText("viện phí đã in danh sách thu tiền") + "\n" + lan.Change_language_MessageText("Yêu cầu chọn phiếu buổi chiều !"), d.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()); DataTable tmp = d.get_data("select * from " + xxx + ".d_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 makp=" + i_makp).Tables[0]; if (tmp.Select("done=1").Length > 0) { MessageBox.Show(lan.Change_language_MessageText("Phiếu này đã đánh dấu phát") + "\n" + lan.Change_language_MessageText("Không cho phép hủy ?"), d.Msg); makp.Focus(); return; } try { bDuyettreole = tmp.Select("duyettreole=1").Length > 0; } catch { bDuyettreole = false; } string tenfile = (i_loai == 2 || bBuhaophi)?"d_bucstt":"d_xuatsdct"; sql = "select distinct a.mabn,a.maql"; if (!bIntheocstt) { sql += ",a.makhoa"; } sql += ",b.mabd"; sql += " from " + xxx + ".d_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; if (i_loai == 2) { if (bIntheocstt) { sql += " and a.makp=" + i_makp; } else { sql += " and a.makhoa=" + i_makp; } } else { sql += " 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"; } tmp = d.get_data(sql).Tables[0]; if (tmp.Rows.Count == 0) { if (kiemtra()) { MessageBox.Show(lan.Change_language_MessageText("Đã thu hồi xong."), lan.Change_language_MessageText("Thu hồi"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); d.close(); this.Close(); return; } MessageBox.Show(lan.Change_language_MessageText("Không có số liệu !"), d.Msg); f_thuhoi_phieu_biloi(s_mmyy, s_ngay, i_makp, i_nhom, i_phieu); makp.Focus(); return; } string s_makhoa = ""; if (!bIntheocstt) { foreach (DataRow r in tmp.Select("true", "makhoa")) { if (s_makhoa.IndexOf(r["makhoa"].ToString().Trim() + ",") == -1) { s_makhoa += r["makhoa"].ToString().Trim() + ","; } } } bool bFound = false; if (i_loai == 1 || i_loai == 3) { string s_id = ""; sql = "select distinct a.id"; sql += " from " + xxx + ".d_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; sql += " and a.makhoa=" + i_makp; sql += " and a.thuoc=" + i_thuoc; sql += " and a.maql<>0"; foreach (DataRow r in d.get_data(sql).Tables[0].Rows) { s_id += r["id"].ToString().Trim() + ","; } if (s_id != "") { string _mabn = ""; foreach (DataRow r in d.get_data("select a.mabn,b.hoten from " + xxx + ".d_tienthuoc a," + user + ".btdbn b where a.mabn=b.mabn and a.id in (" + s_id.Substring(0, s_id.Length - 1) + ") and a.done=1 order by a.mabn").Tables[0].Rows) { if (_mabn.IndexOf(r["mabn"].ToString() + " " + r["hoten"].ToString().Trim()) == -1) { _mabn += r["mabn"].ToString() + " " + r["hoten"].ToString().Trim() + "\n"; } } if (_mabn != "") { MessageBox.Show(lan.Change_language_MessageText("Những người bệnh sau :\n" + _mabn + " đã thanh toán, không được thu hồi !"), d.Msg); makp.Focus(); return; } } } if (i_loai == 1) { string s_mabd = "", s_maql = ""; foreach (DataRow r in tmp.Select("true", "maql")) { if (s_maql.IndexOf(r["maql"].ToString().Trim() + ",") == -1) { s_maql += r["maql"].ToString().Trim() + ","; } } sql = "select distinct c.mabd, b.mabn, to_char(a.ngay,'dd/mm/yyyy') as ngay, d.ten as phieu from xxx.d_duyet a,xxx.d_hoantrall b,xxx.d_hoantract c," + user + ".d_loaiphieu d where a.id=b.idduyet and b.id=c.id and a.phieu=d.id"; sql += " and a.done=2 and c.slthuc>0 and a.nhom=" + i_nhom + " and a.loai=3 and to_char(c.ngay,'dd/mm/yyyy')='" + s_ngay + "'"; sql += " and a.makp=" + i_makp; if (s_maql != "") { sql += " and b.maql in (" + s_maql.Substring(0, s_maql.Length - 1) + ")"; } string s_ptra = ""; foreach (DataRow r in d.get_data_mmyy(sql, s_ngay, s_ngay, true).Tables[0].Rows) { s_mabd += r["mabd"].ToString().PadLeft(7, '0') + ","; s_ptra = "Ngày: " + r["ngay"].ToString() + "- Phiếu: " + r["phieu"].ToString() + "- MSBN: " + r["mabn"].ToString(); } if (s_mabd != "") { foreach (DataRow r in tmp.Rows) { if (s_mabd.IndexOf(r["mabd"].ToString().PadLeft(7, '0')) != -1) { bFound = true; break; } } if (bFound) { MessageBox.Show(phieu.Text + " có hoàn trả, không được thu hồi.\nPhải thu hồi phiếu hoàn trả trước !.\n" + s_ptra, d.Msg); makp.Focus(); return; } } } else if (i_loai == 2 && d.bThuhoi_kiemtra_tutruc(i_nhom)) { bFound = false; DataRow r1; sql = "select a.makp, b.sttt,b.makho,sum(b.soluong) as soluong from " + xxx + ".d_xuatsdll a," + xxx + ".d_thucbucstt 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; if (bIntheocstt) { sql += " and a.makp=" + i_makp; } else { sql += " 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"; } sql += " group by b.sttt,b.makho,a.makp"; // DataSet lds = d.get_data(sql); string s_makp_tt = ","; foreach (DataRow dr in lds.Tables[0].Rows) { s_makp_tt += (s_makp_tt.IndexOf("," + dr["makp"].ToString() + ",") < 0) ? dr["makp"].ToString() + "," : ""; } if (s_makp_tt.Trim().Trim(',') == "") { s_makp_tt = i_makp.ToString(); } else { s_makp_tt = s_makp_tt.Trim().Trim(','); } // tmp = d.get_data("select makp,makho,stt,sum(tondau+slnhap-slxuat) as soluong from " + xxx + ".d_tutrucct where makp in (" + s_makp_tt.Trim().Trim(',') + ") group by makho,stt,makp").Tables[0]; foreach (DataRow r in lds.Tables[0].Rows) { r1 = d.getrowbyid(tmp, "makho=" + int.Parse(r["makho"].ToString()) + " and stt=" + decimal.Parse(r["sttt"].ToString()) + " and makp=" + r["makp"].ToString()); if (r1 != null) { if (decimal.Parse(r["soluong"].ToString()) > decimal.Parse(r1["soluong"].ToString())) { bFound = true; break; } } } if (bFound) { MessageBox.Show(phieu.Text + " có xuất, không được thu hồi.\nPhải thu hồi phiếu xuất tủ trực trước !", d.Msg); makp.Focus(); return; } } if (bKiemtra) { if (i_loai == 1 || (i_loai == 3 && i_thuoc == 1 && !bThua)) { bFound = false; DataRow r2; DataTable dthoten = new DataTable(); string s_ravien = ""; r2 = d.getrowbyid(dtkp, "id=" + int.Parse(makp.SelectedValue.ToString())); if (r2 != null) { sql = "select maql from " + user + ".xuatvien where makp='" + r2["makp"].ToString() + "'"; dthoten = d.get_data(sql).Tables[0]; bFound = true; } if (bFound) { foreach (DataRow r in tmp.Rows) { r2 = d.getrowbyid(dthoten, "maql=" + decimal.Parse(r["maql"].ToString())); if (r2 != null) { s_ravien += r["mabn"].ToString() + "\n"; } } } if (s_ravien != "") { MessageBox.Show(lan.Change_language_MessageText("Người bệnh đã ra viện") + "\n" + s_ravien + lan.Change_language_MessageText("không được thu hồi !"), d.Msg); return; } } } Cursor = Cursors.WaitCursor; if (i_loai == 2 && d.bBucstt_tronso(i_nhom)) { if (s_makhoa != "") { sql = "select idduyet from " + xxx + ".d_ngayduyet where nhom=" + i_nhom + " and loai=" + i_loai + " and phieu=" + i_phieu + " and makp in (" + s_makhoa.Substring(0, s_makhoa.Length - 1) + ") and to_char(ngay,'dd/mm/yyyy')='" + s_ngay + "'"; } else { sql = "select idduyet from " + xxx + ".d_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 + "'"; } tmp = d.get_data(sql).Tables[0]; string sid = ""; foreach (DataRow r in tmp.Rows) { sid += r["idduyet"].ToString() + ","; } string sql1 = "select to_char(a.ngay,'dd/mm/yyyy') as ngay,c.ten from xxx.d_xuatsdll a,xxx.d_bucstt b," + user + ".d_loaiphieu c where a.id=b.id and a.phieu=c.id and b.sltreo>0 "; if (sid != "") { sql1 += " and a.idduyet in (" + sid.Substring(0, sid.Length - 1) + ")"; } sql1 += " and a.makp=" + i_makp + " and a.nhom=" + i_nhom; sid = ""; ////Binh 23032012: comment --> chua hieu kiem tra de lam gi??? ////foreach(DataRow r in d.get_data_mmyy(sql1, s_ngay, s_ngay, 30).Tables[0].Rows) ////{ //// sid = "Ngày " + r["ngay"].ToString() + "\nPhiếu " + r["ten"].ToString() + " có duyệt treo\nPhải thu hồi phiếu này trước !"; //// break; ////} ////if (sid != "") ////{ //// MessageBox.Show(sid, d.Msg); //// Cursor = Cursors.Default; //// return; ////} foreach (DataRow r in tmp.Rows) { sql = "select b.* from xxx.d_xtutrucll a," + user + ".d_treoduyet b where a.id=b.id and a.idduyet=" + decimal.Parse(r["idduyet"].ToString()); foreach (DataRow r1 in d.get_data_mmyy(sql, s_ngay, s_ngay, 30).Tables[0].Rows) { if (d.get_data("select a.* from " + xxx + ".d_xuatsdll a," + xxx + ".d_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) { d.execute_data("update " + user + ".d_treoduyet set slthuc=0 where id=" + decimal.Parse(r1["id"].ToString()) + " and stt=" + int.Parse(r1["stt"].ToString())); } } } } d.upd_duyet(s_mmyy, i_makp, i_nhom, i_loai, i_phieu, s_ngay, (bNguoiduyet_nguoithuhoi ? s_makho : ""));//s_makho d.upd_theodoiduyet(s_mmyy, s_ngay, i_nhom, i_loai, i_makp, 1); d.upd_thuhoi(s_mmyy, i_nhom, s_ngay, i_loai, i_makp, i_userid, i_phieu); sql = "select distinct a.id, to_char(a.ngayylenh,'dd/mm/yyyy') as ngayylenh from " + xxx + ".d_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; if (i_loai == 2) { if (bIntheocstt) { sql += " and a.makp=" + i_makp; } else { sql += " and a.makhoa=" + i_makp; } } else { sql += " and a.makhoa=" + i_makp; } sql += " and a.thuoc=" + i_thuoc; if (b1kho) { sql += " and a.lydo=" + int.Parse(s_makho.Substring(0, s_makho.Length - 1)); } if (bBuhaophi || i_loai == 4 || bThua || i_thuoc == 2) { sql += " and a.maql=0"; } else { sql += " and a.maql<>0"; } foreach (DataRow r in d.get_data(sql).Tables[0].Rows) { d.del(s_mmyy, tenfile, decimal.Parse(r["id"].ToString()), dtll, i_loai, bBuhaophi, i_nhom, i_phieu, s_ngay, i_userid, bDuyettreole, r["ngayylenh"].ToString()); } // string file = (i_loai == 2) ? "d_thucbucstt" : "d_thucxuat"; sql = "select distinct a.id from " + xxx + ".d_xuatsdll a," + xxx + "." + file + " 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; if (i_loai == 2) { if (bIntheocstt) { sql += " and a.makp=" + i_makp; } else { sql += " and a.makhoa=" + i_makp; } } else { sql += " and a.makhoa=" + i_makp; } sql += " and a.thuoc=" + i_thuoc; if (b1kho) { sql += " and a.lydo=" + int.Parse(s_makho.Substring(0, s_makho.Length - 1)); } if (bBuhaophi || i_loai == 4 || bThua || i_thuoc == 2) { sql += " and a.maql=0"; } else { sql += " and a.maql<>0"; } foreach (DataRow r in d.get_data(sql).Tables[0].Rows) { d.execute_data("delete from " + xxx + "." + file + " where id=" + decimal.Parse(r["id"].ToString())); } // dtct.Clear(); sql = "select * from " + user + ".d_dmkho where nhom=" + i_nhom; if (s_makho != "") { sql += " and id in (" + s_makho.Substring(0, s_makho.Length - 1) + ")"; } foreach (DataRow r in d.get_data(sql).Tables[0].Rows) { d.execute_data("delete from " + xxx + ".d_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())); } if (d.bKiemtra_duyet(i_nhom)) { d.upd_tonkho(s_mmyy, i_nhom, 0); } int itable = d.tableid(s_mmyy, "d_ngayduyet"); d.upd_eve_tables(s_mmyy, itable, i_userid, "del"); d.upd_eve_upd_del(s_mmyy, itable, i_userid, "del", i_nhom.ToString() + "^" + i_loai.ToString() + "^" + i_makp.ToString() + "^" + s_ngay + "^0^" + i_phieu.ToString() + "^" + s_makho + "^0"); Cursor = Cursors.Default; if (d.bTinnhan(i_nhom)) { DataRow r = d.getrowbyid(dtkp, "id=" + int.Parse(makp.SelectedValue.ToString())); if (r != null) { if (r["computer"].ToString() != "") { d.netsend(d.sDomain(i_nhom), r["computer"].ToString().Trim(), s_noidung + " KHOA " + m.khongdau(makp.Text) + " PHIEU " + m.khongdau(phieu.Text) + " DA THU HOI !"); } } } // MessageBox.Show(lan.Change_language_MessageText("Đã thu hồi xong."), lan.Change_language_MessageText("Thu hồi"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); d.close(); this.Close(); }
private void butKetthuc_Click(object sender, System.EventArgs e) { m.close(); d.close(); System.GC.Collect(); this.Close(); }
private void butChon_Click(object sender, System.EventArgs e) { if (makp.SelectedIndex == -1) { makp.Focus(); return; } if (phieu.SelectedIndex == -1) { phieu.Focus(); return; } s_phieu = ""; if (phieudutru.CheckedItems.Count > 0) { for (int i = 0; i < phieudutru.Items.Count; i++) { if (phieudutru.GetItemChecked(i)) { s_phieu += dtph.Rows[i]["id"].ToString().Trim() + ","; } } } s_tu = tu.Text; s_den = den.Text; i_phieu = int.Parse(phieu.SelectedValue.ToString()); i_makp = int.Parse(makp.SelectedValue.ToString()); s_tenkp = makp.Text; if (d.get_duyet(s_mmyy, i_makp, i_nhom, i_loai, i_phieu, s_ngay, s_makho)) { MessageBox.Show(lan.Change_language_MessageText("Ngày") + " " + s_ngay + "\n" + lan.Change_language_MessageText("Khoa") + " " + makp.Text + "\n" + lan.Change_language_MessageText("Phiếu") + " " + phieu.Text + "\n" + lan.Change_language_MessageText("Đã duyệt !"), d.Msg); return; } bool bChieu_sang = m.bChieu_sang; if (bChieu_sang) { DataRow r1, r2; r2 = d.getrowbyid(dtphieu, "id=" + int.Parse(phieu.SelectedValue.ToString())); if (r2 != null) { if (r2["buoi"].ToString() == "0") { r1 = d.getrowbyid(dtkp, "id=" + int.Parse(makp.SelectedValue.ToString())); if (r1 != null) { if (d.get_ttngay(s_ngay, r1["makp"].ToString())) { MessageBox.Show(lan.Change_language_MessageText("Ngày") + " " + s_ngay + " " + lan.Change_language_MessageText("viện phí đã in danh sách thu tiền") + "\n" + lan.Change_language_MessageText("Yêu cầu chọn phiếu buổi chiều !"), d.Msg); return; } } } } } if (chkChuyen.Checked) { string sql = "select id from " + xxx + ".d_duyet "; sql += " where done=0 and nhom=" + i_nhom + " and loai=" + i_loai; sql += " and makhoa=" + i_makp; sql += " and ngay between to_date('" + s_tu + "','" + f_ngay + "') and to_date('" + s_den + "','" + f_ngay + "')"; if (s_phieu != "") { sql += " and phieu in (" + s_phieu.Substring(0, s_phieu.Length - 1) + ")"; } foreach (DataRow r in d.get_data(sql).Tables[0].Rows) { d.execute_data("update " + xxx + ".d_duyet set done=1 where id=" + decimal.Parse(r["id"].ToString())); } } DataTable dttam = new DataTable(); dttam = d.get_data("select computer from " + user + ".d_danglaysolieu where makp=" + i_makp + " and phieu=" + i_phieu + " and to_char(ngay,'dd/mm/yyyy')='" + s_ngay + "' and computer<>'" + System.Environment.MachineName + "'").Tables[0]; if (dttam.Rows.Count > 0) { MessageBox.Show(lan.Change_language_MessageText("Phiếu này đang lấy số liệu duyệt tại máy ") + dttam.Rows[0][0].ToString() + lan.Change_language_MessageText(".\n Vui lòng chọn phiếu khác.")); return; } d.upd_danglaysolieu(i_makp, i_phieu, s_ngay, i_userid); d.close(); this.Close(); }