unit U_XSPriceChk;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin,
  StdCtrls, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP,ShellAPI,IniFiles, cxCheckBox, cxCalendar,
  cxButtonEdit, cxTextEdit, cxPC, cxDropDownEdit, Menus;

type
  TfrmXSPriceChk = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    Label3: TLabel;
    FactoryName10: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2CRTime: TcxGridDBColumn;
    v2Qty: TcxGridDBColumn;
    v2QtyUnit: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    v2Column1: TcxGridDBColumn;
    VYB: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    VOrderNo: TcxGridDBColumn;
    v2Note: TcxGridDBColumn;
    v2P_CodeName: TcxGridDBColumn;
    v2ps: TcxGridDBColumn;
    v2P_Spec: TcxGridDBColumn;
    P_CodeName: TEdit;
    Label4: TLabel;
    v2Column7: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    CheckBox1: TCheckBox;
    v2Column13: TcxGridDBColumn;
    Label12: TLabel;
    ChkStatusP: TComboBox;
    v2YunDanNo: TcxGridDBColumn;
    v2P_MF: TcxGridDBColumn;
    v2P_KZ: TcxGridDBColumn;
    v2P_Color: TcxGridDBColumn;
    v2P_HX: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    Label7: TLabel;
    BZTYpe: TComboBox;
    v2Column3: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    Label5: TLabel;
    HanShui: TComboBox;
    v2Column5: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    Label1: TLabel;
    N4: TMenuItem;
    N5: TMenuItem;
    v2Column9: TcxGridDBColumn;
    N6: TMenuItem;
    N7: TMenuItem;
    Panel2: TPanel;
    v2Column10: TcxGridDBColumn;
    Label2: TLabel;
    P_HX: TEdit;
    Label6: TLabel;
    ChkStatusQ: TComboBox;
    v2Column11: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    v2Column14: TcxGridDBColumn;
    v2Column15: TcxGridDBColumn;
    Label8: TLabel;
    FactoryNo: TEdit;
    v2Column16: TcxGridDBColumn;
    Label9: TLabel;
    ConNo: TEdit;
    Label10: TLabel;
    P_Color: TEdit;
    Label11: TLabel;
    ChkerQ: TEdit;
    v2Column17: TcxGridDBColumn;
    v2Column18: TcxGridDBColumn;
    Panel3: TPanel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure FactoryName10Change(Sender: TObject);
    procedure cxGridDBColumn5PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn1PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cxGridDBColumn6PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure v2Column2PropertiesEditValueChanged(Sender: TObject);
    procedure v2BatchNoPropertiesEditValueChanged(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure v2Column7PropertiesEditValueChanged(Sender: TObject);
    procedure v2Column8PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure FactoryName10KeyPress(Sender: TObject; var Key: Char);
    procedure v2Column11CustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure v2Column11PropertiesEditValueChanged(Sender: TObject);
    procedure v2Column14PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2P_SpecPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure Tv2StylesGetContentStyle(Sender: TcxCustomGridTableView;
      ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem;
      out AStyle: TcxStyle);
    procedure N6Click(Sender: TObject);
    procedure N7Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure N5Click(Sender: TObject);
    procedure FactoryNoKeyPress(Sender: TObject; var Key: Char);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure ChkerQKeyPress(Sender: TObject; var Key: Char);

  private
    { Private declarations }

    procedure InitGridHZ();
    procedure InitGrid();
    function  SaveData():Boolean;
    procedure InitYFName();
  public
    fFlag:integer;
    { Public declarations }
    RKFlag,FCYID,fmanage:String;

  end;

var
  frmXSPriceChk: TfrmXSPriceChk;

implementation
uses
  U_DataLink,U_ZDYHelp,U_YSEdit,U_RTFun,U_KHListSelJJ,U_Fun;

{$R *.dfm}
procedure TfrmXSPriceChk.InitGrid();
begin
  ToolBar1.SetFocus;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      Filtered:=False;
      sql.Add(' select A.*,QtyStr=dbo.[F_Get_ShuZiStr](A.Qty),MoneyStr=dbo.[F_Get_ShuZiStr](A.Money) ');
      sql.Add(',FactoryName10=dbo.getPinYin(A.FactoryName)+RTrim(A.FactoryName)');
      sql.Add(',Case when isnull(BZType,'''')=''￥'' then Money else Null end as MoneyRMB ');
      sql.Add(',Case when isnull(BZType,'''')=''$'' then Money else Null end as MoneyMJ ');
      sql.Add(' from YS_Money_CR A');
      if CheckBox1.Checked then
      begin
        sql.Add('where A.CRTime>='''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+''' ');
        sql.Add(' and CRTime<'''+FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)+''' ');
      end else
      begin
        sql.Add('where A.CRTime>=''2000-01-01'' ');
        sql.Add(' and CRTime<''2500-01-01'' ');
      end;
      sql.Add(' and A.CRType=''应收款登记''  ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
    ToolButton2.Click;
  end;
end;
procedure TfrmXSPriceChk.InitGridHZ();
begin
end;

procedure TfrmXSPriceChk.FormDestroy(Sender: TObject);
begin
 // frmYFCR:=nil;
  frmXSPriceChk:=nil;
end;

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

procedure TfrmXSPriceChk.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('应收款登记YX',Tv2,'财务管理');
  Close;
end;
procedure TfrmXSPriceChk.FormShow(Sender: TObject);
begin
  ReadCxGrid('应收款登记YX',Tv2,'财务管理');
  Enddate.DateTime:=SGetServerDate(ADOQueryTemp);
  begdate.DateTime:=SGetServerDateMBeg(ADOQueryTemp);
  InitGrid();
end;
procedure TfrmXSPriceChk.InitYFName();

begin

end;

procedure TfrmXSPriceChk.TBRafreshClick(Sender: TObject);
begin
  begdate.SetFocus;
  InitGrid();
end;

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

procedure TfrmXSPriceChk.FactoryName10Change(Sender: TObject);
begin
  ToolButton2.Click;
end;

function TfrmXSPriceChk.SaveData():Boolean;
var
  maxId,CRID:String;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if GetLSNo(ADOQueryCmd,maxId,'YS','YS_Money_CR',4,1)=False then
    begin
      Result:=False;
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败！','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YS_Money_KC where FactoryName='''+Trim(CDS_HZ.fieldbyname('FactoryName').AsString)+''' ');
      sql.Add(' and KCType=''KH'' ');
      Open;
    end;
    if ADOQueryCmd.IsEmpty=False then
    begin
      CRID:=ADOQueryCmd.fieldbyname('CRID').AsString;
    end else
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update YS_Money_CRID set CRID=CRID+1');
        sql.Add('select * from YS_Money_CRID ');
        Open;
      end;
      CRID:=ADOQueryCmd.fieldbyname('CRID').AsString;
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from YS_Money_KC where 1<>1');
        Open;
      end;
      with ADOQueryCmd do
      begin
        Append;
        FieldByName('CRID').Value:=StrToInt(CRID);
        FieldByName('FactoryNo').Value:=Trim(CDS_HZ.fieldbyname('FactoryNo').AsString);
        FieldByName('FactoryName').Value:=Trim(CDS_HZ.fieldbyname('FactoryName').AsString);
        FieldByName('ZdyStr1').Value:='应收收';
        Post;
      end;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YS_Money_CR where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('YFID').Value:=Trim(maxId);
      FieldByName('CRID').Value:=StrToInt(CRID);
      RTSetSaveDataCDS(ADOQueryCmd,Tv2,CDS_HZ,'YS_Money_CR',7);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('CRType').Value:='应收款登记';
      FieldByName('CRFlag').Value:='应收收';
      FieldByName('QtyFlag').Value:=1;
      FieldByName('FactoryNo').Value:=Trim(CDS_HZ.fieldbyname('FactoryNo').AsString);
      FieldByName('FactoryName').Value:=Trim(CDS_HZ.fieldbyname('FactoryName').AsString);
      FieldByName('CRTime').Value:=formatdateTIme('yyyy-MM-dd',CDS_HZ.fieldbyname('CRTime').AsDateTime);
      Post;
    end;
    with CDS_HZ do
    begin
      Edit;
      FieldByName('YFId').Value:=Trim(maxId);
      FieldByName('CRID').Value:=StrToInt(CRID);
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=True;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('增行失败!','提示',0);
  end;
end;

procedure TfrmXSPriceChk.cxGridDBColumn5PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FQty,FPrice,FMoney,FShuiDian,FHSPrice,FHSMoney,FJSMoney,FHZFee,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    if Trim(mvalue)<>'' then
      FieldByName(FFieldName).Value:=Trim(mvalue)
    else
      FieldByName(FFieldName).Value:=Null;
    Post;
  end;

  FQty:=Trim(CDS_HZ.fieldbyname('Qty').AsString);
  if Trim(FQty)='' then FQty:='0';

  FPrice:=Trim(CDS_HZ.fieldbyname('Price').AsString);
  if Trim(FPrice)='' then FPrice:='0';
  FQty:=Trim(CDS_HZ.fieldbyname('Qty').AsString);
  if Trim(FQty)='' then FQty:='0';

  FHZFee:=Trim(CDS_HZ.fieldbyname('HZFee').AsString);
  if Trim(FHZFee)='' then FHZFee:='0';

  FMoney:=Trim(CDS_HZ.fieldbyname('Money').AsString);
  if Trim(FMoney)='' then FMoney:='0';

  if Trim(FFieldName)<>'Money' then
  begin
    FMoney:=FloatToStr(StrToFloat(FQty)*StrToFloat(FPrice)+StrToFloat(FHZFee));
  end;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('Money').Value:=StrToFloat(FMoney);
    if Trim(CDS_HZ.fieldbyname('BZType').AsString)='￥' then
    begin
      FieldByName('MoneyRMB').Value:=StrToFloat(FMoney);
    end else
    if Trim(CDS_HZ.fieldbyname('BZType').AsString)='$' then
    begin
      FieldByName('MoneyMJ').Value:=StrToFloat(FMoney);
    end;
    Post;
  end;

  FShuiDian:=Trim(CDS_HZ.fieldbyname('ShuiDian').AsString);
  if Trim(FShuiDian)='' then FShuiDian:='0';

  if Trim(CDS_HZ.fieldbyname('ShuiDian').AsString)<>'' then
  begin
    with CDS_HZ do
    begin
      Edit;
      FieldByName('HSPrice').Value:=StrToFloat(FPrice)*(1+StrToFloat(FShuiDian)*0.01);
      FieldByName('HSMoney').Value:=StrToFloat(FPrice)*(1+StrToFloat(FShuiDian)*0.01)*StrToFloat(FQty)+StrToFloat(FHZFee);
      FieldByName('JSMoney').Value:=StrToFloat(FPrice)*(1+StrToFloat(FShuiDian)*0.01)*StrToFloat(FQty)+StrToFloat(FHZFee);
      post;
    end;
  end else
  begin
    with CDS_HZ do
    begin
      Edit;
      FieldByName('HSPrice').Value:=Null;
      FieldByName('HSMoney').Value:=Null;
      FieldByName('JSMoney').Value:=StrToFloat(FMoney);
      post;
    end;
  end;


  
  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmXSPriceChk.cxGridDBColumn1PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  
  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmXSPriceChk.cxGridDBColumn3PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if Trim(CDS_HZ.FieldByName('YFType').AsString)='自动生成' then
  begin
    Application.MessageBox('自动生成的数据不能修改!','提示',0);
    Exit;
  end;
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='YFName';
      flagname:='项目及摘要';
      MainType:='付款';
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('YFCode').Value:=Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString);
          FieldByName('YFName').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
        
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmXSPriceChk.cxGridDBColumn6PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrderUnit';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        Self.CDS_HZ.Edit;
        Self.CDS_HZ.FieldByName('QtyUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmXSPriceChk.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv2,ADOQueryMain,'应收款列表');
end;

procedure TfrmXSPriceChk.v2Column2PropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FBBMoney,FKCBB,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  if Trim(mvalue)='' then
  begin
    mvalue:='0';
  end;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;

 
end;

procedure TfrmXSPriceChk.v2BatchNoPropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  
end;

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

procedure TfrmXSPriceChk.v2Column7PropertiesEditValueChanged(Sender: TObject);
var
  mvalue:Boolean;
begin
  mvalue:=TcxCheckBox(Sender).EditingValue;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('KPFlag').Value:=mvalue;
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('update YS_Money_CR Set ');
    if mvalue=true then
    begin
      sql.Add(' KPFlag=1 ');
    end else
    begin
      sql.Add(' KPFlag=0 ');
    end;
    sql.Add(' where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmXSPriceChk.v2Column8PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if Trim(CDS_HZ.FieldByName('YFType').AsString)='自动生成' then
  begin
    Application.MessageBox('自动生成的数据不能修改!','提示',0);
    Exit;
  end;
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='GSTT';
      flagname:='公司抬头';
      V1Name.Caption:='中文名称';
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('ComTaiTou').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YS_Money_CR ');
          sql.Add(' Set ComTaiTou='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(',Editer='''+Trim(DName)+'''');
          SQL.Add(',Edittime=getdate() ');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmXSPriceChk.FactoryName10KeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then
  begin
    if Trim(FactoryName10.Text)='' then Exit;
    ToolBar1.SetFocus;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        SQL.Clear;
        Filtered:=False;
        sql.Add(' select A.*,QtyStr=dbo.[F_Get_ShuZiStr](A.Qty),MoneyStr=dbo.[F_Get_ShuZiStr](A.Money) ');
        sql.Add(',FactoryName10=dbo.getPinYin(A.FactoryName)+RTrim(A.FactoryName)');
        sql.Add(' from YS_Money_CR A where FactoryName='''+Trim(FactoryName10.Text)+'''');
        if CheckBox1.Checked then
        begin
          sql.Add(' and A.CRTime>='''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+''' ');
          sql.Add(' and A.CRTime<'''+FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)+''' ');
        end;
        sql.Add(' and A.CRType=''应收款登记''  ');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDS_HZ);
      SInitCDSData20(ADOQueryMain,CDS_HZ);
    finally
      ADOQueryMain.EnableControls;
      ToolButton2.Click;
    end;
  end;
end;

procedure TfrmXSPriceChk.v2Column11CustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  id:Integer;
begin
  Id:=TV2.GetColumnByFieldName('DZFlag').Index;//;-TV1.GroupedItemCount;
  if Id<0 then Exit;
  if AViewInfo.GridRecord.Values[Id]=True then
  begin
    ACanvas.Brush.Color:=clRed;
  end;
end;

procedure TfrmXSPriceChk.v2Column11PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue:Boolean;
begin
  mvalue:=TcxCheckBox(Sender).EditValue;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('DZFlag').Value:=mvalue;
  end;
  if mvalue=True then
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update YS_Money_CR Set DZFlag=1,DZTime=getdate(),DZPerson='''+Trim(DName)+'''');
      sql.Add(' where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
      ExecSQL;
    end;
  end else
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update YS_Money_CR Set DZFlag=0,DZTime=getdate(),DZPerson='''+Trim(DName)+'''');
      sql.Add(' where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
      ExecSQL;
    end;
  end; 
end;
procedure TfrmXSPriceChk.v2Column14PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='FHTaiTou';
      flagname:='公司抬头';
      if ShowModal=1 then
      begin
        with CDS_HZ do
        begin
          Edit;
          FieldByName('ComTaiTou').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmXSPriceChk.v2P_SpecPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if Trim(CDS_HZ.fieldbyname('P_CodeName').AsString)='' then
  begin
    Application.MessageBox('品名不能为空!','提示',0);
    Exit;
  end;
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='HLMLSpec';
      flagname:='面料规格';
      MainType:=Trim(CDS_HZ.fieldbyname('P_CodeName').AsString);
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('P_Spec').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmXSPriceChk.N1Click(Sender: TObject);
var
  FDate:TDateTime;
begin
  if CDS_HZ.IsEmpty then Exit;
  ToolBar1.SetFocus;
  try
    FDate:=SGetServerDateTime(ADOQueryTemp);
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YS_Money_CR where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Edit;
      RTSetSaveDataCDS(ADOQueryCmd,Tv2,CDS_HZ,'YS_Money_CR',7);
      FieldByName('ChkerP').Value:=Trim(DName);
      FieldByName('ChkTimeP').Value:=FDate;
      FieldByName('ChkStatusP').Value:='已审核';
      FieldByName('ChkerQ').Value:=Trim(DName);
      FieldByName('ChkTimeQ').Value:=FDate;
      FieldByName('ChkStatusQ').Value:='已审核';
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update YS_Money_CR Set ');
      sql.Add('HSMoney=Money');
      sql.Add(',JSMoney=Money');
      sql.Add(' where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
      ExecSQL;
    end;
    with CDS_HZ do
    begin
      Edit;
      FieldByName('ChkStatusP').Value:='已审核';
      FieldByName('ChkStatusQ').Value:='已审核';
      FieldByName('ChkTimeP').Value:=FDate;
      FieldByName('ChkTimeQ').Value:=FDate;
      FieldByName('ChkerP').Value:=Trim(DName);
      FieldByName('ChkerQ').Value:=Trim(DName);
      Post;
    end;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;

procedure TfrmXSPriceChk.N2Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then Exit;
  ToolBar1.SetFocus;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YS_Money_CR where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Edit;
      FieldByName('ChkerP').Value:=Null;
      FieldByName('ChkTimeP').Value:=Null;
      FieldByName('ChkStatusP').Value:='未审核';
      FieldByName('ChkerQ').Value:=Null;
      FieldByName('ChkTimeQ').Value:=Null;
      FieldByName('ChkStatusQ').Value:='未审核';
      Post;
    end;
    with CDS_HZ do
    begin
      Edit;
      FieldByName('ChkStatusP').Value:='未审核';
      FieldByName('ChkStatusQ').Value:='未审核';
      FieldByName('ChkerQ').Value:=Null;
      FieldByName('ChkTimeQ').Value:=Null;
      FieldByName('ChkerP').Value:=Null;
      FieldByName('ChkTimeP').Value:=Null;
      Post;
    end;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;

procedure TfrmXSPriceChk.N3Click(Sender: TObject);
begin
  if Trim(CDS_HZ.fieldbyname('ChkStatusP').AsString)='已审核' then
  begin
    Application.MessageBox('数据已审核，不能修改!','提示',0);
    Exit;
  end;
  try
    frmYSEdit:=TfrmYSEdit.Create(Application);
    with frmYSEdit do
    begin
      FCKNO:=Trim(Self.CDS_HZ.fieldbyname('CKNO').AsString);
      FYFID:=Trim(Self.CDS_HZ.fieldbyname('YFID').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmYSEdit.Free;
  end;
end;

procedure TfrmXSPriceChk.Tv2StylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
var
  id:Integer;
begin
  Id:=Tv2.GetColumnByFieldName('ChkStatusP').Index;
  if ARecord.Values[id]='已审核' then exit;
  AStyle:=DataLink_Money.SkyBlue;
end;

procedure TfrmXSPriceChk.N6Click(Sender: TObject);
begin
  SelOKNo(CDS_HZ,True);
end;

procedure TfrmXSPriceChk.N7Click(Sender: TObject);
begin
  SelOKNo(CDS_HZ,False);
end;

procedure TfrmXSPriceChk.N4Click(Sender: TObject);
var
  FDate:TDateTime;
begin
  if CDS_HZ.IsEmpty then Exit;
  if CDS_HZ.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  ToolBar1.SetFocus;
  try
    Panel2.Visible:=True;
    Panel2.Refresh;
    FDate:=SGetServerDateTime(ADOQueryTemp);
    ADOQueryCmd.Connection.BeginTrans;
    CDS_HZ.DisableControls;
    with CDS_HZ do
    begin
      First;
      while CDS_HZ.Locate('SSel',True,[]) do
      begin
        if Trim(CDS_HZ.fieldbyname('ChkStatusP').AsString)<>'已审核' then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('select * from YS_Money_CR where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
            Open;
          end;
          with ADOQueryCmd do
          begin
            Edit;
            RTSetSaveDataCDS(ADOQueryCmd,Tv2,CDS_HZ,'YS_Money_CR',7);
            FieldByName('ChkerP').Value:=Trim(DName);
            FieldByName('ChkTimeP').Value:=FDate;
            FieldByName('ChkStatusP').Value:='已审核';
            FieldByName('ChkerQ').Value:=Trim(DName);
            FieldByName('ChkTimeQ').Value:=FDate;
            FieldByName('ChkStatusQ').Value:='已审核';
            Post;
          end;
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Update YS_Money_CR Set ');
            sql.Add('HSMoney=Money');
            sql.Add(',JSMoney=Money');
            sql.Add(' where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
            ExecSQL;
          end;
          with CDS_HZ do
          begin
            Edit;
            FieldByName('ChkStatusP').Value:='已审核';
            FieldByName('ChkerP').Value:=Trim(DName);
            FieldByName('ChkTimeP').Value:=FDate;
            FieldByName('ChkStatusQ').Value:='已审核';
            FieldByName('ChkerQ').Value:=Trim(DName);
            FieldByName('ChkTimeQ').Value:=FDate;
            FieldByName('SSel').Value:=False;
            Post;
          end;
        end else
        begin
          with CDS_HZ do
          begin
            Edit;
            FieldByName('SSel').Value:=False;
            Post;
          end;
        end;
      end;
    end;
    CDS_HZ.EnableControls;

    ADOQueryCmd.Connection.CommitTrans;
    Panel2.Visible:=False;
  except
    Panel2.Visible:=False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;

procedure TfrmXSPriceChk.N5Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then Exit;
  if CDS_HZ.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  ToolBar1.SetFocus;
  try
    Panel2.Visible:=True;
    Panel2.Refresh;
    ADOQueryCmd.Connection.BeginTrans;
    CDS_HZ.DisableControls;
    with CDS_HZ do
    begin
      First;
      while CDS_HZ.Locate('SSel',True,[]) do
      begin
        if Trim(CDS_HZ.fieldbyname('ChkStatusP').AsString)<>'未审核' then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('select * from YS_Money_CR where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
            Open;
          end;
          with ADOQueryCmd do
          begin
            Edit;
            FieldByName('ChkerP').Value:=Null;
            FieldByName('ChkTimeP').Value:=Null;
            FieldByName('ChkStatusP').Value:='未审核';
            FieldByName('ChkerQ').Value:=Null;
            FieldByName('ChkTimeQ').Value:=Null;
            FieldByName('ChkStatusQ').Value:='未审核';
            Post;
          end;
          with CDS_HZ do
          begin
            Edit;
            FieldByName('ChkStatusP').Value:='未审核';
            FieldByName('ChkerP').Value:=Null;
            FieldByName('ChkTimeP').Value:=Null;
            FieldByName('ChkStatusQ').Value:='未审核';
            FieldByName('ChkerQ').Value:=Null;
            FieldByName('ChkTimeQ').Value:=Null;
            FieldByName('SSel').Value:=False;
            Post;
          end;
        end else
        begin
          with CDS_HZ do
          begin
            Edit;
            FieldByName('SSel').Value:=False;
            Post;
          end;
        end;

      end;
    end;
    CDS_HZ.EnableControls;

    ADOQueryCmd.Connection.CommitTrans;
    Panel2.Visible:=False;
  except
    Panel2.Visible:=False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;

procedure TfrmXSPriceChk.FactoryNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    if Trim(FactoryNo.Text)='' then Exit;
    ToolBar1.SetFocus;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        SQL.Clear;
        Filtered:=False;
        sql.Add(' select A.*,QtyStr=dbo.[F_Get_ShuZiStr](A.Qty),MoneyStr=dbo.[F_Get_ShuZiStr](A.Money) ');
        sql.Add(',FactoryName10=dbo.getPinYin(A.FactoryName)+RTrim(A.FactoryName)');
        sql.Add(' from YS_Money_CR A where FactoryNo='''+Trim(FactoryNo.Text)+'''');
        if CheckBox1.Checked then
        begin
          sql.Add(' and A.CRTime>='''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+''' ');
          sql.Add(' and A.CRTime<'''+FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)+''' ');
        end;
        sql.Add(' and A.CRType=''应收款登记''  ');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDS_HZ);
      SInitCDSData20(ADOQueryMain,CDS_HZ);
    finally
      ADOQueryMain.EnableControls;
      ToolButton2.Click;
    end;
  end;
end;

procedure TfrmXSPriceChk.ConNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    if Trim(ConNo.Text)='' then Exit;
    ToolBar1.SetFocus;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        SQL.Clear;
        Filtered:=False;
        sql.Add(' select A.*,QtyStr=dbo.[F_Get_ShuZiStr](A.Qty),MoneyStr=dbo.[F_Get_ShuZiStr](A.Money) ');
        sql.Add(',FactoryName10=dbo.getPinYin(A.FactoryName)+RTrim(A.FactoryName)');
        sql.Add(' from YS_Money_CR A where ConNo='''+Trim(ConNo.Text)+'''');
        if CheckBox1.Checked then
        begin
          sql.Add(' and A.CRTime>='''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+''' ');
          sql.Add(' and A.CRTime<'''+FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)+''' ');
        end;
        sql.Add(' and A.CRType=''应收款登记''  ');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDS_HZ);
      SInitCDSData20(ADOQueryMain,CDS_HZ);
    finally
      ADOQueryMain.EnableControls;
      ToolButton2.Click;
    end;
  end;
end;

procedure TfrmXSPriceChk.ChkerQKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    if Trim(ChkerQ.Text)='' then Exit;
    ToolBar1.SetFocus;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        SQL.Clear;
        Filtered:=False;
        sql.Add(' select A.*,QtyStr=dbo.[F_Get_ShuZiStr](A.Qty),MoneyStr=dbo.[F_Get_ShuZiStr](A.Money) ');
        sql.Add(',FactoryName10=dbo.getPinYin(A.FactoryName)+RTrim(A.FactoryName)');
        sql.Add(' from YS_Money_CR A where ChkerQ='''+Trim(ChkerQ.Text)+'''');
        if CheckBox1.Checked then
        begin
          sql.Add(' and A.CRTime>='''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+''' ');
          sql.Add(' and A.CRTime<'''+FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)+''' ');
        end;
        sql.Add(' and A.CRType=''应收款登记''  ');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDS_HZ);
      SInitCDSData20(ADOQueryMain,CDS_HZ);
    finally
      ADOQueryMain.EnableControls;
      ToolButton2.Click;
    end;
  end;
end;

end.


