Пример #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
        //private async void CalculateCostPercentage()
        //{
        //    try
        //    {
        //        //Action action = new Action(delegate()
        //        //{
        //            double totalWeight = 0;
        //            double totalAmount = 0;
        //            double totalQuantity = 0;

        //            for (int i = 0; i < mtxCost.RowCount; i++)
        //            {
        //                var itmType = ((dynamic)mtxCost.GetCellSpecific("Type", i + 1)).Value;
        //                var itmCost = ((dynamic)mtxCost.GetCellSpecific("Cost", i + 1)).Value;

        //                var itmDoubleCost = itmCost == string.Empty ? 0 : Convert.ToDouble(itmCost);
        //                if (itmType.Equals("Weight"))
        //                    totalWeight += itmDoubleCost;
        //                else if (itmType.Equals("Amount"))
        //                    totalAmount += itmDoubleCost;
        //                else
        //                    totalQuantity += itmDoubleCost;
        //            }

        //            SAPbobsCOM.Items oItem = AddonInfoInfo.GetNewBOneItem();
        //            List<AddonInfoInfo> itemsList = new List<AddonInfoInfo>();

        //            double totalItemsAmount = 0;
        //            double totalItemsAvgPrice = 0;
        //            double totalItemsWeightPrice = 0;
        //            double totalItemQuantity = 0;

        //            for (int i = 0; i < mtxItems.RowCount; i++)
        //            {
        //                var itmCode = ((dynamic)mtxItems.GetCellSpecific("to_Item", i + 1)).Value;
        //                oItem.GetByKey(itmCode);
        //                var oPriceList = oItem.PriceList;
        //                var quantity = ((dynamic)mtxItems.GetCellSpecific("Quantity", i + 1)).Value;
        //                var itmQuantity = Convert.ToDouble(quantity == string.Empty ? 0 : quantity);
        //                var amount = oItem.MovingAveragePrice * Convert.ToDouble(itmQuantity);
        //                var avgPrice = oItem.MovingAveragePrice;
        //                var itemWeight = oItem.PurchaseUnitWeight;

        //                totalItemsAmount += amount;
        //                totalItemsAvgPrice += avgPrice;
        //                totalItemsWeightPrice += itemWeight;
        //                totalItemQuantity += itmQuantity;

        //                var itemInfo = new AddonInfoInfo() { Index = i + 1, ItemWeight = itemWeight, AveragePrice = avgPrice, Amount = amount, Quantity = itmQuantity };
        //                itemsList.Add(itemInfo);
        //            }
        //            var ds = this.UIAPIRawForm.DataSources.DBDataSources.Item(string.Format("@{0}", TableNames.TransferItemsLines));

        //            foreach (var v in itemsList)
        //            {
        //                var itemWeightPercentage = totalItemsWeightPrice == 0 ? 0 : v.ItemWeight * totalWeight / totalItemsWeightPrice;
        //                var itemAmountPercentage = totalItemsAmount == 0 ? 0 : v.Amount * totalAmount / totalItemsAmount;
        //                var itemQuantityPercentage = v.Quantity * totalQuantity / totalItemQuantity;
        //                ds.SetValue("U_AddCost", v.Index - 1, (itemWeightPercentage + itemAmountPercentage + itemQuantityPercentage).ToString());
        //            }
        //            mtxItems.LoadFromDataSource();
        //        //});

        //        //await Task.Run(action);
        //    }
        //    catch (Exception ex)
        //    {
        //        Utilities.LogException(ex);
        //    }
        //}

        private void CalculateCostPercentage()
        {
            try
            {
                //Action action = new Action(delegate()
                //{
                double totalWeight   = 0;
                double totalAmount   = 0;
                double totalQuantity = 0;

                for (int i = 0; i < mtxCost.RowCount; i++)
                {
                    var itmType = ((dynamic)mtxCost.GetCellSpecific("Type", i + 1)).Value;
                    var itmCost = ((dynamic)mtxCost.GetCellSpecific("Cost", i + 1)).Value;

                    var itmDoubleCost = itmCost == string.Empty ? 0 : Convert.ToDouble(itmCost);
                    if (itmType.Equals("Weight"))
                    {
                        totalWeight += itmDoubleCost;
                    }
                    else if (itmType.Equals("Amount"))
                    {
                        totalAmount += itmDoubleCost;
                    }
                    else
                    {
                        totalQuantity += itmDoubleCost;
                    }
                }

                SAPbobsCOM.Items     oItem     = AddonInfoInfo.GetNewBOneItem();
                List <AddonInfoInfo> itemsList = new List <AddonInfoInfo>();

                double totalItemsAmount      = 0;
                double totalItemsAvgPrice    = 0;
                double totalItemsWeightPrice = 0;
                double totalItemQuantity     = 0;

                for (int i = 0; i < mtxItems.RowCount; i++)
                {
                    var itmCode = ((dynamic)mtxItems.GetCellSpecific("to_Item", i + 1)).Value;
                    oItem.GetByKey(itmCode);
                    var oPriceList  = oItem.PriceList;
                    var quantity    = ((dynamic)mtxItems.GetCellSpecific("Quantity", i + 1)).Value;
                    var itmQuantity = Convert.ToDouble(quantity == string.Empty ? 0 : quantity);
                    var amount      = oItem.MovingAveragePrice * Convert.ToDouble(itmQuantity);
                    var avgPrice    = oItem.MovingAveragePrice;
                    var itemWeight  = oItem.PurchaseUnitWeight;

                    totalItemsAmount      += amount;
                    totalItemsAvgPrice    += avgPrice;
                    totalItemsWeightPrice += itemWeight;
                    totalItemQuantity     += itmQuantity;

                    var itemInfo = new AddonInfoInfo()
                    {
                        Index = i + 1, ItemWeight = itemWeight, AveragePrice = avgPrice, Amount = amount, Quantity = itmQuantity
                    };
                    itemsList.Add(itemInfo);
                }
                var ds = this.UIAPIRawForm.DataSources.DBDataSources.Item(string.Format("@{0}", TableNames.TransferItemsLines));

                foreach (var v in itemsList)
                {
                    var itemWeightPercentage   = totalItemsWeightPrice == 0 ? 0 : v.ItemWeight * totalWeight / totalItemsWeightPrice;
                    var itemAmountPercentage   = totalItemsAmount == 0 ? 0 : v.Amount * totalAmount / totalItemsAmount;
                    var itemQuantityPercentage = v.Quantity * totalQuantity / totalItemQuantity;
                    ds.SetValue("U_AddCost", v.Index - 1, (itemWeightPercentage + itemAmountPercentage + itemQuantityPercentage).ToString());
                }
                mtxItems.LoadFromDataSource();
                //});

                //await Task.Run(action);
            }
            catch (Exception ex)
            {
                Utilities.LogException(ex);
            }
        }
Пример #6
0
        public Backup()
        {
            logs.Clear();
            WriteLog("[Log]", "--------------------------------------------------------------------------------");
            WriteLog("[Log]", "Integration Begin:[" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "]");


            #region Connect to SAP
            SAPbobsCOM.Company oCom         = new SAPbobsCOM.Company();
            string             dbServerType = ConfigurationManager.AppSettings.Get("dbServerType");
            if (dbServerType == "MSSQL2005")
            {
                oCom.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005;
            }
            else if (dbServerType == "MSSQL2008")
            {
                oCom.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008;
            }
            else if (dbServerType == "MSSQL2012")
            {
                oCom.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
            }
            else if (dbServerType == "MSSQL2014")
            {
                oCom.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2014;
            }
            else if (dbServerType == "HANADB")
            {
                oCom.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
            }
            else if (dbServerType == "DB_2")
            {
                oCom.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_DB_2;
            }
            oCom.Server        = ConfigurationManager.AppSettings.Get("Server");
            oCom.DbUserName    = ConfigurationManager.AppSettings.Get("dbuser");
            oCom.DbPassword    = ConfigurationManager.AppSettings.Get("dbpass");
            oCom.LicenseServer = ConfigurationManager.AppSettings.Get("LicenseServer");
            oCom.CompanyDB     = ConfigurationManager.AppSettings.Get("CompanyDB");
            oCom.UserName      = ConfigurationManager.AppSettings.Get("UserName");
            oCom.Password      = ConfigurationManager.AppSettings.Get("Password");
            oCom.language      = SAPbobsCOM.BoSuppLangs.ln_English;
            if (oCom.Connect() != 0)
            {
                WriteLog("[Error]", "Connection:[" + oCom.CompanyDB + "] Message:[" + oCom.GetLastErrorDescription() + "] Time:[" + DateTime.Now.ToString("hh: mm:ss tt") + "]");
                goto EndApplication;
            }

            WriteLog("[Log]", "Connected to:[" + oCom.CompanyName + "] Time:[" + DateTime.Now.ToString("hh:mm:ss tt") + "]");
            #endregion


            #region Connect to Data Source
            SqlConnection conn = new SqlConnection(conString);
            SqlCommand    cmd  = new SqlCommand("", conn);
            conn.Close();
            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                WriteLog("[Error]", "Data Source Connection : " + DateTime.Now.ToString() + " : " + ex.Message);
                goto EndApplication;
            }

            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(conString);
            string server   = builder.DataSource;
            string database = builder.InitialCatalog;
            WriteLog("[Log]", "Connected to Data Source:[" + database + "] Time:[" + DateTime.Now.ToString("hh:mm:ss tt") + "]");


            cmd.CommandText = "SELECT ROW_NUMBER() over (Partition by BaseEntry Order by BaseEntry )-1 as [Line], * " +
                              "FROM [dbo].[ProductionReceipt] T0 Where IsNull(T0.Posted,'N') <> 'Y'";
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable      dt = new DataTable();
            da.Fill(dt);

            int nGR = dt.Rows.Count;
            if (nGR == 0)
            {
                WriteLog("[Log]", "No production receipt to import!");
                conn.Close();
                da.Dispose();
                goto EndApplication;
            }

            List <int> idList = new List <int>();
            Dictionary <int, DataTable> doc = new Dictionary <int, DataTable>();

            //Parsing data into header and details
            foreach (DataRow row in dt.Rows)
            {
                int baseEntry = int.Parse(row["BaseEntry"].ToString());
                if (doc.ContainsKey(baseEntry))
                {
                    DataTable dtDoc = doc[baseEntry];
                    dtDoc.ImportRow(row);
                    doc[baseEntry] = dtDoc;
                }
                else
                {
                    DataTable dtDoc = dt.Clone();
                    dtDoc.ImportRow(row);
                    doc.Add(baseEntry, dtDoc);
                }
            }

            WriteLog("[Log]", "Record found:[" + doc.Keys.Count + "] Total Rows:[" + dt.Rows.Count + "]");


            oCom.StartTransaction();

            int n = 0;
            foreach (var item in doc)
            {
                try
                {
                    SAPbobsCOM.Documents        oDocReceipt          = (SAPbobsCOM.Documents)oCom.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry);
                    SAPbobsCOM.ProductionOrders oDocProductionOrders = (SAPbobsCOM.ProductionOrders)oCom.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductionOrders);
                    SAPbobsCOM.Items            oItem = oCom.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);

                    DataTable dtDoc = doc[item.Key];
                    DataRow   hRow  = dtDoc.Rows[0];

                    int retcode = 0;
                    idList = new List <int>();

                    string itemCode = hRow["ItemCode"].ToString();
                    oItem.GetByKey(itemCode);
                    SAPbobsCOM.BoYesNoEnum isManageBatchNumbers = oItem.ManageBatchNumbers;


                    WriteLog("[Log]", "No:[" + (++n) + "] H:Production Order[" + hRow["DocNum"].ToString() + "] Base:[" + item.Key + "] TotalRows:[" + dtDoc.Rows.Count + "]" + " PlannedQty:" + hRow["Quantity"].ToString());
                    // Add Header -----------------------------------
                    string proNo     = hRow["DocNum"].ToString();
                    int    baseEntry = int.Parse(hRow["BaseEntry"].ToString());
                    oDocReceipt.Series      = 53;
                    oDocReceipt.DocDate     = DateTime.Parse(hRow["DocDate"].ToString());
                    oDocReceipt.DocDueDate  = DateTime.Parse(hRow["DocDueDate"].ToString());
                    oDocReceipt.Comments    = hRow["Comments"].ToString();
                    oDocReceipt.JournalMemo = hRow["JournalMemo"].ToString();
                    // Add Details start ----------------------------
                    for (int i = 0; i < dtDoc.Rows.Count; i++)
                    {
                        DataRow row = dtDoc.Rows[i];
                        int     id  = int.Parse(row["Id"].ToString());

                        WriteLog("[Log]", "Id:[" + row["Id"].ToString() + "] R:[" + i + "] ItemCode:" + itemCode + "] BatchNo:" + row["DistNumber"].ToString() + " " + row["status"].ToString() + " Qty:" + row["BatchQuantity"].ToString());

                        idList.Add(id);
                        oDocReceipt.Lines.Add();
                        oDocReceipt.Lines.SetCurrentLine(i);
                        oDocReceipt.Lines.BaseType  = (int)SAPbobsCOM.BoObjectTypes.oProductionOrders;
                        oDocReceipt.Lines.BaseEntry = int.Parse(row["BaseEntry"].ToString());
                        //oDocReceipt.Lines.BaseLine = 0;
                        oDocReceipt.Lines.Quantity      = Double.Parse(row["BatchQuantity"].ToString()); //Batch Quantity = Receipt Quantity
                        oDocReceipt.Lines.WarehouseCode = "KH010";
                        oDocReceipt.Lines.FreeText      = row["Notes"].ToString();

                        //oDocReceipt.Lines.WarehouseCode = row["WarehouseCode"].ToString();
                        string status = row["Status"].ToString().Trim();
                        oDocReceipt.Lines.TransactionType = (status == "AC") ? SAPbobsCOM.BoTransactionTypeEnum.botrntComplete : SAPbobsCOM.BoTransactionTypeEnum.botrntReject;

                        if (isManageBatchNumbers.Equals("tYES"))
                        {
                            oDocReceipt.Lines.BatchNumbers.BatchNumber = row["DistNumber"].ToString();
                            oDocReceipt.Lines.BatchNumbers.Quantity    = Double.Parse(row["BatchQuantity"].ToString());
                            if (!String.IsNullOrEmpty(row["ExpiryDate"].ToString()))
                            {
                                oDocReceipt.Lines.BatchNumbers.ExpiryDate = DateTime.Parse(row["ExpiryDate"].ToString());
                            }
                            if (!String.IsNullOrEmpty(row["MnfDate"].ToString()))
                            {
                                oDocReceipt.Lines.BatchNumbers.ManufacturingDate = DateTime.Parse(row["MnfDate"].ToString());
                            }
                            if (!String.IsNullOrEmpty(row["InDate"].ToString()))
                            {
                                oDocReceipt.Lines.BatchNumbers.AddmisionDate = DateTime.Parse(row["InDate"].ToString());
                            }
                            oDocReceipt.Lines.BatchNumbers.Notes = row["Notes"].ToString();
                            oDocReceipt.Lines.BatchNumbers.Add();
                        }

                        // add line end --------------------
                    }

                    retcode = oDocReceipt.Add();
                    if (retcode == 0)
                    {
                        // Success
                        string docEntry = "";
                        string docNum   = "";

                        oCom.GetNewObjectCode(out docEntry);
                        if (docEntry == "")
                        {
                            errMsg = "Unknown Error! Please try again!";
                            if (oCom.InTransaction)
                            {
                                oCom.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                            }
                            WriteLog("[Error]", "Production Receipt:" + errMsg);
                            continue;
                        }
                        SAPbobsCOM.Documents sapDoc = (SAPbobsCOM.Documents)oCom.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry);
                        if (sapDoc.GetByKey(int.Parse(docEntry)))
                        {
                            docNum = sapDoc.DocNum.ToString();
                        }

                        foreach (int id in idList)
                        {
                            string     str     = "exec sp_FT_UpdateProductionOrder '" + id + "','Y','" + "" + "','" + docNum + "'";
                            SqlCommand cmdExec = new SqlCommand(str, conn);
                            cmdExec.ExecuteNonQuery();
                            WriteLog("[Success]", "Production Receipt:[" + docNum + "] has been added!");
                        }

                        if (oCom.InTransaction)
                        {
                            oCom.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                        }

                        cmd.CommandText = "SELECT CASE WHEN Sum(isNull(BatchQuantity,0.00)) >= MAX(T0.Quantity) Then 1 else 0 END " +
                                          "FROM[dbo].[ProductionReceipt] T0 " +
                                          "Where ISNULL(T0.Posted,'N') = 'Y' AND T0.BaseEntry=" + baseEntry + " GROUP BY T0.BaseEntry";

                        Int32 totalReceived = (Int32)cmd.ExecuteScalar();

                        // Closed Production
                        if (oDocProductionOrders.GetByKey(baseEntry) && totalReceived == 1)
                        {
                            string msg = "Production Order:[" + oDocProductionOrders.DocumentNumber.ToString() + "] has been closed!";
                            string rmk = oDocProductionOrders.Remarks;
                            oDocProductionOrders.ProductionOrderStatus = SAPbobsCOM.BoProductionOrderStatusEnum.boposClosed;
                            oDocProductionOrders.Remarks = rmk + " :closed by integration";
                            //oDocProductionOrders.ProductionOrderStatus = SAPbobsCOM.BoProductionOrderStatusEnum.boposCancelled;
                            oDocProductionOrders.Update();
                            WriteLog("[Success]", msg);
                            foreach (int id in idList)
                            {
                                string     str     = "exec sp_FT_UpdateProductionOrder '" + id + "','Y','" + msg + "','" + docNum + "'";
                                SqlCommand cmdExec = new SqlCommand(str, conn);
                                cmdExec.ExecuteNonQuery();
                            }
                        }
                    }
                    else
                    {  // Error
                        oCom.GetLastError(out errCode, out errMsg);
                        foreach (int id in idList)
                        {
                            string     str     = "exec sp_FT_UpdateProductionOrder '" + id + "','N','" + errMsg.Replace("'", "") + "',''";
                            SqlCommand cmdExec = new SqlCommand(str, conn);
                            cmdExec.ExecuteNonQuery();
                        }
                        WriteLog("[Error]", "Production Order:[" + proNo + "] Error Msg:" + oCom.GetLastErrorDescription());
                        if (oCom.InTransaction)
                        {
                            oCom.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                        }
                    }
                }
                catch (Exception ex)
                {
                    oCom.GetLastError(out errCode, out errMsg);
                    string msg = (ex.Message + " SAP msg:" + errMsg).Replace("'", "");
                    foreach (int id in idList)
                    {
                        string     str     = "exec sp_FT_UpdateProductionOrder '" + id + "','N','" + msg + "','" + "" + "'";
                        SqlCommand cmdExec = new SqlCommand(str, conn);
                        cmdExec.ExecuteNonQuery();
                    }
                    WriteLog("[Error]", "Production Receipt:" + msg);
                }
            }
            #endregion

EndApplication:

            bool sendEmail = false;
            foreach (KeyValuePair <string, List <string> > kvp in logs)
            {
                string        status = kvp.Key;
                List <string> msgs   = kvp.Value;
                if (status == "[Error]")
                {
                    sendEmail = true;
                }
            }
            if (sendEmail)
            {
                WriteLog("[Log]", " ➜ Send E-Mail");
                SendEmail();
            }
            ;
            WriteLog("", "Integration End");
            //Thread.Sleep(3000);
        }
Пример #7
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);
            }
        }