unit U_YMTStockList;

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, cxCheckBox, RM_Common, RM_Class, RM_e_Xls, RM_Dataset,
  RM_System, RM_GridReport, Menus, cxCalendar, cxButtonEdit, cxTextEdit,
  cxContainer, cxImage, cxDBEdit, cxLookAndFeels, cxLookAndFeelPainters,
  dxSkinsCore, 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,
  dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue, dxSkinscxPCPainter, cxNavigator, cxCurrencyEdit,
  cxMaskEdit;

type
  TfrmStockList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    SPName: TEdit;
    FactoryName: TEdit;
    SPID: TEdit;
    SPSpec: TEdit;
    Label6: TLabel;
    SPCF: TEdit;
    Label7: TLabel;
    OrderNo: TEdit;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Label9: TLabel;
    ToFactoryName: TEdit;
    Label12: TLabel;
    CRType: TComboBox;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    Label11: TLabel;
    RCGangNo: TEdit;
    Label13: TLabel;
    SPColor: TEdit;
    Label15: TLabel;
    SPHX: TEdit;
    ADOQueryImage: TADOQuery;
    v1Column21: TcxGridDBColumn;
    CDS_MX: TClientDataSet;
    DS_MX: TDataSource;
    cxGridPopupMenu2: TcxGridPopupMenu;
    TbEditKW: TToolButton;
    Tv1SSel: TcxGridDBColumn;
    Panel4: TPanel;
    Label25: TLabel;
    btnChk: TButton;
    btn1: TButton;
    KuWei: TcxButtonEdit;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure SPIDChange(Sender: TObject);
    procedure SPSpecChange(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure TbEditKWClick(Sender: TObject);
    procedure KuWeiPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure btnChkClick(Sender: TObject);
    procedure btn1Click(Sender: TObject);
  private
    canshu1, canshu2: string;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmStockList: TfrmStockList;

implementation

uses
  U_DataLink, U_RTFun, U_YMTRKInPut, U_ZdyAttachGYS, U_LabelPrintFun, U_ZDYHelp,
  U_KuWeiList;

{$R *.dfm}



procedure TfrmStockList.FormDestroy(Sender: TObject);
begin
  frmStockList := nil;
end;

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

procedure TfrmStockList.FormCreate(Sender: TObject);
begin
  canshu1 := Trim(DParameters1);
  canshu2 := Trim(DParameters2);
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime;
end;

procedure TfrmStockList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(' from YMT_CK_CR A');
      sql.add(' where A.CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
      sql.Add(' and A.CRTime<=''' + Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)) + '''');
      sql.Add(' and isnull(CKName,'''')=''面料''');
      SQL.Add(' and CRFlag=''入库''  ');
      Open;
      //ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmStockList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('待检布入库列表', Tv1, '面料仓库');
  Close;
end;

procedure TfrmStockList.FormShow(Sender: TObject);
begin

  ReadCxGrid('待检布入库列表', Tv1, '面料仓库');

  InitGrid();
end;

procedure TfrmStockList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  TcxGridToExcel('待检布入库列表', cxGrid2);
end;

procedure TfrmStockList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  end;
end;

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

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

procedure TfrmStockList.SPIDChange(Sender: TObject);
begin
  if Length(Trim(SPID.Text)) < 4 then
  begin
    if Trim(SPID.Text) <> '' then
      Exit;
  end;
  TBFind.Click;
end;

procedure TfrmStockList.SPSpecChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmStockList.FactoryNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmStockList.TbEditKWClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  Panel4.Visible := True;
end;

procedure TfrmStockList.KuWeiPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmKuWeiList := TfrmKuWeiList.Create(Application);
    with frmKuWeiList do
    begin
      if ShowModal = 1 then
      begin
        with Self.CDS_Main do
        begin
          Edit;
          KuWei.Text := Trim(frmKuWeiList.Order_Main.fieldbyname('KWName').AsString);
        end;
      end;
    end;
  finally
    frmKuWeiList.Free;
  end;
end;

procedure TfrmStockList.btnChkClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    application.MessageBox('请选择数据！', '提示信息');
    exit;
  end;

  try
    while CDS_Main.Locate('SSel', True, []) do
    begin
      with ADOQueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('update YMT_CK_CR SET KuWei=' + quotedstr(trim(KuWei.Text)));
        sql.Add('where SPID=' + quotedstr(trim(CDS_Main.fieldbyname('SPID').AsString)));
        execsql;
      end;
      with CDS_Main do
      begin
        Edit;
        FieldByName('SSel').Value := False;
        FieldByName('KuWei').Value := trim(KuWei.Text);
        Post;
      end;
    end;

    Panel4.Visible := False;
    application.MessageBox('批量修改成功！', '提示信息');
  except
    application.MessageBox('批量修改失败！', '提示信息', 0);
  end;
end;

procedure TfrmStockList.btn1Click(Sender: TObject);
begin
  Panel4.Visible := False;
end;

end.

