5,388
社区成员
发帖
与我相关
我的任务
分享
procedure TForm1.btn1Click(Sender: TObject);
var
i:Integer;
slTempList:TStringList;
begin
slTempList:=TStringList.Create;
try
with TempGrid do
for i:=1 to RowCount-1 do
begin
slTempList.Values[Cells[0,i]]:=IntToStr(StrToIntDef(slTempList.Values[Cells[0,i]],0)+1);
Cells[1,i]:=Cells[0,i]+'-'+RightStr('00'+slTempList.Values[Cells[0,i]],2);
end;
finally
FreeAndNil(slTempList);
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
TempGrid.ColWidths[0]:=100;
TempGrid.ColWidths[1]:=120;
TempGrid.ColWidths[2]:=120;
TempGrid.Cells[0,1]:='35040112';
TempGrid.Cells[0,2]:='35040112';
TempGrid.Cells[0,3]:='35040112';
TempGrid.Cells[0,4]:='35040102';
TempGrid.Cells[0,5]:='35040102';
TempGrid.Cells[0,6]:='35040102';
TempGrid.Cells[0,7]:='35040102';
TempGrid.Cells[0,8]:='35040105';
TempGrid.Cells[0,9]:='35040105';
TempGrid.Cells[0,10]:='35040105';
TempGrid.Cells[0,11]:='35040105';
TempGrid.Cells[0,12]:='35040105';
end;
procedure TForm1.btn2Click(Sender: TObject);
var
i,iPosNo:Integer;
begin
with TempGrid do
for i:=1 to RowCount-1 do
begin
iPosNo:=Pos('-',Cells[1,i]);
if iPosNo>0 then
begin
Cells[2,i]:=Copy(Cells[1,i],1,iPosNo)+RightStr('00'+IntToStr(StrToInt(Copy(Cells[1,i],iPosNo+1,Length(Cells[1,i])-iPosNo))+1),2);
end;
end;
end;
//创建窗体,初始化数据
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.RowCount := 16;
StringGrid1.ColWidths[0] := 15;
StringGrid1.Cells[1, 0] := '查出的物料号';
StringGrid1.Cells[2, 0] := '需变成这种';
StringGrid1.Cells[1, 1] := '35040112';
StringGrid1.Cells[1, 2] := '35040112';
StringGrid1.Cells[1, 3] := '35040112';
StringGrid1.Cells[1, 4] := '35040102';
StringGrid1.Cells[1, 5] := '35040102';
StringGrid1.Cells[1, 6] := '35040102';
StringGrid1.Cells[1, 7] := '35040102';
StringGrid1.Cells[1, 8] := '35040105';
StringGrid1.Cells[1, 9] := '35040105';
StringGrid1.Cells[1, 10] := '35040105';
StringGrid1.Cells[1, 11] := '35040105';
StringGrid1.Cells[1, 12] := '35040105';
StringGrid1.Cells[1, 13] := '35040105';
StringGrid1.Cells[1, 14] := '35040105';
StringGrid1.Cells[1, 15] := '35040105';
end;
//点击按钮实现功能
procedure TForm1.Button1Click(Sender: TObject);
var
i, j: Integer; //定位单元格
count: Integer;
begin
for i := 1 to StringGrid1.RowCount do
begin
count := 1;
for j := 1 to i do
begin
if StringGrid1.Cells[1, i] = StringGrid1.Cells[1, j] then
begin
StringGrid1.Cells[2, i] := StringGrid1.Cells[1, i] + '-' + vartostr(Format('%.2d', [count]));
Inc(count);
end
else
begin
count := 1;
end;
end;
end;
end;
procedure TForm1.btn1Click(Sender: TObject);
var
i:Integer;
slTempList:TStringList;
begin
slTempList:=TStringList.Create;
try
with TempGrid do
for i:=1 to RowCount-1 do
begin
slTempList.Values[Cells[0,i]]:=IntToStr(StrToIntDef(slTempList.Values[Cells[0,i]],0)+1);
Cells[1,i]:=Cells[0,i]+'-'+RightStr('00'+slTempList.Values[Cells[0,i]],2);
end;
finally
FreeAndNil(slTempList);
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
TempGrid.ColWidths[0]:=100;
TempGrid.ColWidths[1]:=120;
TempGrid.Cells[0,1]:='35040112';
TempGrid.Cells[0,2]:='35040112';
TempGrid.Cells[0,3]:='35040112';
TempGrid.Cells[0,4]:='35040102';
TempGrid.Cells[0,5]:='35040102';
TempGrid.Cells[0,6]:='35040102';
TempGrid.Cells[0,7]:='35040102';
TempGrid.Cells[0,8]:='35040105';
TempGrid.Cells[0,9]:='35040105';
TempGrid.Cells[0,10]:='35040105';
TempGrid.Cells[0,11]:='35040105';
TempGrid.Cells[0,12]:='35040105';
end;
SELECT val AS 查出的料号,val +'-'+ right(cast(power(10,2) as varchar)+CAST(ROW_NUMBER() OVER (PARTITION BY val ORDER BY val) AS NVARCHAR),2) AS 需变成的这种 FROM #T
上边的格式化序号有点问题,修复了一下
CREATE TABLE #T
(
val NVARCHAR(50) NOT NULL
)
INSERT INTO #t
SELECT '35040112' UNION ALL
SELECT '35040112' UNION ALL
SELECT '35040112' UNION ALL
SELECT '35040102' UNION ALL
SELECT '35040102' UNION ALL
SELECT '35040102' UNION ALL
SELECT '35040102' UNION ALL
SELECT '35040105' UNION ALL
SELECT '35040105' UNION ALL
SELECT '35040105' UNION ALL
SELECT '35040105' UNION ALL
SELECT '35040105'
SELECT val AS 查出的料号, val + '-' + REPLICATE('0',1) + CAST(ROW_NUMBER() OVER (PARTITION BY val ORDER BY val) AS NVARCHAR) AS 需变成的这种 FROM #T