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_MJManageNewFDNew, U_ProductOrderList,
  U_ProductOrderAnPai, U_MJEdit, U_JYOrderCDOne, U_JYOrderCDMore,
  U_CpCkSaoMNewSel, U_CKProductBCPInList, U_CKProductBCPOutList, U_BanCpHCSaoM,
  U_CKProductBCPHCList, U_CKProductBCPKCList, U_CKProductBCPKCHZList,
  U_CpRkSaoMNew, U_ClothContractList, U_ClothContractKCList,
  U_ProductOrderNewList, U_ClothPDInfoList, U_ClothHCList, U_ContractListNX,
  U_ClothContractListSX, U_ClothContractListHZ, U_ProductOrderLBNameSet,
  U_ProductOrderNewList_JD, U_CKJYList, U_CKProductJYHZList, U_ModulePromptList,
  U_CPDBAO, U_JYOrderOther_Main;

       /////////////////////////////////////////////////////////////////
      //         功能说明:取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 := 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 := '121.40.233.100,7781';
//   server:='.';
  dtbase := 'zhuoyandata';
  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;
   DParameters1:='高权限';
   //DCode:='ADMIN';
   //DName:='ADMIN';
//   DParameters2:='成品管理'; //12
//   DParameters2:='管理';
  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
    201:  //生产指示单
      begin
        if frmProductOrderNewList = nil then
        begin
          frmProductOrderNewList := TfrmProductOrderNewList.Create(application.MainForm);
          with frmProductOrderNewList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderNewList.BringToFront;
       //句柄
        mnewHandle := frmProductOrderNewList.Handle;
      end;

    202:  //订单信息
      begin
        if FrmJYOrderOther = nil then
        begin
          FrmJYOrderOther := TFrmJYOrderOther.Create(application.MainForm);
          with FrmJYOrderOther do
          begin
            caption := Trim(Title);
            fdatabase := trim(DataBase);
         //  fdatabase:=trim('查询');
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          FrmJYOrderOther.BringToFront;
       //句柄
        mnewHandle := FrmJYOrderOther.Handle;
      end;

    2: // 成品检验
      begin
        if frmMJManageNewFDNewSF = nil then
        begin
          frmMJManageNewFDNewSF := TfrmMJManageNewFDNewSF.Create(application.MainForm);
          with frmMJManageNewFDNewSF do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmMJManageNewFDNewSF.BringToFront;
       //句柄
        mnewHandle := frmMJManageNewFDNewSF.Handle;
      end;
    11:  //标签皮重设置
      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;
    12:  //布匹管理
      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;
    13:  //入库扫描
      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;
    14:  //成品出库
      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;
    15:  //成品入库列表
      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;
    16:  //成品出库列表
      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;
    17:  //库存列表
      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;
    18:  //库存汇总列表
      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;
    19:  //检验报告
      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;

    22:  //检验指示单选择
      begin
        if frmClothHCList = nil then
        begin
          frmClothHCList := TfrmClothHCList.Create(application.MainForm);
          with frmClothHCList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmClothHCList.BringToFront;
       //句柄
        mnewHandle := frmClothHCList.Handle;

      end;

    23:  //生产指示单进度查询
      begin
        if frmProductOrderNewList_JD = nil then
        begin
          frmProductOrderNewList_JD := TfrmProductOrderNewList_JD.Create(application.MainForm);
          with frmProductOrderNewList_JD do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderNewList_JD.BringToFront;
       //句柄
        mnewHandle := frmProductOrderNewList_JD.Handle;

      end;

    28:  //打包
      begin
        if frmCPDBao = nil then
        begin
          frmCPDBao := TfrmCPDBao.Create(application.MainForm);
          with frmCPDBao do
          begin
            caption := Trim(Title);
           //ftype:='内销';
           //ftype:=trim(DataBase);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCPDBao.BringToFront;
       //句柄
        mnewHandle := frmCPDBao.Handle;
      end;

    29:  //检验汇总
      begin
        if frmCKProductJYHZList = nil then
        begin
          frmCKProductJYHZList := TfrmCKProductJYHZList.Create(application.MainForm);
          with frmCKProductJYHZList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKProductJYHZList.BringToFront;
       //句柄
        mnewHandle := frmCKProductJYHZList.Handle;
      end;

    32:  //打卷产量统计
      begin
        if frmCKJYList = nil then
        begin
          frmCKJYList := TfrmCKJYList.Create(application.MainForm);
          with frmCKJYList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKJYList.BringToFront;
       //句柄
        mnewHandle := frmCKJYList.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', '服务器地址类型', '');
    if (UserDataFlag = '0') or (UserDataFlag = '10') then
      UserDataFlag := '';
  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;

end.

