|
So, and what is your exact problem? Does the code not run?
To format text within C# use e.g. the ToString()-method of DateTime. There you can pass the "yyMMdd" format. Formatting the license number is done within the ToString()-method of int32. I think you can pass the same formatstring "000" there as in Java.
Regards
Sebastian
|
|
|
|
|
Hi .... SeMartens
Right ! it can't work , compiler show 7 bugs .
Sorry for my pool programming ability.....I still don't know how to modify this code ....
garnett
|
|
|
|
|
What are the bugs? Copy and paste the compiler errors. Text, line numbers, everything. If you want to be especially helpful, bold the lines where these errors occur and put the error text in comments on the same line
|
|
|
|
|
bug list ........
Wrong 1 Method ' Add' Any has not carried uses ' 2' Argument F:\Documents\Visual Studio 2008 \ Projects \ Keygen \ Keygen \ Program.cs 16 9 Keygen
Wrong 2 Method ' Add' Any has not carried uses ' 2' Argument F:\Documents\Visual Studio 2008 \ Projects \ Keygen \ Keygen \ Program.cs 17 9 Keygen
Wrong 3 Could not find the variant or naming space name ' NumberFormat' (you whether to omit the using pointer word or module reference?) F:\Documents\Visual Studio 2008 \ Projects \ Keygen \ Keygen \ Program.cs 19 9 Keygen
Wrong 4 Could not find the variant or naming space name ' java' (you whether to omit the using pointer word or module reference?) F:\Documents\Visual Studio 2008 \ Projects \ Keygen \ Keygen \ Program.cs 19 31 Keygen
Wrong 5 Could not find the variant or naming space name ' java' (you whether to omit the using pointer word or module reference?) F:\Documents\Visual Studio 2008 \ Projects \ Keygen \ Keygen \ Program.cs 21 60 Keygen
Wrong 6 ' System.DateTime' Does not contain ' getTime' Definition, could also not find expansion method ' getTime' Accepts variant ' System.DateTime' The first argument (you whether to omit the using pointer word or module reference?) F:\Documents\Visual Studio 2008 \ Projects \ Keygen \ Keygen \ Program.cs 21 108 Keygen
Wrong 7 Is unable variant ' string' The concealment transformation is ' sbyte[]' F:\Documents\Visual Studio 2008 \ Projects \ Keygen \ Keygen \ Program.cs 55 18 Keygen
garnett
|
|
|
|
|
I understand English is not your first language. But If you can understand previous posts, sure you can understand the compiler errors.
The compiler saw something that it did not recognize. Read it again. It gave you amble explanations. It is saying Method does not exist. What do you think that means? Think about it.
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Right. First of all, you haven't said what DateTime.Add does in Java (in particular, does it add seconds, minutes, days, etc). Either way, the DateTime.AddSeconds, DateTime.AddMinutes, DateTime.AddDays methods should help. 'string licenseNum' should 'ref string licenseNum' if you plan to persist the changes. These will get rid of Wrongs 1 and 2
For your number formatting, you simply need to set licenseNum to Integer.Parse(licenseNum).ToString("000"), and this will get rid of Wrong 3
cal.getTime() can be replaced with DateTime.Now
The java.text.simpleDateFormat stuff can be replaced with cal.ToString("yyMMdd")
You cannot set an array of sbyte to a string. Just set k to s.Length and j to char.ConvertToUtf32(s, i)
|
|
|
|
|
First of all creating the date:
<br />
DateTime dDate = DateTime.Now.AddYears(3);<br />
To format the license key into a three-digit number use:
<br />
licenseNum = Int32.Parse(licenseNum).ToString("D3"); <br />
The date can be converted using
<br />
string verTime = "-" + dDate.ToString("yyMMdd") + "0";<br />
Convert all other lines according to this.
Hope this helps you a bit.
Regards
Sebastian
|
|
|
|
|
java code is below :
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.add(1, 3);
cal.add(6, -1);
java.text.NumberFormat nf = new java.text.DecimalFormat("000");
licenseNum = nf.format(Integer.valueOf(licenseNum));
and here "sbyte" method has some problem
private string change(string s)
{
//sbyte[] abyte0;
char[] ac;
int i;
int k;
int j;
//abyte0 = s;
ac = new char[s.Length];
i = 0;
k = s.Length;
while (i < k)
{
j = char.ConvertToUtf32(s, i);
if ((j >= 48) && (j <= 57))
garnett
|
|
|
|
|
Thanks everyone again !
but the code that I modified is below,but still has problem:
---------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
public class MyGen
{
private const string LL = "keygen";
public virtual string getSerial(string userId, string licenseNum)
{
DateTime dDate = DateTime.Now.AddYears(3);<br />
dDate.Add(1, 3);<br />
dDate.Add(6, -1);
licenseNum = Int32.Parse(licenseNum).ToString("D3");
string verTime = "-" + dDate.ToString("yyMMdd") + "0";
string type = "YE3MP-";
string need = new StringBuilder(userId.Substring(0, 1)).Append(type).Append("300").Append(licenseNum).Append(verTime).ToString();
string dx = new StringBuilder(need).Append(LL).Append(userId).ToString();
int suf = this.decode(dx);
string code = new StringBuilder(need).Append(Convert.ToString(suf)).ToString();
return this.change(code);
}
private int decode(string s)
{
int i;
char[] ac;
int j;
int k;
i = 0;
ac = s.ToCharArray();
j = 0;
k = ac.Length;
while (j < k)
{
i = (31 * i) + ac[j];
j++;
}
return Math.Abs(i);
}
private string change(string s)
{
sbyte[] abyte0;
char[] ac;
int i;
int k;
int j;
abyte0 = s;<br />
ac = new char[s.Length];<br />
i = 0;<br />
k = s.Length;<br />
while (i < k)<br />
{<br />
j = char.ConvertToUtf32(s, i);
if ((j >= 48) && (j <= 57))
{
j = (((j - 48) + 5) % 10) + 48;
}
else if ((j >= 65) && (j <= 90))
{
j = (((j - 65) + 13) % 26) + 65;
}
else if ((j >= 97) && (j <= 122))
{
j = (((j - 97) + 13) % 26) + 97;
}
ac[i] = (char)j;
i++;
}
return Convert.ToString(ac);
}
public MyGen()
: base()
{
}
static void Main(string[] args)
{
try
{
Console.WriteLine("please input register name:");
string userId = null;
userId = System.Console.ReadLine();
MyGen MyGen = new MyGen();
string res = MyGen.getSerial(userId, "5");
Console.WriteLine("Serial:" + res);
System.Console.ReadLine();
}
catch (IOException ex)
{
}
}
}
garnett
|
|
|
|
|
Remove the fourth highlighted line. However, you need to say: what do the second and third highlighted lines do?
You are also missing the new list of errors
|
|
|
|
|
If I Remove the fourth highlighted line,and mark //abyte0 = s;
the problem remain
DateTime dDate = DateTime.Now.AddYears(3);
dDate.Add(1, 3);
dDate.Add(6, -1);
error show dDate.Add can't overload 2 arguments
and I think "DateTime.Now.AddYears(3)" is wrong to orginal too...
garnett
|
|
|
|
|
Yes, but what would those lines do in java?
|
|
|
|
|
|
Got it. The first line is dDate.AddYears(3);
The second line is dDate.AddDays(-1);
Do you really intend to initialise dDate to a date three years in the future? Based on your original code, you just want it to be initialised to DateTime.Now
By the way, it makes life a lot easier for other people if you use descriptive values. java.util.Calendar contained a list of constants which would have made life a lot easier
|
|
|
|
|
Hi ... Thanks again !
I pass for compiler this code , but the output is wrong
when I run keygen.exe
input name : test
it show
Serial:System.Char[]
somewhere is still wrong .....
---------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
public class MyGen
{
private const string LL = "keygen";
public virtual string getSerial(string userId, string licenseNum)
{
DateTime dDate = DateTime.Now;
dDate.AddYears(3);
dDate.AddDays(-1);
//dDate.Add(1, 3);
//dDate.Add(6, -1);
licenseNum = Int32.Parse(licenseNum).ToString("D3");
string verTime = "-" + dDate.ToString("yyMMdd") + "0";
string type = "YE3MP-";
string need = new StringBuilder(userId.Substring(0, 1)).Append(type).Append("300").Append(licenseNum).Append(verTime).ToString();
string dx = new StringBuilder(need).Append(LL).Append(userId).ToString();
int suf = this.decode(dx);
string code = new StringBuilder(need).Append(Convert.ToString(suf)).ToString();
return this.change(code);
}
private int decode(string s)
{
int i;
char[] ac;
int j;
int k;
i = 0;
ac = s.ToCharArray();
j = 0;
k = ac.Length;
while (j < k)
{
i = (31 * i) + ac[j];
j++;
}
return Math.Abs(i);
}
private string change(string s)
{
//sbyte[] abyte0;
char[] ac;
int i;
int k;
int j;
//abyte0 = s;
ac = new char[s.Length];
i = 0;
k = s.Length;
while (i < k)
{
j = char.ConvertToUtf32(s, i);
if ((j >= 48) && (j <= 57))
{
j = (((j - 48) + 5) % 10) + 48;
}
else if ((j >= 65) && (j <= 90))
{
j = (((j - 65) + 13) % 26) + 65;
}
else if ((j >= 97) && (j <= 122))
{
j = (((j - 97) + 13) % 26) + 97;
}
ac[i] = (char)j;
i++;
}
return Convert.ToString(ac);
}
public MyGen() : base()
{
}
static void Main(string[] args)
{
try
{
System.Console.WriteLine("please input register name:");
string userId = null;
userId = System.Console.ReadLine();
MyGen MyGen = new MyGen();
string res = MyGen.getSerial(userId, "5");
System.Console.WriteLine("Serial:" + res);
System.Console.ReadLine();
}
catch (IOException ex)
{
}
}
}
garnett
|
|
|
|
|
It's the 'Convert.ToString(ac)' line in the change() function. You need to return 'new string(ac)'
|
|
|
|
|
Thanks Computafreak.....
it works
I'll test it !
garnett
|
|
|
|
|
I'm trying to create a new thread which constantly draws graphics to a form.
My problem seems to be when I want to update the graphics, I call the Invalidate() method, but this causes massive flickering which I don't experience if I use a single thread and draw the graphics directly in the Form1_Paint method.
Here's my code:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
namespace app
{
public partial class Form1 : Form
{
private System.Drawing.Bitmap myBitmap;
Thread newThread;
public Form1()
{
InitializeComponent();
newThread = new Thread(new ThreadStart(draw));
newThread.Start();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics graphicsObj = e.Graphics;
graphicsObj.DrawImage(myBitmap, 0, 0, myBitmap.Width, myBitmap.Height);
}
private void Form1_Load(object sender, EventArgs e)
{
myBitmap = new Bitmap(this.ClientRectangle.Width,
this.ClientRectangle.Height,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
}
public void draw()
{
Graphics gfx;
gfx = Graphics.FromImage(myBitmap);
Pen myPen = new Pen(System.Drawing.Color.Plum, 3);
gfxLoop:
for (int i = 1; i < 100; i++)
{
myPen.Color = Color.FromArgb(0, 0 + (i * 2), 0);
gfx.DrawEllipse(myPen, 50 + i, 50 + i, 200 - (i * 2), 200 - (i * 2));
Thread.Sleep(20);
this.Invalidate();
}
for (int j = 0; j < 100; j++)
{
myPen.Color = Color.FromArgb(200 - (j * 2), 0, 100 - j);
gfx.DrawEllipse(myPen, 150 - j, 150 - j, j * 2, j * 2);
Thread.Sleep(20);
this.Invalidate();
}
goto gfxLoop;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
newThread.Abort();
}
}
}
Anyone got any good tips in how to overcome this flickering?
|
|
|
|
|
Your Invalidate() method is causing the flicker. Draw the ellipses to a Bitmap, then at the end of each loop iteration, draw the Bitmap to gfx and Invalidate() then. This is double-buffering
|
|
|
|
|
Hi,
Didn't know where to post it else, because there is no VSX Forum.
I'm stuck with this problem for quiet some time and I can't find an example how do it...
Can somebody please help?
Thanks
|
|
|
|
|
|
Dromar wrote: Didn't know where to post it else, because there is no VSX Forum.
sure there is[^]
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Hi
I have Dataset that include table Items, How can I sort this table by Code field ?
thank's in advance
|
|
|
|
|
use this:
var sortedDataRowEnumerable = dataset.Tables[0].AsEnumerable().OrderBy(r => r["coltosort"]);
Or
dataset.Tables[0].DefaultView..Sort = "coltosort DESC";
|
|
|
|
|
thank you very much !
and how can I run any query on this DataSet ?
|
|
|
|