C# code to calculate Damm Algorithm -- In Script transformation task (in DFT)
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
string value = Row.sourcecodeid.ToString();
Int32 intValue;
if (Int32.TryParse(value, out intValue))
{
// mystring is an integer
int column = 0;
int[] intArray = new int[value.Length];
for (int i = 0; i < value.Length; i++)
{
intArray[i] = int.Parse(value[i].ToString());
}
for (int i = 0; i < intArray.Length; i++)
{
int row = intArray[i];
int newvalue = ReturnArrayValue(row, column);
column = newvalue;
if (i == intArray.Length - 1)
Row.checkdigit = column.ToString();
}
}
else
{
Row.checkdigit = value;
}
}
public int ReturnArrayValue(int column, int row)
{
int[,] myArray = new int[,] { { 0, 3, 1, 7 ,5, 9 ,8, 6, 4, 2 }, {7, 0, 9 ,2 ,1, 5, 4 ,8 ,6, 3 }, { 4,2,0,6,8,7,1,3,5,9 },
{1,7,5,0,9,8,3,4,2,6},
{6,1,2,3,0,4,5,9,7,8}, { 3,6,7,4,2,0,9,5,8,1 }, {5,8,6,9,7,2,0,1,3,4}, { 8,9,4,5,3,6,2,0,1,7},
{9,4,3,8,6,1,7,2,0,5 } ,{ 2,5,8,1,4,3,6,7,9,0} };
return myArray[row, column];
}
}
C# code to calculate Damm Algorithm -- In Script task (in control flow)
public void Main()
{
// TODO: Add your code here
string value = Dts.Variables["User::NumberSequence"].Value.ToString();
//checkDigit(val);
Int32 intValue;
if (Int32.TryParse(value, out intValue))
{
// mystring is an integer
int column = 0;
int[] intArray = new int[value.Length];
for (int i = 0; i < value.Length; i++)
{
intArray[i] = int.Parse(value[i].ToString());
}
for (int i = 0; i < intArray.Length; i++)
{
int row = intArray[i];
int newvalue = ReturnArrayValue(row, column);
column = newvalue;
if (i == intArray.Length - 1)
Dts.Variables["User::CheckDigitTest"].Value = column.ToString();
}
}
else
{
Dts.Variables["User::CheckDigitTest"].Value = value;
}
Dts.TaskResult = (int)ScriptResults.Success;
}
public int ReturnArrayValue(int column, int row)
{
int[,] myArray = new int[,] { { 0, 3, 1, 7 ,5, 9 ,8, 6, 4, 2 }, {7, 0, 9 ,2 ,1, 5, 4 ,8 ,6, 3 }, { 4,2,0,6,8,7,1,3,5,9 },
{1,7,5,0,9,8,3,4,2,6},
{6,1,2,3,0,4,5,9,7,8}, { 3,6,7,4,2,0,9,5,8,1 }, {5,8,6,9,7,2,0,1,3,4}, { 8,9,4,5,3,6,2,0,1,7},
{9,4,3,8,6,1,7,2,0,5 } ,{ 2,5,8,1,4,3,6,7,9,0} };
return myArray[row, column];
}
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
string value = Row.sourcecodeid.ToString();
Int32 intValue;
if (Int32.TryParse(value, out intValue))
{
// mystring is an integer
int column = 0;
int[] intArray = new int[value.Length];
for (int i = 0; i < value.Length; i++)
{
intArray[i] = int.Parse(value[i].ToString());
}
for (int i = 0; i < intArray.Length; i++)
{
int row = intArray[i];
int newvalue = ReturnArrayValue(row, column);
column = newvalue;
if (i == intArray.Length - 1)
Row.checkdigit = column.ToString();
}
}
else
{
Row.checkdigit = value;
}
}
public int ReturnArrayValue(int column, int row)
{
int[,] myArray = new int[,] { { 0, 3, 1, 7 ,5, 9 ,8, 6, 4, 2 }, {7, 0, 9 ,2 ,1, 5, 4 ,8 ,6, 3 }, { 4,2,0,6,8,7,1,3,5,9 },
{1,7,5,0,9,8,3,4,2,6},
{6,1,2,3,0,4,5,9,7,8}, { 3,6,7,4,2,0,9,5,8,1 }, {5,8,6,9,7,2,0,1,3,4}, { 8,9,4,5,3,6,2,0,1,7},
{9,4,3,8,6,1,7,2,0,5 } ,{ 2,5,8,1,4,3,6,7,9,0} };
return myArray[row, column];
}
}
C# code to calculate Damm Algorithm -- In Script task (in control flow)
public void Main()
{
// TODO: Add your code here
string value = Dts.Variables["User::NumberSequence"].Value.ToString();
//checkDigit(val);
Int32 intValue;
if (Int32.TryParse(value, out intValue))
{
// mystring is an integer
int column = 0;
int[] intArray = new int[value.Length];
for (int i = 0; i < value.Length; i++)
{
intArray[i] = int.Parse(value[i].ToString());
}
for (int i = 0; i < intArray.Length; i++)
{
int row = intArray[i];
int newvalue = ReturnArrayValue(row, column);
column = newvalue;
if (i == intArray.Length - 1)
Dts.Variables["User::CheckDigitTest"].Value = column.ToString();
}
}
else
{
Dts.Variables["User::CheckDigitTest"].Value = value;
}
Dts.TaskResult = (int)ScriptResults.Success;
}
public int ReturnArrayValue(int column, int row)
{
int[,] myArray = new int[,] { { 0, 3, 1, 7 ,5, 9 ,8, 6, 4, 2 }, {7, 0, 9 ,2 ,1, 5, 4 ,8 ,6, 3 }, { 4,2,0,6,8,7,1,3,5,9 },
{1,7,5,0,9,8,3,4,2,6},
{6,1,2,3,0,4,5,9,7,8}, { 3,6,7,4,2,0,9,5,8,1 }, {5,8,6,9,7,2,0,1,3,4}, { 8,9,4,5,3,6,2,0,1,7},
{9,4,3,8,6,1,7,2,0,5 } ,{ 2,5,8,1,4,3,6,7,9,0} };
return myArray[row, column];
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.