【发布时间】:2015-07-01 14:42:44
【问题描述】:
我已经修改了我的代码和问题,以更好地反映我想要完成的任务。
背景:我的项目中有不同的层接口。
- 服务层 - 处理我的业务逻辑,验证条目,(大脑)
- 数据访问层 - 只执行它传递的方法或函数
- 需要执行方法的 Aspx 和 aspx.cs 文件(即用户界面)
这是我的 ConnectionTypeSetup.aspx.cs 文件的代码,我还标记了错误所在的行:
protected void uxSaveBtn_Click(object sender, EventArgs e)
{
var accountTrackersvc = new AccountTrackerSvc();
//Insert or update record
var result = ViewState["ConnectionTypeID"] == null ?
accountTrackersvc.InsertConnectionType(uxConnectionTypeDescTxt.Text.Trim(),
CommonSVC.GetUserInfoFormattedFromSession())
/*Error on this line */ : accountTrackersvc.UpdateConnectionType(DataConverter.StringToInteger(ViewState["ConnectionTypeID"].ToString()),
uxConnectionTypeDescTxt.Text.Trim(),
Enums.GetIsDisabledByItemStatusValue(SafeValueAccessor.GetControlValue(uxStatusDdl)),
CommonSVC.GetUserInfoFormattedFromSession(),"Default",false);
//Check result
if(result.Successful)
{
uxInfoMsg.DisplayMessage(result.Message, InfoMessage.InfoMessageType.Success);
BindGridContent();
uxPopupMdl.Hide();
}
else
{
uxModalInfoMsg.DisplayMessage(result.Message, InfoMessage.InfoMessageType.Failure);
uxPopupMdl.Show();
}
// Hide progress indicator
Master.HideProgressIndicator();
再次处理我的业务逻辑的服务层格式如下。请注意,使用了 2 种不同的方法,Insert 和 Update:
public BO.OperationResult InsertConnectionType(string connectionTypeDesc, string createdBy)
{
var operationResult = new BO.OperationResult();
// connection type description required
if (connectionTypeDesc.Trim().Length <= 0)
{
operationResult.Successful = false;
operationResult.Message += "Connection type description is required";
}
//Createdby required
if (createdBy.Trim().Length <= 0)
{
operationResult.Successful = false;
operationResult.Message += "A record has not been saved in the form this entry was created by";
}
if (operationResult.Successful)
{
operationResult.DBPrimaryKey = new DAL.AccountTrackerDAL().InsertConnectionType(connectionTypeDesc.Trim(), createdBy);
operationResult.Message = "Account Access Level Saved Successfully";
}
return operationResult;
}
第二个业务逻辑更新方法和代码:
public BO.OperationResult UpdateConnectionType(int connectionTypeID, string connectionTypeDesc,bool isDisabled,string lastUpdatedBy)
{
var operationResult = new BO.OperationResult();
if (connectionTypeDesc.Trim().Length <= 0)
{
operationResult.Successful = false;
operationResult.Message += "Connection Type Description has not successfully updated.";
}
if (lastUpdatedBy.Trim().Length <= 0)
{
operationResult.Successful = false;
operationResult.Message += "Last updated by must be entered.";
}
if (operationResult.Successful)
{
operationResult.DBPrimaryKey = new DAL.AccountTrackerDAL().UpdateConnectionType(connectionTypeID, lastUpdatedBy, connectionTypeDesc, isDisabled);
operationResult.Message = "Account Access Level Saved Successfully";
}
return operationResult;
}
最后,我将仅包含 DAL 层的方法签名,因为我认为这应该足够了,并且不会用代码使这个问题饱和。
更新连接类型
public int UpdateConnectionType(int connectionTypeID, string lastUpdatedBy, string connectionTypeDesc, bool isDisabled)
插入连接类型
public int InsertConnectionType(string connectionTypeDesc, string createdBy)
我当前的错误是:UpdateConnectionType 方法没有重载需要 6 个参数。我试图默认这些值只是为了收到这个错误。任何反馈将不胜感激,谢谢!
【问题讨论】:
-
InsertConnectionType的方法定义是什么? [方法签名右键->在Visual Studio中查看方法定义] -
除非您使用默认参数,否则无法使用 2 调用需要 4 个参数的方法。我不清楚你希望诚实
-
@now 他不能被命名我右键单击然后选择转到定义(我相信这是相同的),但它随后将我带到了持有我发布的第一个代码块的班级在我的问题中。
-
你想做什么?您尚未发布完整的方法调用,但根据您的异常,您只传递了 2 个参数,而函数需要 4 个参数。
-
@user4966755:如果是这样,那么您必须提供 4 个参数。