使用GUID生成帐单号 [英] Generating billnumber using GUID

查看:97
本文介绍了使用GUID生成帐单号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

请通过此功能告诉我,这是生成GUID的正确方法吗?

 私有 功能 billnumber() As  整数
         Dim  num  As   String  = System.Guid .NewGuid().ToString
         Dim  charCount  As  整数 =  0 
        对于 每个 c  As  字符 如果 字符.IsDigit(c)然后
                billnum + = c.ToString()
                charCount + =  1 

            结束 如果
            如果 charCount =  6  >然后
                退出 用于
            结束 如果
        下一步
        返回 Billnum
    结束 功能 


如果我错了,请指出.

解决方案

您可以将guid转换为两个ulong数字:

向导g = Guid.NewGuid();
字节 [] b = g.ToByteArray();
 UInt64  u1 = BitConverter.ToUInt64(b, 0 );
 UInt64  u2 = BitConverter.ToUInt64(b, 8 );
MessageBox.Show(u1.ToString()+ u2.ToString()); 


但是那些帐单号是巨大的,没有排序...尝试简单地递增并记住您的电话号.


Dim numGuid As Guid = System.Guid.NewGuid();



现在,这在您的代码中看起来还可以.但是之后您需要做的事情是需要解释和查看的.看来您只是在尝试从生成的GUID中选择数字,并将其分配为帐单号.如果您这样做的目的是始终拥有唯一的帐单号,那么我很抱歉这么说,此实现/方法不正确.

整体引导(带有数字和字符串的组合)是唯一的.是的,我想要一个唯一的号码,我想用作账单号码...


Hi friends,

Please go through this function and tell me, is this the right way to generate a guid?

Private Function billnumber() As Integer
        Dim num As String = System.Guid.NewGuid().ToString
        Dim charCount As Integer = 0
        For Each c As Char In num
            If Char.IsDigit(c) Then
                billnum += c.ToString()
                charCount += 1

            End If
            If charCount = 6 Then
                Exit For
            End If
        Next
        Return billnum
    End Function


Please point out if I am wrong.

You can translate guid into two ulong numbers:

Guid g = Guid.NewGuid();
Byte[] b = g.ToByteArray();
UInt64 u1= BitConverter.ToUInt64(b,0);
UInt64 u2 = BitConverter.ToUInt64(b, 8);
MessageBox.Show(u1.ToString() + u2.ToString());


But those bill numbers are giant and not sorted ... try simply increment and remember your numbers.


As far as creation of GUID[^] goes, its just:

Dim numGuid As Guid = System.Guid.NewGuid();



Now, this looks ok in your code. But what you have done after that is something you need to explain and look at. It looks like you are just trying to pick numbers from the generated GUID and assign that as bill number. If your intention of doing this was to have a unique bill number always then I am sorry to say so, this implementation/approach is incorrect.

Guid as a whole (with combination of number & string) is unique. Picking only numbers from it will not assure uniqueness.


Yes i want a unquie number which i want to use as billnumber...


这篇关于使用GUID生成帐单号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆