private void timer1_Tick(object sender, EventArgs e) { DT_Now = DateTime.Now; if (VideoViewer.GetCurrentVideoFrame() != null) { BarcodeReader Reader = new BarcodeReader(); Bitmap img = new Bitmap(VideoViewer.GetCurrentVideoFrame()); //----------------加入CV--------------------- //Image<Gray, byte> I = new Image<Gray, byte>(img); //Image<Bgr, byte> DrawI = I.Convert<Bgr, byte>(); //Image<Gray, byte> CannyImage = I.Clone(); //灰階處理 //CvInvoke.GaussianBlur(I, CannyImage, new Size(5, 5), 0); //CvInvoke.Canny(I, CannyImage, 100, 200); //MyCV.BoundingBox(CannyImage, DrawI); //pictureBox1.Image = DrawI.Bitmap; //pictureBox2.Image = CannyImage.Bitmap; //Result result = Reader.Decode(DrawI.Bitmap); //----------------CV end---------------------- Result result = Reader.Decode(img); //原本 img.Dispose(); //釋放資源 if (result != null) { Scan_result_richTextBox.SelectionColor = Color.Green; Scan_result_richTextBox.AppendText("[" + DT_Now + "] 掃描條碼顯示: " + result + Environment.NewLine); //Scan_result.Items.Add("DBconnection = " + connectionString); //資料庫(自動Dispose寫法) String check_psd = "SELECT * FROM staff_info WHERE Encode_ID = '" + result + "'"; using (OleDbCommand cmd = new OleDbCommand()) { DataSet ds = new DataSet(); Table_Row TBR = new Table_Row(); List <Table_Row> table_row = new List <Table_Row>(); //OleDbDataReader dr; cmd.Connection = Access_DataBase.DB_Conn_Open(connectionString_StaffDB); cmd.CommandText = check_psd; //dr = cmd.ExecuteReader(); OleDbDataAdapter adapter = new OleDbDataAdapter(cmd); try { adapter.Fill(ds, "Encode_ID"); adapter.Fill(ds, "Name"); adapter.Fill(ds, "Sex"); adapter.Fill(ds, "Job"); adapter.Fill(ds, "Phone"); adapter.Fill(ds, "CarNumP"); adapter.Fill(ds, "Photo"); try { TBR.Id = ds.Tables["Encode_ID"].Rows[0]["Encode_ID"].ToString(); TBR.Name = ds.Tables["Name"].Rows[0]["Name"].ToString(); TBR.Sex = ds.Tables["Sex"].Rows[0]["Sex"].ToString(); TBR.Job = ds.Tables["Job"].Rows[0]["Job"].ToString(); TBR.CarNumP = ds.Tables["CarNumP"].Rows[0]["CarNumP"].ToString(); TBR.CarNumP = ds.Tables["Phone"].Rows[0]["Phone"].ToString(); TBR.Photo = (byte[])ds.Tables["Photo"].Rows[0]["Photo"]; table_row.Add(TBR); ds.Tables.Clear(); string Table_name = DT_Now.ToString("yyyy_MM"); Check_Table_Exsits(Access_DataBase.DB_Conn_Open(connectionString_QRcode_Scan), cmd, Table_name);//檢查有無當月Table沒有建立 ShowInfo SI_form = new ShowInfo(table_row, this, Table_name, connectionString_QRcode_Scan); } catch { TimerThread.Stop(); string message = "此條碼可能被註銷,或者不是岡山榮家發行"; string caption = "查無此資料"; MessageBoxButtons buttons = MessageBoxButtons.OK; DialogResult DiaResult = MessageBox.Show(message, caption, buttons); //MessageBox.Show(message, caption, buttons); if (DiaResult == DialogResult.OK) { TimerThread.Start(); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } } }
public void OnServerClose() { RemoveHandler(); RemoveUpdate(); TimerThread.Stop(); }