A Developer Journey who codes for fun

Daily Dose Of Code

  • Home
  • Dot.Net Basics
    • .Net Basics
      • CTS
      • CLS
      • CLR
      • Strong Vs Weak Ref
      • .Net Framework
      • What is Manifest
    • Memory Management
      • Garbage Collection 1
      • Garbage Collection 2
      • Circular Reference
  • C Sharp
    • Abstract Class in C#
    • Interfaces in C#
    • Value type by Val and By Ref
    • Var keyword
    • Null Coalescing Operator
    • Buit-in code snippets
  • OOPS
    • Abstraction and Encapsulation
    • Polymorphism
    • Inheritence
    • Aggregation
  • Threading
    • Delegates
      • Calling Delegate using Invoke, BeginInvoke
      • Multicast Delegate
      • Exception Handling in Multicast Delegate
      • Action
      • Predicate
      • Func
    • Synchronization
    • Thread Pool
    • Exception Handling
    • TPL
  • Design Pattern
    • Creational Patterns
      • Singleton Pattern
      • Factory Pattern
      • Abstract Factory Pattern
      • Prototype Pattern
      • Builder Pattern
    • Structural Patterns
      • Adapter Pattern
      • Bridge Pattern
      • Composite Pattern
      • Proxy Pattern
      • Facade Pattern
      • Decorator Pattern
      • Flyweight Pattern
    • Behavioral Patterns
      • Command Pattern
      • Interpreter Pattern
      • Iterator Pattern
      • Mediator Pattern
      • Memento Pattern
      • Observer Pattern
      • State Pattern
      • Strategy Pattern
      • Visitor Pattern
      • Chain Of Responsibility Pattern
      • Template Pattern
  • Data Structures
    • Generic List in C#
    • 2d array to 1d array
    • 3d arrayto 1d array
    • Linked List
      • Singly Linked List in C#
    • Queue
      • Dummy Data 1
    • Stack
      • Dummy Data 2
    • Tree
      • Dummy Data 3
    • Graph
      • Dummy Data 4
  • WCF
    • WCF Service using VS 2015
  • Scripts
    • Chrome Extensions
      • Create a Chrome Extension
      • Facebook autologout script
      • Gmail autologout script

How to: Read Image Metadata

 Unknown     3:30 AM     No comments   

Some image files contain metadata that you can read to determine features of the image. Like, a digital photograph might contain metadata that you can read to determine the Author,Title and Keywords of the image.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ImageMetaData.aspx.cs" Inherits="ImageMetaData" %>



Untitled Page














using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DSOFile;
public partial class ImageMetaData : System.Web.UI.Page
{
OleDocumentPropertiesClass oDocument;
string strImgName = string.Empty;
string strImgPath = string.Empty;
string strImgTitle = string.Empty;
string strImgAuthor = string.Empty;
string strImgSubject = string.Empty;
string strImgCompany = string.Empty;
string strImgComments = string.Empty;
string strImgApplication = string.Empty;
string strImgVersion = string.Empty;
string strImgCategory = string.Empty;
string strImgKeywords = string.Empty;
string strImgManager = string.Empty;
string strImgLastSavedBy = string.Empty;
string strImgByteCount = string.Empty;
string strImgDateCreated = string.Empty;
string strImgRevisionnum = string.Empty;
string strImgHeight = string.Empty;
string strImgWidth = string.Empty;
string strImgHResolution = string.Empty;
string strImgVResolution = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
OpenDocumentProperties(FileUpload1.PostedFile.FileName.ToString());
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("
AuthorSubjectTitle
");
sb.Append(strImgAuthor);
sb.Append("
");
sb.Append(strImgSubject);
sb.Append("
");
sb.Append(strImgTitle);
sb.Append("
");
Label1.Text = sb.ToString();
}
protected void OpenDocumentProperties(string strFile)
{
try
{
DSOFile.SummaryProperties oSummProps;
string strTmp = string.Empty;
oDocument = new DSOFile.OleDocumentPropertiesClass();
oDocument.Open(strFile, false, DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);
oSummProps = oDocument.SummaryProperties;
strImgName = oDocument.Name;
strImgPath = oDocument.Path;
if (oSummProps.Author == "" || oSummProps.Comments == "" || oSummProps.Title == "" || oSummProps.Keywords == "")
{
strImgTitle = "All";
}
else
{
strImgTitle = oSummProps.Title;
}
if (oSummProps.Author == "")
{
strImgAuthor = "Unknown";
}
else
{
strImgAuthor = oSummProps.Author;
}
strImgSubject = oSummProps.Subject;
strImgCompany = oSummProps.Company;
strImgComments = oSummProps.Comments;
strImgApplication = oSummProps.ApplicationName;
strImgVersion = oSummProps.Version;
strImgCategory = oSummProps.Category;
strImgKeywords = "," + oSummProps.Keywords.ToString() + ",";
strImgManager = oSummProps.Manager;
strImgLastSavedBy = oSummProps.LastSavedBy;
strImgByteCount = oSummProps.ByteCount.ToString();
if (oSummProps.DateCreated != null)
{
strImgDateCreated = oSummProps.DateCreated.ToString();
}
else
{
strImgDateCreated = "";
}
strImgRevisionnum = oSummProps.RevisionNumber;
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
}
}
}
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

How to store a record in xml file from a windows form and extract through Reflection..(A perfect example of reflection)

 Unknown     3:15 AM     No comments   

Reflection.cs Browse folder to store record in xml file and again browse to extract from the xml file all the properties are setting in settings.cs and all constants are defined in Constants.cs and Reflection.Designer contains the designer view..

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Text.RegularExpressions;

namespace ReflectionExample
{
public partial class Reflection : Form
{
private bool boolEmailValidation = false;
private bool boolPercentValidation;
public Reflection()
{
InitializeComponent();
}

Settings settings = new Settings();

private void Form1_Load(object sender, EventArgs e)
{

}
private void RetrieveButton_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
settings.Load(openFileDialog1.FileName);
UpdateSettings();
}
}

private void UpdateSettings()
{
textStudentName.Text = settings.StudentName;
textFathersName.Text = settings.FatherName;
textInstituteName.Text = settings.Institute;
textLastDegree.Text = settings.LastDegree;
textPercentage.Text = settings.Percentage;
textEmailId.Text = settings.EmailId;
SaveButton.Visible = false;
}

private void SaveButton_Click(object sender, EventArgs e)
{
if (boolPercentValidation)
{
if (boolEmailValidation)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
settings.Save(saveFileDialog1.FileName);
FunctionEmpty();
}
}
else
{
MessageBox.Show(Constants.EmailError, Constants.Error1, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show(Constants.PercentageError, Constants.Error1, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void FunctionEmpty()
{
textStudentName.Text = string.Empty;
textFathersName.Text = string.Empty;
textInstituteName.Text = string.Empty;
textLastDegree.Text = string.Empty;
textPercentage.Text = string.Empty;
textEmailId.Text = string.Empty;
}
private void textStudentName_TextChanged(object sender, EventArgs e)
{
settings.StudentName = textStudentName.Text;
}

private void textFathersName_TextChanged(object sender, EventArgs e)
{
settings.FatherName = textFathersName.Text;
}

private void textInstituteName_TextChanged(object sender, EventArgs e)
{
settings.Institute = textInstituteName.Text;
}

private void textLastDegree_TextChanged (object sender, EventArgs e)
{
settings.LastDegree = textLastDegree.Text;
}

private void textPercentage_TextChanged (object sender, EventArgs e)
{
boolPercentValidation = true;
Regex objNotNaturalPattern = new Regex(Constants.PercentageRegularExpression);
if (!objNotNaturalPattern.IsMatch(textPercentage.Text))
{
if (textPercentage.Text != string.Empty)
{
int Marks = Convert.ToInt32(textPercentage.Text);
if (Marks > 100)
{
boolPercentValidation = false;
}
settings.Percentage = textPercentage.Text;
}
}
else
{
boolPercentValidation = false;
}


}

private void textEmailId_TextChanged (object sender, EventArgs e)
{
boolEmailValidation = true;
Regex objNotNaturalPattern = new Regex(Constants.EmailIdRegularExpression);
if (objNotNaturalPattern.IsMatch(textEmailId.Text))
{
boolEmailValidation = true;
settings.EmailId = textEmailId.Text;
}
else
{
boolEmailValidation = false;
}

}

private void CancelButton_Click(object sender, EventArgs e)
{
this.Dispose();
}
}
}

/*Reflection.Designer View*/

namespace ReflectionExample
{
partial class Reflection
{
///
/// Required designer variable.
///

private System.ComponentModel.IContainer components = null;

///
/// Clean up any resources being used.
///

/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (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.components = new System.ComponentModel.Container();
this.Namelabel = new System.Windows.Forms.Label();
this.textStudentName = new System.Windows.Forms.TextBox();
this.FNamelabel = new System.Windows.Forms.Label();
this.textFathersName = new System.Windows.Forms.TextBox();
this.Instituelabel = new System.Windows.Forms.Label();
this.textInstituteName = new System.Windows.Forms.TextBox();
this.Institutelabel = new System.Windows.Forms.Label();
this.textLastDegree = new System.Windows.Forms.TextBox();
this.Percentagelabel = new System.Windows.Forms.Label();
this.textPercentage = new System.Windows.Forms.TextBox();
this.Emaillabel = new System.Windows.Forms.Label();
this.textEmailId = new System.Windows.Forms.TextBox();
this.SaveButton = new System.Windows.Forms.Button();
this.RetrieveButton = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.CancelButton = new System.Windows.Forms.Button();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.errorProvider1 = new System.Windows.Forms.ErrorProvider(this.components);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).BeginInit();
this.SuspendLayout();
//
// Namelabel
//
this.Namelabel.AutoSize = true;
this.Namelabel.Location = new System.Drawing.Point(68, 36);
this.Namelabel.Name = "Namelabel";
this.Namelabel.Size = new System.Drawing.Size(35, 13);
this.Namelabel.TabIndex = 0;
this.Namelabel.Text = "Name";
//
// textStudentName
//
this.textStudentName.Location = new System.Drawing.Point(185, 33);
this.textStudentName.MaxLength = 15;
this.textStudentName.Name = "textStudentName";
this.textStudentName.Size = new System.Drawing.Size(149, 20);
this.textStudentName.TabIndex = 1;
this.textStudentName.TextChanged += new System.EventHandler(this.textStudentName_TextChanged);
//
// FNamelabel
//
this.FNamelabel.AutoSize = true;
this.FNamelabel.Location = new System.Drawing.Point(28, 76);
this.FNamelabel.Name = "FNamelabel";
this.FNamelabel.Size = new System.Drawing.Size(75, 13);
this.FNamelabel.TabIndex = 2;
this.FNamelabel.Text = "Father\'s Name";
//
// textFathersName
//
this.textFathersName.Location = new System.Drawing.Point(185, 73);
this.textFathersName.MaxLength = 15;
this.textFathersName.Name = "textFathersName";
this.textFathersName.Size = new System.Drawing.Size(149, 20);
this.textFathersName.TabIndex = 3;
this.textFathersName.TextChanged += new System.EventHandler(this.textFathersName_TextChanged);
//
// Instituelabel
//
this.Instituelabel.AutoSize = true;
this.Instituelabel.Location = new System.Drawing.Point(59, 125);
this.Instituelabel.Name = "Instituelabel";
this.Instituelabel.Size = new System.Drawing.Size(44, 13);
this.Instituelabel.TabIndex = 4;
this.Instituelabel.Text = "Institute";
//
// textInstituteName
//
this.textInstituteName.Location = new System.Drawing.Point(185, 122);
this.textInstituteName.MaxLength = 25;
this.textInstituteName.Name = "textInstituteName";
this.textInstituteName.Size = new System.Drawing.Size(149, 20);
this.textInstituteName.TabIndex = 5;
this.textInstituteName.TextChanged += new System.EventHandler(this.textInstituteName_TextChanged);
//
// Institutelabel
//
this.Institutelabel.AutoSize = true;
this.Institutelabel.Location = new System.Drawing.Point(38, 174);
this.Institutelabel.Name = "Institutelabel";
this.Institutelabel.Size = new System.Drawing.Size(65, 13);
this.Institutelabel.TabIndex = 6;
this.Institutelabel.Text = "Last Degree";
//
// textLastDegree
//
this.textLastDegree.Location = new System.Drawing.Point(185, 171);
this.textLastDegree.MaxLength = 30;
this.textLastDegree.Name = "textLastDegree";
this.textLastDegree.Size = new System.Drawing.Size(149, 20);
this.textLastDegree.TabIndex = 7;
this.textLastDegree.TextChanged += new System.EventHandler(this.textLastDegree_TextChanged);
//
// Percentagelabel
//
this.Percentagelabel.AutoSize = true;
this.Percentagelabel.Location = new System.Drawing.Point(38, 220);
this.Percentagelabel.Name = "Percentagelabel";
this.Percentagelabel.Size = new System.Drawing.Size(62, 13);
this.Percentagelabel.TabIndex = 8;
this.Percentagelabel.Text = "Percentage";
//
// textPercentage
//
this.textPercentage.Location = new System.Drawing.Point(185, 217);
this.textPercentage.MaxLength = 3;
this.textPercentage.Name = "textPercentage";
this.textPercentage.Size = new System.Drawing.Size(149, 20);
this.textPercentage.TabIndex = 9;
this.textPercentage.TextChanged += new System.EventHandler(this.textPercentage_TextChanged);
//
// Emaillabel
//
this.Emaillabel.AutoSize = true;
this.Emaillabel.Location = new System.Drawing.Point(56, 274);
this.Emaillabel.Name = "Emaillabel";
this.Emaillabel.Size = new System.Drawing.Size(44, 13);
this.Emaillabel.TabIndex = 10;
this.Emaillabel.Text = "Email Id";
//
// textEmailId
//
this.textEmailId.Location = new System.Drawing.Point(185, 271);
this.textEmailId.MaxLength = 30;
this.textEmailId.Name = "textEmailId";
this.textEmailId.Size = new System.Drawing.Size(149, 20);
this.textEmailId.TabIndex = 11;
this.textEmailId.TextChanged += new System.EventHandler(this.textEmailId_TextChanged);
//
// SaveButton
//
this.SaveButton.Location = new System.Drawing.Point(185, 361);
this.SaveButton.Name = "SaveButton";
this.SaveButton.Size = new System.Drawing.Size(75, 23);
this.SaveButton.TabIndex = 12;
this.SaveButton.Text = "Save";
this.SaveButton.UseVisualStyleBackColor = true;
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
//
// RetrieveButton
//
this.RetrieveButton.Location = new System.Drawing.Point(281, 361);
this.RetrieveButton.Name = "RetrieveButton";
this.RetrieveButton.Size = new System.Drawing.Size(75, 23);
this.RetrieveButton.TabIndex = 13;
this.RetrieveButton.Text = "Retrieve";
this.RetrieveButton.UseVisualStyleBackColor = true;
this.RetrieveButton.Click += new System.EventHandler(this.RetrieveButton_Click);
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
this.openFileDialog1.Filter = "XML Files|*.xml|All Files|*.*";
//
// saveFileDialog1
//
this.saveFileDialog1.DefaultExt = "xml";
this.saveFileDialog1.Filter = "XML Files|*.xml|All Files|*.*";
//
// CancelButton
//
this.CancelButton.Location = new System.Drawing.Point(89, 361);
this.CancelButton.Name = "CancelButton";
this.CancelButton.Size = new System.Drawing.Size(75, 23);
this.CancelButton.TabIndex = 14;
this.CancelButton.Text = "Cancel";
this.CancelButton.UseVisualStyleBackColor = true;
this.CancelButton.Click += new System.EventHandler(this.CancelButton_Click);
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(185, 245);
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(120, 20);
this.numericUpDown1.TabIndex = 15;
//
// errorProvider1
//
this.errorProvider1.ContainerControl = this;
//
// Reflection
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(416, 406);
this.Controls.Add(this.numericUpDown1);
this.Controls.Add(this.CancelButton);
this.Controls.Add(this.RetrieveButton);
this.Controls.Add(this.SaveButton);
this.Controls.Add(this.textEmailId);
this.Controls.Add(this.Emaillabel);
this.Controls.Add(this.textPercentage);
this.Controls.Add(this.Percentagelabel);
this.Controls.Add(this.textLastDegree);
this.Controls.Add(this.Institutelabel);
this.Controls.Add(this.textInstituteName);
this.Controls.Add(this.Instituelabel);
this.Controls.Add(this.textFathersName);
this.Controls.Add(this.FNamelabel);
this.Controls.Add(this.textStudentName);
this.Controls.Add(this.Namelabel);
this.Name = "Reflection";
this.Text = "Student-Information";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label Namelabel;
private System.Windows.Forms.TextBox textStudentName;
private System.Windows.Forms.Label FNamelabel;
private System.Windows.Forms.TextBox textFathersName;
private System.Windows.Forms.Label Instituelabel;
private System.Windows.Forms.TextBox textInstituteName;
private System.Windows.Forms.Label Institutelabel;
private System.Windows.Forms.TextBox textLastDegree;
private System.Windows.Forms.Label Percentagelabel;
private System.Windows.Forms.TextBox textPercentage;
private System.Windows.Forms.Label Emaillabel;
private System.Windows.Forms.TextBox textEmailId;
private System.Windows.Forms.Button SaveButton;
private System.Windows.Forms.Button RetrieveButton;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.Button CancelButton;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.ErrorProvider errorProvider1;
}
}

/*settings.cs*/
/*This class contains how to create a xml file how data can store in xml file and how can we extract*/

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.Drawing;
using System.Reflection;
using System.Xml.Serialization;


namespace ReflectionExample
{
#region - public abstract class:XmlSerializable -

public class XmlSerializable
{
#region - public virtual void:Save(string path) -

public virtual void Save(string path)
{
StreamWriter objStreamWriter = new StreamWriter(path);
XmlSerializer objXmlSerializer = new XmlSerializer(this.GetType());
objXmlSerializer.Serialize(objStreamWriter, this);
objStreamWriter.Close();
}

#endregion

#region - public virtual void: Load(string path) -

public virtual void Load(string path)
{
if (File.Exists(path))
{
StreamReader objStreamReader = new StreamReader(path);
XmlTextReader objXmlTextReader = new XmlTextReader(objStreamReader);
XmlSerializer objXmlSerializer = new XmlSerializer(this.GetType());
object obj;
if (objXmlSerializer.CanDeserialize(objXmlTextReader))
{
obj = objXmlSerializer.Deserialize(objXmlTextReader);
Type objType = this.GetType();
PropertyInfo[] properties = objType.GetProperties();
foreach (PropertyInfo objProperty in properties)
{
objProperty.SetValue(this, objProperty.GetValue(obj, null), null);
}
}
objXmlTextReader.Close();
objStreamReader.Close();
}
}

#endregion
}
#endregion

public class Settings : XmlSerializable
{

[XmlIgnore()]
public string StudentName
{
get { return _StudentName; }
set { _StudentName = value; }
}
private string _StudentName = string.Empty;

[XmlElement("StudentName")]
public string XmlStudentName
{
get { return _StudentName; }
set { _StudentName = value; }
}

[XmlIgnore()]
public string FatherName
{
get { return _FatherName; }
set { _FatherName = value; }
}
private string _FatherName = string.Empty;

[XmlElement("FatherName")]
public string XmlFatherName
{
get { return _FatherName; }
set { _FatherName = value; }
}
[XmlIgnore()]
public string Institute
{
get { return _Institute; }
set { _Institute = value; }
}
private string _Institute =string.Empty;
[XmlElement("Institute")]
public string XmlInstitute
{
get { return _Institute; }
set { _Institute = value; }
}
[XmlIgnore()]
public string LastDegree
{
get { return _LastDegree; }
set { _LastDegree = value; }
}
private string _LastDegree = string.Empty;
[XmlElement("LastDegree")]
public string XmlLastDegree
{
get { return _LastDegree; }
set { _LastDegree = value; }
}
[XmlIgnore()]
public string Percentage
{
get { return _Percentage; }
set { _Percentage = value; }
}
private string _Percentage = string.Empty;
[XmlElement("Percentage")]
public string XmlPercentage
{
get { return _Percentage; }
set { _Percentage = value; }
}
[XmlIgnore()]
public string EmailId
{
get { return _EmailId; }
set { _EmailId = value; }
}
private string _EmailId = string.Empty;
[XmlElement("EmailId")]
public string XmlEmailId
{
get { return _EmailId; }
set { _EmailId = value; }
}
}

}

/*Constants.cs*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace ReflectionExample
{
class Constants
{
internal const string EmailError = "Email Id is not valid!!";
internal const string Error1 = "Error";
internal const string PercentageError = "Percentage must be less than 100!!";
internal const string PercentageRegularExpression=@"[^0-9]";
internal const string EmailIdRegularExpression = @"^[a-zA-Z0-9_\-\.]+@([\w-]+\.)+[\w-]+$";

}
}
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Sudoku-Checker in ASP.Net using C#

 Unknown     2:49 AM     No comments   

# region directives

using System;
using System.Collections;

#endregion


namespace sudokuChecker
{

class SudokuMainExample
{
static void Main()
{
SudokuCheck objectSudokuCheck = new SudokuCheck();
int[,] Board=new int[9,9];
int countnumberofInput=0;
string menuStatus="y";
string readInput="n";

try
{
Console.WriteLine("You Are Entering In Sudoku Checker:----");
for (int indexRow = 0; indexRow < 9; indexRow++)
{
for (int indexColumn = 0; indexColumn < 9; indexColumn++)
{
Board[indexRow, indexColumn] = 0;
}

}

do
{
/*try
{
Console.WriteLine("PLease Enter The Size of Row To Start The Game:--");
int row = Int32.Parse(Console.ReadLine());
Console.WriteLine("Lease Enter The Size of Row To Start The Game:--");
int column = Int32.Parse(Console.ReadLine());
if ((row != 9) && (column != 9))
throw new Exception("error");
else
Board = new int[row, column];
for (int indexRow = 0; indexRow < row; indexRow++)
{
for (int indexColumn = 0; indexColumn < column; indexColumn++)
{
Board[indexRow, indexColumn] = 0;
}

}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Your Input Is Not Valid Please Input A Right One ");
Console.WriteLine("If You Want To Input It Again then press :-Y otherwise Press N .");
readInput = (Console.ReadLine());
}*/
while ((menuStatus == "Y") || (menuStatus == "y"))
{
Console.WriteLine("You Have Some Choices:--");
Console.WriteLine("Press:-1 To Give Input In Sudoku Game:-");
Console.WriteLine("Press:-2 To Check Status");
Console.WriteLine("Press:-3 To Put Default Right Values:-");
Console.WriteLine("Press:-4 To Put Default Wrong Values:-");
Console.WriteLine("Press:-5 To Exit From The Menu Status:-");
int readChoice = Int32.Parse(Console.ReadLine());
switch (readChoice)
{
case 1:
int choiceCheck = 0;
while (choiceCheck != 1)
{
Console.WriteLine("Please Input A Row Number Where You Want To Put The Input");
int inputRow = Int32.Parse(Console.ReadLine());
Console.WriteLine("Please Input A Column Number Where You Want to Put The Input");
int inputColumn = Int32.Parse(Console.ReadLine());
Console.WriteLine("Please Input The Value You Want To Fill In This Particular Space");
int inputValue = Int32.Parse(Console.ReadLine());
if ((inputValue > 9) || (inputValue < 1))
{
Console.WriteLine("You Input Value Is Not Valid Please Input A Valid Value");
choiceCheck = 0;
}
else
{
choiceCheck = 1;
if (countnumberofInput != 81)
{
countnumberofInput++;
objectSudokuCheck.UserInputSudoku(inputRow, inputColumn, inputValue,Board);
}
else
{
Console.WriteLine("Board Has Already Filled");
Console.WriteLine("Now Check The status of Sudoku Game.");
}
}
}
Console.WriteLine("If You Again Want To Go To The Main menu Then Press Y To Continue Otherwise Press Any Button");
menuStatus = Console.ReadLine();
break;
case 2:
Console.WriteLine("We Are Going To Check the Status Of Sudoku Game");
SudokuCheck.Status obj= objectSudokuCheck.CheckSudokuStatus(Board);
Console.WriteLine(obj);
Console.WriteLine("If You Again Want To Go To The Main menu Then Press Y To Continue Otherwise Press Any Button");
menuStatus = Console.ReadLine();
break;
case 3:
Console.WriteLine("We Are Going To Put Default Right Values");
objectSudokuCheck.InputDefaultRightValues(Board);
Console.WriteLine("If You Again Want To Go To The Main menu Then Press Y To Continue Otherwise Press Any Button");
menuStatus = Console.ReadLine();
break;
case 4:
Console.WriteLine("We Are Going To Put Default Wrong Values");
objectSudokuCheck.InputDefaultWrongValues(Board);
Console.WriteLine("If You Again Want To Go To The Main menu Then Press Y To Continue Otherwise Press Any Button");
menuStatus = Console.ReadLine();
break;
case 5:
Console.WriteLine("We Are Exiting From The Program");
menuStatus = "N";
Console.WriteLine("If You Want To Input It Again then press :-Y otherwise Press N .");
readInput = (Console.ReadLine());
break;
default:
Console.WriteLine("Invalid Choice");
break;
}
}


} while (readInput == "y");
}
catch (Exception e)
{
Console.WriteLine("Your Input Is Not Valid:--");
Console.WriteLine("Do You Wanna Input It Again:--");
Console.ReadKey();
}
}
}
}



using System;
using System.Collections;

namespace sudokuChecker
{
class SudokuCheck
{
public enum Status
{
Success = 0,
Failure = 1,
Continue = 2
}
public void UserInputSudoku(int inputRow, int inputColumn, int inputValue,int [,]Board)
{
Board[inputRow,inputColumn] = inputValue;
}
public void InputDefaultWrongValues(int[,] Board)
{
Board[0, 0] = 9; Board[0, 1] = 6; Board[0, 2] = 1; Board[0, 3] = 1;
Board[0, 4] = 4; Board[0, 5] = 8; Board[0, 6] = 2; Board[0, 7] = 7;
Board[0, 8] = 3; Board[1, 0] = 8; Board[1, 1] = 7; Board[1, 2] = 2;
Board[1, 3] = 9; Board[1, 4] = 3; Board[1, 5] = 1; Board[1, 6] = 6;
Board[1, 7] = 4; Board[1, 8] = 5; Board[2, 0] = 6; Board[2, 1] = 5;
Board[2, 2] = 3; Board[2, 3] = 3; Board[2, 4] = 2; Board[2, 5] = 7;
Board[2, 6] = 8; Board[2, 7] = 9; Board[2, 8] = 1; Board[3, 0] = 5;
Board[3, 1] = 8; Board[3, 2] = 9; Board[3, 3] = 3; Board[3, 4] = 2;
Board[3, 5] = 2; Board[3, 6] = 1; Board[3, 7] = 6; Board[3, 8] = 7;
Board[4, 0] = 2; Board[4, 1] = 8; Board[4, 2] = 6; Board[4, 3] = 7;
Board[4, 4] = 1; Board[4, 5] = 5; Board[4, 6] = 4; Board[4, 7] = 3;
Board[4, 8] = 9; Board[5, 0] = 1; Board[5, 1] = 3; Board[5, 2] = 7;
Board[5, 3] = 4; Board[5, 4] = 9; Board[5, 5] = 6; Board[5, 6] = 5;
Board[5, 7] = 8; Board[5, 8] = 2; Board[6, 0] = 6; Board[6, 1] = 9;
Board[6, 2] = 4; Board[6, 3] = 1; Board[6, 4] = 5; Board[6, 5] = 3;
Board[6, 6] = 7; Board[6, 7] = 2; Board[6, 8] = 8; Board[7, 0] = 3;
Board[7, 1] = 2; Board[7, 2] = 5; Board[7, 3] = 8; Board[7, 4] = 7;
Board[7, 5] = 4; Board[7, 6] = 9; Board[7, 7] = 1; Board[7, 8] = 6;
Board[8, 0] = 7; Board[8, 1] = 1; Board[8, 2] = 8; Board[8, 3] = 2;
Board[8, 4] = 6; Board[8, 5] = 5; Board[8, 6] = 7; Board[8, 7] = 5;
Board[8, 8] = 4;
}
public void InputDefaultRightValues(int[,] Board)
{

Board[0,0]=9;Board[0,1]=6;Board[0,2]=1;Board[0,3]=5;
Board[0,4]=4;Board[0,5]=8;Board[0,6]=2;Board[0,7]=7;
Board[0,8]=3;Board[1,0]=8;Board[1,1]=7;Board[1,2]=2;
Board[1,3]=9;Board[1,4]=3;Board[1,5]=1;Board[1,6]=6;
Board[1,7]=4;Board[1,8]=5;Board[2,0]=4;Board[2,1]=5;
Board[2,2]=3;Board[2,3]=6;Board[2,4]=2;Board[2,5]=7;
Board[2,6]=8;Board[2,7]=9;Board[2,8]=1;Board[3,0]=5;
Board[3,1]=4;Board[3,2]=9;Board[3,3]=3;Board[3,4]=8;
Board[3,5]=2;Board[3,6]=1;Board[3,7]=6;Board[3,8]=7;
Board[4,0]=2;Board[4,1]=8;Board[4,2]=6;Board[4,3]=7;
Board[4,4]=1;Board[4,5]=5;Board[4,6]=4;Board[4,7]=3;
Board[4,8]=9;Board[5,0]=1;Board[5,1]=3;Board[5,2]=7;
Board[5,3]=4;Board[5,4]=9;Board[5,5]=6;Board[5,6]=5;
Board[5,7]=8;Board[5,8]=2;Board[6,0]=6;Board[6,1]=9;
Board[6,2]=4;Board[6,3]=1;Board[6,4]=5;Board[6,5]=3;
Board[6,6]=7;Board[6,7]=2;Board[6,8]=8;Board[7,0]=3;
Board[7,1]=2;Board[7,2]=5;Board[7,3]=8;Board[7,4]=7;
Board[7,5]=4;Board[7,6]=9;Board[7,7]=1;Board[7,8]=6;
Board[8,0]=7;Board[8,1]=1;Board[8,2]=8;Board[8,3]=2;
Board[8,4]=6;Board[8,5]=9;Board[8,6]=3;Board[8,7]=5;
Board[8,8]=4;

}

public Status CheckSudokuStatus(int[,] Board)
{
int flag = 0;
for (int rowCheck = 0; rowCheck < 9; rowCheck++)
{
flag = 0;
for (int columnCheck = 0; columnCheck < 9; columnCheck++)
{
if (Board[rowCheck, columnCheck] == 0)
continue;

if ((flag & (1 << Board[rowCheck, columnCheck])) != 0)
return Status.Failure;
flag |= (1 << Board[rowCheck, columnCheck]);
}
}
for (int columnCheck = 0; columnCheck < 9; columnCheck++)
{
flag = 0;
for (int rowCheck = 0; rowCheck < 9; rowCheck++)
{
if (Board[rowCheck, columnCheck] == 0)
continue;
if (((flag & (1 << Board[rowCheck, columnCheck])) != 0))
return Status.Failure;
flag |= (1 << Board[rowCheck, columnCheck]);
}
}
for (int rowCheck = 0; rowCheck < 3; rowCheck++)
{
for (int columnCheck = 0; columnCheck < 3; columnCheck++)
{
BoxCheck(Board, rowCheck* 3, columnCheck * 3);

}
}

return Status.Success;

}
private Status BoxCheck(int[,] Board, int Row, int Coloumn)
{
ArrayList ArrElementsCompare = new ArrayList();
ArrElementsCompare.Clear();
for (int rowIndex = Row; rowIndex < Row + 3; rowIndex++)
{
for (int columnIndex = Coloumn; columnIndex < Coloumn + 3; columnIndex++)
{
if (Board[rowIndex, columnIndex] == 0)
continue;
if (ArrElementsCompare.Contains(Board[rowIndex, columnIndex]))
return Status.Failure;
ArrElementsCompare.Add(Board[rowIndex, columnIndex]);
}
}
return Status.Success;
}

}
}
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Posts Home

About The Author

Unknown
View my complete profile

Total Pageviews

Popular Posts

  • Predicate delegate in C#
    Hello Everyone, In the article we will talk about Predicate delegate. Predicate is also a delegate which encapsulate a method that takes...
  • Clr - Common Language Runtime
    .Net framework provides a run time environment - CLR. Common language runtime takes the IL code from the compiler( language specific) and p...
  • Auto logout chrome extension for Gmail
    Hello Friends, In the last article we learned to create a sample chrome extension. Here we are going to create auto logout Gmail script as...
  • Nagarro Placement Papers..
    Ques.1 :- Seat Reservation prog for the theatre. Write a function for seat allocation for the movie tickets. Total no of seats available are...
  • What does it mean by disconnected data access architecture of ADO.Net?
    ADO.Net introduces the concept of disconnected data architecture. In traditional data access components, you make a connection to the databa...
  • .Net Framework overview
    Hello friends : Here i am writing my first article on .Net framework anyways....So the question is What is .Net Framework ? The .Net fram...
  • Calling the Delegates using Invoke(), BeginInvoke() and DynamicInvoke() ?
    Hello Guys, So in the last article we talked about What is delegate and how can we create a delegate. In this article we will discuss w...
  • C code to Check the string has valid identifier or not in.
    #include #include #include char keyword[][10]={"auto","break","case","char","const","...
  • Garbage Collection - Automatic memory management
    While thinking of this question few things are coming in my mind ~ How .Net reclaims objects and memory used by an application ? So the ans...
  • How to convert 3d array to 1d array ?
    Suppose you have to insert a value at (2,1,0) and the value is :-5 means firstly you have to find the index through (2,1,0) then you have to...

Blog Archive

  • ►  2016 (4)
    • ►  September (2)
      • ►  Sep 03 (2)
    • ►  August (1)
      • ►  Aug 28 (1)
    • ►  April (1)
      • ►  Apr 24 (1)
  • ►  2015 (12)
    • ►  September (10)
      • ►  Sep 30 (1)
      • ►  Sep 29 (1)
      • ►  Sep 28 (1)
      • ►  Sep 27 (2)
      • ►  Sep 26 (3)
      • ►  Sep 20 (1)
      • ►  Sep 19 (1)
    • ►  August (1)
      • ►  Aug 16 (1)
    • ►  March (1)
      • ►  Mar 31 (1)
  • ►  2013 (10)
    • ►  June (1)
      • ►  Jun 16 (1)
    • ►  April (1)
      • ►  Apr 21 (1)
    • ►  February (8)
      • ►  Feb 18 (3)
      • ►  Feb 17 (2)
      • ►  Feb 16 (2)
      • ►  Feb 15 (1)
  • ►  2012 (1)
    • ►  May (1)
      • ►  May 27 (1)
  • ►  2010 (22)
    • ►  October (14)
      • ►  Oct 21 (1)
      • ►  Oct 06 (12)
      • ►  Oct 04 (1)
    • ►  April (2)
      • ►  Apr 22 (1)
      • ►  Apr 16 (1)
    • ►  March (1)
      • ►  Mar 30 (1)
    • ►  January (5)
      • ►  Jan 08 (3)
      • ►  Jan 01 (2)
  • ▼  2009 (110)
    • ►  December (8)
      • ►  Dec 18 (2)
      • ►  Dec 05 (1)
      • ►  Dec 04 (5)
    • ►  November (1)
      • ►  Nov 27 (1)
    • ►  October (14)
      • ►  Oct 09 (4)
      • ►  Oct 07 (1)
      • ►  Oct 06 (3)
      • ►  Oct 05 (3)
      • ►  Oct 01 (3)
    • ►  September (17)
      • ►  Sep 30 (1)
      • ►  Sep 29 (1)
      • ►  Sep 28 (1)
      • ►  Sep 25 (1)
      • ►  Sep 24 (1)
      • ►  Sep 17 (2)
      • ►  Sep 15 (3)
      • ►  Sep 11 (2)
      • ►  Sep 09 (3)
      • ►  Sep 08 (2)
    • ►  August (31)
      • ►  Aug 31 (1)
      • ►  Aug 27 (3)
      • ►  Aug 26 (1)
      • ►  Aug 25 (2)
      • ►  Aug 24 (1)
      • ►  Aug 22 (2)
      • ►  Aug 21 (3)
      • ►  Aug 20 (2)
      • ►  Aug 19 (3)
      • ►  Aug 18 (1)
      • ►  Aug 16 (1)
      • ►  Aug 12 (2)
      • ►  Aug 11 (1)
      • ►  Aug 10 (3)
      • ►  Aug 07 (4)
      • ►  Aug 06 (1)
    • ►  July (24)
      • ►  Jul 25 (4)
      • ►  Jul 24 (20)
    • ▼  April (15)
      • ►  Apr 10 (3)
      • ►  Apr 07 (9)
      • ▼  Apr 06 (3)
        • How to: Read Image Metadata
        • How to store a record in xml file from a windows f...
        • Sudoku-Checker in ASP.Net using C#

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments
copyright @ TechGiant 2015. Powered by Blogger.

Disclaimer

This is my personal blog and i write articles on .Net, WPF, C#, OOPS, Threading and other .Net technologies. This is not related to any of my employer and organizations. This is the result of my personal interest.

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Followers

Copyright © A Developer Journey who codes for fun | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com