public static void XuatLyLichCaNhan(int maGiaoDan, int vaiTro) { GetDataChungNhanBiTich(maGiaoDan); string strVaiTro = GetVaiTroText(vaiTro); if (!string.IsNullOrEmpty(strVaiTro)) { strVaiTro = string.Format("Quan hệ GĐ: {0}", strVaiTro); } WordEngine word = ExcelReport.ReportLyLichCaNhan.Export(ds, strVaiTro, null); word.End_Write(); if (System.IO.File.Exists(word.FileName)) { System.Diagnostics.Process.Start(word.FileName); } Memory.ShowError(); }
public static void XuatLyLichCaNhan(Dictionary <int, int> dicMaGiaoDan) { if (dicMaGiaoDan != null && dicMaGiaoDan.Count > 0) { WordEngine word = null; int i = 0; foreach (var item in dicMaGiaoDan) { var maGiaoDan = item.Key; var vaiTro = item.Value; GetDataChungNhanBiTich(maGiaoDan); string strVaiTro = GetVaiTroText(vaiTro); if (!string.IsNullOrEmpty(strVaiTro)) { strVaiTro = string.Format("Quan hệ GĐ: {0}", strVaiTro); } if (word == null) { word = ExcelReport.ReportLyLichCaNhan.Export(ds, strVaiTro, word); } else { ExcelReport.ReportLyLichCaNhan.Export(ds, strVaiTro, word); } Memory.ShowError(); if (i < dicMaGiaoDan.Count - 1) { word.MoveEnd(); word.InsertPage(); word.MoveEnd(); } i++; } word.End_Write(); if (System.IO.File.Exists(word.FileName)) { System.Diagnostics.Process.Start(word.FileName); } } }
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); }
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); }
public Word_Engine_Tests() { wordEngine = new WordEngine(); }
public static void Initialize() { wordEngine = new WordEngine(OnlineManager.Word_Server.Words); }
static void Main(string[] args) { try { Bootstrapper.Initialize(); fileHandler = InjectFactory.Resolve <IFileHandler>(); wordEngine = InjectFactory.Resolve <IWordEngine <IWord> >(); Word startWord; Word targetWord; int wordsLength = Convert.ToInt32(ConfigurationManager.AppSettings.Get("WordsLenght")); string filePath = ConfigurationManager.AppSettings.Get("InputFilePath"); string resultfile; Console.WriteLine(string.Format("Enter start word: ")); startWord = new Word(Console.ReadLine()); Console.WriteLine(string.Format("Enter target Word: ")); targetWord = new Word(Console.ReadLine()); Console.WriteLine(Environment.NewLine); if (!startWord.HasSameLength(targetWord)) { Console.WriteLine("Both words need to have same lenght."); } if (!startWord.IsValid() && !targetWord.IsValid()) { throw new Exception("One words is invalid."); } if (startWord.Value.Length != wordsLength || targetWord.Value.Length != wordsLength) { throw new Exception($"Both words need to have {wordsLength} of length"); } resultfile = startWord.Value + targetWord.Value + ".txt"; originalWords = fileHandler.LoadDictionaryContent(wordsLength).ToList() .Select(x => new Word(x.ToLower())).ToList(); Console.WriteLine($"Word dictionary: {filePath} Loaded"); WordEngine engine = new WordEngine(); IEnumerable <IWord> sPath = engine.FindPath(startWord, targetWord, originalWords); sPath.ToList().ForEach(x => Console.WriteLine(x.Value)); IEnumerable <string> output = sPath.Select(x => x.Value); fileHandler.SaveOutputFile(resultfile, output); Console.WriteLine($"Output file is {resultfile}"); Console.WriteLine("Press some key to exit"); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
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); }
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); }
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); }
public static WordEngine Export(DataSet ds, string vaiTro, WordEngine mainDoc) { 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(null); } 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(null); } LoaiBiTich loaiBiTich = Memory.Instance.GetMemory(GxConstants.CURRENT_REPORT) == null ? LoaiBiTich.TatCa : (LoaiBiTich)Memory.Instance.GetMemory(GxConstants.CURRENT_REPORT); string fileName = GxConstants.REPORT_LYLICH_CANHAN_FILENAME; 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 = "............."; word = new WordEngine(); if (word.CreateObject(outputPath, templatePath)) { try { //Giao xu 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(ReportGiaoDanConst.TenLinhMucGui, rowGiaoXu[ReportGiaoDanConst.TenLinhMucGui]); //Giao ho string tenGiaoHo = rowGiaoDan[GiaoHoConst.TenGiaoHo].ToString(); if (!Memory.IsNullOrEmpty(rowGiaoDan["TenGiaoHoCha"]) && rowGiaoDan["TenGiaoHoCha"].ToString().ToLower().CompareTo(tenGiaoHo.ToLower()) != 0) { tenGiaoHo = string.Format("{0} - {1}", rowGiaoDan["TenGiaoHoCha"], tenGiaoHo); } word.Replace(GiaoHoConst.TenGiaoHo, tenGiaoHo); //Giao dan - thong tin co ban word.Replace(GiaoDanConst.MaGiaoDan, rowGiaoDan[GiaoDanConst.MaGiaoDan], 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(GiaoDanConst.Phai, rowGiaoDan[GiaoDanConst.Phai], defaultValue); word.Replace(ThanhVienGiaDinhConst.VaiTro, vaiTro, ""); 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); //Thong tin khac word.Replace("DiaChiGiaoDan", rowGiaoDan[GiaoDanConst.DiaChi], defaultValue); word.Replace("DienThoaiGiaoDan", rowGiaoDan[GiaoDanConst.DienThoai], defaultValue); word.Replace("EmailGiaoDan", rowGiaoDan[GiaoDanConst.Email], defaultValue); word.Replace("DanToc", rowGiaoDan[GiaoDanConst.DanToc], defaultValue); word.Replace("NgheNghiep", rowGiaoDan[GiaoDanConst.NgheNghiep], defaultValue); word.Replace("TrinhDoVanHoa", rowGiaoDan[GiaoDanConst.TrinhDoVanHoa], defaultValue); word.Replace("ConHoc", (bool)rowGiaoDan[GiaoDanConst.ConHoc] ? "[x]" : "[ ]", ""); word.Replace("TanTong", (bool)rowGiaoDan[GiaoDanConst.TanTong] ? "[x]" : "[ ]", ""); word.Replace("DaCoGiaDinh", (bool)rowGiaoDan[GiaoDanConst.DaCoGiaDinh] ? "[x]" : "[ ]", ""); if ((bool)rowGiaoDan[GiaoDanConst.QuaDoi]) { word.Replace("QuaDoi", (bool)rowGiaoDan[GiaoDanConst.QuaDoi] ? "[x]" : "[ ]", ""); word.Replace("NgayQuaDoi", Memory.IsNullOrEmpty(rowGiaoDan[GiaoDanConst.NgayQuaDoi]) ? "" : string.Concat("Ngày: ", rowGiaoDan[GiaoDanConst.NgayQuaDoi]), ""); word.Replace("NoiAnTang", Memory.IsNullOrEmpty(rowGiaoDan[GiaoDanConst.NoiAnTang]) ? "" : string.Concat("An táng tại: ", rowGiaoDan[GiaoDanConst.NoiAnTang]), ""); word.Replace("SoAnTang", Memory.IsNullOrEmpty(rowGiaoDan[GiaoDanConst.SoAnTang]) ? "" : string.Concat(" Số: ", rowGiaoDan[GiaoDanConst.SoAnTang]), ""); } else { word.Replace("QuaDoi", "[ ]", ""); word.Replace("NoiAnTang", "", ""); word.Replace("SoAnTang", "", ""); word.Replace("NgayQuaDoi", "", ""); } word.Replace(GiaoDanConst.ChaRuocLe, rowGiaoDan[GiaoDanConst.ChaRuocLe], defaultValue); //Hon Phoi 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.NguoiChung1, rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.NguoiChung1] : "", defaultValue); word.Replace(HonPhoiConst.NguoiChung2, rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.NguoiChung2] : "", defaultValue); word.Replace("GhiChuHonPHoi", rowHonPhoi != null ? rowHonPhoi[HonPhoiConst.GhiChu] : "", defaultValue); if (Memory.GetConfig(GxConstants.CF_LANGUAGE).ToString() == GxConstants.LANG_EN) { word.Replace(ReportGiaoDanConst.NgayThangNam, Memory.GetReportNgayThangNamEn()); } else { word.Replace(ReportGiaoDanConst.NgayThangNam, Memory.GetReportNgayThangNamVn()); } if (mainDoc == null) { //System.Diagnostics.Process.Start(outputPath); word.Save(); //word.AllowVisible = true; } else { word.SelectAll(); word.Copy(); mainDoc.Paste(); mainDoc.Save(); word.End_Write(); System.IO.File.Delete(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(null); } } catch (Exception ex) { Memory.Instance.Error = ex; if (word != null) { word.End_Write(); } word = null; return(null); } finally { if (word != null && mainDoc != null && System.IO.File.Exists(word.FileName)) { word.End_Write(); } } return(word); }