public string createItem(string code) { string rtn = ""; try { SAPbobsCOM.Items item = (SAPbobsCOM.Items)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems); item.ItemCode = code; item.ForeignName = code; item.ItemName = code; item.InventoryItem = SAPbobsCOM.BoYesNoEnum.tNO; int ret = item.Add(); if (ret != 0) { errorLog(oCompany.GetLastErrorDescription()); } else { rtn = code; } return(rtn); } catch (Exception ex) { errorLog(ex); } return(rtn); }
public Result CreateOrUpdateMaterial(Material material) { Result result = new Result(); SAPbobsCOM.Items myItem = SAP.SAPCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems); ///检查物料是否创建 bool IsExist = myItem.GetByKey(material.ItemCode); myItem.ItemCode = material.ItemCode; myItem.ItemName = material.ItemName; myItem.SalesVATGroup = material.VatGourpSa; myItem.PurchaseVATGroup = material.VatGourpPu; myItem.UserFields.Fields.Item("U_InitialCost").Value = Convert.ToDouble(material.InitialCost); myItem.UserFields.Fields.Item("U_RealCost").Value = Convert.ToDouble(material.InitialCost); myItem.UserFields.Fields.Item("U_SalesPrice").Value = Convert.ToDouble(material.SalesPrice); myItem.InventoryItem = DataConvertEx.GetSAPValue(material.InvntItem); myItem.UserFields.Fields.Item("U_Consignment").Value = material.Consignment; myItem.UserFields.Fields.Item("U_Vendor").Value = material.Vendor; //myItem.PrchseItem = 'Y'; //myItem.SellItem = 'Y'; myItem.ItemsGroupCode = BOneCommon.GetItemGroupCodeByOMSGroupNum(material.OMSGroupNum); int ResultCode = 0; if (IsExist) { ResultCode = myItem.Update(); } else { ResultCode = myItem.Add(); } if (ResultCode != 0) { result.ResultCode = -1; result.ObjCode = material.ItemCode; result.Message = SAP.SAPCompany.GetLastErrorDescription(); } else { result.ResultCode = 0; result.ObjCode = material.ItemCode; result.Message = "Saved or Updated successfully."; } return(result); }
public void import_Products() { try { System.Reflection.Assembly oItem_R = System.Reflection.Assembly.LoadFrom(Application.StartupPath + "\\Interop.SAPbobsCOM.dll"); string strMaiDB = strCompany_S.ToString();//System.Configuration.ConfigurationManager.AppSettings["MainDB"].ToString(); oCompany = (SAPbobsCOM.Company)TransLog.GetCompany(strMaiDB); SAPbobsCOM.Items oItem = (SAPbobsCOM.Items)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems); foreach (DictionaryEntry entry in oHT_S) { DataRow row = (DataRow)entry.Value; try { bool blnItemExist = false; string strItemCode = row["ItemCode"].ToString(); TransLog.traceService(" Product : " + strItemCode); //Thread.Sleep(100); //oForm_S.label1.Text = "Creation Item No : " + " - :" + strItemCode; //Application.DoEvents(); //oForm_S.Invoke((MethodInvoker)delegate //{ // oForm_S.label1.Text = strItemCode; // runs on UI thread //}); //oForm_S.label1.Invoke(new Action(() => Control.text = "")); if (oItem.GetByKey(row["ItemCode"].ToString())) { blnItemExist = true; } foreach (DataColumn column in oDS_S.Tables[0].Columns) { string DESTF = column.ColumnName; if (!DESTF.StartsWith("U_")) { try { if (DESTF != "ItemsGroupCode") { oItem_R.GetType("SAPbobsCOM.IItems").GetProperty(DESTF).SetValue(oItem, row[DESTF].ToString(), null); } else { oItem_R.GetType("SAPbobsCOM.IItems").GetProperty(DESTF).SetValue(oItem, Convert.ToInt32(row[DESTF].ToString()), null); } } catch (Exception ex) { TransLog.traceService(" Error : " + ex.Message + "--> Field : " + DESTF); } } else { oItem.UserFields.Fields.Item(DESTF).Value = row[column.ColumnName.ToString()].ToString(); } } int intStatus = 0; if (!blnItemExist) { intStatus = oItem.Add(); if (intStatus != 0) { TransLog.traceService(" Error : " + oCompany.GetLastErrorDescription()); } else { TransLog.traceService(" Success "); } } else { intStatus = oItem.Update(); if (intStatus != 0) { TransLog.traceService(" Error : " + oCompany.GetLastErrorDescription()); } else { TransLog.traceService(" Success "); } } } catch (Exception ex) { TransLog.traceService(" Error : " + ex.Message); } } } catch (Exception ex) { TransLog.traceService(" Error : " + ex.Message); } }