📄 form4.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using System.Text;
using System.IO;
using System.Data;
using System.Data.SqlClient ;
using System.Threading;
namespace SmartDeviceApplication5
{
/// <summary>
/// Form4 的摘要说明。
/// </summary>
public class Form4 : System.Windows.Forms.Form
{
public System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn2;
public System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn3;
private System.Windows.Forms.DataGridTableStyle dfgdf1;
private System.Windows.Forms.DataGridTableStyle jkjkj1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox tb_rq;
Client client;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader id;
private System.Windows.Forms.ColumnHeader ch;
private System.Windows.Forms.ColumnHeader cz;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox tb_chcx;
private System.Windows.Forms.Label tb_ch;
string mypreff ="f201";
public Form4()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dfgdf1 = new System.Windows.Forms.DataGridTableStyle();
this.dataGridTextBoxColumn1 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn3 = new System.Windows.Forms.DataGridTextBoxColumn();
this.jkjkj1 = new System.Windows.Forms.DataGridTableStyle();
this.dataGridTextBoxColumn2 = new System.Windows.Forms.DataGridTextBoxColumn();
this.button2 = new System.Windows.Forms.Button();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.button4 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.tb_rq = new System.Windows.Forms.TextBox();
this.listView1 = new System.Windows.Forms.ListView();
this.id = new System.Windows.Forms.ColumnHeader();
this.ch = new System.Windows.Forms.ColumnHeader();
this.cz = new System.Windows.Forms.ColumnHeader();
this.button3 = new System.Windows.Forms.Button();
this.tb_chcx = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.tb_ch = new System.Windows.Forms.Label();
//
// dfgdf1
//
this.dfgdf1.GridColumnStyles.Add(this.dataGridTextBoxColumn1);
this.dfgdf1.GridColumnStyles.Add(this.dataGridTextBoxColumn3);
this.dfgdf1.MappingName = "ggg";
//
// dataGridTextBoxColumn1
//
this.dataGridTextBoxColumn1.HeaderText = "ggg";
this.dataGridTextBoxColumn1.MappingName = "jjj";
this.dataGridTextBoxColumn1.NullText = "(null)";
//
// dataGridTextBoxColumn3
//
this.dataGridTextBoxColumn3.HeaderText = "hgj";
this.dataGridTextBoxColumn3.MappingName = "hj";
this.dataGridTextBoxColumn3.NullText = "(null)";
//
// dataGridTextBoxColumn2
//
this.dataGridTextBoxColumn2.HeaderText = "j";
this.dataGridTextBoxColumn2.MappingName = "j";
this.dataGridTextBoxColumn2.NullText = "(null)";
//
// button2
//
this.button2.Location = new System.Drawing.Point(72, 56);
this.button2.Size = new System.Drawing.Size(40, 24);
this.button2.Text = "察看";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// mainMenu1
//
this.mainMenu1.MenuItems.Add(this.menuItem1);
//
// menuItem1
//
this.menuItem1.Text = "退出";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(32, 56);
this.button4.Size = new System.Drawing.Size(40, 24);
this.button4.Text = "刷新";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// label1
//
this.label1.Font = new System.Drawing.Font("黑体", 15F, System.Drawing.FontStyle.Bold);
this.label1.ForeColor = System.Drawing.Color.DarkTurquoise;
this.label1.Location = new System.Drawing.Point(32, 0);
this.label1.Size = new System.Drawing.Size(176, 24);
this.label1.Text = "选择待预检的车辆";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 24);
this.label2.Size = new System.Drawing.Size(16, 28);
this.label2.Text = "日期";
//
// label3
//
this.label3.Location = new System.Drawing.Point(128, 24);
this.label3.Size = new System.Drawing.Size(24, 28);
this.label3.Text = "车号";
//
// tb_rq
//
this.tb_rq.Location = new System.Drawing.Point(24, 24);
this.tb_rq.Text = "";
//
// listView1
//
this.listView1.Columns.Add(this.id);
this.listView1.Columns.Add(this.ch);
this.listView1.Columns.Add(this.cz);
this.listView1.FullRowSelect = true;
this.listView1.Location = new System.Drawing.Point(0, 104);
this.listView1.Size = new System.Drawing.Size(240, 168);
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged_2);
//
// id
//
this.id.Text = "车辆id";
this.id.Width = 100;
//
// ch
//
this.ch.Text = "车号";
this.ch.Width = 80;
//
// cz
//
this.cz.Text = "车型";
this.cz.Width = 60;
//
// button3
//
this.button3.Location = new System.Drawing.Point(160, 56);
this.button3.Size = new System.Drawing.Size(48, 24);
this.button3.Text = "预检";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// tb_chcx
//
this.tb_chcx.Location = new System.Drawing.Point(144, 24);
this.tb_chcx.Size = new System.Drawing.Size(88, 21);
this.tb_chcx.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(8, 88);
this.label4.Size = new System.Drawing.Size(72, 16);
this.label4.Text = "待预检车号";
//
// tb_ch
//
this.tb_ch.Font = new System.Drawing.Font("宋体", 12F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Underline))));
this.tb_ch.ForeColor = System.Drawing.Color.ForestGreen;
this.tb_ch.Location = new System.Drawing.Point(88, 86);
this.tb_ch.Size = new System.Drawing.Size(96, 16);
//
// Form4
//
this.BackColor = System.Drawing.Color.AliceBlue;
this.ClientSize = new System.Drawing.Size(240, 278);
this.Controls.Add(this.tb_ch);
this.Controls.Add(this.label4);
this.Controls.Add(this.tb_chcx);
this.Controls.Add(this.button3);
this.Controls.Add(this.listView1);
this.Controls.Add(this.tb_rq);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button4);
this.Controls.Add(this.button2);
this.Menu = this.mainMenu1;
this.Text = "Form4";
this.Load += new System.EventHandler(this.Form2_Load);
}
#endregion
public class MessageEventArgst:EventArgs
{
public string Smessage;
public MessageEventArgst(string smessage)
{
this.Smessage = smessage;
}
}
public delegate void MessageEventHandlert(object sender,MessageEventArgst as_e);
public event MessageEventHandlert MessageReceivedt;
private void Form2_Load(object sender, System.EventArgs e)
{
//建立winsock连接
client = new Client();
client = pubics.clients ;
DateTime ld_date = DateTime.Today;
if (pubics.gs_resieve != "")
{
string[] ls_reseve ;
string[] ls_line = new string[3] ;
ListViewItem lisvi;
ls_reseve = pubics.gs_resieve.Split(new char[] {','});
if (ls_reseve.Length > 0)
{
listView1.Items.Clear();
for (int i =0;i < ls_reseve.Length; i++)
{
ls_line = ls_reseve[i].Split(new char[] {'_'});
lisvi =new ListViewItem(ls_line[0].ToString());
lisvi.SubItems.Add(ls_line[1].ToString());
lisvi.SubItems.Add(ls_line[2]);
listView1.Items.Add(lisvi);
}
tb_ch.Text =ls_line[1].ToString();
}
}
tb_rq.Text =ld_date.ToString("yyyy年MM月dd日");
client.MessageReceived += new SocketBase.MessageEventHandler(_server_MessageReceived);
this.MessageReceivedt += new MessageEventHandlert(_MessageReceived);
}
private void _server_MessageReceived(object sender, SocketBase.MessageEventArgs e)
{
//接到winsock信息后促发MessageReceivedt事件
string ls_preff;
int li_end;
ls_preff = e.Message.MessageBody.Substring(0,4);
if(ls_preff == mypreff)
{
li_end = e.Message.MessageBody.IndexOf(mypreff + "end");
this.MessageReceivedt(this,new MessageEventArgst(e.Message.MessageBody.Substring(4,li_end - 4)));
}
}
private void sendyj(string rq)
{
//刷新当日车辆信息
string ls_time;
string strSql;
try
{ ls_time= DateTime.Parse(rq).Date.ToString("yyyy-MM-dd");}
catch
{
MessageBox.Show("请输入正确的日期!");
return;
}
if (tb_chcx.Text.Trim().Length > 0)
{
strSql =mypreff + "select sys_code,ch,cz from d_dx_ct22b where rq =to_date('"+ ls_time +"','yyyy-mm-dd') and ch ='"+ tb_chcx.Text.Trim() +"' order by rq desc,sys_code";
}
else
{
strSql =mypreff + "select sys_code,ch,cz from d_dx_ct22b where rq =to_date('"+ ls_time +"','yyyy-mm-dd') order by rq desc,sys_code";
}
client.StartClient(System.Net.IPAddress.Parse("192.168.1.178"),1001);
Message message = new Message(Message.CommandHeader.SendMessage,1,1,strSql);
client.messageQueue.Add(message);
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, System.EventArgs e)
{
//显示刷新的当日车辆信息
if (pubics.gs_resieve =="")
{
MessageBox.Show("没有记录!");
return;
}
string[] ls_reseve ;
string[] ls_line = new string[3] ;
ListViewItem lisvi;
ls_reseve = pubics.gs_resieve.Split(new char[] {','});
if (ls_reseve.Length > 0)
{
listView1.Items.Clear();
for (int i =0;i < ls_reseve.Length; i++)
{
ls_line = ls_reseve[i].Split(new char[] {'_'});
lisvi =new ListViewItem(ls_line[0].ToString());
lisvi.SubItems.Add(ls_line[1].ToString());
lisvi.SubItems.Add(ls_line[2]);
listView1.Items.Add(lisvi);
}
}
}
private void button4_Click(object sender, System.EventArgs e)
{
sendyj(tb_rq.Text);
Thread.Sleep(2000);
}
private void _MessageReceived(object sender,MessageEventArgst e)
{
if (e.Smessage =="norows")
{
MessageBox.Show("没有记录!");
}
else
{
pubics.gs_resieve = e.Smessage;
}
}
private void button3_Click(object sender, System.EventArgs e)
{
string ls_time;
if (tb_ch.Text.Length > 0)
{
try
{ ls_time= DateTime.Parse(tb_rq.Text.Trim()).Date.ToString("yyyy-MM-dd");}
catch
{
MessageBox.Show("请输入正确的日期!");
return;
}
this.Close();
}
else
{
MessageBox.Show("没有选择待预检车辆!");
}
}
private void listView1_SelectedIndexChanged_2(object sender, System.EventArgs e)
{
if (listView1.Items.Count >0)
{
tb_ch.Text = listView1.FocusedItem.SubItems[1].Text;
pubics.gs_id = listView1.FocusedItem.SubItems[0].Text;
pubics.gs_cz = listView1.FocusedItem.SubItems[2].Text;
pubics.gs_ch = tb_ch.Text;
try
{
pubics.gs_rq = DateTime.Parse(tb_rq.Text.Trim()).Date.ToString("yyyy-MM-dd");
}
catch
{}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -