Exemplo n.º 1
0
        /// <summary>
        /// Retorna as entidades de transações não lida pelo SAP.
        /// </summary>
        /// <param name="isnew">Buscar somente novas entradas?</param>
        /// <returns></returns>
        public static List <TWOEntity> GetDados(bool isnew)
        {
            var transacoes = new List <TWOEntity>();

            principal.GravaAudit("MyRecordSet ini");
            using (var conn = new MyRecordSet())
            {
                //if (isnew) // TODO @BFAGUNDES -
                conn.DoQuery("SELECT * FROM [dbo].[Sage_Transaction_WO] WITH (NOLOCK) WHERE [TransactionType] = 40 AND ReadBySAP <> 'Y' AND (OWOR_DocNum IS NULL OR OWOR_DocNum < 1) ORDER BY AddDate");
                //else
                //conn.DoQuery("SELECT TOP 500 * FROM [dbo].[Sage_Transaction_WO] WITH (NOLOCK) WHERE [TransactionType] = 40 AND OWOR_DocNum > 0  ORDER BY ReadBySAP DESC");
                while (conn.HasNext())
                {
                    var trans = new TWOEntity();
                    try
                    {
                        trans.TransType          = conn.GetFieldValue("TransactionType").ToInt();
                        trans.ReadBySAP          = conn.GetFieldValue("ReadBySAP").ToChar();
                        trans.OWOR_U_ORDER_JOMAR = conn.GetFieldValue("OWOR_ORDER_JOMAR").ToString();
                        trans.OWOR_DocNum        = conn.GetFieldValue("OWOR_DocNum").ToInt();
                        trans.OITM_CodeBars      = conn.GetFieldValue("OITM_CodeBars").ToString();
                        trans.OWOR_PlannedQty    = conn.GetFieldValue("OWOR_PlannedQty").ToDouble();
                        trans.OWOR_WareHouse     = conn.GetFieldValue("OWOR_WareHouse").ToString();
                        trans.OWOR_PostDate      = conn.GetFieldValue("OWOR_PostDate").ToDate();
                        trans.OWOR_DueDate       = conn.GetFieldValue("OWOR_DueDate").ToDate();
                        trans.OWOR_Project       = conn.GetFieldValue("OWOR_Project").ToString();
                        trans.OWOR_Remarks       = String.Format("ID {0} - Transação 40. {1}", trans.Id, conn.GetFieldValue("OWOR_Remarks").ToString());

                        if (MyQuery.Exist("OITT", trans.OITM_ItemCode, "Code"))
                        {
                            if ((Program.contador % 2) == 0)
                            {
                                transacoes.Add(trans);
                            }
                            else
                            {
                                transacoes.Add(trans);
                            }
                        }
                        else
                        {
                            principal.GravaAudit("Não existe estrutura de produto cadastrado para ItemCode \"{0}\".", trans.OITM_ItemCode);
                            throw new Exception(String.Format("0 - Não existe estrutura de produto cadastrado para ItemCode \"{0}\".", trans.OITM_ItemCode));
                        }
                    }
                    catch (Exception ex)
                    {
                        trans.ReadBySAP = 'E';
                        trans.MSG_SAP   = ex.Message;

                        UpdateStatus(trans);

                        principal.GravaAudit("Erro empacotar ID " + trans.Id.ToString() + " " + ex.Message.ToString());
                    }
                }
                principal.GravaAudit("Termino While");
            }

            return(transacoes);
        }
Exemplo n.º 2
0
        public static void UpdateStatusReleased(TWOEntity two, ProductionOrders prd)
        {
            principal.GravaAudit("Inicia OP Liberado");
            using (var rs = new MyRecordSet())
            {
                principal.GravaAudit("Pesquisa OP " + two.OWOR_DocNum);
                if (prd.GetByKey(two.OWOR_DocNum))
                {
                    principal.GravaAudit("Acho OP");
                    prd.ProductionOrderStatus = BoProductionOrderStatusEnum.boposReleased;
                }

                int ii = prd.Update();

                if (ii != 0)
                {
                    principal.GravaAudit("Erro " + MyLibs.v2.sbo.SAPConnection.DI.GetLastErrorDescription());
                }
                else
                {
                    principal.GravaAudit("Atualizado para liberado com sucesso");
                }
            }
            principal.GravaAudit("termino OP Liberado");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retorna as entidades de transações não lida pelo SAP.
        /// </summary>
        /// <returns></returns>
        public static List <TWOEntity> GetTransForOIGE()
        {
            var transacoes = new List <TWOEntity>();

            using (var conn = new ConnSqlServer())
            {
                conn.DoQuery(Properties.Querys.Transacao_nW0OIGE_0);

                while (conn.HasNext())
                {
                    var trans = new TWOEntity();

                    try
                    {
                        trans.OWOR_Type          = 'D'; // Desmontagem
                        trans.TransType          = conn.GetFieldValue("TransactionType").ToInt();
                        trans.OWOR_U_ORDER_JOMAR = conn.GetFieldValue("OWOR_ORDER_JOMAR").ToString();
                        trans.OITM_CodeBars      = conn.GetFieldValue("OITM_CodeBars").ToString();
                        //trans.OWOR_PlannedQty = conn.GetFieldValue("OWOR_PlannedQty").ToDouble();
                        trans.OWOR_WareHouse = conn.GetFieldValue("OWOR_WareHouse").ToString();
                        trans.OWOR_PostDate  = DateTime.Now;
                        trans.OWOR_DueDate   = DateTime.Now;
                        trans.OWOR_DocNum    = conn.GetFieldValue("OWOR_DocNum").ToInt();
                        //trans.OIGE_DocNum = conn.GetFieldValue("OIGE_DocNum").ToInt();
                        trans.OWOR_Remarks = "Transação -WO GroupID : " + conn.GetFieldValue("GroupID").ToString();

                        if (MyQuery.Exist("OITT", trans.OITM_ItemCode, "Code"))
                        {
                            if ((Program.contador % 2) == 0)
                            {
                                if (trans.ReadBySAP != 'E')
                                {
                                    transacoes.Add(trans);
                                }
                            }
                            else
                            {
                                transacoes.Add(trans);
                            }
                        }
                        else
                        {
                            throw new Exception(String.Format("0 - Não existe estrutura de produto cadastrado para ItemCode \"{0}\".", trans.OITM_ItemCode));
                        }
                    }
                    catch (Exception ex)
                    {
                        trans.ReadBySAP = 'E';
                        trans.MSG_SAP   = ex.Message;
                        UpdateStatus(trans);

                        principal.GravaAudit("Transação -WO Erro empacotar ID " + trans.Id.ToString() + " " + ex.Message.ToString());
                    }
                }
            }

            return(transacoes);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Alterar o Status do Pedido.
        /// </summary>
        /// <param name="two"></param>
        private void AlterOWORStatus(TWOEntity two)
        {
            try
            {
                var oOWOR = (SAPbobsCOM.ProductionOrders)SAPConnection.DI.GetBusinessObject(BoObjectTypes.oProductionOrders);
                if (!oOWOR.GetByKey(two.OWOR_DocNum))
                {
                    two.ReadBySAP   = 'E';
                    two.MSG_SAP     = String.Format(Properties.LogMessage.TransWO_0038_2, two.Id, two.OWOR_DocNum);
                    two.OWOR_Status = 'P';
                    TWODAO.UpdateStatus(two);

                    Log.Register("AlterOWORStatus"
                                 , System.Diagnostics.EventLogEntryType.Error
                                 , Properties.LogMessage.TransWO_0038_2
                                 , two.Id
                                 , two.OWOR_DocNum);

                    return;
                }

                oOWOR.ProductionOrderStatus = two.OWOR_StatusBo;

                if (oOWOR.Update() != 0)
                {
                    two.ReadBySAP   = 'E';
                    two.MSG_SAP     = String.Format(Properties.LogMessage.TransWO_0039_3, two.Id, two.OWOR_DocNum, SAPConnection.DI.GetLastErrorDescription());
                    two.OWOR_Status = 'P';
                    TWODAO.UpdateStatus(two);

                    Log.Register("AlterOWORStatus"
                                 , System.Diagnostics.EventLogEntryType.Error
                                 , two.MSG_SAP);
                }
                else
                {
                    two.ReadBySAP = 'Y';
                    two.MSG_SAP   = "SUCESSO - Ordem de Produção liberada";
                    TWODAO.UpdateStatus(two);
                }
            }
            catch (Exception ex)
            {
                Log.Register("Transação WO"
                             , System.Diagnostics.EventLogEntryType.Error
                             , "Erro Atualizar Status OP na ID {0}. {1}"
                             , two.Id
                             , ex.Message);
            }
        }
Exemplo n.º 5
0
        public static void UpdateStatus41(TWOEntity two)
        {
            principal.GravaAudit("Inicio 41");
            using (var rs = new MyRecordSet())
            {
                string sql = "UPDATE [Sage_Transaction41] SET ReadySAP = '" + two.ReadBySAP + "' , ";
                sql += "OWOR_DocNum = '" + two.OWOR_DocNum + "' ";
                sql += "WHERE OWOR_Order_Jomar =  '" + two.OWOR_U_ORDER_JOMAR + "'";

                principal.GravaAudit(sql);
                principal.GravaAudit("Read " + two.ReadBySAP + " Docnum " + two.OWOR_DocNum);
                rs.DoQuery(sql);
            }
            principal.GravaAudit("Termino 41");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Atualiza o Status do pedido na tabela de transações WO
        /// </summary>
        /// <param name="two"></param>
        public static void UpdateStatus(TWOEntity two)
        {
            if (two.Id == 0)
            {
                TWONegDAO.UpdateStatus(two);
            }
            else
            {
                using (var rs = new MyRecordSet())
                {
                    var sql = "UPDATE [Sage_Transaction_WO] SET ReadBySAP = '{0}', OWOR_DocNum = '{1}',[MSG_SBO] = '{3}' WHERE Id = '{2}'";

                    principal.GravaAudit(String.Format(sql, two.ReadBySAP, two.OWOR_DocNum, two.Id, two.MSG_SAP.Replace("'", "''")));
                    rs.DoQuery(sql, two.ReadBySAP, two.OWOR_DocNum, two.Id, two.MSG_SAP.Replace("'", "''"));
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Atualiza o Status do pedido na tabela de transações WO
        /// </summary>
        /// <param name="two"></param>
        public static void UpdateStatus(TWOEntity two)
        {
            using (var rs = new MyRecordSet())
            {
                principal.GravaAudit("two.Id " + two.Id.ToString());
                principal.GravaAudit("two.OWOR_U_ORDER_JOMAR " + two.OWOR_U_ORDER_JOMAR.ToString());
                if (two.Id == 0)
                {
                    string sql = "UPDATE   [Sage_Transaction_WO]  SET ReadBySAP = '" + two.ReadBySAP + "' , ";
                    sql += "OWOR_DocNum = '" + two.OWOR_DocNum + "' ";
                    sql += ",[MSG_SBO] = '" + two.MSG_SAP.Replace("'", "''") + "' ";
                    sql += "WHERE OWOR_Order_Jomar =  '" + two.OWOR_U_ORDER_JOMAR + "'";

//                    var sql = @"
//                            UPDATE   [Sage_Transaction_WO]
//                            SET      ReadBySAP = 'Y'
//                                    ,OWOR_DocNum = '{1}'
//                                    ,[MSG_SBO] = '{3}'
//                            WHERE (CAST(TransactionType as nvarchar(100))
//		                            +	CAST(OWOR_ORDER_JOMAR as nvarchar(100))
//		                            +	CAST(OITM_CodeBars AS nvarchar(20))
//		                            +	CAST(OWOR_DocNum AS nvarchar(20))
//		                            +	OWOR_WareHouse) = '{2}'";

                    principal.GravaAudit(sql);
                    principal.GravaAudit("Read " + two.ReadBySAP + " Docnum " + two.OWOR_DocNum + " MSG " + two.MSG_SAP.Replace("'", "''"));
                    rs.DoQuery(sql);
                }
                else
                {
                    principal.GravaAudit("Update Status 5");
                    string sql = "UPDATE   [Sage_Transaction_WO]  SET ReadBySAP = '" + two.ReadBySAP + "', ";
                    sql += "OWOR_DocNum = '" + two.OWOR_DocNum + "' ";
                    sql += ",[MSG_SBO] = '" + two.MSG_SAP.Replace("'", "''") + "' ";
                    sql += "Id = '" + two.Id + "'";

//                    var sql = @"
//                        UPDATE   [Sage_Transaction_WO]
//                        SET      ReadBySAP = '{0}'
//                                ,OWOR_DocNum = '{1}'
//                                ,[MSG_SBO] = '{3}'
//                        WHERE Id = {2}";
                    rs.DoQuery(sql, two.ReadBySAP, two.OWOR_DocNum, two.Id, two.MSG_SAP.Replace("'", "''"));
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Alterar o Status do Pedido.
        /// </summary>
        /// <param name="two"></param>
        private void AlterOWORStatus(TWOEntity two)
        {
            try
            {
                var oOWOR = (SAPbobsCOM.ProductionOrders)SAPConnection.DI.GetBusinessObject(BoObjectTypes.oProductionOrders);
                if (!oOWOR.GetByKey(two.OWOR_DocNum))
                {
                    two.ReadBySAP   = 'E';
                    two.MSG_SAP     = String.Format(Properties.LogMessage.TransWO_0038_2, two.Id, two.OWOR_DocNum);
                    two.OWOR_Status = 'P';
                    TWODAO.UpdateStatus(two);

                    return;
                }

                oOWOR.ProductionOrderStatus = two.OWOR_StatusBo;

                if (oOWOR.Update() != 0)
                {
                    two.ReadBySAP   = 'E';
                    two.MSG_SAP     = String.Format(Properties.LogMessage.TransWO_0039_3, two.Id, two.OWOR_DocNum, SAPConnection.DI.GetLastErrorDescription());
                    two.OWOR_Status = 'P';
                    TWODAO.UpdateStatus(two);
                }
                else
                {
                    two.ReadBySAP = 'Y';
                    two.MSG_SAP   = "SUCESSO - Ordem de Produção liberada";
                    TWODAO.UpdateStatus(two);
                }
            }
            catch (Exception ex)
            {
                principal.GravaAudit(ex.Message.ToString());
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Criação de uma nova Ordem de Produção com os
        /// componentes da estrutura do produto.
        /// </summary>
        /// <param name="tnwo"></param>
        private void OWORWithProductTreeDefault(TWOEntity two)
        {
            try
            {
                var oOWOR = (SAPbobsCOM.ProductionOrders)SAPConnection.DI.GetBusinessObject(BoObjectTypes.oProductionOrders);
                oOWOR.ItemNo = two.OITM_ItemCode;
                oOWOR.ProductionOrderType = two.OWOR_TypeBo;
                oOWOR.Warehouse           = two.OWOR_WareHouse;
                oOWOR.PostingDate         = two.OWOR_PostDate;
                oOWOR.DueDate             = two.OWOR_DueDate;
                if (two.OWOR_OriginNum > 0)
                {
                    oOWOR.ProductionOrderOriginEntry = two.OWOR_OriginNum;
                }
                oOWOR.ProductionOrderStatus = two.OWOR_StatusBo;
                oOWOR.Project         = two.OWOR_Project;
                oOWOR.PlannedQuantity = two.OWOR_PlannedQty < 0 ? -two.OWOR_PlannedQty : two.OWOR_PlannedQty;
                oOWOR.UserFields.Fields.Item("U_ORDER_JOMAR").Value = two.OWOR_U_ORDER_JOMAR;
                oOWOR.Remarks = two.OWOR_Remarks;

                // Desmontagem - Os itens deverão ser informado manualmente.
                if (oOWOR.ProductionOrderType == BoProductionOrderTypeEnum.bopotDisassembly)
                {
                    var oOITT = (SAPbobsCOM.ProductTrees)SAPConnection.DI.GetBusinessObject(BoObjectTypes.oProductTrees);

                    if (oOITT.GetByKey(two.OITM_ItemCode))
                    {
                        for (int i = 0; i < (oOITT.Items.Count - 1); i++)
                        {
                            oOITT.Items.SetCurrentLine(i);

                            // Desmontagem - Não é permitido inserir recurso.
                            if (oOITT.Items.ItemType == ProductionItemType.pit_Item)
                            {
                                oOWOR.Lines.ItemNo          = oOITT.Items.ItemCode;
                                oOWOR.Lines.ItemType        = oOITT.Items.ItemType;
                                oOWOR.Lines.PlannedQuantity = oOITT.Items.Quantity * (two.OWOR_PlannedQty < 0 ? -two.OWOR_PlannedQty : two.OWOR_PlannedQty);
                                oOWOR.Lines.BaseQuantity    = oOITT.Items.Quantity;
                                oOWOR.Lines.Warehouse       = "PP";//oOITT.Items.Warehouse;
                                oOWOR.Lines.UserFields.Fields.Item("U_Line_Jomar").Value = two.OWOR_U_ORDER_JOMAR;
                                oOWOR.Lines.Add();
                            }
                            else
                            {
                                Log.Register("Transação - WO"
                                             , System.Diagnostics.EventLogEntryType.Information
                                             , "Estrutura de Produto {0} : Recurso '{1}' removido da desmontagem."
                                             , two.OITM_ItemCode
                                             , oOITT.Items.ItemCode);
                            }
                        }
                    }
                    else
                    {
                        Log.Register("Transação " + (int)two.TransType
                                     , System.Diagnostics.EventLogEntryType.Information
                                     , "Estrutura de Produto {0} não localizado."
                                     , two.OITM_ItemCode);
                    }
                }

                #region Itens - Não será mais utilizado
                //var t38lista = T38DAO.GetForOWOR(int.Parse(tnwo.OWOR_U_ORDER_JOMAR));
                //int pos = 0;
                //foreach (var t38 in t38lista)
                //{
                //    if (oODRF.ProductionOrderType != BoProductionOrderTypeEnum.bopotSpecial)
                //        oODRF.ProductionOrderType = BoProductionOrderTypeEnum.bopotSpecial;
                //    var a = oODRF.Lines.Count;
                //    oODRF.Lines.SetCurrentLine(pos++);
                //    oODRF.Lines.ItemNo = t38.OITM_ItemCode;
                //    oODRF.Lines.ItemType = t38.ItemTypeBo;
                //    oODRF.Lines.PlannedQuantity = t38.WOR1_PlannedQty;
                //    oODRF.Lines.BaseQuantity = t38.WOR1_BaseQty;
                //    oODRF.Lines.Warehouse = t38.WOR1_WareHouse;
                //    oODRF.Lines.UserFields.Fields.Item("U_Line_Jomar").Value = t38.JOMAR_LineNum;
                //    oODRF.Lines.Add();
                //}
                #endregion

                if (oOWOR.Add() != 0)
                {
                    two.ReadBySAP = 'E';
                    two.MSG_SAP   = SAPConnection.DI.GetLastErrorDescription().Replace("'", "\"");
                    TWODAO.UpdateStatus(two);

                    Log.Register("Transação " + (int)two.TransType, System.Diagnostics.EventLogEntryType.Error
                                 , "ID {0} - {1}", two.Id, two.MSG_SAP);
                    if (SAPConnection.DI.InTransaction)
                    {
                        SAPConnection.DI.EndTransaction(BoWfTransOpt.wf_RollBack);
                    }
                }
                else
                {
                    two.OWOR_DocNum = SAPConnection.GetNewKey();
                    two.ReadBySAP   = 'Y';
                    two.MSG_SAP     = "SUCESSO - Ordem de Produção criado. Número da Ordem: " + SAPConnection.GetNewKey();
                    TWODAO.UpdateStatus(two);

                    // @BFAGUNDES - alterando o Status como 'Liberado'
                    two.OWOR_Status = 'R'; // Release
                    AlterOWORStatus(two);
                }
            }
            catch (Exception ex)
            {
                Log.Register("Transação WO-WO"
                             , System.Diagnostics.EventLogEntryType.Error
                             , "Erro Adicionar OP na ID {0}. {1}"
                             , two.Id
                             , ex.Message);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Criação de uma nova Ordem de Produção com os
        /// componentes da estrutura do produto.
        /// </summary>
        /// <param name="tnwo"></param>
        private void OWORWithProductTreeDefault(TWOEntity two)
        {
            try
            {
                principal.GravaAudit("Inicio AddOP");
                var oOWOR = (SAPbobsCOM.ProductionOrders)SAPConnection.DI.GetBusinessObject(BoObjectTypes.oProductionOrders);
                oOWOR.ItemNo = two.OITM_ItemCode;
                oOWOR.ProductionOrderType = two.OWOR_TypeBo;
                oOWOR.Warehouse           = two.OWOR_WareHouse;
                oOWOR.PostingDate         = two.OWOR_PostDate;
                oOWOR.DueDate             = two.OWOR_DueDate;
                if (two.OWOR_OriginNum > 0)
                {
                    oOWOR.ProductionOrderOriginEntry = two.OWOR_OriginNum;
                }
                oOWOR.ProductionOrderStatus = BoProductionOrderStatusEnum.boposPlanned;
                oOWOR.Project         = two.OWOR_Project;
                oOWOR.PlannedQuantity = two.OWOR_PlannedQty < 0 ? -two.OWOR_PlannedQty : two.OWOR_PlannedQty;
                oOWOR.UserFields.Fields.Item("U_ORDER_JOMAR").Value = two.OWOR_U_ORDER_JOMAR;
                oOWOR.Remarks = two.OWOR_Remarks;

                // Desmontagem - Os itens deverão ser informado manualmente.
                if (oOWOR.ProductionOrderType == BoProductionOrderTypeEnum.bopotDisassembly)
                {
                    var oOITT = (SAPbobsCOM.ProductTrees)SAPConnection.DI.GetBusinessObject(BoObjectTypes.oProductTrees);

                    if (oOITT.GetByKey(two.OITM_ItemCode))
                    {
                        for (int i = 0; i < (oOITT.Items.Count - 1); i++)
                        {
                            oOITT.Items.SetCurrentLine(i);

                            // Desmontagem - Não é permitido inserir recurso.
                            if (oOITT.Items.ItemType == ProductionItemType.pit_Item)
                            {
                                oOWOR.Lines.ItemNo          = oOITT.Items.ItemCode;
                                oOWOR.Lines.ItemType        = oOITT.Items.ItemType;
                                oOWOR.Lines.PlannedQuantity = oOITT.Items.Quantity * (two.OWOR_PlannedQty < 0 ? -two.OWOR_PlannedQty : two.OWOR_PlannedQty);
                                oOWOR.Lines.BaseQuantity    = oOITT.Items.Quantity;
                                oOWOR.Lines.Warehouse       = "PP";//oOITT.Items.Warehouse;
                                oOWOR.Lines.UserFields.Fields.Item("U_Line_Jomar").Value = two.OWOR_U_ORDER_JOMAR;
                                oOWOR.Lines.Add();
                            }
                        }
                    }
                }

                if (oOWOR.Add() != 0)
                {
                    two.ReadBySAP = 'E';
                    two.MSG_SAP   = SAPConnection.DI.GetLastErrorDescription().Replace("'", "\"");
                    principal.GravaAudit(two.MSG_SAP);
                    TWODAO.UpdateStatus(two);

                    if (SAPConnection.DI.InTransaction)
                    {
                        SAPConnection.DI.EndTransaction(BoWfTransOpt.wf_RollBack);
                    }
                }
                else
                {
                    two.OWOR_DocNum = SAPConnection.GetNewKey();
                    two.ReadBySAP   = 'Y';
                    two.MSG_SAP     = "SUCESSO - Ordem de Produção criado. Número da Ordem: " + SAPConnection.GetNewKey();
                    principal.GravaAudit(two.MSG_SAP);
                    TWODAO.UpdateStatusReleased(two, oOWOR);
                    TWODAO.UpdateLineOP(two, oOWOR);
                    TWODAO.UpdateStatus(two);

                    // @BFAGUNDES - alterando o Status como 'Liberado'
                    two.OWOR_Status = 'R'; // Release
                    AlterOWORStatus(two);
                }
                principal.GravaAudit("Termino AddOP");
            }
            catch (Exception ex)
            {
                principal.GravaAudit(ex.Message.ToString());
            }
        }
Exemplo n.º 11
0
        public static void UpdateLineOP(TWOEntity two, ProductionOrders prd)
        {
            try
            {
                using (var rs = new MyRecordSet())
                {
                    try
                    {
                        principal.GravaAudit("Inicio remove linhas OP");
                        string sql1 = "delete from WOR1 where docentry = " + two.OWOR_DocNum + "and ItemType = 4 ";

                        rs.DoQuery(sql1);
                        principal.GravaAudit("Termino remove linhas OP ");
                    }
                    catch (Exception ex)
                    {
                        principal.GravaAudit("EX " + ex.Message.ToString());
                        principal.GravaAudit("Continua");
                    }

                    string sql = "Select distinct T1.DocEntry, T3.ItemCode, 'PP' As 'ProductionWarehouse', ConsumptionQuantity from [Sage_Transaction41] T0 ";
                    sql += "left join OWOR T1 on T1.U_ORDER_JOMAR = T0.OWOR_Order_Jomar ";
                    sql += "left join OITM T3 on T3.CodeBars = T0.OITM_CodeBars ";
                    sql += "left join ITT1 T2 on T2.Code = T3.ItemCode ";
                    sql += "where T0.OWOR_Order_Jomar = '" + two.OWOR_U_ORDER_JOMAR + "' and T2.Type = 4 and readySAP <> 'Y' ";

                    principal.GravaAudit("Inicio add linhas OP");
                    principal.GravaAudit(sql);
                    rs.DoQuery(sql);

                    int a  = 0;
                    int ii = 0;
                    while (rs.HasNext())
                    {
                        if (prd.GetByKey(rs.GetFieldValue(0).ToInt()))
                        {
                            principal.GravaAudit("Item " + rs.GetFieldValue(1).ToString());
                            principal.GravaAudit("PlannedQuantity " + rs.GetFieldValue(3).ToDouble().ToString());
                            principal.GravaAudit("Warehouse " + rs.GetFieldValue(2).ToString());
                            principal.GravaAudit("U_Line_Jomar " + two.OWOR_U_ORDER_JOMAR);

                            prd.Lines.Add();
                            prd.Lines.ItemNo          = rs.GetFieldValue(1).ToString();
                            prd.Lines.ItemType        = ProductionItemType.pit_Item;
                            prd.Lines.PlannedQuantity = rs.GetFieldValue(3).ToDouble();
                            //prd.Lines.BaseQuantity = rs.GetFieldValue(0).ToInt();
                            prd.Lines.Warehouse = rs.GetFieldValue(2).ToString();
                            prd.Lines.UserFields.Fields.Item("U_Line_Jomar").Value = two.OWOR_U_ORDER_JOMAR;
                            ii = prd.Update();
                        }
                    }

                    principal.GravaAudit("Termino add linhas OP");


                    if (ii != 0)
                    {
                        principal.GravaAudit("Erro " + MyLibs.v2.sbo.SAPConnection.DI.GetLastErrorDescription());
                    }
                    else
                    {
                        UpdateStatus41(two);
                        principal.GravaAudit("Concluido com sucesso");
                    }
                }
            }
            catch (Exception ex)
            {
                principal.GravaAudit("Erro " + ex.Message.ToString());
            }
        }