예제 #1
0
파일: TableDAO.cs 프로젝트: xavl369/UGRS
        /// <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>
        /// <returns>
        /// An int.
        /// </returns>

        public int Update(T pObjRecord)
        {
            SAPbobsCOM.UserTable lObjUserTable = GetUserTable();

            try
            {
                if (lObjUserTable.GetByKey(pObjRecord.GetKey()))
                {
                    lObjUserTable = PopulateUserTable(lObjUserTable, pObjRecord);
                    return(lObjUserTable.Update());
                }
                else
                {
                    throw new TableException(string.Format("No existe el registro '{0}'.", pObjRecord.GetKey()));
                }
            }
            catch (Exception e)
            {
                throw new TableException(e.Message, e);
            }
            finally
            {
                MemoryUtility.ReleaseComObject(lObjUserTable);
            }
        }
예제 #2
0
파일: TableDAO.cs 프로젝트: xavl369/UGRS
        /// <summary>
        /// Populate user table.
        /// </summary>
        /// <remarks>
        /// Ranaya, 26/05/2017.
        /// </remarks>
        /// <param name="pObjUserTable">
        /// The object user table.
        /// </param>
        /// <param name="pObjRecord">
        /// The object record.
        /// </param>
        /// <returns>
        /// A SAPbobsCOM.UserTable.
        /// </returns>

        private SAPbobsCOM.UserTable PopulateUserTable(SAPbobsCOM.UserTable pObjUserTable, T pObjRecord)
        {
            if (!string.IsNullOrEmpty(pObjRecord.GetName()))
            {
                pObjUserTable.Name = pObjRecord.GetName();
            }

            foreach (PropertyInfo lObjProperty in pObjRecord.GetType().GetProperties().Where(x => x.GetMethod.IsPublic && !x.GetMethod.IsVirtual))
            {
                try
                {
                    string lStrFieldName  = string.Format("U_{0}", lObjProperty.Name);
                    Type   lObjFieldType  = lObjProperty.PropertyType;
                    object lUnkFieldValue = lObjFieldType == typeof(bool) ? ((bool)lObjProperty.GetValue(pObjRecord, null) ? "Y" : "N") : (lObjProperty.GetValue(pObjRecord, null));

                    pObjUserTable.UserFields.Fields.Item(lStrFieldName).Value = (lObjFieldType != typeof(DateTime) ? lUnkFieldValue.ToString() : lUnkFieldValue);
                }
                catch (Exception lObjException)
                {
                    //Ignore ;)
                    //LogUtility.Write(string.Format("[ERROR] {0}", lObjException.ToString()));
                }
            }

            return(pObjUserTable);
        }
예제 #3
0
파일: TableDAO.cs 프로젝트: xavl369/UGRS
        /// <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>
        /// <returns>
        /// An int.
        /// </returns>

        public int Add(T pObjRecord)
        {
            SAPbobsCOM.UserTable lObjUserTable = GetUserTable();

            try
            {
                lObjUserTable = PopulateUserTable(lObjUserTable, pObjRecord);
                return(lObjUserTable.Add());
            }
            catch (Exception e)
            {
                throw new TableException(e.Message, e);
            }
            finally
            {
                MemoryUtility.ReleaseComObject(lObjUserTable);
            }
        }
예제 #4
0
파일: TableDAO.cs 프로젝트: xavl369/UGRS
        /// <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>
        /// <returns>
        /// An int.
        /// </returns>

        public int Remove(string pStrCode)
        {
            SAPbobsCOM.UserTable lObjUserTable = GetUserTable();

            try
            {
                if (lObjUserTable.GetByKey(pStrCode))
                {
                    return(lObjUserTable.Remove());
                }
                else
                {
                    throw new TableException(string.Format("No existe el registro '{0}'.", pStrCode));
                }
            }
            catch (Exception e)
            {
                throw new TableException(e.Message, e);
            }
            finally
            {
                MemoryUtility.ReleaseComObject(lObjUserTable);
            }
        }