Beispiel #1
0
        /// <summary>
        /// Load lai thong so phieu, matu truc... khi biet duoc id cua d_xtutrucll
        /// </summary>
        /// <param name="aIDXuatTutruc"></param>
        private void f_get_thongtinphieu(decimal aIDXuatTutruc)
        {
            string asql = "select 'xxx' as mmyy, to_char(a.ngay,'dd/mm/yyyy') as ngay, a.loai, a.phieu, a.nhom, a.makp, a.makhoa ";

            asql += " from xxx.d_duyet a inner join xxx.d_xtutrucll b on a.id=b.idduyet where b.id<>0 and b.id=" + aIDXuatTutruc;
            DataSet ads = new DataSet();

            ads = d.get_data_mmyy(asql, s_ngay, d.ngayhienhanh_server.Substring(0, 10), true);
            if (ads != null && ads.Tables.Count > 0 && ads.Tables[0].Rows.Count > 0)
            {
                string tmp_mmyy = "";
                foreach (DataRow dr in ads.Tables[0].Rows)
                {
                    ngay.Value         = d.StringToDate(dr["ngay"].ToString());
                    tmp_mmyy           = dr["mmyy"].ToString().Replace(user, "");
                    mm.Value           = decimal.Parse(tmp_mmyy.Substring(0, 2));
                    yyyy.Value         = decimal.Parse(tmp_mmyy.Substring(2, 2)) + 2000;
                    chkAll.Checked     = true;
                    nhom.SelectedValue = dr["nhom"].ToString();
                    nhom_SelectedIndexChanged(null, null);
                    makp.SelectedValue = dr["makhoa"].ToString();
                    makp_SelectedIndexChanged(null, null);
                    matutruc.SelectedValue = dr["makp"].ToString();
                    phieu.SelectedValue    = dr["phieu"].ToString();
                    //ena_obj(false);
                    break;
                }
            }
            else
            {
                ena_obj(true);
            }
        }
Beispiel #2
0
        private void load_grid()
        {
            string stime = "'" + m.f_ngay + "'";
            string sql   = "select to_char(c.ngay,'dd/mm/yy') as ngay,d.ten,d.dang,b.slyeucau as slylenh,g.tenkp,i.hoten as tenbs,a.mabn,e.hoten,b.cachdung,b.choduyet,b.id,b.stt";

            sql += " from xxx.d_dutrull a,xxx.d_dutruct b,xxx.d_duyet c," + user + ".d_dmbd d," + user + ".btdbn e," + user + ".d_duockp f," + user + ".btdkp_bv g,xxx.d_dausinhton h," + user + ".dmbs i";
            sql += " where a.id=b.id and a.idduyet=c.id and b.mabd=d.id and a.mabn=e.mabn and c.makhoa=f.id and f.makp=g.makp ";
            sql += " and a.id=h.id and h.mabs=i.ma ";
            sql += " and " + m.for_ngay("c.ngay", stime) + " between to_date('" + tu.Text + "'," + stime + ") and to_date('" + den.Text + "'," + stime + ")";
            sql += " and d.choduyet=1 and c.nhom=" + i_nhom + " order by c.ngay,d.ten";
            ds   = d.get_data_mmyy(sql, tu.Text, den.Text, true);
            ds.Tables[0].Columns.Add("Chon", typeof(bool));
            foreach (DataRow r in ds.Tables[0].Rows)
            {
                r["chon"] = r["choduyet"].ToString() == "0";
            }
            dataGrid1.DataSource = ds.Tables[0];
            CurrencyManager cm = (CurrencyManager)BindingContext[dataGrid1.DataSource, dataGrid1.DataMember];
            DataView        dv = (DataView)cm.List;

            dv.AllowNew = false;
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        private void butChon_Click(object sender, System.EventArgs e)
        {
            if (makp.SelectedIndex == -1)
            {
                makp.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() + ",";
                    }
                }
            }
            i_makp = int.Parse(makp.SelectedValue.ToString());
            string stime = "'" + m.f_ngay + "'";

            sql  = " select a.mabn,e.hoten,f.doituong,g.ten tenkho,d.ma,";
            sql += " trim(d.ten)||' '||d.hamluong ten,d.tenhc,d.dang,b.slyeucau,b.slthuc,";
            sql += " h.ten tennguon,d.hamluong";
            sql += ",i.ten as tennhom";
            sql += " from xxx.d_xtutrucll a," + user + ".d_treoduyet b,xxx.d_duyet c," + user + ".d_dmbd d," + user + ".btdbn e," + user + ".d_doituong f," + user + ".d_dmkho g," + user + ".d_dmnguon h," + user + ".d_dmnhom i";
            sql += " where a.id=b.id and a.idduyet=c.id and b.mabd=d.id and a.mabn=e.mabn and b.madoituong=f.madoituong and b.makho=g.id and b.manguon=h.id and d.manhom=i.id";
            sql += " and c.done<>0 and b.slyeucau>b.slthuc and c.nhom=" + i_nhom;
            sql += " and a.maql<>0";
            if (bTutrucchung)
            {
                sql += " and c.makp=" + i_makp;
            }
            else
            {
                sql += " and c.makhoa=" + i_makp;
            }
            //sql+=" and to_date(c.ngay,'dd/mm/yy') between to_date('"+tu.Text+"','dd/mm/yy') and to_date('"+den.Text+"','dd/mm/yy')";
            sql += " and " + m.for_ngay("c.ngay", stime) + " between to_date('" + tu.Text + "'," + stime + ") and to_date('" + den.Text + "'," + stime + ")";
            if (s_phieu != "")
            {
                sql += " and c.phieu in (" + s_phieu.Substring(0, s_phieu.Length - 1) + ")";
            }
            sql += " union all ";

            sql += " select a.sophieu as mabn,f.doituong as hoten,f.doituong,g.ten tenkho,d.ma,";
            sql += " trim(d.ten)||' '||d.hamluong ten,d.tenhc,d.dang,b.slyeucau,b.slthuc,";
            sql += " h.ten tennguon,d.hamluong";
            sql += ",i.ten as tennhom";
            sql += " from xxx.d_haophill a," + user + ".d_treoduyet b,xxx.d_duyet c," + user + ".d_dmbd d," + user + ".d_doituong f," + user + ".d_dmkho g," + user + ".d_dmnguon h," + user + ".d_dmnhom i";
            sql += " where a.id=b.id and a.idduyet=c.id and b.mabd=d.id and b.madoituong=f.madoituong and b.makho=g.id and b.manguon=h.id and d.manhom=i.id";
            sql += " and c.done<>0 and b.slyeucau>b.slthuc and c.nhom=" + i_nhom;
            if (bTutrucchung)
            {
                sql += " and c.makp=" + i_makp;
            }
            else
            {
                sql += " and c.makhoa=" + i_makp;
            }
            //sql+=" and to_date(c.ngay,'dd/mm/yy') between to_date('"+tu.Text+"','dd/mm/yy') and to_date('"+den.Text+"','dd/mm/yy')";
            sql += " and " + m.for_ngay("c.ngay", stime) + " between to_date('" + tu.Text + "'," + stime + ") and to_date('" + den.Text + "'," + stime + ")";
            if (s_phieu != "")
            {
                sql += " and c.phieu in (" + s_phieu.Substring(0, s_phieu.Length - 1) + ")";
            }
            dt = d.get_data_mmyy(sql, tu.Text, den.Text, true).Tables[0];
            dataGrid1.DataSource = dt;
            if (!bSkip)
            {
                AddGridTableStyle();
            }
            bSkip = true;
        }