unit U_ProductOrderLBNameSet;

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, StrUtils, Menus, cxDropDownEdit,
  cxTextEdit, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  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;

type
  TfrmProductOrderLBNameSet = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    OrderNo: TEdit;
    v1OrderNo: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    v1PRTSpec: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    v1CustomerNoName: TcxGridDBColumn;
    Label4: TLabel;
    CustomerNoName: TEdit;
    v1PRTCodeName: TcxGridDBColumn;
    vPRTMF: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    ToolButton1: TToolButton;
    Label8: TLabel;
    MPRTCodeName: TEdit;
    Label9: TLabel;
    ConNo: TEdit;
    v1PRTKZ: TcxGridDBColumn;
    v1PRTCode: TcxGridDBColumn;
    Label10: TLabel;
    MPRTSpec: TEdit;
    Label11: TLabel;
    MPRTCode: TEdit;
    Label12: TLabel;
    MPRTKZ: TEdit;
    Label13: TLabel;
    MPRTMF: TEdit;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    v1Column4: TcxGridDBColumn;
    Panel4: TPanel;
    Label14: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    Button1: TButton;
    RadioGroup1: TRadioGroup;
    v1SLbName: TcxGridDBColumn;
    v1SPiZhong: TcxGridDBColumn;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    PiZhong: TEdit;
    CheckBox1: TCheckBox;
    v1BLbName: TcxGridDBColumn;
    ToolButton4: TToolButton;
    v1Column1: TcxGridDBColumn;
    v1Orddefstr15: TcxGridDBColumn;
    ODPat: TOpenDialog;
    v1Column2: TcxGridDBColumn;
    ToolButton5: TToolButton;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    v1Column6: TcxGridDBColumn;
    ToolButton9: TToolButton;
    ToolButton10: TToolButton;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    ToolButton11: TToolButton;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    ToolButton12: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure CheckBox2Click(Sender: TObject);
    procedure Tv1StylesGetContentStyle(Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    procedure v1DeliveryDateCustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure ToolButton1Click(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure Panel10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Button1Click(Sender: TObject);
    procedure Image2Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure v1Column2PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure ToolButton9Click(Sender: TObject);
    procedure ToolButton10Click(Sender: TObject);
    procedure ToolButton11Click(Sender: TObject);
    procedure Tv1Column1PropertiesEditValueChanged(Sender: TObject);
    procedure Tv1Column3PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton12Click(Sender: TObject);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();

    { Private declarations }
  public
    FFInt, FCloth: Integer;

    { Public declarations }
  end;

var
  frmProductOrderLBNameSet: TfrmProductOrderLBNameSet;
  newh: hwnd;

implementation

uses
  U_DataLink, U_OrderInPut, U_Fun;

{$R *.dfm}

procedure TfrmProductOrderLBNameSet.FormDestroy(Sender: TObject);
begin
  frmProductOrderLBNameSet := nil;
end;

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

procedure TfrmProductOrderLBNameSet.FormCreate(Sender: TObject);
begin
  cxgrid1.Align := alClient;
  //BegDate.DateTime:=SGetServerDateTime(ADOQueryTemp)-7;
  //EndDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
  DQdate := SGetServerDate(ADOQueryTemp);
end;

procedure TfrmProductOrderLBNameSet.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('标签设置1', Tv1, '生产指示单管理');
end;

procedure TfrmProductOrderLBNameSet.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.add('select A.*,B.* from JYOrder_Main A ');
      Sql.add('inner join JYOrder_Sub B on B.Mainid=A.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)) + ''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmProductOrderLBNameSet.InitForm();
begin
  ReadCxGrid('标签设置1', Tv1, '生产指示单管理');
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 7;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  InitGrid();
end;

procedure TfrmProductOrderLBNameSet.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 TfrmProductOrderLBNameSet.TBPrintClick(Sender: TObject);
begin
  Panel4.Visible := True;
end;

procedure TfrmProductOrderLBNameSet.TBRafreshClick(Sender: TObject);
begin
  CheckBox1.Checked := False;
  with Order_Main do
  begin
    DisableControls;
    first;
    while not Eof do
    begin
      edit;
      fieldbyname('Ssel').AsBoolean := False;
      post;
      next;
    end;
    first;
    EnableControls;
  end;
  InitGrid();
end;

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

procedure TfrmProductOrderLBNameSet.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if ToolButton1.Visible = False then
    Exit;
  ToolButton1.Click;
end;

procedure TfrmProductOrderLBNameSet.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmProductOrderLBNameSet.Tv1StylesGetContentStyle(Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
var
  id, id10: Integer;
begin
  {try
    if Tv1.GroupedItemCount=0 then
    begin
      Id:=Tv1.GetColumnByFieldName('DeliveryDate').Index-tv1.GroupedItemCount;
      Id10:=Tv1.GetColumnByFieldName('SubStatus').Index-tv1.GroupedItemCount;
      if Trim(VarToStr(ARecord.Values[id]))='' then Exit;
      if Id<0 then Exit;
      if ARecord.Values[id10]='完成' then exit;
      if (ARecord.Values[id]-DQdate)>=4 then Exit;
      if ((ARecord.Values[id]-DQdate)>=0) and ((ARecord.Values[id]-DQdate)<4) then
        AStyle:=DataLink_.QHuangSe
      else
      if ARecord.Values[id]-DQdate<0 then
      begin
        AStyle:=DataLink_OrderManage.FenHongS;
      end;
    end else
    begin

    end;
  except
  end; }
end;

procedure TfrmProductOrderLBNameSet.v1DeliveryDateCustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
 { Id:=TV1.GetColumnByFieldName('DeliveryDate').Index;//;-TV1.GroupedItemCount;
  Id10:=TV1.GetColumnByFieldName('SubStatus').Index;
  if Id<0 then Exit;
  if AViewInfo.GridRecord.Values[Id10]='完成' then Exit;
  if AViewInfo.GridRecord.Values[Id]-SGetServerDate(ADOQueryTemp)>=4 then Exit;
  if ((AViewInfo.GridRecord.Values[id]-SGetServerDate10(ADOQueryTemp))>=0) and ((AViewInfo.GridRecord.Values[id]-SGetServerDate(ADOQueryTemp))<4) then
    ACanvas.Brush.Color:=clYellow
  else
  if (AViewInfo.GridRecord.Values[id])-(SGetServerDate10(ADOQueryTemp)<0) then
  begin
    ACanvas.Brush.Color:=clRed;
  end;
  begin
    ACanvas.Brush.Color:=clRed;
  end else
  if AViewInfo.GridRecord.Values[Id]='Purple' then
  begin
    ACanvas.Brush.Color:=clPurple;
  end else
  if AViewInfo.GridRecord.Values[Id]='Olive' then
  begin
    ACanvas.Brush.Color:=clOlive;
  end else
  if AViewInfo.GridRecord.Values[Id]='Teal' then
  begin
    ACanvas.Brush.Color:=clTeal;
  end else
  if AViewInfo.GridRecord.Values[Id]='Background' then
  begin
    ACanvas.Brush.Color:=clBackground;
  end;   }
end;

procedure TfrmProductOrderLBNameSet.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmOrderInPut := TfrmOrderInPut.Create(Application);
    with frmOrderInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      ToolBar2.Visible := False;
      TBSave.Visible := False;
      ScrollBox1.Enabled := False;
      Tv1.OptionsSelection.CellSelect := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmOrderInPut.Free;
  end;
end;

procedure TfrmProductOrderLBNameSet.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 A.*,B.* from JYOrder_Main A ');
        Sql.add('inner join JYOrder_Sub B on B.Mainid=A.Mainid ');
        sql.Add('where A.orderNo like ' + quotedstr('%' + trim(orderNo.Text) + '%'));
      //  ExecSQL;
        Open;
      end;
      SCreateCDS20(ADOQueryMain, Order_Main);
      SInitCDSData20(ADOQueryMain, Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmProductOrderLBNameSet.Panel10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  TWinControl(Panel4).Perform(WM_SYSCOMMAND, $F012, 0);
end;

procedure TfrmProductOrderLBNameSet.Button1Click(Sender: TObject);
var
  fPrintFile: string;
  Porderno, LBName: string;
  i, j: Integer;
  OrderKg: Double;
begin
  if Order_Main.IsEmpty then
    Exit;
  LBName := RadioGroup1.Items.Strings[RadioGroup1.ItemIndex];
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf';
  if RadioGroup1.ItemIndex = 0 then
  begin
    with ADOQueryPrint do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*,B.*,ColorCount=(select isnull(Count(*),0) from JYOrder_Sub where MainId=A.MainId),  ');
      sql.add('ZQty=(select sum(PRTOrderQty) from JYOrder_Sub where MainId=A.MainId)');
      SQL.Add(', Case when B.OrderUnit=''M'' then Cast (dbo.F_Get_Order_MFKZ(A.MainId,''MF'') ');
      sql.Add(' *1.00/100*B.PRTOrderQty*dbo.F_Get_Order_MFKZ(A.MainId,''KZ'')/1000 as varchar(20))+''Kg'' ');
      SQL.Add(' when B.OrderUnit=''Y'' then Cast (dbo.F_Get_Order_MFKZ(A.MainId,''MF'')');
      sql.Add(' *1.00/100*B.PRTOrderQty*0.9144*dbo.F_Get_Order_MFKZ(A.MainId,''KZ'')/1000 as varchar(20))+''Kg'' ');
      sql.Add(' else '''' end as PRTOrderKgQtyStr ');
      sql.Add(' from JYOrder_Main A inner join JYOrder_Sub B on A.MainId=B.MainId ');
      sql.Add(' and A.MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
      Open;
    end;

  end
  else
  begin
    with ADOQueryPrint do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_View_OrderSub :begdate,:enddate,:wsql  ');
      Parameters.ParamByName('WSql').Value := ' and A.MainId=''' + Trim(Order_Main.fieldbyname('Mainid').AsString) + '''';
      Parameters.ParamByName('begdate').Value := '1899-01-01';
      Parameters.ParamByName('enddate').Value := '2050-01-01';
      Open;
    end;
    if Trim(ADOQueryPrint.FieldByName('PRTHX').AsString) <> '' then
    begin
      if Trim(LBName) = '颜色样' then
      begin
        fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\颜色花型样.rmf';
      end;
    end;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select isnull(sum(PRTOrderKgQty),0) PRTOrderKgHZQty from(');
    sql.Add('select  ');
    SQL.Add(' Case when B.OrderUnit=''M'' then Cast(dbo.F_Get_Order_MFKZ(A.MainId,''MF'') ');
    sql.Add(' *1.00/100*B.PRTOrderQty*dbo.F_Get_Order_MFKZ(A.MainId,''KZ'')/1000 as decimal(18,2))');
    SQL.Add(' when B.OrderUnit=''Y'' then Cast(dbo.F_Get_Order_MFKZ(A.MainId,''MF'')');
    sql.Add(' *1.00/100*B.PRTOrderQty*0.9144*dbo.F_Get_Order_MFKZ(A.MainId,''KZ'')/1000 As decimal(18,2)) ');
    sql.Add(' else 0 end as PRTOrderKgQty');
    sql.Add(' from JYOrder_Main A inner join JYOrder_Sub B on A.MainId=B.MainId ');
    sql.Add(' and A.MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + ''')AA');
    Open;
  end;
  OrderKg := ADOQueryTemp.fieldbyname('PRTOrderKgHZQty').Value;
  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);

  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    if OrderKg > 0 then
      RMVariables['OrderKg'] := '/' + Trim(FloatToStr(OrderKg)) + 'Kg'
    else
      RMVariables['OrderKg'] := '';
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf'), '提示', 0);
  end;
end;

procedure TfrmProductOrderLBNameSet.Image2Click(Sender: TObject);
begin
  Panel4.Visible := False;
end;

procedure TfrmProductOrderLBNameSet.ToolButton2Click(Sender: TObject);
type
  TMyFunc = function(App: Tapplication; FormH: hwnd; FormID: integer; Language: integer; WinStyle: integer; GCode: Pchar; GName: Pchar; DataBase: Pchar; Title: PChar; Parameters1: PChar; Parameters2: PChar; Parameters3: PChar; Parameters4: PChar; Parameters5: PChar; Parameters6: PChar; Parameters7: PChar; Parameters8: PChar; Parameters9: PChar; Parameters10: PChar; DataBaseStr: PChar): hwnd; stdcall;
var
  Tf: TMyFunc;
  Tp: TFarProc;
  Th: Thandle;
  LabInt, labname: string;
  OpenDiaLog: TOpenDialog;
  fFileName: string;
  fFilePath: string;
begin
  if Order_Main.IsEmpty then
    exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据！', '提示', 0);
    Exit;
  end;

  fFileName := '';
  try
    OpenDiaLog := TOpenDialog.Create(Self);
    if OpenDiaLog.Execute then
    begin
      fFilePath := OpenDiaLog.FileName;
      fFileName := ExtractFileName(OpenDiaLog.FileName);
    end;
  finally
  end;
  if trim(fFileName) = '' then
    exit;
  with order_Main do
  begin
    first;
    while not Eof do
    begin
      if FieldByName('Ssel').AsBoolean = true then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update JYOrder_Sub Set SLBName=''' + Trim(fFileName) + '''');
          sql.Add(' where Subid=''' + Trim(Order_Main.fieldbyname('Subid').AsString) + '''');
          ExecSQL;
        end;
        Edit;
        FieldByName('SLbName').Value := trim(fFileName);
      end;
      next;
    end;
  end;

  with Order_Main do
  begin
    DisableControls;
    first;
    while not Eof do
    begin
      edit;
      fieldbyname('Ssel').AsBoolean := False;
      post;
      next;
    end;
    first;
    EnableControls;
  end;
end;

procedure TfrmProductOrderLBNameSet.ToolButton3Click(Sender: TObject);
var
  FPiZhong: string;
  FReal: Double;
begin
  if Order_Main.IsEmpty then
    exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据！', '提示', 0);
    Exit;
  end;
  if Trim(PiZhong.Text) = '' then
  begin
    Application.MessageBox('皮重不能为空!', '提示', 0);
    Exit;
  end;
  if TryStrToFloat(PiZhong.Text, FReal) = False then
  begin
    Application.MessageBox('皮重非法数字!', '提示', 0);
    Exit;
  end;
  with order_Main do
  begin
    first;
    while not Eof do
    begin
      if order_Main.FieldByName('Ssel').AsBoolean = true then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update JYOrder_Sub Set SPiZhong=' + Trim(PiZhong.Text));
          sql.Add(' where Subid=''' + Trim(Order_Main.fieldbyname('Subid').AsString) + '''');
          ExecSQL;
        end;
        with Order_Main do
        begin
          Edit;
          FieldByName('SPiZhong').Value := PiZhong.Text;
          Post;
        end;
      end;
      next;
    end;
  end;
  CheckBox1.Checked := False;
  with Order_Main do
  begin
    DisableControls;
    first;
    while not Eof do
    begin
      edit;
      fieldbyname('Ssel').AsBoolean := False;
      post;
      next;
    end;
    first;
    EnableControls;
  end;
end;

procedure TfrmProductOrderLBNameSet.CheckBox1Click(Sender: TObject);
begin
  with Order_Main do
  begin
    DisableControls;
    first;
    while not Eof do
    begin
      edit;
      fieldbyname('Ssel').AsBoolean := CheckBox1.Checked;
      post;
      next;
    end;
    first;
    EnableControls;
  end;
end;

procedure TfrmProductOrderLBNameSet.ToolButton4Click(Sender: TObject);
type
  TMyFunc = function(App: Tapplication; FormH: hwnd; FormID: integer; Language: integer; WinStyle: integer; GCode: Pchar; GName: Pchar; DataBase: Pchar; Title: PChar; Parameters1: PChar; Parameters2: PChar; Parameters3: PChar; Parameters4: PChar; Parameters5: PChar; Parameters6: PChar; Parameters7: PChar; Parameters8: PChar; Parameters9: PChar; Parameters10: PChar; DataBaseStr: PChar): hwnd; stdcall;
var
  Tf: TMyFunc;
  Tp: TFarProc;
  Th: Thandle;
  LabInt, labname: string;
begin
  if Order_Main.IsEmpty then
    exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据！', '提示', 0);
    Exit;
  end;
  Ddatabase := StringOfChar(' ', 32);
  Th := LoadLibrary('LabelSet.dll');
  if Th > 0 then
  begin
    try
      Tp := GetProcAddress(Th, 'GetDllForm');
      if Tp <> nil then
      begin
        Tf := TMyFunc(Tp);
        newh := Tf(Application, 0, 2, 0, 0, PChar(DCode), PChar(DName), PChar(Ddatabase), PChar('标签模版设置'), PChar(''), PChar(''), '', '', '', '', '', '', '', '', PChar(DConString));
        if Trim(PChar(Ddatabase)) <> '' then
        begin
          Ddatabase := Trim(PChar(Ddatabase));
          LabInt := Trim(LeftBStr(Ddatabase, Pos('|', Ddatabase) - 1));
          labname := Trim(RightBStr(Ddatabase, Length(Ddatabase) - Pos('|', Ddatabase)));
          with order_Main do
          begin
            first;
            while not Eof do
            begin
              if order_Main.FieldByName('Ssel').AsBoolean = true then
              begin
                with ADOQueryCmd do
                begin
                  Close;
                  sql.Clear;
                  sql.Add('Update JYOrder_Main Set NLBName=''' + Trim(labname) + '''');
                  sql.Add(' where Mainid=''' + Trim(Order_Main.fieldbyname('Mainid').AsString) + '''');
                  ExecSQL;
                end;
                with Order_Main do
                begin
                  Edit;
                  FieldByName('NLbName').Value := trim(labname);
                end;
              end;
              next;
            end;
          end;
        end;
      end
      else
      begin
        ShowMessage('打印执行错误');
      end;
    finally
    // FreeLibrary();
    end;
  end
  else
  begin
    ShowMessage('找不到' + Trim('LabelSet.dll'));
  end;
  CheckBox1.Checked := False;
  with Order_Main do
  begin
    DisableControls;
    first;
    while not Eof do
    begin
      edit;
      fieldbyname('Ssel').AsBoolean := False;
      post;
      next;
    end;
    first;
    EnableControls;
  end;
end;

procedure TfrmProductOrderLBNameSet.v1Column2PropertiesEditValueChanged(Sender: TObject);
var
  mvalues: string;
begin
  mvalues := TCXTextEdit(Sender).Text;

  with Order_Main do
  begin
    edit;
    fieldbyname('Orddefstr15').Value := mvalues;
    post;
  end;
  tv1.Controller.EditingController.ShowEdit();

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update JYOrder_Main Set Orddefstr15=''' + trim(mvalues) + ''' ');
    sql.Add('where Mainid=''' + Trim(Order_Main.fieldbyname('Mainid').AsString) + '''');
    ExecSQL;
  end;

end;

procedure TfrmProductOrderLBNameSet.ToolButton5Click(Sender: TObject);
var
  FPiZhong: string;
  FReal: Double;
begin
  if Order_Main.IsEmpty then
    exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据！', '提示', 0);
    Exit;
  end;
  if Trim(PiZhong.Text) = '' then
  begin
    Application.MessageBox('换算系数不能为空!', '提示', 0);
    Exit;
  end;
  if TryStrToFloat(PiZhong.Text, FReal) = False then
  begin
    Application.MessageBox('换算系数非法数字!', '提示', 0);
    Exit;
  end;
  with order_Main do
  begin
    first;
    while not Eof do
    begin
      if order_Main.FieldByName('Ssel').AsBoolean = true then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update JYOrder_Sub Set kmxs=' + Trim(PiZhong.Text));
          sql.Add(' where Subid=''' + Trim(Order_Main.fieldbyname('Subid').AsString) + '''');
          ExecSQL;
        end;
        with Order_Main do
        begin
          Edit;
          FieldByName('kmxs').Value := PiZhong.Text;
          Post;
        end;
      end;
      next;
    end;
  end;
  CheckBox1.Checked := False;
  with Order_Main do
  begin
    DisableControls;
    first;
    while not Eof do
    begin
      edit;
      fieldbyname('Ssel').AsBoolean := False;
      post;
      next;
    end;
    first;
    EnableControls;
  end;

end;

procedure TfrmProductOrderLBNameSet.ToolButton6Click(Sender: TObject);
var
  FPiZhong: string;
  FReal: Double;
begin
  if Order_Main.IsEmpty then
    exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据！', '提示', 0);
    Exit;
  end;
  if Trim(PiZhong.Text) = '' then
  begin
    Application.MessageBox('小数位数不能为空!', '提示', 0);
    Exit;
  end;
  if TryStrToFloat(PiZhong.Text, FReal) = False then
  begin
    Application.MessageBox('小数位数非法数字!', '提示', 0);
    Exit;
  end;
  with order_Main do
  begin
    first;
    while not Eof do
    begin
      if order_Main.FieldByName('Ssel').AsBoolean = true then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update JYOrder_main Set XSWS=' + Trim(PiZhong.Text));
          sql.Add(' where mainID=''' + Trim(Order_Main.fieldbyname('mainID').AsString) + '''');
          ExecSQL;
        end;
        with Order_Main do
        begin
          Edit;
          FieldByName('XSWS').Value := PiZhong.Text;
          Post;
        end;
      end;
      next;
    end;
  end;
  CheckBox1.Checked := False;
  with Order_Main do
  begin
    DisableControls;
    first;
    while not Eof do
    begin
      edit;
      fieldbyname('Ssel').AsBoolean := False;
      post;
      next;
    end;
    first;
    EnableControls;
  end;

end;

procedure TfrmProductOrderLBNameSet.ToolButton7Click(Sender: TObject);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if Order_Main.IsEmpty then
    exit;
  if trim(Order_Main.fieldbyname('SLbName').AsString) = '' then
    exit;

  with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Print_Cs_Roll ');
    sql.Add('@mainID=''' + trim(Order_Main.fieldbyname('subID').AsString) + ''' ');
    Open;
  end;
  try
    Moudle := LoadLibrary('MakeQRBarcode.dll');
    @Makebar := GetProcAddress(Moudle, 'Make');
    @Mixtext := GetProcAddress(Moudle, 'MixText');
    Txt := Trim(ADOQueryPrint.fieldbyname('MJID').AsString);
    fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
    if FileExists(fImagePath) then
      DeleteFile(fImagePath);
    Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
  except
    application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
    exit;
  end;

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(Order_Main.fieldbyname('SLbName').AsString);
  if FileExists(fPrintFile) then
  begin
    RMVariables['QRBARCODE'] := fImagePath;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找到' + trim(fPrintFile)), '提示信息', 0);
  end;

end;

procedure TfrmProductOrderLBNameSet.ToolButton8Click(Sender: TObject);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if Order_Main.IsEmpty then
    exit;
  if trim(Order_Main.fieldbyname('NLBName').AsString) = '' then
    exit;
  with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Print_Cs_Bao ');
    sql.Add('@mainID=''' + trim(Order_Main.fieldbyname('mainID').AsString) + ''' ');
    Open;
  end;
  try
    Moudle := LoadLibrary('MakeQRBarcode.dll');
    @Makebar := GetProcAddress(Moudle, 'Make');
    @Mixtext := GetProcAddress(Moudle, 'MixText');
    Txt := Trim(ADOQueryPrint.fieldbyname('MJID').AsString);
    fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
    if FileExists(fImagePath) then
      DeleteFile(fImagePath);
    Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
  except
    application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
    exit;
  end;

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(Order_Main.fieldbyname('NLBName').AsString) + '.rmf';
  if FileExists(fPrintFile) then
  begin
    RMVariables['QRBARCODE'] := fImagePath;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找到' + trim(fPrintFile)), '提示信息', 0);
  end;

end;

procedure TfrmProductOrderLBNameSet.ToolButton9Click(Sender: TObject);
var
  FPiZhong: string;
  FReal: Double;
begin
  if Order_Main.IsEmpty then
    exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据！', '提示', 0);
    Exit;
  end;
  if Trim(PiZhong.Text) = '' then
  begin
    Application.MessageBox('小数位数不能为空!', '提示', 0);
    Exit;
  end;
  if TryStrToFloat(PiZhong.Text, FReal) = False then
  begin
    Application.MessageBox('小数位数非法数字!', '提示', 0);
    Exit;
  end;
  with order_Main do
  begin
    first;
    while not Eof do
    begin
      if order_Main.FieldByName('Ssel').AsBoolean = true then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update JYOrder_main Set XSWS1=' + Trim(PiZhong.Text));
          sql.Add(' where mainID=''' + Trim(Order_Main.fieldbyname('mainID').AsString) + '''');
          ExecSQL;
        end;
        with Order_Main do
        begin
          Edit;
          FieldByName('XSWS1').Value := PiZhong.Text;
          Post;
        end;
      end;
      next;
    end;
  end;
  CheckBox1.Checked := False;
  with Order_Main do
  begin
    DisableControls;
    first;
    while not Eof do
    begin
      edit;
      fieldbyname('Ssel').AsBoolean := False;
      post;
      next;
    end;
    first;
    EnableControls;
  end;

end;

procedure TfrmProductOrderLBNameSet.ToolButton10Click(Sender: TObject);
var
  FPiZhong: string;
  FReal: Double;
begin
  if Order_Main.IsEmpty then
    exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据！', '提示', 0);
    Exit;
  end;
  if Trim(PiZhong.Text) = '' then
  begin
    Application.MessageBox('加重不能为空!', '提示', 0);
    Exit;
  end;
  if TryStrToFloat(PiZhong.Text, FReal) = False then
  begin
    Application.MessageBox('加重非法数字!', '提示', 0);
    Exit;
  end;
  with order_Main do
  begin
    first;
    while not Eof do
    begin
      if order_Main.FieldByName('Ssel').AsBoolean = true then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update JYOrder_Sub Set JIAZhong=' + Trim(PiZhong.Text));
          sql.Add(' where Subid=''' + Trim(Order_Main.fieldbyname('Subid').AsString) + '''');
          ExecSQL;
        end;
        with Order_Main do
        begin
          Edit;
          FieldByName('JIAZhong').Value := PiZhong.Text;
          Post;
        end;
      end;
      next;
    end;
  end;
  CheckBox1.Checked := False;
  with Order_Main do
  begin
    DisableControls;
    first;
    while not Eof do
    begin
      edit;
      fieldbyname('Ssel').AsBoolean := False;
      post;
      next;
    end;
    first;
    EnableControls;
  end;
end;

procedure TfrmProductOrderLBNameSet.ToolButton11Click(Sender: TObject);
var
  FPiZhong: string;
  FReal: Double;
begin
  if Order_Main.IsEmpty then
    exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据！', '提示', 0);
    Exit;
  end;
  if Trim(PiZhong.Text) = '' then
  begin
    Application.MessageBox('加长不能为空!', '提示', 0);
    Exit;
  end;
  if TryStrToFloat(PiZhong.Text, FReal) = False then
  begin
    Application.MessageBox('加长非法数字!', '提示', 0);
    Exit;
  end;
  with order_Main do
  begin
    first;
    while not Eof do
    begin
      if order_Main.FieldByName('Ssel').AsBoolean = true then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update JYOrder_Sub Set jiachang=' + Trim(PiZhong.Text));
          sql.Add(' where Subid=''' + Trim(Order_Main.fieldbyname('Subid').AsString) + '''');
          ExecSQL;
        end;
        with Order_Main do
        begin
          Edit;
          FieldByName('jiachang').Value := PiZhong.Text;
          Post;
        end;
      end;
      next;
    end;
  end;
  CheckBox1.Checked := False;
  with Order_Main do
  begin
    DisableControls;
    first;
    while not Eof do
    begin
      edit;
      fieldbyname('Ssel').AsBoolean := False;
      post;
      next;
    end;
    first;
    EnableControls;
  end;
end;

procedure TfrmProductOrderLBNameSet.Tv1Column1PropertiesEditValueChanged(Sender: TObject);
var
  mvalues: string;
begin
  mvalues := TCXTextEdit(Sender).Text;

  with Order_Main do
  begin
    edit;
    fieldbyname('baosx').Value := mvalues;
    post;
  end;
  tv1.Controller.EditingController.ShowEdit();

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update JYOrder_Main Set baosx=''' + trim(mvalues) + ''' ');
    sql.Add('where Mainid=''' + Trim(Order_Main.fieldbyname('Mainid').AsString) + '''');
    ExecSQL;
  end;

end;

procedure TfrmProductOrderLBNameSet.Tv1Column3PropertiesEditValueChanged(Sender: TObject);
var
  mvalues: string;
begin
  mvalues := TCXTextEdit(Sender).Text;

  with Order_Main do
  begin
    edit;
    fieldbyname('baotype').Value := mvalues;
    post;
  end;
  tv1.Controller.EditingController.ShowEdit();

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update JYOrder_Main Set baotype=''' + trim(mvalues) + ''' ');
    sql.Add('where Mainid=''' + Trim(Order_Main.fieldbyname('Mainid').AsString) + '''');
    ExecSQL;
  end;

end;

procedure TfrmProductOrderLBNameSet.ToolButton12Click(Sender: TObject);
var
  FPiZhong: string;
  FReal: Double;
begin
  if Order_Main.IsEmpty then
    exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据！', '提示', 0);
    Exit;
  end;
  if Trim(PiZhong.Text) = '' then
  begin
    Application.MessageBox('每包卷数不能为空!', '提示', 0);
    Exit;
  end;
  if TryStrToFloat(PiZhong.Text, FReal) = False then
  begin
    Application.MessageBox('每包卷数非法数字!', '提示', 0);
    Exit;
  end;
  with order_Main do
  begin
    first;
    while not Eof do
    begin
      if order_Main.FieldByName('Ssel').AsBoolean = true then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update JYOrder_Sub Set JS=' + Trim(PiZhong.Text));
          sql.Add(' where Subid=''' + Trim(Order_Main.fieldbyname('Subid').AsString) + '''');
          ExecSQL;
        end;
        with Order_Main do
        begin
          Edit;
          FieldByName('JS').Value := PiZhong.Text;
          Post;
        end;
      end;
      next;
    end;
  end;
  CheckBox1.Checked := False;
  with Order_Main do
  begin
    DisableControls;
    first;
    while not Eof do
    begin
      edit;
      fieldbyname('Ssel').AsBoolean := False;
      post;
      next;
    end;
    first;
    EnableControls;
  end;

end;

end.

