我想在文本框中显示最新的增量标识值。
问题不在于程序运行时,而在于重新启动时(值回到 101)。
任何想法?
static int trid = 100;
static int batchNo = 0;
public StartInspection()
{
InitializeComponent();
Fillcombo();
try
{
_capture = new Capture(0);
_capture.ImageGrabbed += ProcessFrame;
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
public static string SetValueForText = "";
void Fillcombo()
{
String constring = "Data Source=JECKDGREAT\\SQLEXPRESS;Initial Catalog=TileDB;Persist Security Info=True;User ID=jeric;Password=jericpogi";
String query = "Select * from addNewTileModel";
SqlConnection conn = new SqlConnection(constring);
SqlCommand command = new SqlCommand(query, conn);
SqlDataReader m_dr;
try
{
conn.Open();
m_dr = command.ExecuteReader();
while (m_dr.Read())
{
String sName = m_dr["prodCode"].ToString();
cmbTileModI.Items.Add(sName);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void ProcessFrame(object sender, EventArgs arg)
{
Image<Bgr, Byte> frame = _capture.RetrieveBgrFrame();
Image<Gray, Byte> grayFrame = frame.Convert<Gray, Byte>();
Image<Gray, Byte> smallGrayFrame = grayFrame.PyrDown();
Image<Gray, Byte> smoothedGrayFrame = smallGrayFrame.PyrUp();
Image<Gray, Byte> cannyFrame = smoothedGrayFrame.Canny(100, 60);
imageBox1.Image = frame;
grayscaleImageBox.Image = grayFrame;
//smoothedGrayscaleImageBox.Image = smoothedGrayFrame;
imageBox2.Image = cannyFrame;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void captureButton_Click_1(object sender, EventArgs e)
{
if (_capture != null)
{
if (_captureInProgress)
{ //start the capture
captureButton.Text = "Start Capture";
_capture.Pause();
}
else
{
//stop the capture
captureButton.Text = "Stop";
_capture.Start();
}
_captureInProgress = !_captureInProgress;
}
}
private void ReleaseData()
{
if (_capture != null)
_capture.Dispose();
}
private void captureImageBox_Click(object sender, EventArgs e)
{
}
private void StartInspection_Load(object sender, EventArgs e)
{
batchNo = batchNo + 1;
txtBatchNumI.Text = batchNo.ToString();
trid = trid + 1;
txtTestRepIDI.Text = trid.ToString();
}
private void lineShape3_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
_capture.Pause();
}
private void button5_Click(object sender, EventArgs e)
{
if (_capture != null) _capture.FlipHorizontal = !_capture.FlipHorizontal;
}
private void button6_Click(object sender, EventArgs e)
{
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
_capture.Stop();
imageBox1.Image = null;
imageBox2.Image = null;
}
private void cmbTileModI_SelectedIndexChanged(object sender, EventArgs e)
{
String constring = "Data Source=JECKDGREAT\\SQLEXPRESS;Initial Catalog=TileDB;Persist Security Info=True;User ID=jeric;Password=jericpogi";
String query = "Select * from addNewTileModel where prodCode= '" + cmbTileModI.Text + "' ;";
SqlConnection conn = new SqlConnection(constring);
SqlCommand command = new SqlCommand(query, conn);
SqlDataReader m_dr;
try
{
conn.Open();
m_dr = command.ExecuteReader();
while (m_dr.Read())
{
String sProdCode = m_dr["prodCode"].ToString();
String sDescProd = m_dr["descProd"].ToString();
String sCeramicType = m_dr["ceramicType"].ToString();
String sClassification = m_dr["classification"].ToString();
String sCollection = m_dr["collection"].ToString();
String sColorFamily = m_dr["colorFamily"].ToString();
String sTileSize = m_dr["tileSize"].ToString();
String sThickness = m_dr["thickness"].ToString();
String sBendingStr = m_dr["bendingStr"].ToString();
String sPorosity = m_dr["porosity"].ToString();
String sChemicalRes = m_dr["chemicalRes"].ToString();
String sWarpage = m_dr["warpage"].ToString();
//Image sTileImage = (Byte [])m_dr["imageTile"];
textBox1.Text = sProdCode;
textBox2.Text = sDescProd;
textBox3.Text = sCeramicType;
textBox4.Text = sClassification;
textBox5.Text = sCollection;
textBox6.Text = sColorFamily;
textBox7.Text = sTileSize;
textBox8.Text = sThickness;
textBox9.Text = sBendingStr;
textBox10.Text = sPorosity;
textBox11.Text = sChemicalRes;
textBox12.Text = sWarpage;
//pictureBox1.Image = sTileImage;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void save_Click(object sender, EventArgs e)
{
//String constring = "Data Source=JECKDGREAT\\SQLEXPRESS;Initial Catalog=TileDB;Persist Security Info=True;User ID=jeric;Password=jericpogi";
//String query = "Insert into testReport5" + "(testReportID, inspectionDate, inspectedBy, batchNumber, prodCode, descProd, ceramicType, classification, collection, colorFamily, tileSize, thickness, bendingStr, porosity, chemicalRes, warpage, tileImage)"
// + "Values('" + txtTestRepIDI.Text + "', '" + dateTimePicker1.Text + "', '" + txtInsByI.Text + "', '" + txtBatchNumI.Text + "', '" + textBox1.Text + "', '" + textBox2.Text + "', '" + textBox3.Text + "', '" + textBox4.Text + "', '" + textBox5.Text + "', '" + textBox6.Text + "', '" + textBox7.Text + "', '" + textBox8.Text + "', '" + textBox9.Text + "', '" + textBox10.Text + "', '" + textBox11.Text + "', '" + textBox12.Text + "', '" + pictureBox1.Image + "')";
//SqlConnection conn = new SqlConnection(constring);
//SqlCommand command = new SqlCommand(query, conn);
//SqlDataReader m_dr;
//try
//{
// conn.Open();
// m_dr = command.ExecuteReader();
// MessageBox.Show("Status Saved");
// while (m_dr.Read())
// {
// }
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message);
//}
}
private void button4_Click(object sender, EventArgs e)
{
var capture = new Emgu.CV.Capture();
using (var ImageFrame = capture.QueryFrame())
{
if (ImageFrame != null)
{
pictureBox1.Image = ImageFrame.ToBitmap();
ImageFrame.Save(@"C:\Users\crowds\Documents\Example\Sample.jpg");
}
_capture.Dispose();
}
//String constring = "Data Source=JECKDGREAT\\SQLEXPRESS;Initial Catalog=TileDB;Persist Security Info=True;User ID=jeric;Password=jericpogi";
//String query = "Insert into imageTable" + " (tileImage)" + "Values('" + pictureBox1.Image + "')";
//SqlConnection conn = new SqlConnection(constring);
//SqlCommand command = new SqlCommand(query, conn);
//SqlDataReader m_dr;
//var capture = new Emgu.CV.Capture();
//try
//{
// conn.Open();
// m_dr = command.ExecuteReader();
// MessageBox.Show("Status Saved");
// using (var ImageFrame = capture.QueryFrame())
// {
// if (ImageFrame != null)
// {
// pictureBox1.Image = ImageFrame.ToBitmap();
// //ImageFrame.Save(@"C:\Users\crowds\Documents\Example\Sample.jpg");
// //ImageFrame.Save(@"Insert into testReport1" + "(tileImage)");
// }
// _capture.Dispose();
// }
// while (m_dr.Read())
// {
// }
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message);
//}
}
private void pictureBox1_Click_1(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (_capture != null)
{
//SetValueForText = cmbTileModI.Text;
//StartCompare FF = new StartCompare();
FF.fa = cmbTileModI.Text;
FF.fb = txtBatchNumI.Text;
FF.fc = dateTimePicker1.Text;
FF.fd = txtTestRepIDI.Text;
FF.fe = txtInsByI.Text;
this.Hide();
FF.Show();
_capture.Dispose();
}
}
private void pictureBox1_Click_2(object sender, EventArgs e)
{
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void txtBatchNumI_TextChanged(object sender, EventArgs e)
{
}
}
}