using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using Lskj.Control;
using Lskj.Core;
using Lskj.Util;
using Lskj.Business.Impl;
using Lskj.Model;
using Lskj.Data;
using Lskj.Notice.Properties;
using DevExpress.XtraGrid;
using Lskj.Business;
namespace Lskj.Notice
{
///
/// 通知界面
///
public partial class FrmMain : BaseForm
{
string mUserID;
string mUserName;
string mUserPassword;
private bool blink = false;
private Icon blank = Resources.blank;
private Icon striped = Resources.logo;
private bool mouseinform = false;
private bool runForm = false;
private int LastRowCount;//上一次记录的行数
private bool FirstEntry = true;//是否是第一次进入
///
/// 语言设置,设置后为true
///
public bool LanguageSettings = false;
///
/// 语言
///
public string Language;
///
/// 语言设置,设置后为true
///
// public bool LanguageSettings = false;
public FrmMain(string[] args)
{
InitializeComponent();
this.gridView.DoubleClick += new EventHandler(OnGridViewDoubleClick);
if (args != null && args.Length > 1)
{
this.mUserID = args[0];
this.mUserName = args[1];
this.mUserPassword = args[2];
}
this.tsmiShowWindow.Checked = DBConfig.Instance.NoticeShowWindow;//新消息弹窗
this.tsmiFlicker.Checked = DBConfig.Instance.NoticeFlicker;//新消息闪烁
this.tsmiExitByMain.Checked = DBConfig.Instance.NoticeExit;//随主系统退出
}
///
/// 说明:显示窗口
/// 创建人:龚宇超
/// 创建日期:2019-09-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
void ThreadShowFrom()
{
int x = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
int y = Screen.PrimaryScreen.WorkingArea.Height - this.Height;
this.SetDesktopLocation(x, y);
//Point p = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height);
//this.PointToClient(p);
//this.Location = p;
//this.Show();
//for (int i = 0; i < this.Height; i++)
//{
// this.Location = new Point(p.X, p.Y - i);
// System.Threading.Thread.Sleep(1);
//}
}
///
/// 说明:显示普通窗口
/// 创建人:龚宇超
/// 创建日期:2019-09-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
void NormalShowForm()
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Activate();
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
this.notifyIcon1.Visible = false;
}
}
///
/// 说明:重新加载表格数据
/// 创建人:龚宇超
/// 创建日期:2019-09-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
void ReloadGridData()
{
DataTable data = null;
string sqlStr = string.Empty;
try
{
DBConfig.Instance.ReadConfig();
DBConfig.Instance.CreateConnection(DBConfig.Instance.Connection);
ERPInfo.Instance.UserId = DBConfig.Instance.NoticeUserID;
ERPInfo.Instance.UserName = DBConfig.Instance.NoticeUserName;
ERPInfo.Instance.Password = mUserPassword;
mUserName = DBConfig.Instance.NoticeUserName;
//判断是否存在多语种的情况
if (!LanguageSettings)
{
if (!string.IsNullOrWhiteSpace(ERPInfo.Instance.UserId))
{
string sql = string.Format("select useLanguage from P_EmployeeTab where EmployeeId='{0}'", ERPInfo.Instance.UserId);
this.Language = SqlHelper.ExecuteScalar(sql) + "";
if (string.IsNullOrWhiteSpace(this.Language)) this.Language = "中文";
ERPInfo.Instance.LanguageName = this.Language;
this.LanguageSettings = true;
}
}
data = NoticeImpl.GetNoticeData2(ERPInfo.Instance.UserId, out sqlStr);
}
catch (Exception)
{
}
//DataTable data = NoticeImpl.GetNoticeData2(ERPInfo.Instance.UserId, out sqlStr);
int rowCount = data == null ? 0 : data.Rows.Count;
this.gridControlEx.DataSource = data;
this.Text = "您有" + rowCount + "条任务需要处理(提示:双击即可处理).";
if (rowCount > 0)
{
// 开启新消息弹窗
if (this.tsmiShowWindow.Checked)
{
this.NormalShowForm();
}
// 开启、关闭新消息闪烁
if (FirstEntry)
{
this.blinkTimer.Enabled = this.tsmiFlicker.Checked;
FirstEntry = false;
}
//开启了闪烁,并且当前数量大于上一次数量,才闪烁
if (this.tsmiFlicker.Checked && rowCount > LastRowCount && this.timer3.Enabled)
{
this.blinkTimer.Enabled = this.tsmiFlicker.Checked;
}
LastRowCount = rowCount;
}
else
{
//this.WindowState = FormWindowState.Minimized;
this.blinkTimer.Enabled = false;
}
}
///
/// 打开基础或单据模块审批模块
///
void OpenAuditControl(DataRow rowItem)
{
try
{
bool isCustomNotice = false;
string BetweenDLLCoid = string.Empty;
String[] AutoParame = rowItem["dllname"].ToString().Split('^');
if (AutoParame.Count() >= 4)
{
rowItem["dllname"] = AutoParame[0];
rowItem["keyvalue"] = AutoParame[1];
rowItem["modulename"] = AutoParame[2];
if (AutoParame[0].Equals("MiniBlink.dll", StringComparison.CurrentCultureIgnoreCase) || AutoParame[0].Equals("Lskj.PubBrower.dll", StringComparison.CurrentCultureIgnoreCase))
{
BetweenDLLCoid = AutoParame[3];
}
else
{
rowItem["stepcode"] = AutoParame[3];
}
isCustomNotice = true;
}
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, rowItem["modulename"] + "", ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, 1, rowItem["moduleid"] + "").Split('~');
string[] menuArgs = new string[] { "0", rowItem["moduleid"] + "", rowItem["stepcode"] + "", rowItem["keyvalue"] + "", "0", "0" };
string dllName = rowItem["dllname"] + "";
dllName = dllName.ToLower();
switch (dllName)
{
case "lskj.baseinfo.dll":
menuArgs = new string[] { "1", rowItem["moduleid"] + "", rowItem["keyvalue"] + "" };
break;
case "lskj.pubbillinfo.dll":
menuArgs = new string[] { rowItem["moduleid"] + "", rowItem["keyvalue"] + "", rowItem["modulename"] + "", rowItem["stepcode"] + "" };
break;
case "lskj.pubbill.dll":
menuArgs = new string[] { "", rowItem["moduleid"] + "" };
break;
case "lskj.pubmoduledetail.dll":
menuArgs = new string[] { "", rowItem["moduleid"] + "" };
break;
case "miniblink.dll":
menuArgs = new string[] { "", rowItem["keyvalue"] + "", BetweenDLLCoid };
break;
case "pubbrower.dll":
menuArgs = new string[] { "", rowItem["keyvalue"] + "", BetweenDLLCoid };
break;
case "lskj.pubbrower.dll":
menuArgs = new string[] { "", rowItem["keyvalue"] + "", BetweenDLLCoid };
break;
}
if ("2".Equals(rowItem["messid"] + ""))
{
menuArgs = new string[] { "0", rowItem["moduleid"] + "", rowItem["stepcode"] + "", rowItem["keyvalue"] + "", "1", "0" };
}
string[] args = defaultArgs.Concat(menuArgs).ToArray();
IForm form = FormHelper.LoadDllForm(dllName, args);
if (dllName.Equals("miniblink.dll")) form.SubForm.WindowState = FormWindowState.Maximized;
if (dllName.Equals("lskj.pubmoduledetail.dll") || dllName.Equals("lskj.pubbill.dll")) form.SubForm.WindowState = FormWindowState.Maximized;//默认全部最大化
DialogResult result = form.SubForm.ShowDialog();
bool status = result != DialogResult.OK;
if (SystemInfo.Instance.EnableSpecialInfoProcess) status = result == DialogResult.OK;
if (status && ("1".Equals(rowItem["messid"] + "") || "2".Equals(rowItem["messid"] + "")))
{
//if ("2".Equals(rowItem["messid"] + ""))
//{
// NoticeImpl.UpdRemindField(rowItem, dllName);
//}
//return;
NoticeImpl.UpeNoticeData(rowItem, isCustomNotice);
string sqlStr = string.Empty;
DataTable data = NoticeImpl.GetNoticeData2(ERPInfo.Instance.UserId, out sqlStr);
int rowCount = data == null ? 0 : data.Rows.Count;
this.gridControlEx.DataSource = data;
this.Text = "您有" + rowCount + "条任务需要处理(提示:双击即可处理).";
}
form.SubForm.Dispose();
}
catch (Exception ex)
{
//MessageUtil.Show(ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message);
}
}
///
/// 说明:窗户加载
/// 创建人:龚宇超
/// 创建日期:2019-09-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
void OnMainLoad(object sender, EventArgs e)
{
try
{
DBConfig.Instance.CreateConnection();
if (!DBConfig.Instance.CreateConnection(DBConfig.Instance.Connection))
{
MessageUtil.Show(ResourceKeys.ServerAddressFault);
return;
}
else
{
if (DelphiHelper.Delphi_Init(new StringBuilder(DBConfig.Instance.GetDelphiConnection(DBConfig.Instance.dephiConnection))) == 0)
{
MessageUtil.Show(ResourceKeys.UnConnectServer + "[By Delphi]");
return;
}
}
if (!BaseImpl.HasExistsTable("p_systemNoticeSheet"))
{
NoticeImpl.CreationNoticeTable();
}
//判断是否存在多语种的情况
if (BaseImpl.HasExistsColumn("P_EmployeeTab", "useLanguage"))
{
if (!string.IsNullOrWhiteSpace(ERPInfo.Instance.UserId))
{
string sql = string.Format("select useLanguage from P_EmployeeTab where EmployeeId='{0}'", ERPInfo.Instance.UserId);
this.Language = SqlHelper.ExecuteScalar(sql) + "";
if (string.IsNullOrWhiteSpace(this.Language)) this.Language = "中文";
ERPInfo.Instance.LanguageName = this.Language;
this.LanguageSettings = true;
}
}
else
{
this.LanguageSettings = true;
this.Language = "中文";
}
SetDelphiDllParams();
this.tsmiFlicker.Checked = DBConfig.Instance.NoticeFlicker;
this.tsmiShowWindow.Checked = DBConfig.Instance.NoticeShowWindow;
string sqlStr = string.Empty;
DataTable data = NoticeImpl.GetNoticeData2(ERPInfo.Instance.UserId, out sqlStr);
int rowCount = data == null ? 0 : data.Rows.Count;
this.gridControlEx.DataSource = data;
this.Text = "您有" + rowCount + "条任务需要处理(提示:双击即可处理).";
this.ThreadShowFrom();
if (rowCount == 0)
this.WindowState = FormWindowState.Minimized;
if (SystemInfo.Instance.MessageRefreshTime > 0) this.timer3.Interval = SystemInfo.Instance.MessageRefreshTime * 1000;
if (SystemInfo.Instance.MessageFlicker) this.tsmiFlicker.Checked = DBConfig.Instance.NoticeFlicker = true;
if (SystemInfo.Instance.MessageRefreshTime > 0) OnTimerReloadTick(null,null);//设置了时间就先刷新一次
if (SystemInfo.Instance.MessageShowWindow) this.tsmiShowWindow.Checked = DBConfig.Instance.NoticeShowWindow = true;
if (SystemInfo.Instance.MessageExitByMain) this.tsmiExitByMain.Checked = DBConfig.Instance.NoticeExit = true;
this.timer3.Start();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message);
}
finally
{
Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this);
}
}
///
/// 说明:重新加载数据
/// 创建人:龚宇超
/// 创建日期:2019-09-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
void OnTimerReloadTick(object sender, EventArgs e)
{
try
{
if (!mouseinform && !runForm)
{
this.ReloadGridData();
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message);
}
}
///
/// 说明:点击打开审批界面
/// 创建人:王一帆
/// 创建日期:2020-08-03
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
void OnGridViewDoubleClick(object sender, EventArgs e)
{
runForm = true;
try
{
DataRow rowItem = this.gridView.GetFocusedDataRow();
if (rowItem != null)
{
//设置第一次点击时间
if (rowItem.Table.Columns.Contains("FirstViewTime"))
{
string tableName = rowItem["TableName"] + "";
string id = rowItem["id"] + "";
if (tableName.Equals("p_systemMessageTab") && string.IsNullOrWhiteSpace(rowItem["FirstViewTime"] + ""))
{
NoticeImpl.UpeNoticeData(tableName, id);
}
}
if (rowItem["messid"] + "" == "1" && string.IsNullOrWhiteSpace(rowItem["dllname"] + ""))
{
// 保存小类设置
FrmNoticePrompt frmNoticePrompt = new FrmNoticePrompt();
frmNoticePrompt.TextBoxObj.Text = BaseImpl.HasExistsTable("p_systemMessageTab") ? rowItem["keyvalue"] + "" : rowItem["Msg"] + "";
if (frmNoticePrompt.ShowDialog() == DialogResult.OK)
{
NoticeImpl.UpeNoticeData(rowItem);
string sqlStr = string.Empty;
DataTable data = NoticeImpl.GetNoticeData2(ERPInfo.Instance.UserId, out sqlStr);
int rowCount = data == null ? 0 : data.Rows.Count;
this.gridControlEx.DataSource = data;
this.Text = "您有" + rowCount + "条任务需要处理(提示:双击即可处理).";
}
}
else
{
OpenAuditControl(rowItem);
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message);
}
runForm = false;
}
///
/// 说明:最小化到托盘
/// 创建人:龚宇超
/// 创建日期:2019-09-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
void OnMainFormClosing(object sender, FormClosingEventArgs e)
{
try
{
this.WindowState = FormWindowState.Minimized;
e.Cancel = true;
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message);
}
}
///
/// 说明:显示窗口
/// 创建人:龚宇超
/// 创建日期:2019-09-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
void OnTsmiShowClick(object sender, EventArgs e)
{
try
{
this.NormalShowForm();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message);
}
}
///
/// 说明:退出系统
/// 创建人:龚宇超
/// 创建日期:2019-09-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
void OnTsmiCloseClick(object sender, EventArgs e)
{
try
{
if (MessageUtil.Show("确定要退出任务监视工具?\r\n退后后将无法收到审批消息.", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
try
{
notifyIcon1.Dispose();
this.Dispose();
this.Close();
}
catch (Exception)
{
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message);
}
}
///
/// 说明:窗口最小化时显示图标
/// 创建人:龚宇超
/// 创建日期:2019-09-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
void OnFrmMainSizeChanged(object sender, EventArgs e)
{
try
{
if (WindowState == FormWindowState.Minimized)
{
this.ShowInTaskbar = false;
this.notifyIcon1.Visible = true;
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message);
}
}
///
/// 说明:左键点击打开消息列表
/// 创建人:龚宇超
/// 创建日期:2019-09-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
void OnNotifyIconMouseClick(object sender, MouseEventArgs e)
{
try
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
this.NormalShowForm();
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message);
}
}
///
/// 说明:闪烁图标
/// 创建人:龚宇超
/// 创建日期:
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
void OnBlinkTimerTick(object sender, EventArgs e)
{
try
{
if (!blink)
{
this.notifyIcon1.Icon = striped;
}
else
{
this.notifyIcon1.Icon = blank;
}
blink = !blink;
}
catch (Exception)
{
}
}
///
/// 说明:
/// 创建人:龚宇超
/// 创建日期:
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
void OnTsmiShowWindowClick(object sender, EventArgs e)
{
try
{
this.tsmiShowWindow.Checked = !this.tsmiShowWindow.Checked;
DBConfig.Instance.NoticeShowWindow = this.tsmiShowWindow.Checked;
DBConfig.Instance.WriteConfig();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message);
}
}
///
/// 说明:
/// 创建人:龚宇超
/// 创建日期:
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
void OnTsmiFlickerClick(object sender, EventArgs e)
{
try
{
this.tsmiFlicker.Checked = !this.tsmiFlicker.Checked;
DBConfig.Instance.NoticeFlicker = this.tsmiFlicker.Checked;
DBConfig.Instance.WriteConfig();
blink = false;
this.notifyIcon1.Icon = striped;
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message);
}
}
///
/// 说明:随主系统退出
/// 创建人:龚宇超
/// 创建日期:
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
void OnTsmiExitByMainClick(object sender, EventArgs e)
{
try
{
this.tsmiExitByMain.Checked = !this.tsmiExitByMain.Checked;
DBConfig.Instance.NoticeExit = this.tsmiExitByMain.Checked;
DBConfig.Instance.WriteConfig();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message);
}
}
///
/// 说明:清除所有标识为1的消息
/// 创建人:王一帆
/// 创建日期:
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void OnTsmiCleanAllClick(object sender, EventArgs e)
{
try
{
NoticeImpl.UpeNoticeData("1");
string sqlStr = string.Empty;
DataTable data = NoticeImpl.GetNoticeData2(ERPInfo.Instance.UserId, out sqlStr);
int rowCount = data == null ? 0 : data.Rows.Count;
this.gridControlEx.DataSource = data;
this.Text = "您有" + rowCount + "条任务需要处理(提示:双击即可处理).";
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message);
}
}
///
/// 说明:鼠标进入窗体事件
/// 创建人:王一帆
/// 创建日期:
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void OnTsmiMouseEnter(object sender, EventArgs e)
{
mouseinform = true;
this.blinkTimer.Enabled = false;
this.notifyIcon1.Icon = striped;
}
///
/// 说明:鼠标离开窗体事件
/// 创建人:王一帆
/// 创建日期:
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void OnTsmiMouseLeave(object sender, EventArgs e)
{
mouseinform = false;
}
///
/// 说明:设置delphi参数
/// 创建人:龚宇超
/// 创建日期:2018-03-12
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void SetDelphiDllParams()
{
try
{
StringBuilder sb1 = new StringBuilder();
sb1.Append(ERPInfo.Instance.UserName);
StringBuilder sb2 = new StringBuilder();
sb2.Append(ERPInfo.Instance.WindowName);
StringBuilder sb3 = new StringBuilder();
sb3.Append(ERPInfo.Instance.SkinName);
//给delphi库设置参数(用户id、子系统id、操作员名称、计算机名称)
DelphiHelper.Delphi_SetParams(Convert.ToInt32(ERPInfo.Instance.UserId), Convert.ToInt32(ERPInfo.Instance.SubSysId), sb1, sb2, sb3);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
LogHelper.Instance.WriteError(ex);
//LogUtil.WriteError("设置delphi参数错误", ex);
}
}
}
}