Acumatica - 无法将参数值从PXResultset`1转换为String

时间:2018-01-09 19:05:30

标签: acumatica

我们必须在ARTran记录的foreach循环中调用存储过程,以根据ARTran记录的原始记录集中的2个值更新一组不同的ARTran记录。我们的代码经过验证和发布,但是当我们点击Process时,我们收到以下错误。

1/9/2018 10:52:52 AM Error: 
Failed to convert parameter value from a PXResultset`1 to a String. 

System.InvalidCastException: Object must implement IConvertible. 
at System.Convert.ChangeType(Object value, Type conversionType, 
IFormatProvider provider) 
at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, 
MetaType destinationType, Boolean& coercedToDataFeed, Boolean& 
typeChanged, Boolean allowStreaming) 
at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, 
MetaType destinationType, Boolean& coercedToDataFeed, Boolean& 
typeChanged, Boolean allowStreaming) 
at System.Data.SqlClient.SqlParameter.GetCoercedValue() 
at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean 
isCommandProc) 
at System.Data.SqlClient.SqlCommand.SetUpRPCParameters(_SqlRPC rpc, 
Int32 startCount, Boolean inSchema, SqlParameterCollection parameters) 
at System.Data.SqlClient.SqlCommand.BuildRPC(Boolean inSchema, 
SqlParameterCollection parameters, _SqlRPC& rpc) 
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior 
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean 
async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, 
SqlDataReader ds, Boolean describeParameterEncryptionRequest) 
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior 
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String 
method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, 
Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) 
at 

System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSou     rce`1 completion,String methodName,Boolean sendToPipe,Int32 timeout,     布尔和放大器; usedCache,Boolean asyncWrite,Boolean inRetry)     在System.Data.SqlClient.SqlCommand.ExecuteNonQuery()     在PX.Data.PXSqlDatabaseProvider.Execute(String procedureName,     PXSPParameter [] pars)     在PX.Data.PXDatabase.Execute(String procedureName,PXSPParameter []     标准杆)     在DocCenter.UpdateLastNotified.b__0()    在PX.Data.PXLongOperation。<> c__DisplayClass17_0.b__0()

以下是我们处理的代码。任何人都可以告诉我这里的问题是什么?

using System;
using System.Collections;
using System.Linq;
using PX.Data;
using PX.SM;
using PX.Objects.AR;
using PX.Objects.CR;
using PX.Objects.IN;


namespace DocCenter
{
  public class UpdateLastNotified : PXGraph<UpdateLastNotified>
  {
    public PXFilter<UpdateLastNotifiedFilter> MasterView;
    public PXCancel<UpdateLastNotifiedFilter> Cancel;

[PXFilterable]




    public PXSelectJoin<ARTran, 
  InnerJoin<InventoryItem, On<ARTran.inventoryID, Equal <InventoryItem.inventoryID>>,
  InnerJoin<ARInvoice, On<ARTran.refNbr, Equal <ARInvoice.refNbr>>,  
  InnerJoin<ItemBaseDocument, On<InventoryItemExt.usrDocumentNumber, Equal<ItemBaseDocument.baseDocumentCode>>,
  InnerJoin<Contact, On<ARTranExt.usrContactID, Equal<Contact.contactID>>>>>>,  
  Where<ARTranExt.usrDateNotified, Less<ItemBaseDocument.revisionDateReceived>>> DetailsView;

 public UpdateLastNotified() 
    {
   Cancel.SetCaption("Clear Filter");
   this.DetailsView.Cache.AllowInsert = false;
   this.DetailsView.Cache.AllowDelete = false;
   this.DetailsView.Cache.AllowUpdate = true; 
    }


protected virtual IEnumerable detailsView()
{
UpdateLastNotifiedFilter filter = MasterView.Current as UpdateLastNotifiedFilter;
PXSelectBase<ARTran> cmd = new PXSelectJoin<ARTran, 
  InnerJoin<InventoryItem, On<ARTran.inventoryID, Equal <InventoryItem.inventoryID>>,
  InnerJoin<ARInvoice, On<ARTran.refNbr, Equal <ARInvoice.refNbr>>,  
  InnerJoin<ItemBaseDocument, On<InventoryItemExt.usrDocumentNumber, Equal<ItemBaseDocument.baseDocumentCode>>,
  InnerJoin<Contact, On<ARTranExt.usrContactID, Equal<Contact.contactID>>>>>>,  
  Where<ARTranExt.usrDateNotified, Less<ItemBaseDocument.revisionDateReceived>>>(this);    

   return cmd.Select();
}



public PXAction<UpdateLastNotifiedFilter> Process;
[PXProcessButton]
[PXButton(CommitChanges=true)]
[PXUIField(DisplayName = "Process")]
protected virtual IEnumerable process(PXAdapter adapter)
{

  PXLongOperation.StartOperation(this, delegate() 
  {
  foreach(ARTran tran in DetailsView.Select())
    {
    if (tran.Selected==true)
      {

      ARTranExt tranExt = tran.GetExtension<ARTranExt>();
      ARInvoiceEntry tranEntry = new ARInvoiceEntry();
      tranExt.UsrDateNotified = MasterView.Current.DateNotified;
      tranEntry.Transactions.Update(tran);
      tranEntry.Save.PressButton();

      int? companyid = PX.Common.PXContext.GetSlot<Int32?>("singleCompanyID");


      var sp_MySP_Parms = new PXSPParameter[4];

      PXSPParameter p1 = new PXSPInParameter("@I_vBaseDocumentCode", PXDbType.NChar, DetailsView.Select("BaseDocumentCode"));
      PXSPParameter p2 = new PXSPInParameter("@I_vEmail", PXDbType.NChar, DetailsView.Select("EMail"));
      PXSPParameter p3 = new PXSPInParameter("@I_vCompanyID", PXDbType.Int, companyid);
      PXSPParameter p4 = new PXSPInParameter("@I_vDateNotified", PXDbType.DateTime, MasterView.Current.DateNotified);

      sp_MySP_Parms[0] = p1;
      sp_MySP_Parms[1] = p2;
      sp_MySP_Parms[2] = p3;
      sp_MySP_Parms[3] = p4;

      object[] ret = PXDatabase.Execute("icanUpdateDateLastNotifiedForBaseDocumentAndEmail", sp_MySP_Parms);

      }

    }


  }

        );
 return adapter.Get();
}

    [Serializable]
    public class UpdateLastNotifiedFilter : IBqlTable
    {

      #region DateNotified
      public abstract class dateNotified : PX.Data.IBqlField
      {
      } 
      [PXDBDate()]
      [PXDefault(typeof(AccessInfo.businessDate))]
      [PXUIField(DisplayName = "Date Notified")]
      public DateTime? DateNotified { get; set; }
      #endregion 

    }
  }
}

0 个答案:

没有答案