Files
cyf ab56a9bcf7 基线 SVN r240
SVN-Revision: r240
2025-02-06 06:46:06 +00:00

500 lines
18 KiB
C#

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 Lskj.Control;
using Lskj.Core;
using Lskj.Business;
using Lskj.Model;
using Lskj.Business.Impl;
using Lskj.Util;
using Lskj.Data;
using System.Diagnostics;
using System.IO;
using System.Drawing.Imaging;
namespace Lskj.FrmMessages
{
public partial class FrmMain : BaseForm
{
/// <summary>
/// 基础档案审批配置对象
/// </summary>
public BaseAccraditationModel BaseAuditModelObj;
//切换图片的标识
private bool iconFlag = false;
//是否在朗速里打开
private bool isLsERP = false;
public string cacheText = string.Empty;
public DataRow mSelectRow = null;
public bool isFinish;//是否已经完成
public DataTable cacheDt;//缓存上一次查询到的审核消息
public string sql = string.Format("select '['+typeName+']'+'=>>'+keyvalue+'单子需要你审核' as AuditMessages,* from wms_billflowOperView where CHARINDEX(',{0},',',' + browsers + ',')>0", DBConfig.Instance.LoginName);
public FrmMain(string[] arg)
{
try
{
InitializeComponent();
InitializationMessages();
if (arg.Length > 0) {
isLsERP = true;
}
}
catch (Exception)
{
}
finally
{
Information_timer.Start();
}
}
/// <summary>
/// 设置托盘显示的图标
/// </summary>
/// <param name="index">图像列表中图片的索引</param>
private void setIconImg(int index)
{
try
{
Image img = this.imgIcon.Images[index];
Bitmap b = new Bitmap(img);
Icon icon = Icon.FromHandle(b.GetHicon());
this.notifyIcon1.Icon = icon;
b.Dispose();
img.Dispose();
icon.Dispose();
}
catch (Exception)
{
}
}
/// <summary>
/// 10秒刷新数据源更新消息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Information_timer_Tick(object sender, EventArgs e)
{
try
{
DataTable newDt = SqlHelper.ExecuteDataTable(sql);
////获取两个数据源的差集
IEnumerable<DataRow> QCJ = newDt.AsEnumerable().Except(cacheDt.AsEnumerable(), DataRowComparer.Default);
////两个数据源的差集集合
int num = QCJ.Count<DataRow>();
if (isFinish && num > 0)
{
MessageTable.DataSource = cacheDt = newDt;
//还原窗体显示
WindowState = FormWindowState.Normal;
//激活窗体并给予它焦点
this.Activate();
//托盘区图标隐藏
notifyIcon1.Visible = false;
this.Opacity = 100D;
isFinish = false;
this.timer2.Enabled = true;
}
}
catch (Exception)
{
if (MessageUtil.Show("检测到网络异常\r\n是否重启信息平台?", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
try
{
this.notifyIcon1.Dispose();
Application.Restart();
}
catch (Exception ex)
{
MessageUtil.Show("删除失败:\r\n" + ex.Message);
}
}
else
{
this.notifyIcon1.Dispose();
this.Dispose();
}
}
}
/// <summary>
/// 最小化工共方法
/// </summary>
public void Minimized()
{
this.WindowState = FormWindowState.Minimized;
//图标显示在托盘区
notifyIcon1.Visible = true;
this.setIconImg(0);
this.isFinish = true;
this.timer2.Enabled = false;
this.Opacity = 0;
}
public void InitializationMessages()
{
if (DBConfig.Instance.CreateConnection())
{
IniHelper.Write("isRefresh", "0");
DataTable table = MainImpl.GetEmployeeList();
DataRow[] drRows = table.Select("UserName='" + DBConfig.Instance.LoginName + "' or UserCode='" + DBConfig.Instance.LoginName + "'");
if ((drRows == null) || (drRows.Count() < 1))
{
MessageUtil.Show(ResourceKeys.NameOrPasswordError);
return;
}
//找到多个操作员
if (drRows.Count() > 1)
{
MessageUtil.Show(ResourceKeys.DuplicatedNameError);
return;
}
DataRow drRow = drRows[0];
//DataRow drRow = table.Rows.Cast<DataRow>().FirstOrDefault(x => userName.Equals(x["UserName"] + ""));
if (drRow != null)
{
ERPInfo.Instance.UserId = drRow["UserId"] + "";
ERPInfo.Instance.UserName = drRow["UserName"] + "";
}
else
{
ERPInfo.Instance.UserId = "";
}
ERPInfo.Instance.UserId = "1";
cacheDt = SqlHelper.ExecuteDataTable(sql);//缓存上次加载的数据源
cacheText = this.labelControl1.Text;
this.ShowInTaskbar = false;
this.MessageTable.DataSource = cacheDt;
this.gridView.DoubleClick += new EventHandler(OnGridViewDoubleClick);
this.notifyIcon1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseClick);
Point p = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height);
this.PointToScreen(p);
this.TopMost = true;
this.Location = p;
//任务栏区显示图标
System.Threading.Thread thread = new System.Threading.Thread(() =>
{
for (int i = 0; i <= this.Height; i++)
{
this.Invoke(new MethodInvoker(delegate
{
Application.DoEvents();
this.Location = new Point(p.X, p.Y - i);
System.Threading.Thread.Sleep(1);
if (i == this.Height)
{
timer1.Start();
timer2.Start();
timer3.Start();
}
}));
}
});
thread.Start();
}
else
{
MessageUtil.Show("请确保数据库连接");
Application.Exit();
}
}
/// <summary>
/// <para>说明:表格双击打开模块配置</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-08-13 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
protected void OnGridViewDoubleClick(object sender, EventArgs e)
{
try
{
mSelectRow = this.gridView.GetFocusedDataRow();
if (mSelectRow == null) return;
if ((mSelectRow["tagid"] + "").Equals("1"))
{
OpenAccraditation();
}
else
{
OpenBaseAccraditation();
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 打开单据模块审批
/// </summary>
public void OpenAccraditation()
{
try
{
//单据审批弹出模块
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, mSelectRow["typeName"] + "", ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, 1, mSelectRow["modid"] + "").Split('~');
//模块Id/stepcode/点击数据键值/权限
string[] menuArgs = { "0", mSelectRow["modid"] + "", mSelectRow["stepcode"] + "", mSelectRow["keyvalue"] + "", "0", "0" };
string[] args = defaultArgs.Concat(menuArgs).ToArray();
IForm form = FormHelper.LoadDllForm(ResourceDynamic.PubAccraditation, args);
Application.DoEvents();
this.TopMost = false;
timer1.Enabled = false;
timer2.Enabled = false;
DialogResult result = form.SubForm.ShowDialog();
if (result == DialogResult.OK || result == DialogResult.Cancel)
{
this.MessageTable.DataSource = SqlHelper.ExecuteDataTable(sql);
this.TopMost = true;
timer1.Start();
timer2.Start();
}
}
catch (Exception ex)
{
LogUtil.WriteError("单据审批模块弹出模块出错!", ex);
MessageUtil.Show("单据审批模块弹出模块出错!" + ex);
}
}
/// <summary>
/// 打开基础模块审批
/// </summary>
public void OpenBaseAccraditation()
{
try
{
this.BaseAuditModelObj = new BaseAccraditationModel(MainImpl.GetSystemdllTab(mSelectRow["modid"] + ""));
//单据审批弹出模块
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, mSelectRow["typeName"] + "", ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, 1, mSelectRow["modid"] + "").Split('~');
//模块Id/stepcode/点击数据键值/权限
string[] menuArgs = { "0", mSelectRow["modid"] + "", mSelectRow["stepcode"] + "", mSelectRow["keyvalue"] + "", "0", "0" };
string[] args = defaultArgs.Concat(menuArgs).ToArray();
IForm form = FormHelper.LoadDllForm(ResourceDynamic.BaseAccraditation, args);
Application.DoEvents();
this.TopMost = false;
timer1.Enabled = false;
timer2.Enabled = false;
DialogResult result = form.SubForm.ShowDialog();
if (result == DialogResult.OK || result == DialogResult.Cancel)
{
this.MessageTable.DataSource = SqlHelper.ExecuteDataTable(sql);
this.TopMost = true;
timer1.Start();
timer2.Start();
}
}
catch (Exception ex)
{
LogUtil.WriteError("基础审批模块弹出模块出错!", ex);
MessageUtil.Show("基础审批模块弹出模块出错!" + ex);
}
}
/// <summary>
/// 10秒不操作隐藏窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
try
{
timer2.Enabled = false;//停止timer2计时器,
if (this.Opacity > 0 && this.Opacity <= 1)//开始执行弹出窗渐渐透明
{
this.Opacity = this.Opacity - 0.1;//透明频度
}
if (System.Windows.Forms.Control.MousePosition.X >= this.Location.X && System.Windows.Forms.Control.MousePosition.Y >= this.Location.Y)//每次都判断鼠标是否是在弹出窗上,使用鼠标在屏幕上的坐标跟弹出窗体的屏幕坐标做比较。
{
timer2.Enabled = true;//如果鼠标在弹出窗上的时候,timer2开始工作
timer1.Enabled = false;//timer1停止工作。
}
if (this.Opacity == 0)//当透明度==0的时候,关闭弹出窗以释放资源。
{
Minimized();
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 判断鼠标是不是还在弹出框上,如果不是则timer1又可以开始工作了
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer2_Tick(object sender, EventArgs e)
{
try
{
timer1.Enabled = false;//timer1停止工作
this.Opacity = 1;//弹出窗透明度设置为1,完全不透明
if (System.Windows.Forms.Control.MousePosition.X < this.Location.X && System.Windows.Forms.Control.MousePosition.Y < this.Location.Y)//如下
{
timer1.Enabled = true;
timer2.Enabled = false;
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 判断是否最小化,然后显示托盘
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void F_Main_SizeChanged(object sender, EventArgs e)
{
try
{
//判断是否选择的是最小化按钮
if (WindowState == FormWindowState.Minimized)
{
//图标显示在托盘区
notifyIcon1.Visible = true;
this.setIconImg(0);
this.isFinish = true;
this.ShowInTaskbar = false;
this.Opacity = 0;
this.timer2.Enabled = false;
}
}
catch (Exception)
{
}
}
/// <summary>
/// 添加双击托盘图标事件(双击显示窗口)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
try
{
if (WindowState == FormWindowState.Minimized && e.Button == MouseButtons.Left)
{
//还原窗体显示
WindowState = FormWindowState.Normal;
//激活窗体并给予它焦点
this.Activate();
//托盘区图标隐藏
notifyIcon1.Visible = false;
this.Opacity = 100D;
isFinish = false;
this.timer2.Enabled = true;
}
}
catch (Exception)
{
}
}
/// <summary>
/// 退出事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.notifyIcon1.Dispose();
this.Dispose();
Application.Exit();
}
private void timer3_Tick(object sender, EventArgs e)
{
try
{
DataTable dt = this.MessageTable.DataSource as DataTable;
if (WindowState == FormWindowState.Minimized)
{
if (dt.Rows.Count == 0)
{
return;
}
if (iconFlag)
{
this.setIconImg(0);
iconFlag = !iconFlag;
}
else
{
this.setIconImg(1);
iconFlag = !iconFlag;
}
}
else
{
this.labelControl1.Text = cacheText + string.Format("(您有{0}条数据需要审批)", dt.Rows.Count);
}
}
catch (Exception)
{
}
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
this.notifyIcon1.Dispose();
}
private void timer4_Tick(object sender, EventArgs e)
{
try
{
if (isLsERP)
{
Process[] p = Process.GetProcessesByName("Ls_ERP");
if (p.Length == 0)
{
this.Close();
}
}
string isRefresh = IniHelper.Read("isRefresh");
if (isRefresh.Equals("1"))
{
IniHelper.Write("isRefresh", "0");
this.timer4.Enabled = false;
Application.Restart();
}
}
catch (Exception)
{
}
}
private void btnMin_Click(object sender, EventArgs e)
{
Minimized();
}
}
}