unit U_OrderInPut;

interface                     

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxMemo,
  cxRichEdit, ComCtrls, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit,
  StdCtrls, ToolWin, DBClient, ADODB, ExtCtrls, BtnEdit, cxCalendar, StrUtils,
  cxCurrencyEdit, cxImage, Menus, cxLookAndFeelPainters, cxButtons, cxDBEdit,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels, cxNavigator,
  RM_Dataset, RM_System, RM_Common, RM_Class, RM_GridReport, RM_Preview,
  RM_DsgGridReport, RM_e_Graphic, RM_e_bmp, dxSkinsCore, dxSkinBlack,
  dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle,
  dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary,
  dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin,
  dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter;

type
  TfrmOrderInPut = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    OrderNo: TEdit;
    Label7: TLabel;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    v1PRTColor: TcxGridDBColumn;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    v1PRTOrderQty: TcxGridDBColumn;
    Label10: TLabel;
    ConNo: TEdit;
    RanFactory: TBtnEditC;
    v1XHNo: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    v1SOrddefstr1: TcxGridDBColumn;
    v1SOrddefstr2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    ToolButton3: TToolButton;
    v1PRTHX: TcxGridDBColumn;
    Label3: TLabel;
    Label14: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    OrdDate: TDateTimePicker;
    CustomerNoName: TBtnEditC;
    MPRTMF: TBtnEditC;
    MPRTKZ: TBtnEditC;
    Label2: TLabel;
    MPRTCodeName: TBtnEditC;
    Label6: TLabel;
    MPRTSpec: TBtnEditC;
    Label5: TLabel;
    MPRTDuiSeGY: TBtnEditC;
    Label11: TLabel;
    MPRTSL: TBtnEditC;
    Label9: TLabel;
    MPRTNiuDu: TBtnEditC;
    Label8: TLabel;
    MPRTPH: TBtnEditC;
    Label15: TLabel;
    HZLFactory: TBtnEditC;
    Label16: TLabel;
    PBFactory: TBtnEditC;
    Label17: TLabel;
    YCLFactory: TBtnEditC;
    Label18: TLabel;
    MPRTZHName: TEdit;
    Label19: TLabel;
    Label20: TLabel;
    MPRTKaiJian: TBtnEditC;
    Label21: TLabel;
    MPRTChuanY: TBtnEditC;
    Label22: TLabel;
    MPRTYaoFeng: TBtnEditC;
    Label23: TLabel;
    MPRTJiBenNote: TBtnEditC;
    Label24: TLabel;
    MPRTTeBieNote: TBtnEditC;
    Label25: TLabel;
    DLYDate: TDateTimePicker;
    Label26: TLabel;
    MPRTCode: TBtnEditC;
    Label27: TLabel;
    MPRTQtyNote: TBtnEditC;
    Label28: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    Label31: TLabel;
    MPRTColorLaoDu1: TBtnEditC;
    MPRTColorLaoDu2: TBtnEditC;
    MPRTColorLaoDu3: TBtnEditC;
    MPRTColorLaoDu4: TBtnEditC;
    Label32: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    MPRTKQiQiu: TBtnEditC;
    MPRTDingPoLv: TBtnEditC;
    MPRTZuRanXing: TBtnEditC;
    Label35: TLabel;
    MPRTKuanNO: TBtnEditC;
    Label36: TLabel;
    Label37: TLabel;
    Label38: TLabel;
    MPRTTangJin: TBtnEditC;
    Label39: TLabel;
    OrdDefDate1: TDateTimePicker;
    Label40: TLabel;
    OrdDefDate2: TDateTimePicker;
    Label41: TLabel;
    OrdPerson1: TBtnEditC;
    Label43: TLabel;
    OrdPerson2: TBtnEditC;
    LBNameNote: TMemo;
    MaiTouNote: TMemo;
    SYRName: TBtnEditC;
    MPRTBZNote: TMemo;
    MPRTSCTeBieNote: TMemo;
    Orddefstr5: TEdit;
    Label45: TLabel;
    v1Column1: TcxGridDBColumn;
    Label46: TLabel;
    orddefnote1: TMemo;
    orddefstr1: TBtnEditC;
    Label47: TLabel;
    orddefstr2: TEdit;
    orddefstr4: TBtnEditC;
    orddefstr3: TEdit;
    Label48: TLabel;
    Label49: TLabel;
    EditCnt: TcxCurrencyEdit;
    v1PRTCodeName: TcxGridDBColumn;
    v1KHorderNo: TcxGridDBColumn;
    v1PRTCode: TcxGridDBColumn;
    v1PRTMF: TcxGridDBColumn;
    v1PRTKZ: TcxGridDBColumn;
    Label42: TLabel;
    Label4: TLabel;
    FileName: TcxButton;
    Files: TcxDBImage;
    ADOQueryImage: TADOQuery;
    DSIMage: TDataSource;
    Label44: TLabel;
    orddefnote2: TMemo;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    Label50: TLabel;
    Label51: TLabel;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label52: TLabel;
    Label53: TLabel;
    PBPrice: TcxCurrencyEdit;
    v1Column9: TcxGridDBColumn;
    PbQty: TcxCurrencyEdit;
    Label54: TLabel;
    Label55: TLabel;
    SLBName: TBtnEditA;
    Button1: TButton;
    GroupBox1: TGroupBox;
    RMPreview1: TRMPreview;
    RMGridReport2: TRMGridReport;
    OpenDialog1: TOpenDialog;
    ADOQuery_label: TADOQuery;
    RMDS_Main: TRMDBDataSet;
    RMGridReport1: TRMGridReport;
    RMGridReportDesigner1: TRMGridReportDesigner;
    RMBMPExport1: TRMBMPExport;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Panel1: TPanel;
    Label56: TLabel;
    Edit7: TEdit;
    Label57: TLabel;
    Label58: TLabel;
    Edit1: TEdit;
    Dxjuan: TComboBox;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1PRTColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure RanFactoryBtnUpClick(Sender: TObject);
    procedure CustomerNoNameBtnUpClick(Sender: TObject);
    procedure CustomerNoNameBtnDnClick(Sender: TObject);
    procedure MPRTCodeNameBtnUpClick(Sender: TObject);
    procedure NoteDblClick(Sender: TObject);
    procedure v1OrderUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1PriceUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure OrdDefStr2BtnUpClick(Sender: TObject);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton3Click(Sender: TObject);
    procedure YCLFactoryBtnUpClick(Sender: TObject);
    procedure MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
    procedure Label36DblClick(Sender: TObject);
    procedure Label37DblClick(Sender: TObject);
    procedure SYRNameBtnUpClick(Sender: TObject);
    procedure MPRTBZNoteDblClick(Sender: TObject);
    procedure MPRTSCTeBieNoteDblClick(Sender: TObject);
    procedure v1PRTCodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure FileNameClick(Sender: TObject);
    procedure v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
    procedure v1Column9PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Button1Click(Sender: TObject);
    procedure SLBNameBtnClick(Sender: TObject);
    procedure Edit7Click(Sender: TObject);
    procedure Edit1Click(Sender: TObject);
  private
    procedure InitData();
    procedure ZDYHelp(FButn: TcxButtonEdit; LType: string);
    function SaveData(): Boolean;
    function SaveDataSubOne(): Boolean;
    function SaveDataMain(): Boolean;
    function SaveDataSubMore(): Boolean;
    function ExportToFtErp(mFileName: string; ADOQueryCmd: TADOQuery): Boolean;
    procedure CJEWM();
    procedure InitImage();
    procedure InitDataSetDictionary();
    { Private declarations }
  public
    PState, CopyInt, PriceFlag: Integer;
    FMainId, FFMainId, FOrderNo: string;
    FXS: Integer;
    fFlileFlag: string;
    { Public declarations }
  end;

var
  frmOrderInPut: TfrmOrderInPut;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_Fun, U_ZDYHelpSel, getpic;
{$R *.dfm}

function TfrmOrderInPut.ExportToFtErp(mFileName: string; ADOQueryCmd: TADOQuery): boolean;
var
  fFileName, fpathFileName: string;
  Stream: TMemoryStream;
  mfileSize: integer;
  mCreationTime: TdateTime;
  mWriteTime: TdateTime;
begin
  result := false;
  fFileName := ExtractFileName(Trim(mFileName));
  fpathFileName := trim(mFileName);
  try
   // ADOQueryCmd.Connection.BeginTrans ;
    try
      with ADOQueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('delete  from RT_FileUpdate');
        sql.Add('where FileName=' + quotedStr(trim(fFileName)));
        execsql;
      end;
      with ADOQueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('select * from RT_FileUpdate');
        sql.Add('where FileName=' + quotedStr(trim(fFileName)));
        Open;
        //////////////////////////
        //获取文件信息
        GetFileInfo(fpathFileName, mfileSize, mCreationTime, mWriteTime);

        if RecordCount <= 0 then
        begin
          Append;
          fieldByName('FileName').AsString := fFileName;
        end
        else
        begin
          edit;
        end;

        fieldByName('FileEditDate').Value := mWriteTime;
        fieldByName('FileCreateDate').Value := mCreationTime;
        fieldByName('FileSize').Value := mfileSize;
        fieldByName('Filler').Value := Dname;
        fieldByName('LastEditer').Value := Dname;
        fieldByName('LastEditTime').Value := DServerDate;
        if pos('.rmf', fFileName) > 0 then
        begin
          fieldByName('FilePath').Value := 'report';
          fieldByName('FileType').Value := '公用';
        end
        else if pos('.dll', fFileName) > 0 then
        begin
          fieldByName('FilePath').Value := '';
          fieldByName('FileType').Value := '一般';
        end
        else
        begin
          fieldByName('FilePath').Value := '';
          fieldByName('FileType').Value := '公用';
        end;
      //  FJStream.LoadFromFile(fpathFileName);
      //  CompressionStream(FJStream);
        //tblobfield(FieldByName('Files')).LoadFromFile(FJStream);
        tblobfield(FieldByName('Files')).LoadFromFile(fpathFileName);
        //将OLE数据存入数据库
     //   ADOQueryCmdFileContent.LoadFromFile(fpathFileName);
        //ADOQueryCmdFileContent.LoadFromStream(Stream);

        post;
      end;
    finally
   //   FJStream.free;
    end;
    result := true;
  //  ADOQueryCmd.Connection.CommitTrans ;
  except
   // ADOQueryCmd.Connection.RollbackTrans ;
    application.MessageBox(pchar('提交文件[' + trim(fFileName) + ']失败!'), '提示信息', MB_ICONERROR);
  end;

end;

procedure TfrmOrderInPut.InitDataSetDictionary();
begin
  with ADOQuery_label do
  begin
    close;
    sql.Clear;
    sql.Add('exec P_Print_RollLabel');
    sql.Add('@MJID='''' ');
    sql.ADD(',@Flag=''1'' ');
    OPen;
  end;
//  with RMGridReport2 do
//  begin
//    Dictionary.FieldAliases.Clear;
//    Dictionary.FieldAliases['RMDS_Main'] := '标签数据';
//   // Dictionary.FieldAliases['RMDS_Main."barcode"']:='标签条码';
//  end;
end;

procedure TfrmOrderInPut.InitImage();
begin
//  IF Order_Sub.IsEmpty then exit;
  with ADOQueryImage do
  begin
    close;
    sql.Clear;
    sql.Add('select * from TP_File A');
    sql.Add('where TFid=' + quotedstr(trim(OrderNO.Text)));
    open;
  end;
end;

procedure TfrmOrderInPut.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(self.Caption + TV1.Name + '1', Tv1, '生产指示单管理2');
end;

procedure TfrmOrderInPut.InitData();
var
  forderno: string;
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from JYOrder_Sub where 1=1 ');
    if PState = 1 then
    begin
      sql.Add(' and MainId=''' + Trim(FMainId) + '''');
    end;
    if PState = 0 then
    begin
      sql.Add(' and 1<>1');
    end;
    Open;
  end;
  SCreateCDS20(ADOQuery1, Order_Sub);
  SInitCDSData20(ADOQuery1, Order_Sub);
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main where MainId=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCSHDataNew(ADOQuery1, ScrollBox1, 2);
  if not Order_Sub.IsEmpty then
  begin
    SLBName.Text := Order_Sub.fieldbyName('SLBName').AsString;
  end;

  if PState = 0 then
  begin
    OrdDate.DateTime := SGetServerDateTime(ADOTemp);
    DlyDate.DateTime := OrdDate.DateTime;
    OrdDefDate1.DateTime := OrdDate.DateTime;
    OrdDefDate2.DateTime := OrdDate.DateTime;
    OrdPerson2.Text := trim(dName);
  end
  else
  begin
  end;
  if CopyInt = 99 then
  begin
    PState := 0;
    FMainId := '';
    OrderNo.Text := '';
    orddefnote1.Text := '';
    OrdPerson2.Text := trim(dName);
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value := '';
        FieldByName('SubId').Value := '';
        Fieldbyname('SLBName').value := null;
        Post;
        Next;
      end;
    end;
    forderno := OrderNo.Text;
  end;
  InitImage();
end;

procedure TfrmOrderInPut.ZDYHelp(FButn: TcxButtonEdit; LType: string);
begin

end;

procedure TfrmOrderInPut.FormShow(Sender: TObject);
begin
  readCxGrid(self.Caption + TV1.Name + '1', Tv1, '生产指示单管理2');
  InitData();
end;

procedure TfrmOrderInPut.CJEWM();
var
  Txt, fImagePath, maxNo: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
//  i: Integer;
begin
//   i := Order_Sub.RecordCount;
//   i := i + 1;
  try
    Moudle := LoadLibrary('MakeQRBarcode.dll');
    @Makebar := GetProcAddress(Moudle, 'Make');
    @Mixtext := GetProcAddress(Moudle, 'MixText');
    Txt := Trim(order_Sub.fieldbyname('Subid').AsString);
    fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
    if FileExists(fImagePath) then
      DeleteFile(fImagePath);
    Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);

    with ADOCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from TP_File ');
      sql.Add('where TFID=' + quotedstr(trim(Txt)));
      sql.Add('and TFType=''EWM''');
      open;
      if isempty then
      begin
        append;
        fieldbyname('TFID').Value := trim(Txt);
        fieldbyname('WBID').Value := trim(order_Sub.fieldbyname('Mainid').AsString);
        fieldbyname('TFType').Value := 'EWM';
        fieldbyname('FillTime').Value := SGetServerDateTime(ADOTemp);
        tblobfield(FieldByName('Filesother')).LoadFromFile(fImagePath);
        post;
      end;
    end;
  except
    application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
    order_Sub.EnableControls;
    exit;
  end;
end;

function TfrmOrderInPut.SaveData(): Boolean;
var
  maxno: string;
begin
  try

    ADOCmd.Connection.BeginTrans;
    if Trim(FMainId) = '' then
    begin
      if GetLSNo(ADOCmd, maxno, 'JM', 'JYOrder_Main', 3, 1) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!', '提示', 0);
        Exit;
      end;
    end
    else
    begin
      maxno := Trim(FMainId);
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from JYOrder_Main where MainId=''' + Trim(FMainId) + '''');
      Open;
    end;

    if PState = 0 then
    begin
      with ADOCmd do
      begin
        if Trim(FMainId) = '' then
        begin
          Append;
        end
        else
        begin
          Edit;
        end;
        FieldByName('MainId').Value := Trim(maxno);
        SSetsaveSqlNew(ADOCmd, 'JYOrder_Main', ScrollBox1, 2);
        if Trim(FMainId) = '' then
        begin
          FieldByName('Filler').Value := Trim(DName);
          FieldByName('Filltime').Value := SGetServerDateTime(ADOTemp);
        end
        else
        begin
          FieldByName('Editer').Value := Trim(DName);
          FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
        end;
        FieldByName('LBNameNote').Value := Trim(LBNameNote.Text);
        FieldByName('MaiTouNote').Value := MaiTouNote.Text;
        FieldByName('editcnt').Value := strtointdef(trim(editcnt.Text), 0);
        FieldByName('PBPrice').Value := strtofloatdef(trim(PBPrice.Text), 0);
        FieldByName('PBQty').Value := strtofloatdef(trim(PBQty.Text), 0);
        FieldByName('Orddefstr15').Value := '按缸号生成';
        FieldByName('status').Value := '0';
        Post;
      end;
    end;

    if PState = 1 then
    begin
      with ADOCmd do
      begin
        if Trim(FMainId) = '' then
        begin
          Append;
        end
        else
        begin
          Edit;
        end;
        FieldByName('MainId').Value := Trim(maxno);
        SSetsaveSqlNew(ADOCmd, 'JYOrder_Main', ScrollBox1, 2);
        if Trim(FMainId) = '' then
        begin
          FieldByName('Filler').Value := Trim(DName);
          FieldByName('Filltime').Value := SGetServerDateTime(ADOTemp);
        end
        else
        begin
          FieldByName('Editer').Value := Trim(DName);
          FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
        end;
        FieldByName('LBNameNote').Value := Trim(LBNameNote.Text);
        FieldByName('MaiTouNote').Value := MaiTouNote.Text;
        FieldByName('editcnt').Value := strtointdef(trim(editcnt.Text), 0);
        FieldByName('PBPrice').Value := strtofloatdef(trim(PBPrice.Text), 0);
        FieldByName('PBQty').Value := strtofloatdef(trim(PBQty.Text), 0);
//        FieldByName('Orddefstr15').Value := '按缸号生成';
        FieldByName('status').Value := '0';
        Post;
      end;
    end;

//    with ADOCmd do
//    begin
//      if Trim(FMainId) = '' then
//      begin
//        Append;
//      end
//      else
//      begin
//        Edit;
//      end;
//      FieldByName('MainId').Value := Trim(maxno);
//      SSetsaveSqlNew(ADOCmd, 'JYOrder_Main', ScrollBox1, 2);
//      if Trim(FMainId) = '' then
//      begin
//        FieldByName('Filler').Value := Trim(DName);
//        FieldByName('Filltime').Value := SGetServerDateTime(ADOTemp);
//      end
//      else
//      begin
//        FieldByName('Editer').Value := Trim(DName);
//        FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
//      end;
//      FieldByName('LBNameNote').Value := Trim(LBNameNote.Text);
//      FieldByName('MaiTouNote').Value := MaiTouNote.Text;
//      FieldByName('editcnt').Value := strtointdef(trim(editcnt.Text), 0);
//      FieldByName('PBPrice').Value := strtofloatdef(trim(PBPrice.Text), 0);
//      FieldByName('PBQty').Value := strtofloatdef(trim(PBQty.Text), 0);
//      FieldByName('Orddefstr15').Value := '按缸号生成';
//      FieldByName('status').Value := '0';
//      Post;
//    end;

    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Main where orderno=''' + Trim(OrderNo.Text) + '''');
      Open;
    end;
    if ADOCmd.RecordCount > 1 then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('指示单号重复!', '提示', 0);
      Exit;
    end;
    FMainId := Trim(maxno);

    if PState = 1 then
    begin
      with ADOCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
        sql.Add(' ' + quotedstr(trim(DName)));
        sql.Add(',getdate() ');
        sql.Add(',' + quotedstr(trim(self.Caption)));
        sql.Add(',' + quotedstr(trim('指示单修改')));
        sql.Add(',' + quotedstr(trim('修改前指示单号：' + trim(forderno))) + quotedstr(trim('修改后指示单号：' + trim(OrderNo.text))));
        sql.Add(',' + quotedstr(trim('成功')));
        sql.Add(')');
        ExecSQL;
      end;
    end;

    if PState = 0 then
    begin
      with ADOCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
        sql.Add(' ' + quotedstr(trim(DName)));
        sql.Add(',getdate() ');
        sql.Add(',' + quotedstr(trim(self.Caption)));
        sql.Add(',' + quotedstr(trim('指示单新增')));
        sql.Add(',' + quotedstr(trim('指示单号：' + trim(OrderNo.text))));
        sql.Add(',' + quotedstr(trim('成功')));
        sql.Add(')');
        ExecSQL;
      end;
    end;



    ///保存子表
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, maxno, 'JS', 'JYOrder_Sub', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxno := Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_Sub where MainId=''' + Trim(FMainId) + '''');
          sql.Add(' and SubId=''' + Trim(maxno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('SubId').AsString) = '' then
          begin
            Append;
          end                                 
          else
            Edit;
          FieldByName('MainId').Value := Trim(FMainId);
          FieldByName('SubId').Value := Trim(maxno);
          RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'JYOrder_Sub', 0);
          fieldbyname('PRTColor').Value := Order_Sub.fieldbyname('SOrddefstr1').AsString;
          fieldbyname('PRTMF').Value := Order_Sub.fieldbyname('PRTMF').AsString;
          fieldbyname('PRTKZ').Value := Order_Sub.fieldbyname('PRTKZ').AsString;
          if Trim(fieldbyname('PRTOrderQty').AsString) = '' then
          begin
            fieldbyname('PRTOrderQty').Value := 0
          end;
          if Trim(fieldbyname('PRTPrice').AsString) = '' then
          begin
            fieldbyname('PRTPrice').Value := 0
          end;
          fieldbyname('Machi').Value := '1';
          fieldbyname('SordQty1').Value := Order_Sub.fieldbyname('SordQty1').AsFloat;
          fieldbyname('SordQty2').Value := Order_Sub.fieldbyname('SordQty2').AsFloat;
          fieldbyname('SordQty3').Value := Order_Sub.fieldbyname('SordQty3').AsFloat;
          FieldByName('Sorddefstr10').Value := Order_Sub.FieldByName('Sorddefstr10').AsString;
          FieldByName('khOrderNO').Value := trim(Order_Sub.FieldByName('khOrderNO').AsString);
          FieldByName('SLBName').Value := ExtractFileName(trim(SLBName.Text));
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value := Trim(maxno);
        Order_Sub.FieldByName('Mainid').Value := Trim(FMainId);
        CJEWM();
        Next;
      end;
    end;

    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

function TfrmOrderInPut.SaveDataMain(): Boolean;
var
  maxno: string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from JYOrder_Main where MainId=''' + Trim(FMainId) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId) = '' then
      begin
        Append;
        maxno := Trim(FFMainId);
      end
      else
      begin
        maxno := Trim(FMainId);
        Edit;
      end;
      FieldByName('MainId').Value := Trim(maxno);
      SSetsaveSqlNew(ADOCmd, 'JYOrder_Main', ScrollBox1, 2);
      if PState = 1 then
      begin
        FieldByName('OrdUpDate').Value := SGetServerDateTime(ADOTemp);
      end;
      if Trim(FMainId) = '' then
      begin
        FieldByName('Filler').Value := Trim(DName);
      end
      else
      begin
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
      end;
      Post;
    end;
    FMainId := Trim(maxno);
    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

function TfrmOrderInPut.SaveDataSubOne(): Boolean;
var
  maxno: string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存子表
    with Order_Sub do
    begin
      //First;
      //while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString) = '' then
        begin
          if GetLSNo(ADOTemp, maxno, 'JS', 'JYOrder_Sub', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxno := Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_Sub where MainId=''' + Trim(FMainId) + '''');
          sql.Add(' and SubId=''' + Trim(maxno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('SubId').AsString) = '' then
            Append
          else
            Edit;
          FieldByName('MainId').Value := Trim(FMainId);
          FieldByName('SubId').Value := Trim(maxno);
          RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'JYOrder_Sub', 0);
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value := Trim(maxno);
        //Order_Sub.Post;
        //Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常！', '提示', 0);
  end;
end;

function TfrmOrderInPut.SaveDataSubMore(): Boolean;
var
  maxno: string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存子表
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString) = '' then
        begin
          if GetLSNo(ADOTemp, maxno, 'JS', 'JYOrder_Sub', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxno := Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_Sub where MainId=''' + Trim(FMainId) + '''');
          sql.Add(' and SubId=''' + Trim(maxno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('SubId').AsString) = '' then
            Append
          else
            Edit;
          FieldByName('MainId').Value := Trim(FMainId);
          FieldByName('SubId').Value := Trim(maxno);
          RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'JYOrder_Sub', 0);
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value := Trim(maxno);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常！', '提示', 0);
  end;
end;

procedure TfrmOrderInPut.TBSaveClick(Sender: TObject);
begin
  OrdDate.SetFocus;
  if Trim(OrderNo.Text) = '' then
  begin
    Application.MessageBox('指示单号不能为空！', '提示', 0);
    Exit;
  end;
{  if Order_Sub.Locate('PRTColor',null,[])=True then
  begin
    Application.MessageBox('颜色不能为空!','提示',0);
    Exit;
  end; }
//  if order_Sub.Locate('OrderUnit', null, []) = true then
//  begin
//    application.messagebox('数量单位不能为空', '提示');
//    exit;
//  end;

  if Order_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!', '提示', 0);
    Exit;
  end;

  if PState = 1 then
  begin

  end;

  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
    ModalResult := 1;
  end;
end;

procedure TfrmOrderInPut.v1PRTColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'OrdColor';
      flagname := '颜色';
      V1Name.Caption := '中文名称';
      V1Note.Caption := '英文名称';
 //     MainType:=Trim(DName);
      fnote := True;
      if ShowModal = 1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PRTColor').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.Order_Sub.FieldByName('SOrddefstr4').Value := Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.ToolButton1Click(Sender: TObject);
var
  i: Integer;
begin
  Tv1.Columns[0].FocusWithSelection;
  if Trim(OrderNo.Text) = '' then
  begin
    Application.MessageBox('订单号不能为空!', '提示', 0);
    Exit;
  end;
  i := Order_Sub.RecordCount;
  i := i + 1;
  CopyAddRow(Tv1, Order_Sub);

  with Order_Sub do
  begin
    Edit;
    FieldByName('XHNO').Value := IntToStr(i);
    if Edit7.Text = '√' then  //色号
    begin
//      FieldByName('prtganghao').Value := StrToFloatDef((Order_Sub.fieldbyname('prtganghao').AsString), 0) + 1;
      FieldByName('SOrddefstr1').Value := StrToFloatDef((Order_Sub.fieldbyname('SOrddefstr1').AsString), 0) + 1;
    end;
    if Edit1.Text = '√' then //缸号
    begin
      FieldByName('prtganghao').Value := StrToFloatDef((Order_Sub.fieldbyname('prtganghao').AsString), 0) + 1;
//      FieldByName('SOrddefstr1').Value := StrToFloatDef((Order_Sub.fieldbyname('SOrddefstr1').AsString), 0) + 1;
    end;
    FieldByName('PRTColor').Value := '';
    FieldByName('PRTOrderQty').Value := null;
    FieldByName('PRTPrice').Value := 0;
    FieldByName('SOrddefstr4').Value := null;
    FieldByName('SOrddefstr2').Value := null;
    FieldByName('SOrddefstr10').Value := null;
    FieldByName('hxFile').Value := '';
    Post;
  end;
end;

procedure TfrmOrderInPut.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then
    Exit;

  if Trim(Order_Sub.fieldbyname('SubId').AsString) <> '' then
  begin
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete TP_File where WBID=''' + Trim(Order_Sub.fieldbyname('SubId').AsString) + ''' and TFType=''EWM'' ');
      ExecSQL;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_Sub where SubId=''' + Trim(Order_Sub.fieldbyname('SubId').AsString) + '''');
      ExecSQL;
    end;
  end;
  Order_Sub.Delete;
 { if Order_Sub.IsEmpty then
  begin
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_Main where MainId='''+Trim(FMainId)+'''');
      ExecSQL;
    end;
  end;  }
end;

procedure TfrmOrderInPut.RanFactoryBtnUpClick(Sender: TObject);
begin
  {try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='RKPlace';
      flagname:='染厂名称';    
      if ShowModal=1 then
      begin
        JGFactoryName.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        JGFactoryName.TxtCode:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end; }
end;

procedure TfrmOrderInPut.CustomerNoNameBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'CustomerNoName';
      flagname := '客户名称';
      if Trim(DParameters1) <> '高权限' then
        MainType := Trim(DName);
      if ShowModal = 1 then
      begin
        CustomerNoName.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        CustomerNoName.TxtCode := Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.CustomerNoNameBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text := '';
  TBtnEditC(Sender).TxtCode := '';
end;

procedure TfrmOrderInPut.MPRTCodeNameBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'MPRTCodeName';
      flagname := '产品名称';
      //fnote:=True;
      //V1Note.Caption:='产品编号';
      if ShowModal = 1 then
      begin
        MPRTCodeName.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        //MPRTCode.Text:=Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.NoteDblClick(Sender: TObject);
begin
  {try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='OrdNote';
      flagname:='备注及要求';
      if ShowModal=1 then
      begin
        Note.Text:=Note.Text+frmZDYHelpSel.ReturnStr;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;}
end;

procedure TfrmOrderInPut.v1OrderUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'OrderUnit';
      flagname := '数量单位';
      if ShowModal = 1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('OrderUnit').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.v1PriceUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'PriceUnit';
      flagname := '价格单位';
      if Trim(DParameters1) <> '高权限' then
      begin
        TBAdd.Visible := False;
        TBEdit.Visible := False;
        TBDel.Visible := False;
      end;

      if ShowModal = 1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PriceUnit').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.OrdDefStr2BtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if Trim(flag) = 'OrdDefStr2' then
      begin
        V1Name.Caption := '中文名称';
        V1Note.Caption := '英文名称';
        fnote := True;
      end;
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        if Trim(flag) = 'MPRTCode' then
        begin
          with ADOTemp do
          begin
            Close;
            sql.Clear;
            sql.Add('select Top 1 * from JYOrder_Main where MPRTCode=''' + Trim(ClientDataSet1.fieldbyname('ZDYName').AsString) + '''');
            sql.Add(' order by FillTime desc');
            Open;
          end;
          MPRTCodeName.Text := ADOTemp.fieldbyname('MPRTCodeName').AsString;
          MPRTMF.Text := ADOTemp.fieldbyname('MPRTMF').AsString;
          MPRTKZ.Text := ADOTemp.fieldbyname('MPRTKZ').AsString;
          MPRTSpec.Text := ADOTemp.fieldbyname('MPRTSpec').AsString;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.ConNoKeyPress(Sender: TObject; var Key: Char);
var
  ConMainId: string;
begin
  if Key = #13 then
  begin
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrderCon_Main where ConNo like ''' + '%' + Trim(ConNo.Text) + '%' + '''');
      Open;
    end;
    if ADOTemp.RecordCount > 1 then
    begin
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select Top 1* from JYOrderCon_Main where ConNo=''' + Trim(ConNo.Text) + '''');
        Open;
      end;
      if ADOTemp.IsEmpty then
        Exit;
    end
    else if ADOTemp.RecordCount = 1 then
    begin
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from JYOrderCon_Main where ConNo like ''' + '%' + Trim(ConNo.Text) + '%' + '''');
        Open;
      end;
    end;
    begin
      ConNo.Text := Trim(ADOTemp.fieldbyname('ConNo').AsString);
      //OrdDefStr1.Text:=Trim(ADOTemp.fieldbyname('ConDefStr1').AsString);
      MPRTCodeName.Text := Trim(ADOTemp.fieldbyname('MPRTCodeName').AsString);
      MPRTZHName.Text := Trim(ADOTemp.fieldbyname('CPZHName').AsString);
      MPRTMF.Text := Trim(ADOTemp.fieldbyname('MPRTMF').AsString);
      MPRTKZ.Text := Trim(ADOTemp.fieldbyname('MPRTKZ').AsString);
      MPRTChuanY.Text := Trim(ADOTemp.fieldbyname('ChuanYangNote').AsString);
      MPRTQtyNote.Text := Trim(ADOTemp.fieldbyname('QtyNote').AsString);
      CustomerNoName.Text := Trim(ADOTemp.fieldbyname('CustomerNoName').AsString);
      CustomerNoName.TxtCode := Trim(ADOTemp.fieldbyname('CustomerNo').AsString);
      DLYDate.DateTime := ADOTemp.fieldbyname('DLYDate').Value;
      ConMainId := Trim(ADOTemp.fieldbyname('MainId').AsString);
     // ConGS:=Trim(ADOTemp.fieldbyname('SYRName').AsString);
      //OrdDefStr2.Text:=Trim(ADOTemp.fieldbyname('ConDefStr2').AsString);
      with ADOTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select A.*,ColorName=(select ZdyName from KH_Zdy B where B.Note=A.PRTColor and B.Type=''OrdColor'' ) ');
        SQL.Add(' from JYOrderCon_Sub A where MainId=''' + Trim(ConMainId) + '''');
        Open;
      end;
      with ADOTemp do
      begin
        First;
        while not Eof do
        begin
          with Order_Sub do
          begin
            Append;
            FieldByName('PRTColor').Value := Trim(ADOTemp.fieldbyname('PRTColor').AsString);
            FieldByName('SOrdDefStr4').Value := Trim(ADOTemp.fieldbyname('SOrdDefStr4').AsString);
            FieldByName('SOrdDefStr3').Value := Trim(ADOTemp.fieldbyname('SOrdDefStr3').AsString);
            FieldByName('PRTOrderQty').Value := Trim(ADOTemp.fieldbyname('PRTOrderQty').AsString);
            FieldByName('OrderUnit').Value := Trim(ADOTemp.fieldbyname('OrderUnit').AsString);
            FieldByName('PRTPrice').Value := Trim(ADOTemp.fieldbyname('PRTPrice').AsString);
            FieldByName('PriceUnit').Value := Trim(ADOTemp.fieldbyname('PriceUnit').AsString);
            FieldByName('PRTHX').Value := Trim(ADOTemp.fieldbyname('PRTHX').AsString);
            FieldByName('XHNO').Value := Trim(ADOTemp.fieldbyname('XHNO').AsString);
            FieldByName('Sorddefstr10').Value := Trim(ADOTemp.fieldbyname('SUBID').AsString);

            Post;
          end;
          Next;
        end;
      end;
    end;

  end;
end;

procedure TfrmOrderInPut.ToolButton3Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then
    Exit;
  OneKeyPost(Tv1, Order_Sub);
end;

procedure TfrmOrderInPut.YCLFactoryBtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      MainType := TEdit(Sender).Name;
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelpSel := TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := ReturnStr;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmOrderInPut.Label36DblClick(Sender: TObject);
begin
  try
    frmZDYHelpSel := TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag := 'LbNameNote';
      flagname := '标签内容';
      if ShowModal = 1 then
      begin
        ClientDataSet1.DisableControls;
        //LBNameNote.Text:='';
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if ClientDataSet1.FieldByName('SSel').AsBoolean = True then
            begin
              if Trim(Self.LBNameNote.Text) = '' then
              begin
                Self.LBNameNote.Text := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
              end
              else
              begin
                Self.LBNameNote.Text := Self.LBNameNote.Text + #13 + #10 + Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
              end;

            end;
            Next;
          end;
        end;
        ClientDataSet1.EnableControls;
      end;
    end;
  finally
  end;
end;

procedure TfrmOrderInPut.Label37DblClick(Sender: TObject);
begin
  try
    frmZDYHelpSel := TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag := 'MaitouNote';
      flagname := '唛头内容';
      if ShowModal = 1 then
      begin
        ClientDataSet1.DisableControls;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if ClientDataSet1.FieldByName('SSel').AsBoolean = True then
            begin
              if Trim(Self.MaitouNote.Text) = '' then
              begin
                Self.MaitouNote.Text := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
              end
              else
              begin
                Self.MaitouNote.Text := Self.MaitouNote.Text + #13 + #10 + Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
              end;

            end;
            Next;
          end;
        end;
        ClientDataSet1.EnableControls;
      end;
    end;
  finally
  end;
end;

procedure TfrmOrderInPut.SYRNameBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'OrdDefStr2';
      flagname := '公司抬头';
      V1Name.Caption := '中文名称';
      V1Note.Caption := '英文名称';
      fnote := True;
    {  if Trim(DParameters1)<>'高权限' then
      begin
        TBAdd.Visible:=False;
        TBEdit.Visible:=false;
        TBDel.Visible:=false;
        TBSave.Visible:=false;
      end;   }
      if ShowModal = 1 then
      begin
        SYRName.Text := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.MPRTBZNoteDblClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
  i: integer;
begin
  fsj := Trim(TMemo(Sender).Hint);
  FWZ := Pos('/', fsj);
  i := 0;
  try
    frmZDYHelpSel := TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if ShowModal = 1 then
      begin
        MPRTBZNote.Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean = True then
            begin
              i := i + 1;
              MPRTBZNote.Lines.Add(inttostr(i) + '.' + FieldByName('ZDYName').AsString)
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmOrderInPut.MPRTSCTeBieNoteDblClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
  i: integer;
begin
  fsj := Trim(TMemo(Sender).Hint);
  FWZ := Pos('/', fsj);
  i := 0;
  try
    frmZDYHelpSel := TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if ShowModal = 1 then
      begin
        MPRTSCTeBieNote.Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean = True then
            begin
              i := i + 1;
              MPRTSCTeBieNote.Lines.Add(inttostr(i) + '.' + FieldByName('ZDYName').AsString)
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmOrderInPut.v1PRTCodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'PRTCodeName';
      flagname := '产品名称';
      if ShowModal = 1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PRTCodeName').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.FileNameClick(Sender: TObject);
begin
  if trim(OrderNo.Text) = '' then
  begin
    application.MessageBox('订单号不能为空！', '提示信息', MB_ICONERROR);
    exit;
  end;

  try
    FormGetPic := TFormGetPic.Create(Application);
    with FormGetPic do
    begin
     // fkeyNO:=trim(Order_Sub.fieldbyname('subID').AsString);
      fkeyNO := trim(OrderNo.Text);
      pat1 := TCXbutton(Sender).Name;
      pic1 := TCXbutton(Sender).Hint;
      FTFType := 'ORDERTY';
 //   pat1:='PatFile1';
//   pic1:='Picture1';
      if ShowModal = 1 then
      begin
     // self.Timage(Tbutton(Sender).Hint).Picture.Assign(FormGetPic.Image2.Picture.Bitmap);
        OrderNo.Enabled := false;
      end;

      Release;
    end;
    Initimage();
  except
    if FormGetPic <> nil then
      FormGetPic.Release;
  end;
end;

procedure TfrmOrderInPut.v1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
var
  mvalue, fieldname: string;
begin
  fieldname := Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with Order_Sub do
  begin
    Edit;
    FieldByName(Trim(fieldname)).Value := TcxTextEdit(Sender).EditingText;
    if (1 - FieldByName('SordQty1').AsFloat / 100.00) <> 0 then
      FieldByName('SordQty3').Value := format('%.0f', [FieldByName('PRTOrderQty').AsFloat * (1 + FieldByName('SordQty2').AsFloat / 100.00) / (1 - FieldByName('SordQty1').AsFloat / 100.00)]);
    Post;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmOrderInPut.v1Column9PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  FormGetPic := TFormGetPic.create(self);
  with FormGetPic do
  begin
    fFlileFlag := self.fFlileFlag;
    fkeyNo := Order_Sub.fieldbyname('HXFile').asstring;
    pat1 := 'FileName';
    pic1 := 'FilesOther';
    FTFType := 'HX';
    if showmodal = 1 then
    begin
      Order_Sub.edit;
      Order_Sub.fieldbyname('HXFile').Value := trim(fkeyNo);
    end;
    free;
  end;
end;

procedure TfrmOrderInPut.Button1Click(Sender: TObject);
var
  fFileName: string;
begin
  if trim(OrderNo.Text) = '' then
  begin
    application.MessageBox('订单号不能为空', '提示信息', 0);
    exit;
  end;

  with RMGridReport2 do
  begin
    InitDataSetDictionary();
    RMDS_Main.DataSet := nil;
    Dictionary.FieldAliases.Clear;
    Dictionary.FieldAliases['RMDS_Main'] := '标签数据';
    RMDS_Main.DataSet := ADOQuery_label;
    if trim(SLBName.Text) <> '' then
    begin
      if FileExists(trim(SLBName.Text)) then
        LoadFromFile(trim(SLBName.Text))
      else
        LoadFromFile(ExtractFilePath(Application.ExeName) + 'report\' + trim(SLBName.Text));
    end
    else
      LoadFromFile(ExtractFilePath(Application.ExeName) + 'report\标签模板.rmf');
    application.ProcessMessages;
    DesignReport();
    fFileName := ExtractFilePath(Application.ExeName) + 'report\' + trim(OrderNO.Text) + '.rmf';

    RMGridReport2.SaveToFile(fFileName);
    SLBName.Text := fFileName;
 //   RMGridReport1.NewReport;
    RMGridReport1.LoadFromFile(fFileName);
    RMGridReport1.Preview := RMPreview1;
    RMGridReport1.PrepareReport;
    RMGridReport1.ShowReport;
    ExportToFtErp(fFileName, ADOCmd);
  end;
end;

procedure TfrmOrderInPut.SLBNameBtnClick(Sender: TObject);
begin
  if trim(OrderNo.Text) = '' then
  begin
    application.MessageBox('订单号不能为空', '提示信息', 0);
    exit;
  end;
  if OpenDialog1.Execute() then
  begin
    InitDataSetDictionary();
    SLBName.Text := OpenDialog1.FileName;
    RMGridReport1.LoadFromFile(SLBName.Text);
    RMGridReport1.Preview := RMPreview1;
    RMGridReport1.ShowReport;
  end;
end;

procedure TfrmOrderInPut.Edit7Click(Sender: TObject);
begin
  if Trim(Edit7.Text) = '' then
  begin
    Edit7.Text := '√';
  end
  else
  begin
    Edit7.Text := '';
  end;
end;

procedure TfrmOrderInPut.Edit1Click(Sender: TObject);
begin
  if Trim(Edit1.Text) = '' then
  begin
    Edit1.Text := '√';
  end
  else
  begin
    Edit1.Text := '';
  end;
end;

end.

