• 不同机器不重复编号、流水号生成


    在添加记录insert前判断是否流水号重复,表中要建立macdizhi字段存储mac地址,参看健鹏软件

    设计思路:

    01     02      03(机器号)

    25     25      25(流水号)

    当几台机器获取流水号相同时,要判断数据库中是否有25的流水号

                           判断第一条记录是不是该机器添加的

    有记录时----      如果是  ->  流水号不变

                           如不是  ->  选记录数最大流水号,改变当前流水号并赋值

    无记录  ---- 直接添加

            //查看流水号,避免不同计算机流水号输入重复,只限单机只开一个客户端
            with    ADOQuery_temp   do
            begin
                    Close;
                    SQL.Clear;
                    SQL.Add('select liushuihao from Y_liushui where liushuihao=:liushuihao and caozuobiaoshi=''药品销售''');
                    Parameters.ParamByName('liushuihao').Value:=Trim(Edit_liushuihao.Text);
                    Open;
            end;

            if      ADOQuery_temp.RecordCount>0   then
            begin
                    //判断记录是不是该机器录的,如果是,流水号不变,如不是要再选出最大流水号并赋值
                    with    ADOQuery_temp   do
                    begin
                            Close;
                            SQL.Clear;
                            SQL.Add('select liushuihao from Y_liushui where liushuihao=:liushuihao and macdizhi=:macdizhi and caozuobiaoshi=''药品销售''');
                            Parameters.ParamByName('liushuihao').Value:=Trim(Edit_liushuihao.Text);
                            Parameters.ParamByName('macdizhi').Value:=Trim(Frm_Login.GetMacAddress);
                            Open;
                    end;
                    //如不是自己机器录的,选最大流水号赋值
                    if    ADOQuery_temp.RecordCount=0   then
                    begin
                          with    ADOQuery_liushuihaocx   do
                          begin
                                  Close;
                                  SQL.Clear;
                                  SQL.Add('select isnull(max(liushuihao),0) as liushuihao from Y_liushui where caozuobiaoshi=''药品销售''');
                                  Open;
                          end;
                          if      (ADOQuery_liushuihaocx.FieldValues['liushuihao']=null) or (ADOQuery_liushuihaocx.FieldValues['liushuihao']=0)   then
                          begin
                                  Edit_liushuihao.Text:='1';
                          end
                          else
                          begin
                                  Edit_liushuihao.Text:=IntToStr(ADOQuery_liushuihaocx.FieldValues['liushuihao']+1);
                          end;
                    end;
            end;

    //获取计算机Mac地址函数

    function TFrm_Login.GetMacAddress: string;
    var
       Lib: Cardinal;
       Func: function(GUID: PGUID): Longint; stdcall;
       GUID1, GUID2: TGUID;
    begin
       Result := '';
       Lib := LoadLibrary('rpcrt4.dll');
       if Lib <> 0 then
       begin
         if Win32Platform <>VER_PLATFORM_WIN32_NT then
           @Func := GetProcAddress(Lib, 'UuidCreate')
           else @Func := GetProcAddress(Lib, 'UuidCreateSequential');
         if Assigned(Func) then
         begin
           if (Func(@GUID1) = 0) and
             (Func(@GUID2) = 0) and
             (GUID1.D4[2] = GUID2.D4[2]) and
             (GUID1.D4[3] = GUID2.D4[3]) and
             (GUID1.D4[4] = GUID2.D4[4]) and
             (GUID1.D4[5] = GUID2.D4[5]) and
             (GUID1.D4[6] = GUID2.D4[6]) and
             (GUID1.D4[7] = GUID2.D4[7]) then
           begin
             Result :=
              IntToHex(GUID1.D4[2], 2) +'-'+
              IntToHex(GUID1.D4[3], 2) +'-'+
              IntToHex(GUID1.D4[4], 2) +'-'+
              IntToHex(GUID1.D4[5], 2) +'-'+
              IntToHex(GUID1.D4[6], 2) +'-'+
              IntToHex(GUID1.D4[7], 2);
           end;
         end;
         FreeLibrary(Lib);
       end;
    end;

  • 相关阅读:
    PLSQL Developer连接Oracle11g 64位数据库配置详解
    PL/SQL developer 登录时提示:database character set(AL32UTF8) and Client character set(ZHS16GBK) are different
    例题P101
    疑问
    基本概念
    参数及术语
    使用python 3.x 对pythonchallenge-----17的解答过程
    使用python3 解析html对称标签
    使用python 3.x 对pythonchallenge-----16的解答过程
    使用python 3.x 对pythonchallenge-----15的解答过程
  • 原文地址:https://www.cnblogs.com/lantianhf/p/5069528.html
Copyright © 2020-2023  润新知