当前位置:编程学习 > C#/ASP.NET >>

把delphi 代码改成c#

哪位高人把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.
--------------------编程问答--------------------   没人帮忙啊。。。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,