Пример #1
0
 public void editPrice(string sItemCode, string sPriceListName, int iPrice)
 {
     try
     {
         SAPbobsCOM.Items oItm = (SAPbobsCOM.Items)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);
         if (oItm.GetByKey(sItemCode))
         {
             for (int i = 0; i < oItm.PriceList.Count - 1; i++)
             {
                 oItm.PriceList.SetCurrentLine(i);
                 if (oItm.PriceList.PriceListName == sPriceListName)  //"基础价格"
                 {
                     oItm.PriceList.Price = iPrice;
                     if (oItm.Update() != 0)
                     {
                         oCompany.GetLastError(out this.iRetCode, out sErrMsg);
                         throw new Exception(iRetCode.ToString() + sErrMsg);
                     }
                     else
                     {
                         MessageBox("OK");
                     }
                     return;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox(ex.ToString());
         DealError(ex.ToString());
     }
 }
Пример #2
0
        public string funEnviarCostosSAP(DataTable dtPrecios)
        {
            try
            {
                string mError = "";
                int    iError = 0;

                csAccesoDatos.proIniciarSesionSAP();
                SAPbobsCOM.Items varOITM = csConexionSap.objConexionSap.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);

                foreach (DataRow drPrecios in dtPrecios.Rows)
                {
                    if (varOITM.GetByKey(drPrecios["IteCodigo"].ToString()))
                    {
                        varOITM.UserFields.Fields.Item("U_Ita_cstReferencial").Value = double.Parse(drPrecios["ItePrecio"].ToString());
                        iError = varOITM.Update();
                        if (!iError.Equals(0))
                        {
                            csConexionSap.objConexionSap.GetLastError(out iError, out mError);
                            return(mError);
                        }
                    }
                }
                return(mError);
            }
            catch (Exception) { throw; }
            finally { csAccesoDatos.proFinalizarSesionSAP(); }
        }
Пример #3
0
        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);
        }
Пример #4
0
        public string funEnviarPreciosSAP(DataTable dtPrecios)
        {
            try
            {
                string mError = "";
                int    iError = 0;

                csAccesoDatos.proIniciarSesionSAP();
                SAPbobsCOM.Items varOITM = csConexionSap.objConexionSap.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);

                foreach (DataRow drPrecios in dtPrecios.Rows)
                {
                    if (varOITM.GetByKey(drPrecios["IteCodigo"].ToString()))
                    {
                        for (int p = 0; p < varOITM.PriceList.Count; p++)
                        {
                            varOITM.PriceList.SetCurrentLine(p);
                            if (varOITM.PriceList.PriceList == int.Parse(drPrecios["LisPrecio"].ToString()))
                            {
                                varOITM.PriceList.Price = double.Parse(drPrecios["ItePrecio"].ToString());
                                break;
                            }
                        }
                        iError = varOITM.Update();
                        if (!iError.Equals(0))
                        {
                            csConexionSap.objConexionSap.GetLastError(out iError, out mError);
                            return(mError);
                        }
                    }
                }
                return(mError);
            }
            catch (Exception) { throw; }
            finally { csAccesoDatos.proFinalizarSesionSAP(); }
        }
Пример #5
0
        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);
            }
        }