2013-07-26 36 views
0

實際問題: Mainform讀取例程超過兩次。和MainForm的空 實例內部的所有組件和對象:Mainform.cs讀取例程超過兩次

按鈕第一的優異

運行添加我的代碼:

namespace CheckNet 
{ 
    /// <summary> 
    /// Description of MainForm. 
    /// </summary> 
    delegate void Function(); 
    public partial class MainForm : Form 
    { 
     public MainForm() 
     { 
      // 
      // The InitializeComponent() call is required for Windows Forms designer support. 
      // 
      InitializeComponent(); 
      Btn_Inicio.Click += new EventHandler (Btn_InicioClick); 
      // VerificationForm += new EventHandler (VerificationForm); 

      // 
      // TODO: Add constructor code after the InitializeComponent() call. 
      // 
     } 

     private DPFP.Template Template; 
     private DPFP.Template myTemplate; 
    // 





     void Btn_InicioClick(object sender, EventArgs e) 

     { 
      // call rutine ejecutar boton primera vez 
        // 
      if (this.panelContenedor.Controls.Count > 0) 
       this.panelContenedor.Controls.RemoveAt(0); 
       VerificationForm hijos = new VerificationForm(); 
       hijos.TopLevel = false; 
       hijos.FormBorderStyle = FormBorderStyle.None; 
       hijos.Dock = DockStyle.Fill; 
       this.panelContenedor.Controls.Add(hijos); 
       this.panelContenedor.Tag = hijos; 

       hijos.Show(); 


     } 




     void Button7Click(object sender, EventArgs e) 
     { 
      AddFormInPanel(new Hijo2());   
     } 


    private void AddFormInPanel(object formHijo) 
     { 
       if (this.panelContenedor.Controls.Count > 0) 
       this.panelContenedor.Controls.RemoveAt(0); 
       Form fh = formHijo as Form; 
       fh.TopLevel = false; 
       fh.FormBorderStyle = FormBorderStyle.None; 
       fh.Dock = DockStyle.Fill; 
       this.panelContenedor.Controls.Add(fh); 
       this.panelContenedor.Tag = fh; 
       fh.Show(); 
     } 



     void Close_bottonClick(object sender, EventArgs e) 
     { 
      Close(); 
     } 
    } 

} 

//////////調用方式VerificationForm

namespace CheckNet 
{ 
    /* NOTE: This form is inherited from the CaptureForm, 
     so the VisualStudio Form Designer may not load it properly 
     (at least until you build the project). 
     If you want to make changes in the form layout - do it in the base CaptureForm. 
     All changes in the CaptureForm will be reflected in all derived forms 
     (i.e. in the EnrollmentForm and in the VerificationForm) 
    */ 
    public class VerificationForm : CaptureForm 
    { 

     public void Verify(DPFP.Template template) 
     { 
      Template = template; 
      ShowDialog(); 
     } 

     protected override void Init() 
     { 
      base.Init(); 
      base.Text = "Fingerprint Verification "; 
      Verificator = new DPFP.Verification.Verification();  // Create a fingerprint template verificator 
      UpdateStatus(0); 
     } 

     protected override void Process(DPFP.Sample Sample) 
     { 
      base.Process(Sample); 

      // Process the sample and create a feature set for the enrollment purpose. 
      DPFP.FeatureSet features = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification); 

      // Check quality of the sample and start verification if it's good 
      // TODO: move to a separate task 
      template= TomarHuellaBd(); 
       Template=template; 

      if (features != null) 
      { 
       // Compare the feature set with our template 
       DPFP.Verification.Verification.Result result = new DPFP.Verification.Verification.Result(); 
       Verificator.Verify(features, Template, ref result); 
       UpdateStatus(result.FARAchieved); 
       if (result.Verified) 
       { 

        MakeReport2(" "); 



       } 
       else 
        MakeReport("Huella no Identificado."); 
      } 
     } 

     private void UpdateStatus(int FAR) 
     { 
      // Show "False accept rate" value 
      SetStatus(String.Format("False Accept Rate (FAR) = {0}", FAR)); 
     } 
         private DPFP.Template TomarHuellaBd() 
      { 
       // Verifica la Huella desde una base de Datos 

       bool Bandera=true; 
      try { // Validar Numero 
       int idEmpleado =int.Parse(Global_ip.Globalip.ToString()); 
       } catch { 
        MessageBox.Show("Error Numero de Empleado ", Global_ip.Globalip.ToString()); 
        Bandera=false; 
        // 

        return null; 

        // 
       } 

      try 
       { 
       int NumEmpleado=int.Parse(Global_ip.Globalip.ToString()); 
       enlacedb db = new enlacedb(); 
       FbConnection conexion2 = new FbConnection(db.connectionString); 
       conexion2.Open(); 
       FbCommand Frda = new FbCommand("SELECT * FROM REGHUMAN WHERE [email protected]_EMPLEADO", conexion2); 
         Frda.Parameters.Add("@ID_EMPLEADO",SqlDbType.VarChar).Value = NumEmpleado; 
         FbDataReader leerF = Frda.ExecuteReader(); 
         bool fseek= leerF.Read(); 
          if (fseek) { 



          Global_Nombre.GlobalNombre= leerF.GetValue(4).ToString(); 



           Byte[] imageF = new Byte[Convert.ToInt32 ((leerF.GetBytes(2, 0,null, 0, Int32.MaxValue)))]; 

           leerF.GetBytes(2, 0, imageF, 0, imageF.Length); 
           MemoryStream memfpt = new MemoryStream(imageF); 
           DPFP.Template template = new DPFP.Template(memfpt); 
           return template; 
           } 
         else 
         { 
         return null; 
         } 
       } 
       catch (Exception err2) { 
           MessageBox.Show(err2.ToString()); 
         } 
      return null; 
      } 



     private DPFP.Template Template; 
     private DPFP.Template template; 
     private DPFP.Verification.Verification Verificator; 

    } 
} 

如果用戶請求運行第二次相同的按鈕

VerificationForm程序和居民CaptureForm數字人裝置,並且不能讀取指紋

如何清空或重置過程或程序(MainForm的,VerificationForm和CaptureForm) 謝謝。

+0

流量: 開放的MainForm: 按鈕準備指紋識別器 開放VerificationForm.cs CaptureForm.cs調用 - ----這些步驟如果你可以讀取設備----- 如果用戶請求bu tton再次按下------- 這裏: 按鈕準備指紋識別器 開放VerificationForm.cs CaptureForm.cs調用 ----指紋讀取裝置,鎖定------ ------------------------- 如何製作和清空或重置。不想關閉程序並重新打開-------------------- 謝謝。 –

回答

0

解決方案是:

修改的Program.cs

private static void Main (string [] args) 
{ 
Application.EnableVisualStyles(); 
Application.SetCompatibleTextRenderingDefault (false); 

      Fm1 MainForm = new MainForm(); 
      Application.Run (fm1); 

      if (fm1.ToRestart) 
       Application.Restart(); 
     } 

開始 ToRestart公共BOOL = FALSE;

void Btn_InicioClick (object sender, EventArgs e) 
{ 

ToRestart = true; 
      this.Close(); 

} 

重置指紋識別器和WinForm的控制

感謝