unit U_JYJT_New;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, MovePanel, cxTextEdit,
  cxContainer, cxCurrencyEdit, BtnEdit, RM_e_main, RM_e_htm, RM_e_Graphic,
  RM_e_Jpeg, RM_e_txt, RM_e_csv, RM_E_llPDF, Math, cxPC, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu;

type
  TfrmJYJT_New = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    MLOrderNo: TEdit;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    MLConNo: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Label10: TLabel;
    JYNo: TEdit;
    Label2: TLabel;
    MLCodeName: TEdit;
    Panel4: TPanel;
    Label11: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    RichEdit1: TRichEdit;
    v1MLOrderNo: TcxGridDBColumn;
    v1GangNo: TcxGridDBColumn;
    v1KHName: TcxGridDBColumn;
    v1JYType: TcxGridDBColumn;
    v1JYKG: TcxGridDBColumn;
    v1JYLen: TcxGridDBColumn;
    v1JYUnit: TcxGridDBColumn;
    Label4: TLabel;
    v1MLCodeName: TcxGridDBColumn;
    v1RKType: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1FillTime: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    v1JYNo: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    TBZF: TToolButton;
    RM2: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    MovePanel2: TMovePanel;
    v1JYPZ: TcxGridDBColumn;
    v1JYJZ: TcxGridDBColumn;
    CDS_CD: TClientDataSet;
    RMCD: TRMGridReport;
    RMDBCD: TRMDBDataSet;
    CDS_LS: TClientDataSet;
    Label14: TLabel;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    KHNameJC: TEdit;
    gangNO: TEdit;
    MLColor: TEdit;
    RM3: TRMGridReport;
    v1Column31: TcxGridDBColumn;
    v1MLConNo: TcxGridDBColumn;
    Label22: TLabel;
    ISHZ: TComboBox;
   // RMllPDFExport1: TRMllPDFExport;
    RMXLSExport1: TRMXLSExport;
    CDS_HZ: TClientDataSet;
    RMDBHZ: TRMDBDataSet;
    RMDBPRT: TRMDBDataSet;
    CDS_PRT: TClientDataSet;
    v1MLColorNo: TcxGridDBColumn;
    v1MLHX: TcxGridDBColumn;
    Filler: TEdit;
    IsJYTime: TCheckBox;
    Panel6: TPanel;
    LBCPAP: TLabel;
    Label1: TLabel;
    BTLP: TButton;
    BTNP: TButton;
    TCBNOR: TComboBox;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1Column4: TcxGridDBColumn;
    Label6: TLabel;
    JYID: TEdit;
    cxTabControl1: TcxTabControl;
    Label9: TLabel;
    HZPS: TEdit;
    Label12: TLabel;
    HZQty: TEdit;
    Panel2: TPanel;
    Label13: TLabel;
    NewMLID: TEdit;
    ToolButton2: TToolButton;
    Panel3: TPanel;
    Label5: TLabel;
    FS: TComboBox;
    Label15: TLabel;
    RKType: TComboBox;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Label16: TLabel;
    BaoId: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Panel10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Image2Click(Sender: TObject);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBZFClick(Sender: TObject);
    procedure v1Column15PropertiesEditValueChanged(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure TCBNORChange(Sender: TObject);
    procedure MLColorKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure NewMLIDKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton2Click(Sender: TObject);
    procedure RKTypeChange(Sender: TObject);
    procedure BaoIdKeyPress(Sender: TObject; var Key: Char);
  private
    DQdate: TDateTime;
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    canshu1, FNewMLID: string;
    procedure InitGrid();
    procedure GetHZData(fwhere: string);
    procedure InitForm();
    function Savedata(): Boolean;
    procedure GetCDSData();
    procedure GetBGData();
    procedure PrtDataMD(FMJID: string);
    { Private declarations }
  public
    FFInt: Integer;
    { Public declarations }
  end;

var
  frmJYJT_New: TfrmJYJT_New;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_MJEdit, U_Fun;

{$R *.dfm}
procedure TfrmJYJT_New.PrtDataMD(FMJID: string);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
  i: Integer;
begin

  with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    sql.Add('select A.*,B.*,C.*,CPBQName1=isnull(CPBQName,''通用标签'') ');
    sql.Add(',KHNameJC=(select KHNameJC  from KH_Main KM where KM.KHNO=B.KHNO)');
    SQL.Add('from JTJY_New A ');
    SQL.Add('inner join ML_OrderMainNew B on B.NewMLID=A.NewMLID ');
    SQL.Add('inner join ML_OrderSubidNew C on C.NewSubid=A.NewSubid ');
    sql.Add('where A.JYID=''' + trim(FMJID) + '''');
    Open;
  end;
  if cxTabControl1.TabIndex = 0 then
  begin
    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(ADOQueryPrint.fieldbyname('CPBQName1').AsString) + '.rmf';
  end
  else if cxTabControl1.TabIndex = 1 then
  begin
    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\面布标签.rmf';
  end
  else if cxTabControl1.TabIndex = 2 then
  begin
    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\底布标签.rmf';
  end
  else if cxTabControl1.TabIndex = 3 then
  begin
    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(ADOQueryPrint.fieldbyname('CPBQName1').AsString) + '.rmf';
  end;

  try
    Moudle := LoadLibrary('MakeQRBarcode.dll');
    @Makebar := GetProcAddress(Moudle, 'Make');
    @Mixtext := GetProcAddress(Moudle, 'MixText');
    Txt := Trim(ADOQueryPrint.fieldbyname('JYID').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);
  except
    application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);

    exit;
  end;

  if FileExists(fPrintFile) then
  begin
    RMVariables['QRBARCODE'] := fImagePath;
    RM2.LoadFromFile(fPrintFile);
    for i := 1 to StrToInt(FS.Text) do
    begin
      RM2.PrintReport;
    end;
  end
  else
  begin
    Application.MessageBox(pchar('没有找' + fPrintFile), '提示', 0);

    exit;
  end;
end;

procedure TfrmJYJT_New.FormDestroy(Sender: TObject);
begin
  frmJYJT_New := nil;
end;

procedure TfrmJYJT_New.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfrmJYJT_New.FormCreate(Sender: TObject);
begin
  cxgrid1.Align := alClient;
  DQdate := SGetServerDate(ADOQueryTemp);
  canshu1 := Trim(DParameters1);
  FNewMLID := '';
end;

procedure TfrmJYJT_New.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('检验信息管理', Tv1, '检验管理');
end;

procedure TfrmJYJT_New.InitGrid();
var
  fwhere, Pwhere: string;
begin

  HZPS.Text := '';
  HZQty.Text := '';
  MovePanel2.Left := (self.Width - MovePanel2.Width) div 2;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  Pwhere := SGetFilters(Panel1, 1, 2);

  if trim(Pwhere) <> '' then
    fwhere := fwhere + ' where ' + trim(Pwhere);

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select top ' + inttostr(RecordsNumber) + ' *  from  ');
      sql.Add('(select rownumber=Cast(row_number() over(order by AA.filltime desc) as int) ');
      sql.Add(',TotalCount=Cast(COUNT(1) OVER() AS int) ,* from (select ');
      sql.Add('  A.*  ');
      sql.Add(' ,B.MLOrderNo,B.MLConNo,B.MLCodeName,B.KHName,KM.KHNameJC ');
      sql.Add(' ,C.MLColor,C.MLColorNo,C.MLHX,C.MLColorEng,C.MLColorNoKH ');
      sql.Add(',KHConNo=(select TOP 1 X.KHConNo from ML_ConMain X where X.MLConID=B.ConMainId)');
      sql.Add('  from JTJY_New A ');
      sql.Add('inner join ML_OrderMainNew B on B.NewMLID=A.NewMLID ');
      sql.Add('inner join ML_OrderSubidNew C on C.NewSubid=A.NewSubid ');
      sql.Add('inner join KH_Main KM on B.KHNO=KM.KHNO');
      sql.Add(' where 1=1');
      if Trim(FNewMLID) <> '' then
      begin
        sql.Add(' and A.NewMLID=''' + Trim(FNewMLID) + '''');
      end;
      if IsJYTime.Checked then
      begin
        sql.Add('and A.FillTime>=''' + trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
        sql.add(' and A.Filltime<''' + trim(FormatDateTime('yyyy-MM-dd', enddate.Date + 1)) + '''');
      end;
      if cxTabControl1.TabIndex = 0 then
      begin
        sql.Add(' and JYTYpe=''成品'' ');
      end
      else if cxTabControl1.TabIndex = 1 then
      begin
        sql.Add(' and JYTYpe=''面布'' ');
      end
      else if cxTabControl1.TabIndex = 2 then
      begin
        sql.Add(' and JYTYpe=''底布'' ');
      end
      else if cxTabControl1.TabIndex = 3 then
      begin
        sql.Add(' and JYTYpe=''退货'' ');
      end;
      sql.Add('   ) AA');
      sql.Add(fwhere + ') temp_row');
      sql.Add(' where rownumber> ' + inttostr((CurrentPage - 1) * RecordsNumber));
//      ShowMessage(SQL.Text);
      Open;
    end;

    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
    LBCPAP.Caption := inttostr(CurrentPage) + '/' + inttostr(ceil(Order_Main.FieldByName('TotalCount').AsInteger / RecordsNumber));
    MovePanel2.Visible := false;
    GetHZData(fwhere);
    FNewMLID := '';
  finally
    ADOQueryMain.EnableControls;
    MovePanel2.Visible := false;
  end;
end;

procedure TfrmJYJT_New.GetHZData(fwhere: string);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add(' select HZPS=count(*),HZQty=sum(JYLen) from  ');
    sql.Add('(select  ');
    sql.Add(' * from (select ');
    sql.Add('  A.*  ');
    sql.Add(' ,B.MLOrderNo,B.MLConNo,B.MLCodeName,B.KHName,KM.KHNameJC ');
    sql.Add(' ,C.MLColor,C.MLColorNo,C.MLHX,C.MLColorEng,C.MLColorNoKH ');
    sql.Add(',KHConNo=(select TOP 1 X.KHConNo from ML_ConMain X where X.MLConID=B.ConMainId)');
    sql.Add('  from JTJY_New A ');
    sql.Add('inner join ML_OrderMainNew B on B.NewMLID=A.NewMLID ');
    sql.Add('inner join ML_OrderSubidNew C on C.NewSubid=A.NewSubid ');
    sql.Add('inner join KH_Main KM on B.KHNO=KM.KHNO');
    sql.Add(' where 1=1');
    if Trim(FNewMLID) <> '' then
    begin
      sql.Add(' and A.NewMLID=''' + Trim(FNewMLID) + '''');
    end;
    if IsJYTime.Checked then
    begin
      sql.Add('and A.FillTime>=''' + trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
      sql.add(' and A.Filltime<''' + trim(FormatDateTime('yyyy-MM-dd', enddate.Date + 1)) + '''');
    end;
    if cxTabControl1.TabIndex = 0 then
    begin
      sql.Add(' and JYTYpe=''成品'' ');
    end
    else if cxTabControl1.TabIndex = 1 then
    begin
      sql.Add(' and JYTYpe=''面布'' ');
    end
    else if cxTabControl1.TabIndex = 2 then
    begin
      sql.Add(' and JYTYpe=''底布'' ');
    end
    else if cxTabControl1.TabIndex = 3 then
    begin
      sql.Add(' and JYTYpe=''退货'' ');
    end;
    sql.Add('   ) AA');
    sql.Add(fwhere + ') temp_row');

    Open;
  end;
  HZPS.Text := Trim(ADOQueryTemp.fieldbyname('HZPS').AsString);
  HZQty.Text := Trim(ADOQueryTemp.fieldbyname('HZQty').AsString);
end;

procedure TfrmJYJT_New.InitForm();
var
  fsj: string;
begin
  ReadCxGrid('检验信息管理', Tv1, '检验管理');
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 1;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
//  TBZF.Visible := false;
  if canshu1 = '高权限' then
  begin
    TBZF.Visible := true;
  end;
  //InitGrid();
end;

procedure TfrmJYJT_New.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '检验报告');
end;

procedure TfrmJYJT_New.TBRafreshClick(Sender: TObject);
begin
  toolbar1.SetFocus;
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmJYJT_New.FormShow(Sender: TObject);
begin
  CurrentPage := 1;
  RecordsNumber := 500;
  InitForm();
end;

procedure TfrmJYJT_New.Panel10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  TWinControl(Panel4).Perform(WM_SYSCOMMAND, $F012, 0);
end;

procedure TfrmJYJT_New.Image2Click(Sender: TObject);
begin
  Panel4.Visible := False;
end;

procedure TfrmJYJT_New.Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FLeft := X;
  FTop := Y;
end;

procedure TfrmJYJT_New.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  Panel4.Left := FLeft;
  Panel4.Top := FTop + 110;
  Panel4.Visible := True;
  Panel4.Refresh;
  Panel10.Caption := Trim(TV1.Controller.FocusedColumn.Caption);
  RichEdit1.Text := Order_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString;
end;

procedure TfrmJYJT_New.N1Click(Sender: TObject);
begin
  SelOKNoFilter(Tv1, True);
end;

procedure TfrmJYJT_New.N2Click(Sender: TObject);
begin
  SelOKNoFilter(Tv1, False);
end;

procedure TfrmJYJT_New.TBZFClick(Sender: TObject);
var
  FYFID: string;
begin
  if Order_Main.Locate('ssel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要作废数据吗？作废后数据不能恢复。', '提示', 32 + 4) <> IDYES then
    Exit;
  Order_Main.DisableControls;
  with Order_Main do
  begin
    First;
    while not Eof do
    begin
      if Order_Main.FieldByName('SSel').AsBoolean = True then
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_MLCP_CR where MJID=' + quotedstr(Trim(Order_Main.fieldbyname('JYID').AsString)));
          sql.Add('and CRFlag=''出库'' ');
          Open;
        end;
        if ADOQueryTemp.RecordCount >= 1 then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          Application.MessageBox('已出库不能删除!', '提示', 0);
          Exit;
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from JTJY_New where JYID=''' + Trim(Order_Main.fieldbyname('JYID').AsString) + '''');
          Open;
        end;
        FYFID := Trim(ADOQueryTemp.fieldbyname('YFID').AsString);
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('delete JTJY_New where JYID=''' + Trim(Order_Main.fieldbyname('JYID').AsString) + '''');
          sql.Add('delete CK_MLCP_CR where MJID=''' + Trim(Order_Main.fieldbyname('JYID').AsString) + '''');
          sql.Add('delete CK_MLCP_KC where MJID=''' + Trim(Order_Main.fieldbyname('JYID').AsString) + '''');
          ExecSQL;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add(' exec P_Update_OrderSub :SubId');
          Parameters.ParamByName('SubId').Value := Trim(Order_Main.fieldbyname('NewSubid').AsString);
          ExecSQL;
        end;
        if cxTabControl1.TabIndex = 0 then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' exec ZDCK_Mian :MainID,:SubId,:DName');
            Parameters.ParamByName('MainID').Value := Trim(Order_Main.fieldbyname('NewMLid').AsString);
            Parameters.ParamByName('SubID').Value := Trim(Order_Main.fieldbyname('NewSubid').AsString);
            Parameters.ParamByName('DName').Value := Trim(DName);
            ExecSQL;
          end;
        end;

        if Trim(FYFID) <> '' then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' exec P_Update_THData :YFID');
            Parameters.ParamByName('YFID').Value := Trim(FYFID);
            ExecSQL;
          end;
        end;
        //更新棉&无纺布耗用
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          //实际
          sql.Add('Update ML_OrderZuHe Set MLJYQty=(select sum(JYLen) from JTJY_New A where A.NewMLID=ML_OrderZuHe.NewMLID and A.JYType=''成品'') ');
          sql.Add(' where NewMLID=''' + Trim(Order_Main.fieldbyname('NewMLid').AsString) + '''');
          sql.Add(' and isnull(MLName,'''')<>'''' and SSGS=''自己'' ');

          ExecSQL;
        end;
        //更新棉&无纺布耗用

        Order_Main.Delete;
      end
      else
        Next;
    end;
  end;
  Order_Main.EnableControls;
end;

function TfrmJYJT_New.Savedata(): Boolean;
var
  maxno, LLID: string;
  HXPS: Integer;
  HXQty, HXMQty: Double;
begin
  HXPS := 0;
  HXQty := 0;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select Top 1 * from Contract_Cloth_LL where OrdSubId=''' + Trim(Order_Main.fieldbyname('SubId').AsString) + '''');
    sql.Add(' and FirstName=''' + Trim(Order_Main.fieldbyname('AOrddefstr4').AsString) + '''');
    Open;
  end;
  LLID := Trim(ADOQueryTemp.fieldbyname('LLID').AsString);
  if Trim(LLID) = '' then
  begin
    Result := False;
    Application.MessageBox('没有相对应的加工厂!', '提示', 0);
    Exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    if GetLSNo(ADOQueryCmd, maxno, 'HX', 'Contract_Cloth_BefChkHX', 2, 1) = False then
    begin
      Result := False;
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取回修最大号失败!', '提示', 0);
      Exit;
    end;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
        if Order_Main.FieldByName('SSel').AsBoolean = True then
        begin
          HXPS := HXPS + 1;
          HXQty := HXQty + Order_Main.FieldByName('MJLen').Value;
        end;
        Next;
      end;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('');
      Open;
    end;
  except
  end;
end;

procedure TfrmJYJT_New.GetCDSData();
begin
  CDS_CD.FieldByName('MJXH').Value := CDS_LS.fieldbyname('MJXH').Value;
  CDS_CD.FieldByName('GangNo').Value := CDS_LS.fieldbyname('Aorddefstr1').Value;
  CDS_CD.FieldByName('PRTColor').Value := CDS_LS.fieldbyname('PRTColor').Value;
  CDS_CD.FieldByName('PRTEColor').Value := CDS_LS.fieldbyname('SOrddefstr4').Value;
  CDS_CD.FieldByName('MJLen').Value := CDS_LS.fieldbyname('MJLen').Value;
  CDS_CD.FieldByName('MJJZ').Value := CDS_LS.fieldbyname('MJQty4').Value;
  CDS_CD.FieldByName('MJMZ').Value := CDS_LS.fieldbyname('MJMaoZ').Value;
  CDS_CD.FieldByName('MJFK').Value := CDS_LS.fieldbyname('MJFK').Value;
  CDS_CD.FieldByName('KFQtyHZ').Value := CDS_LS.fieldbyname('KFQtyHZ').Value;
  CDS_CD.FieldByName('DengJi').Value := CDS_LS.fieldbyname('DengJi').Value;
  CDS_CD.FieldByName('PanDing').Value := CDS_LS.fieldbyname('PanDing').Value;
  CDS_CD.FieldByName('MJID').Value := CDS_LS.fieldbyname('MJID').Value;
end;

procedure TfrmJYJT_New.GetBGData();
begin

end;

procedure TfrmJYJT_New.v1Column15PropertiesEditValueChanged(Sender: TObject);
var
  mvalue: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  with Order_Main do
  begin
    Edit;
    FieldByName('PanDing').Value := Trim(mvalue);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate WFB_MJJY Set PanDing=''' + Trim(mvalue) + '''');
    SQL.Add(' where MJID=''' + Trim(Order_Main.fieldbyname('MJID').AsString) + '''');
    ExecSQL;
  end;
end;

procedure TfrmJYJT_New.CheckBox2Click(Sender: TObject);
begin
  SelOKNo(Order_Main, CheckBox2.Checked);
end;

procedure TfrmJYJT_New.BTLPClick(Sender: TObject);
begin
  if CurrentPage > 1 then
    CurrentPage := CurrentPage - 1;
  InitGrid();
end;

procedure TfrmJYJT_New.BTNPClick(Sender: TObject);
begin
  if CurrentPage < Order_Main.FieldByName('TotalCount').AsInteger / RecordsNumber then
    CurrentPage := CurrentPage + 1;
  InitGrid();
end;

procedure TfrmJYJT_New.TCBNORChange(Sender: TObject);
begin
  RecordsNumber := StrToInt(TCBNOR.Text);
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmJYJT_New.MLColorKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();

  end;
end;

procedure TfrmJYJT_New.ToolButton1Click(Sender: TObject);
var
  i: Integer;
begin
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  Order_Main.DisableControls;
  with Order_Main do
  begin
    First;
    while Locate('SSel', True, []) do
    begin
      PrtDataMD(Trim(Order_Main.fieldbyname('JYID').AsString));
      Edit;
      FieldByName('SSel').Value := False;
    end;
  end;
  Order_Main.EnableControls;

end;

procedure TfrmJYJT_New.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmJYJT_New.NewMLIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    FNewMLID := Trim(NewMLID.Text);
    NewMLID.Text := '';
    InitGrid();
  end;
end;

procedure TfrmJYJT_New.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_MLCP_CR where MJID=''' + Trim(Order_Main.fieldbyname('JYID').AsString) + ''' and CRFlag=''出库''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    Order_Main.EnableControls;
    Application.MessageBox('已产生出库数据不能删除!', '提示', 0);
    Exit;
  end;
  try
    frmMJEdit := TfrmMJEdit.Create(Application);
    with frmMJEdit do
    begin
      FJYID := Trim(Self.Order_Main.fieldbyname('JYID').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmMJEdit.Free;
  end;
end;

procedure TfrmJYJT_New.RKTypeChange(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmJYJT_New.BaoIdKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
    BaoId.Text := '';
  end;
end;

end.

