unit U_PRTOrderList;

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, RM_DsgGridReport, RM_Designer;

type
  TfrmPRTOrderList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    TBPrint: 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;
    OrderNo: TEdit;
    TBExport: TToolButton;
    v1OrderNo: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    RM11: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    v1CustomerNoName: TcxGridDBColumn;
    Label4: TLabel;
    CustomerNoName: TEdit;
    v1MPRTCodeName: TcxGridDBColumn;
    v1MPRTMF: TcxGridDBColumn;
    TBView: TToolButton;
    Label8: TLabel;
    MPRTCodeHZ: TEdit;
    v1MPRTKZ: TcxGridDBColumn;
    Label10: TLabel;
    MPRTSpec: TEdit;
    Label12: TLabel;
    MPRTKZ: TEdit;
    Label13: TLabel;
    MPRTMF: TEdit;
    ToolButton2: TToolButton;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    ComboBox1: TComboBox;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    Label9: TLabel;
    Label2: TLabel;
    ConNo: TEdit;
    LiDanPerson: TEdit;
    v1Column1: TcxGridDBColumn;
    ComboBox2: TComboBox;
    RMDBDataSet1: TRMDBDataSet;
    ToolButton3: TToolButton;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    RMXLSExport2: TRMXLSExport;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    ComboBox4: TComboBox;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    ToolButton8: TToolButton;
    ToolButton9: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure TBViewClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure ToolButton9Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
  private
    CanShu1,CanShu2:string;
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    { Private declarations }
  public
    FFInt,FCloth:Integer;

    { Public declarations }
  end;

var
  frmPRTOrderList: TfrmPRTOrderList;

implementation
uses
  U_DataLink,U_RTFun, U_ZDYHelp, U_ModuleNote,U_OrderInPutPrice;

{$R *.dfm}

procedure TfrmPRTOrderList.FormDestroy(Sender: TObject);
begin
  frmPRTOrderList:=nil;
end;

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

procedure TfrmPRTOrderList.FormCreate(Sender: TObject);
begin
  cxgrid1.Align:=alClient;
  CanShu1:=Trim(DParameters1);
  CanShu2:=Trim(DParameters2);
  DQdate:=SGetServerDate(ADOQueryTemp);
end;

procedure TfrmPRTOrderList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('指示单列表',Tv1,'生产指示单管理');
end;

procedure TfrmPRTOrderList.InitGrid();
var
  fsj:String;
begin
  fsj:='';
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.add(' exec P_View_OrderQT :WSql') ;
      if Trim(ComboBox4.Text)='按制单日期' then
      begin
        fsj:=fsj+' and OrdDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+'''';
        fsj:=fsj+' and OrdDate<'''+Trim(FormatDateTime('yyyy-MM-dd',enddate.DateTime+1))+'''';
      end else
      if Trim(ComboBox4.Text)='按打卷完成日期' then
      begin
        fsj:=fsj+' and DJFinishTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+'''';
        fsj:=fsj+' and DJFinishTime<'''+Trim(FormatDateTime('yyyy-MM-dd',enddate.DateTime+1))+'''';
      end else
      if Trim(ComboBox4.Text)='按交货日期' then
      begin
        fsj:=fsj+' and DlyDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+'''';
        fsj:=fsj+' and DlyDate<'''+Trim(FormatDateTime('yyyy-MM-dd',enddate.DateTime+1))+'''';
      end;
      Parameters.ParamByName('WSql').Value:=Trim(fsj);
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmPRTOrderList.InitForm();
begin
  ReadCxGrid('指示单列表',Tv1,'生产指示单管理');
  BegDate.DateTime:=SGetServerDate10(ADOQueryTemp)-92;
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select Top 10* from JYOrder_Main Order by FillTime desc');
    Open;
  end;
  ComboBox1.Clear;
  with ADOQueryTemp do
  begin
    First;
    while not Eof do
    begin
      ComboBox1.Items.Add(Trim(ADOQueryTemp.fieldbyname('OrderNO').AsString));
      Next;
    end;
  end;
  //InitGrid();
end;

procedure TfrmPRTOrderList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmPRTOrderList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Trim(CanShu1)<>'高权限' then
  begin
    if Trim(Order_Main.fieldbyname('FillerCode').AsString)<>Trim(DCode) then
    begin
      Application.MessageBox('不能操作他人的数据!','提示',0);
      Exit;
    end;
  end;
  try
    frmOrderInPutPrice:=TfrmOrderInPutPrice.Create(Application);
    with frmOrderInPutPrice do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FOrderNo:=Trim(Self.Order_Main.fieldbyname('OrderNo').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmOrderInPutPrice.Free;
  end;
  //RM11.Clear;
end;

procedure TfrmPRTOrderList.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
 // if Trim(CanShu1)<>'高权限' then
  begin
    if Trim(Order_Main.fieldbyname('FillerCode').AsString)<>Trim(DCode) then
    begin
      Application.MessageBox('不能操作他人的数据!','提示',0);
      Exit;
    end;
  end;

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_SXPB_CR where ORDMainIdRK='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=false then
  begin
    Application.MessageBox('已经录入入库码单不能删除数据!','提示',0);
    Exit;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_SXPB_CR where ORDMainIdCK='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=false then
  begin
    Application.MessageBox('码单已有出库数据，不能删除数据!','提示',0);
    Exit;
  end;
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from JYOrder_Main where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
    Open;
  end;
  if Trim(ADOQueryTemp.fieldbyname('SGJSSH').AsString)<>'' then
  begin
    Application.MessageBox('已填写手工损耗不能删除数据!','提示',0);
    Exit;
  end;
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select Top 1* from WFB_MJJY where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=false  then
  begin
    Application.MessageBox('已填写手工损耗不能删除数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  if DelData() then
  begin
    Order_Main.Delete;
  end;
end;

function TfrmPRTOrderList.DelData():Boolean;
begin
  try
    Result:=false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_Main where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
      sql.Add('delete JYOrder_Sub where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result:=False;
    Application.MessageBox('数据删除异常！','提示',0);
  end;
end;

procedure TfrmPRTOrderList.TBExportClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  TcxGridToExcel('指示单列表',cxGrid1);

end;

procedure TfrmPRTOrderList.TBPrintClick(Sender: TObject);
var
   fPrintFile:string;
   Porderno,PFTPUnit,LD,LDTel,GD,GDTel,CPQtyStr,BPQtyStr,QtyUnit:string;
   i,j:Integer;
begin
  if Order_Main.IsEmpty then Exit;
  if Trim(ComboBox2.Text)='' then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\生产指示单.rmf' ;
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('select C.ClothOneQty,C.MPRTOneQty,C.OneQtyUnit,C.OrderNo,C.MPRTCode,C.MPRTCodeName,C.MPRTCF '); //B.PSName,B.PSNote,
    sql.Add(' ,C.MPRTSpec,C.MPRTMF,C.MPRTKZ,C.ChuanY,C.MPRTGY,C.MPRTGYHZ,C.ORDType,D.*');
    sql.Add(',GSTT=(select Top 1 ZdyStr1 from KH_Zdy A where A.ZdyName=C.ComTaiTou)');
    sql.Add(',C.LiDanPerson,LDTel10=(select Top 1 Note from KH_Zdy KZ where KZ.ZdyName=C.LiDanPerson and KZ.Type=''LiDanPerson'' )');
    sql.Add(',MStr='''',GDTel10='''',PFTPUnit='''',PFGenDanPerson='''',PFTPPS=Null,PSName=NULl,PSNote=Null,FactoryName=Null  ');
    sql.Add(',PFDLYDate=NUll');
    sql.Add(' from JYOrder_Main C');
    sql.Add(' left join JYOrder_Sub D on C.MainId=D.MainId');
    sql.Add(' where C.MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
    SQL.Add(' order by D.SubId');
    Open;
  end;

  SCreateCDS20(ADOQueryPrint,CDS_Print);
  SInitCDSData20(ADOQueryPrint,CDS_Print);
  PFTPUnit:=Trim(CDS_Print.fieldbyname('PFTPUnit').AsString);
  LD:=Trim(CDS_Print.fieldbyname('LiDanPerson').AsString);
  LDTel:=Trim(CDS_Print.fieldbyname('LDTel10').AsString);
  GD:=Trim(CDS_Print.fieldbyname('PFGenDanPerson').AsString);
  GDTel:=Trim(CDS_Print.fieldbyname('GDTel10').AsString);
  if (CDS_Print.RecordCount mod 2)=1 then
  begin
    CDS_Print.Append;
    CDS_Print.Post;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select sum(PFTPQty) PFTPQtyHZ,sum(PFTPPS) PFTPPSHZ ');
    sql.Add(' from JYOrder_PCS_Sub A');
    SQL.Add(' inner join JYOrder_Process B on A.PSID=B.PSID');
    sql.Add(' inner join JYOrder_Main C on A.MainId=C.Mainid');
    sql.Add(' left join JYOrder_Sub D on A.Subid=D.SubId');
    sql.Add(' where A.MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
    SQL.Add(' and A.FactoryName='''+Trim(ComboBox2.Text)+'''');
    sql.Add(' group by A.FactoryName');
    Open;
  end;

  RMXLSExport2:= TRMXLSExport.Create(RMXLSExport2);

  if FileExists(fPrintFile) then
  begin
    RMVariables['ZQty']:=Order_Main.fieldbyname('ZQty').Value;
    RMVariables['OrderUnit']:=Order_Main.fieldbyname('OrderUnit').Value;
    RMVariables['QtyUnit']:=Order_Main.fieldbyname('OneQtyUnit').Value;
    RMVariables['PFTPUnitHZ']:=Trim(PFTPUnit);
    RMVariables['LD']:=Trim(LD);
    RMVariables['LDTel']:=Trim(LDTel);
    RMVariables['GD']:=Trim(GD);
    RMVariables['GDTel']:=Trim(GDTel);
    RM11.LoadFromFile(fPrintFile);
    RM11.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\生产指示单.rmf'),'提示',0);
  end;
 // Panel4.Visible:=True;
end;

procedure TfrmPRTOrderList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select Top 10* from JYOrder_Main Order by FillTime desc');
    Open;
  end;
  ComboBox1.Clear;
  with ADOQueryTemp do
  begin
    First;
    while not Eof do
    begin
      ComboBox1.Items.Add(Trim(ADOQueryTemp.fieldbyname('OrderNO').AsString));
      Next;
    end;
  end;
  if Order_Main.IsEmpty=False then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select distinct(FactoryName) FactoryName from JYOrder_PCS_Sub ');
      sql.Add(' where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
      Open;
    end;
    ComboBox2.Clear;
    with ADOQueryTemp do
    begin
      First;
      while not Eof do
      begin
        ComboBox2.Items.Add(Trim(ADOQueryTemp.fieldbyname('FactoryName').AsString));
        Next;
      end;
    end;
  end;
end;

procedure TfrmPRTOrderList.TBAddClick(Sender: TObject);
var
  maxno:string;
begin
  try
    frmOrderInPutPrice:=TfrmOrderInPutPrice.Create(Application);
    with frmOrderInPutPrice do
    begin
      PState:=0;
      FMainId:='';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmOrderInPutPrice.Free;
  end;
end;

procedure TfrmPRTOrderList.OrderNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmPRTOrderList.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmPRTOrderList.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if TBView.Visible=False then Exit;
  TBView.Click;
end;

procedure TfrmPRTOrderList.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmPRTOrderList.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmPRTOrderList.TBViewClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
    frmOrderInPutPrice:=TfrmOrderInPutPrice.Create(Application);
    with frmOrderInPutPrice do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      ToolBar2.Visible:=False;
      ToolBar4.Visible:=False;
      TBSave.Visible:=False;
      ToolButton4.Visible:=False;
      ToolButton5.Visible:=False;
      ToolButton8.Visible:=False;
      ToolButton10.Visible:=False;
      ToolButton11.Visible:=False;
      Tv1.OptionsSelection.CellSelect:=False;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmOrderInPutPrice.Free;
  end;
end;

procedure TfrmPRTOrderList.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
    frmOrderInPutPrice:=TfrmOrderInPutPrice.Create(Application);
    with frmOrderInPutPrice do
    begin
      PState:=1;
      CopyInt:=99;
      FMainId:=Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmOrderInPutPrice.Free;
  end;
end;

procedure TfrmPRTOrderList.OrderNoKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then
  begin
    if Length(OrderNo.Text)<3 then Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.add('exec P_View_OrderQT :WSql') ;
        Parameters.ParamByName('WSql').Value:=' and orderno like '''+'%'+Trim(OrderNo.Text)+'%'+'''';
        Open;
      end;
      SCreateCDS20(ADOQueryMain,Order_Main);
      SInitCDSData20(ADOQueryMain,Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmPRTOrderList.ConNoKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then
  begin
    if Length(conno.Text)<3 then Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.add('exec P_View_OrderQT :WSql') ;
        Parameters.ParamByName('WSql').Value:=' and ConNo like '''+'%'+Trim(ConNo.Text)+'%'+'''';
        ExecSQL;
        Open;
      end;
      SCreateCDS20(ADOQueryMain,Order_Main);
      SInitCDSData20(ADOQueryMain,Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmPRTOrderList.Tv1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if Order_Main.IsEmpty then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select distinct(FactoryName) FactoryName from JYOrder_PCS_Sub ');
    sql.Add(' where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
    Open;
  end;
  ComboBox2.Clear;
  with ADOQueryTemp do
  begin
    First;
    while not Eof do
    begin
      ComboBox2.Items.Add(Trim(ADOQueryTemp.fieldbyname('FactoryName').AsString));
      Next;
    end;
  end;
end;

procedure TfrmPRTOrderList.ToolButton3Click(Sender: TObject);
begin
  try
    frmModuleNote:=TfrmModuleNote.Create(Application);
    with frmModuleNote do
    begin
      flag:='生产指示单';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmModuleNote.Free;
  end;
end;

procedure TfrmPRTOrderList.ToolButton4Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Trim(CanShu1)<>'高权限' then
  begin
    if Trim(Order_Main.fieldbyname('FillerCode').AsString)<>Trim(DCode) then
    begin
      Application.MessageBox('不能操作他人的数据!','提示',0);
      Exit;
    end;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' UPdate JYOrder_Main Set DJFinishFlag=1,DJFinishTime=getdate(),DJFinishPerson='''+Trim(DName)+'''');
    sql.Add(' where Mainid='''+Trim(Order_Main.fieldbyname('Mainid').AsString)+'''');
    ExecSQL;
  end;
  with Order_Main do
  begin
    Edit;
    FieldByName('DJFinishFlag').Value:=True;
    Post;
  end;
end;

procedure TfrmPRTOrderList.ToolButton5Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Trim(CanShu1)<>'高权限' then
  begin
    if Trim(Order_Main.fieldbyname('FillerCode').AsString)<>Trim(DCode) then
    begin
      Application.MessageBox('不能操作他人的数据!','提示',0);
      Exit;
    end;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' UPdate JYOrder_Main Set DJFinishFlag=0,DJFinishTime=getdate(),DJFinishPerson='''+Trim(DName)+'''');
    sql.Add(' where Mainid='''+Trim(Order_Main.fieldbyname('Mainid').AsString)+'''');
    ExecSQL;
  end;
  with Order_Main do
  begin
    Edit;
    FieldByName('DJFinishFlag').Value:=False;
    Post;
  end;
end;

procedure TfrmPRTOrderList.ToolButton6Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Trim(CanShu1)<>'高权限' then
  begin
    if Trim(Order_Main.fieldbyname('FillerCode').AsString)<>Trim(DCode) then
    begin
      Application.MessageBox('不能操作他人的数据!','提示',0);
      Exit;
    end;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' UPdate JYOrder_Main Set GDFinishFlag=1,GDFinishTime=getdate(),GDFinishPerson='''+Trim(DName)+'''');
    sql.Add(' where Mainid='''+Trim(Order_Main.fieldbyname('Mainid').AsString)+'''');
    ExecSQL;
  end;
  with Order_Main do
  begin
    Edit;
    FieldByName('GDFinishFlag').Value:=True;
    Post;
  end;
end;

procedure TfrmPRTOrderList.ToolButton8Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Trim(CanShu1)<>'高权限' then
  begin
    if Trim(Order_Main.fieldbyname('FillerCode').AsString)<>Trim(DCode) then
    begin
      Application.MessageBox('不能操作他人的数据!','提示',0);
      Exit;
    end;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' UPdate JYOrder_Main Set GDStartFlag=1,GDStartTime=getdate(),GDStartPerson='''+Trim(DName)+'''');
    sql.Add(' where Mainid='''+Trim(Order_Main.fieldbyname('Mainid').AsString)+'''');
    ExecSQL;
  end;
  with Order_Main do
  begin
    Edit;
    FieldByName('GDStartFlag').Value:=True;
    Post;
  end;
end;

procedure TfrmPRTOrderList.ToolButton9Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Trim(CanShu1)<>'高权限' then
  begin
    if Trim(Order_Main.fieldbyname('FillerCode').AsString)<>Trim(DCode) then
    begin
      Application.MessageBox('不能操作他人的数据!','提示',0);
      Exit;
    end;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' UPdate JYOrder_Main Set GDStartFlag=0,GDStartTime=getdate(),GDStartPerson='''+Trim(DName)+'''');
    sql.Add(' where Mainid='''+Trim(Order_Main.fieldbyname('Mainid').AsString)+'''');
    ExecSQL;
  end;
  with Order_Main do
  begin
    Edit;
    FieldByName('GDStartFlag').Value:=False;
    Post;
  end;
end;

procedure TfrmPRTOrderList.ToolButton7Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Trim(CanShu1)<>'高权限' then
  begin
    if Trim(Order_Main.fieldbyname('FillerCode').AsString)<>Trim(DCode) then
    begin
      Application.MessageBox('不能操作他人的数据!','提示',0);
      Exit;
    end;
  end;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' UPdate JYOrder_Main Set GDFinishFlag=0,GDFinishTime=getdate(),GDFinishPerson='''+Trim(DName)+'''');
    sql.Add(' where Mainid='''+Trim(Order_Main.fieldbyname('Mainid').AsString)+'''');
    ExecSQL;
  end;
  with Order_Main do
  begin
    Edit;
    FieldByName('GDFinishFlag').Value:=False;
    Post;
  end;
end;

end.
