Esempio n. 1
0
 /// <summary>
 /// 生成自动编号
 /// </summary>
 /// <param name="prefix">自动生成编号的前缀</param>
 /// <param name="numberFormat">自动生成的编号中自增序列号的长度</param>
 /// <param name="type">自动编号的类型</param>
 /// <returns></returns>
 public string CreateID(string prefix, int serialLen, string type)
 {
     try
     {
         DataContext dc  = AttendanceDataContextFactory.Createattendance(ConnectStr);
         StringID    num = dc.GetTable <StringID>().SingleOrDefault(item => item.Prefix == prefix && item.Entity == type);
         if (num == null)
         {
             num = new StringID()
             {
                 Prefix = prefix,
                 Serial = 1,
                 Entity = type
             };
             dc.GetTable <StringID>().InsertOnSubmit(num);
         }
         else
         {
             num.Serial += 1;
         }
         dc.SubmitChanges();
         return(num.Prefix + num.Serial.ToString("D" + serialLen));
     }
     catch (Exception ex)
     {
         LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
     }
     return(null);
 }
Esempio n. 2
0
        public QueryResult <TInfo> GetByID(TID id)
        {
            QueryResult <TInfo> result = null;

            try
            {
                AttendanceDataContext attendance = AttendanceDataContextFactory.Createattendance(ConnectStr);
                TInfo info = GetingItemByID(id, attendance);
                if (info != null)
                {
                    result = new QueryResult <TInfo>(ResultCode.Successful, successMsg, info);
                }
                else
                {
                    result = new QueryResult <TInfo>(ResultCode.Fail, string.Empty, info);
                }
            }
            catch (SqlException ex)
            {
                result = new QueryResult <TInfo>(ResultCodeResolver.GetFromSqlExceptionNumber(ex.Number), ex.Message, null);
                ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "GetByID()");
            }
            catch (Exception ex)
            {
                result = new QueryResult <TInfo>(ResultCode.Fail, ex.Message, null);
                ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "GetByID()");
            }
            return(result);
        }
Esempio n. 3
0
 public void ResetID(string entity, long id)
 {
     try
     {
         AttendanceDataContext dc = AttendanceDataContextFactory.Createattendance(_ConnStr);
         IntegerID             ii = dc.GetTable <IntegerID>().SingleOrDefault(item => item.Entity == entity);
         if (ii == null)
         {
             ii = new IntegerID()
             {
                 Entity = entity, Value = id
             };
             dc.GetTable <IntegerID>().InsertOnSubmit(ii);
             dc.SubmitChanges();
         }
         else
         {
             ii.Value = id;
             dc.SubmitChanges();
         }
     }
     catch (Exception ex)
     {
         LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
     }
 }
Esempio n. 4
0
        public long?GetCurID(string entity)
        {
            long?id = null;
            AttendanceDataContext dc = AttendanceDataContextFactory.Createattendance(_ConnStr);
            IntegerID             ii = dc.GetTable <IntegerID>().SingleOrDefault(item => item.Entity == entity);

            if (ii != null)
            {
                id = ii.Value;
            }
            return(id);
        }
Esempio n. 5
0
        public CommandResult Insert(TInfo info)
        {
            CommandResult result;

            try
            {
                AttendanceDataContext attendance = AttendanceDataContextFactory.Createattendance(ConnectStr);
                InsertingItem(info, attendance);
                attendance.SubmitChanges();
                result = new CommandResult(ResultCode.Successful, successMsg);
            }
            catch (SqlException ex)
            {
                result = new CommandResult(ResultCodeResolver.GetFromSqlExceptionNumber(ex.Number), ex.Message);
                ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "Insert()");
            }
            catch (Exception ex)
            {
                result = new CommandResult(ResultCode.Fail, ex.Message);
                ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "Insert()");
            }
            return(result);
        }
Esempio n. 6
0
        public QueryResultList <TInfo> GetItems(SearchCondition search)
        {
            QueryResultList <TInfo> result;

            try
            {
                AttendanceDataContext attendance = AttendanceDataContextFactory.Createattendance(ConnectStr);
                List <TInfo>          infoes;
                infoes = GetingItems(attendance, search);
                result = new QueryResultList <TInfo>(ResultCode.Successful, successMsg, infoes);
            }
            catch (SqlException ex)
            {
                result = new QueryResultList <TInfo>(ResultCodeResolver.GetFromSqlExceptionNumber(ex.Number), ex.Message, new List <TInfo>());
                ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "GetItems()");
            }
            catch (Exception ex)
            {
                result = new QueryResultList <TInfo>(ResultCode.Fail, ex.Message, new List <TInfo>());
                ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "GetItems()");
            }
            return(result);
        }
Esempio n. 7
0
        public long?CreateID(string entity)
        {
            long?id = null;
            AttendanceDataContext dc = AttendanceDataContextFactory.Createattendance(_ConnStr);
            IntegerID             ii = dc.GetTable <IntegerID>().SingleOrDefault(item => item.Entity == entity);

            if (ii == null)
            {
                ii = new IntegerID()
                {
                    Entity = entity, Value = 2
                };
                dc.GetTable <IntegerID>().InsertOnSubmit(ii);
                dc.SubmitChanges();
                id = 1;
            }
            else
            {
                id        = ii.Value;
                ii.Value += 1;
                dc.SubmitChanges();
            }
            return(id);
        }
Esempio n. 8
0
 public UnitWork(string connStr)
 {
     _attendance = AttendanceDataContextFactory.Createattendance(connStr);
 }