unit U_LSJJ;

interface

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

type
  TfrmLSJJ = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    MovePanel2: TMovePanel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Panel1: TPanel;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column4: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    BegDate: TDateTimePicker;
    v1Column1: TcxGridDBColumn;
    TBFind: TToolButton;
    Label1: TLabel;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TCBNORChange(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure ordernoChange(Sender: TObject);
    procedure Y_CodeNameChange(Sender: TObject);
    procedure Y_CodeChange(Sender: TObject);
    procedure MachNoChange(Sender: TObject);
    procedure Y_ColNoChange(Sender: TObject);
    procedure v1Column4PropertiesEditValueChanged(Sender: TObject);
    procedure v2Column1PropertiesEditValueChanged(Sender: TObject);
  private
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
    procedure SetStatus();
    { Private declarations }
  public
    { Public declarations }
    FMainid, FSubId, FConNo, FColor, FCodeName: string;
    canshu1: string;
  end;

var
  frmLSJJ: TfrmLSJJ;

implementation

uses
  U_DataLink, U_Fun, U_SysLogHelp;

{$R *.dfm}
procedure TfrmLSJJ.SetStatus();
var
  i: Integer;
begin

end;

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

procedure TfrmLSJJ.InitGrid();
begin
  with ADOQueryMain do
  begin
    Close;
    sql.Clear;
    sql.Add(' select * from LS_JJSZ');
//     where crtime=' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)));
    sql.Add('order by machqty');
    Open;
  end;
//自动增加每日工资
//  if ADOQueryMain.IsEmpty then
//  begin
//    with ADOQueryCmd do
//    begin
//      Close;
//      sql.Clear;
//      sql.Add('insert into ls_jjsz select MachQty,Price1,Price2,''' + FormatDateTime('yyyy-MM-dd', BegDate.DateTime) + ''' from ls_jjsz where CRTime=(select top 1 CRTime from ls_jjsz where CRTime<''' + FormatDateTime('yyyy-MM-dd', BegDate.DateTime) + ''' order by CRTime desc)');
//      ExecSQL;
//    end;
//  end;
//  with ADOQueryMain do
//  begin
//    Close;
//    sql.Clear;
//    sql.Add(' select * from LS_JJSZ where crtime=' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)));
//    Open;
//  end;

  SCreateCDS20(ADOQueryMain, CDS_Main);
  SInitCDSData20(ADOQueryMain, CDS_Main);
end;

procedure TfrmLSJJ.TBRafreshClick(Sender: TObject);
begin
//  BegDate.SetFocus;
//  ToolBar1.SetFocus;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible := False;
end;

procedure TfrmLSJJ.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  end;
end;

procedure TfrmLSJJ.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption, Tv1, '拉丝仓库');
  Close;
end;

procedure TfrmLSJJ.FormShow(Sender: TObject);
var
  fsj: string;
begin
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp);
  ReadCxGrid(self.Caption, Tv1, '拉丝仓库');
  SetStatus();
  InitGrid();
end;

procedure TfrmLSJJ.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  TcxGridToExcel('拉丝工价列表', cxGrid2);
end;

procedure TfrmLSJJ.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

procedure TfrmLSJJ.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, False);
end;

procedure TfrmLSJJ.BTLPClick(Sender: TObject);
begin
  if CurrentPage > 1 then
    CurrentPage := CurrentPage - 1;
  InitGrid();
end;

procedure TfrmLSJJ.BTNPClick(Sender: TObject);
begin
  if CurrentPage < CDS_Main.FieldByName('TotalCount').AsInteger / RecordsNumber then
    CurrentPage := CurrentPage + 1;
  InitGrid();
end;

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

procedure TfrmLSJJ.TCBNORChange(Sender: TObject);
begin
//  RecordsNumber := StrToInt(TCBNOR.Text);
//  CurrentPage := 1;
//  InitGrid();
end;

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

procedure TfrmLSJJ.ordernoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmLSJJ.Y_CodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmLSJJ.Y_CodeChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmLSJJ.MachNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmLSJJ.Y_ColNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmLSJJ.v1Column4PropertiesEditValueChanged(Sender: TObject);
var
  mvalues: string;
begin
  mvalues := TCXTextEdit(Sender).Text;

  with CDS_Main do
  begin
    edit;
    fieldbyname('price1').Value := mvalues;
    post;
  end;
  tv1.Controller.EditingController.ShowEdit();

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update ls_jjsz Set price1=''' + trim(mvalues) + ''' ');
    sql.Add('where machqty=''' + Trim(CDS_Main.fieldbyname('machqty').AsString) + '''');
    sql.Add('and crtime=''' + Trim(CDS_Main.fieldbyname('crtime').AsString) + ''' ');
    ExecSQL;
  end;

end;

procedure TfrmLSJJ.v2Column1PropertiesEditValueChanged(Sender: TObject);
var
  mvalues: string;
begin
  mvalues := TCXTextEdit(Sender).Text;

  with CDS_Main do
  begin
    edit;
    fieldbyname('price2').Value := mvalues;
    post;
  end;
  tv1.Controller.EditingController.ShowEdit();

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update ls_jjsz Set price2=''' + trim(mvalues) + ''' ');
    sql.Add('where machqty=''' + Trim(CDS_Main.fieldbyname('machqty').AsString) + '''');
    sql.Add('and crtime=''' + Trim(CDS_Main.fieldbyname('crtime').AsString) + ''' ');
    ExecSQL;
  end;

end;

end.

