public void insertSequence(DBConnection_EF conn, ASEQUENCE seq)
 {
     try
     {
         conn.ASEQUENCE.Add(seq);
         conn.SaveChanges();
     }
     catch (Exception ex)
     {
         logger.Warn(ex);
     }
 }
Exemple #2
0
 /// <summary>
 /// 取得Command ID Sequence(由手動方式所產生的Command ID 流水號)
 /// </summary>
 /// <returns></returns>
 public long getCommandID_Manual_Number()
 {
     lock (SCAppConstants.SEQUENCE_NAME_COMMANDID_MANUAL)
     {
         long seqVal = 0;
         try
         {
             using (TransactionScope tx = new TransactionScope
                                              (TransactionScopeOption.Suppress))
             {
                 //using (DBConnection_EF con = new DBConnection_EF())
                 using (DBConnection_EF con = DBConnection_EF.GetUContext())
                 {
                     ASEQUENCE seq = seqDao.getSequence(con, SCAppConstants.SEQUENCE_NAME_COMMANDID_MANUAL);
                     if (seq == null)
                     {
                         seqVal = SCAppConstants.COMMANDID_MANUAL_NUMBER_MIN;
                         seq    = new ASEQUENCE()
                         {
                             SEQ_NAME = SCAppConstants.SEQUENCE_NAME_COMMANDID_MANUAL,
                             NXT_VAL  = seqVal + 1
                         };
                         seqDao.insertSequence(con, seq);
                     }
                     else
                     {
                         seqVal = seq.NXT_VAL;
                         if (seqVal >= SCAppConstants.COMMANDID_MANUAL_NUMBER_MAX)
                         {
                             seq.NXT_VAL = SCAppConstants.COMMANDID_MANUAL_NUMBER_MIN;
                         }
                         else
                         {
                             seq.NXT_VAL = seqVal + 1;
                         }
                         seqDao.updateSequence(con, seq);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             logger.Error(ex, "Exception");
             return(seqVal);
         }
         finally
         {
         }
         return(seqVal);
     }
 }
 /// <summary>
 /// Updates the sequence.
 /// </summary>
 /// <param name="conn">The connection.</param>
 /// <param name="seq">The seq.</param>
 public void updateSequence(DBConnection_EF conn, ASEQUENCE seq)
 {
     try
     {
         //bool isDetached = conn.Entry(seq).State == EntityState.Modified;
         //if (isDetached)
         conn.SaveChanges();
         conn.Entry(seq).State = EntityState.Detached;
     }
     catch (Exception ex)
     {
         logger.Warn(ex);
     }
 }
        /// <summary>
        /// Gets the sequence.
        /// </summary>
        /// <param name="conn">The connection.</param>
        /// <param name="readLock">The read lock.</param>
        /// <param name="seq_name">The seq_name.</param>
        /// <returns>Sequence.</returns>
        public ASEQUENCE getSequence(DBConnection_EF conn, string seq_name)
        {
            ASEQUENCE rtnSeq = null;

            try
            {
                var query = from point in conn.ASEQUENCE
                            where point.SEQ_NAME == seq_name.Trim()
                            select point;
                return(query.FirstOrDefault());
            }
            catch (Exception ex)
            {
                logger.Warn(ex);
            }
            return(rtnSeq);
        }