unit U_MaDanManageWW;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, StdCtrls, ExtCtrls, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  cxCalendar, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid,
  cxCheckBox, cxButtonEdit, cxDropDownEdit, BtnEdit, cxGridBandedTableView,
  cxGridDBBandedTableView, cxContainer, cxTextEdit, cxMemo, cxRichEdit,
  DBClient, ADODB, cxGridCustomPopupMenu, cxGridPopupMenu, cxPC;

type
  TfrmMaDanManageWW = class(TForm)
    Panel1: TPanel;
    Label3: TLabel;
    OrderNo: TEdit;
    ScrollBox3: TScrollBox;
    ScrollBox4: TScrollBox;
    Panel5: TPanel;
    Label9: TLabel;
    Panel4: TPanel;
    Label12: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label25: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    DLYDate: TDateTimePicker;
    MPRTCodeName: TEdit;
    MPRTSpec: TEdit;
    MPRTCF: TEdit;
    MPRTMF: TEdit;
    MPRTKZ: TEdit;
    MPRTKZNote: TEdit;
    LiDanPerson: TEdit;
    CDS_OrderNo: TClientDataSet;
    DS_OrderNo: TDataSource;
    cxGrid6: TcxGrid;
    TvOrdeNo: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGrid4Level1: TcxGridLevel;
    ADOQuery1: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    ClientDataSet2: TClientDataSet;
    DataSource2: TDataSource;
    ClientDataSet5: TClientDataSet;
    DataSource5: TDataSource;
    ClientDataSet3: TClientDataSet;
    DataSource3: TDataSource;
    ClientDataSet6: TClientDataSet;
    DataSource6: TDataSource;
    Label4: TLabel;
    PFGenDanPerson: TEdit;
    MPRTCode: TEdit;
    cxGridPopupMenu1: TcxGridPopupMenu;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxGridPopupMenu3: TcxGridPopupMenu;
    cxGridPopupMenu4: TcxGridPopupMenu;
    cxGridPopupMenu5: TcxGridPopupMenu;
    Button7: TButton;
    ScrollBox2: TScrollBox;
    Panel3: TPanel;
    Label2: TLabel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Column2: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    Panel2: TPanel;
    Label1: TLabel;
    cxGrid5: TcxGrid;
    Tv5: TcxGridDBTableView;
    v5Column8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    v5Column2: TcxGridDBColumn;
    v5Column7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    v5Column3: TcxGridDBColumn;
    v5Column4: TcxGridDBColumn;
    v5Column5: TcxGridDBColumn;
    v5Column1: TcxGridDBColumn;
    v5Column9: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    ScrollBox5: TScrollBox;
    Panel7: TPanel;
    Label13: TLabel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column2: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1PRTColor: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label5: TLabel;
    MPRTGYHZ: TEdit;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    v3Column1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    Tv3Column1: TcxGridDBColumn;
    Tv3Column2: TcxGridDBColumn;
    Tv3Column3: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    v3Column3: TcxGridDBColumn;
    v3Column4: TcxGridDBColumn;
    v3Column5: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Panel9: TPanel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    cxTabSheet2: TcxTabSheet;
    Panel8: TPanel;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    cxGrid4: TcxGrid;
    Tv6: TcxGridDBBandedTableView;
    cxGridDBBandedColumn1: TcxGridDBBandedColumn;
    cxGridDBBandedColumn2: TcxGridDBBandedColumn;
    Tv6Column1: TcxGridDBBandedColumn;
    Tv6Column2: TcxGridDBBandedColumn;
    v6Column1: TcxGridDBBandedColumn;
    v6Column2: TcxGridDBBandedColumn;
    v6Column3: TcxGridDBBandedColumn;
    v6Column4: TcxGridDBBandedColumn;
    v6Column5: TcxGridDBBandedColumn;
    v6Column6: TcxGridDBBandedColumn;
    v6Column9: TcxGridDBBandedColumn;
    v6Column10: TcxGridDBBandedColumn;
    v6Column11: TcxGridDBBandedColumn;
    v6Column12: TcxGridDBBandedColumn;
    v6Column14: TcxGridDBBandedColumn;
    v6Column7: TcxGridDBBandedColumn;
    v6Column13: TcxGridDBBandedColumn;
    v6Column15: TcxGridDBBandedColumn;
    cxGridLevel3: TcxGridLevel;
    v5Column6: TcxGridDBColumn;
    Button10: TButton;
    v5Column10: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v6Column8: TcxGridDBBandedColumn;
    v3Column6: TcxGridDBColumn;
    v3Column7: TcxGridDBColumn;
    ADOQuery2: TADOQuery;
    ClientDataSet8: TClientDataSet;
    v6Column16: TcxGridDBBandedColumn;
    v1Column9: TcxGridDBColumn;
    v3Column8: TcxGridDBColumn;
    v3Column9: TcxGridDBColumn;
    v6Column17: TcxGridDBBandedColumn;
    v1Column10: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure TvOrdeNoDblClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure v2Column2PropertiesEditValueChanged(Sender: TObject);
    procedure v5Column8PropertiesEditValueChanged(Sender: TObject);
    procedure Tv3Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure v6Column8PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v6Column2PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v6Column14PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column2PropertiesEditValueChanged(Sender: TObject);
    procedure Tv6MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Tv3MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormShow(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Tv3Column1PropertiesEditValueChanged(Sender: TObject);
    procedure v6Column8PropertiesEditValueChanged(Sender: TObject);
    procedure v6Column2PropertiesEditValueChanged(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure v6Column3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cxGridDBColumn32PropertiesEditValueChanged(Sender: TObject);
    procedure v6Column16PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  private
    { Private declarations }
     FMainId,SParameters1:String;

     procedure InitGrid();
     function UpdateTJCKQty(FFPFID:string):Boolean;
  public
    { Public declarations }
  end;

var
  frmMaDanManageWW: TfrmMaDanManageWW;

implementation
uses
  U_DataLink,U_RTFun, U_GYSList,U_ModuleNote,U_ZDYHelp, U_ZDYHelpSel,
  U_GYSSelList;

{$R *.dfm}

procedure TfrmMaDanManageWW.FormDestroy(Sender: TObject);
begin
  frmMaDanManageWW:=nil;

end;

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

procedure TfrmMaDanManageWW.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('Tv1',Tv1,'外围码单');
  WriteCxGrid('Tv2',Tv2,'外围码单');
  WriteCxGrid('Tv3',Tv3,'外围码单');
  WriteCxGrid('Tv5',Tv5,'外围码单');
  WriteCxBandedGrid('Tv6',Tv6,'外围码单');
  close;
end;

procedure TfrmMaDanManageWW.OrderNoChange(Sender: TObject);
var
  mvalue:String;
begin
  mvalue:=Trim(OrderNo.Text);
  if Length(Trim(mvalue))<2 then
  begin
    cxGrid6.Visible:=False;
    Exit;
  end;
  mvalue:='%'+Trim(mvalue)+'%';
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select OrderNo,MPRTCodeName,A.MainId from JYOrder_Main A');
    sql.Add(' where A.orderno like :orderno ');
    //sql.Add(' and A.MainId in(select MainId from JYOrder_Sub B where B.Mainid=A.MainId and B.subId in(select OrdSubId from Contract_Cloth_LL))');
    Parameters.ParamByName('orderno').Value:=mvalue;
    Open;
  end;
  SCreateCDS20(ADOQuery1,CDS_OrderNo);
  SInitCDSData20(ADOQuery1,CDS_OrderNo);
  if CDS_OrderNo.IsEmpty then cxGrid6.Visible:=False else cxGrid6.Visible:=True;
end;

procedure TfrmMaDanManageWW.TvOrdeNoDblClick(Sender: TObject);
var
  fsj:String;
begin
  OrderNo.Text:=CDS_OrderNo.fieldbyname('OrderNo').AsString;
  cxGrid6.Visible:=False;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* ');
    sql.Add(' from JYOrder_Main A');
    sql.Add(' where Orderno='''+Trim(OrderNo.Text)+'''');
    Open;
  end;
  SCSHData(ADOQueryTemp,Panel4,2);
  MPRTCode.Text:=Trim(ADOQueryTemp.fieldbyname('MPRTCode').AsString);
  FMainId:=Trim(ADOQueryTemp.fieldbyname('MainId').AsString);
  if ADOQueryTemp.FieldByName('JSFlag').AsBoolean=True then
  begin
    Panel8.Visible:=False;
    Panel9.Visible:=False;

  end else
  begin
    Panel8.Visible:=True;
    Panel9.Visible:=True;

  end;
  fsj:='select Code=FactoryNo,Name=FactoryName from JYOrder_PCS_Sub where MainId='''+Trim(FMainId)+''''+
       ' and isnull(FactoryNo,'''')<>'''' group by FactoryNo,FactoryName';
  SInitCxGridComboBoxBySql(ADOQuery1,Tv3Column1,fsj,1,True,'');
 // SInitCxBandGridComboBoxBySql(ADOQuery1,v6Column8,fsj,1,True,'');
  SInitCxBandGridComboBoxBySql(ADOQuery1,v6Column2,fsj,1,True,'');
  fsj:='select Code=PFGenDanPerson,Name=PFGenDanPerson from JYOrder_PCS_Sub where MainId='''+Trim(FMainId)+''''+
       ' and isnull(PFGenDanPerson,'''')<>'''' group by PFGenDanPerson';
  SInitCxBandGridComboBoxBySql(ADOQuery1,v6Column1,fsj,1,True,'');
  fsj:='';
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Process where MainId='''+Trim(FMainId)+'''');
    Open;
  end;
  with ADOQueryTemp do
  begin
    First;
    while not Eof do
    begin
      with ADOQuery1 do
      begin
        Close;
        sql.Clear;
        sql.Add('select AA=dbo.F_Get_Order_SubStr(:PSID,''PFGenDanPerson'')');
        Parameters.ParamByName('PSID').Value:=Trim(ADOQueryTemp.fieldbyname('PSID').AsString);
        open;
      end;
      if Trim(fsj)='' then
      begin
        fsj:=Trim(ADOQueryTemp.fieldbyname('PSName').AsString)+':'+Trim(ADOQuery1.fieldbyname('AA').AsString);
      end else
        fsj:=fsj+'  '+Trim(ADOQueryTemp.fieldbyname('PSName').AsString)+':'+Trim(ADOQuery1.fieldbyname('AA').AsString);
      Next;
    end;
  end;
  PFGenDanPerson.Text:=Trim(fsj);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.PRTHX,PRTColor=isnull(B.PRTColor,'''')+'' ''+isnull(B.PRTColorNo,'''')');
    sql.Add(' ,orderNo=(select OrderNo from JYOrder_Main JM where JM.MainId=(select ORDMainid from JYOrder_Main_MD MD where MD.MDID=A.DiaoYongMDID))');
    sql.Add(',B.PRTOrdQty,B.OrderUnit,B.ColorNote,JP.PSName,B.FZGYNote  ');
    sql.Add(',Case when isnull(A.CKName,'''')='''' then ''正常'' else ''调用'' end as APType ');
    sql.Add(',Case when A.PFTPMQty<>0 then Cast((A.WCMQty-A.TJMQty)*100*1.00/A.PFTPMQty as decimal(18,2)) else 0 end as WCL');
    sql.Add(' from JYOrder_PCS_Sub A');
    sql.Add(' inner join JYOrder_Process JP on A.PSID=JP.PSID');
    sql.Add(' left join JYOrder_Sub B on A.SubId=B.SubId');
    sql.Add(' where A.MainId='''+Trim(FMainId)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet1);
  SInitCDSData20(ADOQueryTemp,ClientDataSet1);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Contract_Main A inner join Contract_Sub B on A.MainId=B.MainId ');
    sql.Add(' where A.ConNo like '''+'%'+Trim(OrderNo.Text)+'%'+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet5);
  SInitCDSData20(ADOQueryTemp,ClientDataSet5);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Process where MainId='''+Trim(FMainId)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet2);
  SInitCDSData20(ADOQueryTemp,ClientDataSet2);
  InitGrid();
end;
procedure TfrmMaDanManageWW.InitGrid();
var
  FPSID,FOrdSubId,FConSubId,FPFID:String;
begin
  if ClientDataSet2.Locate('SSel',True,[])=True then
  begin
    FPSID:=Trim(ClientDataSet2.fieldbyname('PSID').AsString);
  end else
  begin
    FPSID:='';
  end;
  if ClientDataSet5.Locate('SSel',True,[])=True then
  begin
    FConSubId:=Trim(ClientDataSet5.fieldbyname('SubId').AsString);
  end else
  begin
    FConSubId:='';
  end;
  if ClientDataSet1.Locate('SSel',True,[])=True then
  begin
    FOrdSubId:=Trim(ClientDataSet1.fieldbyname('SubId').AsString);
    FPFID:=Trim(ClientDataSet1.fieldbyname('PFID').AsString);
  end else
  begin
    FOrdSubId:='';
    FPFID:='';
  end;

  with ADOQuery2 do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.PSName OrdPSName,C.ConNo,C.FactoryNoName,D.Price,JS.PRTHX,JS.ColorNote ');
    sql.Add(',PRTColor=isnull(JS.PRTColor,'''')+'' ''+isnull(JS.PRTColorNo,'''')');
    sql.Add(' from JYOrder_Main_MD  A');
    sql.Add(' inner join JYOrder_Process B on A.PSID=B.PSID');
    sql.Add(' inner join JYOrder_PCS_Sub JPS on A.PFID=JPS.PFID ');
    sql.Add(' left join JYOrder_Sub JS on A.OrdSubId=JS.SubId');
    sql.Add(' left join Contract_Main C on A.ConMainid=C.MainID');
    sql.Add(' left join Contract_Sub D on A.ConSubid=D.SubID');
    sql.Add(' where A.ORDMainId='''+Trim(FMainId)+'''');
    if Trim(FPSID)<>'' then
    begin
      sql.Add(' and A.PSID='''+Trim(FPSID)+'''');
    end;
    if Trim(FConSubId)<>'' then
    begin
      sql.Add(' and A.ConSubID='''+Trim(FConSubId)+'''');
    end;
    if Trim(FOrdSubId)<>'' then
    begin
      sql.Add(' and A.OrdSubID='''+Trim(FOrdSubId)+'''');
    end;
    if Trim(FPFID)<>'' then
    begin
      sql.Add(' and A.PFID='''+Trim(FPFID)+'''');
    end;
    {if Trim(SParameters1)<>'高权限' then
    begin
      SQL.Add(' and A.Filler='''+Trim(DName)+'''');
    end; }
    sql.Add(' and A.MDType=''外围'' ');
    SQL.Add(' and isnull(A.CKName,'''')<>''调节仓库'' ');
    Open;
  end;
  //ShowMessage(ADOQuery1.SQL.Text);
  SCreateCDS20(ADOQuery2,ClientDataSet3);
  SInitCDSData20(ADOQuery2,ClientDataSet3);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.PSName OrdPSName,C.ConNo,C.FactoryNoName,D.Price,JS.PRTHX,JS.ColorNote ');
    sql.Add(',PRTColor=isnull(JS.PRTColor,'''')+'' ''+isnull(JS.PRTColorNo,'''')');
    sql.Add(' from JYOrder_Main_MD  A');
    sql.Add(' inner join JYOrder_Process B on A.PSID=B.PSID');
    sql.Add(' inner join JYOrder_PCS_Sub JPS on A.PFID=JPS.PFID ');
    sql.Add(' left join JYOrder_Sub JS on A.OrdSubId=JS.SubId');
    sql.Add(' left join Contract_Main C on A.ConMainid=C.MainID');
    sql.Add(' left join Contract_Sub D on A.ConSubid=D.SubID');
    sql.Add(' where A.ORDMainId='''+Trim(FMainId)+'''');
    if Trim(FPSID)<>'' then
    begin
      sql.Add(' and A.PSID='''+Trim(FPSID)+'''');
    end;
    if Trim(FConSubId)<>'' then
    begin
      sql.Add(' and A.ConSubID='''+Trim(FConSubId)+'''');
    end;
    if Trim(FOrdSubId)<>'' then
    begin
      sql.Add(' and A.OrdSubID='''+Trim(FOrdSubId)+'''');
    end;
    if Trim(FPFID)<>'' then
    begin
      sql.Add(' and A.PFID='''+Trim(FPFID)+'''');
    end;
    {if Trim(SParameters1)<>'高权限' then
    begin
      SQL.Add(' and A.Filler='''+Trim(DName)+'''');
    end;  }
    sql.Add(' and A.MDType=''外围'' ');
    SQL.Add(' and isnull(A.CKName,'''')=''调节仓库'' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet6);
  SInitCDSData20(ADOQueryTemp,ClientDataSet6);
end;

procedure TfrmMaDanManageWW.Button1Click(Sender: TObject);
begin
  if Trim(FMainId)='' then
  begin
    Application.MessageBox('没有选择订单!','提示',0);
    Exit;
  end;
  if ClientDataSet2.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择生产流程!','提示',0);
    Exit;
  end;
  if ClientDataSet1.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择安排信息!','提示',0);
    Exit;
  end;
  if Trim(ClientDataSet1.fieldbyname('APType').AsString)='调用' then
  begin
    Application.MessageBox('外围调用数据，无需手工增加码单!','提示',0);
    Exit;
  end;
  if ClientDataSet5.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择加工合同!','提示',0);
    Exit;
  end;

  ClientDataSet5.Locate('SSel',True,[]);
  ClientDataSet2.Locate('SSel',True,[]);
  ClientDataSet1.Locate('SSel',True,[]);
  if Trim(ClientDataSet1.fieldbyname('FactoryName').AsString)<>Trim(ClientDataSet5.fieldbyname('FactoryNoName').AsString) then
  begin
    Application.MessageBox('订单安排供应商与合同供应商不同，不能增加数据!','提示',0);
    Exit;
  end;
  with ClientDataSet3 do
  begin
    Append;
    FieldByName('ConNo').Value:=ClientDataSet5.fieldbyname('ConNo').Value;
    FieldByName('MDDate').Value:=Trim(FormatDateTime('yyyy-MM-dd',SGetServerDate(ADOQueryTemp)));
    FieldByName('FactoryNo').Value:=ClientDataSet1.fieldbyname('FactoryNo').Value;
    FieldByName('FactoryName').Value:=ClientDataSet1.fieldbyname('FactoryName').Value;
    FieldByName('FactoryNoName').Value:=ClientDataSet5.fieldbyname('FactoryNoName').Value;
    FieldByName('Price').Value:=ClientDataSet5.fieldbyname('Price').Value;
    FieldByName('PSName').Value:=ClientDataSet2.fieldbyname('PSName').Value;
    FieldByName('QtyUnit').Value:=ClientDataSet1.fieldbyname('PFTPUnit').Value;
    FieldByName('Filler').Value:=Trim(DName);
    FieldByName('FillTime').Value:=SGetServerDateTime(ADOQueryTemp);
    FieldByName('PRTHX').Value:=ClientDataSet1.fieldbyname('PRTHX').Value;
    FieldByName('PRTColor').Value:=ClientDataSet1.fieldbyname('PRTColor').Value;
    Post;
  end;
end;

procedure TfrmMaDanManageWW.v2Column2PropertiesEditValueChanged(
  Sender: TObject);
var
  PSID,ConType,fsj:String;
  Mvalue:Boolean;
begin
  Mvalue:=TcxCheckBox(Sender).EditingValue;
  PSID:=Trim(ClientDataSet2.fieldbyname('PSID').AsString);
  with ClientDataSet2 do
  begin
    while ClientDataSet2.Locate('SSel',True,[])=True do
    begin
      Edit;
      FieldByName('SSel').Value:=False;
      Post;
    end;
    ClientDataSet2.Locate('PSID',PSID,[]);
    Edit;
    FieldByName('SSel').Value:=Mvalue;
    Post;
  end;
  if Mvalue=True then
  begin
    fsj:='select Code=FactoryNo,Name=FactoryName from JYOrder_PCS_Sub A'+
         ' inner join JYOrder_Process B on A.PSID=B.PSID'+
         ' where A.MainId='''+Trim(FMainId)+''' and B.PSXH in('+
         Trim(ClientDataSet2.fieldbyname('PSXH').AsString)+','+
         inttostr(ClientDataSet2.fieldbyname('PSXH').AsInteger+1)+','+
         inttostr(ClientDataSet2.fieldbyname('PSXH').AsInteger+2)+
         ' )and isnull(FactoryNo,'''')<>'''' group by FactoryNo,FactoryName';
    //ShowMessage(fsj);
    SInitCxGridComboBoxBySql(ADOQuery1,Tv3Column1,fsj,1,True,'');
  end;
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.PRTHX,PRTColor=isnull(B.PRTColor,'''')+'' ''+isnull(B.PRTColorNo,'''')');
    sql.Add(' ,orderNo=(select OrderNo from JYOrder_Main JM where JM.MainId=(select ORDMainid from JYOrder_Main_MD MD where MD.MDID=A.DiaoYongMDID))');
    sql.Add(',B.PRTOrdQty,B.OrderUnit,B.ColorNote,JP.PSName,B.FZGYNote  ');
    sql.Add(',Case when isnull(A.CKName,'''')='''' then ''正常'' else ''调用'' end as APType ');
    sql.Add(',Case when A.PFTPMQty<>0 then Cast((A.WCMQty-A.TJMQty)*100*1.00/A.PFTPMQty as decimal(18,2)) else 0 end as WCL');
    sql.Add(' from JYOrder_PCS_Sub A');
    sql.Add(' inner join JYOrder_Process JP on A.PSID=JP.PSID');
    sql.Add(' left join JYOrder_Sub B on A.SubId=B.SubId');
    if Mvalue=True then
      sql.Add('where A.PSID='''+Trim(ClientDataSet2.fieldbyname('PSID').AsString)+'''')
    else
      sql.Add(' where A.MainId='''+Trim(FMainId)+'''');
    Open;
  end;
  SCreateCDS20(ADOQuery1,ClientDataSet1);
  SInitCDSData20(ADOQuery1,ClientDataSet1);


  if Mvalue=True then
  begin
    ClientDataSet2.Locate('SSel',True,[]);
    ConType:=Trim(ClientDataSet2.fieldbyname('PSName').AsString);
  end else
  begin
    ConType:='';
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.*,Case when isnull(A.JYType,'''')<>'''' then Cast(1 as bit) else Cast(0 as bit) end as JYFlag   ');
    sql.Add(' from Contract_Main A inner join Contract_Sub B on A.MainId=B.MainId');
    sql.Add(' where A.ConNo like '''+'%'+Trim(OrderNo.Text)+'%'+'''');
    if Trim(ConType)<>'' then
    begin
      sql.Add(' and A.ConType='''+Trim(ConType)+'''');
    end;
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet5);
  SInitCDSData20(ADOQueryTemp,ClientDataSet5);
  InitGrid();
end;

procedure TfrmMaDanManageWW.v5Column8PropertiesEditValueChanged(
  Sender: TObject);
var
  PSID:String;
  Mvalue:Boolean;
begin
  Mvalue:=TcxCheckBox(Sender).EditingValue;
  PSID:=Trim(ClientDataSet5.fieldbyname('SubID').AsString);
  with ClientDataSet5 do
  begin
    while  ClientDataSet5.Locate('SSel',True,[])=True do
    begin
      Edit;
      FieldByName('SSel').Value:=False;
      Post;
    end;
    ClientDataSet5.Locate('SubID',PSID,[]);
    Edit;
    FieldByName('SSel').Value:=Mvalue;
    Post;
  end;
  InitGrid();
end;

procedure TfrmMaDanManageWW.Tv3Column1PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmGYSList:=TfrmGYSList.Create(Application);
    with frmGYSList do
    begin
      if ShowModal=1 then
      begin
        with Self.ClientDataSet3 do
        begin
          Edit;
          FieldByName('FromFactoryNo').Value:=Trim(frmGYSList.Order_Main.fieldbyname('ZKID').AsString) ;
          FieldByName('FromFactoryName').Value:=Trim(frmGYSList.Order_Main.fieldbyname('KHNameJC').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmGYSList.Free;
  end;
end;

procedure TfrmMaDanManageWW.Button3Click(Sender: TObject);
var
  maxno,ConMainId,ConSubId,PSID,OrdSubId,PFID:string;
begin
  if ClientDataSet3.IsEmpty then Exit;
 // if Trim(ClientDataSet3.FieldByName('MDId').AsString)='' then
  begin
    if ClientDataSet2.Locate('SSel',True,[])=False then
    begin
      Application.MessageBox('没有选择生产流程!','提示',0);
      Exit;
    end;
    if cxPageControl1.ActivePageIndex=0 then
    begin
      if ClientDataSet5.Locate('SSel',True,[])=False then
      begin
        Application.MessageBox('没有选择加工合同!','提示',0);
        Exit;
      end;
    end;
    { }

    if ClientDataSet1.Locate('SSel',True,[])=False then
    begin
      Application.MessageBox('没有选择安排信息!','提示',0);
      Exit;
    end;
    if cxPageControl1.ActivePageIndex=1 then
    begin
      if Trim(ClientDataSet1.fieldbyname('APType').AsString)<>'调用' then
      begin
        if ClientDataSet5.Locate('SSel',True,[])=False then
        begin
          Application.MessageBox('没有选择加工合同!','提示',0);
          Exit;
        end;
      end;
    end;

  end;
  if ClientDataSet3.Locate('QtyUnit',null,[])=True then
  begin
    Application.MessageBox('单位不能为空!','提示',0);
    Exit;
  end;
  if ClientDataSet3.Locate('MDDate',null,[])=True then
  begin
    Application.MessageBox('码单日期不能为空!','提示',0);
    Exit;
  end;
  if ClientDataSet3.Locate('FromFactoryName',null,[])=True then
  begin
    Application.MessageBox('下道供应商不能为空!','提示',0);
    Exit;
  end;
  if Trim(SParameters1)='高权限' then
  begin
    if Application.MessageBox('确定要保存数据吗？','提示',32+4)<>IDYES then Exit;
  end else
  begin
    if Application.MessageBox('确定要保存数据吗?数据保存后将不能修改！','提示',32+4)<>IDYES then Exit;
  end;

  //ClientDataSet1.Locate('SSel',True,[]);
  ConMainId:=Trim(ClientDataSet5.fieldbyname('MainId').AsString);
  ConSubId:=Trim(ClientDataSet5.fieldbyname('SubId').AsString);
  PSID:=Trim(ClientDataSet2.fieldbyname('PSID').AsString);
  OrdSubId:=Trim(ClientDataSet1.fieldbyname('SubId').AsString);
  PFID:=Trim(ClientDataSet1.fieldbyname('PFID').AsString);
  if Trim(ClientDataSet3.fieldbyname('ConMainId').AsString)<>'' then
  begin
    ConMainId:=Trim(ClientDataSet3.fieldbyname('ConMainId').AsString);
  end;
  if Trim(ClientDataSet3.fieldbyname('ConSubId').AsString)<>'' then
  begin
    ConSubId:=Trim(ClientDataSet3.fieldbyname('ConSubId').AsString);
  end;
  if Trim(ClientDataSet3.fieldbyname('OrdSubId').AsString)<>'' then
  begin
    OrdSubId:=Trim(ClientDataSet3.fieldbyname('OrdSubId').AsString);
  end;
  if Trim(ClientDataSet3.fieldbyname('PSID').AsString)<>'' then
  begin
    PSID:=Trim(ClientDataSet3.fieldbyname('PSID').AsString);
  end;
  if Trim(ClientDataSet3.fieldbyname('PFID').AsString)<>'' then
  begin
    PFID:=Trim(ClientDataSet3.fieldbyname('PFID').AsString);
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    ClientDataSet3.DisableControls;
    with ClientDataSet3 do
    begin
      First;
      while not Eof do
      begin
        if Trim(SParameters1)<>'高权限' then
        begin
          if Trim(ClientDataSet3.fieldbyname('MDID').AsString)<>'' then
          begin
            Next;
            Continue;
          end;
        end;

        if Trim(ClientDataSet3.fieldbyname('MDId').AsString)='' then
        begin
          if GetLSNo(ADOQueryCmd,maxno,'','JYOrder_Main_MD',4,1)=False then
          begin
            ClientDataSet3.EnableControls;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取码单流水号失败!','提示',0);
            Exit;
          end;
        end else
        begin
          maxno:=Trim(ClientDataSet3.fieldbyname('MDId').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from JYOrder_Main_MD where MDID='''+Trim(ClientDataSet3.fieldbyname('MDId').AsString)+'''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(ClientDataSet3.fieldbyname('MDId').AsString)='' then
          begin
            Append;
            FieldByName('Filler').Value:=Trim(DName);
          end else
          begin
            Edit;
            FieldByName('Editer').Value:=Trim(DName);
            FieldByName('EditTime').Value:=SGetServerDateTime(ADOQueryTemp);
          end;
          FieldByName('MDID').Value:=Trim(maxno);
          FieldByName('OrdMainID').Value:=Trim(FMainId);
          FieldByName('ConMainID').Value:=Trim(ConMainId);
          FieldByName('ConSubID').Value:=Trim(ConSubId);
          FieldByName('OrdSubId').Value:=Trim(OrdSubId);
          FieldByName('PSID').Value:=Trim(PSID);
          FieldByName('PFID').Value:=Trim(PFID);
          FieldByName('MDType').Value:='外围';
          RTSetSaveDataCDS(ADOQueryCmd,Tv3,ClientDataSet3,'JYOrder_Main_MD',2);
          if Trim(ClientDataSet3.fieldbyname('FZQty').AsString)='' then
          begin
            FieldByName('FZQty').Value:=0;
          end else
          begin
            FieldByName('FZQty').Value:=ClientDataSet3.fieldbyname('FZQty').Value;
          end;
          if ClientDataSet3.FieldByName('HXFlag').AsBoolean=True then
          begin
            FieldByName('HXFlag').Value:=1;
          end else
          begin
            FieldByName('HXFlag').Value:=0;
          end;
          if Trim(ClientDataSet3.FieldByName('MDNO').AsString)='' then
            FieldByName('MDNO').Value:='MD'+Trim(maxno);
          FieldByName('FactoryNo').Value:=Trim(ClientDataSet3.fieldbyname('FactoryNo').AsString);
          FieldByName('FromFactoryNo').Value:=Trim(ClientDataSet3.fieldbyname('FromFactoryNo').AsString);
          if ClientDataSet5.Locate('SSel',True,[])=True then
          begin
            FieldByName('ConCode').Value:=ClientDataSet5.fieldbyname('C_Code').Value;
            FieldByName('ConName').Value:=ClientDataSet5.fieldbyname('C_CodeName').Value;
            FieldByName('ConSpec').Value:=ClientDataSet5.fieldbyname('C_Spec').Value;
            FieldByName('ConCF').Value:=ClientDataSet5.fieldbyname('C_CF').Value;
            FieldByName('ConMF').Value:=ClientDataSet5.fieldbyname('MFQty').AsString;
            FieldByName('ConKZ').Value:=ClientDataSet5.fieldbyname('KZQty').AsString;
            FieldByName('ConPrice').Value:=ClientDataSet5.fieldbyname('Price').Value;
          end;
          Post;
        end;
        with ADOQueryTemp do
        begin
          close;
          sql.Clear;
          sql.Add('select QtyUnit from JYOrder_Main_MD where PFID='''+Trim(PFID)+'''');
          sql.Add(' and isnull(CKName,'''')='''' ');
          sql.Add(' Group by QtyUnit');
          Open;
        end;
        if ADOQueryTemp.RecordCount>1 then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          ClientDataSet3.EnableControls;
          Application.MessageBox('单位不一致，不能保存数据!','提示',0);
          Exit;
        end;
        Edit;
        FieldByName('MDID').Value:=Trim(maxno);
        FieldByName('MDNO').Value:='MD'+Trim(maxno);
        FieldByName('OrdMainID').Value:=Trim(FMainId);
        FieldByName('ConMainID').Value:=Trim(ConMainId);
        FieldByName('ConSubID').Value:=Trim(ConSubId);
        FieldByName('OrdSubId').Value:=Trim(OrdSubId);
        FieldByName('PSID').Value:=Trim(PSID);
        FieldByName('PFID').Value:=Trim(PFID);
        Post;
        Next;
      end;
    end;
    //UpdateTJCKQty(PFID);//更新调节仓库中的库存数量。(自动核销)
    ADOQueryCmd.Connection.CommitTrans;
    ClientDataSet3.EnableControls;
  except
    ClientDataSet3.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存异常!','提示',0);
  end;
end;
function TfrmMaDanManageWW.UpdateTJCKQty(FFPFID:string):Boolean;
var
  FAPQty,FMDQty,FPS,FQty:Double;
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add(' select * from JYOrder_Main_MD_Out where PFID='''+Trim(FFPFID)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty then
  begin
    Exit;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_PCS_Sub where PFID='''+Trim(FFPFID)+'''');
    Open;
  end;
  FAPQty:=ADOQueryTemp.fieldbyname('PFTPQty').Value;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select isnull(sum(Qty),0) MDQty from JYOrder_Main_MD where PFID='''+Trim(FFPFID)+'''');
    sql.Add(' and isnull(CKName,'''')<>''调节仓库'' ');
    Open;
  end;
  FMDQty:=ADOQueryTemp.fieldbyname('MDQty').Value;
  if FMDQty>FAPQty then
  begin
    Application.MessageBox('出库数量大于调用申请数量不能录入码单!','提示',0);
    Exit;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select isnull(sum(PS),0) PS,isnull(Sum(Qty),0) Qty from JYOrder_Main_MD where PFID='''+Trim(FFPFID)+'''');
    sql.Add(' and isnull(CKName,'''')<>''调节仓库''');
    Open;
  end;
  FPS:=ADOQueryTemp.fieldbyname('PS').Value;
  FQty:=ADOQueryTemp.fieldbyname('Qty').Value;
  if FQty=0 then
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update JYOrder_Main_MD_Out Set SJCKPS=0,SJCKQty=0');
      sql.Add(' where PFID='''+Trim(FFPFID)+'''');
      sql.Add('Update JYOrder_Main_MD Set CKPS=');
      sql.Add('(select isnull(sum(SJCKPS),0) from JYOrder_Main_MD_Out A where A.MDID=JYOrder_Main_MD.MDID) ');
      sql.Add(',CKQty=(select isnull(sum(SJCKQty),0) from JYOrder_Main_MD_Out A where A.MDID=JYOrder_Main_MD.MDID) ');
      sql.Add(' where MDID in');
      sql.Add('(select MDID from JYOrder_Main_MD_Out JMO where JMO.PFID='''+Trim(FFPFID)+''')');
      ExecSQL;
    end;
    Exit;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update JYOrder_Main_MD_Out Set SJCKPS=0,SJCKQty=0');
    sql.Add(' where PFID='''+Trim(FFPFID)+'''');
    ExecSQL;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main_MD_Out where PFID='''+Trim(FFPFID)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet8);
  SInitCDSData20(ADOQueryTemp,ClientDataSet8);

  with ClientDataSet8 do
  begin
    First;
    while not Eof do
    begin
      if ClientDataSet8.FieldByName('CKQty').Value<=FQty then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add(' Update JYOrder_Main_MD_Out Set SJCKPS=CKPS,SJCKQty=CKQty ');
          sql.Add(' where CKID='''+Trim(ClientDataSet8.fieldbyname('CKID').AsString)+'''');
          ExecSQL;
        end;
        FPS:=FPS-ClientDataSet8.FieldByName('CKPS').Value;
        FQty:=FQty-ClientDataSet8.FieldByName('CKQty').Value;
        ClientDataSet8.Delete;
      end else
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add(' Update JYOrder_Main_MD_Out Set SJCKPS='+floattostr(FPS) );
          sql.Add(' ,SJCKQty='+floattostr(FQty) );
          sql.Add(' where CKID='''+Trim(ClientDataSet8.fieldbyname('CKID').AsString)+'''');
          ExecSQL;
        end;
        ClientDataSet8.Last;
      end;
    end;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update JYOrder_Main_MD Set CKPS=');
    sql.Add('(select isnull(sum(SJCKPS),0) from JYOrder_Main_MD_Out A where A.MDID=JYOrder_Main_MD.MDID) ');
    sql.Add(',CKQty=(select isnull(sum(SJCKQty),0) from JYOrder_Main_MD_Out A where A.MDID=JYOrder_Main_MD.MDID) ');
    sql.Add(' where MDID in');
    sql.Add('(select MDID from JYOrder_Main_MD_Out JMO where JMO.PFID='''+Trim(FFPFID)+''')');
    ExecSQL;
  end;
end;
procedure TfrmMaDanManageWW.FormCreate(Sender: TObject);
begin
  SParameters1:=Trim(DParameters1);
end;

procedure TfrmMaDanManageWW.Button2Click(Sender: TObject);
begin
  if ClientDataSet3.IsEmpty then Exit;
  if Trim(ClientDataSet3.fieldbyname('MDID').AsString)<>'' then
  begin
    if Trim(SParameters1)<>'高权限' then
    begin
      Application.MessageBox('已保存的数据不能删除!','提示',0);
      Exit;
    end;
    if ClientDataSet3.FieldByName('HCFlag').AsBoolean=True then
    begin
      Application.MessageBox('已核查，不能删除!','提示',0);
      Exit;
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_PCS_Sub where PFID='''+Trim(ClientDataSet3.fieldbyname('PFID').AsString)+'''');
      Open;
    end;
    if Trim(ADOQueryTemp.fieldbyname('DiaoYongMDID').AsString)<>'' then
    begin
      Application.MessageBox('外围调用数据，请到指示单安排界面删除!','提示',0);
      Exit;
    end;
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_Main_MD where MDID='''+Trim(ClientDataSet3.fieldbyname('MDID').AsString)+'''');
      ExecSQL;
    end;

    if Trim(ClientDataSet3.fieldbyname('QtyUnit').AsString)<>'M' then
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update JYOrder_PCS_Sub Set WCMQty=');
        sql.Add('(select isnull(sum(Qty),0) from JYOrder_Main_MD A where A.PFID=JYOrder_PCS_Sub.PFID and isnull(CKName,'''')='''')*');
        sql.Add('(select KgZM from JYOrder_Process A where A.PSID=JYOrder_PCS_Sub.PSID)');
        sql.Add(' where PFID='''+Trim(ClientDataSet3.fieldbyname('PFID').AsString)+'''');
        ExecSQL;
      end;
    end else
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update JYOrder_PCS_Sub Set WCMQty=');
        sql.Add('(select isnull(sum(Qty),0) from JYOrder_Main_MD A where A.PFID=JYOrder_PCS_Sub.PFID and isnull(CKName,'''')='''')');
        sql.Add(' where PFID='''+Trim(ClientDataSet3.fieldbyname('PFID').AsString)+'''');
        ExecSQL;
      end;
    end;
    //UpdateTJCKQty(Trim(ClientDataSet3.fieldbyname('PFID').AsString));
  end;

  ClientDataSet3.Delete;
end;

procedure TfrmMaDanManageWW.Button4Click(Sender: TObject);
begin
  if Trim(FMainId)='' then
  begin
    Application.MessageBox('没有选择订单!','提示',0);
    Exit;
  end;
  if ClientDataSet2.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择生产流程!','提示',0);
    Exit;
  end;
  if ClientDataSet1.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择安排信息!','提示',0);
    Exit;
  end;
  ClientDataSet2.Locate('SSel',True,[]);
  ClientDataSet1.Locate('SSel',True,[]);
  if  Trim(ClientDataSet1.fieldbyname('APType').AsString)<>'调用' then
  begin
    if ClientDataSet5.Locate('SSel',True,[])=False then
    begin
      Application.MessageBox('没有选择采购加工合同!','提示',0);
      Exit;
    end;
  end;
 { if ClientDataSet5.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择加工合同!','提示',0);
    Exit;
  end;}



  with ClientDataSet6 do
  begin
    Append;
    if  Trim(ClientDataSet1.fieldbyname('APType').AsString)<>'调用' then
    begin
      ClientDataSet5.Locate('SSel',True,[]);
    end;
    ClientDataSet2.Locate('SSel',True,[]);
    ClientDataSet1.Locate('SSel',True,[]);
    if  Trim(ClientDataSet1.fieldbyname('APType').AsString)<>'调用' then
    begin
      FieldByName('ConNo').Value:=ClientDataSet5.fieldbyname('ConNo').Value;
      FieldByName('FactoryNoName').Value:=ClientDataSet5.fieldbyname('FactoryNoName').Value;
      FieldByName('Price').Value:=ClientDataSet5.fieldbyname('Price').Value;
    end;

    FieldByName('MDDate').Value:=Trim(FormatDateTime('yyyy-MM-dd',SGetServerDate(ADOQueryTemp)));
    FieldByName('FactoryNo').Value:=ClientDataSet1.fieldbyname('FactoryNo').Value;
    FieldByName('FactoryName').Value:=ClientDataSet1.fieldbyname('FactoryName').Value;


    FieldByName('PSName').Value:=ClientDataSet2.fieldbyname('PSName').Value;
    FieldByName('QtyUnit').Value:=ClientDataSet1.fieldbyname('PFTPUnit').Value;
    FieldByName('Filler').Value:=Trim(DName);
    FieldByName('FillTime').Value:=SGetServerDateTime(ADOQueryTemp);
    FieldByName('PRTHX').Value:=ClientDataSet1.fieldbyname('PRTHX').Value;
    FieldByName('PRTColor').Value:=ClientDataSet1.fieldbyname('PRTColor').Value;
    Post;
  end;
end;

procedure TfrmMaDanManageWW.Button5Click(Sender: TObject);
begin

  if ClientDataSet6.IsEmpty then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main_MD where MDID='''+Trim(ClientDataSet6.fieldbyname('MDID').AsString)+'''');
    Open;
  end;
  if Trim(ADOQueryTemp.fieldbyname('CRFlag').asstring)='入库' then
  begin
    Application.MessageBox('已经入库不能删除数据!','提示',0);
    Exit;
  end;
  if Trim(ClientDataSet6.fieldbyname('MDID').AsString)<>'' then
  begin
    if Trim(SParameters1)<>'高权限' then
    begin
      Application.MessageBox('已保存的数据不能删除!','提示',0);
      Exit;
    end;
    if ClientDataSet6.FieldByName('HCFlag').AsBoolean=True then
    begin
      Application.MessageBox('已核查，不能删除!','提示',0);
      Exit;
    end;
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_Main_MD where MDID='''+Trim(ClientDataSet6.fieldbyname('MDID').AsString)+'''');
      ExecSQL;
    end;
    if Trim(ClientDataSet6.fieldbyname('QtyUnit').AsString)<>'M' then
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update JYOrder_PCS_Sub Set TJMQty=');
        sql.Add('(select isnull(sum(Qty),0) from JYOrder_Main_MD A where A.PFID=JYOrder_PCS_Sub.PFID and isnull(CKName,'''')<>'''')*');
        sql.Add('(select KgZM from JYOrder_Process A where A.PSID=JYOrder_PCS_Sub.PSID)');
        sql.Add(' where PFID='''+Trim(ClientDataSet6.fieldbyname('PFID').AsString)+'''');
        ExecSQL;
      end;
    end else
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update JYOrder_PCS_Sub Set TJMQty=');
        sql.Add('(select isnull(sum(Qty),0) from JYOrder_Main_MD A where A.PFID=JYOrder_PCS_Sub.PFID and isnull(CKName,'''')<>'''')');
        sql.Add(' where PFID='''+Trim(ClientDataSet6.fieldbyname('PFID').AsString)+'''');
        ExecSQL;
      end;
    end;
  end;
  ClientDataSet6.Delete;
end;

procedure TfrmMaDanManageWW.Button6Click(Sender: TObject);
var
  maxno,ConMainId,ConSubId,PSID,OrdSubId,PFID:string;
begin
  if ClientDataSet6.IsEmpty then Exit;
  //if Trim(ClientDataSet6.FieldByName('MDId').AsString)='' then
  begin
    if ClientDataSet2.Locate('SSel',True,[])=False then
    begin
      Application.MessageBox('没有选择生产流程!','提示',0);
      Exit;
    end;
    if ClientDataSet5.Locate('SSel',True,[])=False then
    begin
      Application.MessageBox('没有选择加工合同!','提示',0);
      Exit;
    end;

    if ClientDataSet1.Locate('SSel',True,[])=False then
    begin
      Application.MessageBox('没有选择安排信息!','提示',0);
      Exit;
    end;
  end;
  if ClientDataSet6.Locate('MDDate',null,[])=True then
  begin
    Application.MessageBox('码单日期不能为空!','提示',0);
    Exit;
  end;
  {if ClientDataSet6.Locate('MDDate','',[])=True then
  begin
    Application.MessageBox('码单日期不能为空!','提示',0);
    Exit;
  end;  }
  if ClientDataSet6.Locate('ToFactoryName',null,[])=True then
  begin
    Application.MessageBox('存放地点不能为空!','提示',0);
    Exit;
  end;
  if ClientDataSet6.Locate('ToFactoryName','',[])=True then
  begin
    Application.MessageBox('存放地点不能为空!','提示',0);
    Exit;
  end;
  if ClientDataSet6.Locate('QtyUnit',null,[])=True then
  begin
    Application.MessageBox('单位不能为空!','提示',0);
    Exit;
  end;
  if ClientDataSet6.Locate('DutyReason',null,[])=True then
  begin
    Application.MessageBox('入库原因不能为空!','提示',0);
    Exit;
  end;
  if Trim(SParameters1)='高权限' then
  begin
    if Application.MessageBox('确定要保存数据吗？','提示',32+4)<>IDYES then Exit;
  end else
  begin
    if Application.MessageBox('确定要保存数据吗?数据保存后将不能修改！','提示',32+4)<>IDYES then Exit;
  end;
  //if Application.MessageBox('确定要保存数据吗？','提示',32+4)<>IDYES then Exit;
  //ClientDataSet1.Locate('SSel',True,[]);
  ConMainId:=Trim(ClientDataSet5.fieldbyname('MainId').AsString);
  ConSubId:=Trim(ClientDataSet5.fieldbyname('SubId').AsString);
  PSID:=Trim(ClientDataSet2.fieldbyname('PSID').AsString);
  OrdSubId:=Trim(ClientDataSet1.fieldbyname('SubId').AsString);
  PFID:=Trim(ClientDataSet1.fieldbyname('PFID').AsString);
  if Trim(ClientDataSet6.fieldbyname('ConMainId').AsString)<>'' then
  begin
    ConMainId:=Trim(ClientDataSet6.fieldbyname('ConMainId').AsString);
  end;
  if Trim(ClientDataSet6.fieldbyname('ConSubId').AsString)<>'' then
  begin
    ConSubId:=Trim(ClientDataSet6.fieldbyname('ConSubId').AsString);
  end;
  if Trim(ClientDataSet6.fieldbyname('OrdSubId').AsString)<>'' then
  begin
    OrdSubId:=Trim(ClientDataSet6.fieldbyname('OrdSubId').AsString);
  end;
  if Trim(ClientDataSet6.fieldbyname('PSID').AsString)<>'' then
  begin
    PSID:=Trim(ClientDataSet6.fieldbyname('PSID').AsString);
  end;
  if Trim(ClientDataSet6.fieldbyname('PFID').AsString)<>'' then
  begin
    PFID:=Trim(ClientDataSet6.fieldbyname('PFID').AsString);
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    ClientDataSet6.DisableControls;
    with ClientDataSet6 do
    begin
      First;
      while not Eof do
      begin
        if Trim(SParameters1)<>'高权限' then
        begin
          if Trim(ClientDataSet6.fieldbyname('MDID').AsString)<>'' then
          begin
            Next;
            Continue;
          end;
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from JYOrder_Main_MD where MDID='''+Trim(ClientDataSet6.fieldbyname('MDID').AsString)+'''');
          Open;
        end;
        if Trim(ADOQueryTemp.fieldbyname('CRFlag').AsString)='入库' then
        begin
          Next;
          Continue;
        end;
        if Trim(ClientDataSet6.fieldbyname('MDId').AsString)='' then
        begin
          if GetLSNo(ADOQueryCmd,maxno,'','JYOrder_Main_MD',4,1)=False then
          begin
            ClientDataSet6.EnableControls;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取码单流水号失败!','提示',0);
            Exit;
          end;
        end else
        begin
          maxno:=Trim(ClientDataSet6.fieldbyname('MDId').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from JYOrder_Main_MD where MDID='''+Trim(ClientDataSet6.fieldbyname('MDId').AsString)+'''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(ClientDataSet6.fieldbyname('MDId').AsString)='' then
          begin
            Append;
            FieldByName('Filler').Value:=Trim(DName);
          end else
          begin
            Edit;
            FieldByName('Editer').Value:=Trim(DName);
            FieldByName('EditTime').Value:=SGetServerDateTime(ADOQueryTemp);
          end;
          FieldByName('MDID').Value:=Trim(maxno);
          FieldByName('OrdMainID').Value:=Trim(FMainId);
          FieldByName('ConMainID').Value:=Trim(ConMainId);
          FieldByName('ConSubID').Value:=Trim(ConSubId);
          FieldByName('OrdSubId').Value:=Trim(OrdSubId);
          FieldByName('PSID').Value:=Trim(PSID);
          FieldByName('PFID').Value:=Trim(PFID);
          FieldByName('MDType').Value:='外围';
          RTSetSaveDataCDSBand(ADOQueryCmd,Tv6,ClientDataSet6,'JYOrder_Main_MD',2);
          FieldByName('MDNO').Value:='TJ'+Trim(maxno);
          FieldByName('FactoryNo').Value:=Trim(ClientDataSet6.fieldbyname('FactoryNo').AsString);
          FieldByName('FromFactoryNo').Value:=Trim(ClientDataSet6.fieldbyname('FromFactoryNo').AsString);
          FieldByName('ToFactoryNo').Value:=Trim(ClientDataSet6.fieldbyname('ToFactoryNo').AsString);
          FieldByName('DutyFactoryNo').Value:=Trim(ClientDataSet6.fieldbyname('DutyFactoryNo').AsString);
          FieldByName('CKName').Value:='调节仓库';
          if ClientDataSet6.FieldByName('OtherOrdFlag').AsBoolean=True then
          begin
            FieldByName('OtherOrdFlag').Value:=1;
          end else
          begin
            FieldByName('OtherOrdFlag').Value:=0;
          end;
          if ClientDataSet6.FieldByName('CiPinFlag').AsBoolean=True then
          begin
            FieldByName('CiPinFlag').Value:=1;
          end else
          begin
            FieldByName('CiPinFlag').Value:=0;
          end;
          FieldByName('RKDate').Value:=ClientDataSet6.fieldbyname('MDDate').Value;
          FieldByName('RKPS').Value:=ClientDataSet6.fieldbyname('PS').Value;
          FieldByName('RKQty').Value:=ClientDataSet6.fieldbyname('Qty').Value;
          FieldByName('RKQtyUnit').Value:=ClientDataSet6.fieldbyname('QtyUnit').Value;
          if Trim(ClientDataSet6.fieldbyname('ClotheType').AsString)<>'次品' then
          begin
            FieldByName('Status').Value:='已确认';
            FieldByName('LiYongXS').Value:=1;
          end;
          if ClientDataSet5.Locate('SSel',True,[])=True then
          begin
            FieldByName('ConCode').Value:=ClientDataSet5.fieldbyname('C_Code').Value;
            FieldByName('ConName').Value:=ClientDataSet5.fieldbyname('C_CodeName').Value;
            FieldByName('ConSpec').Value:=ClientDataSet5.fieldbyname('C_Spec').Value;
            FieldByName('ConCF').Value:=ClientDataSet5.fieldbyname('C_CF').Value;
            FieldByName('ConMF').Value:=ClientDataSet5.fieldbyname('MFQty').AsString;
            FieldByName('ConKZ').Value:=ClientDataSet5.fieldbyname('KZQty').AsString;
            FieldByName('ConPrice').Value:=ClientDataSet5.fieldbyname('Price').Value;
          end;
          Post;
        end;
        with ADOQueryTemp do
        begin
          close;
          sql.Clear;
          sql.Add('select QtyUnit from JYOrder_Main_MD where PFID='''+Trim(PFID)+'''');
          sql.Add(' and isnull(CKName,'''')<>'''' ');
          sql.Add(' Group by QtyUnit');
          Open;
        end;
        if ADOQueryTemp.RecordCount>1 then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          ClientDataSet6.EnableControls;
          Application.MessageBox('单位不一致，不能保存数据!','提示',0);
          Exit;
        end;
        Edit;
        FieldByName('MDID').Value:=Trim(maxno);
        FieldByName('MDNO').Value:='TJ'+Trim(maxno);
        FieldByName('OrdMainID').Value:=Trim(FMainId);
        FieldByName('ConMainID').Value:=Trim(ConMainId);
        FieldByName('ConSubID').Value:=Trim(ConSubId);
        FieldByName('OrdSubId').Value:=Trim(OrdSubId);
        FieldByName('PSID').Value:=Trim(PSID);
        FieldByName('PFID').Value:=Trim(PFID);
        Post;
        Next;
      end;
    end;
    
    ADOQueryCmd.Connection.CommitTrans;
    ClientDataSet6.EnableControls;
  except
    ClientDataSet6.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存异常!','提示',0);
  end;
end;

procedure TfrmMaDanManageWW.v6Column8PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmGYSList:=TfrmGYSList.Create(Application);
    with frmGYSList do
    begin
      if ShowModal=1 then
      begin
        with Self.ClientDataSet6 do
        begin
          Edit;
          FieldByName('FromFactoryNo').Value:=Trim(frmGYSList.Order_Main.fieldbyname('ZKID').AsString) ;
          FieldByName('FromFactoryName').Value:=Trim(frmGYSList.Order_Main.fieldbyname('KHNameJC').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmGYSList.Free;
  end;
end;

procedure TfrmMaDanManageWW.v6Column2PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmGYSList:=TfrmGYSList.Create(Application);
    with frmGYSList do
    begin
      if ShowModal=1 then
      begin
        with Self.ClientDataSet6 do
        begin
          Edit;
          FieldByName('DutyFactoryNo').Value:=Trim(frmGYSList.Order_Main.fieldbyname('ZKID').AsString) ;
          FieldByName('DutyFactoryName').Value:=Trim(frmGYSList.Order_Main.fieldbyname('KHNameJC').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmGYSList.Free;
  end;
end;

procedure TfrmMaDanManageWW.v6Column14PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmGYSSelList:=TfrmGYSSelList.Create(Application);
    with frmGYSSelList do
    begin
      if ShowModal=1 then
      begin
        with Self.ClientDataSet6 do
        begin
          Edit;
          FieldByName('ToFactoryNo').Value:=Trim(frmGYSSelList.Order_Main.fieldbyname('ZKID').AsString) ;
          FieldByName('ToFactoryName').Value:=Trim(frmGYSSelList.Order_Main.fieldbyname('KHNameJC').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmGYSSelList.Free;
  end;
end;

procedure TfrmMaDanManageWW.v1Column2PropertiesEditValueChanged(
  Sender: TObject);
var
  PFID:String;
  Mvalue:Boolean;
begin
  Mvalue:=TcxCheckBox(Sender).EditingValue;
  PFID:=Trim(ClientDataSet1.fieldbyname('PFID').AsString);
  with ClientDataSet1 do
  begin
    while  ClientDataSet1.Locate('SSel',True,[])=True do
    begin
      Edit;
      FieldByName('SSel').Value:=False;
      Post;
    end;
    ClientDataSet1.Locate('PFID',PFID,[]);
    Edit;
    FieldByName('SSel').Value:=Mvalue;
    Post;
  end;
  if Mvalue=True then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from Contract_Main A inner join Contract_Sub B on A.MainId=B.MainId ');
      sql.Add(' where A.ConNo like '''+'%'+Trim(OrderNo.Text)+'%'+'''');
      sql.Add(' and A.ConType='''+Trim(ClientDataSet1.fieldbyname('PSName').AsString)+'''');
      sql.Add(' and A.FactoryNoName='''+Trim(ClientDataSet1.fieldbyname('FactoryName').AsString)+'''');
      if Trim(ClientDataSet1.fieldbyname('APType').AsString)='调用' then
      begin
        sql.Add(' and A.MainId not like ''CM%'' ');
      end else
      begin
        //sql.Add(' and A.MainId like ''CM%'' ');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,ClientDataSet5);
    SInitCDSData20(ADOQueryTemp,ClientDataSet5);
  end else
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*,B.*,Case when isnull(A.JYType,'''')<>'''' then Cast(1 as bit) else Cast(0 as bit) end as JYFlag   ');
      sql.Add(' from Contract_Main A inner join Contract_Sub B on A.MainId=B.MainId');
      sql.Add(' where A.ConNo like '''+'%'+Trim(OrderNo.Text)+'%'+'''');
      sql.Add(' and A.ConType='''+Trim(ClientDataSet1.fieldbyname('PSName').AsString)+'''');
      //sql.Add(' and A.FactoryNoName='''+Trim(ClientDataSet1.fieldbyname('FactoryName').AsString)+'''');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,ClientDataSet5);
    SInitCDSData20(ADOQueryTemp,ClientDataSet5);
  end;

  InitGrid();
end;

procedure TfrmMaDanManageWW.Tv6MouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  {with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main_MD where MDID='''+Trim(ClientDataSet6.fieldbyname('MDID').AsString)+'''');
    Open;
  end;}
  if ClientDataSet6.IsEmpty then Exit;
  if ClientDataSet6.fieldbyname('HCFlag').AsBoolean=True then
  begin
    Tv6.OptionsSelection.CellSelect:=False;
    Exit;
  end else
  begin
    Tv6.OptionsSelection.CellSelect:=True;

  end;
  if Trim(ClientDataSet6.fieldbyname('CRFlag').asstring)='入库' then
  begin
    Tv6.OptionsSelection.CellSelect:=False;
  end else
  begin
    Tv6.OptionsSelection.CellSelect:=True;
  end;
  if Trim(SParameters1)='高权限' then Exit;
  if Trim(ClientDataSet6.fieldbyname('MDID').asstring)<>'' then
  begin
    Tv6.OptionsSelection.CellSelect:=False;
  end else
  begin
    Tv6.OptionsSelection.CellSelect:=True;
  end;

end;

procedure TfrmMaDanManageWW.Tv3MouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if ClientDataSet3.fieldbyname('HCFlag').AsBoolean=True then
  begin
    Tv3.OptionsSelection.CellSelect:=False;
    Exit;
  end else
  begin
    Tv3.OptionsSelection.CellSelect:=True;

  end;
  if Trim(SParameters1)='高权限' then Exit;
  if ClientDataSet3.IsEmpty then Exit;
  if Trim(ClientDataSet3.fieldbyname('MDID').asstring)<>'' then
  begin
    Tv3.OptionsSelection.CellSelect:=False;
  end else
  begin
    Tv3.OptionsSelection.CellSelect:=True;
  end;
end;

procedure TfrmMaDanManageWW.FormShow(Sender: TObject);
begin
  ReadCxGrid('Tv11',Tv1,'外围码单');
  ReadCxGrid('Tv2',Tv2,'外围码单');
  ReadCxGrid('Tv3',Tv3,'外围码单');
  ReadCxGrid('Tv5',Tv5,'外围码单');
  ReadCxBandedGrid('Tv6',Tv6,'外围码单');
  cxPageControl1.ActivePageIndex:=0;
end;

procedure TfrmMaDanManageWW.Button7Click(Sender: TObject);
begin
  WriteCxGrid('Tv11',Tv1,'外围码单');
  WriteCxGrid('Tv2',Tv2,'外围码单');
  WriteCxGrid('Tv3',Tv3,'外围码单');
  WriteCxGrid('Tv5',Tv5,'外围码单');
  WriteCxBandedGrid('Tv6',Tv6,'外围码单');
  close;
end;

procedure TfrmMaDanManageWW.Tv3Column1PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,fsj:string;
begin
  mvalue:=TcxComboBox(Sender).EditingText;
  with ClientDataSet3 do
  begin
    Edit;
    FieldByName('FromFactoryName').Value:=Trim(mvalue);
    fsj:=TA((Tv3Column1.Properties as TcxComboBoxProperties).Items.Objects[(Tv3Column1.Properties as TcxComboBoxProperties).Items.IndexOf(Trim(mvalue))]).S;
    FieldByName('FromFactoryNo').Value:=Trim(fsj);
    Post;
  end;

end;

procedure TfrmMaDanManageWW.v6Column8PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,fsj:string;
begin
 { mvalue:=TcxComboBox(Sender).EditingText;
  with ClientDataSet6 do
  begin
    Edit;
    FieldByName('FromFactoryName').Value:=Trim(mvalue);
    fsj:=TA((v6Column8.Properties as TcxComboBoxProperties).Items.Objects[(v6Column8.Properties as TcxComboBoxProperties).Items.IndexOf(Trim(mvalue))]).S;
    FieldByName('FromFactoryNo').Value:=Trim(fsj);
    Post;
  end;}

end;

procedure TfrmMaDanManageWW.v6Column2PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,fsj:string;
begin
  mvalue:=TcxComboBox(Sender).EditingText;
  with ClientDataSet6 do
  begin
    Edit;
    FieldByName('DutyFactoryName').Value:=Trim(mvalue);
    fsj:=TA((v6Column2.Properties as TcxComboBoxProperties).Items.Objects[(v6Column2.Properties as TcxComboBoxProperties).Items.IndexOf(Trim(mvalue))]).S;
    FieldByName('DutyFactoryNo').Value:=Trim(fsj);
    Post;
  end;

end;

procedure TfrmMaDanManageWW.Button10Click(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 TfrmMaDanManageWW.v6Column3PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='DutyReason';
      flagname:='入库原因';
      if ShowModal=1 then
      begin
        with Self.ClientDataSet6 do
        begin
          Edit;
          FieldByName('DutyReason').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmMaDanManageWW.cxGridDBColumn32PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,JFPrice,JFQty:string;
begin
 
end;

procedure TfrmMaDanManageWW.v6Column16PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='RKYongTu';
      flagname:='用途';
      if ShowModal=1 then
      begin
        with Self.ClientDataSet6 do
        begin
          Edit;
          FieldByName('RKYongTu').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.
