⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 global.pas

📁 是分布式粮库程序,是采用Delphi实现的
💻 PAS
字号:
unit Global;

interface

uses SysUtils,Messages,DB,Controls,Forms,Windows;

type
  Tuser = record//系统登陆用户
    UserID : string;  //
    UserName : string;//登陆用户名
    UserRole : string;//角色
    PassWord : string;//密码
    UserMemo : string;//描述
    sName:string;
    UnitID: Integer;   //所属的分公司编号
    UnitName: string; //所属的分公司
    USER_CODE:integer;//
  end;

function ChkInptYMTime(DT : string):boolean;
procedure DateFieldGetText(Sender: TField;  Text: String);
function DateFieldSetText(Sender: TField;  Text: String):Boolean;

var
  g_user : Tuser;

implementation


procedure DateFieldGetText(Sender: TField;  Text: String);

var 
  dDate:TDate;
  wYear,wMonth,wDay:Word;
  aryTestYMD:Array [1..2] of Char;{测试输入掩码用临时数组}
  iYMD:Integer;
begin
  dDate:=Sender.AsDateTime;
  if dDate<>0 then
  begin
    DecodeDate(dDate,wYear,wMonth,wDay);
    {测试输入掩码所包含的格式.}
    aryTestYMD:='年';
    if StrScan(PChar(Sender.EditMask) ,aryTestYMD[1])<>nil then
    iYMD:=1;
    aryTestYMD:='月';
    if StrScan(PChar(Sender.EditMask),aryTestYMD[1])<>nil then
    iYMD:=2;
    aryTestYMD:='日';
    if StrScan(PChar(Sender.EditMask),aryTestYMD[1])<>nil then
    iYMD:=3;
    case iYMD of
      1:{输入掩码为:”yyyy年”的格式.}
      Text:=IntToStr(wYear)+'年';
      2: {输入掩码为:”yyyy年mm月”的格式.}
      Text:=IntToStr(wYear)+'年'+IntToStr(wMonth)+'月';
      3: {输入掩码为:”yyyy年mm月dd日”的格式.}
      Text:=IntToStr(wYear)+'年'+IntToStr(wMonth)+'月'+IntToStr(wDay)+'日';
    else {默认为:”yyyy年mm月dd日”的格式.}
      Text:=IntToStr(wYear)+'年'+IntToStr(wMonth)+'月'+IntToStr(wDay)+'日';
    end;
  end;
end;


function DateFieldSetText(Sender: TField; Text: String):Boolean;
var
  dDate:TDate;
  sYear,sMonth,sDay:String;
  aryTestYMD:Array [1..2] of Char;
  iYMD:Integer;
begin {获得用户输入的日期}
  sYear:=Copy(Text,1,4);
  sMonth:=Copy(Text,7,2);
  SDay:=Copy(Text,11,2);
  if ((sYear='    ') and (sMonth='  ')) and (Sday='  ') then
  begin
    Sender.AsDateTime:=0;
    DateFieldSetText:=True;
    exit;
  end;
{测试输入掩码所包含的格式.}
  aryTestYMD:='年';
  if StrScan(PChar(Sender.EditMask),aryTestYMD[1])<>nil then
  iYMD:=1;
  aryTestYMD:='月';
  if StrScan(PChar(Sender.EditMask),  aryTestYMD[1])<>nil then
  iYMD:=2;
  aryTestYMD:='日';
  if StrScan(PChar(Sender.EditMask),  aryTestYMD[1])<>nil then
  iYMD:=3;
  {利用Try…Except进行输入的日期转换}
  try
   begin
     if (strtoint(syear)<=1900) or (strtoint(syear)>=2050) then
     begin
       Application.MessageBox(PChar(Text+'不是有效的日期!'),'错误',mb_Ok+mb_IconError);
       DateFieldSetText:=False;
       exit;
     end;
     case iYMD of
     1: {输入掩码为:”yyyy年”的格式.}
     begin
       dDate:=StrToDate(sYear+'-01-01');{中文Windows默认的日期格式为:yyyy-mm-dd.下同}
       Sender.AsDateTime:=dDate;
     end;
     2: {输入掩码为:”yyyy年mm月”的格式.}
     begin
       dDate:=StrToDate(sYear+'-'+sMonth+'-01');
       Sender.AsDateTime:=dDate;
     end;
     3: {输入掩码为:”yyyy年mm月dd日”的格式.}
     begin
       dDate:=StrToDate(sYear+'-'+sMonth+'-'+sDay);
       Sender.AsDateTime:=dDate;
     end;
     else {默认为:”yyyy年mm月dd日”的格式.}
       begin
         dDate:=StrToDate(sYear+'-'+sMonth+'-'+sDay);
         Sender.AsDateTime:=dDate;
       end;
     end;
    DateFieldSetText:=True;
  end;
  except
   {日期转换出错}
    begin
      Application.MessageBox(PChar(Text+'不是有效的日期!'),'错误',mb_Ok+mb_IconError);
      DateFieldSetText:=False;
    end;
  end;
end;


function ChkInptYMTime(DT : string):boolean;
var
  S:array [0..10] of char;
  str:string;
begin
  StrPCopy(S,DT);
  if (s[0]=' ')and(s[1]=' ')and(s[2]=' ')and(s[3]=' ')and(s[5]=' ')and(s[6]=' ')and(s[8]=' ')and(s[9]=' ') then
    result:= true
  else
    begin
    try
      StrToDate(DT);
      Result := true;
    Except
      result := false;
    end;
    end;
end;

end.
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -