示例#1
0
        static public void loadDepto()
        {
            SAPbobsCOM.CompanyService          objCompanyService = null;
            SAPbobsCOM.GeneralService          UDOService        = null;
            SAPbobsCOM.GeneralData             headerInfo        = null;
            SAPbobsCOM.GeneralDataParams       addResult         = null;
            SAPbobsCOM.GeneralCollectionParams objList           = null;

            try
            {
                objCompanyService = MainObject.Instance.B1Company.GetCompanyService();
                UDOService        = objCompanyService.GetGeneralService(Settings._Main.loadDeptUDO);
                headerInfo        = UDOService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralData);
                try
                {
                    objList = UDOService.GetList();
                }
                catch (COMException comEx)
                {
                    if (comEx.ErrorCode == -2028)
                    {
                        objList = null;
                    }
                }
                catch (Exception er)
                {
                    _Logger.Error("", er);
                    objList = null;
                }
                if (objList == null || objList.Count == 0)
                {
                    using (StreamReader sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "LoadData\\" + Settings._Main.loadDeptUDO))
                    {
                        while (!sr.EndOfStream)
                        {
                            string   strLine   = sr.ReadLine();
                            string[] strResult = strLine.Split('|');
                            headerInfo.SetProperty("Code", strResult[0].Trim());
                            headerInfo.SetProperty("Name", strResult[1].Trim());
                            addResult = UDOService.Add(headerInfo);
                        }
                    }
                }
            }
            catch (Exception er)
            {
                _Logger.Error("", er);
            }
        }
示例#2
0
        static public void loadGenericUDO()
        {
            SAPbobsCOM.CompanyService objCompanyService = null;
            SAPbobsCOM.GeneralService UDOService        = null;
            SAPbobsCOM.GeneralData    headerInfo        = null;

            SAPbobsCOM.GeneralDataParams       oResult = null;
            SAPbobsCOM.GeneralCollectionParams objList = null;
            XmlDocument oXMLLod = new XmlDocument();

            try
            {
                if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "LoadData\\AutomaticLoad.xml"))
                {
                    oXMLLod.Load(AppDomain.CurrentDomain.BaseDirectory + "LoadData\\AutomaticLoad.xml");
                    XmlNodeList oList = oXMLLod.SelectNodes("/LoadFiles/File");
                    if (oList != null && oList.Count > 0)
                    {
                        foreach (XmlNode oFileNode in oList)
                        {
                            string strFilePath = oFileNode.SelectSingleNode("definition/location").InnerText;
                            string strUDOName  = oFileNode.SelectSingleNode("definition/UDO").InnerText;

                            objCompanyService = MainObject.Instance.B1Company.GetCompanyService();
                            UDOService        = objCompanyService.GetGeneralService(strUDOName);
                            headerInfo        = UDOService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralData);
                            try
                            {
                                objList = UDOService.GetList();
                            }

                            catch (COMException comEx)
                            {
                                if (comEx.ErrorCode == -2028)
                                {
                                    objList = null;
                                    _Logger.Error("The UDO with name " + strUDOName + " was not found");
                                }
                            }
                            catch (Exception er)
                            {
                                _Logger.Error("", er);
                                objList = null;
                            }

                            using (StreamReader sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + strFilePath))
                            {
                                while (!sr.EndOfStream)
                                {
                                    string   strLine   = sr.ReadLine();
                                    string[] strResult = strLine.Split('|');
                                    bool     runAdd    = false;

                                    string strCode = "";

                                    for (int i = 0; i < strResult.Length; i++)
                                    {
                                        string strPropertyName = oFileNode.SelectSingleNode("mapping/column[@index='" + i.ToString() + "']") != null?oFileNode.SelectSingleNode("mapping/column[@index='" + i.ToString() + "']/@property").InnerText : "";

                                        if (i == 0)
                                        {
                                            oResult = UDOService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams);
                                            strCode = strResult[i];
                                            oResult.SetProperty("Code", strResult[i]);
                                            try
                                            {
                                                headerInfo = UDOService.GetByParams(oResult);
                                            }
                                            catch (COMException comEx)
                                            {
                                                if (comEx.ErrorCode == -2028)
                                                {
                                                    runAdd     = true;
                                                    headerInfo = UDOService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralData);
                                                    headerInfo.SetProperty("Code", strResult[i].Trim());
                                                }
                                                else
                                                {
                                                    headerInfo = null;
                                                }
                                            }
                                            catch (Exception er)
                                            {
                                                _Logger.Error("", er);
                                                headerInfo = null;
                                            }
                                        }
                                        else
                                        {
                                            if (strPropertyName.Trim().Length > 0 && headerInfo != null)
                                            {
                                                headerInfo.SetProperty(strPropertyName, strResult[i].Trim());
                                            }
                                        }
                                    }
                                    if (runAdd)
                                    {
                                        oResult = UDOService.Add(headerInfo);
                                        _Logger.Info(strCode + " added OK");
                                    }
                                    else
                                    {
                                        try
                                        {
                                            UDOService.Update(headerInfo);
                                            _Logger.Info(strCode + " updated OK");
                                        }
                                        catch (COMException comEx)
                                        {
                                            _Logger.Error("Could not update value " + strCode + " of UDO " + strUDOName, comEx);
                                        }
                                        catch (Exception er)
                                        {
                                            _Logger.Error("Could not update value " + strCode + " of UDO " + strUDOName, er);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception er)
            {
                _Logger.Error("", er);
            }
        }