unit U_LSGZCX;

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,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmLSGZCX = 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;
    BegDate: TDateTimePicker;
    TBFind: TToolButton;
    Label1: TLabel;
    EndDate: TDateTimePicker;
    Label2: TLabel;
    cxGrid2: TcxGrid;
    TV1: TcxGridDBBandedTableView;
    V1Column1: TcxGridDBBandedColumn;
    V1Column2: TcxGridDBBandedColumn;
    V1Column3: TcxGridDBBandedColumn;
    V1Column4: TcxGridDBBandedColumn;
    V1Column5: TcxGridDBBandedColumn;
    V1Column6: TcxGridDBBandedColumn;
    V1Column7: TcxGridDBBandedColumn;
    V1Column8: TcxGridDBBandedColumn;
    V1Column9: TcxGridDBBandedColumn;
    V1Column10: TcxGridDBBandedColumn;
    V1Column11: TcxGridDBBandedColumn;
    V1Column23: TcxGridDBBandedColumn;
    V1Column12: TcxGridDBBandedColumn;
    V1Column13: TcxGridDBBandedColumn;
    V1Column14: TcxGridDBBandedColumn;
    V1Column15: TcxGridDBBandedColumn;
    V1Column16: TcxGridDBBandedColumn;
    V1Column17: TcxGridDBBandedColumn;
    V1Column18: TcxGridDBBandedColumn;
    V1Column22: TcxGridDBBandedColumn;
    V1Column24: TcxGridDBBandedColumn;
    cxGridLevel1: TcxGridLevel;
    person: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Money: TEdit;
    Button1: TButton;
    Button2: TButton;
    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);
    procedure personChange(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(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
  frmLSGZCX: TfrmLSGZCX;

implementation

uses
  U_DataLink, U_Fun, U_SysLogHelp;

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

end;

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

procedure TfrmLSGZCX.InitGrid();
begin
  with ADOQueryMain do
  begin
    Close;
    sql.Clear;
    sql.Add(' exec P_LSGZ_View');
    sql.Add(' ' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)));
    sql.Add(', ' + quotedstr(FormatDateTime('yyyy-MM-dd', endDate.DateTime + 1)));
//    ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryMain, CDS_Main);
  SInitCDSData20(ADOQueryMain, CDS_Main);
end;

procedure TfrmLSGZCX.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;
  InitGrid();
end;

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

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

procedure TfrmLSGZCX.FormShow(Sender: TObject);
var
  fsj: string;
begin
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp);
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
//  SetStatus();
//  InitGrid();
end;

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

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

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

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

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

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

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

procedure TfrmLSGZCX.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 TfrmLSGZCX.ordernoChange(Sender: TObject);
begin
  TBFind.Click;
end;

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

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

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

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

procedure TfrmLSGZCX.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 TfrmLSGZCX.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;

procedure TfrmLSGZCX.personChange(Sender: TObject);
begin
  tbfind.Click;
end;

procedure TfrmLSGZCX.Button1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  if Money.Text = '' then
    Exit;
  if Application.MessageBox('确定要修改数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  with CDS_Main do
  begin
    First;
    while not Eof do
    begin
      if FieldByName('money').asstring = '0' then
      begin
        Edit;
        FieldByName('money').Value := Money.Text;
        Post;
      end;
      next;
    end;
  end;
end;

procedure TfrmLSGZCX.Button2Click(Sender: TObject);
begin
//  with ADOQueryCmd do
//  begin
//    Close;
//    sql.Clear;
//    sql.Add(' exec P_LSGZJS');
//    sql.Add(' ' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)));
//    sql.Add(', ' + quotedstr(FormatDateTime('yyyy-MM-dd', endDate.DateTime + 1)));
//    Open;
//  end;
  Money.Text := CDS_Main.fieldbyname('money').AsString;
end;

end.

