unit U_MovecardEdit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxTextEdit, DBClient, ADODB, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxControls, cxGridCustomView, cxGrid, StdCtrls, ExtCtrls, ComCtrls, ToolWin,
  cxButtonEdit, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter, cxCheckBox;

type
  Tfrmmovecardedit = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTmp: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_MJ: TClientDataSet;
    ToolButton1: TToolButton;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    V2Column1: TcxGridDBColumn;
    V2Column4: TcxGridDBColumn;
    V2Column3: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    TV2Column4: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    V2Column2: TcxGridDBColumn;
    TV2Column1: TcxGridDBColumn;
    TV2Column2: TcxGridDBColumn;
    TV2Column3: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Panel1: TPanel;
    Label1: TLabel;
    Label5: TLabel;
    Label10: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    P_CodeName: TEdit;
    P_Code: TEdit;
    ToolButton2: TToolButton;
    TV2Column5: TcxGridDBColumn;
    TV2Column6: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    Label2: TLabel;
    Label3: TLabel;
    edtKaNo: TEdit;
    PCid: TEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure tv2CDTypePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure tv2CDWZPropertiesEditValueChanged(Sender: TObject);
    procedure v2Column2PropertiesEditValueChanged(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure tv2CDWZPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure P_CodeChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    { Private declarations }

  public
    { Public declarations }
  end;

var
  frmmovecardedit: Tfrmmovecardedit;

implementation

uses
  U_Fun, U_ZDYHelp, U_DataLink, U_SCPerson1;

{$R *.dfm}

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

procedure Tfrmmovecardedit.FormDestroy(Sender: TObject);
begin
  frmmovecardedit := nil;
end;

procedure Tfrmmovecardedit.tv2CDTypePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'GreyCD';
      flagname := '疵点';
      if ShowModal = 1 then
      begin
        Self.Order_MJ.Edit;
        Self.Order_MJ.FieldByName('CDName').value := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure Tfrmmovecardedit.tv2CDWZPropertiesEditValueChanged(Sender: TObject);
var
  mvalue, CDBeg, CDEnd: string;
  FFReal: Double;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  with Order_MJ do
  begin
    Edit;
    FieldByName('CDBeg').Value := mvalue;
    Post;
  end;
  CDBeg := Trim(Order_MJ.fieldbyname('CDBeg').AsString);
  CDEnd := Trim(Order_MJ.fieldbyname('CDEnd').AsString);
  if (Trim(CDBeg) <> '') and (Trim(CDEnd) <> '') then
  begin
    if TryStrToFloat(CDBeg, FFReal) and TryStrToFloat(CDBeg, FFReal) then
    begin
      if StrToFloat(CDEnd) < StrToFloat(CDBeg) then
      begin
        Application.MessageBox('终止位置小于起始位置!', '提示', 0);
        Exit;
      end;
      with Order_MJ do
      begin
        Edit;
        FieldByName('CDQty').Value := StrToFloat(CDEnd) - StrToFloat(CDBeg);
        Post;
      end;
    end
    else
    begin
      Application.MessageBox('非法数字!', '提示', 0);
      Exit;
    end;
  end;
end;

procedure Tfrmmovecardedit.v2Column2PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, CDBeg, CDEnd: string;
  FFReal: Double;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  with Order_MJ do
  begin
    Edit;
    FieldByName('CDEnd').Value := mvalue;
    Post;
  end;
  CDBeg := Trim(Order_MJ.fieldbyname('CDBeg').AsString);
  CDEnd := Trim(Order_MJ.fieldbyname('CDEnd').AsString);
  if (Trim(CDBeg) <> '') and (Trim(CDEnd) <> '') then
  begin
    if TryStrToFloat(CDBeg, FFReal) and TryStrToFloat(CDBeg, FFReal) then
    begin
      if StrToFloat(CDEnd) < StrToFloat(CDBeg) then
      begin
        Application.MessageBox('终止位置小于起始位置!', '提示', 0);
        Exit;
      end;
      with Order_MJ do
      begin
        Edit;
        FieldByName('CDQty').Value := StrToFloat(CDEnd) - StrToFloat(CDBeg);
        Post;
      end;
    end
    else
    begin
      Application.MessageBox('非法数字!', '提示', 0);
      Exit;
    end;
  end;
end;

procedure Tfrmmovecardedit.TBCloseClick(Sender: TObject);
begin

  WriteCxGrid('布匹转卡', Tv2, '染厂检验管理');
  Close;
end;

procedure Tfrmmovecardedit.FormShow(Sender: TObject);
begin
  ReadCxGrid('布匹转卡', Tv2, '染厂检验管理');
  with ADOQueryMain do
  begin
    Filtered := False;
    Close;
    sql.Clear;
    sql.Add('select A.*,B.*  ');
    sql.Add(',p_code=(select p_code from PD_Plan_sub e where b.subid=e.subid)');
    sql.Add(',p_codename=(select p_codename from PD_Plan_sub e where b.subid=e.subid)');
    sql.Add(' from PD_Plan_Card A inner join PD_Plan_Card_MS B on A.PCID=B.PCID');
    sql.Add(' where  A.FillTIme>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
    sql.Add(' and A.FillTIme<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1)) + '''');

    Open;
  end;
  SCreateCDS20(ADOQueryMain, Order_MJ);
  SInitCDSData20(ADOQueryMain, Order_MJ);
end;

procedure Tfrmmovecardedit.tv2CDWZPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin

  try
    frmSCPerson1 := TfrmSCPerson1.Create(self);
    with frmSCPerson1 do
    begin
      FlagStr := 'SCPerson';
      if ShowModal = 1 then
      begin
        Order_MJ.Edit;
        Order_MJ.FieldByName('DCheKouK').Value := frmSCPerson1.FSDPerson;
      end;
    end;
  finally
    frmSCPerson1.Free;
  end;
end;

procedure Tfrmmovecardedit.FormCreate(Sender: TObject);
begin
  EndDate.DateTime := SGetServerDate10(ADOTmp);
  BegDate.DateTime := SGetServerDate10(ADOTmp) - 30;
end;

procedure Tfrmmovecardedit.ToolButton2Click(Sender: TObject);
begin
  with ADOQueryMain do
  begin
    Filtered := False;
    Close;
    sql.Clear;
    sql.Add('select A.*,B.*  ');
    sql.Add(',p_code=(select p_code from PD_Plan_sub e where b.subid=e.subid)');
    sql.Add(',p_codename=(select p_codename from PD_Plan_sub e where b.subid=e.subid)');
    sql.Add(' from PD_Plan_Card A inner join PD_Plan_Card_MS B on A.PCID=B.PCID');
    sql.Add(' where  A.FillTIme>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
    sql.Add(' and A.FillTIme<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1)) + '''');

    Open;
  end;
  SCreateCDS20(ADOQueryMain, Order_MJ);
  SInitCDSData20(ADOQueryMain, Order_MJ);
end;

procedure Tfrmmovecardedit.P_CodeChange(Sender: TObject);
begin
  if ADOQuerymain.Active = False then
    Exit;
  SDofilter(ADOQuerymain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQuerymain, Order_MJ);
  SInitCDSData20(ADOQuerymain, Order_MJ);

end;

procedure Tfrmmovecardedit.ToolButton1Click(Sender: TObject);
begin
  ModalResult := 1;
end;

end.

