unit U_ProductSS;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  cxStyles, 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, cxCustomData, cxFilter, cxData,
  cxDataStorage, cxEdit, cxNavigator, DB, cxDBData, cxCalendar, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxGridCustomView, cxGrid, DBClient, Menus, cxGridCustomPopupMenu,
  cxGridPopupMenu, ADODB, StdCtrls, ComCtrls, ExtCtrls, ToolWin;

type
  TFRMProductSS = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    ToolButton2: TToolButton;
    TBCK: TToolButton;
    TBDel: TToolButton;
    TBExport: TToolButton;
    TRZ: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label4: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    OrderNo: TEdit;
    SScolor: TEdit;
    SSCodeName: TEdit;
    SSGH: TEdit;
    SSCodeNo: TEdit;
    MPRTKZ: TEdit;
    ADOQueryCmd: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    ADOQueryTemp: TADOQuery;
    ADOQueryMain: TADOQuery;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    v1OrdDate: TcxGridDBColumn;
    v1OrderNo: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1MPRTCodeName: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    v1MPRTMF: TcxGridDBColumn;
    v1MPRTKZ: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    Panel4: TPanel;
    Tv1Column2: TcxGridDBColumn;
    Label2: TLabel;
    RCFactoryName: TEdit;
    Label3: TLabel;
    ssType: TComboBox;
    Tv1Column3: TcxGridDBColumn;
    procedure TBAddClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBCKClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure TBCloseClick(Sender: TObject);
    procedure ssTypeChange(Sender: TObject);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    procedure SetStatus();
    function DelData(): Boolean;
    { Private declarations }
  public
    FFInt, FCloth: Integer;
    canshu1, canshu2: string;
    fFlileFlag: string;
    { Public declarations }
  end;

var
  FRMProductSS: TFRMProductSS;

implementation

uses
  U_DataLink, U_RTFun, U_SysLogHelp, U_Fun, U_ZDYHelp, U_ProductSSedit;

{$R *.dfm}
procedure TFRMProductSS.InitGrid();
var
  strwhere: string;
begin
  Panel4.Visible := True;
  Panel4.Refresh;
  strwhere := '';
//  if Trim(canshu1) = '录入' then
//    strwhere := strwhere + ' and Filler=''' + Trim(DName) + '''';
//  if cxTabControl1.TabIndex < 4 then
//  begin
//    strwhere := strwhere + ' and  isnull(A.status,''0'')=''' + inttostr(cxTabControl1.TabIndex) + '''';
//  end;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;        
      Close;
      sql.Clear;
      sql.Add(' select * from JYOrder_SS     ');
      Sql.add('where  filltime>=''' + formatdateTime('yyyy-MM-dd', begdate.Date) + ''' ');
      Sql.add('and  filltime<''' + formatdateTime('yyyy-MM-dd', enddate.Date + 1) + ''' ');
      sql.Add('and  DDTYpe=''大货'' ');
      if Trim(canshu1) = '录入' then
      begin
        SQL.Add(' and Filler=''' + Trim(DName) + '''');
      end;
      sql.Add(' order by filltime  ');
//      ShowMessage(SQL.text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  Panel4.Visible := false;
end;

procedure TFRMProductSS.TBAddClick(Sender: TObject);
var
  maxno: string;
begin
  try
    FRMProductSSedit := TFRMProductSSedit.Create(Application);
    with FRMProductSSedit do
    begin
      PState := 0;
      FSSId := '';
      canshu1 := self.canshu1;
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    FRMProductSSedit.Free;
  end;
end;

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

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

procedure TFRMProductSS.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TFRMProductSS.FormShow(Sender: TObject);
begin
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 30;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  SetStatus();
  InitGrid();

end;

procedure TFRMProductSS.SetStatus();
begin

  TBAdd.Visible := false;
  TBEdit.Visible := false;
  TBDel.Visible := false;

  ToolButton2.Visible := false;  //复制

  if Trim(canshu1) = '高权限' then
  begin
    TBAdd.Visible := true;
    TBEdit.Visible := true;
    TBDel.Visible := true;
    ToolButton2.Visible := true;
  end;

  if Trim(canshu1) = '录入' then
  begin
    TBAdd.Visible := true;
    TBEdit.Visible := true;
    TBDel.Visible := true;
    ToolButton2.Visible := true;
  end;
  if Trim(canshu1) = '查询' then
  begin

  end;

end;

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

procedure TFRMProductSS.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
//  if Trim(Order_Main.fieldbyname('Filler').AsString) <> Trim(DName) then
//  begin
//    Application.MessageBox('不能操作他人的数据!', '提示', 0);
//    Exit;
//  end;

  try
    FRMProductSSedit := TFRMProductSSedit.Create(Application);
    with FRMProductSSedit do
    begin
      PState := 1;
      FSSId := Trim(Self.Order_Main.fieldbyname('SSId').AsString);
//      FOrderNo := Trim(Self.Order_Main.fieldbyname('OrderNoM').AsString);
      canshu1 := self.canshu1;
//      conNo.Enabled := false;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    FRMProductSSedit.Free;
  end;
  self.TBRafresh.Click;
end;

procedure TFRMProductSS.TBCKClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    FRMProductSSedit := TFRMProductSSedit.Create(Application);
    with FRMProductSSedit do
    begin
      PState := 1;
      FSSId := Trim(Self.Order_Main.fieldbyname('SSId').AsString);
//      ToolBar2.Visible := False;
      TBSave.Visible := False;
//      ScrollBox1.Enabled := False;
      Tv1.OptionsSelection.CellSelect := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    FRMProductSSedit.Free;
  end;
end;

procedure TFRMProductSS.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
//  if Trim(Order_Main.fieldbyname('Filler').AsString) <> Trim(DName) then
//  begin
//    Application.MessageBox('不能操作他人的数据!', '提示', 0);
//    Exit;
//  end;

  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if DelData() then
  begin
    Order_Main.Delete;
  end;
end;

function TFRMProductSS.DelData(): Boolean;
begin
  try
    Result := false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_SS where SSId=''' + Trim(Order_Main.fieldbyname('SSId').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(trim('指示单号：' + trim(Order_Main.FieldByName('OrderNO').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      ExecSQL;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result := False;
    Application.MessageBox('数据删除异常！', '提示', 0);
  end;
end;

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

procedure TFRMProductSS.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(OrderNo.Text) < 3 then
      Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered := False;
        Close;
        sql.Clear;
        sql.Add(' select * from JYOrder_SS  ');
        Sql.add('where  filltime>=''' + formatdateTime('yyyy-MM-dd', begdate.Date) + ''' ');
        Sql.add('and  filltime<''' + formatdateTime('yyyy-MM-dd', enddate.Date + 1) + ''' ');
        if Trim(canshu1) <> '高权限' then
        begin
          sql.Add('and Filler=''' + Trim(DName) + '''');
//          Parameters.ParamByName('WSql').Value := ' and Filler=''' + Trim(DName) + '''';
        end;
        begin
          sql.Add('and orderno like ''' + '%' + Trim(OrderNo.Text) + '%' + '''');

        end;
        sql.Add(' order by filltime  ');
        Open;
      end;
      SCreateCDS20(ADOQueryMain, Order_Main);
      SInitCDSData20(ADOQueryMain, Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TFRMProductSS.TBCloseClick(Sender: TObject);
begin
  Close;
  //WriteCxGrid('指示单列表FF', Tv1, '生产指示单管理');
  if Trim(DName) = 'ADMIN' then
  begin
    WriteCxGridAll(trim(self.Caption), Tv1, ADOQueryCmd, ADOQueryTemp);
  end;
end;

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

end.

