示例#1
0
        public static int Export(DataSet ds)
        {
            ExcelEngine excel = null;
            WordEngine  word  = null;

            try
            {
                if (!ds.Tables.Contains(GiaoXuConst.TableName) || !ds.Tables.Contains(GiaDinhConst.TableName) || !ds.Tables.Contains(ReportChungNhanHPConst.TableName))
                {
                    Memory.Instance.Error = new Exception("Không có dữ liệu làm việc!");
                    return(-1);
                }

                DataTable tblGiaDinh = ds.Tables[GiaDinhConst.TableName];
                DataTable tblGiaoXu  = ds.Tables[GiaoXuConst.TableName];
                DataTable tblReport  = ds.Tables[ReportChungNhanHPConst.TableName];

                if (tblGiaDinh.Rows.Count == 0 || tblGiaoXu.Rows.Count == 0 || tblReport.Rows.Count == 0)
                {
                    return(-1);
                }

                DataRow rowGiaoXu  = tblGiaoXu.Rows[0];
                DataRow rowGiaDinh = tblGiaDinh.Rows[0];
                DataRow rowReport  = tblReport.Rows[0];



                string templatePath = Memory.GetReportTemplatePath(GxConstants.REPORT_CHUNGNHAN_HONPHOI_FILENAME);
                string outputPath   = Memory.GetTempPath(GxConstants.REPORT_CHUNGNHAN_HONPHOI_FILENAME);

                string reportFormat = Memory.GetReportFormat();
                templatePath = string.Concat(templatePath, reportFormat);
                outputPath   = string.Concat(outputPath, reportFormat);

                if (reportFormat == GxConstants.DOC_FORMAT)
                {
                    word = new WordEngine();
                    if (word.CreateObject(outputPath, templatePath))
                    {
                        word.Replace(GiaoPhanConst.TenGiaoPhan, rowGiaoXu[GiaoPhanConst.TenGiaoPhan]);
                        word.Replace(GiaoHatConst.TenGiaoHat, rowGiaoXu[GiaoHatConst.TenGiaoHat]);
                        word.Replace(GiaoXuConst.TenGiaoXu, rowGiaoXu[GiaoXuConst.TenGiaoXu]);

                        word.Replace(ReportChungNhanHPConst.HoTenNam, rowReport[ReportChungNhanHPConst.HoTenNam]);
                        word.Replace(ReportChungNhanHPConst.HoTenNu, rowReport[ReportChungNhanHPConst.HoTenNu]);
                        word.Replace(ReportChungNhanHPConst.NgaySinhNam, rowReport[ReportChungNhanHPConst.NgaySinhNam]);
                        word.Replace(ReportChungNhanHPConst.NgaySinhNu, rowReport[ReportChungNhanHPConst.NgaySinhNu]);
                        word.Replace(ReportChungNhanHPConst.NgayThangNamHP, rowReport[ReportChungNhanHPConst.NgayThangNamHP]);
                        word.Replace(ReportChungNhanHPConst.NoiSinhNam, rowReport[ReportChungNhanHPConst.NoiSinhNam]);
                        word.Replace(ReportChungNhanHPConst.NoiSinhNu, rowReport[ReportChungNhanHPConst.NoiSinhNu]);
                        word.Replace(ReportChungNhanHPConst.TenChaNam, rowReport[ReportChungNhanHPConst.TenChaNam]);
                        word.Replace(ReportChungNhanHPConst.TenChaNu, rowReport[ReportChungNhanHPConst.TenChaNu]);
                        word.Replace(ReportChungNhanHPConst.TenLinhMucGui, rowReport[ReportChungNhanHPConst.TenLinhMucGui]);
                        word.Replace(ReportChungNhanHPConst.TenMeNam, rowReport[ReportChungNhanHPConst.TenMeNam]);
                        word.Replace(ReportChungNhanHPConst.TenMeNu, rowReport[ReportChungNhanHPConst.TenMeNu]);
                        word.Replace(ReportChungNhanHPConst.GiaoXuNam, rowReport[ReportChungNhanHPConst.GiaoXuNam]);
                        word.Replace(ReportChungNhanHPConst.GiaoXuNu, rowReport[ReportChungNhanHPConst.GiaoXuNu]);
                        word.Replace(ReportChungNhanHPConst.NgayRuaToiNam, rowReport[ReportChungNhanHPConst.NgayRuaToiNam]);
                        word.Replace(ReportChungNhanHPConst.SoRuaToiNam, rowReport[ReportChungNhanHPConst.SoRuaToiNam]);
                        word.Replace(ReportChungNhanHPConst.NgayRuaToiNu, rowReport[ReportChungNhanHPConst.NgayRuaToiNu]);
                        word.Replace(ReportChungNhanHPConst.SoRuaToiNu, rowReport[ReportChungNhanHPConst.SoRuaToiNu]);

                        word.Replace(HonPhoiConst.SoHonPhoi, rowReport[HonPhoiConst.SoHonPhoi]);
                        word.Replace(HonPhoiConst.LinhMucChung, rowReport[HonPhoiConst.LinhMucChung]);
                        word.Replace(HonPhoiConst.NoiHonPhoi, rowReport[HonPhoiConst.NoiHonPhoi]);
                        word.Replace(HonPhoiConst.NguoiChung1, rowReport[HonPhoiConst.NguoiChung1]);
                        word.Replace(HonPhoiConst.NguoiChung2, rowReport[HonPhoiConst.NguoiChung2]);
                        if (Memory.GetConfig(GxConstants.CF_LANGUAGE) == GxConstants.LANG_VN)
                        {
                            word.Replace(ReportChungNhanHPConst.NgayThangNam, Memory.GetReportNgayThangNamVn());
                        }
                        else
                        {
                            word.Replace(ReportChungNhanHPConst.NgayThangNam, Memory.GetReportNgayThangNamEn());
                        }

                        word.End_Write();
                        System.Diagnostics.Process.Start(outputPath);
                    }
                    else
                    {
                        Memory.Instance.Error = new Exception("Xuất giới thiệu thất bại." + Environment.NewLine +
                                                              "Có thể bạn chưa cài MS Office 2003 trở lên" + Environment.NewLine +
                                                              "Có thể do tập tin \"HonPhoi.doc\" trong thư mục Template của chương trình đang được mở" + Environment.NewLine +
                                                              "Xin vui lòng đóng tập tin này và thử lại lần nữa");
                        return(-1);
                    }
                }
                else
                {
                    excel = new ExcelEngine();

                    if (excel.CreateObject(outputPath, templatePath))
                    {
                        try
                        {
                            excel.Write_to_excel(GiaoPhanConst.TenGiaoPhan, rowGiaoXu[GiaoPhanConst.TenGiaoPhan]);
                            excel.Write_to_excel(GiaoHatConst.TenGiaoHat, rowGiaoXu[GiaoHatConst.TenGiaoHat]);
                            excel.Write_to_excel(GiaoXuConst.TenGiaoXu, rowGiaoXu[GiaoXuConst.TenGiaoXu]);

                            excel.Write_to_excel(ReportChungNhanHPConst.HoTenNam, rowReport[ReportChungNhanHPConst.HoTenNam]);
                            excel.Write_to_excel(ReportChungNhanHPConst.HoTenNu, rowReport[ReportChungNhanHPConst.HoTenNu]);
                            excel.Write_to_excel(ReportChungNhanHPConst.NgaySinhNam, rowReport[ReportChungNhanHPConst.NgaySinhNam]);
                            excel.Write_to_excel(ReportChungNhanHPConst.NgaySinhNu, rowReport[ReportChungNhanHPConst.NgaySinhNu]);
                            excel.Write_to_excel(ReportChungNhanHPConst.NgayThangNamHP, rowReport[ReportChungNhanHPConst.NgayThangNamHP]);
                            excel.Write_to_excel(ReportChungNhanHPConst.NoiSinhNam, rowReport[ReportChungNhanHPConst.NoiSinhNam]);
                            excel.Write_to_excel(ReportChungNhanHPConst.NoiSinhNu, rowReport[ReportChungNhanHPConst.NoiSinhNu]);
                            excel.Write_to_excel(ReportChungNhanHPConst.TenChaNam, rowReport[ReportChungNhanHPConst.TenChaNam]);
                            excel.Write_to_excel(ReportChungNhanHPConst.TenChaNu, rowReport[ReportChungNhanHPConst.TenChaNu]);
                            excel.Write_to_excel(ReportChungNhanHPConst.TenLinhMucGui, rowReport[ReportChungNhanHPConst.TenLinhMucGui]);
                            excel.Write_to_excel(ReportChungNhanHPConst.TenMeNam, rowReport[ReportChungNhanHPConst.TenMeNam]);
                            excel.Write_to_excel(ReportChungNhanHPConst.TenMeNu, rowReport[ReportChungNhanHPConst.TenMeNu]);
                            excel.Write_to_excel(ReportChungNhanHPConst.GiaoXuNam, rowReport[ReportChungNhanHPConst.GiaoXuNam]);
                            excel.Write_to_excel(ReportChungNhanHPConst.GiaoXuNu, rowReport[ReportChungNhanHPConst.GiaoXuNu]);
                            excel.Write_to_excel(ReportChungNhanHPConst.NgayRuaToiNam, rowReport[ReportChungNhanHPConst.NgayRuaToiNam]);
                            excel.Write_to_excel(ReportChungNhanHPConst.SoRuaToiNam, rowReport[ReportChungNhanHPConst.SoRuaToiNam]);
                            excel.Write_to_excel(ReportChungNhanHPConst.NgayRuaToiNu, rowReport[ReportChungNhanHPConst.NgayRuaToiNu]);
                            excel.Write_to_excel(ReportChungNhanHPConst.SoRuaToiNu, rowReport[ReportChungNhanHPConst.SoRuaToiNu]);

                            excel.Write_to_excel(HonPhoiConst.SoHonPhoi, rowReport[HonPhoiConst.SoHonPhoi]);
                            excel.Write_to_excel(HonPhoiConst.LinhMucChung, rowReport[HonPhoiConst.LinhMucChung]);
                            excel.Write_to_excel(HonPhoiConst.NoiHonPhoi, rowReport[HonPhoiConst.NoiHonPhoi]);
                            excel.Write_to_excel(HonPhoiConst.NguoiChung1, rowReport[HonPhoiConst.NguoiChung1]);
                            excel.Write_to_excel(HonPhoiConst.NguoiChung2, rowReport[HonPhoiConst.NguoiChung2]);
                            if (Memory.GetConfig(GxConstants.CF_LANGUAGE) == GxConstants.LANG_VN)
                            {
                                excel.Write_to_excel(ReportChungNhanHPConst.NgayThangNam, Memory.GetReportNgayThangNamVn());
                            }
                            else
                            {
                                excel.Write_to_excel(ReportChungNhanHPConst.NgayThangNam, Memory.GetReportNgayThangNamEn());
                            }
                            excel.End_Write();
                            System.Diagnostics.Process.Start(outputPath);
                        }
                        catch (Exception ex)
                        {
                            Memory.Instance.Error = ex;
                        }
                    }
                    else
                    {
                        Memory.Instance.Error = new Exception("Xuất chứng nhận thất bại." + Environment.NewLine +
                                                              "Có thể bạn chưa cài MS Office 2003 trở lên" + Environment.NewLine +
                                                              "Có thể do tập tin \"ChungNhanHonPhoi.xls\" trong thư mục Template của chương trình đang được mở" + Environment.NewLine +
                                                              "Xin vui lòng đóng tập tin này và thử lại lần nữa");
                        return(-1);
                    }
                }
            }
            catch (Exception ex)
            {
                Memory.Instance.Error = ex;
                return(-1);
            }
            finally
            {
                if (excel != null)
                {
                    excel.End_Write();
                }
                if (word != null)
                {
                    word.End_Write();
                }
            }
            return(0);
        }
示例#2
0
        public static int Export(DataSet ds)
        {
            ExcelEngine excel = null;
            WordEngine  word  = null;

            try
            {
                if (!ds.Tables.Contains(GiaoXuConst.TableName) || !ds.Tables.Contains(GiaoDanConst.TableName))
                {
                    Memory.Instance.Error = new Exception("Không có dữ liệu làm việc!");
                    return(-1);
                }

                DataTable tblGiaoDan = ds.Tables[GiaoDanConst.TableName];
                DataTable tblGiaoXu  = ds.Tables[GiaoXuConst.TableName];
                //DataTable tblGiaDinh = ds.Tables[GiaDinhConst.TableName];
                DataTable tblGiaoXuNhan = ds.Tables[ReportHonPhoiConst.TableName];
                if (tblGiaoDan.Rows.Count == 0 || tblGiaoXu.Rows.Count == 0)
                {
                    return(-1);
                }
                string templatePath = Memory.GetReportTemplatePath(GxConstants.REPORT_HONPHOI_FILENAME);
                string outputPath   = Memory.GetTempPath(GxConstants.REPORT_HONPHOI_FILENAME);

                DataRow rowGiaoXu     = tblGiaoXu.Rows[0];
                DataRow rowGiaoDan    = tblGiaoDan.Rows[0];
                DataRow rowGiaoXuNhan = tblGiaoXuNhan.Rows[0];

                string reportFormat = Memory.GetReportFormat();
                templatePath = string.Concat(templatePath, reportFormat);
                outputPath   = string.Concat(outputPath, reportFormat);

                if (reportFormat == GxConstants.DOC_FORMAT)
                {
                    word = new WordEngine();
                    word.CreateObject(outputPath, templatePath);

                    try
                    {
                        word.Replace(GiaoPhanConst.TenGiaoPhan, rowGiaoXu[GiaoPhanConst.TenGiaoPhan]);
                        word.Replace(GiaoHatConst.TenGiaoHat, rowGiaoXu[GiaoHatConst.TenGiaoHat]);
                        word.Replace(GiaoXuConst.TenGiaoXu, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
                        word.Replace(GiaoXuConst.DienThoai, rowGiaoXu[GiaoXuConst.DienThoai]);
                        word.Replace(GiaoXuConst.Email, rowGiaoXu[GiaoXuConst.Email]);
                        word.Replace(GiaoXuConst.DiaChi, rowGiaoXu[GiaoXuConst.DiaChi]);
                        word.Replace(GiaoXuConst.Website, rowGiaoXu[GiaoXuConst.Website]);

                        word.Replace(ReportHonPhoiConst.TenGiaoXuNhan, rowGiaoXuNhan[ReportHonPhoiConst.TenLinhMucNhan]);
                        word.Replace(ReportHonPhoiConst.TenGiaoPhanNhan, rowGiaoXuNhan[ReportHonPhoiConst.TenGiaoXuNhan]);
                        word.Replace(ReportHonPhoiConst.TenLinhMucGui, rowGiaoXu[ReportHonPhoiConst.TenLinhMucGui]);
                        //word.Replace(7, 19, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
                        word.Replace(GiaoDanConst.HoTen, rowGiaoDan[GiaoDanConst.TenThanh].ToString() + " " + rowGiaoDan[GiaoDanConst.HoTen].ToString());
                        word.Replace(GiaoDanConst.NgaySinh, rowGiaoDan[GiaoDanConst.NgaySinh]);
                        word.Replace(ReportHonPhoiConst.Tuoi1, Memory.GetTuoi(rowGiaoDan[GiaoDanConst.NgaySinh].ToString()));
                        word.Replace(GiaoDanConst.NoiSinh, rowGiaoDan[GiaoDanConst.NoiSinh]);

                        word.Replace(ReportGiaoDanConst.TenCha, rowGiaoDan[GiaoDanConst.HoTenCha]);
                        word.Replace(ReportGiaoDanConst.TenMe, rowGiaoDan[GiaoDanConst.HoTenMe]);

                        word.Replace(GiaoDanConst.NgayRuaToi, rowGiaoDan[GiaoDanConst.NgayRuaToi]);
                        word.Replace(GiaoDanConst.NoiRuaToi, rowGiaoDan[GiaoDanConst.NoiRuaToi]);
                        word.Replace(GiaoDanConst.ChaRuaToi, rowGiaoDan[GiaoDanConst.ChaRuaToi]);
                        word.Replace(GiaoDanConst.NguoiDoDauRuaToi, rowGiaoDan[GiaoDanConst.NguoiDoDauRuaToi]);
                        word.Replace(GiaoDanConst.SoRuaToi, rowGiaoDan[GiaoDanConst.SoRuaToi]);
                        word.Replace(GiaoDanConst.NgayThemSuc, rowGiaoDan[GiaoDanConst.NgayThemSuc]);
                        word.Replace(GiaoDanConst.NoiThemSuc, rowGiaoDan[GiaoDanConst.NoiThemSuc]);
                        word.Replace(GiaoDanConst.ChaThemSuc, rowGiaoDan[GiaoDanConst.ChaThemSuc]);
                        word.Replace(GiaoDanConst.NguoiDoDauThemSuc, rowGiaoDan[GiaoDanConst.NguoiDoDauThemSuc]);
                        word.Replace(GiaoDanConst.SoThemSuc, rowGiaoDan[GiaoDanConst.SoThemSuc]);
                        word.Replace(ReportHonPhoiConst.Nguoi2, rowGiaoXuNhan[ReportHonPhoiConst.Nguoi2]);
                        word.Replace(ReportHonPhoiConst.Tuoi2, rowGiaoXuNhan[ReportHonPhoiConst.Tuoi2]);
                        word.Replace(ReportHonPhoiConst.TenCha2, rowGiaoXuNhan[ReportHonPhoiConst.TenCha2]);
                        word.Replace(ReportHonPhoiConst.TenMe2, rowGiaoXuNhan[ReportHonPhoiConst.TenMe2]);
                        word.Replace(ReportHonPhoiConst.TenGiaoXu2, rowGiaoXuNhan[ReportHonPhoiConst.TenGiaoXu2]);
                        word.Replace(ReportHonPhoiConst.TenGiaoPhan2, rowGiaoXuNhan[ReportHonPhoiConst.TenGiaoPhan2]);
                        word.Replace(ReportHonPhoiConst.NoiHocGLHN, rowGiaoXuNhan[ReportHonPhoiConst.NoiHocGLHN]);

                        if (Memory.GetConfig(GxConstants.CF_LANGUAGE) == GxConstants.LANG_EN)
                        {
                            word.Replace(ReportGiaoDanConst.NgayThangNam, Memory.GetReportNgayThangNamEn());
                        }
                        else
                        {
                            word.Replace(ReportGiaoDanConst.NgayThangNam, Memory.GetReportNgayThangNamVn());
                        }
                        word.End_Write();
                        System.Diagnostics.Process.Start(outputPath);
                    }
                    catch (Exception ex)
                    {
                        Memory.Instance.Error = ex;
                    }
                }
                else
                {
                    excel = new ExcelEngine();
                    if (excel.CreateObject(outputPath, templatePath))
                    {
                        excel.LoaiBaoCao = ReportType.GioiThieuHonPhoi;
                        excel.Write_to_excel(GiaoPhanConst.TenGiaoPhan, rowGiaoXu[GiaoPhanConst.TenGiaoPhan]);
                        excel.Write_to_excel(GiaoHatConst.TenGiaoHat, rowGiaoXu[GiaoHatConst.TenGiaoHat]);
                        excel.Write_to_excel(GiaoXuConst.TenGiaoXu, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
                        excel.Write_to_excel(GiaoXuConst.DienThoai, rowGiaoXu[GiaoXuConst.DienThoai]);
                        excel.Write_to_excel(GiaoXuConst.Email, rowGiaoXu[GiaoXuConst.Email]);
                        excel.Write_to_excel(GiaoXuConst.DiaChi, rowGiaoXu[GiaoXuConst.DiaChi]);
                        excel.Write_to_excel(GiaoXuConst.Website, rowGiaoXu[GiaoXuConst.Website]);

                        excel.Write_to_excel(ReportHonPhoiConst.TenGiaoXuNhan, rowGiaoXuNhan[ReportHonPhoiConst.TenLinhMucNhan]);
                        excel.Write_to_excel(ReportHonPhoiConst.TenGiaoPhanNhan, rowGiaoXuNhan[ReportHonPhoiConst.TenGiaoXuNhan]);
                        excel.Write_to_excel(ReportHonPhoiConst.TenLinhMucGui, rowGiaoXu[ReportHonPhoiConst.TenLinhMucGui]);
                        //excel.Write_to_excel(7, 19, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
                        excel.Write_to_excel(GiaoDanConst.HoTen, rowGiaoDan[GiaoDanConst.TenThanh].ToString() + " " + rowGiaoDan[GiaoDanConst.HoTen].ToString());
                        excel.Write_to_excel(GiaoDanConst.NgaySinh, rowGiaoDan[GiaoDanConst.NgaySinh]);
                        excel.Write_to_excel(GiaoDanConst.NoiSinh, rowGiaoDan[GiaoDanConst.NoiSinh]);

                        excel.Write_to_excel(ReportGiaoDanConst.TenCha, rowGiaoDan[GiaoDanConst.HoTenCha]);
                        excel.Write_to_excel(ReportGiaoDanConst.TenMe, rowGiaoDan[GiaoDanConst.HoTenMe]);

                        excel.Write_to_excel(GiaoDanConst.NgayRuaToi, rowGiaoDan[GiaoDanConst.NgayRuaToi]);
                        excel.Write_to_excel(GiaoDanConst.NoiRuaToi, rowGiaoDan[GiaoDanConst.NoiRuaToi]);
                        excel.Write_to_excel(GiaoDanConst.ChaRuaToi, rowGiaoDan[GiaoDanConst.ChaRuaToi]);
                        excel.Write_to_excel(GiaoDanConst.NguoiDoDauRuaToi, rowGiaoDan[GiaoDanConst.NguoiDoDauRuaToi]);
                        excel.Write_to_excel(GiaoDanConst.SoRuaToi, rowGiaoDan[GiaoDanConst.SoRuaToi]);
                        excel.Write_to_excel(GiaoDanConst.NgayThemSuc, rowGiaoDan[GiaoDanConst.NgayThemSuc]);
                        excel.Write_to_excel(GiaoDanConst.NoiThemSuc, rowGiaoDan[GiaoDanConst.NoiThemSuc]);
                        excel.Write_to_excel(GiaoDanConst.ChaThemSuc, rowGiaoDan[GiaoDanConst.ChaThemSuc]);
                        excel.Write_to_excel(GiaoDanConst.NguoiDoDauThemSuc, rowGiaoDan[GiaoDanConst.NguoiDoDauThemSuc]);
                        excel.Write_to_excel(GiaoDanConst.SoThemSuc, rowGiaoDan[GiaoDanConst.SoThemSuc]);
                        excel.Write_to_excel(ReportHonPhoiConst.Nguoi2, rowGiaoXuNhan[ReportHonPhoiConst.Nguoi2]);
                        if (Memory.GetConfig(GxConstants.CF_LANGUAGE) == GxConstants.LANG_EN)
                        {
                            excel.Write_to_excel(ReportGiaoDanConst.NgayThangNam, Memory.GetReportNgayThangNamEn());
                        }
                        else
                        {
                            excel.Write_to_excel(ReportGiaoDanConst.NgayThangNam, Memory.GetReportNgayThangNamVn());
                        }
                        excel.End_Write();
                        System.Diagnostics.Process.Start(outputPath);
                    }
                    else
                    {
                        Memory.Instance.Error = new Exception("Xuất giới thiệu thất bại." + Environment.NewLine +
                                                              "Có thể bạn chưa cài MS Office 2003 trở lên" + Environment.NewLine +
                                                              "Có thể do tập tin \"HonPhoi.xls\" trong thư mục Template của chương trình đang được mở" + Environment.NewLine +
                                                              "Xin vui lòng đóng tập tin này và thử lại lần nữa");
                        return(-1);
                    }
                }
            }
            catch (Exception ex)
            {
                Memory.Instance.Error = ex;
                return(-1);
            }
            finally
            {
                if (excel != null)
                {
                    excel.End_Write();
                }
                if (word != null)
                {
                    word.End_Write();
                }
            }
            return(0);
        }
示例#3
0
        public static int ExportList(DataSet ds)
        {
            ExcelEngine excel = new ExcelEngine();

            try
            {
                if (!ds.Tables.Contains(RaoHonPhoiTMPConst.TableName))
                {
                    Memory.Instance.Error = new Exception("Không có dữ liệu làm việc!");
                    return(-1);
                }

                DataTable tblReportRaoHonPhoi = ds.Tables[RaoHonPhoiTMPConst.TableName];
                //Get template and output path
                if (tblReportRaoHonPhoi.Rows.Count == 0)
                {
                    return(-1);
                }
                string templatePath = Memory.GetReportTemplatePath(GxConstants.REPORT_RAOHONPHOILIST_FILENAME);
                string outputPath   = Memory.GetTempPath(GxConstants.REPORT_RAOHONPHOILIST_FILENAME);
                //Get working row
                DataRow rowData = tblReportRaoHonPhoi.Rows[0];

                if (excel.CreateObject(outputPath, templatePath))
                {
                    try
                    {
                        excel.LoaiBaoCao = ReportType.RaoHonPhoiList;
                        Dictionary <string, int> dicPos = getPositionsDic(excel, tblReportRaoHonPhoi);
                        int maxColIndex = 0;
                        foreach (KeyValuePair <string, int> item in dicPos)
                        {
                            if (item.Value > maxColIndex)
                            {
                                maxColIndex = item.Value;
                            }
                        }
                        string lasDetailColName = excel.MapColIndexToColName(maxColIndex);

                        int minColIndex = 20;
                        foreach (KeyValuePair <string, int> item in dicPos)
                        {
                            if (item.Value < minColIndex)
                            {
                                minColIndex = item.Value;
                            }
                        }
                        string beginDetailColName = excel.MapColIndexToColName(minColIndex);

                        int    i              = beginDetailRow;
                        bool   inNoiSinh      = Memory.GetConfig(GxConstants.CF_SOGIADINH_INNOISINH) == GxConstants.CF_TRUE;
                        string lang           = Memory.GetConfig(GxConstants.CF_LANGUAGE);
                        bool   isUSFormatName = Memory.GetConfig(GxConstants.CF_US_FORMAT_NAME) == GxConstants.CF_TRUE;
                        int    tmp            = 0;
                        int    stt            = 0;
                        foreach (DataRow row in tblReportRaoHonPhoi.Rows)
                        {
                            //if (tmp != (int)row[RaoHonPhoiTMPConst.MaRaoHonPhoi])
                            //{
                            //    tmp = (int)row[RaoHonPhoiTMPConst.MaRaoHonPhoi];
                            //    stt++;
                            //}
                            //excel.Write_to_excel(i, 2, stt);//in so thu tu

                            foreach (KeyValuePair <string, int> item in dicPos)
                            {
                                string key = item.Key.ToLower();
                                if (key.StartsWith("ngay"))
                                {
                                    row[item.Key] = Memory.GetDateStringByLang(row[item.Key]);
                                    excel.Write_to_excel(i, item.Value, "'" + row[item.Key].ToString());
                                }
                                if (item.Key == GiaoDanConst.TanTong)
                                {
                                    if ((bool)row[GiaoDanConst.TanTong] == false)
                                    {
                                        excel.Write_to_excel(i, item.Value, "");
                                    }
                                    else
                                    {
                                        excel.Write_to_excel(i, item.Value, "X");
                                    }
                                }
                                else
                                {
                                    if (Validator.IsNumber(row[item.Key].ToString()))
                                    {
                                        excel.Write_to_excel(i, item.Value, "'" + row[item.Key].ToString());
                                    }
                                    else
                                    {
                                        excel.Write_to_excel(i, item.Value, row[item.Key]);
                                    }
                                }
                            }
                            //Merge
                            if ((i - beginDetailRow) % 2 != 0)
                            {
                                stt++;
                                excel.Write_to_excel(i, 1, stt);
                                excel.Merge("A" + (i - 1).ToString(), "A" + i.ToString()); //STT
                                excel.Merge("B" + (i - 1).ToString(), "B" + i.ToString()); //Doi rao
                                //excel.Merge("C" + (i - 1).ToString(), "C" + i.ToString());//Lan rao
                            }
                            i++;
                        }
                        excel.Border_Range(beginDetailColName + beginDetailRow.ToString(), lasDetailColName + (i - 1).ToString());

                        i++;

                        excel.SetWrapText(beginDetailColName + i.ToString(), lasDetailColName + i.ToString(), false);
                        DateTime d = DateTime.Now;
                        if (Memory.Instance.GetMemory(ReportRaoHonPhoiConst.ThoiGianRao) != null && Memory.Instance.GetMemory(ReportRaoHonPhoiConst.ThoiGianRao) is DateTime)
                        {
                            d = (DateTime)Memory.Instance.GetMemory(ReportRaoHonPhoiConst.ThoiGianRao);
                        }
                        excel.Write_to_excel(ReportRaoHonPhoiConst.ThoiGianRao, d.ToString("dd/MM/yyyy"));

                        excel.End_Write();

                        System.Diagnostics.Process.Start(outputPath);
                    }
                    catch (Exception ex)
                    {
                        Memory.Instance.Error = ex;
                    }
                }
                else
                {
                    Memory.Instance.Error = new Exception("Xuất danh sách điều tra hôn phối." + Environment.NewLine +
                                                          "Có thể bạn chưa cài MS Office 2003 trở lên" + Environment.NewLine +
                                                          "Có thể do tập tin \"DanhSachRaoHonPhoi.xls\" trong thư mục Template của chương trình đang được mở" + Environment.NewLine +
                                                          "Xin vui lòng đóng tập tin này và thử lại lần nữa");
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                Memory.Instance.Error = ex;
                return(-1);
            }
            beginDetailRow = -1;
            return(0);
        }
示例#4
0
        //public static int Export(DataSet ds)
        //{
        //    try
        //    {
        //        if (!ds.Tables.Contains(GiaoDanConst.TableName) || !ds.Tables.Contains(GiaoXuConst.TableName) || !ds.Tables.Contains(GiaoDanConst.TableName))
        //        {
        //            Memory.Instance.Error = new Exception("Không có dữ liệu làm việc!");
        //            return -1;
        //        }

        //        DataTable tblGiaoDan = ds.Tables[GiaoDanConst.TableName];
        //        DataTable tblGiaoXu = ds.Tables[GiaoXuConst.TableName];
        //        DataTable tblGiaDinh = ds.Tables[GiaDinhConst.TableName];
        //        DataTable tblGiaoXuNhan = ds.Tables[ReportGiaoDanConst.TableName];
        //        if (tblGiaoDan.Rows.Count == 0 || tblGiaoXu.Rows.Count == 0) return -1;
        //        string templatePath = Memory.GetReportTemplatePath(GXConstants.REPORT_BITICH_FILENAME);
        //        string outputPath = Memory.GetReportTempPath(GXConstants.REPORT_BITICH_FILENAME);

        //        ExcelEngine excel = new ExcelEngine();
        //        DataRow rowGiaoXu = tblGiaoXu.Rows[0];
        //        DataRow rowGiaoDan = tblGiaoDan.Rows[0];
        //        DataRow rowGiaoXuNhan = tblGiaoXuNhan.Rows[0];
        //        DataRow rowGiaDinh = null;
        //        if (tblGiaDinh.Rows.Count > 0)
        //        {
        //            rowGiaDinh = tblGiaDinh.Rows[0];
        //        }
        //        if (excel.CreateObject(outputPath, templatePath))
        //        {
        //            excel.Write_to_excel(1, 5, rowGiaoXu[GiaoPhanConst.TenGiaoPhan]);
        //            excel.Write_to_excel(2, 5, rowGiaoXu[GiaoHatConst.TenGiaoHat]);
        //            excel.Write_to_excel(3, 5, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
        //            excel.Write_to_excel(6, 7, rowGiaoXuNhan[ReportGiaoDanConst.TenLinhMucNhan]);
        //            excel.Write_to_excel(6, 17, rowGiaoXuNhan[ReportGiaoDanConst.GiaoXuNhan]);
        //            excel.Write_to_excel(7, 6, rowGiaoXu[ReportGiaoDanConst.TenLinhMucGui]);
        //            excel.Write_to_excel(7, 19, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
        //            excel.Write_to_excel(8, 6, rowGiaoDan[GiaoDanConst.TenThanh].ToString() + " " + rowGiaoDan[GiaoDanConst.HoTen].ToString());
        //            excel.Write_to_excel(9, 6, rowGiaoDan[GiaoDanConst.NgaySinh]);
        //            excel.Write_to_excel(9, 15, rowGiaoDan[GiaoDanConst.NoiSinh]);
        //            if (rowGiaDinh != null)
        //            {
        //                excel.Write_to_excel(10, 6, rowGiaDinh[ReportGiaoDanConst.TenCha]);
        //                excel.Write_to_excel(11, 6, rowGiaDinh[ReportGiaoDanConst.TenMe]);
        //            }
        //            excel.Write_to_excel(12, 8, rowGiaoDan[GiaoDanConst.NgayRuaToi]);
        //            excel.Write_to_excel(12, 15, rowGiaoDan[GiaoDanConst.NoiRuaToi]);
        //            excel.Write_to_excel(13, 7, rowGiaoDan[GiaoDanConst.ChaRuaToi]);
        //            excel.Write_to_excel(14, 7, rowGiaoDan[GiaoDanConst.NguoiDoDauRuaToi]);
        //            excel.Write_to_excel(15, 7, rowGiaoDan[GiaoDanConst.SoRuaToi]);
        //            excel.Write_to_excel(16, 9, rowGiaoDan[GiaoDanConst.NgayThemSuc]);
        //            excel.Write_to_excel(16, 15, rowGiaoDan[GiaoDanConst.NoiThemSuc]);
        //            excel.Write_to_excel(17, 8, rowGiaoDan[GiaoDanConst.ChaThemSuc]);
        //            excel.Write_to_excel(18, 7, rowGiaoDan[GiaoDanConst.NguoiDoDauThemSuc]);
        //            excel.Write_to_excel(19, 7, rowGiaoDan[GiaoDanConst.SoThemSuc]);
        //            excel.Write_to_excel(22, 3, rowGiaoXuNhan[ReportGiaoDanConst.LyDo]);
        //            excel.Write_to_excel(24, 11, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
        //            excel.Write_to_excel(24, 15, string.Format("Ngày {0} tháng {1} năm {2}", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year));
        //            excel.End_Write();

        //            System.Diagnostics.Process.Start(outputPath);
        //        }
        //        else
        //        {
        //            Memory.Instance.Error = new Exception("Xuất giới thiệu thất bại." + Environment.NewLine +
        //                                                    "Có thể bạn chưa cài MS Office 2003 trở lên" + Environment.NewLine +
        //                                                    "Có thể do tập tin \"BiTich.xls\" trong thư mục Template của chương trình đang được mở" + Environment.NewLine +
        //                                                    "Xin vui lòng đóng tập tin này và thử lại lần nữa");
        //            return -1;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Memory.Instance.Error = ex;
        //        return -1;
        //    }
        //    return 0;
        //}
        public static int Export(DataSet ds)
        {
            try
            {
                if (!ds.Tables.Contains(GiaoDanConst.TableName) || !ds.Tables.Contains(GiaoXuConst.TableName) || !ds.Tables.Contains(GiaoDanConst.TableName))
                {
                    Memory.Instance.Error = new Exception("Không có dữ liệu làm việc!");
                    return(-1);
                }

                DataTable tblGiaoDan    = ds.Tables[GiaoDanConst.TableName];
                DataTable tblGiaoXu     = ds.Tables[GiaoXuConst.TableName];
                DataTable tblGiaDinh    = ds.Tables[GiaDinhConst.TableName];
                DataTable tblGiaoXuNhan = ds.Tables[ReportGiaoDanConst.TableName];
                if (tblGiaoDan.Rows.Count == 0 || tblGiaoXu.Rows.Count == 0)
                {
                    return(-1);
                }
                string templatePath = Memory.GetReportTemplatePath(GXConstants.REPORT_BITICH_FILENAME);
                string outputPath   = Memory.GetReportTempPath(GXConstants.REPORT_BITICH_FILENAME);

                ExcelEngine excel         = new ExcelEngine();
                DataRow     rowGiaoXu     = tblGiaoXu.Rows[0];
                DataRow     rowGiaoDan    = tblGiaoDan.Rows[0];
                DataRow     rowGiaoXuNhan = tblGiaoXuNhan.Rows[0];
                DataRow     rowGiaDinh    = null;
                if (tblGiaDinh.Rows.Count > 0)
                {
                    rowGiaDinh = tblGiaDinh.Rows[0];
                }
                if (excel.CreateObject(outputPath, templatePath))
                {
                    excel.Write_to_excel(GiaoPhanConst.TenGiaoPhan, rowGiaoXu[GiaoPhanConst.TenGiaoPhan]);
                    excel.Write_to_excel(GiaoHatConst.TenGiaoHat, rowGiaoXu[GiaoHatConst.TenGiaoHat]);
                    excel.Write_to_excel(GiaoXuConst.TenGiaoXu, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
                    excel.Write_to_excel(ReportGiaoDanConst.TenLinhMucNhan, rowGiaoXuNhan[ReportGiaoDanConst.TenLinhMucNhan]);
                    excel.Write_to_excel(ReportGiaoDanConst.GiaoXuNhan, rowGiaoXuNhan[ReportGiaoDanConst.GiaoXuNhan]);
                    excel.Write_to_excel(ReportGiaoDanConst.TenLinhMucGui, rowGiaoXu[ReportGiaoDanConst.TenLinhMucGui]);
                    //excel.Write_to_excel(7, 19, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
                    excel.Write_to_excel(GiaoDanConst.HoTen, rowGiaoDan[GiaoDanConst.TenThanh].ToString() + " " + rowGiaoDan[GiaoDanConst.HoTen].ToString());
                    excel.Write_to_excel(GiaoDanConst.NgaySinh, rowGiaoDan[GiaoDanConst.NgaySinh]);
                    excel.Write_to_excel(GiaoDanConst.NoiSinh, rowGiaoDan[GiaoDanConst.NoiSinh]);
                    if (rowGiaDinh != null)
                    {
                        excel.Write_to_excel(ReportGiaoDanConst.TenCha, rowGiaDinh[ReportGiaoDanConst.TenCha]);
                        excel.Write_to_excel(ReportGiaoDanConst.TenMe, rowGiaDinh[ReportGiaoDanConst.TenMe]);
                    }
                    else
                    {
                        excel.Write_to_excel(ReportGiaoDanConst.TenCha, "");
                        excel.Write_to_excel(ReportGiaoDanConst.TenMe, "");
                    }
                    excel.Write_to_excel(GiaoDanConst.NgayRuaToi, rowGiaoDan[GiaoDanConst.NgayRuaToi]);
                    excel.Write_to_excel(GiaoDanConst.NoiRuaToi, rowGiaoDan[GiaoDanConst.NoiRuaToi]);
                    excel.Write_to_excel(GiaoDanConst.ChaRuaToi, rowGiaoDan[GiaoDanConst.ChaRuaToi]);
                    excel.Write_to_excel(GiaoDanConst.NguoiDoDauRuaToi, rowGiaoDan[GiaoDanConst.NguoiDoDauRuaToi]);
                    excel.Write_to_excel(GiaoDanConst.SoRuaToi, rowGiaoDan[GiaoDanConst.SoRuaToi]);
                    excel.Write_to_excel(GiaoDanConst.NgayThemSuc, rowGiaoDan[GiaoDanConst.NgayThemSuc]);
                    excel.Write_to_excel(GiaoDanConst.NoiThemSuc, rowGiaoDan[GiaoDanConst.NoiThemSuc]);
                    excel.Write_to_excel(GiaoDanConst.ChaThemSuc, rowGiaoDan[GiaoDanConst.ChaThemSuc]);
                    excel.Write_to_excel(GiaoDanConst.NguoiDoDauThemSuc, rowGiaoDan[GiaoDanConst.NguoiDoDauThemSuc]);
                    excel.Write_to_excel(GiaoDanConst.SoThemSuc, rowGiaoDan[GiaoDanConst.SoThemSuc]);
                    excel.Write_to_excel(ReportGiaoDanConst.LyDo, rowGiaoXuNhan[ReportGiaoDanConst.LyDo]);
                    //excel.Write_to_excel(24, 11, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
                    excel.Write_to_excel(ReportGiaoDanConst.NgayThangNam, string.Format("Ngày {0} tháng {1} năm {2}", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year));
                    excel.End_Write();

                    System.Diagnostics.Process.Start(outputPath);
                }
                else
                {
                    Memory.Instance.Error = new Exception("Xuất giới thiệu thất bại." + Environment.NewLine +
                                                          "Có thể bạn chưa cài MS Office 2003 trở lên" + Environment.NewLine +
                                                          "Có thể do tập tin \"BiTich.xls\" trong thư mục Template của chương trình đang được mở" + Environment.NewLine +
                                                          "Xin vui lòng đóng tập tin này và thử lại lần nữa");
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                Memory.Instance.Error = ex;
                return(-1);
            }
            return(0);
        }
示例#5
0
        public static int Export(DataSet ds)
        {
            ExcelEngine excel = new ExcelEngine();

            try
            {
                if (!ds.Tables.Contains(GiaoXuConst.TableName) || !ds.Tables.Contains(ReportRaoHonPhoiConst.TableName))
                {
                    Memory.Instance.Error = new Exception("Không có dữ liệu làm việc!");
                    return(-1);
                }

                DataTable tblReportRaoHonPhoi = ds.Tables[ReportRaoHonPhoiConst.TableName];
                DataTable tblGiaoXu           = ds.Tables[GiaoXuConst.TableName];
                //Get template and output path
                if (tblGiaoXu.Rows.Count == 0 || tblReportRaoHonPhoi.Rows.Count == 0)
                {
                    return(-1);
                }
                string templatePath = Memory.GetReportTemplatePath(GxConstants.REPORT_RAOHONPHOI_FILENAME);
                string outputPath   = Memory.GetTempPath(GxConstants.REPORT_RAOHONPHOI_FILENAME);
                //Get working row
                DataRow rowGiaoXu = tblGiaoXu.Rows[0];
                DataRow rowData   = tblReportRaoHonPhoi.Rows[0];

                string reportFormat = Memory.GetReportFormat();
                if (!System.IO.File.Exists(string.Concat(templatePath, reportFormat)))
                {
                    reportFormat = ".xls";
                }
                templatePath = string.Concat(templatePath, reportFormat);
                outputPath   = string.Concat(outputPath, reportFormat);

                if (reportFormat == ".xls" && excel.CreateObject(outputPath, templatePath))
                {
                    try
                    {
                        excel.LoaiBaoCao = ReportType.RaoHonPhoi;
                        excel.Write_to_excel(GiaoPhanConst.TenGiaoPhan, rowGiaoXu[GiaoPhanConst.TenGiaoPhan]);
                        excel.Write_to_excel(GiaoHatConst.TenGiaoHat, rowGiaoXu[GiaoHatConst.TenGiaoHat]);
                        excel.Write_to_excel(GiaoXuConst.TenGiaoXu, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
                        excel.Write_to_excel(GiaoXuConst.DienThoai, rowGiaoXu[GiaoXuConst.DienThoai]);
                        excel.Write_to_excel(GiaoXuConst.Email, rowGiaoXu[GiaoXuConst.Email]);
                        excel.Write_to_excel(GiaoXuConst.DiaChi, rowGiaoXu[GiaoXuConst.DiaChi]);
                        excel.Write_to_excel(GiaoXuConst.Website, rowGiaoXu[GiaoXuConst.Website]);
                        excel.Write_to_excel(ReportChungNhanBTConst.TenGiaoXuNhan, rowData[ReportRaoHonPhoiConst.TenLinhMucNhan]);
                        excel.Write_to_excel(ReportChungNhanBTConst.TenGiaoPhanNhan, rowData[ReportRaoHonPhoiConst.GiaoXuNhan]);

                        foreach (DataColumn col in tblReportRaoHonPhoi.Columns)
                        {
                            excel.Write_to_excel(col.ColumnName, rowData[col]);
                        }

                        excel.End_Write();
                        System.Diagnostics.Process.Start(outputPath);
                    }
                    catch (Exception ex)
                    {
                        Memory.Instance.Error = ex;
                    }
                }
                else if (reportFormat == ".doc")
                {
                    WordEngine word = new WordEngine();
                    word.CreateObject(outputPath, templatePath);

                    try
                    {
                        word.Replace(GiaoPhanConst.TenGiaoPhan, rowGiaoXu[GiaoPhanConst.TenGiaoPhan]);
                        word.Replace(GiaoHatConst.TenGiaoHat, rowGiaoXu[GiaoHatConst.TenGiaoHat]);
                        word.Replace(GiaoXuConst.TenGiaoXu, rowGiaoXu[GiaoXuConst.TenGiaoXu].ToString().Replace("GIÁO XỨ ", "").Replace("Giáo xứ ", "").Replace("Giáo Xứ ", ""));
                        word.Replace(GiaoXuConst.DienThoai, rowGiaoXu[GiaoXuConst.DienThoai]);
                        word.Replace(GiaoXuConst.Email, rowGiaoXu[GiaoXuConst.Email]);
                        word.Replace(GiaoXuConst.DiaChi, rowGiaoXu[GiaoXuConst.DiaChi]);
                        word.Replace(GiaoXuConst.Website, rowGiaoXu[GiaoXuConst.Website]);
                        word.Replace(ReportChungNhanBTConst.TenGiaoXuNhan, rowData[ReportRaoHonPhoiConst.TenLinhMucNhan]);
                        word.Replace(ReportChungNhanBTConst.TenGiaoPhanNhan, rowData[ReportRaoHonPhoiConst.GiaoXuNhan]);

                        foreach (DataColumn col in tblReportRaoHonPhoi.Columns)
                        {
                            word.Replace(col.ColumnName, rowData[col]);
                        }

                        word.End_Write();
                        System.Diagnostics.Process.Start(outputPath);
                    }
                    catch (Exception ex)
                    {
                        Memory.Instance.Error = ex;
                    }
                }
                else
                {
                    Memory.Instance.Error = new Exception("Xuất rao hôn phối thất bại." + Environment.NewLine +
                                                          "Có thể bạn chưa cài MS Office 2003 trở lên" + Environment.NewLine +
                                                          "Có thể do tập tin \"RaoHonPhoi.xls\" trong thư mục Template của chương trình đang được mở" + Environment.NewLine +
                                                          "Xin vui lòng đóng tập tin này và thử lại lần nữa");
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                if (excel != null)
                {
                    excel.End_Write();
                }
                Memory.Instance.Error = ex;
                return(-1);
            }
            return(0);
        }
示例#6
0
        public static int Export(DataSet ds)
        {
            try
            {
                if (!ds.Tables.Contains(GiaoDanConst.TableName) || !ds.Tables.Contains(GiaoXuConst.TableName) || !ds.Tables.Contains(GiaDinhConst.TableName))
                {
                    Memory.Instance.Error = new Exception("Không có dữ liệu làm việc!");
                    return(-1);
                }

                DataTable tblGiaoDan = ds.Tables[GiaoDanConst.TableName];
                DataTable tblGiaoXu  = ds.Tables[GiaoXuConst.TableName];
                DataTable tblGiaDinh = ds.Tables[GiaDinhConst.TableName];
                if (tblGiaoDan.Rows.Count == 0 || tblGiaoXu.Rows.Count == 0)
                {
                    return(-1);
                }
                string templatePath = Memory.GetReportTemplatePath(GxConstants.REPORT_SOGIADINH_FILENAME);
                string outputPath   = Memory.GetTempPath(GxConstants.REPORT_SOGIADINH_FILENAME);

                ExcelEngine excel      = new ExcelEngine();
                DataRow     rowGiaoXu  = tblGiaoXu.Rows[0];
                DataRow     rowGiaDinh = tblGiaDinh.Rows[0];

                if (excel.CreateObject(outputPath, templatePath))
                {
                    try
                    {
                        bool isMaGDRieng = (Memory.GetConfig(GxConstants.CF_TUNHAP_MAGIADINH) == "1");
                        excel.LoaiBaoCao = ReportType.SoGiaDinh;
                        excel.Write_to_excel(GiaoXuConst.TenGiaoXu, rowGiaoXu[GiaoXuConst.TenGiaoXu].ToString().ToUpper());
                        excel.Write_to_excel(GiaDinhConst.MaGiaDinh, isMaGDRieng ? rowGiaDinh[GiaDinhConst.MaGiaDinhRieng] : rowGiaDinh[GiaDinhConst.MaGiaDinh]);
                        excel.Write_to_excel(GiaDinhConst.TenGiaDinh, rowGiaDinh[GiaDinhConst.TenGiaDinh]);
                        excel.Write_to_excel(GiaoHoConst.TenGiaoHo, rowGiaDinh[GiaoHoConst.TenGiaoHo]);
                        Dictionary <string, int> dicPos = getPositionsDic(excel, tblGiaoDan);
                        int maxColIndex = 0;
                        foreach (KeyValuePair <string, int> item in dicPos)
                        {
                            if (item.Value > maxColIndex)
                            {
                                maxColIndex = item.Value;
                            }
                        }
                        string lasDetailColName = excel.MapColIndexToColName(maxColIndex);

                        int minColIndex = 20;
                        foreach (KeyValuePair <string, int> item in dicPos)
                        {
                            if (item.Value < minColIndex)
                            {
                                minColIndex = item.Value;
                            }
                        }
                        string beginDetailColName = excel.MapColIndexToColName(minColIndex);

                        int    i              = beginDetailRow;
                        bool   inNoiSinh      = Memory.GetConfig(GxConstants.CF_SOGIADINH_INNOISINH) == GxConstants.CF_TRUE;
                        string lang           = Memory.GetConfig(GxConstants.CF_LANGUAGE);
                        bool   isUSFormatName = Memory.GetConfig(GxConstants.CF_US_FORMAT_NAME) == GxConstants.CF_TRUE;
                        foreach (DataRow row in tblGiaoDan.Rows)
                        {
                            //xem xet giao dan hien tai co cho phep in khong?
                            if ((bool)row[GiaoDanConst.QuaDoi] || row[GiaoDanConst.DaChuyenXu].ToString() != GxConstants.CF_FALSE)
                            {
                                if (Memory.GetConfig(GxConstants.CF_SOGIADINH_IN_LUUTRU) == GxConstants.CF_TRUE)
                                {
                                    if (Memory.GetConfig(GxConstants.CF_SOGIADINH_IN_GACHNGANG) == GxConstants.CF_TRUE)
                                    {
                                        System.Drawing.FontStyle fontStyle = System.Drawing.FontStyle.Italic;
                                        System.Drawing.Font      font      = new System.Drawing.Font("Times New Roman", 9, fontStyle);
                                        if ((bool)row[GiaoDanConst.QuaDoi])
                                        {
                                            fontStyle = System.Drawing.FontStyle.Strikeout;
                                            font      = new System.Drawing.Font("Times New Roman", 10, fontStyle);
                                        }
                                        excel.SetFont("A" + i.ToString(), "Z" + i.ToString(), font);
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            if ((int)row[ThanhVienGiaDinhConst.VaiTro] > 1 && (bool)row[GiaoDanConst.DaCoGiaDinh])
                            {
                                if (Memory.GetConfig(GxConstants.CF_SOGIADINH_IN_LAPGD) == GxConstants.CF_TRUE)
                                {
                                    System.Drawing.Font font = new System.Drawing.Font("Times New Roman", 9, System.Drawing.FontStyle.Italic);

                                    excel.SetFont("A" + i.ToString(), "Z" + i.ToString(), font);
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            #region For nhung thuoc tinh dac biet, co nhieu truong hop
                            if (dicPos.ContainsKey(GiaoDanConst.MaGiaoDan))
                            {
                                if (Memory.GetConfig(GxConstants.CF_SOGIADINH_THAYSTT_MAGIAODAN) == GxConstants.CF_TRUE)
                                {
                                    row[GiaoDanConst.MaGiaoDan] = row[GiaoDanConst.MaGiaoDan];
                                }
                                else
                                {
                                    row[GiaoDanConst.MaGiaoDan] = (i - beginDetailRow + 1);
                                }
                            }

                            if (dicPos.ContainsKey(HonPhoiConst.NgayHonPhoi))
                            {
                                //for hon phoi
                                if (!Memory.IsNullOrEmpty(row[HonPhoiConst.NgayHonPhoi]))
                                {
                                }
                                else
                                {
                                    if ((bool)row[GiaoDanConst.DaCoGiaDinh])
                                    {
                                        //honPhoi = "X";
                                        row[HonPhoiConst.NgayHonPhoi] = "X";
                                    }
                                }
                            }

                            if (dicPos.ContainsKey(GiaoDanConst.NgayQuaDoi))
                            {
                                //for qua doi
                                if (!Memory.IsNullOrEmpty(row[GiaoDanConst.NgayQuaDoi]))
                                {
                                }
                                else
                                {
                                    if ((bool)row[GiaoDanConst.QuaDoi])
                                    {
                                        row[GiaoDanConst.NgayQuaDoi] = "X";
                                    }
                                }
                            }
                            if (dicPos.ContainsKey(GiaoDanConst.HoTen))
                            {
                                if (lang == GxConstants.LANG_EN && isUSFormatName)
                                {
                                    row[GiaoDanConst.HoTen] = Memory.GetHoTenByLangKhongTenThanh(row[GiaoDanConst.HoTen].ToString(), lang);
                                }
                            }

                            if (inNoiSinh)
                            {
                                row[GiaoDanConst.NgaySinh]    = getNgayVaNoi(row[GiaoDanConst.NgaySinh], row[GiaoDanConst.NoiSinh]);
                                row[GiaoDanConst.NgayRuaToi]  = getNgayVaNoi(row[GiaoDanConst.NgayRuaToi], row[GiaoDanConst.NoiRuaToi]);
                                row[GiaoDanConst.NgayRuocLe]  = getNgayVaNoi(row[GiaoDanConst.NgayRuocLe], row[GiaoDanConst.NoiRuocLe]);
                                row[GiaoDanConst.NgayThemSuc] = getNgayVaNoi(row[GiaoDanConst.NgayThemSuc], row[GiaoDanConst.NoiThemSuc]);
                                row[HonPhoiConst.NgayHonPhoi] = getNgayVaNoi(row[HonPhoiConst.NgayHonPhoi], row[HonPhoiConst.NoiHonPhoi]);
                            }
                            #endregion
                            foreach (KeyValuePair <string, int> item in dicPos)
                            {
                                string key = item.Key.ToLower();
                                if (key.StartsWith("ngay"))
                                {
                                    if (inNoiSinh &&
                                        (key == GiaoDanConst.NgaySinh.ToLower() || key == GiaoDanConst.NgayRuaToi.ToLower() || key == GiaoDanConst.NgayRuocLe.ToLower() ||
                                         key == GiaoDanConst.NgayThemSuc.ToLower() || key == HonPhoiConst.NgayHonPhoi.ToLower()))
                                    {
                                        excel.Write_to_excel(i, item.Value, row[item.Key]);
                                    }
                                    else
                                    {
                                        row[item.Key] = Memory.GetDateStringByLang(row[item.Key]);
                                        excel.Write_to_excel(i, item.Value, "'" + row[item.Key].ToString());
                                    }
                                }
                                else
                                {
                                    if (Validator.IsNumber(row[item.Key].ToString()))
                                    {
                                        excel.Write_to_excel(i, item.Value, "'" + row[item.Key].ToString());
                                    }
                                    else
                                    {
                                        excel.Write_to_excel(i, item.Value, row[item.Key]);
                                    }
                                }
                            }
                            if (inNoiSinh && (!Memory.IsNullOrEmpty(row[GiaoDanConst.NoiSinh]) ||
                                              !Memory.IsNullOrEmpty(row[GiaoDanConst.NoiRuaToi]) || !Memory.IsNullOrEmpty(row[GiaoDanConst.NoiRuocLe]) ||
                                              !Memory.IsNullOrEmpty(row[GiaoDanConst.NoiThemSuc]) || !Memory.IsNullOrEmpty(row[HonPhoiConst.NoiHonPhoi])))
                            {
                                excel.AutoFitRow(i, i);
                            }
                            i++;
                        }

                        //luon dong khung 10 thanh vien
                        //neu chua du thi them cho du dong
                        //bat dau tinh toan
                        int dis = i - beginDetailRow;
                        dis = 10 - dis;
                        i   = i + dis;
                        //ket thuc tinh toan
                        excel.Border_Range(beginDetailColName + beginDetailRow.ToString(), lasDetailColName + (i - 1).ToString());

                        excel.Write_to_excel(GiaDinhConst.DienThoai, "'" + rowGiaDinh[GiaDinhConst.DienThoai].ToString());

                        excel.Write_to_excel(GiaDinhConst.DiaChi, rowGiaDinh[GiaDinhConst.DiaChi]);

                        //i++;
                        if (rowGiaDinh[GiaDinhConst.GhiChu].ToString().Trim() != "")
                        {
                            if (Memory.GetConfig(GxConstants.CF_LANGUAGE) == GxConstants.LANG_EN)
                            {
                                excel.Write_to_excel(i, minColIndex, "Note: " + rowGiaDinh[GiaDinhConst.GhiChu].ToString());
                            }
                            else
                            {
                                excel.Write_to_excel(i, minColIndex, "Ghi chú: " + rowGiaDinh[GiaDinhConst.GhiChu].ToString());
                            }
                        }
                        else
                        {
                            if (Memory.GetConfig(GxConstants.CF_LANGUAGE) == GxConstants.LANG_EN)
                            {
                                excel.Write_to_excel(i, minColIndex, "Note: ");
                            }
                            else
                            {
                                excel.Write_to_excel(i, minColIndex, "Ghi chú: ");
                            }
                        }
                        excel.SetWrapText(beginDetailColName + i.ToString(), lasDetailColName + i.ToString(), false);
                        excel.SetAlignment(beginDetailColName + i.ToString(), lasDetailColName + i.ToString(), XlHAlign.xlHAlignLeft);

                        excel.End_Write();

                        System.Diagnostics.Process.Start(outputPath);
                    }
                    catch (Exception ex)
                    {
                        Memory.Instance.Error = ex;
                    }
                }
                else
                {
                    Memory.Instance.Error = new Exception("Xuất giới thiệu thất bại." + Environment.NewLine +
                                                          "Có thể bạn chưa cài MS Office 2003 trở lên" + Environment.NewLine +
                                                          "Có thể do tập tin \"SoGiaDinh.xls\" trong thư mục Template của chương trình đang được mở" + Environment.NewLine +
                                                          "Xin vui lòng đóng tập tin này và thử lại lần nữa");
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                Memory.Instance.Error = ex;
                return(-1);
            }
            beginDetailRow = -1;
            return(0);
        }
示例#7
0
        public static int Export(DataSet ds)
        {
            ExcelEngine excel = null;
            WordEngine  word  = null;

            try
            {
                if (!ds.Tables.Contains(GiaoDanConst.TableName) || !ds.Tables.Contains(GiaoXuConst.TableName))
                {
                    Memory.Instance.Error = new Exception("Không có dữ liệu làm việc!");
                    return(-1);
                }

                DataTable tblGiaoDan = ds.Tables[GiaoDanConst.TableName];
                DataTable tblGiaoXu  = ds.Tables[GiaoXuConst.TableName];
                //DataTable tblGiaDinh = ds.Tables[GiaDinhConst.TableName];
                //DataTable tblGiaoXuNhan = null;
                //if (ds.Tables.Contains(ReportGiaoDanConst.TableName))
                //{
                //    tblGiaoXuNhan = ds.Tables[ReportGiaoDanConst.TableName];
                //}
                if (tblGiaoDan.Rows.Count == 0 || tblGiaoXu.Rows.Count == 0)
                {
                    return(-1);
                }
                LoaiBiTich loaiBiTich = Memory.Instance.GetMemory(GxConstants.CURRENT_REPORT) == null ? LoaiBiTich.TatCa : (LoaiBiTich)Memory.Instance.GetMemory(GxConstants.CURRENT_REPORT);
                string     fileName   = "";
                switch (loaiBiTich)
                {
                case LoaiBiTich.RuaToi:
                    fileName = GxConstants.REPORT_RUATOI_FILENAME;
                    break;

                case LoaiBiTich.RuocLe:
                    fileName = GxConstants.REPORT_XTRL_FILENAME;
                    break;

                case LoaiBiTich.ThemSuc:
                    fileName = GxConstants.REPORT_THEMSUC_FILENAME;
                    break;

                default:
                    fileName = GxConstants.REPORT_BITICH_FILENAME;
                    break;
                }

                string templatePath = Memory.GetReportTemplatePath(fileName);
                string outputPath   = Memory.GetTempPath(fileName);

                DataRow rowGiaoXu  = tblGiaoXu.Rows[0];
                DataRow rowGiaoDan = tblGiaoDan.Rows[0];
                //DataRow rowGiaoXuNhan = null;
                //if (tblGiaoXuNhan != null && tblGiaoXuNhan.Rows.Count > 0)
                //{
                //    rowGiaoXuNhan = tblGiaoXuNhan.Rows[0];
                //}

                string reportFormat = Memory.GetReportFormat();
                templatePath = string.Concat(templatePath, reportFormat);
                outputPath   = string.Concat(outputPath, reportFormat);

                if (reportFormat == GxConstants.DOC_FORMAT)
                {
                    word = new WordEngine();
                    if (word.CreateObject(outputPath, templatePath))
                    {
                        try
                        {
                            word.Replace(GiaoPhanConst.TenGiaoPhan, rowGiaoXu[GiaoPhanConst.TenGiaoPhan]);
                            word.Replace(GiaoHatConst.TenGiaoHat, rowGiaoXu[GiaoHatConst.TenGiaoHat]);
                            word.Replace(GiaoXuConst.TenGiaoXu, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
                            word.Replace(ReportGiaoDanConst.TenLinhMucGui, rowGiaoXu[ReportGiaoDanConst.TenLinhMucGui]);
                            word.Replace(GiaoDanConst.HoTen, rowGiaoDan[GiaoDanConst.TenThanh].ToString() + " " + rowGiaoDan[GiaoDanConst.HoTen].ToString());
                            word.Replace(GiaoDanConst.NgaySinh, rowGiaoDan[GiaoDanConst.NgaySinh]);
                            word.Replace(GiaoDanConst.NoiSinh, rowGiaoDan[GiaoDanConst.NoiSinh]);

                            word.Replace(ReportGiaoDanConst.TenCha, rowGiaoDan[GiaoDanConst.HoTenCha]);
                            word.Replace(ReportGiaoDanConst.TenMe, rowGiaoDan[GiaoDanConst.HoTenMe]);

                            word.Replace(GiaoDanConst.NgayRuaToi, rowGiaoDan[GiaoDanConst.NgayRuaToi]);
                            word.Replace(GiaoDanConst.NoiRuaToi, rowGiaoDan[GiaoDanConst.NoiRuaToi]);
                            word.Replace(GiaoDanConst.ChaRuaToi, rowGiaoDan[GiaoDanConst.ChaRuaToi]);
                            word.Replace(GiaoDanConst.NguoiDoDauRuaToi, rowGiaoDan[GiaoDanConst.NguoiDoDauRuaToi]);
                            word.Replace(GiaoDanConst.SoRuaToi, rowGiaoDan[GiaoDanConst.SoRuaToi]);
                            word.Replace(GiaoDanConst.NgayThemSuc, rowGiaoDan[GiaoDanConst.NgayThemSuc]);
                            word.Replace(GiaoDanConst.NoiThemSuc, rowGiaoDan[GiaoDanConst.NoiThemSuc]);
                            word.Replace(GiaoDanConst.ChaThemSuc, rowGiaoDan[GiaoDanConst.ChaThemSuc]);
                            word.Replace(GiaoDanConst.NguoiDoDauThemSuc, rowGiaoDan[GiaoDanConst.NguoiDoDauThemSuc]);
                            word.Replace(GiaoDanConst.SoThemSuc, rowGiaoDan[GiaoDanConst.SoThemSuc]);
                            word.Replace(GiaoDanConst.SoRuocLe, rowGiaoDan[GiaoDanConst.SoRuocLe]);
                            word.Replace(GiaoDanConst.NgayRuocLe, rowGiaoDan[GiaoDanConst.NgayRuocLe]);
                            word.Replace(GiaoDanConst.NoiRuocLe, rowGiaoDan[GiaoDanConst.NoiRuocLe]);
                            word.Replace(GiaoDanConst.ChaRuocLe, rowGiaoDan[GiaoDanConst.ChaRuocLe]);

                            //if (rowGiaoXuNhan != null)
                            //{
                            //    word.Replace(ReportGiaoDanConst.LyDo, rowGiaoXuNhan[ReportGiaoDanConst.LyDo]);
                            //    word.Replace(ReportGiaoDanConst.TenLinhMucNhan, rowGiaoXuNhan[ReportGiaoDanConst.TenLinhMucNhan]);
                            //    word.Replace(ReportGiaoDanConst.GiaoXuNhan, rowGiaoXuNhan[ReportGiaoDanConst.GiaoXuNhan]);
                            //}

                            if (Memory.GetConfig(GxConstants.CF_LANGUAGE).ToString() == GxConstants.LANG_VN)
                            {
                                word.Replace(ReportGiaoDanConst.NgayThangNam, Memory.GetReportNgayThangNamVn());
                            }
                            else
                            {
                                word.Replace(ReportGiaoDanConst.NgayThangNam, Memory.GetReportNgayThangNamEn());
                            }
                            word.End_Write();

                            System.Diagnostics.Process.Start(outputPath);
                        }
                        catch (Exception ex)
                        {
                            Memory.Instance.Error = ex;
                        }
                    }
                    else
                    {
                        Memory.Instance.Error = new Exception("Xuất giới thiệu thất bại." + Environment.NewLine +
                                                              "Có thể bạn chưa cài MS Office 2003 trở lên" + Environment.NewLine +
                                                              "Có thể do tập tin \"BiTich.doc\" trong thư mục Template của chương trình đang được mở" + Environment.NewLine +
                                                              "Xin vui lòng đóng tập tin này và thử lại lần nữa");
                        return(-1);
                    }
                }
                else
                {
                    excel = new ExcelEngine();
                    if (excel.CreateObject(outputPath, templatePath))
                    {
                        try
                        {
                            excel.Write_to_excel(GiaoPhanConst.TenGiaoPhan, rowGiaoXu[GiaoPhanConst.TenGiaoPhan]);
                            excel.Write_to_excel(GiaoHatConst.TenGiaoHat, rowGiaoXu[GiaoHatConst.TenGiaoHat]);
                            excel.Write_to_excel(GiaoXuConst.TenGiaoXu, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
                            excel.Write_to_excel(ReportGiaoDanConst.TenLinhMucGui, rowGiaoXu[ReportGiaoDanConst.TenLinhMucGui]);
                            excel.Write_to_excel(GiaoDanConst.HoTen, rowGiaoDan[GiaoDanConst.TenThanh].ToString() + " " + rowGiaoDan[GiaoDanConst.HoTen].ToString());
                            excel.Write_to_excel(GiaoDanConst.NgaySinh, rowGiaoDan[GiaoDanConst.NgaySinh]);
                            excel.Write_to_excel(GiaoDanConst.NoiSinh, rowGiaoDan[GiaoDanConst.NoiSinh]);

                            excel.Write_to_excel(ReportGiaoDanConst.TenCha, rowGiaoDan[GiaoDanConst.HoTenCha]);
                            excel.Write_to_excel(ReportGiaoDanConst.TenMe, rowGiaoDan[GiaoDanConst.HoTenMe]);

                            excel.Write_to_excel(GiaoDanConst.NgayRuaToi, rowGiaoDan[GiaoDanConst.NgayRuaToi]);
                            excel.Write_to_excel(GiaoDanConst.NoiRuaToi, rowGiaoDan[GiaoDanConst.NoiRuaToi]);
                            excel.Write_to_excel(GiaoDanConst.ChaRuaToi, rowGiaoDan[GiaoDanConst.ChaRuaToi]);
                            excel.Write_to_excel(GiaoDanConst.NguoiDoDauRuaToi, rowGiaoDan[GiaoDanConst.NguoiDoDauRuaToi]);
                            excel.Write_to_excel(GiaoDanConst.SoRuaToi, rowGiaoDan[GiaoDanConst.SoRuaToi]);
                            excel.Write_to_excel(GiaoDanConst.NgayThemSuc, rowGiaoDan[GiaoDanConst.NgayThemSuc]);
                            excel.Write_to_excel(GiaoDanConst.NoiThemSuc, rowGiaoDan[GiaoDanConst.NoiThemSuc]);
                            excel.Write_to_excel(GiaoDanConst.ChaThemSuc, rowGiaoDan[GiaoDanConst.ChaThemSuc]);
                            excel.Write_to_excel(GiaoDanConst.NguoiDoDauThemSuc, rowGiaoDan[GiaoDanConst.NguoiDoDauThemSuc]);
                            excel.Write_to_excel(GiaoDanConst.SoThemSuc, rowGiaoDan[GiaoDanConst.SoThemSuc]);
                            excel.Write_to_excel(GiaoDanConst.SoRuocLe, rowGiaoDan[GiaoDanConst.SoRuocLe]);
                            excel.Write_to_excel(GiaoDanConst.NgayRuocLe, rowGiaoDan[GiaoDanConst.NgayRuocLe]);
                            excel.Write_to_excel(GiaoDanConst.NoiRuocLe, rowGiaoDan[GiaoDanConst.NoiRuocLe]);
                            excel.Write_to_excel(GiaoDanConst.ChaRuocLe, rowGiaoDan[GiaoDanConst.ChaRuocLe]);

                            //if (rowGiaoXuNhan != null)
                            //{
                            //    excel.Write_to_excel(ReportGiaoDanConst.LyDo, rowGiaoXuNhan[ReportGiaoDanConst.LyDo]);
                            //    excel.Write_to_excel(ReportGiaoDanConst.TenLinhMucNhan, rowGiaoXuNhan[ReportGiaoDanConst.TenLinhMucNhan]);
                            //    excel.Write_to_excel(ReportGiaoDanConst.GiaoXuNhan, rowGiaoXuNhan[ReportGiaoDanConst.GiaoXuNhan]);
                            //}

                            if (Memory.GetConfig(GxConstants.CF_LANGUAGE).ToString() == GxConstants.LANG_VN)
                            {
                                excel.Write_to_excel(ReportGiaoDanConst.NgayThangNam, Memory.GetReportNgayThangNamVn());
                            }
                            else
                            {
                                excel.Write_to_excel(ReportGiaoDanConst.NgayThangNam, Memory.GetReportNgayThangNamEn());
                            }
                            excel.End_Write();

                            System.Diagnostics.Process.Start(outputPath);
                        }
                        catch (Exception ex)
                        {
                            Memory.Instance.Error = ex;
                        }
                    }
                    else
                    {
                        Memory.Instance.Error = new Exception("Xuất giới thiệu thất bại." + Environment.NewLine +
                                                              "Có thể bạn chưa cài MS Office 2003 trở lên" + Environment.NewLine +
                                                              "Có thể do tập tin \"BiTich.xls\" trong thư mục Template của chương trình đang được mở" + Environment.NewLine +
                                                              "Xin vui lòng đóng tập tin này và thử lại lần nữa");
                        return(-1);
                    }
                }
            }
            catch (Exception ex)
            {
                Memory.Instance.Error = ex;
                return(-1);
            }
            finally
            {
                if (excel != null)
                {
                    excel.End_Write();
                }
                if (word != null)
                {
                    word.End_Write();
                }
            }
            return(0);
        }
示例#8
0
        public static int Export(DataSet ds)
        {
            ExcelEngine excel = null;
            WordEngine  word  = null;

            try
            {
                if (!ds.Tables.Contains(GiaoDanConst.TableName) || !ds.Tables.Contains(GiaoXuConst.TableName))
                {
                    Memory.Instance.Error = new Exception("Không có dữ liệu làm việc!");
                    return(-1);
                }

                DataTable tblGiaoDan    = ds.Tables[GiaoDanConst.TableName];
                DataTable tblGiaoXu     = ds.Tables[GiaoXuConst.TableName];
                DataTable tblGiaoXuNhan = ds.Tables.Contains(ReportChungNhanBTConst.TableName) ? ds.Tables[ReportChungNhanBTConst.TableName] : null;
                //DataTable tblGiaDinh = ds.Tables[GiaDinhConst.TableName];

                if (tblGiaoDan.Rows.Count == 0 || tblGiaoXu.Rows.Count == 0)
                {
                    return(-1);
                }
                LoaiBiTich loaiBiTich = Memory.Instance.GetMemory(GxConstants.CURRENT_REPORT) == null ? LoaiBiTich.TatCa : (LoaiBiTich)Memory.Instance.GetMemory(GxConstants.CURRENT_REPORT);
                string     fileName   = "";
                switch (loaiBiTich)
                {
                case LoaiBiTich.RuaToi:
                    fileName = GxConstants.REPORT_RUATOI_FILENAME;
                    break;

                case LoaiBiTich.RuocLe:
                    fileName = GxConstants.REPORT_XTRL_FILENAME;
                    break;

                case LoaiBiTich.ThemSuc:
                    fileName = GxConstants.REPORT_THEMSUC_FILENAME;
                    break;

                default:
                    fileName = GxConstants.REPORT_BITICH_FILENAME;
                    break;
                }

                string templatePath = Memory.GetReportTemplatePath(fileName);
                string outputPath   = Memory.GetTempPath(fileName);

                DataRow rowGiaoXu     = tblGiaoXu.Rows[0];
                DataRow rowGiaoDan    = tblGiaoDan.Rows[0];
                DataRow rowHonPhoi    = ds.Tables.Contains(HonPhoiConst.TableName) ? ds.Tables[HonPhoiConst.TableName].Rows[0] : null;
                DataRow rowGiaoXuNhan = tblGiaoXuNhan != null && tblGiaoXuNhan.Rows.Count != 0 ? tblGiaoXuNhan.Rows[0] : null;

                string reportFormat = Memory.GetReportFormat();
                templatePath = string.Concat(templatePath, reportFormat);
                outputPath   = string.Concat(outputPath, reportFormat);
                string defaultValue  = ".................................";
                string defaultValue1 = ".............";
                if (reportFormat == GxConstants.DOC_FORMAT)
                {
                    word = new WordEngine();
                    if (word.CreateObject(outputPath, templatePath))
                    {
                        try
                        {
                            word.Replace(GiaoPhanConst.TenGiaoPhan, rowGiaoXu[GiaoPhanConst.TenGiaoPhan]);
                            word.Replace(GiaoHatConst.TenGiaoHat, rowGiaoXu[GiaoHatConst.TenGiaoHat]);
                            word.Replace(GiaoXuConst.TenGiaoXu, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
                            word.Replace(GiaoXuConst.DienThoai, rowGiaoXu[GiaoXuConst.DienThoai]);
                            word.Replace(GiaoXuConst.Email, rowGiaoXu[GiaoXuConst.Email]);
                            word.Replace(GiaoXuConst.DiaChi, rowGiaoXu[GiaoXuConst.DiaChi]);
                            word.Replace(GiaoXuConst.Website, rowGiaoXu[GiaoXuConst.Website]);

                            word.Replace(GiaoHoConst.TenGiaoHo, rowGiaoDan[GiaoHoConst.TenGiaoHo]);
                            word.Replace("TenGiaoHoCha", rowGiaoDan["TenGiaoHoCha"]);
                            word.Replace(ReportChungNhanBTConst.TenLinhMucGui, rowGiaoXuNhan != null ? rowGiaoXuNhan[ReportChungNhanBTConst.TenLinhMucGui] : rowGiaoXu[ReportGiaoDanConst.TenLinhMucGui], defaultValue);

                            word.Replace(GiaoDanConst.HoTen, rowGiaoDan[GiaoDanConst.TenThanh].ToString() + " " + rowGiaoDan[GiaoDanConst.HoTen].ToString(), defaultValue);
                            word.Replace(GiaoDanConst.NgaySinh, rowGiaoDan[GiaoDanConst.NgaySinh], defaultValue);
                            word.Replace(GiaoDanConst.NoiSinh, rowGiaoDan[GiaoDanConst.NoiSinh], defaultValue);

                            word.Replace(ReportGiaoDanConst.TenCha, rowGiaoDan[GiaoDanConst.HoTenCha], defaultValue);
                            word.Replace(ReportGiaoDanConst.TenMe, rowGiaoDan[GiaoDanConst.HoTenMe], defaultValue);

                            word.Replace(GiaoDanConst.NgayRuaToi, rowGiaoDan[GiaoDanConst.NgayRuaToi], defaultValue);
                            if (rowGiaoDan[GiaoDanConst.NgayRuaToi].ToString().Length >= 4)
                            {
                                word.Replace("NamRuaToi", rowGiaoDan[GiaoDanConst.NgayRuaToi].ToString().Substring(rowGiaoDan[GiaoDanConst.NgayRuaToi].ToString().Length - 4), defaultValue);
                            }
                            word.Replace(GiaoDanConst.NoiRuaToi, rowGiaoDan[GiaoDanConst.NoiRuaToi], defaultValue);
                            word.Replace(GiaoDanConst.ChaRuaToi, rowGiaoDan[GiaoDanConst.ChaRuaToi], defaultValue);
                            word.Replace(GiaoDanConst.NguoiDoDauRuaToi, rowGiaoDan[GiaoDanConst.NguoiDoDauRuaToi], defaultValue);
                            word.Replace(GiaoDanConst.SoRuaToi, rowGiaoDan[GiaoDanConst.SoRuaToi], defaultValue1);
                            word.Replace(GiaoDanConst.NgayThemSuc, rowGiaoDan[GiaoDanConst.NgayThemSuc], defaultValue);
                            if (rowGiaoDan[GiaoDanConst.NgayThemSuc].ToString().Length >= 4)
                            {
                                word.Replace("NamThemSuc", rowGiaoDan[GiaoDanConst.NgayThemSuc].ToString().Substring(rowGiaoDan[GiaoDanConst.NgayThemSuc].ToString().Length - 4), defaultValue);
                            }
                            word.Replace(GiaoDanConst.NoiThemSuc, rowGiaoDan[GiaoDanConst.NoiThemSuc], defaultValue);
                            word.Replace(GiaoDanConst.ChaThemSuc, rowGiaoDan[GiaoDanConst.ChaThemSuc], defaultValue);
                            word.Replace(GiaoDanConst.NguoiDoDauThemSuc, rowGiaoDan[GiaoDanConst.NguoiDoDauThemSuc], defaultValue);
                            word.Replace(GiaoDanConst.SoThemSuc, rowGiaoDan[GiaoDanConst.SoThemSuc], defaultValue1);
                            word.Replace(GiaoDanConst.SoRuocLe, rowGiaoDan[GiaoDanConst.SoRuocLe], defaultValue1);
                            word.Replace(GiaoDanConst.NgayRuocLe, rowGiaoDan[GiaoDanConst.NgayRuocLe], defaultValue);
                            if (rowGiaoDan[GiaoDanConst.NgayRuocLe].ToString().Length >= 4)
                            {
                                word.Replace("NamRuocLe", rowGiaoDan[GiaoDanConst.NgayRuocLe].ToString().Substring(rowGiaoDan[GiaoDanConst.NgayRuocLe].ToString().Length - 4), defaultValue);
                            }
                            word.Replace(GiaoDanConst.NoiRuocLe, rowGiaoDan[GiaoDanConst.NoiRuocLe], defaultValue);
                            word.Replace(GiaoDanConst.ChaRuocLe, rowGiaoDan[GiaoDanConst.ChaRuocLe], defaultValue);

                            word.Replace(HonPhoiConst.SoHonPhoi, rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.SoHonPhoi] : "", defaultValue1);
                            word.Replace(HonPhoiConst.NgayHonPhoi, rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.NgayHonPhoi] : "", defaultValue);
                            if (rowHonPhoi != null && rowHonPhoi[HonPhoiConst.NgayHonPhoi].ToString().Length >= 4)
                            {
                                word.Replace("NamHonPhoi", rowHonPhoi[HonPhoiConst.NgayHonPhoi].ToString().Substring(rowHonPhoi[HonPhoiConst.NgayHonPhoi].ToString().Length - 4), defaultValue);
                            }
                            word.Replace(HonPhoiConst.NoiHonPhoi, rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.NoiHonPhoi] : "", defaultValue);
                            word.Replace("ChaHonPhoi", rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.LinhMucChung] : "", defaultValue);
                            word.Replace(HonPhoiConst.CachThucHonPhoi, rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.CachThucHonPhoi] : "", defaultValue);
                            word.Replace(HonPhoiConst.VoChong, rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.VoChong] : "", defaultValue);
                            word.Replace("GhiChuHonPHoi", rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.GhiChu] : "", defaultValue);
                            word.Replace("NgaySinhVoChong", rowHonPhoi != null ? rowHonPhoi["NgaySinhVoChong"] : "", defaultValue);

                            word.Replace(ReportChungNhanBTConst.LyDo, rowGiaoXuNhan != null ? rowGiaoXuNhan[ReportChungNhanBTConst.LyDo] : "");
                            word.Replace(ReportChungNhanBTConst.TenLinhMucNhan, rowGiaoXuNhan != null ? rowGiaoXuNhan[ReportChungNhanBTConst.TenLinhMucNhan] : ".................................");
                            word.Replace(ReportChungNhanBTConst.TenGiaoXuNhan, rowGiaoXuNhan != null ? rowGiaoXuNhan[ReportChungNhanBTConst.TenGiaoXuNhan] : ".................................");
                            word.Replace(ReportChungNhanBTConst.TenGiaoPhanNhan, rowGiaoXuNhan != null ? rowGiaoXuNhan[ReportChungNhanBTConst.TenGiaoPhanNhan] : ".................................");

                            if (Memory.GetConfig(GxConstants.CF_LANGUAGE).ToString() == GxConstants.LANG_EN)
                            {
                                word.Replace(ReportGiaoDanConst.NgayThangNam, Memory.GetReportNgayThangNamEn());
                            }
                            else
                            {
                                word.Replace(ReportGiaoDanConst.NgayThangNam, Memory.GetReportNgayThangNamVn());
                            }
                            word.End_Write();

                            System.Diagnostics.Process.Start(outputPath);
                        }
                        catch (Exception ex)
                        {
                            Memory.Instance.Error = ex;
                        }
                    }
                    else
                    {
                        Memory.Instance.Error = new Exception("Xuất giới thiệu thất bại." + Environment.NewLine +
                                                              "Có thể bạn chưa cài MS Office 2003 trở lên" + Environment.NewLine +
                                                              "Có thể do tập tin \"BiTich.doc\" trong thư mục Template của chương trình đang được mở" + Environment.NewLine +
                                                              "Xin vui lòng đóng tập tin này và thử lại lần nữa");
                        return(-1);
                    }
                }
                else
                {
                    excel = new ExcelEngine();
                    if (excel.CreateObject(outputPath, templatePath))
                    {
                        try
                        {
                            excel.Write_to_excel(GiaoPhanConst.TenGiaoPhan, rowGiaoXu[GiaoPhanConst.TenGiaoPhan]);
                            excel.Write_to_excel(GiaoHatConst.TenGiaoHat, rowGiaoXu[GiaoHatConst.TenGiaoHat]);
                            excel.Write_to_excel(GiaoXuConst.TenGiaoXu, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
                            excel.Write_to_excel(ReportChungNhanBTConst.TenLinhMucGui, rowGiaoXuNhan != null ? rowGiaoXuNhan[ReportChungNhanBTConst.TenLinhMucGui] : rowGiaoXu[ReportGiaoDanConst.TenLinhMucGui]);
                            excel.Write_to_excel(GiaoDanConst.HoTen, rowGiaoDan[GiaoDanConst.TenThanh].ToString() + " " + rowGiaoDan[GiaoDanConst.HoTen].ToString());
                            excel.Write_to_excel(GiaoDanConst.NgaySinh, rowGiaoDan[GiaoDanConst.NgaySinh]);
                            excel.Write_to_excel(GiaoDanConst.NoiSinh, rowGiaoDan[GiaoDanConst.NoiSinh]);

                            excel.Write_to_excel(ReportGiaoDanConst.TenCha, rowGiaoDan[GiaoDanConst.HoTenCha]);
                            excel.Write_to_excel(ReportGiaoDanConst.TenMe, rowGiaoDan[GiaoDanConst.HoTenMe]);

                            excel.Write_to_excel(GiaoDanConst.NgayRuaToi, rowGiaoDan[GiaoDanConst.NgayRuaToi]);
                            excel.Write_to_excel(GiaoDanConst.NoiRuaToi, rowGiaoDan[GiaoDanConst.NoiRuaToi]);
                            excel.Write_to_excel(GiaoDanConst.ChaRuaToi, rowGiaoDan[GiaoDanConst.ChaRuaToi]);
                            excel.Write_to_excel(GiaoDanConst.NguoiDoDauRuaToi, rowGiaoDan[GiaoDanConst.NguoiDoDauRuaToi]);
                            excel.Write_to_excel(GiaoDanConst.SoRuaToi, rowGiaoDan[GiaoDanConst.SoRuaToi]);
                            excel.Write_to_excel(GiaoDanConst.NgayThemSuc, rowGiaoDan[GiaoDanConst.NgayThemSuc]);
                            excel.Write_to_excel(GiaoDanConst.NoiThemSuc, rowGiaoDan[GiaoDanConst.NoiThemSuc]);
                            excel.Write_to_excel(GiaoDanConst.ChaThemSuc, rowGiaoDan[GiaoDanConst.ChaThemSuc]);
                            excel.Write_to_excel(GiaoDanConst.NguoiDoDauThemSuc, rowGiaoDan[GiaoDanConst.NguoiDoDauThemSuc]);
                            excel.Write_to_excel(GiaoDanConst.SoThemSuc, rowGiaoDan[GiaoDanConst.SoThemSuc]);
                            excel.Write_to_excel(GiaoDanConst.SoRuocLe, rowGiaoDan[GiaoDanConst.SoRuocLe]);
                            excel.Write_to_excel(GiaoDanConst.NgayRuocLe, rowGiaoDan[GiaoDanConst.NgayRuocLe]);
                            excel.Write_to_excel(GiaoDanConst.NoiRuocLe, rowGiaoDan[GiaoDanConst.NoiRuocLe]);
                            excel.Write_to_excel(GiaoDanConst.ChaRuocLe, rowGiaoDan[GiaoDanConst.ChaRuocLe]);

                            excel.Write_to_excel(HonPhoiConst.SoHonPhoi, rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.SoHonPhoi] : "");
                            excel.Write_to_excel(HonPhoiConst.NgayHonPhoi, rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.NgayHonPhoi] : "");
                            excel.Write_to_excel(HonPhoiConst.NoiHonPhoi, rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.NoiHonPhoi] : "");
                            excel.Write_to_excel("ChaHonPhoi", rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.LinhMucChung] : "");
                            excel.Write_to_excel(HonPhoiConst.CachThucHonPhoi, rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.CachThucHonPhoi] : "");
                            excel.Write_to_excel(HonPhoiConst.VoChong, rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.VoChong] : "");
                            excel.Write_to_excel("GhiChuHonPHoi", rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.GhiChu] : "");
                            excel.Write_to_excel("NgaySinhVoChong", rowHonPhoi != null ? rowHonPhoi["NgaySinhVoChong"] : "");

                            if (rowGiaoDan[GiaoDanConst.NgayRuaToi].ToString().Length >= 4)
                            {
                                excel.Write_to_excel("NamRuaToi", rowGiaoDan[GiaoDanConst.NgayRuaToi].ToString().Substring(rowGiaoDan[GiaoDanConst.NgayRuaToi].ToString().Length - 4));
                            }
                            if (rowGiaoDan[GiaoDanConst.NgayThemSuc].ToString().Length >= 4)
                            {
                                excel.Write_to_excel("NamThemSuc", rowGiaoDan[GiaoDanConst.NgayThemSuc].ToString().Substring(rowGiaoDan[GiaoDanConst.NgayThemSuc].ToString().Length - 4));
                            }
                            if (rowGiaoDan[GiaoDanConst.NgayRuocLe].ToString().Length >= 4)
                            {
                                excel.Write_to_excel("NamRuocLe", rowGiaoDan[GiaoDanConst.NgayRuocLe].ToString().Substring(rowGiaoDan[GiaoDanConst.NgayRuocLe].ToString().Length - 4));
                            }
                            if (rowHonPhoi != null && rowHonPhoi[HonPhoiConst.NgayHonPhoi].ToString().Length >= 4)
                            {
                                excel.Write_to_excel("NamHonPhoi", rowHonPhoi[HonPhoiConst.NgayHonPhoi].ToString().Substring(rowHonPhoi[HonPhoiConst.NgayHonPhoi].ToString().Length - 4));
                            }

                            excel.Write_to_excel(ReportChungNhanBTConst.LyDo, rowGiaoXuNhan != null ? rowGiaoXuNhan[ReportChungNhanBTConst.LyDo] : "");
                            excel.Write_to_excel(ReportChungNhanBTConst.TenLinhMucNhan, rowGiaoXuNhan != null ? rowGiaoXuNhan[ReportChungNhanBTConst.TenLinhMucNhan] : "");
                            excel.Write_to_excel(ReportChungNhanBTConst.TenGiaoXuNhan, rowGiaoXuNhan != null ? rowGiaoXuNhan[ReportChungNhanBTConst.TenGiaoXuNhan] : "");
                            excel.Write_to_excel(ReportChungNhanBTConst.TenGiaoPhanNhan, rowGiaoXuNhan != null ? rowGiaoXuNhan[ReportChungNhanBTConst.TenGiaoPhanNhan] : "");

                            if (Memory.GetConfig(GxConstants.CF_LANGUAGE).ToString() == GxConstants.LANG_EN)
                            {
                                excel.Write_to_excel(ReportGiaoDanConst.NgayThangNam, Memory.GetReportNgayThangNamEn());
                            }
                            else
                            {
                                excel.Write_to_excel(ReportGiaoDanConst.NgayThangNam, Memory.GetReportNgayThangNamVn());
                            }
                            excel.End_Write();

                            System.Diagnostics.Process.Start(outputPath);
                        }
                        catch (Exception ex)
                        {
                            Memory.Instance.Error = ex;
                        }
                    }
                    else
                    {
                        Memory.Instance.Error = new Exception("Xuất giới thiệu thất bại." + Environment.NewLine +
                                                              "Có thể bạn chưa cài MS Office 2003 trở lên" + Environment.NewLine +
                                                              "Có thể do tập tin \"BiTich.xls\" trong thư mục Template của chương trình đang được mở" + Environment.NewLine +
                                                              "Xin vui lòng đóng tập tin này và thử lại lần nữa");
                        return(-1);
                    }
                }
            }
            catch (Exception ex)
            {
                Memory.Instance.Error = ex;
                return(-1);
            }
            finally
            {
                if (excel != null)
                {
                    excel.End_Write();
                }
                if (word != null)
                {
                    word.End_Write();
                }
            }
            return(0);
        }
示例#9
0
        public static int Export(DataSet ds)
        {
            ExcelEngine excel = new ExcelEngine();

            try
            {
                if (!ds.Tables.Contains(GiaoXuConst.TableName) || !ds.Tables.Contains(ReportRaoHonPhoiConst.TableName))
                {
                    Memory.Instance.Error = new Exception("Không có dữ liệu làm việc!");
                    return(-1);
                }

                DataTable tblReportRaoHonPhoi = ds.Tables[ReportRaoHonPhoiConst.TableName];
                DataTable tblGiaoXu           = ds.Tables[GiaoXuConst.TableName];
                //Get template and output path
                if (tblGiaoXu.Rows.Count == 0 || tblReportRaoHonPhoi.Rows.Count == 0)
                {
                    return(-1);
                }
                string templatePath = Memory.GetReportTemplatePath(GxConstants.REPORT_RAOHONPHOI_FILENAME);
                string outputPath   = Memory.GetTempPath(GxConstants.REPORT_RAOHONPHOI_FILENAME);
                //Get working row
                DataRow rowGiaoXu = tblGiaoXu.Rows[0];
                DataRow rowData   = tblReportRaoHonPhoi.Rows[0];

                if (excel.CreateObject(outputPath, templatePath))
                {
                    try
                    {
                        excel.LoaiBaoCao = ReportType.RaoHonPhoi;
                        excel.Write_to_excel(GiaoPhanConst.TenGiaoPhan, rowGiaoXu[GiaoPhanConst.TenGiaoPhan]);
                        excel.Write_to_excel(GiaoHatConst.TenGiaoHat, rowGiaoXu[GiaoHatConst.TenGiaoHat]);
                        excel.Write_to_excel(GiaoXuConst.TenGiaoXu, rowGiaoXu[GiaoXuConst.TenGiaoXu]);
                        excel.Write_to_excel(GiaoXuConst.DiaChi, rowGiaoXu[GiaoXuConst.DiaChi]);

                        foreach (DataColumn col in tblReportRaoHonPhoi.Columns)
                        {
                            excel.Write_to_excel(col.ColumnName, rowData[col]);
                        }

                        excel.End_Write();
                        System.Diagnostics.Process.Start(outputPath);
                    }
                    catch (Exception ex)
                    {
                        Memory.Instance.Error = ex;
                    }
                }
                else
                {
                    Memory.Instance.Error = new Exception("Xuất rao hôn phối thất bại." + Environment.NewLine +
                                                          "Có thể bạn chưa cài MS Office 2003 trở lên" + Environment.NewLine +
                                                          "Có thể do tập tin \"RaoHonPhoi.xls\" trong thư mục Template của chương trình đang được mở" + Environment.NewLine +
                                                          "Xin vui lòng đóng tập tin này và thử lại lần nữa");
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                if (excel != null)
                {
                    excel.End_Write();
                }
                Memory.Instance.Error = ex;
                return(-1);
            }
            return(0);
        }