C# 遇到奇怪难解的问题 程式执行一半自己跳出

 这个程式会叫用ABC(),ABC会用到DocNum所以在它之后才进行叫用

 public partial class inventory : ContentPage
    {
        ABC evm;
        public inventory()
        {
            InitializeComponent();
        }
        private async void gotoinventory2(Object sender, EventArgs e)
        {
            string x = DocNum.Text;
            Num.DocNum = x;
            evm = new ABC();
            foreach (var i in evm.Data)
            {
                test.Text = Convert.ToString(i.ABCNumber);
            }
        }

而这是ABC()的程式

class ABC : INotifyPropertyChanged
    {

        public ABC()
        {
            GetData();
        }
        public async void GetData()
        {
            using (var client = new HttpClient())

            {
                var x = Num.DocNum;
                var uri = "http://XXX.XXX.X.XXX:8056/API/api/TEST/GetInventory?x=" + x;
                var result = await client.GetStringAsync(uri);
                ////////////////////////////////////////////////
                uri = "http://XXX.XXX.X.XXX:8056/API/api/TEST/GetABC";
                result = await client.GetStringAsync(uri);
                //handling the answer  
                var DataList = JsonConvert.DeserializeObject<List<DataABC>>(result);
                Data = new ObservableCollection<DataABC>(DataList);
            }

        }

        ObservableCollection<DataABC> _Data;
        public ObservableCollection<DataABC> Data
        {
            get
            {
                return _Data;
            }
            set
            {
                _Data = value;
                OnPropertyChanged();
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }


    }

奇怪的地方来了,当我第一张的那个回圈存在时,第二张的程式只执行//////以上,就跳出执行迴圈,导致DATA没有抓到资料,所以迴圈没办法in Data,所以回传错误。 而当我把回圈删除时,ABC()的程式便能跑完全部且抓资料进到Data。

不过我的程式一定要跑那个回圈,小的百思不得其解 请求各位老铁们助我一臂之力。

 

以下是我的API,GetABC可以顺利抓到我要的资料
public IEnumerable<Inventory> GetInventory(int x)
        {

            int errorCode = 0;
            string errorMessage = "";
            SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
            try
            {
                oCompany.CompanyDB = "XXXX";
                oCompany.Server = "XXXX";
                oCompany.LicenseServer = "XXXX";
                oCompany.DbUserName = "sa";
                oCompany.DbPassword = "XXX";
                oCompany.UserName = "manager";
                oCompany.Password = "XXX";
                oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014;
                oCompany.UseTrusted = false;
                int connectionResult = oCompany.Connect();

                if (connectionResult != 0)
                {
                    oCompany.GetLastError(out errorCode, out errorMessage);
                    List<Inventory> Inventory = new List<Inventory>();
                    Inventory Getdata = new Inventory();
                    Getdata.ItemCode = "連接失敗";
                    Inventory.Add(Getdata);
                    return Inventory;
                }
                else
                {
                    Parameter.DocNum = x;
                    List<Inventory> Inventory = new List<Inventory>();
                    Inventory Getdata = new Inventory();
                    SAPbobsCOM.Recordset oRecordSet = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                    oRecordSet.DoQuery("SELECT T0.[DocNum], T1.[ItemCode], T1.[ItemDesc], T1.[WhsCode] FROM OINC T0  INNER JOIN INC1 T1 ON T0.[DocEntry] = T1.[DocEntry] WHERE T0.[DocNum] =" + x);
                    while (oRecordSet.EoF == false)
                    {
                        Getdata.ItemCode = oRecordSet.Fields.Item("ItemCode").Value.ToString();
                        Getdata.ItemDesc = oRecordSet.Fields.Item("ItemDesc").Value.ToString();
                        Getdata.WhsCode = oRecordSet.Fields.Item("WhsCode").Value.ToString();
                        Parameter.ItemCode = Getdata.ItemCode;
                        Parameter.WhsCode = Getdata.WhsCode;
                        oRecordSet.MoveNext();
                        Inventory.Add(Getdata);
                    }
                    return Inventory;
                }
            }
            catch (Exception errMsg)
            {
                throw errMsg;
            }
        }
        //GetInventory


        //GetABC 
        public IEnumerable<ABC> GetABC()
        {

            int errorCode = 0;
            string errorMessage = "";
            SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
            try
            {
                oCompany.CompanyDB = "XXX";
                oCompany.Server = "XXXX";
                oCompany.LicenseServer = "XXXX";
                oCompany.DbUserName = "sa";
                oCompany.DbPassword = "XXX";
                oCompany.UserName = "manager";
                oCompany.Password = "XXXX";
                oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014;
                oCompany.UseTrusted = false;
                int connectionResult = oCompany.Connect();

                if (connectionResult != 0)
                {
                    oCompany.GetLastError(out errorCode, out errorMessage);
                    List<ABC> ABC = new List<ABC>();
                    ABC Getdata = new ABC();
                    Getdata.ABCNumber = "連接失敗";
                    ABC.Add(Getdata);
                    
                    return ABC;
                }
                else
                {
                    var ItemCode = Parameter.ItemCode;
                    List<ABC> ABC = new List<ABC>();
                    ABC Getdata = new ABC();
                    SAPbobsCOM.Recordset oRecordSet = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                    oRecordSet.DoQuery("SELECT T0.[ManbtchNum], T0.[ManSerNum] FROM OITM T0 WHERE T0.[ItemCode] =" + "'" + ItemCode + "'");
                    while (oRecordSet.EoF == false)
                    {
                        string Ser = oRecordSet.Fields.Item("ManSerNum").Value.ToString();
                        string Btch = oRecordSet.Fields.Item("ManbtchNum").Value.ToString();
                        if (Ser == "Y" && Btch == "N")
                        {
                            Getdata.ABCNumber = "A";
                        }
                        else if (Ser == "N" && Btch == "Y")
                        {
                            Getdata.ABCNumber = "B";
                        }
                        else
                        {
                            Getdata.ABCNumber = "C";
                        }
                        oRecordSet.MoveNext();
                        ABC.Add(Getdata);
                    }
                    return ABC;
                }
            }
            catch (Exception errMsg)
            {
                throw errMsg;
            }
        }

 

api是自己写的,还是第三方的呢?能不能调试一下API

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632