unit U_YPGL_YGDJ;

interface

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

type
  TfrmYPGLYGDJ = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOQuery1: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOCmd: TADOQuery;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    DataSource2: TDataSource;
    Order_ZL: TClientDataSet;
    DataSource3: TDataSource;
    Order_MLJG: TClientDataSet;
    DataSource4: TDataSource;
    Order_FL: TClientDataSet;
    DataSource5: TDataSource;
    Order_CBJG: TClientDataSet;
    cxStyle2: TcxStyle;
    cxTabControl1: TcxTabControl;
    cxPageControl1: TcxPageControl;
    cxTabSheet2: TcxTabSheet;
    cxGrid4: TcxGrid;
    TV2: TcxGridDBBandedTableView;
    cxGridDBBandedColumn19: TcxGridDBBandedColumn;
    cxGridDBBandedColumn20: TcxGridDBBandedColumn;
    TV2Qty: TcxGridDBBandedColumn;
    TV2PRTPrice: TcxGridDBBandedColumn;
    TV2Money: TcxGridDBBandedColumn;
    cxGridLevel3: TcxGridLevel;
    cxTabSheet3: TcxTabSheet;
    cxTabSheet4: TcxTabSheet;
    cxTabSheet1: TcxTabSheet;
    cxGrid3: TcxGrid;
    TV3: TcxGridDBBandedTableView;
    TV3XHNo: TcxGridDBBandedColumn;
    TV3PrtCodeName: TcxGridDBBandedColumn;
    TV3Qty: TcxGridDBBandedColumn;
    TV3PRTPrice: TcxGridDBBandedColumn;
    TV3Money: TcxGridDBBandedColumn;
    cxGridLevel2: TcxGridLevel;
    ScrollBox1: TScrollBox;
    Label14: TLabel;
    Label22: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    Label30: TLabel;
    Label2: TLabel;
    Label12: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    Label35: TLabel;
    Label36: TLabel;
    Label37: TLabel;
    Label38: TLabel;
    Label39: TLabel;
    Label40: TLabel;
    Label45: TLabel;
    Label47: TLabel;
    Label7: TLabel;
    Label1: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    BankFastNo: TEdit;
    CPTanLi: TCheckBox;
    CPRanYin: TRadioGroup;
    CPRanHouGY: TBtnEditC;
    CPType: TRadioGroup;
    CPZHName: TEdit;
    CPCFNo: TEdit;
    CPCFBi: TEdit;
    conDefstr1: TEdit;
    conDefstr4: TEdit;
    conDefstr8: TEdit;
    conDefstr7: TEdit;
    conDefstr5: TEdit;
    conDefstr6: TEdit;
    condefNote1: TEdit;
    FLMoney: TcxCurrencyEdit;
    CYNo: TcxCurrencyEdit;
    ZLMoney: TcxCurrencyEdit;
    MLJGMoney: TcxCurrencyEdit;
    CPJGMoney: TcxCurrencyEdit;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    Label5: TLabel;
    CYName: TcxCurrencyEdit;
    cxGrid2: TcxGrid;
    TV4: TcxGridDBBandedTableView;
    TV4XHNo: TcxGridDBBandedColumn;
    TV4PrtCodeName: TcxGridDBBandedColumn;
    TV4XLQty: TcxGridDBBandedColumn;
    TV4PRTPrice: TcxGridDBBandedColumn;
    TV4Money: TcxGridDBBandedColumn;
    cxGridLevel1: TcxGridLevel;
    cxGrid5: TcxGrid;
    TV5: TcxGridDBBandedTableView;
    TV5XHNo: TcxGridDBBandedColumn;
    TV5PrtCodeName: TcxGridDBBandedColumn;
    TV5Qty: TcxGridDBBandedColumn;
    TV5PRTPrice: TcxGridDBBandedColumn;
    tv5Money: TcxGridDBBandedColumn;
    cxGridLevel4: TcxGridLevel;
    Label6: TLabel;
    ZMoney: TcxCurrencyEdit;
    V2Column1: TcxGridDBBandedColumn;
    V4Column1: TcxGridDBBandedColumn;
    V5Column1: TcxGridDBBandedColumn;
    V3Column1: TcxGridDBBandedColumn;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TV4XLQtyPropertiesEditValueChanged(Sender: TObject);
    procedure TV5QtyPropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure TV2CustomDrawIndicatorCell(Sender: TcxGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo;
      var ADone: Boolean);
    procedure V2Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure TV2QtyPropertiesEditValueChanged(Sender: TObject);
    procedure V4Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cxGridDBBandedColumn20PropertiesEditValueChanged(
      Sender: TObject);
    procedure TV4PrtCodeNamePropertiesEditValueChanged(Sender: TObject);
    procedure TV3QtyPropertiesEditValueChanged(Sender: TObject);
    procedure TV5PrtCodeNamePropertiesEditValueChanged(Sender: TObject);
    procedure TV3PrtCodeNamePropertiesEditValueChanged(Sender: TObject);
    procedure V5Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure V3Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cxPageControl1Change(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
  private
    procedure InitData();
    procedure ZDYHelp(FButn:TcxButtonEdit;LType:string);
    function  SaveData(ado:TADOQuery;cds:TClientDataSet;MCYID,MYGType,MYGLevel:string):Boolean;
    function  DelData(ado:TADOQuery;cds:TClientDataSet;MYGID:string):Boolean;
    procedure HJ();
    { Private declarations }
  public
    PState,CopyInt:Integer;
    FCYID:String;
    { Public declarations }
  end;

var
  frmYPGLYGDJ: TfrmYPGLYGDJ;
  newh:hwnd;
implementation
uses
  U_DataLink,U_ZDYHelp,U_Fun, U_CPManageCX;

{$R *.dfm}
function TfrmYPGLYGDJ.DelData(ado:TADOQuery;cds:TClientDataSet;MYGID:string):Boolean;
begin
  try
    with ado do
    begin
      Close;
      SQL.Clear;
      sql.Add('delete CP_YDang_CBYG where YGID='''+Trim(MYGID)+'''');
      ExecSQL;
    end;
    cds.Delete;
    Result:=True;
  except
    Result:=False;
  end;
end;  
function TfrmYPGLYGDJ.SaveData(ado:TADOQuery;cds:TClientDataSet;MCYID,MYGType,MYGLevel:string):Boolean;
var
  maxId:string;
begin
  try
    if GetLSNo(ado,maxId,'YG','CP_YDang_CBYG',4,1)=False then
    begin
      Application.MessageBox('取最大号失败！','提示',0);
      Exit;
    end;
    with ado do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from CP_YDang_CBYG where YGID='''+Trim(FCYID)+'''');
      Open;
    end;
    with ado do
    begin
      Append;
      FieldByName('YGID').Value:=Trim(maxId);
      FieldByName('CYID').Value:=Trim(MCYID);
      FieldByName('YGType').Value:=Trim(MYGType);
      FieldByName('YGLevel').Value:=Trim(MYGLevel);
      FieldByName('Filler').Value:=Trim(DName);
      Post;
    end;
  
    with cds do
    begin
      Append;
      FieldByName('YGID').Value:=Trim(maxId);
      FieldByName('YGType').Value:=Trim(MYGType);
      FieldByName('CYID').Value:=Trim(MCYID);
      FieldByName('YGLevel').Value:=Trim(MYGLevel);
      FieldByName('Filler').Value:=Trim(DName);
      Post;
    end;
    Result:=True;
  except
    Result:=False;
  end;
end;
procedure TfrmYPGLYGDJ.HJ();
var
  FZLMoney,FFLMoney,FCPJGMoney,FMLJGMoney,FZMoney:Double;
begin
  //主料成本
  if TV2.DataController.Summary.FooterSummaryValues[2]<>NULL then
    FZLMoney:=TV2.DataController.Summary.FooterSummaryValues[2]
  else
    FZLMoney:=0;
  //辅料成本
  if TV4.DataController.Summary.FooterSummaryValues[1]<>NULL then
    FFLMoney:=TV4.DataController.Summary.FooterSummaryValues[1]
  else
    FFLMoney:=0;
  //成品加工成本
  if TV5.DataController.Summary.FooterSummaryValues[1]<>NULL then
    FCPJGMoney:=TV5.DataController.Summary.FooterSummaryValues[1]
  else
    FCPJGMoney:=0;
  //面料加工成本
  if TV3.DataController.Summary.FooterSummaryValues[1]<>NULL then
    FMLJGMoney:=TV3.DataController.Summary.FooterSummaryValues[1]
  else
    FMLJGMoney:=0;

  FZMoney:= FZLMoney+FFLMoney+FCPJGMoney+FMLJGMoney;

   ZLMoney.Text:=FloatToStr(FZLMoney);
   FLMoney.Text:=FloatToStr(FFLMoney);
   CPJGMoney.Text:=FloatToStr(FCPJGMoney);
   MLJGMoney.Text:=FloatToStr(FMLJGMoney);
   ZMoney.Text:=FloatToStr(FZMoney);

end;

procedure TfrmYPGLYGDJ.TBCloseClick(Sender: TObject);
begin
  Close;
//  WriteCxBandedGrid('预估成本1',Tv1,'预估成本管理');
//  WriteCxBandedGrid('预估成本2',Tv2,'预估成本管理');
//  WriteCxBandedGrid('预估成本3',Tv3,'预估成本管理');
//  WriteCxBandedGrid('预估成本4',Tv4,'预估成本管理');
//  WriteCxBandedGrid('预估成本5',Tv5,'预估成本管理');
end;

procedure TfrmYPGLYGDJ.InitData();
var i:Integer;
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('select A.* ');
    sql.Add('from CP_YDang_CBYG A ');
    sql.Add('where A.CYID='+quotedstr(Trim(FCYID)));
    sql.add(' and A.YGLevel='+quotedstr(Trim(IntToStr(cxTabControl1.TabIndex))));
    sql.add(' and A.YGType='+quotedstr('主料'));
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_ZL);
  SInitCDSData20(ADOQuery1,Order_ZL);
  
   with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('select A.* ');
    sql.Add('from CP_YDang_CBYG A ');
    sql.Add('where A.CYID='+quotedstr(Trim(FCYID)));
    sql.add(' and A.YGLevel='+quotedstr(Trim(IntToStr(cxTabControl1.TabIndex))));
    sql.add(' and A.YGType='+quotedstr('面料加工'));
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_MLJG);
  SInitCDSData20(ADOQuery1,Order_MLJG);

  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('select A.* ');
    sql.Add('from CP_YDang_CBYG A ');
    sql.Add('where A.CYID='+quotedstr(Trim(FCYID)));
    sql.add(' and A.YGLevel='+quotedstr(Trim(IntToStr(cxTabControl1.TabIndex))));
    sql.add(' and A.YGType='+quotedstr('辅料'));
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_FL);
  SInitCDSData20(ADOQuery1,Order_FL);

  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('select A.* ');
    sql.Add('from CP_YDang_CBYG A ');
    sql.Add('where A.CYID='+quotedstr(Trim(FCYID)));
    sql.add(' and A.YGLevel='+quotedstr(Trim(IntToStr(cxTabControl1.TabIndex))));
    sql.add(' and A.YGType='+quotedstr('成品加工'));
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_CBJG);
  SInitCDSData20(ADOQuery1,Order_CBJG);

end;

procedure TfrmYPGLYGDJ.ZDYHelp(FButn:TcxButtonEdit;LType:string);
var
  FType,ZDYName,FText:String;
begin
end;

procedure TfrmYPGLYGDJ.FormShow(Sender: TObject);
begin
//  ReadCxBandedGrid('预估成本1',Tv1,'预估成本管理');
//  ReadCxBandedGrid('预估成本2',Tv2,'预估成本管理');
//  ReadCxBandedGrid('预估成本3',Tv3,'预估成本管理');
//  ReadCxBandedGrid('预估成本4',Tv4,'预估成本管理');
//  ReadCxBandedGrid('预估成本5',Tv5,'预估成本管理');

  InitData();
  HJ();
end;

procedure TfrmYPGLYGDJ.TV4XLQtyPropertiesEditValueChanged(
  Sender: TObject);
var
  mavlue,FFieldName:string;
  FQty,FMoney,FPrice:Double;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Tv4.Controller.FocusedColumn.DataBinding.FilterFieldName;
  if mavlue='' then
  mavlue:='0';
  with Order_FL do
  begin
    edit;
    FieldByName(FFieldName).Value:=mavlue;
    post;
    FQty:= FieldByName('Qty').AsFloat;
    FPrice:=FieldByName('Price').AsFloat;
  end;

  FMoney:=FQty*FPrice;
  
  with Order_FL do
  begin
    edit;
    FieldByName('Money').Value:=FMoney;
    post;
  end;
   with ADOCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('update CP_YDang_CBYG set Money='+quotedstr(FloatToStr(FMoney)));
      SQL.Add(','+FFieldName+'='+quotedstr(mavlue));
      SQL.Add(' where YGID='+quotedstr(Trim(Order_FL.fieldbyname('YGID').AsString)));
      ExecSQL;
    end;
  tv4.Controller.EditingController.ShowEdit();
  HJ();
end;

procedure TfrmYPGLYGDJ.TV5QtyPropertiesEditValueChanged(
  Sender: TObject);
var
  mavlue,FFieldName:string;
  FQty,FMoney,FPrice:Double;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Tv5.Controller.FocusedColumn.DataBinding.FilterFieldName;
  if mavlue='' then
  mavlue:='0';
  with Order_CBJG do
  begin
    edit;
    FieldByName(FFieldName).Value:=mavlue;
    post;
    FQty:= FieldByName('Qty').AsFloat;
    FPrice:=FieldByName('Price').AsFloat;
  end;

  FMoney:=FQty*FPrice;
  
  with Order_CBJG do
  begin
    edit;
    FieldByName('Money').Value:=FMoney;
    post;
  end;
   with ADOCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('update CP_YDang_CBYG set Money='+quotedstr(FloatToStr(FMoney)));
      SQL.Add(','+FFieldName+'='+quotedstr(mavlue));
      SQL.Add(' where YGID='+quotedstr(Trim(Order_CBJG.fieldbyname('YGID').AsString)));
      ExecSQL;
    end;
  tv5.Controller.EditingController.ShowEdit();
  HJ();
end;

procedure TfrmYPGLYGDJ.ToolButton1Click(Sender: TObject);
begin
  case cxPageControl1.ActivePageIndex of
  0:begin
      SaveData(ADOCmd,Order_ZL,FCYID,'主料',IntToStr(cxTabControl1.TabIndex));
    end;
  1:begin
      SaveData(ADOCmd,Order_FL,FCYID,'辅料',IntToStr(cxTabControl1.TabIndex));
    end;
  2:begin
      SaveData(ADOCmd,Order_CBJG,FCYID,'面料加工',IntToStr(cxTabControl1.TabIndex));
    end;
  3:begin
     SaveData(ADOCmd,Order_MLJG,FCYID,'成品加工',IntToStr(cxTabControl1.TabIndex));
    end;
  end;
end;

procedure TfrmYPGLYGDJ.TV2CustomDrawIndicatorCell(Sender: TcxGridTableView;
  ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo;
  var ADone: Boolean);
var
  FValue: string;
  FBounds: TRect;
begin
  if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
  begin
    FValue :=IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index+1);
    FBounds := AViewInfo.Bounds;
    ACanvas.FillRect(FBounds);
    ACanvas.DrawComplexFrame(FBounds, clBtnHighlight, clBtnShadow, [bBottom, bLeft, bRight], 1);
    InflateRect(FBounds, -1, -1);
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
    ACanvas.DrawText(FValue, FBounds, cxAlignCenter or cxAlignTop);
    ADone := True;
  end;
end;

procedure TfrmYPGLYGDJ.V2Column1PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
var
  FValue:string;
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='ZLQtyUnit';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        FValue:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
    with Order_ZL do
    begin
      Edit;
      FieldByName('QtyUnit').Value:=FValue;
      Post;
    end;
    with ADOCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('update CP_YDang_CBYG set QtyUnit='+quotedstr(FValue));
      SQL.Add(' where YGID='+quotedstr(Trim(Order_ZL.fieldbyname('YGID').AsString)));
      ExecSQL;
    end;
  finally
    tv2.Controller.EditingController.ShowEdit();
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYPGLYGDJ.TV2QtyPropertiesEditValueChanged(Sender: TObject);
var
  mavlue,FFieldName:string;
  FQty,FMoney,FPrice:Double;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName;
  if mavlue='' then
  mavlue:='0';
  with Order_ZL do
  begin
    edit;
    FieldByName(FFieldName).Value:=mavlue;
    post;
    FQty:= FieldByName('Qty').AsFloat;
    FPrice:=FieldByName('Price').AsFloat;
  end;
     FMoney:=FQty*FPrice;
  with Order_ZL do
  begin
    edit;
    FieldByName('Money').Value:=FMoney;
    post;
  end;
   with ADOCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('update CP_YDang_CBYG set Money='+quotedstr(FloatToStr(FMoney)));
      SQL.Add(','+FFieldName+'='+quotedstr(mavlue));
      SQL.Add(' where YGID='+quotedstr(Trim(Order_ZL.fieldbyname('YGID').AsString)));
      ExecSQL;
    end;
  tv2.Controller.EditingController.ShowEdit();
  HJ();
end;

procedure TfrmYPGLYGDJ.V4Column1PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
var
  FValue:string;
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='FLQtyUnit';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        FValue:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
    with Order_FL do
    begin
      Edit;
      FieldByName('QtyUnit').Value:=FValue;
      Post;
    end;
    with ADOCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('update CP_YDang_CBYG set QtyUnit='+quotedstr(FValue));
      SQL.Add(' where YGID='+quotedstr(Trim(Order_FL.fieldbyname('YGID').AsString)));
      ExecSQL;
    end;
  finally
    tv4.Controller.EditingController.ShowEdit();
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYPGLYGDJ.cxGridDBBandedColumn20PropertiesEditValueChanged(
  Sender: TObject);
var
  mavlue,FFieldName:string;
begin
  mavlue:=Trim(TcxTextEdit(Sender).EditingText);
  FFieldName:=Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with Order_ZL do
  begin
    edit;
    FieldByName(FFieldName).Value:=mavlue;
    post;
  end;
  with ADOCmd do
  begin
    Close;
    SQL.Clear;
    SQL.Add('update CP_YDang_CBYG set '+FFieldName+'='+quotedstr(mavlue));
    SQL.Add(' where YGID='+quotedstr(Trim(Order_ZL.fieldbyname('YGID').AsString)));
    ExecSQL;
  end;
  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmYPGLYGDJ.TV4PrtCodeNamePropertiesEditValueChanged(
  Sender: TObject);
var
  mavlue,FFieldName:string;
begin
  mavlue:=Trim(TcxTextEdit(Sender).EditingText);
  FFieldName:=Tv4.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with Order_FL do
  begin
    edit;
    FieldByName(FFieldName).Value:=mavlue;
    post;
  end;
  with ADOCmd do
  begin
    Close;
    SQL.Clear;
    SQL.Add('update CP_YDang_CBYG set '+FFieldName+'='+quotedstr(mavlue));
    SQL.Add(' where YGID='+quotedstr(Trim(Order_FL.fieldbyname('YGID').AsString)));
    ExecSQL;
  end;
  tv4.Controller.EditingController.ShowEdit();
end;

procedure TfrmYPGLYGDJ.TV3QtyPropertiesEditValueChanged(Sender: TObject);
var
  mavlue,FFieldName:string;
  FQty,FMoney,FPrice:Double;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Tv3.Controller.FocusedColumn.DataBinding.FilterFieldName;
  if mavlue='' then
  mavlue:='0';
  with Order_MLJG do
  begin
    edit;
    FieldByName(FFieldName).Value:=mavlue;
    post;
    FQty:= FieldByName('Qty').AsFloat;
    FPrice:=FieldByName('Price').AsFloat;
  end;

  FMoney:=FQty*FPrice;
  
  with Order_MLJG do
  begin
    edit;
    FieldByName('Money').Value:=FMoney;
    post;
  end;
   with ADOCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('update CP_YDang_CBYG set Money='+quotedstr(FloatToStr(FMoney)));
      SQL.Add(','+FFieldName+'='+quotedstr(mavlue));
      SQL.Add(' where YGID='+quotedstr(Trim(Order_MLJG.fieldbyname('YGID').AsString)));
      ExecSQL;
    end;
  tv3.Controller.EditingController.ShowEdit();
  HJ();
end;

procedure TfrmYPGLYGDJ.TV5PrtCodeNamePropertiesEditValueChanged(
  Sender: TObject);
var
  mavlue,FFieldName:string;
begin
  mavlue:=Trim(TcxTextEdit(Sender).EditingText);
  FFieldName:=Tv5.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with Order_CBJG do
  begin
    edit;
    FieldByName(FFieldName).Value:=mavlue;
    post;
  end;
  with ADOCmd do
  begin
    Close;
    SQL.Clear;
    SQL.Add('update CP_YDang_CBYG set '+FFieldName+'='+quotedstr(mavlue));
    SQL.Add(' where YGID='+quotedstr(Trim(Order_CBJG.fieldbyname('YGID').AsString)));
    ExecSQL;
  end;
  tv5.Controller.EditingController.ShowEdit();
end;

procedure TfrmYPGLYGDJ.TV3PrtCodeNamePropertiesEditValueChanged(
  Sender: TObject);
var
  mavlue,FFieldName:string;
begin
  mavlue:=Trim(TcxTextEdit(Sender).EditingText);
  FFieldName:=Tv3.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with Order_MLJG do
  begin
    edit;
    FieldByName(FFieldName).Value:=mavlue;
    post;
  end;
  with ADOCmd do
  begin
    Close;
    SQL.Clear;
    SQL.Add('update CP_YDang_CBYG set '+FFieldName+'='+quotedstr(mavlue));
    SQL.Add(' where YGID='+quotedstr(Trim(Order_MLJG.fieldbyname('YGID').AsString)));
    ExecSQL;
  end;
  tv3.Controller.EditingController.ShowEdit();
end;

procedure TfrmYPGLYGDJ.V5Column1PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
var
  FValue:string;
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CPQtyUnit';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        FValue:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
    with Order_CBJG do
    begin
      Edit;
      FieldByName('QtyUnit').Value:=FValue;
      Post;
    end;
    with ADOCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('update CP_YDang_CBYG set QtyUnit='+quotedstr(FValue));
      SQL.Add(' where YGID='+quotedstr(Trim(Order_CBJG.fieldbyname('YGID').AsString)));
      ExecSQL;
    end;
  finally
    tv5.Controller.EditingController.ShowEdit();
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYPGLYGDJ.V3Column1PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
var
  FValue:string;
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MLQtyUnit';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        FValue:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
    with Order_MLJG do
    begin
      Edit;
      FieldByName('QtyUnit').Value:=FValue;
      Post;
    end;
    with ADOCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('update CP_YDang_CBYG set QtyUnit='+quotedstr(FValue));
      SQL.Add(' where YGID='+quotedstr(Trim(Order_MLJG.fieldbyname('YGID').AsString)));
      ExecSQL;
    end;
  finally
    tv3.Controller.EditingController.ShowEdit();
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYPGLYGDJ.cxPageControl1Change(Sender: TObject);
begin
  InitData();
  HJ();
end;

procedure TfrmYPGLYGDJ.ToolButton2Click(Sender: TObject);
begin
  case cxPageControl1.ActivePageIndex of
  0:begin
      DelData(ADOCmd,Order_ZL,Trim(Order_ZL.fieldbyname('YGID').AsString));
    end;
  1:begin
      DelData(ADOCmd,Order_FL,Trim(Order_FL.fieldbyname('YGID').AsString));
    end;
  2:begin
      DelData(ADOCmd,Order_CBJG,Trim(Order_CBJG.fieldbyname('YGID').AsString));
    end;
  3:begin
     DelData(ADOCmd,Order_MLJG,Trim(Order_MLJG.fieldbyname('YGID').AsString));
    end;  
  end;
end;

procedure TfrmYPGLYGDJ.cxTabControl1Change(Sender: TObject);
begin
  InitData();
  HJ();
end;

end.
