tijian_tieying/web/dccdc.hujiao/frm_main.cs
2025-02-20 12:14:39 +08:00

260 lines
9.8 KiB
C#

using Apache.NMS;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace dccdc.hujiao
{
public partial class frm_main : Form
{
IConnectionFactory factory;
IConnection connection;
ISession session;
string MQAddress
{
get
{
return System.Configuration.ConfigurationManager.AppSettings["MQAddress"];
}
}
ICollection<string> setting = extend.Config.AppSettings.Settings.AllKeys as ICollection<string>;
public frm_main()
{
InitializeComponent();
}
private void frm_main_Load(object sender, EventArgs e)
{
btn_xyw.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
btn_xyw.FlatAppearance.BorderSize = 0;
btn_xyw.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Transparent;
btn_xyw.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;
btn_xyw.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
btn_ch.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
btn_ch.FlatAppearance.BorderSize = 0;
btn_xyw.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Transparent;
btn_ch.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;
btn_ch.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
btn_gh.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
btn_gh.FlatAppearance.BorderSize = 0;
btn_gh.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Transparent;
btn_gh.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;
btn_gh.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
btn_lb.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
btn_lb.FlatAppearance.BorderSize = 0;
btn_lb.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Transparent;
btn_lb.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;
btn_lb.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
btn_exit.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
btn_exit.FlatAppearance.BorderSize = 0;
btn_exit.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Transparent;
btn_exit.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;
btn_exit.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
try
{
kjqd();
}
catch { }
nyinit();
}
private void nyinit()
{
if (string.IsNullOrEmpty(MQAddress))
{
MessageBox.Show("消息服务器地址没有设置!");
Application.Exit();
}
factory = new Apache.NMS.ActiveMQ.ConnectionFactory(MQAddress);
bool conned = false;
for (int i = 0; i < 10; i++)
{
try
{
connection = factory.CreateConnection();
connection.ClientId = Dns.GetHostName();
connection.Start();
conned = true;
break;
}
catch
{
Thread.Sleep(2000);
}
}
if (!conned)
{
MessageBox.Show("消息服务器设置不正常程序退出!");
Application.Exit();
return;
}
session = connection.CreateSession();
//receivemessageinit();
gxpdlb = session.CreateConsumer(new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("gxpdlb"));
//remsg2 = session.CreateConsumer(new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("jbtxTopic"), "dept_code='20151'", false);
gxpdlb.Listener += new MessageListener(gxpdlb_Listener);
WebClient wc = new WebClient();
//WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string jsondata = wc.UploadString(extend.URL + "zzj/getpdlb", "");
var pd = Newtonsoft.Json.JsonConvert.DeserializeObject<pdxx>(jsondata);
lbl_dqhm.Text = "0000";
ddlb = new hujiao.frm_ddlb();
ddlb.gxlb(pd.dds);
ddlb.Show();
}
frm_ddlb ddlb = null;
/// <summary>
/// 更新排队列表
/// </summary>
/// <param name="message"></param>
private void gxpdlb_Listener(IMessage message)
{
//throw new NotImplementedException();
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string jsondata = wc.UploadString(extend.URL + "zzj/getpdlb", "");
var pd = Newtonsoft.Json.JsonConvert.DeserializeObject<pdxx>(jsondata);
//sendtoLED(pd);
if (ddlb != null && !ddlb.IsDisposed)
{
ddlb.gxlb(pd.dds);
}
}
IMessageConsumer gxpdlb;
private void kjqd()
{
string path = Application.ExecutablePath;
RegistryKey rk = Registry.LocalMachine;
RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
rk2.SetValue("SOH.FenZhen", path);
rk2.Close();
rk.Close();
}
bool _mousedown = false;
private void frm_main_MouseDown(object sender, MouseEventArgs e)
{
_mousedown = true;
_louselocation = PointToScreen(e.Location);
}
Point _louselocation = new Point();
private void frm_main_MouseMove(object sender, MouseEventArgs e)
{
if (_mousedown)
{
Point cp = PointToScreen(e.Location);
Point fp = new Point();
fp.X = this.Location.X + cp.X - _louselocation.X;
fp.Y = this.Location.Y + cp.Y - _louselocation.Y;
_louselocation = cp;
this.Location = fp;
}
}
private void frm_main_MouseUp(object sender, MouseEventArgs e)
{
_mousedown = false;
}
private void btn_exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btn_lb_Click(object sender, EventArgs e)
{
if(ddlb!=null&&!ddlb.IsDisposed)
{
ddlb.Activate();
}
else
{
WebClient wc = new WebClient();
//WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string jsondata = wc.UploadString(extend.URL + "zzj/getpdlb", "");
var pd = Newtonsoft.Json.JsonConvert.DeserializeObject<pdxx>(jsondata);
//lbl_dqhm.Text = "0000";
ddlb = new hujiao.frm_ddlb();
ddlb.gxlb(pd.dds);
ddlb.Show();
}
}
private void btn_xyw_Click(object sender, EventArgs e)
{
WebClient wc = new WebClient();
//WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string jsondata = wc.UploadString(extend.URL + "zzj/hj", "ksid="+extend.Config.AppSettings.Settings["ksid"].Value+"&ksmc="+System.Web.HttpUtility.UrlEncode(extend.Config.AppSettings.Settings["ksmc"].Value));
var or = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.OperationResult>(jsondata);
lbl_dqhm.Text = or.Message ;
}
private void btn_ch_Click(object sender, EventArgs e)
{
WebClient wc = new WebClient();
//WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string jsondata = wc.UploadString(extend.URL + "zzj/hj", "ksid=" + extend.Config.AppSettings.Settings["ksid"].Value + "&ksmc=" + System.Web.HttpUtility.UrlEncode(extend.Config.AppSettings.Settings["ksmc"].Value)+"&hm="+lbl_dqhm.Text);
var or = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.OperationResult>(jsondata);
lbl_dqhm.Text = or.Message;
}
private void btn_gh_Click(object sender, EventArgs e)
{
WebClient wc = new WebClient();
//WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string jsondata = wc.UploadString(extend.URL + "zzj/hj", "gh=true&ksid=" + extend.Config.AppSettings.Settings["ksid"].Value + "&ksmc=" + System.Web.HttpUtility.UrlEncode(extend.Config.AppSettings.Settings["ksmc"].Value) + "&hm=" + lbl_dqhm.Text);
var or = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.OperationResult>(jsondata);
lbl_dqhm.Text = or.Message;
}
private void frm_main_MouseClick(object sender, MouseEventArgs e)
{
this.TopMost = true;
}
}
public class pdxx
{
public List<Models.PD_XX> jhs { get; set; }
public List<Models.PD_XX> dds { get; set; }
}
}