unit U_ShuttleClothGYListsel;

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, cxCalendar, cxButtonEdit, cxSplitter, RM_Common, RM_Class,
  RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxTextEdit, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, StrUtils, RM_e_Graphic, RM_e_Jpeg,
  dxBarBuiltInMenu, cxPC, 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
  TfrmShuttleClothGYListSEL = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    Label2: TLabel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label5: TLabel;
    P_CodeName: TEdit;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    CDS_PM: TClientDataSet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1PRTMF: TcxGridDBColumn;
    v1PRTKZ: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column6: TcxGridDBColumn;
    RMDB_Main: TRMDBDataSet;
    v1Column19: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    Label10: TLabel;
    P_Code: TEdit;
    v1Column20: TcxGridDBColumn;
    v1Column31: TcxGridDBColumn;
    v1Column30: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    RMDB_JS: TRMDBDataSet;
    CDS_PJS: TClientDataSet;
    RMDB_WS: TRMDBDataSet;
    CDS_PWS: TClientDataSet;
    v1Column7: TcxGridDBColumn;
    Label4: TLabel;
    v1Column8: TcxGridDBColumn;
    cxGrid2: TcxGrid;
    cxGridDBTableView1: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    RMDB_CZ: TRMDBDataSet;
    CDS_CZ: TClientDataSet;
    cxGrid3: TcxGrid;
    cxGridDBTableView2: TcxGridDBTableView;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridDBColumn21: TcxGridDBColumn;
    cxGridDBColumn22: TcxGridDBColumn;
    cxGridDBColumn23: TcxGridDBColumn;
    cxGridDBColumn24: TcxGridDBColumn;
    cxGridDBColumn25: TcxGridDBColumn;
    cxGridDBColumn26: TcxGridDBColumn;
    cxGridDBColumn27: TcxGridDBColumn;
    cxGridDBColumn28: TcxGridDBColumn;
    cxGridDBColumn29: TcxGridDBColumn;
    cxGridDBColumn30: TcxGridDBColumn;
    cxGridDBColumn31: TcxGridDBColumn;
    cxGridDBColumn32: TcxGridDBColumn;
    cxGridDBColumn33: TcxGridDBColumn;
    cxGridDBColumn34: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGrid4: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn36: TcxGridDBColumn;
    cxGridDBColumn38: TcxGridDBColumn;
    cxGridDBColumn40: TcxGridDBColumn;
    cxGridDBColumn41: TcxGridDBColumn;
    cxGridDBColumn43: TcxGridDBColumn;
    cxGridDBColumn44: TcxGridDBColumn;
    cxGridDBColumn45: TcxGridDBColumn;
    cxGridDBColumn47: TcxGridDBColumn;
    cxGridDBColumn49: TcxGridDBColumn;
    cxGridDBColumn51: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    RMDB_QZ: TRMDBDataSet;
    CDS_QZ: TClientDataSet;
    CDS_QZ2: TClientDataSet;
    RMDB_QZ2: TRMDBDataSet;
    ADOQuery1: TADOQuery;
    ADOQuery2: TADOQuery;
    Tv3Column6: TcxGridDBColumn;
    Tv3Column7: TcxGridDBColumn;
    Tv3Column9: TcxGridDBColumn;
    RMJPEGExport1: TRMJPEGExport;
    cxTabControl1: TcxTabControl;
    ToolButton1: TToolButton;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBViewClick(Sender: TObject);
    procedure TBCopyClick(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure cxGridDBColumn46PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv3CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
  private
    FInt, PFInt: Integer;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;


    { Private declarations }
  public
    canshu1, FCheJian: string;
    { Public declarations }
  end;

var
  frmShuttleClothGYListSEL: TfrmShuttleClothGYListSEL;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_LabelList, U_CompressionFun,
  U_ShuttleClothGYInPut;

{$R *.dfm}

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

procedure TfrmShuttleClothGYListSEL.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Trim(self.Caption), Tv1, '坯布生产管理');
  Close;
end;

procedure TfrmShuttleClothGYListSEL.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
     // Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select A.*,B.*  ');

      sql.Add(' from PD_GY_Main A inner join PD_GY_SUB B on A.Mainid=B.MainId');
      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)) + '''');
      case cxTabControl1.TabIndex of
        0:
          begin
            SQL.Add('AND A.VALID=''Y''');
          end;
        1:
          begin
            SQL.Add('AND A.VALID=''N''');
          end;
      end;
      if Trim(canshu1) = '录入' then
        sql.Add(' and A.Filler=' + quotedstr(DName));
        //ShowMessage(SQL.Text);
      Open;
    end;

    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmShuttleClothGYListSEL.InitForm();
begin

  ReadCxGrid(Trim(self.Caption), Tv1, '坯布生产管理');
  BegDate.DateTime := StrToDate('2024-01-01');;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  InitGrid();
  TBFind.Click();
end;

procedure TfrmShuttleClothGYListSEL.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 TfrmShuttleClothGYListSEL.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if Order_Main.FieldByName('ISSD').AsString = '已锁定' then
  begin
    Application.MessageBox('已锁定数据不能删除!', '提示', 0);
    Exit;
  end;
  try
    frmClothGYInPut := tfrmClothgyInPut.Create(Application);
    with frmClothGYInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FSubId := Trim(Self.Order_Main.fieldbyname('SubId').AsString);
      if ShowModal = 1 then
      begin
        InitGrid();
//        Self.Order_Main.Locate('MainId', frmClothgyInPut.FMainId, []);
      end;
    end;
  finally
    frmClothgyInPut.Free;
  end;
end;

procedure TfrmShuttleClothGYListSEL.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;

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

function TfrmShuttleClothGYListSEL.DelData(): Boolean;
begin
  try
    Result := false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE  PD_GY_Main SET VALID=''N'' where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');

      ExecSQL;
    end;

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

procedure TfrmShuttleClothGYListSEL.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel('坯布工艺单', cxGrid1);
end;

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

procedure TfrmShuttleClothGYListSEL.TBAddClick(Sender: TObject);
begin

  try
    frmClothGYInPut := TfrmClothGYInPut.Create(Application);
    with frmClothGYInPut do
    begin
      PState := 0;
      FMainId := '';
      FSubId := '';
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmClothGYInPut.Free;
  end;
end;

procedure TfrmShuttleClothGYListSEL.ConNoChange(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 TfrmShuttleClothGYListSEL.FormShow(Sender: TObject);
begin
  InitForm();

end;

procedure TfrmShuttleClothGYListSEL.TBViewClick(Sender: TObject);
begin
  try
    frmClothGYInPut := TfrmClothGYInPut.Create(Application);
    with frmClothGYInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FSubId := Trim(Self.Order_Main.fieldbyname('SubId').AsString);

      TBSave.Visible := False;

      ScrollBox1.Enabled := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmClothGYInPut.Free;
  end;
end;

procedure TfrmShuttleClothGYListSEL.TBCopyClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmClothGYInPut := tfrmClothGYInPut.Create(Application);
    with frmClothGYInPut do
    begin
      PState := 1;
      FCopyInt := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FConNo := Trim(Self.Order_Main.fieldbyname('ConNo').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmClothGYInPut.Free;
  end;
end;

procedure TfrmShuttleClothGYListSEL.Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  FDDZT: string;
begin

//  if AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('ConNoStatu').Index] = '已取消' then
//  begin
//    ACanvas.Brush.Color := $0000FF;
//    ACanvas.Font.Color := $F0FBFF;
//  end;
//
//  FDDZT := AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('DDZT').Index];
//
//  if FDDZT = '已开始' then
//    ACanvas.Font.Color := $FF0000;
//  if FDDZT = '已结束' then
//    ACanvas.Font.Color := $0000FF;

end;

procedure TfrmShuttleClothGYListSEL.cxGridDBColumn46PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv3.Controller.FocusedColumn.DataBinding.FilterFieldName);
  try
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      Edit;
      FieldByName(FFieldName).Value := Trim(mvalue);
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate PD_Plan_Sub ');
      sql.Add(' Set ' + FFieldName + '=''' + Trim(mvalue) + '''');
      sql.Add(' where SubId=' + quotedstr(Order_Main.fieldbyname('SubId').AsString));
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    tv3.Controller.EditingController.ShowEdit();

  except
    tv3.Controller.EditingController.ShowEdit();
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end
end;

procedure TfrmShuttleClothGYListSEL.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  ModalResult := 1;
end;

procedure TfrmShuttleClothGYListSEL.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;

  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  PD_Plan_Main SET sdren=NULL,sdtime=NULL,issd=NULL ');
      sql.Add('where mainid=' + quotedstr(trim(Order_Main.fieldbyname('mainid').AsString)));
      execsql;
    end;

    InitGrid();
    application.MessageBox('解除锁定成功！', '提示信息');
  except
    application.MessageBox('解除锁定失败！', '提示信息', 0);
  end;
end;

procedure TfrmShuttleClothGYListSEL.ToolButton3Click(Sender: TObject);
var
  MLBName: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmLabelList := TfrmLabelList.Create(Application);
    with frmLabelList do
    begin
      if ShowModal = 1 then
      begin
//        MLBName := leftStr(Trim(ADOQueryLabel.fieldbyname('labelCaption').AsString), );
        MLBName := Trim(Copy(Trim(ADOQueryLabel.fieldbyname('labelCaption').AsString), 1, Length(Trim(ADOQueryLabel.fieldbyname('labelCaption').AsString)) - 4));
//        ShowMessage(MLBName);
      end;
    end;
  finally
    frmLabelList.Free;
  end;
  if MLBName <> '' then
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update PD_Plan_Main Set LaBName=''' + MLBName + '''');
      sql.Add(' where Mainid=''' + Trim(self.Order_Main.fieldbyname('Mainid').AsString) + '''');
      ExecSQL;
    end;
    with Order_Main do
    begin
      Edit;
      FieldByName('SSel').Value := False;
      FieldByName('LaBName').Value := MLBName;
      Post;
    end;

    tv1.Controller.EditingController.ShowEdit();
  end;

end;

procedure TfrmShuttleClothGYListSEL.cxTabControl1Change(Sender: TObject);
begin
  initgrid();
end;

procedure TfrmShuttleClothGYListSEL.Tv3CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if Order_Main.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('exec P_Del_CF2 @mainid=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');

    ExecSQL;
  end;
end;

end.

