unit U_GetDllForm;

interface

uses
  Windows, Messages, forms, OleCtnrs, DateUtils, SysUtils, ADODB, IniFiles,
  dxCore, ActiveX;

function GetDllForm(App: Tapplication; FormH: hwnd; FormID: integer; Language: integer; WinStyle: integer; GCode: Pchar; GName: Pchar; DataBase: Pchar; Title: PChar; Parameters1: PChar; Parameters2: PChar; Parameters3: PChar; Parameters4: PChar; Parameters5: PChar; Parameters6: PChar; Parameters7: PChar; Parameters8: PChar; Parameters9: PChar; Parameters10: PChar; DataBaseStr: PChar): hwnd; export; stdcall;

function ConnData(): Boolean;

function GetsysParam(muserId: pchar; fparam1: pchar): Boolean;

implementation

uses
  U_DataLink, U_getDogServer, U_BpRklist, U_CPRklist, U_Bpcklist, U_Bpkclist,
  U_ZDYHelp, U_CPKWListSel, U_BpckXjList, U_Bpkclist_HZ, U_CpCklist;

       /////////////////////////////////////////////////////////////////
      //         功能说明:取Dll中得窗体                              //
     //        参数说明：App>>调用应用程序；                        //
    //                 FormH>>调用窗口句柄 ；                      //
   //                 FormID>>窗口号;                             //
  //                 Language>>语言种类;                         //
 //                 WinStyle>>窗口类型；                        //
/////////////////////////////////////////////////////////////////
function GetDllForm(App: Tapplication; FormH: hwnd; FormID: integer; Language: integer; WinStyle: integer; GCode: Pchar; GName: Pchar; DataBase: Pchar; Title: PChar; Parameters1: PChar; Parameters2: PChar; Parameters3: PChar; Parameters4: PChar; Parameters5: PChar; Parameters6: PChar; Parameters7: PChar; Parameters8: PChar; Parameters9: PChar; Parameters10: PChar; DataBaseStr: PChar): hwnd;
var
  mnewHandle: hwnd;
  mstyle: TFormStyle;     // 0:子窗口; 1：普通窗口
  mstate: TWindowState;
  mborderstyle: TFormBorderStyle;
begin
  mnewHandle := 0;
  DName := GName;
  DCode := GName;
  DdataBase := DataBase;
  DTitCaption := Title;
  DParameters1 := Parameters1;
  DParameters2 := Parameters2;
  DParameters3 := Parameters3;
  DParameters4 := Parameters4;
  DParameters5 := Parameters5;
  DParameters6 := Parameters6;
  DParameters7 := Parameters7;
  DParameters8 := Parameters8;
  DParameters9 := Parameters9;
  DParameters10 := Parameters10;

  MainApplication := App;
  DCurHandle := FormH;
  IsDelphiLanguage := Language;

  Application := TApplication(App);
  DCurHandle := 0;


   //赋值链接字符串
  SetLength(server, 255);
  SetLength(dtbase, 255);
  SetLength(user, 255);
  SetLength(pswd, 255);

  server := '139.224.12.182,7781';     // 122.224.36.142,7781
  dtbase := 'aidengdata'; //jinzhicaidata
  user := 'aidengsa';
  pswd := 'rightsoft@3203';
  DConString := 'Provider=SQLOLEDB.1;Password=' + pswd + ';Persist Security Info=True;User ID=' + user + ';Initial Catalog=' + dtbase + ';Data Source=' + server;
  if trim(DataBaseStr) <> '' then
  begin
    DConString := DataBaseStr;

  end;
  Parameters1 := '成品仓库';

 //  if GetLinkDog(DCurHandle,DConString)<0 then application.Terminate;
  if not ConnData() then
  begin
    result := 0;
    exit;
  end;
  GetsysParam('', '');
   // 定义窗口类型 、状态
  if WinStyle = 0 then
  begin
    mstyle := fsMDIChild;
    mstate := wsMaximized;
    mborderstyle := bsSizeable;
  end
  else
  begin
    mstyle := fsNormal;
    mstate := wsNormal;
    mborderstyle := bsSizeable;
  end;
  /////////////////////
  //调用子模块窗口
  case FormID of
    -1:     //仓库
      begin
        frmZDYHelp := TfrmZDYHelp.Create(Application);
        with frmZDYHelp do
        begin
          flag := 'CPCK';
          flagname := '名称';
          if ShowModal = 1 then
          begin

          end;
          free;
        end;
      end;
    -2:         //入库类型
      begin
        frmZDYHelp := TfrmZDYHelp.Create(Application);
        with frmZDYHelp do
        begin
          flag := 'CPRKTYPE';
          flagname := '名称';
          fnote := true;
          if ShowModal = 1 then
          begin

          end;
          free;
        end;
      end;
    -3:         //出库类型
      begin
        frmZDYHelp := TfrmZDYHelp.Create(Application);
        with frmZDYHelp do
        begin
          flag := 'CPCKTYPE';
          flagname := '名称';
          fnote := true;
          if ShowModal = 1 then
          begin

          end;
          free;
        end;
      end;
    102:  //成品入库(原本)
      begin
        if frmBpRklist = nil then
        begin
          frmBpRklist := TfrmBpRklist.Create(application.MainForm);
          with frmBpRklist do
          begin
            caption := Trim(Title);
            fCkName := trim(Parameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmBpRklist.BringToFront;
       //句柄
        mnewHandle := frmBpRklist.Handle;
      end;
    10:  //成品入库
      begin
        if frmCPRklist = nil then
        begin
          frmCPRklist := TfrmCPRklist.Create(application.MainForm);
          with frmCPRklist do
          begin
            caption := Trim(Title);
            fCkName := trim(Parameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCPRklist.BringToFront;
       //句柄
        mnewHandle := frmCPRklist.Handle;
      end;
    20:  //成品出库
      begin
        if frmCpCklist = nil then
        begin
          frmCpCklist := TfrmCpCklist.Create(application.MainForm);
          with frmCpCklist do
          begin
            caption := Trim(Title);
            fCkName := trim(Parameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCpCklist.BringToFront;
       //句柄
        mnewHandle := frmCpCklist.Handle;
      end;
    201:  //成品出库（原本）
      begin
        if frmBpCklist = nil then
        begin
          frmBpCklist := TfrmBpCklist.Create(application.MainForm);
          with frmBpCklist do
          begin
            caption := Trim(Title);
            fCkName := trim(Parameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmBpCklist.BringToFront;
       //句柄
        mnewHandle := frmBpCklist.Handle;
      end;
    21:  //成品出库
      begin
        if frmBpckXjList = nil then
        begin
          frmBpckXjList := TfrmBpckXjList.Create(application.MainForm);
          with frmBpckXjList do
          begin
            caption := Trim(Title);
            fCkName := trim(Parameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmBpckXjList.BringToFront;
       //句柄
        mnewHandle := frmBpckXjList.Handle;
      end;
    30:  //成品库存
      begin
        if frmBpkclist = nil then
        begin
          frmBpkclist := TfrmBpkclist.Create(application.MainForm);
          with frmBpkclist do
          begin
            caption := Trim(Title);
            fCkName := trim(Parameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmBpkclist.BringToFront;
       //句柄
        mnewHandle := frmBpkclist.Handle;
      end;
    31:  //成品库存
      begin
        if frmBpkclist_HZ = nil then
        begin
          frmBpkclist_HZ := TfrmBpkclist_HZ.Create(application.MainForm);
          with frmBpkclist_HZ do
          begin
            caption := Trim(Title);
            fCkName := trim(Parameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmBpkclist_HZ.BringToFront;
       //句柄
        mnewHandle := frmBpkclist_HZ.Handle;
      end;

  end;  // end case

  Result := mnewHandle;
//  NewDllApp := Application;
end;
//===========================================================
  //建立数据库连接池
//===========================================================

function ConnData(): Boolean;
var
  IniFile: TIniFile;
begin
  try
    IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'SYSTEMSET.INI');
    server := IniFile.ReadString('SERVER', '服务器地址', '127.0.0.1');
  finally
    IniFile.Free;
  end;
  if not Assigned(CPCK_DataLink) then
    CPCK_DataLink := TCPCK_DataLink.Create(Application);
  try
    with CPCK_DataLink.ADOLink do
    begin
      if not Connected then
      begin
        Connected := false;
        ConnectionString := DConString;
        LoginPrompt := false;
        Connected := true;
       // BaseData10_DataLink.Timer1.Enabled:=true;
      end;
    end;
    Result := true;
  except
    Result := false;
    application.MessageBox('数据库连接失败！', '错误', mb_Ok + MB_ICONERROR);
  end;

end;
//=========================================================
  //获取系统参数
//=========================================================

function GetsysParam(muserId: pchar; fparam1: pchar): Boolean;
begin
  result := true;
  //////////////////////////////
  shortDateFormat := 'yyyy-MM-dd';
  //服务器日期
  with CPCK_DataLink.AdoDataLink do
  begin
    close;
    sql.Clear;
    sql.Add('select getDate()as dt');
    open;
    DServerDate := fieldByName('dt').AsDatetime;
  end;
  result := true;
end;

initialization
  CoInitialize(nil);
  dxUnitsLoader.Initialize;


finalization
  CPCK_DataLink.Free;
  application := NewDllApp;
  dxUnitsLoader.Finalize;

end.

