所以我在运行我的代码时试图找出并破坏每个方法,我仍然无法找到为什么setTempID始终为0,我已经为它分配了一个值。
这是我的代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
//imports
using DHELTASSys.DataAccess;
using DHELTASSys.Modules;
using DHELTASSys.AuditTrail;
namespace Enrollment
{
public partial class HRLogin : Form
{
HRModuleBL obj = new HRModuleBL();
DHELTASSysAuditTrail audit = new DHELTASSysAuditTrail();
public HRLogin()
{
InitializeComponent();
}
private void txtLogin_Click(object sender, EventArgs e)
{
obj.Emp_id = int.Parse(txtEmpID.Text);
audit.Emp_id = int.Parse(txtEmpID.Text);
obj.Password = txtPassword.Text;
if (obj.AccountEnrollmentLogin().Rows.Count == 0)
{
MessageBox.Show("Username and Password is incorrect!");
}
else if (obj.CheckIfHRManager().Rows.Count == 0)
{
MessageBox.Show("You are not allowed to access this system!");
}
else
{
CreateAccount frm = new CreateAccount();
frm.FormClosed += new FormClosedEventHandler(frm_FormClosed);
audit.AddAuditTrail("Has logged in into the Fingerprint Enrollment System.");
frm.setEmpID = int.Parse(txtEmpID.Text);
frm.Show();
this.Hide();
}
}
void frm_FormClosed(object sender, FormClosedEventArgs e)
{
this.Show();
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
这是另一种形式
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
//imports
using DHELTASSys.AuditTrail;
using DHELTASSys.Modules;
namespace Enrollment
{
delegate void Function(); // a simple delegate for marshalling calls from event handlers to the GUI thread
public partial class CreateAccount : Form
{
HRModuleBL obj = new HRModuleBL();
DHELTASSysAuditTrail audit = new DHELTASSysAuditTrail();
private int emp_id;
public int setEmpID
{
set { emp_id = value;}
}
public CreateAccount()
{
InitializeComponent();
}
private void CloseButton_Click(object sender, EventArgs e)
{
Close();
}
private void OnTemplate(DPFP.Template template)
{
this.Invoke(new Function(delegate()
{
Template = template;
VerifyButton.Enabled = SaveButton.Enabled = (Template != null);
if (Template != null)
MessageBox.Show("The fingerprint template is ready for verification and saving", "Fingerprint Enrollment");
else
MessageBox.Show("The fingerprint template is not valid. Repeat fingerprint enrollment.", "Fingerprint Enrollment");
}));
}
private DPFP.Template Template;
private void EnrollButton_Click(object sender, EventArgs e)
{
EnrollmentForm Enroller = new EnrollmentForm();
Enroller.OnTemplate += this.OnTemplate;
Enroller.ShowDialog();
}
private void SaveButton_Click(object sender, EventArgs e)
{
obj.Last_name = txtLastname.Text;
obj.First_name = txtFirstName.Text;
obj.Middle_name = txtMiddleName.Text;
obj.Position_name = cmbPosition.Text;
obj.Company_name = cmbCompany.Text;
obj.Password = txtTempPassword.Text;
obj.Department_name = cmbDepartment.Text;
if (obj.Last_name == string.Empty) //Validation for empty texts
{
MessageBox.Show("Last name can't be empty!");
} else if (obj.First_name == string.Empty)
{
MessageBox.Show("First name can't be empty!");
}
else if (obj.Middle_name == string.Empty)
{
MessageBox.Show("Middle name can't be empty!");
}
else if (obj.Position_name == string.Empty)
{
MessageBox.Show("Position name can't be empty!");
}
else if (obj.Department_name == string.Empty)
{
MessageBox.Show("Deparment can't be empty!");
}
else if (obj.Company_name == string.Empty)
{
MessageBox.Show("Company name can't be empty!");
}
else if (obj.Password == string.Empty)
{
MessageBox.Show("Password can't be empty!");
}
else if (txtConfirmTempPassword.Text == string.Empty)
{
MessageBox.Show("Please verify your input password!");
}
else
{
if (txtTempPassword.Text != txtConfirmTempPassword.Text)
{
MessageBox.Show("Password does not match", "Password Mismatch",
MessageBoxButtons.OK);
}
else
{
MemoryStream fingerprintData = new MemoryStream();
Template.Serialize(fingerprintData);
fingerprintData.Position = 0;
BinaryReader br = new BinaryReader(fingerprintData);
Byte[] bytes = br.ReadBytes((Int32)fingerprintData.Length);
audit.Emp_id = emp_id;
obj.Biometric_code = bytes;
obj.AddAccountSetTempPassword();
}
}
}
private void VerifyButton_Click(object sender, EventArgs e)
{
VerificationForm Verifier = new VerificationForm();
Verifier.Verify(Template);
}
}
}
我将它设置为frm.setEmpID,以便我可以从另一个表单中获取它。
感谢帮助人员。
答案 0 :(得分:0)
也许在SaveButton_Click
形式的CreateAccount
事件中,您还需要设置在该表单中定义的obj实例的Emp_Id
变量(正如您在该实例中所做的那样) HRModuleBL
在第一种形式中定义。)
private void SaveButton_Click(object sender, EventArgs e)
{
.....
audit.Emp_id = emp_id;
obj.Emp_id = emp_id;
obj.Biometric_code = bytes;
obj.AddAccountSetTempPassword();
.....
}