public static void InChungNhanBiTich(int maGiaoDan, LoaiBiTich loaiBiTich) { Memory.Instance.SetMemory(GxConstants.CURRENT_REPORT, loaiBiTich); GetDataChungNhanBiTich(maGiaoDan); int rs = ExcelReport.ReportChungNhanBT.Export(ds); Memory.ShowError(); Memory.Instance.SetMemory(GxConstants.CURRENT_REPORT, null); }
public void XuatChungNhanMotBiTich(LoaiBiTich loaiBiTich) { if (this.CurrentRow == null || (this.CurrentRow.DataRow as DataRowView) == null) { return; } DataRow row = (this.CurrentRow.DataRow as DataRowView).Row; InChungNhanBiTich((int)row[GiaoDanConst.MaGiaoDan], loaiBiTich); }
private DataRow GetDotBiTich(DataTable tblDotBiTich, LoaiBiTich loaiBitich, string tenLinhMuc, string ngay, string noiBitich) { string tenLMLower = tenLinhMuc.ToLower(); string ngaySo = Memory.GetIntOfDateFrom(ngay); foreach (DataRow row in tblDotBiTich.Rows) { string sdate = Memory.GetIntOfDateFrom(row[DotBiTichConst.NgayBiTich].ToString()); if (row[DotBiTichConst.LinhMuc].ToString().ToLower().Equals(tenLMLower) && (int)row[DotBiTichConst.LoaiBiTich] == (int)loaiBitich && sdate.CompareTo(ngaySo) == 0 ) { return(row); } } DataRow newRow = tblDotBiTich.NewRow(); newRow[DotBiTichConst.LinhMuc] = tenLinhMuc; newRow[DotBiTichConst.LoaiBiTich] = (int)loaiBitich; newRow[DotBiTichConst.MaDotBiTich] = Memory.Instance.GetNextId(DotBiTichConst.TableName, DotBiTichConst.MaDotBiTich, false); newRow[DotBiTichConst.NgayBiTich] = ngay; newRow[DotBiTichConst.NoiBiTich] = noiBitich; newRow[DotBiTichConst.UpdateDate] = DateTime.Now; //tao mo ta cho dot bi tich DateDTO dateDTO = Memory.GetDatePart(ngay); string mota = string.Format("Đợt bí tích{0}{1}{2}", dateDTO.Day != "" ? " ngày " + dateDTO.Day : "", dateDTO.Month != "" ? " tháng " + dateDTO.Month : "", dateDTO.Year != "" ? " năm " + dateDTO.Year : ""); newRow[DotBiTichConst.MoTa] = mota; tblDotBiTich.Rows.Add(newRow); tongDotBiTich++; return(newRow); }
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); }