private static void ValidateDecimal(string pFieldName, object pValue, OperationResult pOperationResult)
        {
            decimal lResult;

            if (!Decimal.TryParse(pValue.ToString(), out lResult))
            {
                pOperationResult.InvalidField(pFieldName, "Invalid", pValue);
            }
        }
        private static void ValidateDate(string pFieldName, object pValue, OperationResult pOperationResult)
        {
            DateTime lResult;

            if (pValue.GetType() == typeof(DateTime)) return;

            if (!DateTime.TryParse(pValue.ToString(), out lResult))
            {
                pOperationResult.InvalidField(pFieldName, "Invalid", pValue);
            }
        }
        public static decimal GetNext(Transaction pTransaction, string pIDFieldValue)
        {
            decimal lID;

            // Inicializa operação
            OperationResult lReturn = new OperationResult(QueryDictionaries.SequencesQD.TableName, QueryDictionaries.SequencesQD.TableName);

            // Recupera Valor
            SelectCommand lSelectNext;

            string lSelectQuery = QueryDictionaries.SequencesQD.qSequencesMax;
            lSelectQuery += String.Format("WHERE {0} = >>{0}", QueryDictionaries.SequencesQD._SEQ_NAME.Name);

            object lScalarReturn;

            lSelectNext = new SelectCommand(lSelectQuery);

            // Passagem dos Valores de Parametros para a Clausula WHERE [comando SELECT]
            lSelectNext.Fields.Add(QueryDictionaries.SequencesQD._SEQ_NAME.Name, pIDFieldValue, ItemType.String);

            // Recupera Valor do Select (Seq_Value)
            lScalarReturn = lSelectNext.ReturnScalar(pTransaction);

            if (lScalarReturn == null || lScalarReturn == DBNull.Value) lScalarReturn = 1;
            lID = Convert.ToDecimal(lScalarReturn);

            // Altera Valor da Sequence
            UpdateCommand lUpdate;
            lUpdate = new UpdateCommand(QueryDictionaries.SequencesQD.TableName);

            // Identificação dos Campos a serem Alterados
            lUpdate.Fields.Add(QueryDictionaries.SequencesQD._SEQ_VALUE.Name, lID, (ItemType) QueryDictionaries.SequencesQD._SEQ_VALUE.DBType);

            string lUpdateQuery;

            lUpdateQuery = String.Format("WHERE {0} = >>{0}", QueryDictionaries.SequencesQD._SEQ_NAME.Name);
            lUpdate.Condition = lUpdateQuery;

            // Passagem dos Valores para a Condição Where do Update
            lUpdate.Conditions.Add(QueryDictionaries.SequencesQD._SEQ_NAME.Name, pIDFieldValue);

            // Execução do UPDATE
            lUpdate.Execute(pTransaction);

            // Retorna novo valor da chave [SEQUENCE VALUE]
            return lID;
        }
 public static void ValidateRequired(DataField pField, DataFieldCollection pValues, OperationResult pOperationResult)
 {
     if (!pValues.ContainsKey(pField))
     {
         pOperationResult.InvalidField(pField.Name, "Required", null);
     }
     else
     {
         if (pValues[pField] == null)
         {
             pOperationResult.InvalidField(pField.Name, "Required", null);
         }
         else
         {
             if (pValues[pField].ToString() == "")
                 pOperationResult.InvalidField(pField.Name, "Required", null);
         }
     }
 }
        public static void ValidateConversion(DataFieldCollection pValues, OperationResult pOperationResult)
        {
            foreach (DataField lField in pValues.Keys)
            {
                switch (lField.DBType)
                {
                    case 0:

                        ValidateDecimal(lField.Name, pValues[lField], pOperationResult);

                        break;

                    case 2:

                        ValidateDate(lField.Name, pValues[lField], pOperationResult);

                        break;
                }
            }
        }
        public static OperationResult Insert(
           DataFieldCollection pValues,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(SystemUserQD.TableName, SystemUserQD.TableName);

            ValidateInsert(pValues, lReturn);

            if (!lReturn.HasError)
            {
                try
                {
                    if (lLocalTransaction)
                    {
                        lReturn.Trace("Transação local, instanciando banco...");
                    }

                    lInsert = new InsertCommand(SystemUserQD.TableName);

                    lReturn.Trace("Adicionando campos ao objeto de insert");

                    foreach (DataField lField in pValues.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }

                    decimal lSequence;

                    lSequence = DataBaseSequenceControl.GetNext(pInfo, "SUSR_ID");

                    lInsert.Fields.Add(SystemUserQD._SUSR_ID.Name, lSequence, (ItemType)SystemUserQD._SUSR_ID.DBType);

                    lReturn.Trace("Executando o Insert");

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lReturn.Trace("Insert finalizado, executando commit");

                                lTransaction.Commit();
                            }
                            else
                            {
                                lTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
        private static void ValidateUpdate(DataFieldCollection pValues, OperationResult pResult)
        {
            GenericDataObject.ValidateRequired(SystemUserQD._SUSR_ID, pValues, pResult);

            GenericDataObject.ValidateRequired(SystemUserQD._SUSR_REGDATE, pValues, pResult);

            GenericDataObject.ValidateRequired(SystemUserQD._SUSR_REGUSR, pValues, pResult);

            GenericDataObject.ValidateRequired(SystemUserQD._SUSR_STATUS, pValues, pResult);
        }
 private static void ValidateInsert(DataFieldCollection pValues, OperationResult pResult)
 {
     GenericDataObject.ValidateConversion(pValues, pResult);
 }
        public static OperationResult Update(
            DataFieldCollection pValues,
            ConnectionInfo pInfo
        )
        {
            Transaction pTransaction;

            pTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (pTransaction != null);

            UpdateCommand lUpdate;

            OperationResult lReturn = new OperationResult(SystemUserQD.TableName, SystemUserQD.TableName);

            ValidateUpdate(pValues, lReturn);

            if (lReturn.IsValid)
            {
                try
                {
                    if (lLocalTransaction)
                    {
                        lReturn.Trace("Transação local, instanciando banco...");
                    }

                    lUpdate = new UpdateCommand(SystemUserQD.TableName);

                    lReturn.Trace("Adicionando campos ao objeto de update");

                    foreach (DataField lField in pValues.Keys)
                    {
                        lUpdate.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }

                    string lSql = "";
                    lSql = String.Format("WHERE {0} = <<{0}", SystemUserQD._SUSR_ID.Name);

                    lUpdate.Condition = lSql;

                    lUpdate.Conditions.Add(SystemUserQD._SUSR_ID.Name, pValues[SystemUserQD._SUSR_ID].DBToDecimal());

                    lReturn.Trace("Executando o Update");

                    lUpdate.Execute(pTransaction);

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lReturn.Trace("Update finalizado, executando commit");

                                pTransaction.Commit();
                            }
                            else
                            {
                                pTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            pTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        pTransaction.Rollback();
                }
            }

            return lReturn;
        }
 private static void ValidateUpdate(DataFieldCollection pValues, OperationResult pResult)
 {
     GenericDataObject.ValidateRequired(TIPOMATERIAXNAAPQD._TPMN_ID, pValues, pResult);
     GenericDataObject.ValidateRequired(TIPOMATERIAXNAAPQD._TPMN_REGDATE, pValues, pResult);
     GenericDataObject.ValidateRequired(TIPOMATERIAXNAAPQD._TPMN_USUARIO, pValues, pResult);
     GenericDataObject.ValidateRequired(TIPOMATERIAXNAAPQD._TPMN_STATUS , pValues, pResult);
 }
        public static decimal GetNext(ConnectionInfo pInfo, string pIDFieldValue)
        {
            Transaction lTransaction;
            DataBase lDataBase;

            lDataBase = Instance.CreateDatabase(pInfo);

            lTransaction = new Transaction(lDataBase);
            try
            {
                decimal lID;

                // Inicializa operação
                OperationResult lReturn = new OperationResult(QueryDictionaries.SequencesControlQD.TableName, QueryDictionaries.SequencesControlQD.TableName);

                // Recupera Valor
                SelectCommand lSelectNext;

                string lSelectQuery = QueryDictionaries.SequencesControlQD.qSequencesControlMax;
                lSelectQuery += String.Format("WHERE {0} = >>{0}", QueryDictionaries.SequencesControlQD._CONTROLNAME.Name);

                object lScalarReturn;
                //APB.Framework.Math.Module11

                lSelectNext = new SelectCommand(lSelectQuery);

                // Passagem dos Valores de Parametros para a Clausula WHERE [comando SELECT]
                lSelectNext.Fields.Add(QueryDictionaries.SequencesControlQD._CONTROLNAME.Name, pIDFieldValue, ItemType.String);

                // Recupera Valor do Select (Seq_Value)
                lScalarReturn = lSelectNext.ReturnScalar(lTransaction);

                if (lScalarReturn == null || lScalarReturn == DBNull.Value) lScalarReturn = 1;
                lID = Convert.ToDecimal(lScalarReturn);

                // Altera Valor da Sequence
                UpdateCommand lUpdate;
                lUpdate = new UpdateCommand(QueryDictionaries.SequencesControlQD.TableName);

                // Identificação dos Campos a serem Alterados
                lUpdate.Fields.Add(QueryDictionaries.SequencesControlQD._CONTROLVALUE.Name, lID, (ItemType)QueryDictionaries.SequencesControlQD._CONTROLVALUE.DBType);

                string lUpdateQuery;

                lUpdateQuery = String.Format("WHERE {0} = >>{0}", QueryDictionaries.SequencesControlQD._CONTROLNAME.Name);
                lUpdate.Condition = lUpdateQuery;

                // Passagem dos Valores para a Condição Where do Update
                lUpdate.Conditions.Add(QueryDictionaries.SequencesControlQD._CONTROLNAME.Name, pIDFieldValue);

                // Execução do UPDATE
                lUpdate.Execute(lTransaction);

                lTransaction.Commit();
                // Retorna novo valor da chave [CONTROL VALUE]
                return lID;
            }
            catch (Exception ex)
            {
                lTransaction.Rollback();
                throw new UnknownException(ex);
            }
        }
 private static void ValidateUpdate(DataFieldCollection pValues, OperationResult pResult)
 {
     GenericDataObject.ValidateRequired(ModeloPeticaoQD._MDPT_ID, pValues, pResult);
     GenericDataObject.ValidateRequired(ModeloPeticaoQD._MDPT_REGDATE, pValues, pResult);
     GenericDataObject.ValidateRequired(ModeloPeticaoQD._MDPT_REGUSER, pValues, pResult);
     GenericDataObject.ValidateRequired(ModeloPeticaoQD._MDPT_STATUS, pValues, pResult);
 }