📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Collections.Specialized;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace jianshiFile
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
/// <summary>
/// 文件长度
/// </summary>
long fileStreamLength;
private System.Windows.Forms.TextBox textBox_txtFileLengh;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox_Value1;
private System.Windows.Forms.TextBox textBox_Value2;
private System.Windows.Forms.TextBox textBox_ValueTime;
private System.Windows.Forms.TextBox textBox_CodeNumber;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button button_submit;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton radioButton_manual;
private System.Windows.Forms.RadioButton radioButton_auto;
private System.Windows.Forms.DataGrid dataGrid_tempValue;
private System.Windows.Forms.TextBox textBox_ValueTemp1;
private System.Windows.Forms.TextBox textBox_ValueTemp2;
private System.Windows.Forms.TextBox textBox_ValueTempTime;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
string fileName;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.Label label_Message;
private System.Windows.Forms.Button button_PrintCode;
string GangTiHao = System.Configuration.ConfigurationSettings.AppSettings.GetValues("GangTiHao")[0].ToString();
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
fileName = @"d:\\zhang.txt";
FileStream s = new FileStream(fileName,FileMode.Open,FileAccess.Read);
fileStreamLength = s.Length;
s.Close();
this.textBox_txtFileLengh.Text = fileStreamLength.ToString();
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.textBox_txtFileLengh = new System.Windows.Forms.TextBox();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.dataGrid_tempValue = new System.Windows.Forms.DataGrid();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.textBox_Value1 = new System.Windows.Forms.TextBox();
this.textBox_Value2 = new System.Windows.Forms.TextBox();
this.textBox_ValueTime = new System.Windows.Forms.TextBox();
this.textBox_CodeNumber = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.button_submit = new System.Windows.Forms.Button();
this.radioButton_manual = new System.Windows.Forms.RadioButton();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.radioButton_auto = new System.Windows.Forms.RadioButton();
this.textBox_ValueTemp1 = new System.Windows.Forms.TextBox();
this.textBox_ValueTemp2 = new System.Windows.Forms.TextBox();
this.textBox_ValueTempTime = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.label_Message = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.button_PrintCode = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGrid_tempValue)).BeginInit();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// textBox_txtFileLengh
//
this.textBox_txtFileLengh.Location = new System.Drawing.Point(104, 24);
this.textBox_txtFileLengh.Name = "textBox_txtFileLengh";
this.textBox_txtFileLengh.ReadOnly = true;
this.textBox_txtFileLengh.TabIndex = 0;
this.textBox_txtFileLengh.Text = "";
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// dataGrid_tempValue
//
this.dataGrid_tempValue.CaptionVisible = false;
this.dataGrid_tempValue.DataMember = "";
this.dataGrid_tempValue.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid_tempValue.Location = new System.Drawing.Point(16, 216);
this.dataGrid_tempValue.Name = "dataGrid_tempValue";
this.dataGrid_tempValue.ReadOnly = true;
this.dataGrid_tempValue.Size = new System.Drawing.Size(248, 104);
this.dataGrid_tempValue.TabIndex = 3;
this.dataGrid_tempValue.CurrentCellChanged += new System.EventHandler(this.dataGrid_tempValue_CurrentCellChanged);
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(88, 23);
this.label1.TabIndex = 5;
this.label1.Text = "文件长度:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 72);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 23);
this.label2.TabIndex = 6;
this.label2.Text = "测量值1:";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 112);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(88, 23);
this.label3.TabIndex = 7;
this.label3.Text = "测量值2:";
//
// label4
//
this.label4.Location = new System.Drawing.Point(16, 152);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(88, 23);
this.label4.TabIndex = 8;
this.label4.Text = "测量时间:";
//
// textBox_Value1
//
this.textBox_Value1.Location = new System.Drawing.Point(104, 72);
this.textBox_Value1.Name = "textBox_Value1";
this.textBox_Value1.ReadOnly = true;
this.textBox_Value1.TabIndex = 9;
this.textBox_Value1.Text = "";
//
// textBox_Value2
//
this.textBox_Value2.Location = new System.Drawing.Point(104, 112);
this.textBox_Value2.Name = "textBox_Value2";
this.textBox_Value2.ReadOnly = true;
this.textBox_Value2.TabIndex = 10;
this.textBox_Value2.Text = "";
//
// textBox_ValueTime
//
this.textBox_ValueTime.Location = new System.Drawing.Point(104, 152);
this.textBox_ValueTime.Name = "textBox_ValueTime";
this.textBox_ValueTime.ReadOnly = true;
this.textBox_ValueTime.TabIndex = 11;
this.textBox_ValueTime.Text = "";
//
// textBox_CodeNumber
//
this.textBox_CodeNumber.Location = new System.Drawing.Point(144, 344);
this.textBox_CodeNumber.Name = "textBox_CodeNumber";
this.textBox_CodeNumber.Size = new System.Drawing.Size(128, 21);
this.textBox_CodeNumber.TabIndex = 12;
this.textBox_CodeNumber.Text = "";
//
// label5
//
this.label5.Location = new System.Drawing.Point(24, 344);
this.label5.Name = "label5";
this.label5.TabIndex = 13;
this.label5.Text = "输入条码号:";
//
// button_submit
//
this.button_submit.Location = new System.Drawing.Point(320, 344);
this.button_submit.Name = "button_submit";
this.button_submit.TabIndex = 14;
this.button_submit.Text = "确定";
this.button_submit.Click += new System.EventHandler(this.button_submit_Click);
//
// radioButton_manual
//
this.radioButton_manual.Checked = true;
this.radioButton_manual.Location = new System.Drawing.Point(32, 16);
this.radioButton_manual.Name = "radioButton_manual";
this.radioButton_manual.TabIndex = 15;
this.radioButton_manual.TabStop = true;
this.radioButton_manual.Text = "手动产生";
this.radioButton_manual.CheckedChanged += new System.EventHandler(this.radioButton_manual_CheckedChanged);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.radioButton_auto);
this.groupBox1.Controls.Add(this.radioButton_manual);
this.groupBox1.Location = new System.Drawing.Point(248, 16);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(192, 80);
this.groupBox1.TabIndex = 16;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "条码产生方式";
//
// radioButton_auto
//
this.radioButton_auto.Location = new System.Drawing.Point(32, 40);
this.radioButton_auto.Name = "radioButton_auto";
this.radioButton_auto.TabIndex = 16;
this.radioButton_auto.Text = "自动产生";
this.radioButton_auto.CheckedChanged += new System.EventHandler(this.radioButton_auto_CheckedChanged);
//
// textBox_ValueTemp1
//
this.textBox_ValueTemp1.Location = new System.Drawing.Point(408, 216);
this.textBox_ValueTemp1.Name = "textBox_ValueTemp1";
this.textBox_ValueTemp1.ReadOnly = true;
this.textBox_ValueTemp1.TabIndex = 18;
this.textBox_ValueTemp1.Text = "";
//
// textBox_ValueTemp2
//
this.textBox_ValueTemp2.Location = new System.Drawing.Point(408, 256);
this.textBox_ValueTemp2.Name = "textBox_ValueTemp2";
this.textBox_ValueTemp2.ReadOnly = true;
this.textBox_ValueTemp2.TabIndex = 19;
this.textBox_ValueTemp2.Text = "";
//
// textBox_ValueTempTime
//
this.textBox_ValueTempTime.Location = new System.Drawing.Point(408, 304);
this.textBox_ValueTempTime.Name = "textBox_ValueTempTime";
this.textBox_ValueTempTime.ReadOnly = true;
this.textBox_ValueTempTime.TabIndex = 20;
this.textBox_ValueTempTime.Text = "";
//
// label7
//
this.label7.Location = new System.Drawing.Point(312, 296);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(88, 23);
this.label7.TabIndex = 23;
this.label7.Text = "测量时间:";
//
// label8
//
this.label8.Location = new System.Drawing.Point(312, 256);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(88, 23);
this.label8.TabIndex = 22;
this.label8.Text = "测量值2:";
//
// label9
//
this.label9.Location = new System.Drawing.Point(312, 216);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(88, 23);
this.label9.TabIndex = 21;
this.label9.Text = "测量值1:";
//
// label_Message
//
this.label_Message.Location = new System.Drawing.Point(256, 128);
this.label_Message.Name = "label_Message";
this.label_Message.Size = new System.Drawing.Size(248, 72);
this.label_Message.TabIndex = 24;
//
// label10
//
this.label10.Location = new System.Drawing.Point(256, 104);
this.label10.Name = "label10";
this.label10.TabIndex = 25;
this.label10.Text = "提示信息:";
//
// button_PrintCode
//
this.button_PrintCode.Location = new System.Drawing.Point(440, 384);
this.button_PrintCode.Name = "button_PrintCode";
this.button_PrintCode.TabIndex = 26;
this.button_PrintCode.Text = "打印测试";
this.button_PrintCode.Click += new System.EventHandler(this.button_PrintCode_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(552, 421);
this.Controls.Add(this.button_PrintCode);
this.Controls.Add(this.label10);
this.Controls.Add(this.label_Message);
this.Controls.Add(this.label7);
this.Controls.Add(this.label8);
this.Controls.Add(this.label9);
this.Controls.Add(this.textBox_ValueTempTime);
this.Controls.Add(this.textBox_ValueTemp2);
this.Controls.Add(this.textBox_ValueTemp1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.button_submit);
this.Controls.Add(this.label5);
this.Controls.Add(this.textBox_CodeNumber);
this.Controls.Add(this.textBox_ValueTime);
this.Controls.Add(this.textBox_Value2);
this.Controls.Add(this.textBox_Value1);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.dataGrid_tempValue);
this.Controls.Add(this.textBox_txtFileLengh);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.Closed += new System.EventHandler(this.Form1_Closed);
((System.ComponentModel.ISupportInitialize)(this.dataGrid_tempValue)).EndInit();
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
/// <summary>
/// 监视txt文件状态
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, System.EventArgs e)
{
long fileStreamLengthTemp;
string ValuesFromTxt = "";
bool IsOKAccess = false;
DataSet ValueTableData;
//DataSet ValueTableTempData;
bool IsOKSQL ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -