基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,537 @@
|
||||
using Lskj.Business;
|
||||
using Lskj.Business.Impl;
|
||||
using Lskj.Control;
|
||||
using Lskj.Control.Model;
|
||||
using Lskj.Core;
|
||||
using Lskj.Data;
|
||||
using Lskj.Model;
|
||||
using Lskj.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Printing;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Lskj.PubPrint
|
||||
{
|
||||
public partial class Form1 : DevExpress.XtraEditors.XtraForm
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
if (DBConfig.Instance.CreateConnection())
|
||||
{
|
||||
InitializeComponent();
|
||||
if (DelphiHelper.Delphi_Init(new StringBuilder(DBConfig.Instance.GetDelphiConnection())) == 0)
|
||||
{
|
||||
MessageUtil.Show(ResourceKeys.UnConnectServer + "[By Delphi]");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
private object _objLock = new object();
|
||||
/// <summary>
|
||||
/// 日志队列
|
||||
/// </summary>
|
||||
private Queue<DataRow> _logQueue = new Queue<DataRow>();
|
||||
/// <summary>
|
||||
/// 日志队列锁
|
||||
/// </summary>
|
||||
private object _queueLock = new object();
|
||||
/// <summary>
|
||||
/// 用于判断是否加载完成就刷新
|
||||
/// </summary>
|
||||
int Count = 0;
|
||||
/// <summary>
|
||||
/// 用于判断是否加载完成就刷新
|
||||
/// </summary>
|
||||
bool flog = false;
|
||||
/// <summary>
|
||||
/// 设置刷新时间
|
||||
/// </summary>
|
||||
private string Timer;
|
||||
/// <summary>
|
||||
/// 设置sql表格数据
|
||||
/// </summary>
|
||||
private string Sql;
|
||||
/// <summary>
|
||||
/// 创建ini文件
|
||||
/// </summary>
|
||||
IniFiles ini = new IniFiles(Application.StartupPath + @"\MyConfig.INI");
|
||||
/// <summary>
|
||||
/// 临时表
|
||||
/// </summary>
|
||||
DataTable copydt = new DataTable();
|
||||
/// <summary>
|
||||
/// 查询条件
|
||||
/// </summary>
|
||||
public string condition;
|
||||
/// <summary>
|
||||
/// 多打印机筛选
|
||||
/// </summary>
|
||||
public string PrintScreen = string.Empty;
|
||||
/// <summary>
|
||||
/// 打印机列表
|
||||
/// </summary>
|
||||
List<string> PrinList = new List<string>();
|
||||
/// <summary>
|
||||
/// 查询条件
|
||||
/// </summary>
|
||||
public string SortField = string.Empty;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化程序
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Initialization();
|
||||
InitialGridFormat();
|
||||
//// 创建后台线程
|
||||
//Thread backThread = new Thread(ObtainPrint);
|
||||
//backThread.IsBackground = true;
|
||||
//backThread.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 打印成功判断
|
||||
/// </summary>
|
||||
public int PrintFlag;
|
||||
/// <summary>
|
||||
/// 设置表格名称
|
||||
/// </summary>
|
||||
private void InitialGridFormat()
|
||||
{
|
||||
this.gridView1.OptionsView.ColumnAutoWidth = false;
|
||||
this.gridView2.OptionsView.ColumnAutoWidth = false;
|
||||
Afterprint.DataSource = SqlHelper.ExecuteDataTable(string.Format("{0} {1} printFlag = 1 {2} {3}", Sql, condition, PrintScreen, SortField));
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取需要打印表格
|
||||
/// </summary>
|
||||
public void ObtainPrint()
|
||||
{
|
||||
this.Invoke(new EventHandler(delegate
|
||||
{
|
||||
DataTable DT = SqlHelper.ExecuteDataTable(string.Format("{0} {1} printFlag = 0 {2} {3}", Sql, condition, PrintScreen, SortField));
|
||||
copydt = DT.Copy();
|
||||
flog = false;
|
||||
this.timer1.Enabled = false;
|
||||
Dictionary<DataRow, List<Task<DataTable>>> sqlSourceDic = new Dictionary<DataRow, List<Task<DataTable>>>();
|
||||
foreach (DataRow item in DT.Rows)
|
||||
{
|
||||
string printSQL = ReplaceHelper.ReplaceRowParam(item, item["printSQL"] + "");
|
||||
string dllName = item["libaryName"] + "";
|
||||
List<Task<DataTable>> dataTableTasks = new List<Task<DataTable>>();
|
||||
if (dllName.Equals("Lskj.FastReportDesign.dll", StringComparison.CurrentCultureIgnoreCase))//匹配frx调用打印
|
||||
{
|
||||
List<string> tmpSqls = printSQL.Split(';').ToList();
|
||||
foreach (string sql in tmpSqls)
|
||||
{
|
||||
Task<DataTable> task = new Task<DataTable>(() =>
|
||||
{
|
||||
DataTable dataTable = new DataTable();
|
||||
string index = tmpSqls.IndexOf(sql) + "";
|
||||
if (!string.IsNullOrEmpty(sql))
|
||||
{
|
||||
dataTable = BaseImpl.GetDataTableResult(sql).Copy();
|
||||
dataTable.TableName = "temp" + index;
|
||||
}
|
||||
return dataTable;
|
||||
});
|
||||
task.Start();
|
||||
dataTableTasks.Add(task);
|
||||
}
|
||||
}
|
||||
sqlSourceDic.Add(item, dataTableTasks);
|
||||
}
|
||||
foreach (DataRow item in DT.Rows)
|
||||
{
|
||||
PrintFlag = 0;
|
||||
try
|
||||
{
|
||||
bool over = false;
|
||||
string msg = "";
|
||||
Thread t = new Thread(() =>
|
||||
{
|
||||
KeyValuePair<DataRow, List<Task<DataTable>>> keyValuePair = sqlSourceDic.Where(n => n.Key == item).FirstOrDefault();
|
||||
StartPrint(keyValuePair, out msg);
|
||||
over = true;
|
||||
});
|
||||
t.SetApartmentState(ApartmentState.STA);
|
||||
t.Start();
|
||||
t.Join();
|
||||
while (!over)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
if (PrintFlag == 1)
|
||||
{
|
||||
RefreshLogUIThread(msg + "\r\n" + DateTime.Now + "模块" + item["id"].ToString() + "打印失败!\r\n");
|
||||
string sqlValue = string.Format("update p_SystemPrintTaskTab set printFlag = 1,printTime='{1}',msg='{2}' where id='{0}'", item["id"], DateTime.Now.ToString(), "打印机条件出错!");
|
||||
SqlHelper.ExecuteNonQuery(sqlValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
RefreshLogUIThread(DateTime.Now + "" + "模块" + item["id"] + "打印成功!" + "\r\n");
|
||||
string sqlValue = string.Format("update p_SystemPrintTaskTab set printFlag = 1,printTime='{1}' where id='{0}'", item["id"], DateTime.Now.ToString());
|
||||
SqlHelper.ExecuteNonQuery(sqlValue);
|
||||
}
|
||||
if (copydt.Rows.Count > 0)
|
||||
{
|
||||
copydt.Rows.RemoveAt(0);
|
||||
}
|
||||
Afterprint.DataSource = SqlHelper.ExecuteDataTable(string.Format("{0} {1} printFlag=1 {2} {3}", Sql, condition, PrintScreen, SortField));
|
||||
this.PrintTable.DataSource = copydt;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RefreshLog(DateTime.Now + "打印失败.\r\n" + ex);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
/// <summary>
|
||||
/// 开始打印
|
||||
/// </summary>
|
||||
public void StartPrint(KeyValuePair<DataRow, List<Task<DataTable>>> keyValuePair, out string msg)
|
||||
{
|
||||
DataRow item = keyValuePair.Key;
|
||||
List<Task<DataTable>> dataTableTasks = keyValuePair.Value;
|
||||
//DataTable dt=SqlHelper.ExecuteDataTable(string.Format("select PrintAddress from p_systemComputerTab where PrintName='{0}'", item["printerName"]));
|
||||
//String PrintAddress=dt.Rows.Count>0?dt.Rows[0]["PrintAddress"]+"":string.Empty;
|
||||
//if (!PrinList.Contains(PrintAddress)) {
|
||||
// PrintFlag = 1;
|
||||
// return;
|
||||
//}
|
||||
try
|
||||
{
|
||||
msg = "";
|
||||
string printSQL = ReplaceHelper.ReplaceRowParam(item, item["printSQL"] + "");
|
||||
int num = int.Parse(item["PrintCount"] + "");
|
||||
string dllName = item["libaryName"] + "";
|
||||
string printerName = item["printerName"] + "";
|
||||
if (dllName.Equals("Lskj.FastReportDesign.dll", StringComparison.CurrentCultureIgnoreCase))//匹配frx调用打印
|
||||
{
|
||||
List<string> tmpSqls = printSQL.Split(';').ToList();
|
||||
PrintUtil.FastReportPrint(tmpSqls, item["printModuleName"] + "", true, printerName, dataTableTasks);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (num > 1)
|
||||
{
|
||||
DelphiHelper.LoadDelphiDll(PubUtil.AbsolutelyPath + "Lib\\" + item["libaryName"], item["libaryName"] + "", item["printModuleName"] + "", item["printSQL"] + "", printSQL, Convert.ToInt32(3), item["printSQL"] + "");
|
||||
item["PrintCount"] = num - 1;
|
||||
StartPrint(keyValuePair, out msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
DelphiHelper.LoadDelphiDll(PubUtil.AbsolutelyPath + "Lib\\" + item["libaryName"], item["libaryName"] + "", item["printModuleName"] + "", item["printSQL"] + "", printSQL, Convert.ToInt32(3), item["printSQL"] + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
msg = ex.Message;
|
||||
PrintFlag = 1;
|
||||
}
|
||||
}
|
||||
public void Initialization()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
RefreshLog(DateTime.Now + "正在初始化平台.\r\n");
|
||||
|
||||
//判断当前程序是否已经有在允许的,有就关闭当前程序
|
||||
Process[] processes = Process.GetProcessesByName("Lskj.PubPrint");
|
||||
if (processes.Length > 1)
|
||||
{
|
||||
//MessageUtil.Show("已有打开的当前程序");
|
||||
System.Environment.Exit(0);
|
||||
}
|
||||
|
||||
|
||||
if (DBConfig.Instance.CreateConnection())
|
||||
{
|
||||
string ip = string.Empty;
|
||||
//得到本机名
|
||||
//ERPInfo.Instance.WindowName "SERVER-T"
|
||||
string hostname = ERPInfo.Instance.WindowName;
|
||||
//解析主机名称或IP地址的system.net.iphostentry实例。
|
||||
//IPHostEntry localhost = Dns.GetHostEntry(hostname);
|
||||
ip = ERPInfo.Instance.LoginIP;
|
||||
//hostname = "PC-20210908GGIV";
|
||||
DataTable dt = SqlHelper.ExecuteDataTable(string.Format("select * from p_systemComputerTab where ComputerName='{0}'", hostname));
|
||||
|
||||
//foreach (string ss in PrinterSettings.InstalledPrinters)
|
||||
//{
|
||||
// ///在列表框中列出所有的打印机,
|
||||
// PrinList.Add(ss);
|
||||
//}
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
MessageUtil.Show("未配置权限,请联系朗速工作人员!");
|
||||
// 关闭所有的线程
|
||||
System.Environment.Exit(0);
|
||||
}
|
||||
RefreshLog(DateTime.Now + "初始化平台成功.\r\n");
|
||||
string print = dt.Rows[0]["PrintName"].ToString();
|
||||
PrintScreen = print != null ? string.Format("and printerName='{0}'", print) : null;
|
||||
|
||||
if (dt.Columns.Contains("SortField"))
|
||||
{
|
||||
SortField = dt.Rows[0]["SortField"].ToString();
|
||||
}
|
||||
|
||||
|
||||
//获取ini配置的值
|
||||
string time = ini.IniReadValue("刷新时间", "Timer");
|
||||
Timer = string.IsNullOrWhiteSpace(time) ? "1000" : time;
|
||||
string sql = ini.IniReadValue("刷新时间", "Sql");
|
||||
Sql = !string.IsNullOrWhiteSpace(sql) ? ini.IniReadValue("刷新时间", "Sql") : "select * from p_SystemPrintTaskTab with(nolock)";
|
||||
condition = Sql.Contains("where") ? "and" : "where";
|
||||
string sqlValue = string.Format("update p_systemComputerTab set ipAddress ='{0}' where ComputerName='{1}'", ip, hostname);
|
||||
SqlHelper.ExecuteNonQuery(sqlValue);
|
||||
this.timer1.Start();
|
||||
this.timer1.Interval = int.Parse(Timer) * 1000;
|
||||
this.timer2.Interval = 100;
|
||||
this.timer2.Start();
|
||||
if (ini.ExistINIFile())
|
||||
{
|
||||
txt_timer.Text = ini.IniReadValue("刷新时间", "Timer");
|
||||
lab_Sql.EditText = ini.IniReadValue("刷新时间", "Sql");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
RefreshLog(DateTime.Now + " 初始化平台失败.\r\n");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RefreshLog(DateTime.Now + string.Format("初始化失败.原因:{0}.\r\n", ex.Message));
|
||||
}
|
||||
}
|
||||
#region 设置后台线程
|
||||
/// <summary>
|
||||
/// 主线程刷新数据
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
public void RefreshLog(string msg)
|
||||
{
|
||||
txtLog.Text += msg;
|
||||
txtLog.Select(txtLog.TextLength, 0);
|
||||
txtLog.ScrollToCaret();
|
||||
}
|
||||
/// <summary>
|
||||
/// 后台线程刷新数据
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
public void RefreshLogUIThread(string msg)
|
||||
{
|
||||
Invoke((EventHandler)delegate
|
||||
{
|
||||
txtLog.Text += msg;
|
||||
txtLog.Select(txtLog.TextLength, 0);
|
||||
txtLog.ScrollToCaret();
|
||||
});
|
||||
}
|
||||
private void FileViewer(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Process.Start(fileName);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void timer1_Tick(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
ObtainPrint();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
}
|
||||
private void timer2_Tick(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (copydt != null)
|
||||
{
|
||||
if (copydt.Rows.Count == 0)
|
||||
{
|
||||
this.timer1.Enabled = true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 更改刷新时间
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void simpleButton1_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
//将ini文件清空
|
||||
ini.IniWriteValue(null, null, null);
|
||||
ini.IniWriteValue("刷新时间", "Timer", txt_timer.Text);
|
||||
ini.IniWriteValue("刷新时间", "Sql", lab_Sql.EditText);
|
||||
Initialization();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加双击托盘图标事件(双击显示窗口)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (WindowState == FormWindowState.Minimized)
|
||||
{
|
||||
//还原窗体显示
|
||||
WindowState = FormWindowState.Normal;
|
||||
//激活窗体并给予它焦点
|
||||
this.Activate();
|
||||
//任务栏区显示图标
|
||||
this.ShowInTaskbar = true;
|
||||
//托盘区图标隐藏
|
||||
notifyIcon1.Visible = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否最小化,然后显示托盘
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void F_Main_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
//判断是否选择的是最小化按钮
|
||||
if (WindowState == FormWindowState.Minimized)
|
||||
{
|
||||
//隐藏任务栏区图标
|
||||
this.ShowInTaskbar = false;
|
||||
//图标显示在托盘区
|
||||
notifyIcon1.Visible = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 确认是否退出
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void F_Main_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (MessageBox.Show("是否确认退出程序?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
|
||||
{
|
||||
// 关闭所有的线程
|
||||
this.Dispose();
|
||||
this.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void 打印查看ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataRow item = this.gridView2.GetFocusedDataRow();
|
||||
string printSQL = ReplaceHelper.ReplaceRowParam(item, item["printSQL2"] + "");
|
||||
DelphiHelper.LoadDelphiDll(PubUtil.AbsolutelyPath + "Lib\\" + item["libaryName"], item["libaryName"] + "", item["printModuleName"] + "", item["printSQL"] + "", printSQL, Convert.ToInt32(4), item["printSQL"] + "");
|
||||
RefreshLogUIThread(DateTime.Now + " 正在查看打印格式.\r\n");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void 打印回撤ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataRow item = this.gridView2.GetFocusedDataRow();
|
||||
string sqlValue = string.Format("update p_SystemPrintTaskTab set printFlag = 0 where id='{0}'", item["id"]);
|
||||
SqlHelper.ExecuteNonQuery(sqlValue);
|
||||
DataTable DT = SqlHelper.ExecuteDataTable(string.Format("{0} {1} printFlag = 1 {2} {3}", Sql, condition, PrintScreen, SortField));
|
||||
this.Afterprint.DataSource = DT;
|
||||
RefreshLogUIThread(DateTime.Now + " 打印已回退.\r\n");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user