unit U_GKManage_CX;

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, cxCheckComboBox, cxDropDownEdit, Menus, RM_e_Xls,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxDateRanges,
  dxBarBuiltInMenu, U_BaseList, RM_BarCode, dxScrollbarAnnotations, cxContainer,
  cxProgressBar, dxSkinsCore, dxSkinsDefaultPainters;

type
  TfrmGKManage_CX = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    GPM_1: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Panel1: TPanel;
    Label1: TLabel;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    GKNo: TcxTextEdit;
    Tv2Column1: TcxGridDBColumn;
    Tv2Column2: TcxGridDBColumn;
    Tv2Column3: TcxGridDBColumn;
    Tv2Column4: TcxGridDBColumn;
    Tv2Column5: TcxGridDBColumn;
    Tv2Column6: TcxGridDBColumn;
    Tv2Column7: TcxGridDBColumn;
    Tv2Column8: TcxGridDBColumn;
    Tv2Column9: TcxGridDBColumn;
    Tv2Column10: TcxGridDBColumn;
    Tv2Column11: TcxGridDBColumn;
    Tv2Column12: TcxGridDBColumn;
    Tv2Column13: TcxGridDBColumn;
    Tv2Column14: TcxGridDBColumn;
    Tv2Column15: TcxGridDBColumn;
    Tv2Column16: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure CustomerChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure MCNOPropertiesChange(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure v2Column12PropertiesEditValueChanged(Sender: TObject);
    procedure cxgrdbclmnTv2Column3PropertiesEditValueChanged(Sender: TObject);
    procedure v2Column8PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
    fFlag: integer;
    { Public declarations }
    RKFlag, FCYID, fmanage: string;
  end;

var
  frmGKManage_CX: TfrmGKManage_CX;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_LabelPrint, U_MachineInPut, U_EmployeeSel,
  U_GKInput;

{$R *.dfm}

procedure TfrmGKManage_CX.InitGrid();
begin
  GKNO.SetFocus;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.* from  BS_GK A  ');

//      showmessage(Sql.text);
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_HZ);
    SInitCDSData(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
    ToolButton2.Click;
  end;
end;

procedure TfrmGKManage_CX.MCNOPropertiesChange(Sender: TObject);
var
  sql: string;
begin
  if ADOQueryMain.Active then
  begin
    sql := SGetFilters(Panel1, 1, 2);
    SDofilter(ADOQueryMain, sql);
    SCreateCDS(ADOQueryMain, CDS_HZ);
    SInitCDSData(ADOQueryMain, CDS_HZ);
  end;
end;

procedure TfrmGKManage_CX.FormDestroy(Sender: TObject);
begin
  inherited;
  frmGKManage_CX := nil;
end;

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

procedure TfrmGKManage_CX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Trim(Self.Caption), Tv2, '汇率管理');
  Close;
end;

procedure TfrmGKManage_CX.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(Trim(Self.Caption), Tv2, '汇率管理');
  InitGrid();
end;

procedure TfrmGKManage_CX.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmGKManage_CX.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;

  TcxGridToExcel(self.Caption, cxgrid2);
end;

procedure TfrmGKManage_CX.ToolButton4Click(Sender: TObject);
begin
  try
    frmGKInput := TfrmGKInput.Create(Application);
    with frmGKInput do
    begin
      FGKID := '';
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmGKInput.Free;
  end;
end;

procedure TfrmGKManage_CX.ToolButton5Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    Exit;

  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete BS_GK where GKID=' + QuotedStr(CDS_HZ.FieldByName('GKID').AsString));
    ExecSQL;
  end;

  InitGrid();
end;

procedure TfrmGKManage_CX.ToolButton6Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  try
    frmGKInput := TfrmGKInput.Create(Application);
    with frmGKInput do
    begin
      FGKID := Trim(Self.CDS_HZ.fieldbyname('GKID').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmGKInput.Free;
  end;
end;

procedure TfrmGKManage_CX.v2Column12PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);

  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_HZ do
    begin
      Edit;
      FieldByName(FFieldName).Value := Trim(mvalue);
      Post;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' UPdate BS_HL ');
      sql.Add(' Set Begdate = ''' + mvalue + '''');
      sql.Add(' where HLID=' + quotedstr(CDS_HZ.fieldbyname('HLID').AsString));
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    tv2.Controller.EditingController.ShowEdit();
  except
    tv2.Controller.EditingController.ShowEdit();
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end
end;

procedure TfrmGKManage_CX.v2Column8PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);

  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_HZ do
    begin
      Edit;
      FieldByName(FFieldName).Value := Trim(mvalue);
      Post;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' UPdate BS_HL ');
      sql.Add(' Set HL = ' + mvalue + '');
      sql.Add(' where HLID=' + quotedstr(CDS_HZ.fieldbyname('HLID').AsString));
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    tv2.Controller.EditingController.ShowEdit();
  except
    tv2.Controller.EditingController.ShowEdit();
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end
end;

procedure TfrmGKManage_CX.cxgrdbclmnTv2Column3PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);

  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_HZ do
    begin
      Edit;
      FieldByName(FFieldName).Value := Trim(mvalue);
      Post;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' UPdate BS_HL ');
      sql.Add(' Set EndDate = ''' + mvalue + '''');
      sql.Add(' where HLID=' + quotedstr(CDS_HZ.fieldbyname('HLID').AsString));
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    tv2.Controller.EditingController.ShowEdit();
  except
    tv2.Controller.EditingController.ShowEdit();
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end
end;

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

procedure TfrmGKManage_CX.N1Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  SelOKNo(CDS_HZ, True);
end;

procedure TfrmGKManage_CX.N2Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  SelOKNo(CDS_HZ, False);
end;

procedure TfrmGKManage_CX.CustomerChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmGKManage_CX.FormCreate(Sender: TObject);
begin
  inherited;
  fmanage := Trim(DParameters1);
end;

end.

