using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;

using System.Data;

using System.IO;
using System.Windows.Forms;

using System.Text;
using ABC.File;

namespace ABC.Report
{
    public partial class T_Tien1_Sot : DevExpress.XtraReports.UI.XtraReport
    {
        public T_Tien1_Sot()
        {
            InitializeComponent();
            lbngay.Text = Get_CauHinh.sono1_sot;
            Detail.SortFields.Add(new GroupField("Tbl_KhachHang_Name", XRColumnSortOrder.Ascending));
            #region
            DataView dtv = new DataView(Get_CauHinh.RE);
            dtv.RowFilter = "STT = 17";
            txtten.Text = dtv[0]["TIEUDE"].ToString();
            txtdienthoai.Text = dtv[0]["DT"].ToString();
            txtdiachi.Text = dtv[0]["DC"].ToString();
            #endregion
        }

        private void T_Tien_AfterPrint(object sender, EventArgs e)
        {
            pdf();
        }
        public void pdf()
        {
            #region
            // export pdf3
            string ten_file_pdf = "SO THU TIEN (BAN 1)";
            string thumuc = Get_CauHinh.Dt_DAT.Rows[0]["Fordel_pdf2"].ToString();
            if (!Directory.Exists(thumuc))
            {
                msgbox.dialog_OK_warning("Không tìm thấy thư mục " + thumuc + " \n Vui lòng kiểm tra lại");

            }
            else
            {
                string thumucmoi = thumuc + @"\" + Get_CauHinh.ngay_text.Replace(@"\", "_").Replace("-", "_").Replace("/", "_");
               // string thumucmoi = thumuc + @"\" + "Ngay " + T_Remember_sys.Ngay_DN.Day.ToString() + "_" + T_Remember_sys.Ngay_DN.Month.ToString() + "_" + T_Remember_sys.Ngay_DN.Year.ToString();
                check_va_taothumuc(thumucmoi);
                var reportPath = string.Concat(thumucmoi, @"\" + ten_file_pdf, ".pdf");
                var stream = new MemoryStream();
                this.ExportToPdf(stream);

                using (var fs = System.IO.File.Create(reportPath))
                {
                    stream.WriteTo(fs);
                }

                var reportStream = System.IO.File.OpenRead(reportPath);
                // return File(reportStream, "application/pdf", "report.pdf");
            }
   

            #endregion

        }
        public void check_va_taothumuc(string pa)
        {
            string path = pa;
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);

            }
            else
            {

            }
        }
        public void luuduongdan(string pa)
        {
            taofile(pa);
        }
        public void taofile(string noidung)
        {
            string filename_root = Path.GetDirectoryName(Application.ExecutablePath);
            string file_opent = filename_root + "\\Source\\CN\\PRE.dll";
            FileStream fs = new FileStream(file_opent, FileMode.Create);
            StreamWriter w = new StreamWriter(fs, Encoding.UTF8);
            w.WriteLine("" + noidung + "");
            w.Flush();
            w.Close();
            fs.Close();
        }

    }
}
