unit U_GetDllForm;

interface

uses
  Windows, Messages, forms, OleCtnrs, DateUtils, SysUtils, ADODB, 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;

implementation

uses
  U_DataLink, U_SxXnKcList, U_KkAndDjList, U_OrderProgress, U_AllOrderProgress,
  U_KuLinList, U_KuLinHZList, U_KaiJiList, U_JTSCTJList, U_YCClothCPList,
  U_YCClothRZPList, U_CKCHHZList, U_AllOrderProgress2023;

       /////////////////////////////////////////////////////////////////
      //         功能说明:取Dll中得窗体                              //
     //        参数说明：App>>调用应用程序；                        //
    //                 FormH>>调用窗口句柄 ；                      //
   //                 FormID>>窗口号;                             //
  //                 Language>>语言种类;                         //
 //                 WinStyle>>窗口类型；                        //
/////////////////////////////////////////////////////////////////
var
  frmKkAndDjList, frmKkAndDjListGQX: TfrmKkAndDjList;
  frmKuLinListGL, frmKuLinListCX: TfrmKuLinList;
  frmKuLinHZList: TfrmKuLinHZList;
  frmKaiJiList: TfrmKaiJiList;
  frmJTSCTJList: TfrmJTSCTJList;
  frmYCClothCPList: TfrmYCClothCPList;
  frmYCClothRZPList: TfrmYCClothRZPList;
  frmCKCHHZList: TfrmCKCHHZList;

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 := PChar(GName);
  DCode := PChar(GCode);
  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);
  if trim(DataBaseStr) = '' then
  begin
    server := '139.196.189.214,7781';
  //server:='.';
    dtbase := 'yongjindata';
  //dtbase := 'YiFudata';
    user := 'YIFUsa';
  //user := 'sa';
    pswd := 'rightsoft@123';
  //pswd:='rightsoft';
    DConString := 'Provider=SQLOLEDB.1;Password=' + pswd + ';Persist Security Info=True;User ID=' + user + ';Initial Catalog=' + dtbase + ';Data Source=' + server;

//    DName := '王巧';
    DName := 'ADMIN';
    DParameters1 := '高权限';  
   //DParameters3:='1';
  end
  else
  begin
    DConString := DataBaseStr;
  end;

  if not ConnData() then
  begin
    result := 0;
    exit;
  end;

   // 定义窗口类型 、状态
  if WinStyle = 0 then
  begin
    mstyle := fsMDIChild;
    mstate := wsMaximized;
    mborderstyle := bsSizeable;
  end
  else
  begin
    mstyle := fsNormal;
    mstate := wsNormal;
    mborderstyle := bsSizeable;
  end;
  /////////////////////
  //调用子模块窗口
  case FormID of

    111:  //开卡与打卷分析
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '开卡与打卷分析' then
          begin
            BringWindowToTop(frmKkAndDjList.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmKkAndDjList := TfrmKkAndDjList.Create(application.MainForm);
          with frmKkAndDjList do
          begin
            Title := '开卡与打卷分析';
            canshu1 := '查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmKkAndDjList.BringToFront;
       //句柄
        mnewHandle := frmKkAndDjList.Handle;
      end;

    112:  //开卡与打卷分析管理
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '开卡与打卷分析管理' then
          begin
            BringWindowToTop(frmKkAndDjListGQX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmKkAndDjListGQX := TfrmKkAndDjList.Create(application.MainForm);
          with frmKkAndDjListGQX do
          begin
            canshu1 := '管理';
            Title := '开卡与打卷分析管理';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmKkAndDjListGQX.BringToFront;
       //句柄
        mnewHandle := frmKkAndDjListGQX.Handle;
      end;

    151:  //总跟进表2023
      begin
        if frmAllOrderProgress2023 = nil then
        begin
          frmAllOrderProgress2023 := TfrmAllOrderProgress2023.Create(application.MainForm);
          with frmAllOrderProgress2023 do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmAllOrderProgress2023.BringToFront;
       //句柄
        mnewHandle := frmAllOrderProgress2023.Handle;
      end;

    121:  //跟进表
      begin
        if frmOrderProgress = nil then
        begin
          frmOrderProgress := TfrmOrderProgress.Create(application.MainForm);
          with frmOrderProgress do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmOrderProgress.BringToFront;
       //句柄
        mnewHandle := frmOrderProgress.Handle;
      end;
    131:  //总跟进表
      begin
        if frmAllOrderProgress = nil then
        begin
          frmAllOrderProgress := TfrmAllOrderProgress.Create(application.MainForm);
          with frmAllOrderProgress do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmAllOrderProgress.BringToFront;
       //句柄
        mnewHandle := frmAllOrderProgress.Handle;
      end;

      
//    211:  //库龄分析
//      begin
//        bFound := FALSE;
//        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
//        begin
//          if App.MainForm.MDIChildren[i].Caption = '库龄分析' then
//          begin
//            BringWindowToTop(frmKuLinListGL.Handle);
//            bFound := TRUE;
//            Break;
//          end;
//        end;
//        if not bFound then
//        begin
//          frmKuLinListGL := TfrmKuLinList.Create(application.MainForm);
//          with frmKuLinListGL do
//          begin
//            canshu1 := '管理';
//            Title := '库龄分析';
//            caption := Trim(Title);
//            FormStyle := mstyle;
//            windowState := mstate;
//            BorderStyle := mborderstyle;
//           //show;
//          end;
//        end
//        else
//          frmKuLinListGL.BringToFront;
//       //句柄
//        mnewHandle := frmKuLinListGL.Handle;
//      end;
      212:  //汇总库龄分析
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '汇总库龄分析' then
          begin
            BringWindowToTop(frmKuLinHZList.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmKuLinHZList := TfrmKuLinHZList.Create(application.MainForm);
          with frmKuLinHZList do
          begin
            canshu1 := '提交';
            Title := '汇总库龄分析';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmKuLinHZList.BringToFront;
       //句柄
        mnewHandle := frmKuLinHZList.Handle;
      end;
    213:  //汇总库龄分析审核
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '汇总库龄分析审核' then
          begin
            BringWindowToTop(frmKuLinHZList.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmKuLinHZList := TfrmKuLinHZList.Create(application.MainForm);
          with frmKuLinHZList do
          begin
            canshu1 := '管理';
            Title := '汇总库龄分析审核';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmKuLinHZList.BringToFront;
       //句柄
        mnewHandle := frmKuLinHZList.Handle;
      end;
    311:  //开机率
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '开机率' then
          begin
            BringWindowToTop(frmKaiJiList.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmKaiJiList := TfrmKaiJiList.Create(application.MainForm);
          with frmKaiJiList do
          begin
            canshu1 := '管理';
            Title := '开机率';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmKaiJiList.BringToFront;
       //句柄
        mnewHandle := frmKaiJiList.Handle;
      end;
    321:  //机台生产统计
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '机台生产统计' then
          begin
            BringWindowToTop(frmJTSCTJList.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmJTSCTJList := TfrmJTSCTJList.Create(application.MainForm);
          with frmJTSCTJList do
          begin
            canshu1 := '管理';
            Title := '机台生产统计';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJTSCTJList.BringToFront;
       //句柄
        mnewHandle := frmJTSCTJList.Handle;
      end;

    411:  //超范围坯布查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '超范围坯布查询' then
          begin
            BringWindowToTop(frmYCClothCPList.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmYCClothCPList := TfrmYCClothCPList.Create(application.MainForm);
          with frmYCClothCPList do
          begin
            Title := '超范围坯布查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYCClothCPList.BringToFront;
       //句柄
        mnewHandle := frmYCClothCPList.Handle;
      end;
    421:  // 超范围成品查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '超范围成品查询' then
          begin
            BringWindowToTop(frmYCClothRZPList.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmYCClothRZPList := TfrmYCClothRZPList.Create(application.MainForm);
          with frmYCClothRZPList do
          begin
            Title := '超范围成品查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYCClothRZPList.BringToFront;
       //句柄
        mnewHandle := frmYCClothRZPList.Handle;
      end;

    511:  // 仓库进度表
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '仓库进度表' then
          begin
            BringWindowToTop(frmCKCHHZList.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmCKCHHZList := TfrmCKCHHZList.Create(application.MainForm);
          with frmCKCHHZList do
          begin
            Title := '仓库进度表';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKCHHZList.BringToFront;
       //句柄
        mnewHandle := frmCKCHHZList.Handle;
      end;
  end;

  Result := mnewHandle;

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

function ConnData(): Boolean;
begin
  if not Assigned(DataLink_Statistics) then
    DataLink_Statistics := TDataLink_Statistics.Create(Application);
  try
    with DataLink_Statistics.ADOLink do
    begin
      //if not Connected then
      begin
        Connected := false;
        ConnectionString := DConString;
        LoginPrompt := false;
        Connected := true;
      end;
    end;
    Result := true;
  except
    Result := false;
    application.MessageBox('数据库连接失败！', '错误', mb_Ok + MB_ICONERROR);
  end;

end;

initialization
  CoInitialize(nil);
  dxUnitsLoader.Initialize;


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

end.

