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;

type
  TfrmJYJT_New = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    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;
    KHName: 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;
    Label5: TLabel;
    JYType: TComboBox;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure MLOrderNoChange(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 RadioGroup1Click(Sender: TObject);
    procedure Aorddefstr1Change(Sender: TObject);
    procedure MLOrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure PRTColorChange(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure v1Column15PropertiesEditValueChanged(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure ISbaoChange(Sender: TObject);
    procedure gangNOKeyPress(Sender: TObject; var Key: Char);
    procedure MLConNoKeyPress(Sender: TObject; var Key: Char);
  private
    DQdate:TDateTime;
    FLeft,FTop:Integer;
    canshu1:string;
    procedure InitGrid();
    procedure InitForm();
    function  Savedata():Boolean;
    procedure GetCDSData();
    procedure GetBGData();
    { Private declarations }
  public
    FFInt:Integer;
    { Public declarations }
  end;

var
  frmJYJT_New: TfrmJYJT_New;

implementation
uses
  U_DataLink,U_Fun, U_ZDYHelp;

{$R *.dfm}

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);
end;

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

procedure TfrmJYJT_New.InitGrid();
var
  i:integer;
  j:Integer;
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select A.*,B.*,C.* 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.FillTime>='''+trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
      sql.add(' and A.Filltime<'''+trim(FormatDateTime('yyyy-MM-dd',enddate.Date+1))+'''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
    TBFind.Click;
  end;
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.TBFindClick(Sender: TObject);
var
  fsj,fwhere:String;
begin
  if ADOQueryMain.Active=False then Exit;
  fwhere:=SGetFilters(Panel1,1,2);
  SDofilter(ADOQueryMain,fwhere);
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
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;
  MovePanel2.Left:=(self.Width-MovePanel2.Width) div 2;
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible:=False;
end;

procedure TfrmJYJT_New.MLOrderNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmJYJT_New.FormShow(Sender: TObject);
begin
  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
  SelOKNo(Order_Main,True);
end;

procedure TfrmJYJT_New.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main,False);
end;

procedure TfrmJYJT_New.TBZFClick(Sender: TObject);
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 ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('delete JTJY_New where JYID='''+Trim(Order_Main.fieldbyname('JYID').AsString)+'''');
          ExecSQL;
        end;
        Order_Main.Delete;
      end
      else
      Next;
    end;
  end;
  Order_Main.EnableControls;
end;

procedure TfrmJYJT_New.RadioGroup1Click(Sender: TObject);
begin
  TBFind.Click;
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.Aorddefstr1Change(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmJYJT_New.MLOrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    MovePanel2.Visible:=True;
    MovePanel2.Refresh;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.Add('select A.*,B.*,C.* 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 B.MLOrderNo like '''+'%'+trim(MLOrderNo.Text)+'%'+'''');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,Order_Main);
      SInitCDSData20(ADOQueryMain,Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
    MovePanel2.Visible:=False;
  end;
end;

procedure TfrmJYJT_New.PRTColorChange(Sender: TObject);
begin
  TBFind.Click;
  if Order_Main.IsEmpty=False then
  begin
    //InitOrderColor(Trim(Order_Main.fieldbyname('MainId').AsString),PRTColor,ADOQueryTemp);
   // InitBCGangNo(Trim(Order_Main.fieldbyname('SubId').AsString),AOrdDefStr1,ADOQueryTemp);
  end;
end;

procedure TfrmJYJT_New.Tv1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if Order_Main.IsEmpty=False then
  begin
  //  InitOrderColor(Trim(Order_Main.fieldbyname('MainId').AsString),PRTColor,ADOQueryTemp);
  //  InitBCGangNo(Trim(Order_Main.fieldbyname('SubId').AsString),AOrdDefStr1,ADOQueryTemp);
  //  InitRCGangNo(Trim(Order_Main.fieldbyname('SubId').AsString),GangNo,ADOQueryTemp);
  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.ISbaoChange(Sender: TObject);
begin
  Tbfind.Click;
end;

procedure TfrmJYJT_New.gangNOKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    MovePanel2.Visible:=True;
    MovePanel2.Refresh;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.Add('select A.*,B.*,C.* 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.gangNO like '''+'%'+trim(gangNO.Text)+'%'+'''');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,Order_Main);
      SInitCDSData20(ADOQueryMain,Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
    MovePanel2.Visible:=False;
  end;
end;

procedure TfrmJYJT_New.MLConNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    MovePanel2.Visible:=True;
    MovePanel2.Refresh;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.Add('select A.*,B.*,C.* 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 B.MLConNo like '''+'%'+trim(MLConNo.Text)+'%'+'''');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,Order_Main);
      SInitCDSData20(ADOQueryMain,Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
    MovePanel2.Visible:=False;
  end;
end;

end.
