unit U_FinishedCloth_DCGCAR;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, MovePanel, cxTextEdit,
  cxContainer, cxCurrencyEdit, BtnEdit, RM_e_main, RM_e_htm, RM_e_Graphic,
  RM_e_Jpeg, RM_e_txt, RM_e_csv, RM_E_llPDF, Math, Clipbrd, cxPC, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter, dxSkinBlack, dxSkinBlue,
  dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle,
  dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary,
  dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin,
  dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue;

type
  TfrmFinishedCloth_DCGCAR = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_Main: TDataSource;
    v1Column4: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    RM2: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    MovePanel2: TMovePanel;
    RMXLSExport1: TRMXLSExport;
    N3: TMenuItem;
    X1: TMenuItem;
    Order_Main: TClientDataSet;
    v1Column1: TcxGridDBColumn;
    Panel1: TPanel;
    Label7: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    PERSON: TEdit;
    ToolButton1: TToolButton;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Label1: TLabel;
    CARNO: TEdit;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyleRepository2: TcxStyleRepository;
    cxStyle2: TcxStyle;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    IsJYTime: TCheckBox;
    ToolButton2: TToolButton;
    Tv1Column5: TcxGridDBColumn;
    Label2: TLabel;
    JTH: TEdit;
    Tv1Column6: TcxGridDBColumn;
    Label3: TLabel;
    Edit1: TEdit;
    Label4: TLabel;
    Edit2: TEdit;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    ToolButton3: TToolButton;
    Panel2: TPanel;
    Label5: TLabel;
    Edit3: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure MJIDKeyPress(Sender: TObject; var Key: Char);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure MJStr2Change(Sender: TObject);
    procedure KHConNOKeyPress(Sender: TObject; var Key: Char);
    procedure RKOrdIDKeyPress(Sender: TObject; var Key: Char);
    procedure TCBNORChange(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure APIDKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton1Click(Sender: TObject);
    procedure personChange(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    DQdate: TDateTime;
    FLeft, FTop: Integer;
    FDCheG, FPCode, FTabInt: string;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
    procedure InitForm();
    function Savedata(): Boolean;
    { Private declarations }
  public
    FFInt: Integer;
    canshu1: string;
    procedure SetStatus();
    { Public declarations }
  end;

var
  frmFinishedCloth_DCGCAR: TfrmFinishedCloth_DCGCAR;

implementation

uses
  U_DataLink, U_Fun, U_MJEdit, U_ZDYHelp, U_SysLogHelp,
  U_FinishedClothStatistical;

{$R *.dfm}

procedure TfrmFinishedCloth_DCGCAR.SetStatus();
begin

end;

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

procedure TfrmFinishedCloth_DCGCAR.FormCreate(Sender: TObject);
begin
  cxgrid1.Align := alClient;
  DQdate := SGetServerDate(ADOQueryTemp);
end;

procedure TfrmFinishedCloth_DCGCAR.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption, Tv1, '检验管理');
  Close;
end;

procedure TfrmFinishedCloth_DCGCAR.InitGrid();
var
  fwhere, Pwhere: string;
begin
  MovePanel2.Left := (self.Width - MovePanel2.Width) div 2;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      //Filtered := False;
      Close;
      sql.Clear;
      sql.Add('exec P_CK_Cloth_DCGJZHZ ');
      if IsJYTime.Checked then
      begin
        sql.add('@FBegTime=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime))));
        sql.Add(',@FEndTime=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1))));
      end
      else
      begin
        sql.add('@FBegTime=' + QuotedStr(Trim(FormatDateTime('2000-01-01', BegDate.DateTime))));
        sql.Add(',@FEndTime=' + QuotedStr(Trim(FormatDateTime('2099-12-12', enddate.DateTime + 1))));
      end;
      if Edit1.Text <> '' then
      begin
        SQL.Add(',@JTHBEG=' + Trim(Edit1.Text));
      end;
      if Edit2.Text <> '' then
      begin
        SQL.Add(',@JTHEND=' + Trim(Edit2.Text));
      end;


//      ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);

    MovePanel2.Visible := false;
  finally
    ADOQueryMain.EnableControls;
    MovePanel2.Visible := false;
  end;
end;

procedure TfrmFinishedCloth_DCGCAR.InitForm();
var
  fsj: string;
begin
  ReadCxGrid(self.Caption, Tv1, '检验管理');
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime;
  InitGrid();
end;

procedure TfrmFinishedCloth_DCGCAR.TBFindClick(Sender: TObject);
var
  fsj, fwhere: string;
begin

end;

procedure TfrmFinishedCloth_DCGCAR.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;
  SetStatus();
  InitGrid();

end;

procedure TfrmFinishedCloth_DCGCAR.FormShow(Sender: TObject);
begin
  CurrentPage := 1;
  RecordsNumber := 500;
  SetStatus();
  InitForm();
end;

procedure TfrmFinishedCloth_DCGCAR.Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FLeft := X;
  FTop := Y;
end;

procedure TfrmFinishedCloth_DCGCAR.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main, True);
end;

procedure TfrmFinishedCloth_DCGCAR.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main, False);
end;

function TfrmFinishedCloth_DCGCAR.Savedata(): Boolean;
begin

end;

procedure TfrmFinishedCloth_DCGCAR.MJIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmFinishedCloth_DCGCAR.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  //Clipboard.SetTextBuf(PChar(Trim(Order_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmFinishedCloth_DCGCAR.MJStr2Change(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmFinishedCloth_DCGCAR.KHConNOKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmFinishedCloth_DCGCAR.RKOrdIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmFinishedCloth_DCGCAR.TCBNORChange(Sender: TObject);
begin

  InitGrid();
end;

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

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

procedure TfrmFinishedCloth_DCGCAR.APIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if ADOQueryMain.Active = False then
      Exit;
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  end;
end;

procedure TfrmFinishedCloth_DCGCAR.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '品种汇总统计');
end;

procedure TfrmFinishedCloth_DCGCAR.personChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  end;
end;

procedure TfrmFinishedCloth_DCGCAR.ToolButton2Click(Sender: TObject);
begin
  try
    frmFinishedClothStatistical := TfrmFinishedClothStatistical.Create(self);
    with frmFinishedClothStatistical do
    begin
      BegDate.DateTime := self.BegDate.DateTime;
      endDate.DateTime := self.endDate.DateTime;
      DCheG.Text := Self.Order_Main.fieldbyname('PERSON').AsString;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmFinishedClothStatistical.Free;
  end;
end;

procedure TfrmFinishedCloth_DCGCAR.Button1Click(Sender: TObject);
begin
  if Order_Main.Locate('ssel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

  Order_Main.DisableControls;
  with Order_Main do
  begin
    First;
    while not Eof do
    begin
      if Order_Main.FieldByName('SSel').AsBoolean = True then
      begin

        ADOQueryCmd.Connection.BeginTrans;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;

//            更新开卡
//            sql.Add('exec P_UPdate_LCKJY @SPID=''' + trim(Order_Main.fieldbyname('SPID').AsString) + '''');
          sql.Add('update PD_Plan_card set SDPRICE=' + Edit3.Text);
          sql.Add('where PCID =''' + trim(Order_Main.fieldbyname('PCID').AsString) + ''' ');

          sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
          sql.Add(' ' + quotedstr(trim(DName)));
          sql.Add(',getdate() ');
          sql.Add(',' + quotedstr(trim(self.Caption)));
          sql.Add(',' + quotedstr(trim('修改单价')));
          sql.Add(',' + quotedstr('pcid：' + trim(Order_Main.fieldbyname('PCID').AsString) + ' 改为：' + trim(edit3.Text)));
          sql.Add(',' + quotedstr(trim('成功')));
          sql.Add(')');
//            showmessage(sql.text);
          ExecSQL;
        end;

        ADOQueryCmd.Connection.CommitTrans;

        Order_Main.Delete;
      end
      else
        Next;
    end;
  end;
  Order_Main.EnableControls;
  InitGrid();

end;

procedure TfrmFinishedCloth_DCGCAR.ToolButton3Click(Sender: TObject);
begin
  if Order_Main.Locate('ssel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  Panel2.Visible := True;
end;

procedure TfrmFinishedCloth_DCGCAR.Button2Click(Sender: TObject);
begin
  Panel2.Visible := false;
end;

end.

