using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.RichTextBox richTextBox2;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.richTextBox2 = new System.Windows.Forms.RichTextBox();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// richTextBox2
//
this.richTextBox2.Location = new System.Drawing.Point(240, 128);
this.richTextBox2.Name = "richTextBox2";
this.richTextBox2.Size = new System.Drawing.Size(176, 32);
this.richTextBox2.TabIndex = 5;
this.richTextBox2.Text = "5048480100296497";
//
// label1
//
this.label1.BackColor = System.Drawing.Color.SlateGray;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(24, 128);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(176, 32);
this.label1.TabIndex = 2;
this.label1.Text = "Enter your 16/15 digits credit card number";
//
// button1
//
this.button1.BackColor = System.Drawing.Color.LightSlateGray;
this.button1.Location = new System.Drawing.Point(80, 208);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(120, 32);
this.button1.TabIndex = 1;
this.button1.Text = "Check";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.BackColor = System.Drawing.Color.SlateGray;
this.button2.Location = new System.Drawing.Point(232, 208);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(120, 32);
this.button2.TabIndex = 3;
this.button2.Text = "&Exit";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// richTextBox1
//
this.richTextBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.richTextBox1.Location = new System.Drawing.Point(16, 312);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(472, 104);
this.richTextBox1.TabIndex = 4;
this.richTextBox1.Text = "Enter Your Credit Card number and press Check button";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.MidnightBlue;
this.ClientSize = new System.Drawing.Size(504, 517);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.richTextBox2,
this.richTextBox1,
this.button2,
this.label1,
this.button1});
this.Name = "Form1";
this.Text = "Credit Card Check Digit";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
// Console.WriteLine("raju : ");
}
private void button1_Click(object sender, System.EventArgs e)
{
int[] intNumber = new int[16];
int[] arr = new int[16];
int[] arr1 = new int[16];
int[] sum = new int[16];
int k =0;
string cardno = richTextBox2.Text;
for(int i=0;i<=15;i++)
intNumber[i]=-1;
char[] myChars = cardno.ToCharArray();
for(int i=0;i<=myChars.Length-1;i++)
{
intNumber[i] = (System.Convert.ToInt32(myChars[i])-48);
}
// For 16 Digit Credit Card Number
if(intNumber[15]!= -1)
{
// placing 1's in even places
for(int j=1;j<=15;)
{
arr[j]=1;
j=j+2;
}
// placing 2's in odd places
for(int j=0;j<=15;)
{
arr[j]=2;
j=j+2;
}
sum[0]=0;
for(k=0;k<=15;k++)
{
arr1[k]=((intNumber[k]*arr[k]));
// Substract 9 if the product is greater than 9
if(arr1[k]>9)
arr1[k]= (arr1[k]-9);
else
arr1[k]=arr1[k];
// Find Sum of all elements
if(k==0)
{
sum[k]=arr1[k];
}
if(k!=0)
{
sum[k]=sum[k-1]+arr1[k];
}
// finding mod
if(sum[k]%10==0)
{
richTextBox1.Text= "Congrats!! The Credit Card Number You Entered is Correct";
}
else richTextBox1.Text="Sorry,Please Check Your Credit Card Number and Try Again";
}// end of for
}// end of if
// Similarly the code for 15 digit credit card
if(intNumber[14]!= -1 && intNumber[15]== -1)
{
for(int j=1;j<=14;)
{
arr[j]=2;
j=j+2;
}
for(int j=0;j<=14;)
{
arr[j]=1;
j=j+2;
}
for(int j=0;j<=14;j++)
sum[0]=0;
for(k=0;k<=14;k++)
{
arr1[k]=((intNumber[k]*arr[k]));
if(arr1[k]>9)
arr1[k]= (arr1[k]-9);
else
arr1[k]=arr1[k];
if(k==0)
{
sum[k]=arr1[k];
}
if(k!=0)
{
sum[k]=sum[k-1]+arr1[k];
}
if(sum[k]%10==0)
{
richTextBox1.Text= "Congrats!! The Credit Card Number You Entered is Correct";
}
else richTextBox1.Text="Sorry,Please Check Your Credit Card Number and Try Again";
}// end of for
}
}
private void button2_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}