예제 #1
0
        private void butOk_Click(object sender, System.EventArgs e)
        {
            if (ttb.songay(ttb.StringToDate(den.Text), ttb.StringToDate(tu.Text), 1) > i_songay)
            {
                MessageBox.Show("Số ngày in phiếu (" + i_songay.ToString() + ")", ttb.Msg);
                tu.Focus();
                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());
            s_makho   = ""; s_tenkho = "";
            s_madt    = ""; s_tendt = "";
            s_manguon = ""; s_tennguon = "";
            if (madoituong.CheckedItems.Count == 0)
            {
                for (int i = 0; i < madoituong.Items.Count; i++)
                {
                    s_madt += dtdt.Rows[i]["madoituong"].ToString() + ",";
                }
            }
            else
            {
                for (int i = 0; i < madoituong.Items.Count; i++)
                {
                    if (madoituong.GetItemChecked(i))
                    {
                        s_madt  += dtdt.Rows[i]["madoituong"].ToString() + ",";
                        s_tendt += dtdt.Rows[i]["doituong"].ToString() + ";";
                    }
                }
            }
            if (manguon.CheckedItems.Count == 0)
            {
                for (int i = 0; i < manguon.Items.Count; i++)
                {
                    s_manguon += dtnguon.Rows[i]["id"].ToString().Trim() + ",";
                }
            }
            else
            {
                for (int i = 0; i < manguon.Items.Count; i++)
                {
                    if (manguon.GetItemChecked(i))
                    {
                        s_manguon  += dtnguon.Rows[i]["id"].ToString().Trim() + ",";
                        s_tennguon += dtnguon.Rows[i]["ten"].ToString() + ";";
                    }
                }
            }
            if (kho.CheckedItems.Count == 0)
            {
                for (int i = 0; i < kho.Items.Count; i++)
                {
                    s_makho += dtkho.Rows[i]["id"].ToString().Trim() + ",";
                }
            }
            else
            {
                for (int i = 0; i < kho.Items.Count; i++)
                {
                    if (kho.GetItemChecked(i))
                    {
                        s_makho  += dtkho.Rows[i]["id"].ToString().Trim() + ",";
                        s_tenkho += dtkho.Rows[i]["ten"].ToString() + ";";
                    }
                }
            }
            ds.Clear();
            s_idduyet = "";
            string s_idstt = "";

            foreach (DataRow r in ttb.get_data("select idduyet,sttduyet from " + xxx + ".ttb_ngayduyet where nhom=" + i_nhom + " and loai=" + i_loai + " and makp=" + i_makp + " and ngay between to_date('" + tu.Text + "','" + f_ngay + "') and to_date('" + den.Text + "','" + f_ngay + "') and phieu=" + i_phieu).Tables[0].Rows)
            {
                s_idduyet += "(a.id=" + decimal.Parse(r["idduyet"].ToString());
                if (r["sttduyet"].ToString() != "")
                {
                    s_idduyet += " and b.sttduyet in (" + r["sttduyet"].ToString().Trim().Substring(0, r["sttduyet"].ToString().Trim().Length - 1) + ")";
                }
                s_idduyet += ") or ";

                s_idstt += "(a.id=" + decimal.Parse(r["idduyet"].ToString());
                if (r["sttduyet"].ToString() != "")
                {
                    s_idstt += " and b.stt in (" + r["sttduyet"].ToString().Trim().Substring(0, r["sttduyet"].ToString().Trim().Length - 1) + ")";
                }
                s_idstt += ") or ";
            }
            if (s_idduyet == "")
            {
                MessageBox.Show("Không có số liệu !", ttb.Msg);
                tu.Focus();
                return;
            }

            if (s_idstt != "")
            {
                s_idstt = s_idstt.Substring(0, s_idstt.Length - 4);
            }
            if (s_idduyet != "")
            {
                s_idduyet = s_idduyet.Substring(0, s_idduyet.Length - 4);
            }
            if (ttb.bSLYeucau(i_nhom))
            {
                ds = ttb.get_slyeucau(s_mmyy, ds, dt, dtkho, i_loai, file1, file2, s_idstt, s_madt, s_makho, s_manguon, bBuhaophi, dtdt, bDoituong_phieulinh, bNhomin_mabd, s_doc, tu.Text, tu.Text);
            }
            if (xuatcstt.Checked)
            {
                tieude = "PHIẾU XUẤT TỦ TRỰC";
                if (ttb.bPhieulinh_dongia(i_nhom))
                {
                    ds = ttb.get_xuatcstt_dongia(s_mmyy, ds, dt, dtkho, s_idduyet, s_madt, s_makho, s_manguon, bBuhaophi, s_doc, bNhomin_mabd, dtdt, bDoituong_phieulinh, i_nhom);
                }
                else
                {
                    ds = ttb.get_xuatcstt(s_mmyy, ds, dt, dtkho, s_idduyet, s_madt, s_makho, s_manguon, bBuhaophi, s_doc, bNhomin_mabd, dtdt, bDoituong_phieulinh);
                }
            }
            else
            {
                if (ttb.bPhieulinh_dongia(i_nhom))
                {
                    ds = ttb.get_slxuat_dongia(ds, dt, dtkho, tu.Text, den.Text, s_mmyy, i_nhom, i_loai, i_phieu, i_makp, s_madt, s_makho, s_manguon, bBuhaophi, s_doc, bNhomin_mabd, dtdt, bDoituong_phieulinh, "");
                }
                else
                {
                    ds = ttb.get_slxuat(ds, dt, dtkho, tu.Text, den.Text, s_mmyy, i_nhom, i_loai, i_phieu, i_makp, s_madt, s_makho, s_manguon, bBuhaophi, s_doc, bNhomin_mabd, dtdt, bDoituong_phieulinh, "");
                }
                if (bBuhaophi)
                {
                    tieude = "PHIẾU BÙ";
                }
                else
                {
                    tieude = s_title;
                }
            }
            if (ds.Tables[0].Rows.Count == 0 && s_doc == "")
            {
                MessageBox.Show("Không có số liệu !", ttb.Msg);
                tu.Focus();
                return;
            }
            if (ttb.bPhieulinh_dongia(i_nhom))
            {
                ttb.sort_inphieu_dongia(dsxml, ds, ttb.bSLYeucau(i_nhom), s_mmyy, tu.Text, i_nhom, i_makp, i_loai, i_phieu, s_makho, s_madt, s_manguon, nguoilinh.Text, dtdt, bDoituong_phieulinh, (xuatcstt.Checked)?false:(i_loai == 2)?true:bBuhaophi);
            }
            else
            {
                ttb.sort_inphieu(dsxml, ds, ttb.bSLYeucau(i_nhom), s_mmyy, tu.Text, i_nhom, i_makp, i_loai, i_phieu, s_makho, s_madt, s_manguon, nguoilinh.Text, dtdt, bDoituong_phieulinh, (xuatcstt.Checked)?false:(i_loai == 2)?true:bBuhaophi);
            }
            if (bDoituong_phieulinh)
            {
                tenfile = (ttb.bPhieulinh_dongia(i_nhom))?"ttb_phieulanh_yc_dt_dg":"ttb_phieulanh_yc_dt";
                tenfile = (ttb.Mabv_so == 701424)?"ttb_phieulanh_dt_dg":tenfile;
            }
            else if (bInngang)
            {
                tenfile = "ttb_phieulanh_ng";
            }
            else
            {
                tenfile  = (ttb.bSLYeucau(i_nhom))?"ttb_phieulanh_yc":"ttb_phieulanh";
                tenfile += (ttb.bPhieulinh_dongia(i_nhom))?"_dg":"";
            }
            if (xem.Checked)
            {
                frmReport f = new frmReport(ttb, dsxml.Tables[0], tenfile + ".rpt", makp.Text, tieude, (tu.Text == den.Text)?"Ngày " + tu.Text:"Từ ngày " + tu.Text + " đến " + den.Text, phieu.Text, s_tendt, s_tenkho, s_tennguon, s_mmyy, "", "");
                f.ShowDialog(this);
            }
            else
            {
                prn.Printer(ttb, dsxml, tenfile + ".rpt", makp.Text, tieude, (tu.Text == den.Text)?"Ngày " + tu.Text:"Từ ngày " + tu.Text + " đến " + den.Text, phieu.Text, s_tendt, s_tenkho, s_tennguon, s_mmyy, "", "", (bInngang || bDoituong_phieulinh)?2:1, Convert.ToInt16(banin.Value));
                MessageBox.Show("Đang in " + tieude, "In phiếu", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            if (s_doc != "")
            {
                dsxml = ttb.get_slxuat_doc(dsxml, tu.Text, den.Text, s_mmyy, i_nhom, i_loai, i_phieu, i_makp, s_madt, s_makho, s_manguon, bBuhaophi, s_doc, bNhomin_mabd, nguoilinh.Text, "", null);
                if (dsxml.Tables[0].Rows.Count <= 0)
                {
                    return;
                }
                tenfile = "ttb_pldoc.rpt";
                if (xem.Checked)
                {
                    frmReport f = new frmReport(ttb, dsxml.Tables[0], tenfile, makp.Text, tieude, (tu.Text == den.Text)?"Ngày " + tu.Text:"Từ ngày " + tu.Text + " đến " + den.Text, phieu.Text, s_tendt, s_tenkho, s_tennguon, s_mmyy, "", "");
                    f.ShowDialog(this);
                }
                else
                {
                    prn.Printer(ttb, dsxml, tenfile, makp.Text, tieude, (tu.Text == den.Text)?"Ngày " + tu.Text:"Từ ngày " + tu.Text + " đến " + den.Text, phieu.Text, s_tendt, s_tenkho, s_tennguon, s_mmyy, "", "", 1, Convert.ToInt16(banin.Value));
                    MessageBox.Show("Đang in " + tieude, "In phiếu", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }