嘿抱歉看起来像是一个愚蠢的问题,我通常在PHP中开发,但我必须对由过去的开发人员构建的Web应用程序进行更改,而且我真的没有.net
的任何经验应该很容易解决问题我有一个Web应用程序用于管理员工在我们添加和编辑员工时,我只想添加手机号码输入
下面是我到目前为止所尝试的
我在数据库中添加了一个字段,调用UserPhone
当我进行以下更改时,它会破坏代码,我不确定现在我哪里出错了它只有一个额外的输入字段。
抱歉,这可能是一些代码过载。我将ID =“txtMobile”的输入字段添加到aspx文件
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="tbl_form">
<tr>
<td colspan="4">
<asp:Label ID="lblErrorMessage" runat="server" Text="" Visible="false" ForeColor="Red"
Font-Bold="true"></asp:Label>
</td>
</tr>
<tr>
<td>
*
</td>
<td>
Employee Number
</td>
<td>
:
</td>
<td>
<asp:TextBox runat="server" ID="txtEmployeeNumber" MaxLength="25" class="textfield"></asp:TextBox>
<asp:RequiredFieldValidator ID="vEmployeeNumber" runat="server" ControlToValidate="txtEmployeeNumber"
ErrorMessage="Employee Number Field is required" ValidationGroup="User"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
*
</td>
<td>
First Name
</td>
<td>
:
</td>
<td>
<asp:TextBox runat="server" ID="txtFirstName" MaxLength="25" class="textfield"></asp:TextBox>
<asp:RequiredFieldValidator ID="vFirstName" runat="server" ControlToValidate="txtFirstName"
ErrorMessage="First Name Field is required" ValidationGroup="User"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
*
</td>
<td>
Last Name
</td>
<td>
:
</td>
<td>
<asp:TextBox runat="server" ID="txtLastName" MaxLength="25" class="textfield"></asp:TextBox>
<asp:RequiredFieldValidator ID="vLastName" runat="server" ControlToValidate="txtLastName"
ErrorMessage="Last Name Field is required" ValidationGroup="User"></asp:RequiredFieldValidator>
</td>
</tr>
<tr style="height: 29px; vertical-align: top;">
<td>
</td>
<td>
Mobile
</td>
<td>
:
</td>
<td>
<asp:TextBox runat="server" ID="txtMobile" class="textfield" MaxLength="100"></asp:TextBox>
</td>
</tr>
<tr style="height: 29px; vertical-align: top;">
<td>
</td>
<td>
E Mail
</td>
<td>
:
</td>
<td>
<asp:TextBox runat="server" ID="txtEMail" class="textfield" MaxLength="100"></asp:TextBox>
<asp:RegularExpressionValidator ID="emailformat" runat="server" ControlToValidate="txtEMail"
ValidationGroup="User" ErrorMessage="Please enter Email in proper format" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
C#Code Behind file 我为每个函数添加了一行代码,目前已被注释掉
protected void btnCancel_Click(object sender, EventArgs e)
{
try
{
base.Response.Redirect("DisplayEmployee.aspx", false);
}
catch (SqlException sqlException)
{
BL_ErrorHandling.SQLExceptionHandling(sqlException, "ManageEmployee", "btnCancel_Click", "SQL Error in ManageEmployee");
}
catch (Exception exception)
{
BL_ErrorHandling.GeneralExceptionHandling(exception, "ManageEmployee", "btnCancel_Click", "General Error in ManageEmployee");
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
DataRow drNew = null;
BL_UserMaster objUser = new BL_UserMaster(this.sConnStr);
if (this.dsManageUser.Tables["User"].Rows.Count != 0)
{
this.gUserID = new Guid(this.dsManageUser.Tables["User"].Rows[0]["UserID"].ToString());
}
else
{
this.gUserID = Guid.NewGuid();
}
string ErrorMessage = "";
ErrorMessage = objUser.CheckUserMasterForUniqueLoginNameAndEmpNo(this.gUserID, this.txtEmployeeNumber.Text, this.txtUserName.Text);
if (string.IsNullOrEmpty(ErrorMessage))
{
if (this.dsManageUser.Tables["User"].Rows.Count != 0)
{
drNew = this.dsManageUser.Tables["User"].Rows[0];
drNew["UserIsActive"] = this.chkIsActive.Checked;
if (!string.IsNullOrEmpty(this.txtPassword.Text))
{
drNew["UserPassword"] = this.txtPassword.Text;
}
}
else
{
drNew = this.dsManageUser.Tables["User"].NewRow();
drNew["UserID"] = this.gUserID;
drNew["UserPassword"] = this.txtPassword.Text;
}
drNew["EmployeeNumber"] = this.txtEmployeeNumber.Text;
drNew["UserFirstName"] = this.txtFirstName.Text;
drNew["UserLastName"] = this.txtLastName.Text;
drNew["UserEmailID"] = this.txtEMail.Text;
// drNew["UserPhone"] = this.txtMobile.Text;
drNew["UserOrganisationID"] = new Guid(this.ddlOrganisation.SelectedValue);
drNew["UserVenueId"] = this.ddlVenue.SelectedValue;
drNew["UserName"] = this.txtUserName.Text;
drNew["UserRoleID"] = this.ddlRole.SelectedValue;
if (this.dsManageUser.Tables["User"].Rows.Count == 0)
{
this.dsManageUser.Tables["User"].Rows.Add(drNew);
}
objUser.SaveUser(this.dsManageUser);
this.btnCancel_Click(this.btnCancel, new EventArgs());
}
else
{
this.lblErrorMessage.Visible = true;
this.lblErrorMessage.Text = ErrorMessage;
}
}
catch (SqlException sqlException)
{
BL_ErrorHandling.SQLExceptionHandling(sqlException, "ManageEmployee", "btnSave_Click", "SQL Error in ManageEmployee");
}
catch (Exception exception)
{
BL_ErrorHandling.GeneralExceptionHandling(exception, "ManageEmployee", "btnSave_Click", "General Error in ManageEmployee");
}
}
protected void DisplayData()
{
try
{
BL_UserMaster objUser = new BL_UserMaster(this.sConnStr);
this.dsManageUser = objUser.GetUser(this.gUserID);
this.trActive.Visible = false;
this.txtUserName.ReadOnly = false;
if (this.dsManageUser.Tables["User"].Rows.Count > 0)
{
this.txtEmployeeNumber.Text = this.dsManageUser.Tables["User"].Rows[0]["EmployeeNumber"].ToString();
this.txtFirstName.Text = this.dsManageUser.Tables["User"].Rows[0]["UserFirstName"].ToString();
this.txtLastName.Text = this.dsManageUser.Tables["User"].Rows[0]["UserLastName"].ToString();
this.ddlOrganisation.SelectedValue = this.dsManageUser.Tables["User"].Rows[0]["UserOrganisationID"].ToString();
this.ddlVenue.SelectedValue = this.dsManageUser.Tables["User"].Rows[0]["UserVenueId"].ToString();
this.txtUserName.Text = this.dsManageUser.Tables["User"].Rows[0]["UserName"].ToString();
this.txtPassword.Text = this.dsManageUser.Tables["User"].Rows[0]["UserPassword"].ToString();
this.ddlRole.SelectedValue = this.dsManageUser.Tables["User"].Rows[0]["UserRoleID"].ToString();
this.txtEMail.Text = this.dsManageUser.Tables["User"].Rows[0]["UserEmailID"].ToString();
//this.txtMobile.Text = this.dsManageUser.Tables["User"].Rows[0]["UserPhone"].ToString();
this.trActive.Visible = true;
this.chkIsActive.Checked = Convert.ToBoolean(this.dsManageUser.Tables["User"].Rows[0]["UserIsActive"]);
}
this.Session["dsManageUser"] = this.dsManageUser;
}
catch (SqlException sqlException)
{
BL_ErrorHandling.SQLExceptionHandling(sqlException, "ManageEmployee", "DisplayData", "SQL Error in ManageEmployee");
}
catch (Exception exception)
{
BL_ErrorHandling.GeneralExceptionHandling(exception, "ManageEmployee", "DisplayData", "General Error in ManageEmployee");
}
}
用户主类
using Microsoft.ApplicationBlocks.Data;
using System;
using System.Data;
using System.Data.SqlClient;
namespace BLPubGroupTimeSheet
{
public class BL_UserMaster
{
private string sConnString = "";
public BL_UserMaster(string sConnectionString)
{
this.sConnString = sConnectionString;
}
public string ChangePassword(Guid UserID, string OLDPassword, string NewPassword)
{
SqlConnection objConn = new SqlConnection(this.sConnString);
objConn.Open();
string sMessage = "";
try
{
try
{
SqlParameter[] objParam = new SqlParameter[] { new SqlParameter("@UserID", SqlDbType.UniqueIdentifier), null, null, null };
objParam[0].Value = UserID;
objParam[1] = new SqlParameter("@UserOLDPassword", SqlDbType.VarChar, 20);
objParam[1].Value = OLDPassword;
objParam[2] = new SqlParameter("@UserNewPassword", SqlDbType.VarChar, 20);
objParam[2].Value = NewPassword;
objParam[3] = new SqlParameter("@Message", SqlDbType.VarChar, 200);
objParam[3].Direction = ParameterDirection.Output;
SqlHelper.ExecuteNonQuery(objConn, CommandType.StoredProcedure, "UpdateUserMasterForChangePassword", objParam);
sMessage = (objParam[3].Value != null ? objParam[3].Value.ToString() : "Error in updating password");
}
catch (SqlException sqlException)
{
SqlException exsql = sqlException;
sMessage = "Error in updating password";
BL_ErrorHandling.SQLExceptionHandling(exsql, "BL_UserMaster", "ChangePassword", "SQL Error in BL_UserMaster");
}
catch (Exception exception)
{
Exception ex = exception;
sMessage = "Error in updating password";
BL_ErrorHandling.GeneralExceptionHandling(ex, "BL_UserMaster", "ChangePassword", "General Error in BL_UserMaster");
}
}
finally
{
objConn.Close();
}
return sMessage;
}
public DataSet CheckUserLogin(string UserName, string Password)
{
DataSet dsReturn = new DataSet();
try
{
SqlParameter[] objParam = new SqlParameter[] { new SqlParameter("@UserName", SqlDbType.VarChar, 50), null };
objParam[0].Value = UserName;
objParam[1] = new SqlParameter("@UserPassword", SqlDbType.VarChar, 20);
objParam[1].Value = Password;
dsReturn = SqlHelper.ExecuteDataset(this.sConnString, CommandType.StoredProcedure, "CheckUserLogin", objParam);
}
catch (SqlException sqlException)
{
BL_ErrorHandling.SQLExceptionHandling(sqlException, "BL_UserMaster", "CheckUserLogin", "SQL Error in BL_UserMaster");
}
catch (Exception exception)
{
BL_ErrorHandling.GeneralExceptionHandling(exception, "BL_UserMaster", "CheckUserLogin", "General Error in BL_UserMaster");
}
return dsReturn;
}
public string CheckUserMasterForUniqueLoginNameAndEmpNo(Guid UserID, string EmployeeNumber, string UserName)
{
string sErrorMessage = "";
try
{
SqlParameter[] objParam = new SqlParameter[] { new SqlParameter("@UserID", SqlDbType.UniqueIdentifier), null, null, null };
objParam[0].Value = UserID;
objParam[1] = new SqlParameter("@EmployeeNumber", SqlDbType.VarChar, 25);
objParam[1].Value = EmployeeNumber;
objParam[2] = new SqlParameter("@UserName", SqlDbType.VarChar, 50);
objParam[2].Value = UserName;
objParam[3] = new SqlParameter("@ErrorMessage", SqlDbType.VarChar, 100);
objParam[3].Direction = ParameterDirection.Output;
SqlHelper.ExecuteNonQuery(this.sConnString, CommandType.StoredProcedure, "CheckUserMasterForUniqueLoginNameAndEmpNo", objParam);
sErrorMessage = (objParam[3].Value != null ? objParam[3].Value.ToString() : "");
}
catch (SqlException sqlException)
{
SqlException exsql = sqlException;
sErrorMessage = exsql.Message;
BL_ErrorHandling.SQLExceptionHandling(exsql, "BL_UserMaster", "CheckUserMasterForUniqueLoginNameAndEmpNo", "SQL Error in BL_UserMaster");
}
catch (Exception exception)
{
Exception ex = exception;
sErrorMessage = ex.Message;
BL_ErrorHandling.GeneralExceptionHandling(ex, "BL_UserMaster", "CheckUserMasterForUniqueLoginNameAndEmpNo", "General Error in BL_UserMaster");
}
return sErrorMessage;
}
public DataSet GetRole()
{
DataSet dsReturn = new DataSet();
try
{
dsReturn = SqlHelper.ExecuteDataset(this.sConnString, CommandType.StoredProcedure, "GetRoleMaster");
dsReturn.Tables[0].TableName = "Role";
}
catch (SqlException sqlException)
{
BL_ErrorHandling.SQLExceptionHandling(sqlException, "BL_UserMaster", "GetRole", "SQL Error in BL_UserMaster");
}
catch (Exception exception)
{
BL_ErrorHandling.GeneralExceptionHandling(exception, "BL_UserMaster", "GetRole", "General Error in BL_UserMaster");
}
return dsReturn;
}
public DataSet GetUser(Guid UserID)
{
DataSet dsReturn = new DataSet();
try
{
SqlParameter[] objParam = new SqlParameter[] { new SqlParameter("@UserID", SqlDbType.UniqueIdentifier) };
objParam[0].Value = UserID;
dsReturn = SqlHelper.ExecuteDataset(this.sConnString, CommandType.StoredProcedure, "GetUserMaster", objParam);
dsReturn.Tables[0].TableName = "User";
}
catch (SqlException sqlException)
{
BL_ErrorHandling.SQLExceptionHandling(sqlException, "BL_UserMaster", "GetUser", "SQL Error in BL_UserMaster");
}
catch (Exception exception)
{
BL_ErrorHandling.GeneralExceptionHandling(exception, "BL_UserMaster", "GetUser", "General Error in BL_UserMaster");
}
return dsReturn;
}
public DataSet GetUserForDisplay()
{
DataSet dsReturn = new DataSet();
try
{
dsReturn = SqlHelper.ExecuteDataset(this.sConnString, CommandType.StoredProcedure, "GetAllUserMaster");
dsReturn.Tables[0].TableName = "AllUser";
}
catch (SqlException sqlException)
{
BL_ErrorHandling.SQLExceptionHandling(sqlException, "BL_UserMaster", "GetUserForDisplay", "SQL Error in BL_UserMaster");
}
catch (Exception exception)
{
BL_ErrorHandling.GeneralExceptionHandling(exception, "BL_UserMaster", "GetUserForDisplay", "General Error in BL_UserMaster");
}
return dsReturn;
}
public bool ResetPassword(Guid UserID, string NewPassword)
{
SqlConnection objConn = new SqlConnection(this.sConnString);
objConn.Open();
bool bReturn = false;
try
{
try
{
SqlParameter[] objParam = new SqlParameter[] { new SqlParameter("@UserID", SqlDbType.UniqueIdentifier), null };
objParam[0].Value = UserID;
objParam[1] = new SqlParameter("@UserNewPassword", SqlDbType.VarChar, 20);
objParam[1].Value = NewPassword;
SqlHelper.ExecuteNonQuery(objConn, CommandType.StoredProcedure, "UpdateUserMasterForResetPassword", objParam);
bReturn = true;
}
catch (SqlException sqlException)
{
SqlException exsql = sqlException;
bReturn = false;
BL_ErrorHandling.SQLExceptionHandling(exsql, "BL_UserMaster", "ResetPassword", "SQL Error in BL_UserMaster");
}
catch (Exception exception)
{
Exception ex = exception;
bReturn = false;
BL_ErrorHandling.GeneralExceptionHandling(ex, "BL_UserMaster", "ResetPassword", "General Error in BL_UserMaster");
}
}
finally
{
objConn.Close();
}
return bReturn;
}
public void SaveUser(DataSet dsUser)
{
SqlConnection objConn = new SqlConnection(this.sConnString);
objConn.Open();
try
{
try
{
string[] strArrays = new string[] { "UserID", "EmployeeNumber", "UserFirstName", "UserLastName", "UserOrganisationID", "UserVenueId", "UserName", "UserPassword", "UserRoleID", "UserPhone", "UserEmailID" };
SqlCommand objInsert = SqlHelper.CreateCommand(objConn, "InsertUserMaster", strArrays);
string[] strArrays1 = new string[] { "UserID", "EmployeeNumber", "UserFirstName", "UserLastName", "UserOrganisationID", "UserVenueId", "UserPassword", "UserRoleID", "UserPhone", "UserEmailID", "UserIsActive", "UserName" };
SqlCommand objUpdate = SqlHelper.CreateCommand(objConn, "UpdateUserMaster", strArrays1);
SqlHelper.UpdateDataset(objInsert, new SqlCommand(), objUpdate, dsUser, "User");
}
catch (SqlException sqlException)
{
BL_ErrorHandling.SQLExceptionHandling(sqlException, "BL_UserMaster", "SaveUser", "SQL Error in BL_UserMaster");
}
catch (Exception exception)
{
BL_ErrorHandling.GeneralExceptionHandling(exception, "BL_UserMaster", "SaveUser", "General Error in BL_UserMaster");
}
}
finally
{
objConn.Close();
}
}
}
}