Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

c# - Method Overload and argument 6 error

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...