234 lines
8.3 KiB
C#
234 lines
8.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace dccdc.Selfhelp
|
|
{
|
|
public partial class frm_sjdj : Form
|
|
{
|
|
public frm_sjdj()
|
|
{
|
|
|
|
InitializeComponent();
|
|
}
|
|
static MouseHook mh;
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
mh.UnHook();
|
|
mh.SetHook();
|
|
mh.MouseClickEvent += mh_MouseClickEvent;
|
|
//Mousee
|
|
WebClient wc = new WebClient();
|
|
wc.Encoding = System.Text.Encoding.UTF8;
|
|
string jsonData = wc.DownloadString(extend.URL + "zzj/getxgyyxxsjh?id=" + txt_sjh.Text);
|
|
OperationResult or = Newtonsoft.Json.JsonConvert.DeserializeObject<OperationResult>(jsonData);
|
|
if (or.State == 0)
|
|
{
|
|
Status sss = new Status(or.Message);
|
|
sss.ShowDialog();
|
|
return;
|
|
}
|
|
List<dccdc.Models.xg_yyxx> yys = Newtonsoft.Json.JsonConvert.DeserializeObject<List<dccdc.Models.xg_yyxx>>(or.Tag);
|
|
foreach (var yy in yys)
|
|
{
|
|
NameValueCollection nvc = new NameValueCollection();
|
|
//sfzh: $("#f_sfzh").val(), xm: $("#f_xm").val(), sjh: $("#f_sjh").val(), cks: scks
|
|
nvc.Add("sfzh", yy.sfzh);
|
|
nvc.Add("xm", yy.xm);
|
|
nvc.Add("sjh", yy.sjh);
|
|
string cks = "";
|
|
foreach (var mx in yy.yymx)
|
|
{
|
|
cks += mx.xmid + ",";
|
|
}
|
|
nvc.Add("cks", cks);
|
|
byte[] result = wc.UploadValues(extend.URL + "xg/xgdj", nvc);
|
|
var dj = Newtonsoft.Json.JsonConvert.DeserializeObject<djxx>(System.Text.Encoding.UTF8.GetString(result));
|
|
if(dj.State==0)
|
|
{
|
|
Status sss = new Status(dj.Message);
|
|
sss.ShowDialog();
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
string jsonData1 = wc.DownloadString(extend.URL + "xg/xgtm?id=" + dj.id);
|
|
DataTable dt = Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(jsonData1);
|
|
FastReport.Report re = new FastReport.Report();
|
|
re.Load(Application.StartupPath + "\\xgtm.frx");
|
|
re.RegisterData(dt, "bg");
|
|
|
|
string _tm_dyj = System.Configuration.ConfigurationManager.AppSettings["tmprint"];
|
|
//re.PrintSettings.ShowDialog = false;
|
|
try
|
|
{
|
|
if (!string.IsNullOrEmpty(_tm_dyj))
|
|
re.PrintSettings.Printer = _tm_dyj;
|
|
re.PrintSettings.ShowDialog = false;
|
|
re.Print();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
Status s = new Status("登记成功!");
|
|
s.ShowDialog();
|
|
this.Close();
|
|
}
|
|
|
|
private void txt_sjh_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
{
|
|
button1_Click(button1, EventArgs.Empty);
|
|
}
|
|
}
|
|
|
|
private void frm_sjdj_Load(object sender, EventArgs e)
|
|
{
|
|
mh = new MouseHook();
|
|
mh.SetHook();
|
|
mh.MouseClickEvent += mh_MouseClickEvent;
|
|
|
|
}
|
|
|
|
private void Frm_sjdj_MouseEnter(object sender, EventArgs e)
|
|
{
|
|
//throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
private void mh_MouseClickEvent(object sender, MouseEventArgs e)
|
|
{
|
|
//throw new NotImplementedException();
|
|
//MessageBox.Show(e.X + "," + e.Y);
|
|
var p= this.PointToClient(new Point(e.X, e.Y));
|
|
if(! this.ClientRectangle.Contains(p))
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
|
|
private void frm_sjdj_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
mh.UnHook();
|
|
}
|
|
}
|
|
public class Win32Api
|
|
{
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public class POINT
|
|
{
|
|
public int x;
|
|
public int y;
|
|
}
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public class MouseHookStruct
|
|
{
|
|
public POINT pt;
|
|
public int hwnd;
|
|
public int wHitTestCode;
|
|
public int dwExtraInfo;
|
|
}
|
|
public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
|
|
//安装钩子
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
|
|
//卸载钩子
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
|
public static extern bool UnhookWindowsHookEx(int idHook);
|
|
//调用下一个钩子
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int CallNextHookEx(int idHook, int nCode, IntPtr wParam, IntPtr lParam);
|
|
}
|
|
public class MouseHook
|
|
{
|
|
|
|
private Point point;
|
|
private Point Point
|
|
{
|
|
get { return point; }
|
|
set
|
|
{
|
|
if (point != value)
|
|
{
|
|
point = value;
|
|
if (MouseMoveEvent != null)
|
|
{
|
|
var e = new MouseEventArgs(MouseButtons.Left, 0, point.X, point.Y, 0);
|
|
MouseMoveEvent(this, e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private int hHook;
|
|
public const int WH_MOUSE_LL = 14;
|
|
public Win32Api.HookProc hProc;
|
|
public MouseHook()
|
|
{
|
|
this.Point = new Point();
|
|
}
|
|
public int SetHook()
|
|
{
|
|
hProc = new Win32Api.HookProc(MouseHookProc);
|
|
hHook = Win32Api.SetWindowsHookEx(WH_MOUSE_LL, hProc, IntPtr.Zero, 0);
|
|
return hHook;
|
|
}
|
|
public void UnHook()
|
|
{
|
|
Win32Api.UnhookWindowsHookEx(hHook);
|
|
}
|
|
private const int WM_LBUTTONDOWN = 0x201;
|
|
private int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
|
|
{
|
|
Win32Api.MouseHookStruct MyMouseHookStruct = (Win32Api.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32Api.MouseHookStruct));
|
|
//Win32Api.MouseHookStruct MyMouseHookStruct = (Win32Api.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32Api.MouseHookStruct));
|
|
if (nCode < 0)
|
|
{
|
|
return Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam);
|
|
}
|
|
else
|
|
{
|
|
if (MouseClickEvent != null)
|
|
{
|
|
MouseButtons button = MouseButtons.None;
|
|
int clickCount = 0;
|
|
switch ((Int32)wParam)
|
|
{
|
|
case WM_LBUTTONDOWN:
|
|
button = MouseButtons.Left;
|
|
clickCount = 1;
|
|
var e = new MouseEventArgs(button, clickCount, point.X, point.Y, 0);
|
|
MouseClickEvent(this, e);
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
this.Point = new Point(MyMouseHookStruct.pt.x, MyMouseHookStruct.pt.y);
|
|
return Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam);
|
|
}
|
|
}
|
|
//委托+事件(把钩到的消息封装为事件,由调用者处理)
|
|
public delegate void MouseMoveHandler(object sender, MouseEventArgs e);
|
|
public event MouseMoveHandler MouseMoveEvent;
|
|
|
|
public delegate void MouseClickHandler(object sender, MouseEventArgs e);
|
|
public event MouseClickHandler MouseClickEvent;
|
|
}
|
|
}
|