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_iniParam, U_ProductOrderList, U_ProductOrderLBNameSet,
  U_MarkingInspection, U_JYOrderCDList, U_OrderProgress, U_JYOrderCDListGH,
  U_TableInspection, U_ProductZHList, U_ProductPBCGList, U_SketchManageList,
  U_MGFYBB, U_MGFYBBMXGL, U_SketchManageListD, U_PRICECHANGE;

       /////////////////////////////////////////////////////////////////
      //         功能说明:取Dll中得窗体                              //
     //        参数说明：App>>调用应用程序；                        //
    //                 FormH>>调用窗口句柄 ；                      //
   //                 FormID>>窗口号;                             //
  //                 Language>>语言种类;                         //
 //                 WinStyle>>窗口类型；                        //
/////////////////////////////////////////////////////////////////
var
  frmProductOrderListLR, frmProductOrderListGL, frmProductOrderListCX: TfrmProductOrderList;
  frmProductOrderLBNameSetDQX, frmProductOrderLBNameSetGQX: TfrmProductOrderLBNameSet;
  frmJYOrderCDListCX, frmJYOrderCDListGL, frmJYOrderCDListCPGL, frmJYOrderCDListCPCX, frmJYOrderCDListSHGL, frmJYOrderCDListHHGL: TfrmJYOrderCDList;
  frmJYOrderCDListGH: TfrmJYOrderCDListGH; //检验信息汇总
  frmSketchManageListYW, frmSketchManageListCX, frmSketchManageListGL: TfrmSketchManageList;  //印花描稿
  frmMGFYBB: tfrmMGFYBB; //描稿费用报表
  frmMGFYBBMXGL: tfrmMGFYBBMXGL; //      描稿费用管理

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 := '47.100.130.130,7781';
//  server := '.';
    dtbase := 'zhenyongdata';
//  dtbase := 'cszhenyong';
    user := 'zhenyongsa';
    pswd := 'rightsoft@9101';
//  pswd := 'rightsoft';
    DConString := 'Provider=SQLOLEDB.1;Password=' + pswd + ';Persist Security Info=True;User ID=' + user + ';Initial Catalog=' + dtbase + ';Data Source=' + server;
//
    DName := 'ADMIN';
    DCode := 'ADMIN';
    DParameters1 := '高权限';
  end
  else
    DConString := DataBaseStr;

  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

    101:  //生产计划单录入
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '生产计划单录入' then
          begin
            BringWindowToTop(frmProductOrderListLR.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmProductOrderListLR := TfrmProductOrderList.Create(application.MainForm);
          with frmProductOrderListLR do
          begin
            canshu1 := '录入';
            Title := '生产计划单录入';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderListLR.BringToFront;
       //句柄
        mnewHandle := frmProductOrderListLR.Handle;
      end;
    102:  //生产计划单管理
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '生产计划单管理' then
          begin
            BringWindowToTop(frmProductOrderListGL.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
       //if frmBaoGuanListBGZL=nil then
        begin
          frmProductOrderListGL := TfrmProductOrderList.Create(application.MainForm);
          with frmProductOrderListGL do
          begin
            canshu1 := '高权限';
            Title := '生产计划单管理';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderListGL.BringToFront;
       //句柄
        mnewHandle := frmProductOrderListGL.Handle;
      end;
    103:  //生产计划单查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '生产计划单查询' then
          begin
            BringWindowToTop(frmProductOrderListCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmProductOrderListCX := TfrmProductOrderList.Create(application.MainForm);
          with frmProductOrderListCX do
          begin
            Title := '生产计划单查询';
            canshu1 := '查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderListCX.BringToFront;
       //句柄
        mnewHandle := frmProductOrderListCX.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(frmProductOrderLBNameSetDQX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmProductOrderLBNameSetDQX := TfrmProductOrderLBNameSet.Create(application.MainForm);
          with frmProductOrderLBNameSetDQX do
          begin
            Title := '标签皮重设置';
            canshu1 := '低权限';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderLBNameSetDQX.BringToFront;
       //句柄
        mnewHandle := frmProductOrderLBNameSetDQX.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(frmProductOrderLBNameSetGQX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmProductOrderLBNameSetGQX := TfrmProductOrderLBNameSet.Create(application.MainForm);
          with frmProductOrderLBNameSetGQX do
          begin
            Title := '标签皮重设置(高权限)';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderLBNameSetGQX.BringToFront;
       //句柄
        mnewHandle := frmProductOrderLBNameSetGQX.Handle;
      end;

    311:  //成品检验
      begin
        if frmMarkingInspection = nil then
        begin
          frmMarkingInspection := TfrmMarkingInspection.Create(application.MainForm);
          with frmMarkingInspection do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmMarkingInspection.BringToFront;
       //句柄
        mnewHandle := frmMarkingInspection.Handle;
      end;

    312:  //翻布检验
      begin
        if frmTableInspection = nil then
        begin
          frmTableInspection := TfrmTableInspection.Create(application.MainForm);
          with frmTableInspection do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmTableInspection.BringToFront;
       //句柄
        mnewHandle := frmTableInspection.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(frmJYOrderCDListGL.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmJYOrderCDListGL := TfrmJYOrderCDList.Create(application.MainForm);
          with frmJYOrderCDListGL do
          begin
            Title := '检验信息管理';
            canshu1 := '管理';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJYOrderCDListGL.BringToFront;
       //句柄
        mnewHandle := frmJYOrderCDListGL.Handle;
      end;
    412:  //检验信息查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '检验信息查询' then
          begin
            BringWindowToTop(frmJYOrderCDListCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmJYOrderCDListCX := TfrmJYOrderCDList.Create(application.MainForm);
          with frmJYOrderCDListCX do
          begin
            Title := '检验信息查询';
            canshu1 := '查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJYOrderCDListCX.BringToFront;
       //句柄
        mnewHandle := frmJYOrderCDListCX.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(frmJYOrderCDListGH.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmJYOrderCDListGH := TfrmJYOrderCDListGH.Create(application.MainForm);
          with frmJYOrderCDListGH do
          begin
            Title := '检验信息汇总';
            canshu1 := '检验信息汇总';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJYOrderCDListGH.BringToFront;
       //句柄
        mnewHandle := frmJYOrderCDListGH.Handle;
      end;

    511:  //组合订单查询
      begin
        if frmJYOrderZHLIST = nil then
        begin
          frmJYOrderZHLIST := tfrmJYOrderZHLIST.Create(application.MainForm);
          with frmJYOrderZHLIST do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJYOrderZHLIST.BringToFront;
       //句柄
        mnewHandle := frmJYOrderZHLIST.Handle;
      end;
    512:  //坯布采购单价设置
      begin
        if frmPBCGLIST = nil then
        begin
          frmPBCGLIST := TfrmPBCGLIST.Create(application.MainForm);
          with frmPBCGLIST do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmPBCGLIST.BringToFront;
       //句柄
        mnewHandle := frmPBCGLIST.Handle;
      end;

    611:  //印花描稿管理
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '印花描稿管理' then
          begin
            BringWindowToTop(frmSketchManageListYW.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmSketchManageListYW := TfrmSketchManageList.Create(application.MainForm);
          with frmSketchManageListYW do
          begin
            canshu1 := '录入';
            Title := '印花描稿管理';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmSketchManageListYW.BringToFront;
       //句柄
        mnewHandle := frmSketchManageListYW.Handle;
      end;

    612:  //印花描稿管理（设计）
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '印花描稿管理（设计）' then
          begin
            BringWindowToTop(frmSketchManageListGL.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmSketchManageListGL := TfrmSketchManageList.Create(application.MainForm);
          with frmSketchManageListGL do
          begin
            canshu1 := '管理';
            Title := '印花描稿管理（设计）';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmSketchManageListGL.BringToFront;
       //句柄
        mnewHandle := frmSketchManageListGL.Handle;
      end;
    613:  //印花描稿查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '印花描稿查询' then
          begin
            BringWindowToTop(frmSketchManageListCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmSketchManageListCX := TfrmSketchManageList.Create(application.MainForm);
          with frmSketchManageListCX do
          begin
            canshu1 := '查询';
            Title := '印花描稿查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmSketchManageListCX.BringToFront;
       //句柄
        mnewHandle := frmSketchManageListCX.Handle;
      end;

    614:  //印花描稿跟单查询
      begin
        if frmSketchManageListD = nil then
        begin
          frmSketchManageListD := TfrmSketchManageListD.Create(application.MainForm);
          with frmSketchManageListD do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmSketchManageListD.BringToFront;
       //句柄
        mnewHandle := frmSketchManageListD.Handle;
      end;

    615:  //印花描稿费修改
      begin
        if frmPRICECHANGE = nil then
        begin
          frmPRICECHANGE := TfrmPRICECHANGE.Create(application.MainForm);
          with frmPRICECHANGE do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmPRICECHANGE.BringToFront;
       //句柄
        mnewHandle := frmPRICECHANGE.Handle;
      end;

    911:  //描稿费用报表
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '描稿费用报表' then
          begin
            BringWindowToTop(frmMGFYBB.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
       //if frmBaoGuanList=nil then
        begin
          frmMGFYBB := TfrmMGFYBB.Create(application.MainForm);
          with frmMGFYBB do
          begin
            Title := '描稿费用报表';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmMGFYBB.BringToFront;
       //句柄
        mnewHandle := frmMGFYBB.Handle;
      end;

    922:  //描稿费用管理
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '描稿费用管理' then
          begin
            BringWindowToTop(frmMGFYBBMXGL.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
       //if frmBaoGuanList=nil then
        begin
          frmMGFYBBMXGL := TfrmMGFYBBMXGL.Create(application.MainForm);
          with frmMGFYBBMXGL do
          begin
            Title := '描稿费用管理';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmMGFYBBMXGL.BringToFront;
       //句柄
        mnewHandle := frmMGFYBBMXGL.Handle;
      end;
  end;

  Result := mnewHandle;
end;

function GetsysParam(muserId: pchar; fparam1: pchar): Boolean;
begin
  result := true;
  //////////////////////////////
  shortDateFormat := 'yyyy-MM-dd';
  //服务器日期
  with DataLink_DyeingFinishingPlan.AdoDataLink do
  begin
    close;
    sql.Clear;
    sql.Add('select getDate()as dt');
    open;
    DServerDate := fieldByName('dt').AsDatetime;
  end;
  result := true;
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(DataLink_DyeingFinishingPlan) then
    DataLink_DyeingFinishingPlan := TDataLink_DyeingFinishingPlan.Create(Application);
  try
    with DataLink_DyeingFinishingPlan.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_DyeingFinishingPlan.Free;
  application := NewDllApp;
  dxUnitsLoader.Finalize;

end.

