Ejemplo n.º 1
0
        /// <summary> Adds pObjRecord. </summary>
        /// <remarks> Ranaya, 26/05/2017. </remarks>
        /// <exception cref="TableException"> Thrown when a Table error condition occurs. </exception>
        /// <param name="pObjRecord"> The Object record to add. </param>

        public void Add(T pObjRecord)
        {
            SAPbobsCOM.GeneralService    lObjGeneralService    = null;
            SAPbobsCOM.GeneralData       lObjGeneralData       = null;
            SAPbobsCOM.GeneralDataParams lObjGeneralDataParams = null;
            SAPbobsCOM.CompanyService    lObjCompanyService    = null;

            try
            {
                //Initialize variables
                lObjCompanyService = DIApplication.Company.GetCompanyService();
                lObjGeneralService = lObjCompanyService.GetGeneralService(GetObjectCode());
                lObjGeneralData    = ((SAPbobsCOM.GeneralData)(lObjGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralData)));

                //Set data
                lObjGeneralData = PopulateGeneralData(lObjGeneralData, pObjRecord);

                //Add data
                lObjGeneralDataParams = lObjGeneralService.Add(lObjGeneralData);
            }
            catch (Exception e)
            {
                throw new TableException(e.Message, e);
            }
            finally
            {
                MemoryUtility.ReleaseComObject(lObjGeneralService, lObjGeneralData, lObjGeneralDataParams, lObjCompanyService);
            }
        }
        public static string DeleteRecord(string UDO_Name, string CodigoObj)
        {
            SAPbobsCOM.GeneralService    oGeneralService = null;
            SAPbobsCOM.GeneralData       oGeneralData    = null;
            SAPbobsCOM.GeneralDataParams oGeneralParams  = null;
            SAPbobsCOM.CompanyService    sCmp            = null;
            SAPbobsCOM.Company           SBO_Company     = Conexion.oCompany;

            sCmp = SBO_Company.GetCompanyService();
            string rpta = "N";

            try
            {
                // Get a handle to the SM_MOR UDO
                oGeneralService = sCmp.GetGeneralService(UDO_Name);

                // Delete UDO record
                oGeneralParams = ((SAPbobsCOM.GeneralDataParams)(oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams)));
                oGeneralParams.SetProperty("Code", CodigoObj);
                oGeneralData = oGeneralService.GetByParams(oGeneralParams);
                oGeneralService.Delete(oGeneralParams);
            }
            catch (Exception) {}
            return(rpta);
        }
Ejemplo n.º 3
0
        /// <summary> Updates the given pObjRecord. </summary>
        /// <remarks> Ranaya, 26/05/2017. </remarks>
        /// <exception cref="TableException"> Thrown when a Table error condition occurs. </exception>
        /// <param name="pObjRecord"> The object record. </param>

        public void Update(T pObjRecord)
        {
            SAPbobsCOM.GeneralService    lObjGeneralService    = null;
            SAPbobsCOM.GeneralData       lObjGeneralData       = null;
            SAPbobsCOM.GeneralDataParams lObjGeneralDataParams = null;
            SAPbobsCOM.CompanyService    lObjCompanyService    = null;

            try
            {
                //Initialize variables
                lObjCompanyService    = DIApplication.Company.GetCompanyService();
                lObjGeneralService    = lObjCompanyService.GetGeneralService(GetObjectCode());
                lObjGeneralDataParams = ((SAPbobsCOM.GeneralDataParams)(lObjGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams)));

                //Get current data by params
                lObjGeneralDataParams.SetProperty("DocEntry", pObjRecord.GetKey());
                lObjGeneralData = lObjGeneralService.GetByParams(lObjGeneralDataParams);

                //Set new data
                lObjGeneralData = PopulateGeneralData(lObjGeneralData, pObjRecord);

                //Update data
                lObjGeneralService.Update(lObjGeneralData);
            }
            catch (Exception e)
            {
                throw new TableException(e.Message, e);
            }
            finally
            {
                MemoryUtility.ReleaseComObject(lObjGeneralService, lObjGeneralData, lObjGeneralDataParams, lObjCompanyService);
            }
        }
Ejemplo n.º 4
0
        //Alteração em tabela customizada por objeto, passar nome da tabela e coleção de parâmetros(Nome do campo e valor)
        protected bool Alterar(string nomeObjeto, string codigo, Dictionary <string, string> parametros)
        {
            bool retorno = false;

            try
            {
                oCompService    = oCompany.GetCompanyService();
                oGeneralService = oCompService.GetGeneralService(nomeObjeto);
                oGeneralParams  = ((SAPbobsCOM.GeneralDataParams)(oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams)));

                //Recupera Objeto para alteração
                oGeneralParams.SetProperty("Code", codigo);
                oGeneralData = oGeneralService.GetByParams(oGeneralParams);

                if (parametros != null && parametros.Count > 0)
                {
                    foreach (var item in parametros)
                    {
                        oGeneralData.SetProperty(item.Key.ToString(), item.Value.ToString());
                    }

                    oGeneralService.Update(oGeneralData);
                }

                retorno = true;
            }
            catch (Exception e)
            {
                throw e;
            }

            return(retorno);
        }
Ejemplo n.º 5
0
        /// <summary> Removes the given pStrDocEntry. </summary>
        /// <remarks> Ranaya, 26/05/2017. </remarks>
        /// <exception cref="TableException"> Thrown when a Table error condition occurs. </exception>
        /// <param name="pStrDocEntry"> The String Document entry to remove. </param>

        public void Remove(string pStrDocEntry)
        {
            SAPbobsCOM.GeneralService    lObjGeneralService    = null;
            SAPbobsCOM.GeneralData       lObjGeneralData       = null;
            SAPbobsCOM.GeneralDataParams lObjGeneralDataParams = null;
            SAPbobsCOM.CompanyService    lObjCompanyService    = null;

            try
            {
                //Initialize variables
                lObjCompanyService    = DIApplication.Company.GetCompanyService();
                lObjGeneralService    = lObjCompanyService.GetGeneralService(GetObjectCode());
                lObjGeneralDataParams = ((SAPbobsCOM.GeneralDataParams)(lObjGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams)));

                //Set docentry
                lObjGeneralDataParams.SetProperty("DocEntry", pStrDocEntry);

                //Delete data
                lObjGeneralService.Delete(lObjGeneralDataParams);
            }
            catch (Exception e)
            {
                throw new TableException(e.Message, e);
            }
            finally
            {
                MemoryUtility.ReleaseComObject(lObjGeneralService, lObjGeneralData, lObjGeneralDataParams, lObjCompanyService);
            }
        }
Ejemplo n.º 6
0
        //Consulta em tabela customizada por objeto, passar nome da tabela e coleção de parâmetros(Nome do campo e valor)
        protected GeneralData Consultar(string nomeObjeto, Dictionary <string, string> parametros)
        {
            oGeneralData = null;

            try
            {
                if (!String.IsNullOrEmpty(nomeObjeto) && parametros != null)
                {
                    oCompService    = oCompany.GetCompanyService();
                    oGeneralService = oCompService.GetGeneralService(nomeObjeto);
                    oGeneralParams  = ((SAPbobsCOM.GeneralDataParams)(oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams)));

                    if (parametros != null && parametros.Count > 0)
                    {
                        foreach (var item in parametros)
                        {
                            oGeneralParams.SetProperty(item.Key.ToString(), item.Value);
                        }

                        oGeneralData = oGeneralService.GetByParams(oGeneralParams);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(oGeneralData);
        }
Ejemplo n.º 7
0
        //Inclusão em tabela customizada por objeto, passar nome da tabela e coleção de parâmetros(Nome do campo e valor)
        protected void Incluir(string nomeObjeto, Dictionary <string, string> parametros)
        {
            try
            {
                oCompService = oCompany.GetCompanyService();
                oCompany.StartTransaction();
                oGeneralService = oCompService.GetGeneralService(nomeObjeto);

                oGeneralData = (SAPbobsCOM.GeneralData)oGeneralService.GetDataInterface(GeneralServiceDataInterfaces.gsGeneralData);

                if (parametros != null && parametros.Count > 0)
                {
                    foreach (var item in parametros)
                    {
                        oGeneralData.SetProperty(item.Key.ToString(), item.Value.ToString());
                    }

                    oGeneralService.Add(oGeneralData);
                }

                if (oCompany.InTransaction)
                {
                    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                }
            }
            catch (Exception e)
            {
                if (oCompany.InTransaction)
                {
                    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                }

                throw e;
            }
        }
Ejemplo n.º 8
0
        //Consulta o o último Id por objeto na tabela customizada
        protected int ConsultarUltimoId(string nomeObjeto)
        {
            int ultimo = 0;

            try
            {
                oCompService    = oCompany.GetCompanyService();
                oGeneralService = oCompService.GetGeneralService(nomeObjeto);

                try
                {
                    oGeneralData = (SAPbobsCOM.GeneralData)oGeneralService.GetDataInterface(GeneralServiceDataInterfaces.gsGeneralData);
                    GeneralCollectionParams oGeneralCol = oGeneralService.GetList();

                    List <int> lista = new List <int>();

                    foreach (GeneralDataParams item in oGeneralCol)
                    {
                        string aux = item.GetProperty("Code").ToString();
                        if (aux != "*")
                        {
                            lista.Add(Convert.ToInt32(aux));
                        }
                    }

                    lista.Sort();
                    ultimo = lista.Last();
                }
                catch (Exception e)
                {
                    //Não existe registro no BD
                    if (e.HResult == -2028)
                    {
                        return(ultimo);
                    }
                    //Registro Duplicado
                    else if (e.HResult == -2035)
                    {
                        throw e;
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(ultimo);
        }
        public static string UpdateRecordHead(string UDO_Name, Object Objeto, string CodigoObj)
        {
            SAPbobsCOM.GeneralService    oGeneralService = null;
            SAPbobsCOM.GeneralData       oGeneralData    = null;
            SAPbobsCOM.GeneralDataParams oGeneralParams  = null;
            SAPbobsCOM.CompanyService    sCmp            = null;
            SAPbobsCOM.Company           SBO_Company     = Conexion.oCompany;

            sCmp = SBO_Company.GetCompanyService();
            string rpta = "N";

            //  This function updates only parent record.
            //  Child records remain as is.
            try
            {
                // Get a handle UDO
                oGeneralService = sCmp.GetGeneralService(UDO_Name);
                // Get UDO record
                oGeneralParams = ((SAPbobsCOM.GeneralDataParams)(oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams)));
                oGeneralParams.SetProperty("Code", CodigoObj);
                oGeneralData = oGeneralService.GetByParams(oGeneralParams);
                // Update UDO record
                foreach (PropertyInfo propiedad in Objeto.GetType().GetProperties())
                {
                    try
                    {
                        string tipoPropiedad   = propiedad.PropertyType.Name;
                        string NombrePropiedad = propiedad.Name;
                        var    valorPropiedad  = propiedad.GetValue(Objeto, null);
                        oGeneralData.SetProperty(NombrePropiedad, valorPropiedad);
                    }
                    catch (Exception) { }
                }
                oGeneralService.Update(oGeneralData);
                rpta = "S";
            }
            catch (Exception) { }
            return(rpta);
        }
Ejemplo n.º 10
0
        //Exclusão em tabela customizada por objeto, passar nome da tabela e parâmetros(Nome do campo e valor)
        protected bool Excluir(string nomeObjeto, KeyValuePair <string, string> parametro)
        {
            bool retorno = false;

            try
            {
                oCompService    = oCompany.GetCompanyService();
                oGeneralService = oCompService.GetGeneralService(nomeObjeto);
                oGeneralParams  = ((SAPbobsCOM.GeneralDataParams)(oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams)));

                if (parametro.Key != null && parametro.Value != null)
                {
                    oGeneralParams.SetProperty(parametro.Key, parametro.Value);
                    oGeneralService.Delete(oGeneralParams);
                    retorno = true;
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(retorno);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Click button replace
        /// </summary>
        private void ChangeCompItm_Replace(string formUID, ref ItemEvent pVal, ref bool bubbleEvent)
        {
            if (bubbleEvent)
            {
                if (pVal.BeforeAction == false && pVal.ActionSuccess == true)// && pVal.EventType == BoEventTypes.et_CLICK)
                {
                    // Checkk Validation
                    string errorMsg = string.Empty;
                    if (IsBlocReplace(formUID, out errorMsg))
                    {
                        oSBOApplication.StatusBar.SetText(errorMsg, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                    }
                    else
                    {
                        Form oForm = oSBOApplication.Forms.Item(formUID);
                        oForm.Freeze(true);

                        SAPbobsCOM.ProductionOrders oProd;
                        oProd = oSBOCompany.GetBusinessObject(BoObjectTypes.oProductionOrders);

                        SAPbobsCOM.GeneralService oGenService = oSBOCompany.GetCompanyService().GetGeneralService("COMPITM");
                        SAPbobsCOM.GeneralData    compLog     = (SAPbobsCOM.GeneralData)oGenService.GetDataInterface(GeneralServiceDataInterfaces.gsGeneralData);

                        Recordset oRec = oSBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
                        Matrix    oMtx = oForm.Items.Item("mt_1").Specific;

                        ProgressBar oProgressBar = oSBOApplication.StatusBar.CreateProgressBar("Replace Work Order", oMtx.RowCount, true);
                        oProgressBar.Text = "Replace Work Order...";
                        int progress = 0;

                        try
                        {
                            for (int i = 1; i <= oMtx.RowCount; i++)
                            {
                                string check = string.Empty;
                                if (oMtx.Columns.Item("cCheck").Cells.Item(i).Specific.Checked == true)
                                {
                                    check = "Y";
                                }

                                if (check == "Y")
                                {
                                    string query = "SELECT \"DocEntry\" FROM OWOR WHERE \"DocNum\" = '" + oMtx.Columns.Item("cNoWo").Cells.Item(i).Specific.Value + "'";
                                    oRec.DoQuery(query);

                                    int docEntry = 0;
                                    if (oRec.RecordCount > 0)
                                    {
                                        docEntry = oRec.Fields.Item("DocEntry").Value;
                                    }

                                    oProd.GetByKey(docEntry);

                                    for (int j = 0; j < oProd.Lines.Count; j++)
                                    {
                                        string b = oForm.Items.Item("tComItmCd").Specific.Value;
                                        if (oProd.Lines.ItemNo == b)
                                        {
                                            oProd.Lines.SetCurrentLine(j);
                                            oProd.Lines.ItemNo = oForm.Items.Item("tAltItmCd").Specific.Value;
                                            string altQty = oMtx.Columns.Item("cAltQty").Cells.Item(i).Specific.Value;
                                            oProd.Lines.PlannedQuantity = Convert.ToDouble(altQty.Replace(".", ","));

                                            int retCode = oProd.Update();
                                            if (retCode == 0)
                                            {
                                                compLog.SetProperty("Code", GetLogCode());
                                                compLog.SetProperty("U_SOL_DOCNUM", oMtx.Columns.Item("cNoWo").Cells.Item(i).Specific.Value);
                                                compLog.SetProperty("U_SOL_RPLDATE", DateTime.Now.Date);
                                                compLog.SetProperty("U_SOL_ITEMCODE", oForm.Items.Item("tComItmCd").Specific.Value);
                                                compLog.SetProperty("U_SOL_ITEMNAME", oForm.Items.Item("tComItmNm").Specific.Value);
                                                compLog.SetProperty("U_SOL_ITMCODE", oForm.Items.Item("tAltItmCd").Specific.Value);
                                                compLog.SetProperty("U_SOL_ITMNAME", oForm.Items.Item("tAltItmNm").Specific.Value);
                                                compLog.SetProperty("U_SOL_COMPQTY", oMtx.Columns.Item("cComQty").Cells.Item(i).Specific.Value);
                                                compLog.SetProperty("U_SOL_ALTQTY", oMtx.Columns.Item("cAltQty").Cells.Item(i).Specific.Value);

                                                oGenService.Add(compLog);
                                                if (oSBOCompany.InTransaction)
                                                {
                                                    oSBOCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                                                }
                                            }
                                            else
                                            {
                                                throw new Exception();
                                            }
                                            break;
                                        }
                                        else
                                        {
                                            oProd.Lines.SetCurrentLine(j + 1);
                                        }
                                    }
                                }

                                progress          += 1;
                                oProgressBar.Value = progress;
                            }

                            oSBOApplication.StatusBar.SetText("Success change component item.", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
                        }
                        catch (Exception ex)
                        {
                            bubbleEvent = false;
                            oSBOApplication.MessageBox(ex.Message);
                            oSBOCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                        }
                        finally
                        {
                            TemplateLoad(ref oForm);
                            oProgressBar.Stop();
                            if (oForm != null)
                            {
                                oForm.Freeze(false);
                            }
                        }
                    }
                }
            }
        }
        public bool InsertMonitoring(MonitoringEntity monitoring)
        {
            bool success = false;

            try
            {
                oCompService = oCompany.GetCompanyService();
                oCompany.StartTransaction();
                oGeneralService = oCompService.GetGeneralService("UD_INT_MONITORING");

                oGeneralData = (SAPbobsCOM.GeneralData)oGeneralService.GetDataInterface(GeneralServiceDataInterfaces.gsGeneralData);

                oGeneralData.SetProperty("Code", monitoring.DocCode);

                oGeneralData.SetProperty("U_SketchInv", monitoring.Sketch_Invoice);

                oGeneralData.SetProperty("U_DocDate", DateTime.Now.ToString("yyyyMMdd"));

                oGeneralData.SetProperty("U_DocTotal", monitoring.DocTot);

                if (monitoring.BL != null)
                {
                    oGeneralData.SetProperty("U_Bl", monitoring.BL);
                }

                if (monitoring.BLId != null)
                {
                    oGeneralData.SetProperty("U_BlId", monitoring.BLId);
                }

                if (monitoring.Draft != null)
                {
                    oGeneralData.SetProperty("U_Draft", monitoring.Draft);
                }

                if (monitoring.Branch != null)
                {
                    oGeneralData.SetProperty("U_Branch", monitoring.Branch);
                }

                if (monitoring.BranchId != null)
                {
                    oGeneralData.SetProperty("U_BranchId", monitoring.BranchId);
                }

                oGeneralData.SetProperty("U_StatusId", monitoring.StatusId);
                oGeneralData.SetProperty("U_Status", monitoring.Status);

                oGeneralData.SetProperty("U_XMLPath", monitoring.XMLPath);
                oGeneralData.SetProperty("U_Message", monitoring.Message);

                oGeneralService.Add(oGeneralData);
            }
            catch (Exception e)
            {
                if (oCompany.InTransaction)
                {
                    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                }

                LogDAL _log = new LogDAL();
                _log.WriteEntry("InsertMonitoring error: " + e.Message);

                throw e;
            }
            if (oCompany.InTransaction)
            {
                oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
            }
            return(success);
        }