예제 #1
0
 private void AddNewIdentityNoInfo(IdentityNoInfo identityNoInfo)
 {
     string cmdText = "INSERT INTO tuge_identitynoinfo(RecordID, Type, IdentityNo, LastReadDate, TenantCode) values(@RecordID, @Type, @IdentityNo, @LastReadDate, @TenantCode)";
     MySqlParameter[] paras = new MySqlParameter[] {
         new MySqlParameter("RecordID", identityNoInfo.RecordID),
         new MySqlParameter("Type", identityNoInfo.Type),
         new MySqlParameter("IdentityNo", identityNoInfo.IdentityNo),
         new MySqlParameter("LastReadDate", identityNoInfo.LastReadDate),
         new MySqlParameter("TenantCode", identityNoInfo.TenantCode)
     };
     try
     {
         MySqlDB.ExecuteNonQuery(CommandType.Text, cmdText, paras);
     }
     catch(Exception ex)
     {
         Logger.Error("IdentityNoService.AddNewIdentityNoInfo(IdentityNoInfo identityNoInfo):" + ex.StackTrace + "【" + ex.Message + "】", ex);
     }
 }
예제 #2
0
 private void UpdateIndetityNo(IdentityNoInfo identityNoInfo)
 {
     string cmdText = "UPDATE tuge_identitynoinfo SET Type=@Type, IdentityNo=@IdentityNo, LastReadDate=@LastReadDate, TenantCode=@TenantCode WHERE RecordID = @RecordID";
     MySqlParameter[] paras = new MySqlParameter[] {
         new MySqlParameter("RecordID", identityNoInfo.RecordID),
         new MySqlParameter("Type", identityNoInfo.Type),
         new MySqlParameter("IdentityNo", identityNoInfo.IdentityNo),
         new MySqlParameter("LastReadDate", identityNoInfo.LastReadDate),
         new MySqlParameter("TenantCode", identityNoInfo.TenantCode)
     };
     try
     {
         MySqlDB.ExecuteNonQuery(CommandType.Text, cmdText, paras);
     }
     catch (Exception ex)
     {
         Logger.Error("IdentityNoService.UpdateIndetityNo(IdentityNoInfo identityNoInfo):" + ex.StackTrace + "【" + ex.Message + "】", ex);
     }
 }
예제 #3
0
        private double GetSerialNo(int type)
        {
            List<IdentityNoInfo> ltIdentityNoInfo = null;
            string cmdText = string.Format("SELECT RecordID, Type, IdentityNo, LastReadDate, TenantCode FROM tuge_identitynoinfo WHERE Type={0}", type);
            using (MySqlDataReader sdr = MySqlDB.GetDataReader(CommandType.Text, cmdText))
            {
                if (sdr != null)
                {
                    ltIdentityNoInfo = new List<IdentityNoInfo>();
                    while (sdr.Read())
                    {
                        ltIdentityNoInfo.Add(new IdentityNoInfo
                        {
                            RecordID = sdr.GetGuidExt(0),
                            Type = sdr.GetDoubleNull(1),
                            IdentityNo = sdr.GetDoubleExt(2),
                            LastReadDate = sdr.GetDateTimeNull(3),
                            TenantCode = sdr.GetStringExt(4)
                        });
                    }
                    sdr.Close();
                }
            }

            IdentityNoInfo identityNoInfo = null;
            if (ltIdentityNoInfo.IsEmpty())
            {
                identityNoInfo = new IdentityNoInfo();
                identityNoInfo.RecordID = Guid.NewGuid();
                identityNoInfo.IdentityNo = 1;
                identityNoInfo.Type = type;
                identityNoInfo.LastReadDate = DateTime.Now;

                AddNewIdentityNoInfo(identityNoInfo);
            }
            else
            {
                if (ltIdentityNoInfo.Count > 1)
                {
                    throw new Exception("一个类型的流水号只能有一条记录,请查询数据表数据确认数据是否出现错误!");
                }
                identityNoInfo = ltIdentityNoInfo[0];
            }

            IdentityNoInfo updateIdentityNoInfo = identityNoInfo;

            DateTime lastReadDate = updateIdentityNoInfo.LastReadDate.Value;
            TimeSpan differenceDay = DateTime.Now.Date - lastReadDate.Date;

            if (differenceDay.Days == 0)
            {
                updateIdentityNoInfo.IdentityNo++;
            }
            else
            {
                updateIdentityNoInfo.IdentityNo = 1;
            }

            updateIdentityNoInfo.LastReadDate = DateTime.Now;
            UpdateIndetityNo(updateIdentityNoInfo);

            return updateIdentityNoInfo.IdentityNo;
        }