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_Bpcklist, U_Bpckchklist, U_Bpkclist,
  U_ZDYHelp, U_Bpkcsumlist, U_ZdyAttachmentBJ, U_CYGGRklist, U_CYGGCklist,
  U_CYGGkcsumlist, U_ProductOrderLYList, U_YHCLLYList,U_KCHZBpkcsumlist;

       /////////////////////////////////////////////////////////////////
      //         功能说明:取Dll中得窗体                              //
     //        参数说明：App>>调用应用程序；                        //
    //                 FormH>>调用窗口句柄 ；                      //
   //                 FormID>>窗口号;                             //
  //                 Language>>语言种类;                         //
 //                 WinStyle>>窗口类型；                        //
/////////////////////////////////////////////////////////////////
var
  frmBpRklistLR, frmBpRklistGL: TfrmBpRklist;
  frmBpCklistCX, frmBpCklistGL: TfrmBpCklist;
  frmCYGGCklistCX, frmCYGGCklistGL: TfrmCYGGCklist;
//  frmBpkcsumlistCX, frmBpkcsumlist: TfrmBpkcsumlist;

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
  i: integer;
  bFound: Boolean;
  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 := '106.14.113.234,7781';
  dtbase := 'yunxiangdata';
  user := 'sa';
  pswd := 'rightsoft@123';
  DConString := 'Provider=SQLOLEDB.1;Password=' + pswd + ';Persist Security Info=True;User ID=' + user + ';Initial Catalog=' + dtbase + ';Data Source=' + server;
//  DConString := DataBaseStr;
  if trim(DataBaseStr) <> '' then
    DConString := DataBaseStr;
//DParameters1:='高权限';
//DParameters3:='1';
  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

    11:  //样品入库
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '样品入库' then
          begin
            BringWindowToTop(frmBpRklistLR.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmBpRklistLR := TfrmBpRklist.Create(application.MainForm);
          with frmBpRklistLR do
          begin
            caption := Trim(Title);
            fCkName := trim(Parameters1);
            canshu1 := '录入';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmBpRklistLR.BringToFront;
       //句柄
        mnewHandle := frmBpRklistLR.Handle;
      end;
    12:  //样品入库管理
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '样品入库管理' then
          begin
            BringWindowToTop(frmBpRklistGL.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmBpRklistGL := TfrmBpRklist.Create(application.MainForm);
          with frmBpRklistGL do
          begin
            caption := Trim(Title);
            fCkName := trim(Parameters1);
            canshu1 := '管理';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmBpRklistGL.BringToFront;
       //句柄
        mnewHandle := frmBpRklistGL.Handle;
      end;

    21:  //样品出库  //
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '样品出库' then
          begin
            BringWindowToTop(frmBpCklistCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmBpCklistCX := TfrmBpCklist.Create(application.MainForm);
          with frmBpCklistCX do
          begin
            Title := '样品出库';
            canshu1 := '录入';
            caption := Trim(Title);
            fCkName := trim(Parameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmBpCklistCX.BringToFront;
       //句柄
        mnewHandle := frmBpCklistCX.Handle;
      end;
    22:  //样品出库管理  //
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '样品仓库出库' then
          begin
            BringWindowToTop(frmBpCklistGL.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmBpCklistGL := TfrmBpCklist.Create(application.MainForm);
          with frmBpCklistGL do
          begin
            Title := '样品仓库出库';
            canshu1 := '管理';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmBpCklistGL.BringToFront;
       //句柄
        mnewHandle := frmBpCklistGL.Handle;
      end;
    31:  //样品库存
      begin
        if frmBpkcsumlist = nil then
        begin
          frmBpkcsumlist := TfrmBpkcsumlist.Create(application.MainForm);
          with frmBpkcsumlist do
          begin
            Title := '样品库存';
            caption := Trim(Title);
            fCkName := trim(Parameters1);
            canshu2 := trim(Parameters2);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;

           //show;
          end;
        end
        else
          frmBpkcsumlist.BringToFront;
       //句柄
        mnewHandle := frmBpkcsumlist.Handle;
      end;
    311:  //库存汇总
      begin
        if frmKCHZBpkcsumlist = nil then
        begin
          frmKCHZBpkcsumlist := TfrmKCHZBpkcsumlist.Create(application.MainForm);
          with frmKCHZBpkcsumlist do
          begin
            Title := '样品库存';
            caption := Trim(Title);
            fCkName := trim(Parameters1);
            canshu2 := trim(Parameters2);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;

           //show;
          end;
        end
        else
          frmKCHZBpkcsumlist.BringToFront;
       //句柄
        mnewHandle := frmKCHZBpkcsumlist.Handle;
      end;

//    32:  //样品库存汇总查询
//      begin
//        bFound := FALSE;
//        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
//        begin
//          if App.MainForm.MDIChildren[i].Caption = '样品库存汇总查询' then
//          begin
//            BringWindowToTop(frmBpkcsumlistCX.Handle);
//            bFound := TRUE;
//            Break;
//          end;
//        end;
//        if not bFound then
//        begin
//          frmBpkcsumlistCX := TfrmBpkcsumlist.Create(application.MainForm);
//          with frmBpkcsumlistCX do
//          begin
//            Title := '样品库存汇总查询';
//            canshu1 := '查询';
//            caption := Trim(Title);
//            FormStyle := mstyle;
//            windowState := mstate;
//            BorderStyle := mborderstyle;
//           //show;
//          end;
//        end
//        else
//          frmBpkcsumlistCX.BringToFront;
//       //句柄
//        mnewHandle := frmBpkcsumlistCX.Handle;
//      end;

    111:  //印花船样挂钩入库
      begin
        if frmCYGGRklist = nil then
        begin
          frmCYGGRklist := TfrmCYGGRklist.Create(application.MainForm);
          with frmCYGGRklist do
          begin
            caption := Trim(Title);
            fCkName := trim(Parameters1);
            canshu1 := trim(Parameters2);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCYGGRklist.BringToFront;
       //句柄
        mnewHandle := frmCYGGRklist.Handle;
      end;

    121:  //印花船样挂钩出库查询  //
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '印花船样挂钩出库查询' then
          begin
            BringWindowToTop(frmCYGGCklistCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmCYGGCklistCX := TfrmCYGGCklist.Create(application.MainForm);
          with frmCYGGCklistCX do
          begin
            Title := '印花船样挂钩出库查询';
            canshu1 := '查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCYGGCklistCX.BringToFront;
       //句柄
        mnewHandle := frmCYGGCklistCX.Handle;
      end;
    122:  //印花船样挂钩出库管理  //
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '印花船样挂钩仓库出库' then
          begin
            BringWindowToTop(frmCYGGCklistGL.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmCYGGCklistGL := TfrmCYGGCklist.Create(application.MainForm);
          with frmCYGGCklistGL do
          begin
            Title := '印花船样挂钩仓库出库';
            canshu1 := '管理';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCYGGCklistGL.BringToFront;
       //句柄
        mnewHandle := frmCYGGCklistGL.Handle;
      end;
    131:  //船样库存
      begin
        if frmCYGGkcsumlist = nil then
        begin
          frmCYGGkcsumlist := TfrmCYGGkcsumlist.Create(application.MainForm);
          with frmCYGGkcsumlist do
          begin

            caption := Trim(Title);
            fCkName := trim(Parameters1);
            canshu2 := trim(Parameters2);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;

           //show;
          end;
        end
        else
          frmCYGGkcsumlist.BringToFront;
       //句柄
        mnewHandle := frmCYGGkcsumlist.Handle;
      end;
    331:  //印花船样挂钩留样情况表
      begin
        if frmYHCLLYList = nil then
        begin
          frmYHCLLYList := TfrmYHCLLYList.Create(application.MainForm);
          with frmYHCLLYList do
          begin
            caption := Trim(Title);
            canshu1 := trim(Parameters2);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYHCLLYList.BringToFront;
       //句柄
        mnewHandle := frmYHCLLYList.Handle;
      end;
//    141:  //计划单留样
//      begin
//        if frmProductOrderLYList = nil then
//        begin
//          frmProductOrderLYList := TfrmProductOrderLYList.Create(application.MainForm);
//          with frmProductOrderLYList do
//          begin
//
//            caption := Trim(Title);
////            fCkName := trim(Parameters1);
////            canshu2 := trim(Parameters2);
//            FormStyle := mstyle;
//            windowState := mstate;
//            BorderStyle := mborderstyle;
//
//           //show;
//          end;
//        end
//        else
//          frmProductOrderLYList.BringToFront;
//       //句柄
//        mnewHandle := frmProductOrderLYList.Handle;
//      end;
  end;  // end case

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

function ConnData(): Boolean;
var
  IniFile: TIniFile;
begin
  try
    IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'SYSTEMSET.INI');
    PicSvr := IniFile.ReadString('SERVER', '服务器地址', '127.0.0.1');
    UserDataFlag := IniFile.ReadString('SERVER', '服务器地址类型', '-1');
  finally
    IniFile.Free;
  end;
  if not Assigned(YPCK_DataLink) then
    YPCK_DataLink := TYPCK_DataLink.Create(Application);
  try
    with YPCK_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 YPCK_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
  YPCK_DataLink.Free;
  application := NewDllApp;
  dxUnitsLoader.Finalize;

end.

