简体   繁体   English

带有 NAV Dynamics Web 服务的 C# 插入枚举类型对象

[英]C# with NAV Dynamics web services inserting enum type object

Let's say I've the web service for NAV dynamics假设我有 NAV 动态的网络服务

inside the web services there are some business objects which one of them is enum type在 Web 服务内部有一些业务对象,其中之一是枚举类型

public Type Type {
            get {
                return this.typeField;
            }
            set {
                this.typeField = value;
            }
        }

and has the value for the objects below, which contains in the web services too并具有以下对象的值,这些对象也包含在 Web 服务中

public enum Type{

        /// <remarks/>
        _blank_,

        /// <remarks/>
        G_L_Account,

        /// <remarks/>
        Item,

        /// <remarks/>
        Fixed_Asset,

        /// <remarks/>
        Charge_Item,
    }

the case is when doing this method below情况是在下面执行此方法时

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using NAVDomain;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using LocalDomain;
using NAVFacade.GoodReturnNAVService;

public bool SaveData(PurchCrdMemoNav objHd, List<Purch_Cr_Memo_Line> objDt)
            {
                PurchCrdMemoNav_Service service = new PurchCrdMemoNav_Service();
                NetworkCredential cred = new NetworkCredential();
                try
                {
                    cred.UserName = ConfigurationManager.AppSettings["NAVUser3"];
                    cred.Password = ConfigurationManager.AppSettings["NAVPassword3"];
                    cred.Domain = ConfigurationManager.AppSettings["NAVDataSource3"];

                    service.Credentials = cred;

                    PurchCrdMemoNav DataSave = new PurchCrdMemoNav();
                    DataSave.No = objHd.No;

                    service.Create(ref DataSave);

                    var purch = service.Read(objHd.No);

                    DataSave.Buy_from_Vendor_No = objHd.Buy_from_Vendor_No;
                    DataSave.Buy_from_Vendor_Name = objHd.Buy_from_Vendor_Name;
                    DataSave.Applies_to_Doc_Type = objHd.Applies_to_Doc_Type;
                    DataSave.Applies_to_Doc_No = objHd.Applies_to_Doc_No;
                    DataSave.Location_Code = objHd.Location_Code;
                    DataSave.Posting_Date = objHd.Posting_Date;

                    DataSave.Key = purch.Key;

                    service.Update(ref DataSave);

                    DataSave.PurchLines = new Purch_Cr_Memo_Line[objHd.PurchLines.Count()];



                    for (int i = 0; i < objHd.PurchLines.Count(); i++)
                    {
                        DataSave.PurchLines[i] = new Purch_Cr_Memo_Line();
                        DataSave.PurchLines[i].Document_Type = Document_Type.Credit_Memo;
                        DataSave.PurchLines[i].Document_No = objHd.No;
                        DataSave.PurchLines[i].Type = NAVFacade.GoodReturnNAVService.Type.Item;
                        DataSave.PurchLines[i].No = objHd.PurchLines[i].No;  
                        DataSave.PurchLines[i].Description = objHd.PurchLines[i].Description;
                        DataSave.PurchLines[i].Unit_of_Measure = objHd.PurchLines[i].Unit_of_Measure;
                        DataSave.PurchLines[i].Quantity = objHd.PurchLines[i].Quantity;
                    }

                    service.Update(ref DataSave);

                    return true;
                }
                catch (Exception err)
                {
                    MsgCode = 99;
                    MsgDesc = err.Message;
                    return false;
                }
            }

the problem is when executing the service.Update(ref DataSave) after the loop its catching an error which said问题是在循环之后执行service.Update(ref DataSave) ,它捕获了一个错误,它说

The field No. of table Purchase Line contains a value (C125) that cannot be found in the related table (Standard Text).表采购行的字段编号包含在相关表(标准文本)中找不到的值 (C125)。

because in NAV, when saving this one transaction, it needs to check it's item type each that recorded in this object below因为在 NAV 中,当保存这一笔交易时,它需要检查它在下面这个对象中记录的每个项目类型

DataSave.PurchLines[i].Type = NAVFacade.GoodReturnNAVService.Type.Item;

I've done the debugging and inside the DataSave.PurchLines[i].Type, there's the data that has the value as Item我已经完成了调试,在 DataSave.PurchLines[i].Type 中,有值为 Item 的数据

but when i check the database, the data aint saved但是当我检查数据库时,数据没有保存

in NAV the object read as option, in SQL the object read as integer在 NAV 中,对象读取为选项,在 SQL 中,对象读取为整数

please help,请帮忙,

I'm kind of stuck here since anything on my code is working except this method我有点卡在这里,因为除了这个方法之外,我的代码上的任何东西都在工作

sincerely,真挚地,

just another mediocore junior developer只是另一个中等初级开发人员

Maybe your value isn't sent correctly, check if there is attribute "YourField"_Specified and set it to true...也许您的值没有正确发送,请检查是否有属性“YourField”_Specified 并将其设置为 true...

EX: ...前任: ...

    currWorkOrder.Order_Type = Order_Type.AKC; //(Order_Type)2;
    currWorkOrder.Order_TypeSpecified = true;

... When i don't set ...当我没有设置

    Order_TypeSpecified = true; 

plugin sends default value, so 0...插件发送默认值,所以 0...

yes, the Type field in NAV is an Option field but it's stored as Integer therefore you need to give it a numeric value.是的,NAV 中的 Type 字段是一个 Option 字段,但它存储为整数,因此您需要为其指定一个数值。 Check with a NAV Developer of the actual database but the default values are: " ,G/L Account,Item,,Fixed Asset,Charge (Item)" - it starts from 0 so if you want Item you'll need 2与实际数据库的 NAV 开发人员核对,但默认值是:“,总账科目,项目,,固定资产,费用(项目)” - 它从 0 开始,所以如果你想要项目,你需要 2

I hope it helps!我希望它有帮助!

Cheers干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM