예제 #1
0
 public void ExportRportData(DoSoEmail email, XtraReport report)
 {
     if (email.ExportFileFormat == ReportExportFileFormatEnum.HTML)
     {
         report.ExportToHtml(Path.Combine(email.FolderPath, "HtmlContent"));
     }
     if (email.ExportFileFormat == ReportExportFileFormatEnum.PDF)
     {
         var filePath = Path.Combine(email.FolderPath, HS.MyTempName + ".Pdf");
         report.ExportToPdf(filePath);
         email.SourceFilePath += filePath + ";";
     }
     if (email.ExportFileFormat == ReportExportFileFormatEnum.Xlsx)
     {
         var filePath = Path.Combine(email.FolderPath, HS.MyTempName + ".Xlsx");
         report.ExportToXlsx(filePath);
         email.SourceFilePath += filePath + ";";
     }
 }
        private void exportFileHtml(XtraReport report)
        {
            string         reportPath = "";
            SaveFileDialog sf         = new SaveFileDialog();

            sf.FileName = "Save Here.html";
            if (sf.ShowDialog() == DialogResult.OK)
            {
                reportPath = Path.GetDirectoryName(sf.FileName) + sf.FileName;
                try
                {
                    report.ExportToHtml(sf.FileName);
                    MessageBox.Show("Lưu thành công!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
예제 #3
0
        private void sendEMail(rptInfo rpti, string Caption, XtraReport xr, string eMails, string eMailSubject, string eMailBody)
        {
            try
            {
                MainDataSet.SMTPRow SMTP = Program.MF.SMTP();

                MemoryStream mem = new MemoryStream();
                xr.ExportToHtml(mem);

                // Create a new attachment and put the PDF report into it.
                mem.Seek(0, System.IO.SeekOrigin.Begin);
                var aaa = Encoding.UTF8.GetString(mem.ToArray());

                // Create a new message and attach the PDF report to it.
                MailMessage mail = new MailMessage();
                //mail.Attachments.Add(att);

                mail.To.Add(eMails);
                mail.Subject    = string.Format("{0} {1}{2}", eMailSubject, rpti.refTO, rpti.refID);
                mail.Body       = aaa; // eMailBody;
                mail.IsBodyHtml = true;

                mail.From = new MailAddress(SMTP.MAIL_FROM_ADDRESS, SMTP.MAIL_FROM_DISPLAY_NAME);
                SmtpClient smtp = new SmtpClient(SMTP.CLIENT_HOST);
                smtp.Credentials = new System.Net.NetworkCredential(SMTP.CREDENTIALS_USER_NAME, SMTP.CREDENTIALS_USER_PASSWORD);
                smtp.EnableSsl   = SMTP.ENABLE_SSL == "T" ? true : false;
                smtp.Port        = SMTP.PORT;

                smtp.Send(mail);
                mem.Close();    // Close the memory stream.

                Program.MF.reportDone(rpti, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Error sending eMail.\n" + ex.ToString());
            }
        }
예제 #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string Type=Request.Form.Get("type");

        //Section "Восстановить у пользователя"
        if (Type == DOWNLOAD_FILE_RECOVER_USER)
        {
            if (Request.Form.Get("dataBlockId") != null)
            {
                int dataBlockId = Convert.ToInt32(Request.Form.Get("dataBlockId"));
                string connectionString = ConfigurationManager.AppSettings["fleetnetbaseConnectionString"];
                DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]);
                dataBlock.OpenConnection();
                byte[] fileBytes = dataBlock.GetDataBlock_BytesArray(dataBlockId);
                string fileName = dataBlock.GetDataBlock_FileName(dataBlockId);
                dataBlock.CloseConnection();

                Response.Clear();
                Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", fileName));
                Response.AddHeader("Content-Length", fileBytes.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.OutputStream.Write(fileBytes, 0, fileBytes.Length);
                Response.End();
                return;
            }
        }

        //Section "PLF Файлы"
        if (Type == GET_PLF_REPORT)
        {
            string CardID=Request.Form.Get("CardID");
            string PLFID=Request.Form.Get("PLFID");
            string UserName = Request.Form.Get("UserName");
            string Format = Request.Form.Get("Format");
            string ReportType = Request.Form.Get("ReportType");
            if (string.IsNullOrEmpty(ReportType))
            {
                ReportType = "Полный отчет";
            }

            int dataBlockId = int.Parse(PLFID);
            List<int> dataBlockIDS = new List<int>();
            dataBlockIDS.Add(dataBlockId);
            int cardID = int.Parse(CardID);

            string connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"];
            BLL.DataBlock dataBlock = new BLL.DataBlock(connectionString, ConfigurationManager.AppSettings["language"]);
            dataBlock.OpenConnection();

            DateTime from = new DateTime();
            from = dataBlock.plfUnitInfo.Get_START_PERIOD(dataBlockId);

            DateTime to = new DateTime();
            to = dataBlock.plfUnitInfo.Get_END_PERIOD(dataBlockId);

            string vehicle = dataBlock.plfUnitInfo.Get_VEHICLE(dataBlockId);
            string deviceID = dataBlock.plfUnitInfo.Get_ID_DEVICE(dataBlockId);

            DataSet dataset = new DataSet();

            int userId = dataBlock.usersTable.Get_UserID_byName(UserName);

            List<PLFUnit.PLFRecord> records = new List<PLFUnit.PLFRecord>();
            dataset = ReportDataSetLoader.Get_PLF_ALLData(dataBlockIDS,
                new DateTime(from.Year, from.Month, from.Day), new DateTime(to.Year, to.Month, to.Day),
                cardID, userId, ref records);

            dataBlock.CloseConnection();

            //gets table PlfHeader_1
            DataTable dt = dataset.Tables[0];
            //gets the first row
            DataRow dr = dt.Rows[0];
            string driverName = dr["Имя водителя"].ToString();

            //load needed template
            string path = HttpContext.Current.Server.MapPath("~/templates_plf") + "\\";
            XtraReport report = new XtraReport();
            report.LoadLayout(path + ReportType+".repx");
            report.DataSource = dataset;
            MemoryStream reportStream = new MemoryStream();
            switch (Format)
            {
                case "html": report.ExportToHtml(reportStream); break;
                case "pdf": report.ExportToPdf(reportStream); break;
                case "rtf": report.ExportToRtf(reportStream); break;
                case "png": report.ExportToImage(reportStream,ImageFormat.Png); break;
            }

            Response.Clear();
            Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", "Отчет " + driverName + " " +
                new DateTime(from.Year, from.Month, from.Day).ToString("dd_MM_yyyy") + "-" + new DateTime(to.Year, to.Month, to.Day).ToString("dd_MM_yyyy") + "." + Format));
            Response.AddHeader("Content-Length", reportStream.GetBuffer().Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.OutputStream.Write(reportStream.GetBuffer(), 0, reportStream.GetBuffer().Length);
            Response.End();
            return;
        }

        if (Type == GET_PLF_REPORT_FOR_PERIOD)
        {
            string CardID = Request.Form.Get("CardID");
            string StartDate = Request.Form.Get("StartDate");
            string EndDate = Request.Form.Get("EndDate");
            string UserName = Request.Form.Get("UserName");
            string Format = Request.Form.Get("Format");
            string ReportType = Request.Form.Get("ReportType");
            if (string.IsNullOrEmpty(ReportType))
            {
                ReportType = "Полный отчет";
            }

            int cardID = int.Parse(CardID);

            string connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"];
            BLL.DataBlock dataBlock = new BLL.DataBlock(connectionString, ConfigurationManager.AppSettings["language"]);
            dataBlock.OpenConnection();

            DateTime from = DateTime.Parse(StartDate);
            DateTime to = DateTime.Parse(EndDate);

            DataSet dataset = new DataSet();
            List<int> dataBlockIDS = dataBlock.cardsTable.GetAllDataBlockIds_byCardId(cardID);

            int userId = dataBlock.usersTable.Get_UserID_byName(UserName);

            List<PLFUnit.PLFRecord> records = new List<PLFUnit.PLFRecord>();
            dataset = ReportDataSetLoader.Get_PLF_ALLData(dataBlockIDS,
                new DateTime(from.Year, from.Month, from.Day), new DateTime(to.Year, to.Month, to.Day),
                cardID, userId, ref records);

            dataBlock.CloseConnection();

            //gets table PlfHeader_1
            DataTable dt = dataset.Tables[0];
            //gets the first row
            DataRow dr = dt.Rows[0];
            string driverName = dr["Имя водителя"].ToString();

            //load needed template
            string path = HttpContext.Current.Server.MapPath("~/templates_plf") + "\\";
            XtraReport report = new XtraReport();
            report.LoadLayout(path + ReportType + ".repx");
            report.DataSource = dataset;
            MemoryStream reportStream = new MemoryStream();
            switch (Format)
            {
                case "html": report.ExportToHtml(reportStream); break;
                case "pdf": report.ExportToPdf(reportStream); break;
                case "rtf": report.ExportToRtf(reportStream); break;
                case "png": report.ExportToImage(reportStream, ImageFormat.Png); break;
            }

            Response.Clear();
            Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", "Отчет " + driverName + " " +
                new DateTime(from.Year, from.Month, from.Day).ToString("dd_MM_yyyy") + "-" + new DateTime(to.Year, to.Month, to.Day).ToString("dd_MM_yyyy") + "." + Format));
            Response.AddHeader("Content-Length", reportStream.GetBuffer().Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.OutputStream.Write(reportStream.GetBuffer(), 0, reportStream.GetBuffer().Length);
            Response.End();

            return;
        }

        //Section "Транспортные средства"
        if (Type == GET_DDD_REPORT)
        {
            string DataBlockID = Request.Form.Get("DataBlockID");
            string UserName = Request.Form.Get("UserName");
            string Format = Request.Form.Get("Format");
            string ReportType = Request.Form.Get("ReportType");
            if (string.IsNullOrEmpty(ReportType))
            {
                ReportType = "Полный отчет";
            }

            int dataBlockId = int.Parse(DataBlockID);
            List<int> dataBlockIDS = new List<int>();
            dataBlockIDS.Add(dataBlockId);

            string connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"];
            DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]);
            dataBlock.OpenConnection();

            DataSet dataset = new DataSet();

            string VIN = dataBlock.vehicleUnitInfo.Get_VehicleOverview_IdentificationNumber(dataBlockId).ToString();
            string RegNumb = dataBlock.vehicleUnitInfo.Get_VehicleOverview_RegistrationIdentification(dataBlockId).vehicleRegistrationNumber.ToString();
            int vehicleId = dataBlock.vehiclesTables.GetVehicleId_byVinRegNumbers(VIN, RegNumb);

            List<DateTime> vehsCardPeriod = dataBlock.vehicleUnitInfo.Get_StartEndPeriod(dataBlockId);

            int userId = dataBlock.usersTable.Get_UserID_byName(UserName);

            dataset = ReportDataSetLoader.Get_Vehicle_ALLDate(vehicleId,
                dataBlockIDS, vehsCardPeriod[0], vehsCardPeriod[1], userId);

            dataBlock.CloseConnection();

            //load needed template
            string path = HttpContext.Current.Server.MapPath("~/templates_ddd") + "\\";
            XtraReport report = new XtraReport();
            report.LoadLayout(path + ReportType + ".repx");
            report.DataSource = dataset;
            MemoryStream reportStream = new MemoryStream();
            switch (Format)
            {
                case "html": report.ExportToHtml(reportStream); break;
                case "pdf": report.ExportToPdf(reportStream); break;
                case "rtf": report.ExportToRtf(reportStream); break;
                case "png": report.ExportToImage(reportStream, ImageFormat.Png); break;
            }

            Response.Clear();
            Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", "Отчет " + VIN + "_" + RegNumb + " " +
                vehsCardPeriod[0].ToString("dd_MM_yyyy") + "-" + vehsCardPeriod[1].ToString("dd_MM_yyyy") + "." + Format));
            Response.AddHeader("Content-Length", reportStream.GetBuffer().Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.OutputStream.Write(reportStream.GetBuffer(), 0, reportStream.GetBuffer().Length);
            Response.End();
            return;
        }

        //Section "Транспортные средства"
        if (Type == GET_DDD_REPORT_FOR_PERIOD)
        {
            string CardID = Request.Form.Get("CardID");
            string StartDate = Request.Form.Get("StartDate");
            string EndDate = Request.Form.Get("EndDate");
            string UserName = Request.Form.Get("UserName");
            string Format = Request.Form.Get("Format");
            string ReportType = Request.Form.Get("ReportType");
            if (string.IsNullOrEmpty(ReportType))
            {
                ReportType = "Полный отчет";
            }

            string connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"];
            DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]);
            dataBlock.OpenConnection();

            DataSet dataset = new DataSet();
            int cardId = int.Parse(CardID);

            string VIN = dataBlock.vehiclesTables.GetVehicleVin(cardId);
            string RegNumb = dataBlock.vehiclesTables.GetVehicleGOSNUM(cardId);

            int vehicleId = dataBlock.vehiclesTables.GetVehicle_byCardId(cardId);
            List<int> dataBlockIDS = dataBlock.cardsTable.GetAllDataBlockIds_byCardId(cardId);

            int userId = dataBlock.usersTable.Get_UserID_byName(UserName);

            DateTime from = DateTime.Parse(StartDate);
            DateTime to = DateTime.Parse(EndDate);

            dataset = ReportDataSetLoader.Get_Vehicle_ALLDate(vehicleId,
                dataBlockIDS, from, to, userId);

            dataBlock.CloseConnection();

            //load needed template
            string path = HttpContext.Current.Server.MapPath("~/templates_ddd") + "\\";
            XtraReport report = new XtraReport();
            report.LoadLayout(path + ReportType + ".repx");
            report.DataSource = dataset;
            MemoryStream reportStream = new MemoryStream();
            switch (Format)
            {
                case "html": report.ExportToHtml(reportStream); break;
                case "pdf": report.ExportToPdf(reportStream); break;
                case "rtf": report.ExportToRtf(reportStream); break;
                case "png": report.ExportToImage(reportStream, ImageFormat.Png); break;
            }

            Response.Clear();
            Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", "Отчет " + VIN + "_" + RegNumb + " " +
                from.ToString("dd_MM_yyyy") + "-" + to.ToString("dd_MM_yyyy") + "." + Format));
            Response.AddHeader("Content-Length", reportStream.GetBuffer().Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.OutputStream.Write(reportStream.GetBuffer(), 0, reportStream.GetBuffer().Length);
            Response.End();
            return;
        }
    }
예제 #5
0
        public static void MailReportAsBodyTask(rptInfo rpti, string Caption, XtraReport xr, string eMails, string eMailSubject, string eMailBody)
        {
            MainDataSet.SMTPRow SMTP = Program.MF.SMTP();

            alertControl1.FormLoad         += alertControl1_FormLoad;
            alertControl1.BeforeFormShow   += alertControl1_BeforeFormShow;
            alertControl1.FormLocation      = DevExpress.XtraBars.Alerter.AlertFormLocation.BottomRight;
            alertControl1.FormShowingEffect = DevExpress.XtraBars.Alerter.AlertFormShowingEffect.MoveHorizontal;
            alertControl1.AutoFormDelay     = 10000;
            alertControl1.AutoHeight        = true;
            System.Drawing.Bitmap img = Resources.mailForward64;  //Resources.ResourceManager.GetObject("mailForward64"); //Bu da OK

            Task <string> .Factory.StartNew(() =>
            {
                // Background work
                try
                {
                    MemoryStream mem = new MemoryStream();
                    xr.ExportToHtml(mem);

                    mem.Seek(0, System.IO.SeekOrigin.Begin);
                    var aaa = Encoding.UTF8.GetString(mem.ToArray());

                    //System.Net.Mail.Attachment att = new System.Net.Mail.Attachment(mem, Caption + ".pdf", "application/pdf");

                    MailMessage mail = new MailMessage();
                    mail.To.Add(eMails);
                    mail.Subject    = string.Format("{0} {1}{2}", eMailSubject, rpti.refTO, rpti.refID);
                    mail.Body       = aaa; // eMailBody;
                    mail.IsBodyHtml = true;
                    mail.From       = new MailAddress(SMTP.MAIL_FROM_ADDRESS, SMTP.MAIL_FROM_DISPLAY_NAME);

                    SmtpClient smtp  = new SmtpClient(SMTP.CLIENT_HOST);
                    smtp.Credentials = new System.Net.NetworkCredential(SMTP.CREDENTIALS_USER_NAME, SMTP.CREDENTIALS_USER_PASSWORD);
                    smtp.EnableSsl   = SMTP.ENABLE_SSL == "T" ? true : false;
                    smtp.Port        = SMTP.PORT;

                    smtp.Send(mail);
                    mem.Close();    // Close the memory stream.

                    return("");
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            }).ContinueWith((t) =>
            {
                // Update UI thread
                //alertControl1.FormLocation = DevExpress.XtraBars.Alerter.AlertFormLocation.B;

                if (string.IsNullOrEmpty(t.Result))
                {
                    alertControl1.Show(null, Caption, eMails.Replace(",", "\n"), img);
                    Program.MF.reportDone(rpti, false);
                }
                else
                {
                    alertControl1.Show(null, Caption, t.Result, img);
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
예제 #6
0
    public static String GetDDDReport(String DataBlockID, String UserName, String ReportType)
    {
        int dataBlockId = int.Parse(DataBlockID);
        List<int> dataBlockIDS = new List<int>();
        dataBlockIDS.Add(dataBlockId);

        string connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"];
        DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]);
        dataBlock.OpenConnection();

        DataSet dataset = new DataSet();

        string VIN = dataBlock.vehicleUnitInfo.Get_VehicleOverview_IdentificationNumber(dataBlockId).ToString();
        string RegNumb = dataBlock.vehicleUnitInfo.Get_VehicleOverview_RegistrationIdentification(dataBlockId).vehicleRegistrationNumber.ToString();
        int vehicleId = dataBlock.vehiclesTables.GetVehicleId_byVinRegNumbers(VIN, RegNumb);

        List<DateTime> vehsCardPeriod = dataBlock.vehicleUnitInfo.Get_StartEndPeriod(dataBlockId);

        int userId = dataBlock.usersTable.Get_UserID_byName(UserName);

        dataset = ReportDataSetLoader.Get_Vehicle_ALLDate(vehicleId,
            dataBlockIDS, vehsCardPeriod[0], vehsCardPeriod[1], userId);

        dataBlock.CloseConnection();

        //load needed template
        string path = HttpContext.Current.Server.MapPath("~/templates_ddd") + "\\";
        XtraReport report = new XtraReport();
        if (string.IsNullOrEmpty(ReportType))
        {
            ReportType = "Полный отчет";
        }
        report.LoadLayout(path + ReportType + ".repx");
        report.DataSource = dataset;
        MemoryStream reportStream = new MemoryStream();
        report.ExportToHtml(reportStream);
        reportStream.Seek(0, SeekOrigin.Begin);

        // convert stream to string
        StreamReader reader = new StreamReader(reportStream);
        string textReport = reader.ReadToEnd();

        return textReport;
    }
예제 #7
0
    public static Report GetPLFReportForPeriod(String CardID, String StartDate, String EndDate, String UserName, String ReportType)
    {
        int cardID = int.Parse(CardID);

        string connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"];
        BLL.DataBlock dataBlock = new BLL.DataBlock(connectionString, ConfigurationManager.AppSettings["language"]);
        dataBlock.OpenConnection();

        DateTime from = DateTime.Parse(StartDate);
        DateTime to = DateTime.Parse(EndDate);

        DataSet dataset = new DataSet();
        List<int> dataBlockIDS = dataBlock.cardsTable.GetAllDataBlockIds_byCardId(cardID);

        int userId = dataBlock.usersTable.Get_UserID_byName(UserName);

        List<PLFUnit.PLFRecord> records = new List<PLFUnit.PLFRecord>();
        dataset = ReportDataSetLoader.Get_PLF_ALLData(dataBlockIDS,
            new DateTime(from.Year, from.Month, from.Day), new DateTime(to.Year, to.Month, to.Day),
            cardID, userId, ref records);

        //if (dataset == null) {
            //return null;
        //}

        dataBlock.CloseConnection();

        //load needed template
        string path = HttpContext.Current.Server.MapPath("~/templates_plf") + "\\";
        XtraReport report = new XtraReport();
        if (string.IsNullOrEmpty(ReportType))
        {
            ReportType = "Полный отчет";
        }
        report.LoadLayout(path + ReportType + ".repx");
        report.DataSource = dataset;
        MemoryStream reportStream = new MemoryStream();
        report.ExportToHtml(reportStream);
        reportStream.Seek(0, SeekOrigin.Begin);

        // convert stream to string
        StreamReader reader = new StreamReader(reportStream);
        string textReport = reader.ReadToEnd();

        Report r = new Report();
        r.report = textReport;
        r.time = new double[records.Count];
        r.speed = new double[records.Count];
        r.voltage = new double[records.Count];
        r.rpm = new double[records.Count];
        r.fuel = new double[records.Count];
        List<double> lats = new List<double>();
        List<double> lngs = new List<double>();

        for (int i = 0; i < records.Count; i++)
        {
            double t = (records[i].SYSTEM_TIME.GetSystemTime() - new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds;
            r.time[i] = t;
            r.speed[i] = double.Parse(records[i].SPEED, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo);
            r.voltage[i] = double.Parse(records[i].VOLTAGE, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo);
            r.rpm[i] = double.Parse(records[i].ENGINE_RPM, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo);
            r.fuel[i] = Math.Round(double.Parse(records[i].FUEL_VOLUME1), 1);
            if (records[i].LATITUDE != null && records[i].LONGITUDE != null)
            {
                lats.Add(double.Parse(records[i].LATITUDE, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo));
                lngs.Add(double.Parse(records[i].LONGITUDE, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo));
            }
        }

        r.lat = new double[lats.Count];
        r.lng = new double[lats.Count];

        for (int i = 0; i < lats.Count; i++) {
            r.lat[i] = lats[i];
            r.lng[i] = lngs[i];
        }

        r.period = new DateTime(from.Year, from.Month, from.Day).ToShortDateString() + " - " + new DateTime(to.Year, to.Month, to.Day).ToShortDateString();

        return r;
    }
예제 #8
0
    public static String GetDDDReportForPeriod(String CardID, String StartDate, String EndDate, String UserName, String ReportType)
    {
        int cardId = Int16.Parse(CardID);

        string connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"];
        DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]);
        dataBlock.OpenConnection();

        DataSet dataset = new DataSet();

        int vehicleId = dataBlock.vehiclesTables.GetVehicle_byCardId(cardId);
        List<int> dataBlockIDS = dataBlock.cardsTable.GetAllDataBlockIds_byCardId(cardId);

        int userId = dataBlock.usersTable.Get_UserID_byName(UserName);

        DateTime from = DateTime.Parse(StartDate);
        DateTime to = DateTime.Parse(EndDate);

        dataset = ReportDataSetLoader.Get_Vehicle_ALLDate(vehicleId,
            dataBlockIDS, from, to, userId);

        dataBlock.CloseConnection();

        //load needed template
        string path = HttpContext.Current.Server.MapPath("~/templates_ddd") + "\\";
        XtraReport report = new XtraReport();
        if (string.IsNullOrEmpty(ReportType))
        {
            ReportType = "Полный отчет";
        }
        report.LoadLayout(path + ReportType + ".repx");
        report.DataSource = dataset;
        MemoryStream reportStream = new MemoryStream();
        report.ExportToHtml(reportStream);
        reportStream.Seek(0, SeekOrigin.Begin);

        // convert stream to string
        StreamReader reader = new StreamReader(reportStream);
        string textReport = reader.ReadToEnd();

        return textReport;
    }
예제 #9
0
 public static void ExportToMemory(this XtraReport report)
 {
     report.ExportToHtml(new MemoryStream());
 }
예제 #10
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string Type = Request.Form.Get("type");

        //Section "Восстановить у пользователя"
        if (Type == DOWNLOAD_FILE_RECOVER_USER)
        {
            if (Request.Form.Get("dataBlockId") != null)
            {
                int       dataBlockId      = Convert.ToInt32(Request.Form.Get("dataBlockId"));
                string    connectionString = ConfigurationManager.AppSettings["fleetnetbaseConnectionString"];
                DataBlock dataBlock        = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]);
                dataBlock.OpenConnection();
                byte[] fileBytes = dataBlock.GetDataBlock_BytesArray(dataBlockId);
                string fileName  = dataBlock.GetDataBlock_FileName(dataBlockId);
                dataBlock.CloseConnection();

                Response.Clear();
                Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", fileName));
                Response.AddHeader("Content-Length", fileBytes.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.OutputStream.Write(fileBytes, 0, fileBytes.Length);
                Response.End();
                return;
            }
        }

        //Section "PLF Файлы"
        if (Type == GET_PLF_REPORT)
        {
            string CardID     = Request.Form.Get("CardID");
            string PLFID      = Request.Form.Get("PLFID");
            string UserName   = Request.Form.Get("UserName");
            string Format     = Request.Form.Get("Format");
            string ReportType = Request.Form.Get("ReportType");
            if (string.IsNullOrEmpty(ReportType))
            {
                ReportType = "Полный отчет";
            }

            int        dataBlockId  = int.Parse(PLFID);
            List <int> dataBlockIDS = new List <int>();
            dataBlockIDS.Add(dataBlockId);
            int cardID = int.Parse(CardID);

            string        connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"];
            BLL.DataBlock dataBlock        = new BLL.DataBlock(connectionString, ConfigurationManager.AppSettings["language"]);
            dataBlock.OpenConnection();

            DateTime from = new DateTime();
            from = dataBlock.plfUnitInfo.Get_START_PERIOD(dataBlockId);

            DateTime to = new DateTime();
            to = dataBlock.plfUnitInfo.Get_END_PERIOD(dataBlockId);

            string vehicle  = dataBlock.plfUnitInfo.Get_VEHICLE(dataBlockId);
            string deviceID = dataBlock.plfUnitInfo.Get_ID_DEVICE(dataBlockId);

            DataSet dataset = new DataSet();

            int userId = dataBlock.usersTable.Get_UserID_byName(UserName);

            List <PLFUnit.PLFRecord> records = new List <PLFUnit.PLFRecord>();
            dataset = ReportDataSetLoader.Get_PLF_ALLData(dataBlockIDS,
                                                          new DateTime(from.Year, from.Month, from.Day), new DateTime(to.Year, to.Month, to.Day),
                                                          cardID, userId, ref records);

            dataBlock.CloseConnection();

            //gets table PlfHeader_1
            DataTable dt = dataset.Tables[0];
            //gets the first row
            DataRow dr         = dt.Rows[0];
            string  driverName = dr["Имя водителя"].ToString();

            //load needed template
            string     path   = HttpContext.Current.Server.MapPath("~/templates_plf") + "\\";
            XtraReport report = new XtraReport();
            report.LoadLayout(path + ReportType + ".repx");
            report.DataSource = dataset;
            MemoryStream reportStream = new MemoryStream();
            switch (Format)
            {
            case "html": report.ExportToHtml(reportStream); break;

            case "pdf": report.ExportToPdf(reportStream); break;

            case "rtf": report.ExportToRtf(reportStream); break;

            case "png": report.ExportToImage(reportStream, ImageFormat.Png); break;
            }

            Response.Clear();
            Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", "Отчет " + driverName + " " +
                                                                    new DateTime(from.Year, from.Month, from.Day).ToString("dd_MM_yyyy") + "-" + new DateTime(to.Year, to.Month, to.Day).ToString("dd_MM_yyyy") + "." + Format));
            Response.AddHeader("Content-Length", reportStream.GetBuffer().Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.OutputStream.Write(reportStream.GetBuffer(), 0, reportStream.GetBuffer().Length);
            Response.End();
            return;
        }

        if (Type == GET_PLF_REPORT_FOR_PERIOD)
        {
            string CardID     = Request.Form.Get("CardID");
            string StartDate  = Request.Form.Get("StartDate");
            string EndDate    = Request.Form.Get("EndDate");
            string UserName   = Request.Form.Get("UserName");
            string Format     = Request.Form.Get("Format");
            string ReportType = Request.Form.Get("ReportType");
            if (string.IsNullOrEmpty(ReportType))
            {
                ReportType = "Полный отчет";
            }

            int cardID = int.Parse(CardID);

            string        connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"];
            BLL.DataBlock dataBlock        = new BLL.DataBlock(connectionString, ConfigurationManager.AppSettings["language"]);
            dataBlock.OpenConnection();

            DateTime from = DateTime.Parse(StartDate);
            DateTime to   = DateTime.Parse(EndDate);

            DataSet    dataset      = new DataSet();
            List <int> dataBlockIDS = dataBlock.cardsTable.GetAllDataBlockIds_byCardId(cardID);

            int userId = dataBlock.usersTable.Get_UserID_byName(UserName);

            List <PLFUnit.PLFRecord> records = new List <PLFUnit.PLFRecord>();
            dataset = ReportDataSetLoader.Get_PLF_ALLData(dataBlockIDS,
                                                          new DateTime(from.Year, from.Month, from.Day), new DateTime(to.Year, to.Month, to.Day),
                                                          cardID, userId, ref records);

            dataBlock.CloseConnection();

            //gets table PlfHeader_1
            DataTable dt = dataset.Tables[0];
            //gets the first row
            DataRow dr         = dt.Rows[0];
            string  driverName = dr["Имя водителя"].ToString();

            //load needed template
            string     path   = HttpContext.Current.Server.MapPath("~/templates_plf") + "\\";
            XtraReport report = new XtraReport();
            report.LoadLayout(path + ReportType + ".repx");
            report.DataSource = dataset;
            MemoryStream reportStream = new MemoryStream();
            switch (Format)
            {
            case "html": report.ExportToHtml(reportStream); break;

            case "pdf": report.ExportToPdf(reportStream); break;

            case "rtf": report.ExportToRtf(reportStream); break;

            case "png": report.ExportToImage(reportStream, ImageFormat.Png); break;
            }


            Response.Clear();
            Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", "Отчет " + driverName + " " +
                                                                    new DateTime(from.Year, from.Month, from.Day).ToString("dd_MM_yyyy") + "-" + new DateTime(to.Year, to.Month, to.Day).ToString("dd_MM_yyyy") + "." + Format));
            Response.AddHeader("Content-Length", reportStream.GetBuffer().Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.OutputStream.Write(reportStream.GetBuffer(), 0, reportStream.GetBuffer().Length);
            Response.End();

            return;
        }

        //Section "Транспортные средства"
        if (Type == GET_DDD_REPORT)
        {
            string DataBlockID = Request.Form.Get("DataBlockID");
            string UserName    = Request.Form.Get("UserName");
            string Format      = Request.Form.Get("Format");
            string ReportType  = Request.Form.Get("ReportType");
            if (string.IsNullOrEmpty(ReportType))
            {
                ReportType = "Полный отчет";
            }

            int        dataBlockId  = int.Parse(DataBlockID);
            List <int> dataBlockIDS = new List <int>();
            dataBlockIDS.Add(dataBlockId);

            string    connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"];
            DataBlock dataBlock        = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]);
            dataBlock.OpenConnection();

            DataSet dataset = new DataSet();

            string VIN       = dataBlock.vehicleUnitInfo.Get_VehicleOverview_IdentificationNumber(dataBlockId).ToString();
            string RegNumb   = dataBlock.vehicleUnitInfo.Get_VehicleOverview_RegistrationIdentification(dataBlockId).vehicleRegistrationNumber.ToString();
            int    vehicleId = dataBlock.vehiclesTables.GetVehicleId_byVinRegNumbers(VIN, RegNumb);

            List <DateTime> vehsCardPeriod = dataBlock.vehicleUnitInfo.Get_StartEndPeriod(dataBlockId);

            int userId = dataBlock.usersTable.Get_UserID_byName(UserName);

            dataset = ReportDataSetLoader.Get_Vehicle_ALLDate(vehicleId,
                                                              dataBlockIDS, vehsCardPeriod[0], vehsCardPeriod[1], userId);

            dataBlock.CloseConnection();

            //load needed template
            string     path   = HttpContext.Current.Server.MapPath("~/templates_ddd") + "\\";
            XtraReport report = new XtraReport();
            report.LoadLayout(path + ReportType + ".repx");
            report.DataSource = dataset;
            MemoryStream reportStream = new MemoryStream();
            switch (Format)
            {
            case "html": report.ExportToHtml(reportStream); break;

            case "pdf": report.ExportToPdf(reportStream); break;

            case "rtf": report.ExportToRtf(reportStream); break;

            case "png": report.ExportToImage(reportStream, ImageFormat.Png); break;
            }

            Response.Clear();
            Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", "Отчет " + VIN + "_" + RegNumb + " " +
                                                                    vehsCardPeriod[0].ToString("dd_MM_yyyy") + "-" + vehsCardPeriod[1].ToString("dd_MM_yyyy") + "." + Format));
            Response.AddHeader("Content-Length", reportStream.GetBuffer().Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.OutputStream.Write(reportStream.GetBuffer(), 0, reportStream.GetBuffer().Length);
            Response.End();
            return;
        }

        //Section "Транспортные средства"
        if (Type == GET_DDD_REPORT_FOR_PERIOD)
        {
            string CardID     = Request.Form.Get("CardID");
            string StartDate  = Request.Form.Get("StartDate");
            string EndDate    = Request.Form.Get("EndDate");
            string UserName   = Request.Form.Get("UserName");
            string Format     = Request.Form.Get("Format");
            string ReportType = Request.Form.Get("ReportType");
            if (string.IsNullOrEmpty(ReportType))
            {
                ReportType = "Полный отчет";
            }

            string    connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"];
            DataBlock dataBlock        = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]);
            dataBlock.OpenConnection();

            DataSet dataset = new DataSet();
            int     cardId  = int.Parse(CardID);

            string VIN     = dataBlock.vehiclesTables.GetVehicleVin(cardId);
            string RegNumb = dataBlock.vehiclesTables.GetVehicleGOSNUM(cardId);

            int        vehicleId    = dataBlock.vehiclesTables.GetVehicle_byCardId(cardId);
            List <int> dataBlockIDS = dataBlock.cardsTable.GetAllDataBlockIds_byCardId(cardId);

            int userId = dataBlock.usersTable.Get_UserID_byName(UserName);

            DateTime from = DateTime.Parse(StartDate);
            DateTime to   = DateTime.Parse(EndDate);

            dataset = ReportDataSetLoader.Get_Vehicle_ALLDate(vehicleId,
                                                              dataBlockIDS, from, to, userId);

            dataBlock.CloseConnection();

            //load needed template
            string     path   = HttpContext.Current.Server.MapPath("~/templates_ddd") + "\\";
            XtraReport report = new XtraReport();
            report.LoadLayout(path + ReportType + ".repx");
            report.DataSource = dataset;
            MemoryStream reportStream = new MemoryStream();
            switch (Format)
            {
            case "html": report.ExportToHtml(reportStream); break;

            case "pdf": report.ExportToPdf(reportStream); break;

            case "rtf": report.ExportToRtf(reportStream); break;

            case "png": report.ExportToImage(reportStream, ImageFormat.Png); break;
            }

            Response.Clear();
            Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", "Отчет " + VIN + "_" + RegNumb + " " +
                                                                    from.ToString("dd_MM_yyyy") + "-" + to.ToString("dd_MM_yyyy") + "." + Format));
            Response.AddHeader("Content-Length", reportStream.GetBuffer().Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.OutputStream.Write(reportStream.GetBuffer(), 0, reportStream.GetBuffer().Length);
            Response.End();
            return;
        }
    }