Mainform.cs读取例程超过两次

时间:2013-07-26 05:10:02

标签: c# .net winforms mono

真正的问题: Mainform读取例程超过两次。以及MainForm中的所有组件和对象都是空的 例如:

按钮第一次运行优秀

添加我的代码:

    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();
        }
    }

}

//////////调用Form 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  ID_EMPLEADO=@ID_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 Digital Persona设备,无法读取指纹

如何清空或重置过程或例程(MainForm,VerificationForm和CaptureForm) 感谢。

1 个答案:

答案 0 :(得分: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 public bool = false;

void Btn_InicioClick  (object sender, EventArgs e)
{

ToRestart = true;
             this.Close ();

}

重置指纹识别器和winform控件

感谢