哪位高人把delphi 代码改成c#

zynk 2013-07-01 04:42:20
哪位高人把delphi 代码改成c#,delphi的基本看不懂。。。改里面顺丰算法部分就行。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function calcutedanhao(str:string;num:integer):string;
function zhaijisong(str:string;num:integer):string;



end;
function add1(s:string):string;
function addstr(s:string):string;
var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
num : integer;
begin
if (Edit1.Text <> '') and (Edit2.Text <> '') then
begin
try
memo1.Clear;
num := strtoint(edit1.Text);
calcutedanhao(edit2.Text,num);
except
on E: Exception do ShowMessage(E.Message);
end;
end
else
ShowMessage('单号,数量不能为空');
end;
function add1(s:string):string;
var
Temp: Int64;
begin
Temp := StrToInt64Def(s, 0);
Inc(Temp);
Result := Format('%-.' + IntToStr(Length(s)) + 'd', [Temp]);
end;
function tform1.zhaijisong(str: string; num: Integer):string;
var
i : integer;
s : string;
l : integer;
st : string;
res : string;
begin
s := copy(str,length(str),1);
st := copy(str,1,length(str)-1);
//showmessage(s+'--------'+st);
l := strtoint(s);
l := l + 1;
if l = 7 then l := 0;
st := add1(st);
//showmessage(st);
res := st + inttostr(l);
if num = 0 then
begin
// showmessage(res);
memo1.lines.add(res);
end
else
if num > 0 then
begin
num := num - 1 ;
memo1.lines.add(res);
zhaijisong(res,num);
end;



end;
procedure TForm1.Button2Click(Sender: TObject);
var
num : integer;
begin
if (Edit1.Text <> '') and (Edit2.Text <> '') then
begin
try
memo1.Clear;
num := strtoint(edit1.Text);


zhaijisong(edit2.Text,num);
except
on E: Exception do ShowMessage(E.Message);
end;
end
else
ShowMessage('单号,数量不能为空');
end;
function tform1.calcutedanhao(str: string; num:integer): string;
var
i1,i2,i3,i4,i5 : integer;
itemp : integer;
//ilast : integer;
//itemplast : integer;
//ilasttemp : integer;
ilastfinal : integer;
tt : integer;
ts : integer;
tr : integer;
tn : integer;
tl : integer;
res : string;
tstr: TStringList;
nnn : string;
begin
if num = 0 then
begin
res := str;
end
else
begin

i1 := strtoint(copy(str,12,1));

i2 := strtoint(copy(str,11,1));
i3 := strtoint(copy(str,10,1));
i4 := strtoint(copy(str,9,1));
i5 := strtoint(copy(str,8,1));
nnn := Copy(str,1,10);
if (i3=9) and (i2=9) then

begin
tl := i1;
if tl = 0 then tl := 10;
tl := tl - 1;
itemp := tl;
if i4 mod 2 = 0 then
begin
itemp := itemp + 4;
end
else
begin
itemp := itemp + 3;
end;

i1 := itemp;
end
else
begin
ilastfinal := i1;

i1 := ilastfinal + 9;
end;

i2 := i2 + 1;

if i2 >= 10 then
begin
i2 := i2 - 10;
tt := ilastfinal;

if tt= 0 then
begin
tt := 10;
end;
tt := tt - 1;
ts := tt;
tr := tt;
tn := tt;
case i3 + 1 of
1,2,3:
begin
ts := tt + 7;
if ts >= 10 then ts := ts - 10;
i1 := ts;
end;
4,5,6 :
begin
if i3 + 1 = 4 then

tr := tr + 6
else
tr := tr + 7;

if tr >= 10 then tr := tr - 10;
i1 := tr;
end;
7,8,9 :
begin
if i3 + 1 = 7 then

tn := tn + 6
else
tn := tn + 7;

if tn >= 10 then tn := tn - 10;
i1 := tn;
end;
end;
nnn := addstr(nnn);
end;
if i1 >= 10 then
begin
i1 := i1 - 10;
end;
str := nnn + inttostr(i2) + inttostr(i1);
num := num - 1;
memo1.Lines.Add(nnn + inttostr(i2) + inttostr(i1));

if i2 = 9 then memo1.Lines.Add('');

res := calcutedanhao(str,num);
end;

end;
function addstr(s:string):string;
var

i:integer;

begin

for i:=length(s) downto 1 do
if s[i]='9' then
s[i]:='0'
else
begin
s[i]:=chr(ord(s[i])+1);
break;
end;
result:=s;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Memo1.Lines.SaveToFile('E:\temp.txt');
end;

end.


.

...全文
347 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zynk 2013-07-18
  • 打赏
  • 举报
回复
引用 9 楼 SunRise86 的回复:
[quote=引用 8 楼 u010463491 的回复:] [quote=引用 7 楼 SunRise86 的回复:] [quote=引用 6 楼 u010463491 的回复:] [quote=引用 4 楼 SunRise86 的回复:]
public string  zhaijisong( string str,int num)
        {
           int i,l;
           string s,st,res;
            s=str.Substring(str.Length,1);
            st=str.Substring(1,str.Length-1);
            l =int.Parse(s);
            l=l+1;
            if (l==7 )
            {
                l=0;
            }
            st=add1(st);//这段没有翻译。
            res =st+l.ToString();
            if (num==0)
            {
                memo1.lines.add(res);//这里的memo是控件,你在C#找一个代替
            }
            else if (num>0) 
            {
                num =num-1;
                memo1.lines.add(res);
                zhaijisong( str,num);
            }
            return string.Empty;
        }
很粗的翻译了,估计有很多的不对的。 但是看了你原来的delphi代码,你确定你的delphi程序能跑吗?我怎么感觉里面有很多的错丫误。
我只要顺丰的哦。不要宅急送的[/quote] 你把翻译的那段代码,贴出来呢,我翻译下看看[/quote] 方便留个联系方式吗?我直接把软件发给你。[/quote] QQ :364485745 晚上8点后给我吧[/quote] 非常感谢,8点后我加你。
白色翅膀的鱼 2013-07-18
  • 打赏
  • 举报
回复
引用 8 楼 u010463491 的回复:
[quote=引用 7 楼 SunRise86 的回复:] [quote=引用 6 楼 u010463491 的回复:] [quote=引用 4 楼 SunRise86 的回复:]
public string  zhaijisong( string str,int num)
        {
           int i,l;
           string s,st,res;
            s=str.Substring(str.Length,1);
            st=str.Substring(1,str.Length-1);
            l =int.Parse(s);
            l=l+1;
            if (l==7 )
            {
                l=0;
            }
            st=add1(st);//这段没有翻译。
            res =st+l.ToString();
            if (num==0)
            {
                memo1.lines.add(res);//这里的memo是控件,你在C#找一个代替
            }
            else if (num>0) 
            {
                num =num-1;
                memo1.lines.add(res);
                zhaijisong( str,num);
            }
            return string.Empty;
        }
很粗的翻译了,估计有很多的不对的。 但是看了你原来的delphi代码,你确定你的delphi程序能跑吗?我怎么感觉里面有很多的错丫误。
我只要顺丰的哦。不要宅急送的[/quote] 你把翻译的那段代码,贴出来呢,我翻译下看看[/quote] 方便留个联系方式吗?我直接把软件发给你。[/quote] QQ :364485745 晚上8点后给我吧
zynk 2013-07-18
  • 打赏
  • 举报
回复
引用 7 楼 SunRise86 的回复:
[quote=引用 6 楼 u010463491 的回复:] [quote=引用 4 楼 SunRise86 的回复:]
public string  zhaijisong( string str,int num)
        {
           int i,l;
           string s,st,res;
            s=str.Substring(str.Length,1);
            st=str.Substring(1,str.Length-1);
            l =int.Parse(s);
            l=l+1;
            if (l==7 )
            {
                l=0;
            }
            st=add1(st);//这段没有翻译。
            res =st+l.ToString();
            if (num==0)
            {
                memo1.lines.add(res);//这里的memo是控件,你在C#找一个代替
            }
            else if (num>0) 
            {
                num =num-1;
                memo1.lines.add(res);
                zhaijisong( str,num);
            }
            return string.Empty;
        }
很粗的翻译了,估计有很多的不对的。 但是看了你原来的delphi代码,你确定你的delphi程序能跑吗?我怎么感觉里面有很多的错丫误。
我只要顺丰的哦。不要宅急送的[/quote] 你把翻译的那段代码,贴出来呢,我翻译下看看[/quote] 方便留个联系方式吗?我直接把软件发给你。
白色翅膀的鱼 2013-07-18
  • 打赏
  • 举报
回复
引用 6 楼 u010463491 的回复:
[quote=引用 4 楼 SunRise86 的回复:]
public string  zhaijisong( string str,int num)
        {
           int i,l;
           string s,st,res;
            s=str.Substring(str.Length,1);
            st=str.Substring(1,str.Length-1);
            l =int.Parse(s);
            l=l+1;
            if (l==7 )
            {
                l=0;
            }
            st=add1(st);//这段没有翻译。
            res =st+l.ToString();
            if (num==0)
            {
                memo1.lines.add(res);//这里的memo是控件,你在C#找一个代替
            }
            else if (num>0) 
            {
                num =num-1;
                memo1.lines.add(res);
                zhaijisong( str,num);
            }
            return string.Empty;
        }
很粗的翻译了,估计有很多的不对的。 但是看了你原来的delphi代码,你确定你的delphi程序能跑吗?我怎么感觉里面有很多的错丫误。
我只要顺丰的哦。不要宅急送的[/quote] 你把翻译的那段代码,贴出来呢,我翻译下看看
zynk 2013-07-18
  • 打赏
  • 举报
回复
引用 4 楼 SunRise86 的回复:
public string  zhaijisong( string str,int num)
        {
           int i,l;
           string s,st,res;
            s=str.Substring(str.Length,1);
            st=str.Substring(1,str.Length-1);
            l =int.Parse(s);
            l=l+1;
            if (l==7 )
            {
                l=0;
            }
            st=add1(st);//这段没有翻译。
            res =st+l.ToString();
            if (num==0)
            {
                memo1.lines.add(res);//这里的memo是控件,你在C#找一个代替
            }
            else if (num>0) 
            {
                num =num-1;
                memo1.lines.add(res);
                zhaijisong( str,num);
            }
            return string.Empty;
        }
很粗的翻译了,估计有很多的不对的。 但是看了你原来的delphi代码,你确定你的delphi程序能跑吗?我怎么感觉里面有很多的错丫误。
我只要顺丰的哦。不要宅急送的
zynk 2013-07-18
  • 打赏
  • 举报
回复
非常感谢,我来测试一下
白色翅膀的鱼 2013-07-12
  • 打赏
  • 举报
回复
public string  zhaijisong( string str,int num)
        {
           int i,l;
           string s,st,res;
            s=str.Substring(str.Length,1);
            st=str.Substring(1,str.Length-1);
            l =int.Parse(s);
            l=l+1;
            if (l==7 )
            {
                l=0;
            }
            st=add1(st);//这段没有翻译。
            res =st+l.ToString();
            if (num==0)
            {
                memo1.lines.add(res);//这里的memo是控件,你在C#找一个代替
            }
            else if (num>0) 
            {
                num =num-1;
                memo1.lines.add(res);
                zhaijisong( str,num);
            }
            return string.Empty;
        }
很粗的翻译了,估计有很多的不对的。 但是看了你原来的delphi代码,你确定你的delphi程序能跑吗?我怎么感觉里面有很多的错丫误。
白色翅膀的鱼 2013-07-12
  • 打赏
  • 举报
回复
zhaijisong,calcutedanhao这个2个函数?
zynk 2013-07-12
  • 打赏
  • 举报
回复
直接翻译一下呗
homeyone 2013-07-10
  • 打赏
  • 举报
回复
个人估计~这样发帖回复不多~ 最少你也指出哪些不懂啊!

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧