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_Fun, U_iniParam, U_ContractList, U_ContractListNX
  //合同  U_CPGangNo
    , U_ProductOrderNewList, U_ProductOrderLBNameSet//指示单
    , U_MJManageNewFDNew, U_KcRollCaiFen, U_JYOrderCDOne, U_MJEdit, U_CPDBAO
    //检验打包
    , U_CpRkSaoMNew, U_CKProductBCPInList, U_CKProductRKHZList  //成品入库
    , U_ProductOrderNewList_CY, U_CpCkSaoMNewSel, U_CKProductBCPOutList,
    U_CKProductCKHZList   //成品出库
    , U_CKProductBCPKCList, U_CKProductBCPKCHZList, U_CKProductBSCRCList//库存
    , U_ModulePromptList //提示
    , U_ProductOrderNewList_JD, U_OrderLRList, U_ContractListXF_YGML,
    U_ProductOrderJdList;

       /////////////////////////////////////////////////////////////////
      //         功能说明:取Dll中得窗体                              //
     //        参数说明：App>>调用应用程序；                        //
    //                 FormH>>调用窗口句柄 ；                      //
   //                 FormID>>窗口号;                             //
  //                 Language>>语言种类;                         //
 //                 WinStyle>>窗口类型；                        //
/////////////////////////////////////////////////////////////////

var
  frmPRTCYLR, frmPRTCYCW, frmPRTCYCK: TfrmProductOrderNewList_CY;
  frmProductOrderLR, frmProductOrderGQX: TfrmProductOrderNewList;

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 := 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);

//  server := '.';
  server := '121.40.233.100,7781';
  dtbase := 'chengxiedata';
  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;
  DConString := DataBaseStr;

 //  DCode:='002';
//   DName:='袁泉港';
//  DParameters1 := '高权限';
//   DParameters1:='录入';
  if not ConnData() then
  begin
    result := 0;
    exit;
  end;
  if IsINIFile() then
    ReadINIFile()
  else
    WriteINIFile;
  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
    111: //外销合同
      begin
        if frmContractList = nil then
        begin
          frmContractList := TfrmContractList.Create(application.MainForm);
          with frmContractList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmContractList.BringToFront;
       //句柄
        mnewHandle := frmContractList.Handle;
      end;

    121: //内销合同
      begin
        if frmContractListNX = nil then
        begin
          frmContractListNX := TfrmContractListNX.Create(application.MainForm);
          with frmContractListNX do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmContractListNX.BringToFront;
       //句柄
        mnewHandle := frmContractListNX.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(frmProductOrderLR.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmProductOrderLR := TfrmProductOrderNewList.Create(application.MainForm);
          with frmProductOrderLR do
          begin
            Title := '生产指示单录入';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderLR.BringToFront;
       //句柄
        mnewHandle := frmProductOrderLR.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(frmProductOrderGQX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmProductOrderGQX := TfrmProductOrderNewList.Create(application.MainForm);
          with frmProductOrderGQX do
          begin
            Title := '生产指示单录入（高权限）';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderGQX.BringToFront;
       //句柄
        mnewHandle := frmProductOrderGQX.Handle;
      end;

    221:  //标签皮重设置
      begin
        if frmProductOrderLBNameSet = nil then
        begin
          frmProductOrderLBNameSet := TfrmProductOrderLBNameSet.Create(application.MainForm);
          with frmProductOrderLBNameSet do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderLBNameSet.BringToFront;
       //句柄
        mnewHandle := frmProductOrderLBNameSet.Handle;

      end;

    231:  //成本预估
      begin
        if frmContractListXF_YGML = nil then
        begin
          frmContractListXF_YGML := TfrmContractListXF_YGML.Create(application.MainForm);
          with frmContractListXF_YGML do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmContractListXF_YGML.BringToFront;
       //句柄
        mnewHandle := frmContractListXF_YGML.Handle;
      end;

    241:  //订单利润
      begin
        if frmOrderLRList = nil then
        begin
          frmOrderLRList := TfrmOrderLRList.Create(application.MainForm);
          with frmOrderLRList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmOrderLRList.BringToFront;
       //句柄
        mnewHandle := frmOrderLRList.Handle;
      end;

    251:  //生产指示单明细进度查询
      begin
        if frmProductOrderJdList = nil then
        begin
          frmProductOrderJdList := TfrmProductOrderJdList.Create(application.MainForm);
          with frmProductOrderJdList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderJdList.BringToFront;
       //句柄
        mnewHandle := frmProductOrderJdList.Handle;
      end;
    311: // 成品检验
      begin
        if frmMJManageNewFDNewSF = nil then
        begin
          frmMJManageNewFDNewSF := TfrmMJManageNewFDNewSF.Create(application.MainForm);
          with frmMJManageNewFDNewSF do
          begin
            fmanage := Trim(DataBase);
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmMJManageNewFDNewSF.BringToFront;
       //句柄
        mnewHandle := frmMJManageNewFDNewSF.Handle;
      end;

    321: // 库存拆匹
      begin
        if frmKcRollCaiFen = nil then
        begin
          frmKcRollCaiFen := TfrmKcRollCaiFen.Create(application.MainForm);
          with frmKcRollCaiFen do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmKcRollCaiFen.BringToFront;
       //句柄
        mnewHandle := frmKcRollCaiFen.Handle;
      end;

    331:  //检验信息管理
      begin
        if frmJYOrderCDOne = nil then
        begin
          frmJYOrderCDOne := TfrmJYOrderCDOne.Create(application.MainForm);
          with frmJYOrderCDOne do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJYOrderCDOne.BringToFront;
       //句柄
        mnewHandle := frmJYOrderCDOne.Handle;
      end;

    341:  //布匹管理
      begin
        if frmMJEdit = nil then
        begin
          frmMJEdit := TfrmMJEdit.Create(application.MainForm);
          with frmMJEdit do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmMJEdit.BringToFront;
       //句柄
        mnewHandle := frmMJEdit.Handle;

      end;

    351: // 布匹打包
      begin
        if frmCPDBao = nil then
        begin
          frmCPDBao := TfrmCPDBao.Create(application.MainForm);
          with frmCPDBao do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCPDBao.BringToFront;
       //句柄
        mnewHandle := frmCPDBao.Handle;
      end;

    411:  //入库扫描
      begin
        if frmCpRkSaoMNew = nil then
        begin
          frmCpRkSaoMNew := TfrmCpRkSaoMNew.Create(application.MainForm);
          with frmCpRkSaoMNew do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCpRkSaoMNew.BringToFront;
       //句柄
        mnewHandle := frmCpRkSaoMNew.Handle;
      end;

    421:  //成品入库列表
      begin
        if frmCKProductBCPInList = nil then
        begin
          frmCKProductBCPInList := TfrmCKProductBCPInList.Create(application.MainForm);
          with frmCKProductBCPInList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKProductBCPInList.BringToFront;
       //句柄
        mnewHandle := frmCKProductBCPInList.Handle;

      end;

    431:  //入库汇总
      begin
        if frmCKProductRKHZList = nil then
        begin
          frmCKProductRKHZList := TfrmCKProductRKHZList.Create(application.MainForm);
          with frmCKProductRKHZList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKProductRKHZList.BringToFront;
       //句柄
        mnewHandle := frmCKProductRKHZList.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(frmPRTCYLR.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmPRTCYLR := TfrmProductOrderNewList_CY.Create(application.MainForm);
          with frmPRTCYLR do
          begin
            Title := '发货申请录入';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmPRTCYLR.BringToFront;
       //句柄
        mnewHandle := frmPRTCYLR.Handle;
      end;
    512:  //发货申请财务审核
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '发货申请财务审核' then
          begin
            BringWindowToTop(frmPRTCYCW.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmPRTCYCW := TfrmProductOrderNewList_CY.Create(application.MainForm);
          with frmPRTCYCW do
          begin
            Title := '发货申请财务审核';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmPRTCYCW.BringToFront;
       //句柄
        mnewHandle := frmPRTCYCW.Handle;
      end;
    513:  //发货申请仓库审核
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '发货申请仓库审核' then
          begin
            BringWindowToTop(frmPRTCYCK.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmPRTCYCK := TfrmProductOrderNewList_CY.Create(application.MainForm);
          with frmPRTCYCK do
          begin
            Title := '发货申请仓库审核';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmPRTCYCK.BringToFront;
       //句柄
        mnewHandle := frmPRTCYCK.Handle;
      end;
//     511:  //发货申请
//     begin
//       if frmProductOrderNewList_CY=nil then
//       begin
//         frmProductOrderNewList_CY:= TfrmProductOrderNewList_CY.Create(application.MainForm);
//         with frmProductOrderNewList_CY do
//         begin
//           caption:=Trim(Title);
//           FormStyle := mstyle ;
//           windowState := mstate ;
//           BorderStyle := mborderstyle;
//           //show;
//         end;
//       end
//       else
//         frmProductOrderNewList_CY.BringToFront;
//       //句柄
//       mNewHandle:=frmProductOrderNewList_CY.Handle;
//     end ;
    521:  //成品扫描出库
      begin
        if frmCpCkSaoMNewSel = nil then
        begin
          frmCpCkSaoMNewSel := TfrmCpCkSaoMNewSel.Create(application.MainForm);
          with frmCpCkSaoMNewSel do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCpCkSaoMNewSel.BringToFront;
       //句柄
        mnewHandle := frmCpCkSaoMNewSel.Handle;
      end;

    531:  //成品出库列表
      begin
        if frmCKProductBCPOutList = nil then
        begin
          frmCKProductBCPOutList := TfrmCKProductBCPOutList.Create(application.MainForm);
          with frmCKProductBCPOutList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKProductBCPOutList.BringToFront;
       //句柄
        mnewHandle := frmCKProductBCPOutList.Handle;
      end;

    541:  //出库汇总
      begin
        if frmCKProductCKHZList = nil then
        begin
          frmCKProductCKHZList := TfrmCKProductCKHZList.Create(application.MainForm);
          with frmCKProductCKHZList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKProductCKHZList.BringToFront;
       //句柄
        mnewHandle := frmCKProductCKHZList.Handle;
      end;

    611:  //库存列表
      begin
        if frmCKProductBCPKCList = nil then
        begin
          frmCKProductBCPKCList := TfrmCKProductBCPKCList.Create(application.MainForm);
          with frmCKProductBCPKCList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKProductBCPKCList.BringToFront;
       //句柄
        mnewHandle := frmCKProductBCPKCList.Handle;
      end;

    621:  //库存汇总列表
      begin
        if frmCKProductBCPKCHZList = nil then
        begin
          frmCKProductBCPKCHZList := TfrmCKProductBCPKCHZList.Create(application.MainForm);
          with frmCKProductBCPKCHZList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKProductBCPKCHZList.BringToFront;
       //句柄
        mnewHandle := frmCKProductBCPKCHZList.Handle;

      end;

    631:  //成品仓库 出入存
      begin
        if frmCKProductBSCRCList = nil then
        begin
          frmCKProductBSCRCList := TfrmCKProductBSCRCList.Create(application.MainForm);
          with frmCKProductBSCRCList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKProductBSCRCList.BringToFront;
       //句柄
        mnewHandle := frmCKProductBSCRCList.Handle;

      end;

    61:  //提示窗口
      begin
        if frmModulePromptList = nil then
        begin
          frmModulePromptList := TfrmModulePromptList.Create(application.MainForm);
          with frmModulePromptList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmModulePromptList.BringToFront;
       //句柄
        mnewHandle := frmModulePromptList.Handle;
      end;

  end;  // end case

  Result := mnewHandle;
//  NewDllApp := Application;
end;

function GetsysParam(muserId: pchar; fparam1: pchar): Boolean;
begin
  result := true;
  //////////////////////////////
  shortDateFormat := 'yyyy-MM-dd';
  //服务器日期
  with DataLink_TradeManage.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_TradeManage) then
    DataLink_TradeManage := TDataLink_TradeManage.Create(Application);
  try
    with DataLink_TradeManage.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_TradeManage.Free;
  application := NewDllApp;
  dxUnitsLoader.Finalize;
//initialization
//  OldDllApp := Application;
//
//finalization
//  DataLink_TradeManage.Free;
//  Application := OldDllApp;

end.

