/// <summary>
        /// Draws the graphs for each of the devices.
        /// </summary>
        /// <returns>The graphs.</returns>
        /// <param name="file">File.</param>
        /// <param name="dlr">Dlr.</param>
        /// <param name="row">The x coordinate.</param>
        /// <param name="col">The y coordinate.</param>
        private Tuple <int, int> DrawGraphs(XlsFile file, DataLogReport dlr, int row, int col)
        {
            var l = dlr.localization;
            var imageCellWidth  = 8;
            var imageCellHeight = 4;

            var index = 0;

            foreach (var sensor in dlr.dataLogResults.Keys)
            {
                if (!dlr.graphImages.ContainsKey(sensor))
                {
                    Log.E(this, "Failed to export sensor graph");
                    continue;
                }

                int xoff = 0, yoff = 0;

                if (index > 0)
                {
                    xoff = 1;
                    yoff = 1;
                }
                else
                {
                    xoff = col;
                    yoff = row;
                }

                var image = dlr.graphImages[sensor];
                file.MergeCells(yoff, xoff, yoff + imageCellHeight, xoff + imageCellWidth);

                file.SetRowHeight(yoff, (int)(image.height * FlxConsts.RowMult));
                TClientAnchor anchor = new TClientAnchor(TFlxAnchorType.MoveAndDontResize, yoff, 0, xoff, 0, yoff + imageCellHeight, 0, xoff + imageCellWidth, 0);
                double        width = 0.0, height = 0.0;

                anchor.CalcImageCoords(ref height, ref width, file);
                // Width should always be greater than the height.
                anchor = new TClientAnchor(TFlxAnchorType.MoveAndDontResize, yoff, 0, xoff, 0, (int)height, (int)width, file);


                var imageProperties = new TImageProperties();
                imageProperties.Anchor = anchor;
                file.AddImage(image.data, TXlsImgType.Png, imageProperties);
                index++;
                file.ActiveSheet++;
            }

            return(new Tuple <int, int>(imageCellWidth, index * (imageCellHeight + 1)));
        }
 /// <summary>
 /// Attempts to draw the Appion logo into the upper left of the file on the current sheet.
 /// </summary>
 /// <param name="file">File.</param>
 /// <returns>A Tuple containing the width and height respectively of the drawn section.</returns>
 private Tuple <int, int> DrawAppionLogo(XlsFile file, DataLogReport dlr)
 {
     if (dlr.appionLogoPng != null)
     {
         // Add the image
         var image = new TImageProperties();
         image.Anchor    = new TClientAnchor(TFlxAnchorType.MoveAndDontResize, 1, 0, 1, 0, 5, 255, 3, 1024);
         image.ShapeName = "Logo";
         file.AddImage(dlr.appionLogoPng.data, image);
         // Add the header
         file.MergeCells(4, 4, 5, 6);
         file.SetCellValue(4, 4, dlr.reportName, titleFormat);
         return(new Tuple <int, int>(6, 4));
     }
     else
     {
         Log.E(this, "Failed to draw appion logo: no bitmap bytes");
         return(new Tuple <int, int>(0, 0));
     }
 }
        /// <summary>
        /// Draws the graphs for each of the devices.
        /// </summary>
        /// <returns>The graphs.</returns>
        /// <param name="file">File.</param>
        /// <param name="dlr">Dlr.</param>
        /// <param name="row">The x coordinate.</param>
        /// <param name="col">The y coordinate.</param>
        private Tuple <int, int> DrawSmallGraphs(XlsFile file, DataLogReport dlr, int row, int col)
        {
            var l = dlr.localization;
            var imageCellWidth  = 4;
            var imageCellHeight = 3;

            var index = 0;

            foreach (var sensor in dlr.dataLogResults.Keys)
            {
                if (!dlr.graphImages.ContainsKey(sensor))
                {
                    Log.E(this, "Failed to export sensor graph");
                    continue;
                }

                int xoff = 0, yoff = 0;
                // The shift that is used to stagger the graphs down the pages.
                xoff = col + (index % 2 == 1 ? imageCellWidth + 1 : 0);
                yoff = (int)(row + (index / 2 * imageCellHeight));

                var image = dlr.graphImages[sensor];
                file.MergeCells(yoff, xoff, yoff + imageCellHeight, xoff + imageCellWidth);

                file.SetRowHeight(yoff, (int)(image.height * FlxConsts.RowMult));
                TClientAnchor anchor = new TClientAnchor(TFlxAnchorType.MoveAndDontResize, yoff, 0, xoff, 0, yoff + imageCellHeight, 0, xoff + imageCellWidth, 0);
                double        width = 0.0, height = 0.0;

                anchor.CalcImageCoords(ref height, ref width, file);
                // Width should always be greater than the height.
                anchor = new TClientAnchor(TFlxAnchorType.MoveAndDontResize, yoff, 0, xoff, 0, (int)height, (int)width, file);


                var imageProperties = new TImageProperties();
                imageProperties.Anchor = anchor;
                file.AddImage(image.data, TXlsImgType.Png, imageProperties);
                index++;
            }

            return(new Tuple <int, int>((imageCellWidth + 1) * 2, (int)Math.Ceiling(index / 2.0) * (imageCellHeight + 1)));
        }
        /// <summary>
        /// Tạo báo cáo
        /// </summary>
        /// <param name="path"></param>
        /// <param name="iID_MaCanBo"></param>
        /// <returns></returns>
        public ExcelFile CreateReport(String path, String iID_MaCanBo)
        {
            XlsFile Result = new XlsFile(true);
            Result.Open(path);
            String KhenThuong = "";
            DataTable dtKhenThuong = NhanSu_KhenThuong(iID_MaCanBo, "0");
            for (int i = 0; i < dtKhenThuong.Rows.Count;i++ )
            {
                KhenThuong += "+" + dtKhenThuong.Rows[i]["CapPhongTang"].ToString() + "," + dtKhenThuong.Rows[i]["HinhThuc"].ToString() + "(" + dtKhenThuong.Rows[i]["iThang"].ToString() + "--" + dtKhenThuong.Rows[i]["iNam"].ToString() + ")," + dtKhenThuong.Rows[i]["sLyDo"].ToString() + ", ";
            }
            String DanhHieu = "";
            DataTable dtDanhHieu = NhanSu_KhenThuong(iID_MaCanBo, "1");
            for (int i = 0; i < dtDanhHieu.Rows.Count; i++)
            {
                DanhHieu += "+" + dtDanhHieu.Rows[i]["CapPhongTang"].ToString() + "," + dtDanhHieu.Rows[i]["HinhThuc"].ToString() + "(" + dtDanhHieu.Rows[i]["iThang"].ToString() + "--" + dtDanhHieu.Rows[i]["iNam"].ToString() + ")," + dtDanhHieu.Rows[i]["sLyDo"].ToString() + ", ";
            }
            String KyLuat = "";
            DataTable dtKyLuat = NhanSu_KyLuat(iID_MaCanBo);
            for (int i = 0; i < dtKyLuat.Rows.Count; i++)
            {
                KyLuat += "+" + dtKyLuat.Rows[i]["CapKyLuat"].ToString() + "," + dtKyLuat.Rows[i]["HinhThuc"].ToString() + "(" + dtKyLuat.Rows[i]["iThang"].ToString() + "--" + dtKyLuat.Rows[i]["iNam"].ToString() + ")," + dtKyLuat.Rows[i]["sLydoDi"].ToString() + ", ";
            }
            if (KyLuat == "")
            {
                KyLuat = "Không";
            }
            String DiNuocNgoai = "";
            DataTable dtNuocNgoai = NhanSu_DiNuocNgoai(iID_MaCanBo);
            for (int i = 0; i < dtNuocNgoai.Rows.Count; i++)
            {
                DiNuocNgoai += "+"+dtNuocNgoai.Rows[i]["dTuNgay"].ToString() + "--" + dtNuocNgoai.Rows[i]["dDenNgay"].ToString() + ":" + dtNuocNgoai.Rows[i]["TenNuoc"].ToString() + "," + dtNuocNgoai.Rows[i]["sLyDoDi"].ToString() + ", ";
            }

            using (FlexCelReport fr = new FlexCelReport())
            {
                String sPathImg =  LoadData(fr, iID_MaCanBo);
                fr.SetValue("KhenThuong", KhenThuong);
                fr.SetValue("DanhHieu", DanhHieu);
                fr.SetValue("KyLuat", KyLuat);
                fr.SetValue("DiNuocNgoai", DiNuocNgoai);
                fr.Run(Result);
                try
                {
                    // lay thong tin anh
                    if (!sPathImg.Equals(""))
                    {
                        int indexPath = sPathImg.LastIndexOf("../");
                        if (indexPath >= 0)
                        {
                            sPathImg = "~" + sPathImg.Substring(indexPath+2);
                        }
                        sPathImg = Server.MapPath(sPathImg);
                        Image imgAnh = GetImage(sPathImg, 118, 133);
                        if (imgAnh != null)
                        {
                            Result.AddImage(1, 10, imgAnh);
                        }
                    }
                }
                catch (Exception)
                {

                }
                return Result;
            }
        }
예제 #5
0
        /// <summary>
        /// Записывает данные страницы на текущий лист XLS-файла.
        /// </summary>
        /// <param name="table">Таблица с данными.</param>
        /// <param name="xlsFile">XLS-файл.</param>
        private static void WriteDataTable(DataTable table, XlsFile xlsFile)
        {
            // установить имя листа
            xlsFile.SheetName = table.TableName;

            // записать названия столбцов
            for (int i = 0; i < table.Columns.Count; ++i)
            {
                // название столбца
                xlsFile.SetCellValue( 1, i + 1, table.Columns[i].ColumnName );
                // .NET-тип данных столбца
                xlsFile.SetCellValue( 2, i + 1, table.Columns[i].DataType.ToString() );
            }
            // скрыть строку с типами данных
            xlsFile.SetRowHidden( 2, true );

            // записать данные таблицы
            int rowFrom = 3;
            for (int row = 0; row < table.Rows.Count; ++row)
            {
                object[] values = table.Rows[row].ItemArray;
                for(int col = 0; col < values.Length; ++col)
                {
                    object val = values[col];
                    if(val != DBNull.Value)
                    {
                        if(table.Columns[col].DataType == typeof( byte[] ))
                        {
                            Image image = Image.FromStream( new MemoryStream( (byte[])ConvertValue( val ) ) );
                            xlsFile.AddImage( row + rowFrom, col + 1, image );
                        }
                        else
                        {
                            xlsFile.SetCellValue( row + rowFrom, col + 1, ConvertValue( val ) );
                        }
                    }
                }
            }
        }