方法重载和参数6错误 [英] Method Overload and argument 6 error

查看:658
本文介绍了方法重载和参数6错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我修改了我的代码和问题,以更好地反映我要完成的工作。



背景:我的项目中有不同的图层界面。





  • 数据访问层 - 只是执行传递的方法或函数

  • Aspx& aspx.cs文件所在的方法需要发生(例如用户界面)



这里是我的代码为ConnectionTypeSetup.aspx。 cs文件,我也标记的行有一个错误:

  protected void uxSaveBtn_Click(object sender,EventArgs e) 
{
var accountTrackersvc = new AccountTrackerSvc();

//插入或更新记录
var result = ViewState [ConnectionTypeID] == null?
accountTrackersvc.InsertConnectionType(uxConnectionTypeDescTxt.Text.Trim(),
CommonSVC.GetUserInfoFormattedFromSession())

/ *此行上的错误* /:accountTrackersvc.UpdateConnectionType(DataConverter.StringToInteger (ViewState [ConnectionTypeID]。ToString()),
uxConnectionTypeDescTxt.Text.Trim(),
Enums.GetIsDisabledByItemStatusValue(SafeValueAccessor.GetControlValue(uxStatusDdl)),
CommonSVC.GetUserInfoFormattedFromSession ,Default,false);


//检查结果
if(result.Successful)
{
uxInfoMsg.DisplayMessage(result.Message,InfoMessage.InfoMessageType.Success);
BindGridContent();
uxPopupMdl.Hide();
}
else
{
uxModalInfoMsg.DisplayMessage(result.Message,InfoMessage.InfoMessageType.Failure);
uxPopupMdl.Show();
}
//隐藏进度指示器
Master.HideProgressIndicator();

再次处理我的业务逻辑的服务层的格式如下。请注意,使用了两种不同的方法,插入更新

  public BO.OperationResult InsertConnectionType(string connectionTypeDesc,string createdBy)
{
var operationResult = new BO.OperationResult

//需要连接类型描述
if(connectionTypeDesc.Trim()。Length< = 0)
{
operationResult.Successful = false;
operationResult.Message + =需要连接类型描述;
}
// Createdby required
if(createdBy.Trim()。Length< = 0)
{
operationResult.Successful = false;
operationResult.Message + =记录未以此条目创建的形式保存;
}
if(operationResult.Successful)
{
operationResult.DBPrimaryKey = new DAL.AccountTrackerDAL()。InsertConnectionType(connectionTypeDesc.Trim(),createdBy);
operationResult.Message =帐户访问级别已成功保存;
}
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 + =连接类型说明尚未成功更新。
}
if(lastUpdatedBy.Trim()。Length< = 0)
{
operationResult.Successful = false;
operationResult.Message + =最后更新者必须输入。
}
if(operationResult.Successful)
{
operationResult.DBPrimaryKey = new DAL.AccountTrackerDAL()。UpdateConnectionType(connectionTypeID,lastUpdatedBy,connectionTypeDesc,isDisabled);
operationResult.Message =帐户访问级别已成功保存;
}
return operationResult;
}



最后,我将只包括DAL层的方法认为应该足够和不饱和这个问题与代码。



更新ConnectionType

  public int UpdateConnectionType(int connectionTypeID,string lastUpdatedBy ,string connectionTypeDesc,bool isDisabled)

插入ConnectionType

  public int InsertConnectionType(string connectionTypeDesc,string createdBy)

我当前的错误读取:没有重载方法UpdateConnectionType需要6个参数。我试图默认值只接收这个错误。 c $ c> InsertConnectionType

当你调用 ,您可以必须提供四(4)个参数。这是方法的写法,所以这是你必须做的:

  accountTrackersvc.InsertConnectionType(
uxConnectionTypeDescTxt。 Text.Trim(),
CommonSVC.GetUserInfoFormattedFromSession(),
Default,false)

上面的参数会传递编译器。



如果你绝对坚持只使用两个参数,你可以创建一个重载方法: p>

  public BO.OperationResult InsertConnectionType(string connectionTypeDesc,int connectionTypeID)
{
return InsertConnectionType(connectionTypeDesc,connectionTypeID, Default,false);
}



UPDATE



要为 UpdateConnectionType 方法添加重载,请尝试这样:

  public BO.OperationResult UpdateConnectionType (int connectionTypeID,string connectionTypeDesc)
{
var operationResult = new BO.OperationResult();

if(connectionTypeDesc.Trim()。Length< = 0)
{
operationResult.Successful = false;
operationResult.Message + =连接类型说明尚未成功更新。
}
if(operationResult.Successful)
{
operationResult.DBPrimaryKey = new DAL.AccountTrackerDAL()。UpdateConnectionType(connectionTypeID,Default,connectionTypeDesc,false)
operationResult.Message =帐户访问级别已成功保存;
}
return operationResult;
}

当然,请确保替换文本默认和布尔值 false


I've revised my code and question to better reflect what I'm trying to accomplish.

Background: I have different layer interfaces as part of my project.

  • Service Layer - handles my business logic, validates entries, (the brains)
  • Data Access Layer - simply executes the methods or functions it is passed
  • Aspx & aspx.cs files where the methods need to take place (i.e the user interface)

Here is my code for the ConnectionTypeSetup.aspx.cs file, I've also marked the line where there is an error:

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

The service layer which again handles my business logic is formatted as follows. Please note there are 2 separate methods being used and Insert and 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;
    }

2nd Business logic Method and code for update:

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

Lastly, I'll only include the method signitures for the DAL layer as I think that should be enough and not saturate this question with code.

Update ConnectionType

public int UpdateConnectionType(int connectionTypeID, string lastUpdatedBy, string connectionTypeDesc, bool isDisabled)

Insert ConnectionType

 public int InsertConnectionType(string connectionTypeDesc, string createdBy)

My current error reads: No overload for method UpdateConnectionType takes 6 arguments. I've tried to default the values only to receive this error. Any feedback would be appreciated, thanks!

解决方案

When you call InsertConnectionType, you MUST provide four (4) parameters. That is how the method is written, so that is what you must do:

accountTrackersvc.InsertConnectionType(
  uxConnectionTypeDescTxt.Text.Trim(), 
  CommonSVC.GetUserInfoFormattedFromSession(),
  "Default", false)

The parameters above would pass the compiler.

If you absolutely insist on using only two (2) parameters, you could create an overload method:

public BO.OperationResult InsertConnectionType(string connectionTypeDesc, int connectionTypeID)
{
  return InsertConnectionType(connectionTypeDesc, connectionTypeID, "Default", false);
}

UPDATE

To add an overload for your UpdateConnectionType method, try something like this:

    public BO.OperationResult UpdateConnectionType(int connectionTypeID, string connectionTypeDesc)
    {
        var operationResult = new BO.OperationResult();

        if (connectionTypeDesc.Trim().Length <= 0)
        {
            operationResult.Successful = false;
            operationResult.Message += "Connection Type Description has not successfully updated.";
        }
        if (operationResult.Successful)
        {
            operationResult.DBPrimaryKey = new DAL.AccountTrackerDAL().UpdateConnectionType(connectionTypeID, "Default", connectionTypeDesc, false);
            operationResult.Message = "Account Access Level Saved Successfully";
        }
        return operationResult;
    }

Of course, make sure you replace the text "Default" and the Boolean value false with whatever is appropriate for your class.

这篇关于方法重载和参数6错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆