基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
using Lskj.Business;
|
||||
using Lskj.Business.Impl;
|
||||
using Lskj.Control;
|
||||
using Lskj.Core;
|
||||
using Lskj.Model;
|
||||
using Lskj.Util;
|
||||
using Spire.Doc;
|
||||
using Spire.Doc.Documents;
|
||||
using Spire.Doc.Fields;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Lskj.AutoWordFile
|
||||
{
|
||||
public partial class FrmMain : BaseForm
|
||||
{
|
||||
private bool NewInitSuccess = false;
|
||||
private int fileCount;
|
||||
/// <summary>
|
||||
/// 基础对象
|
||||
/// </summary>
|
||||
public ModuleModel ModuleModel;
|
||||
/// <summary>
|
||||
/// 本地打开word路径
|
||||
/// </summary>
|
||||
public string WordPath;
|
||||
/// <summary>
|
||||
/// 调用动态链接库默认传递参数
|
||||
/// </summary>
|
||||
public DynamicAutoCreate Model;
|
||||
// 可替换模板文档
|
||||
public Document document;
|
||||
// 替换的数据集合
|
||||
public DataSet ds;
|
||||
/// <summary>
|
||||
/// 模块编号
|
||||
/// </summary>
|
||||
public string ModelCode;
|
||||
|
||||
public FrmMain()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.Load += OnFrmMainLoad;
|
||||
}
|
||||
/// <summary>
|
||||
/// 窗口初始化
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnFrmMainLoad(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
string mainTempPath = $@"{PubUtil.AbsolutelyPath}\WordFile\{Model.MainTempPath}.doc";
|
||||
if (!File.Exists(mainTempPath))
|
||||
{
|
||||
mainTempPath = $@"{PubUtil.AbsolutelyPath}\WordFile\{Model.MainTempPath}.docx";
|
||||
if (!File.Exists(mainTempPath))
|
||||
{
|
||||
//throw new Exception($"模板文件{mainTempPath}不存在");
|
||||
}
|
||||
else
|
||||
{
|
||||
Model.MainTempPath = $"{Model.MainTempPath}.docx";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Model.MainTempPath = $"{Model.MainTempPath}.doc";
|
||||
}
|
||||
string menuTempPath = $@"{PubUtil.AbsolutelyPath}\WordFile\{Model.MenuTempPath}.doc";
|
||||
if (!File.Exists(menuTempPath))
|
||||
{
|
||||
menuTempPath = $@"{PubUtil.AbsolutelyPath}\WordFile\{Model.MenuTempPath}.docx";
|
||||
if (!File.Exists(menuTempPath))
|
||||
{
|
||||
//throw new Exception($"模板文件{menuTempPath}不存在");
|
||||
}
|
||||
else
|
||||
{
|
||||
Model.MenuTempPath = $"{Model.MenuTempPath}.doc";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Model.MenuTempPath = $"{Model.MenuTempPath}.doc";
|
||||
}
|
||||
string fileName = Path.GetFileName(Model.MainTempPath);
|
||||
fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + "word文档" + fileName;
|
||||
string saveFilePath = $@"{PubUtil.AbsolutelyPath}\Tempfiles\{fileName}";
|
||||
string savePdfPath = $@"{Path.GetDirectoryName(saveFilePath)}\{Path.GetFileNameWithoutExtension(saveFilePath)}.doc";
|
||||
CancellationTokenSource cts = new CancellationTokenSource();
|
||||
CancellationToken token = cts.Token;
|
||||
Task progressTask = new Task(() =>
|
||||
{
|
||||
for (int i = 1; i <= 99; i++)
|
||||
{
|
||||
token.ThrowIfCancellationRequested();
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
progressBar1.Value = i;
|
||||
}));
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}, token);
|
||||
progressTask.Start();
|
||||
Task crateTask = new Task(() =>
|
||||
{
|
||||
AutoCreatWord.CreateWordUtil.DbOperator = new Lskj.Data.ADO.Template.DbTemplate(string.Format("server={0};database={1};persist security info=true;user id=lserpAdmin;password=lserp110;max pool size = 512;", DBConfig.Instance.ServerName, DBConfig.Instance.DataBase), "system.data.sqlclient");
|
||||
AutoCreatWord.CreateWordUtil.Create(mainTempPath, menuTempPath, Model.MenuTempArray, SqlHelper.ExecuteDataSet(Model.MasterSql), savePdfPath, SystemInfo.Instance.OAUrl, out string msg);
|
||||
cts.Cancel();
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
progressBar1.Value = 100;
|
||||
Process.Start(savePdfPath);
|
||||
Close();
|
||||
}));
|
||||
}
|
||||
});
|
||||
crateTask.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user