using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using MySql.Data.MySqlClient;

using System.Windows.Forms;


namespace WindowsFormsApp17

{

    public partial class LoginForm : Form

    {

        private MySqlConnection con = new MySqlConnection();

        public LoginForm()

        {

            InitializeComponent();

            con.ConnectionString = @"server=localhost;database=user_info;userid=root;password=;";

        }


        private void button1_Click(object sender, EventArgs e)

        {

            MySqlCommand cmd;

            MySqlDataReader dr;

            try

            {


                con.Open();

                cmd = new MySqlCommand();

                cmd.Connection = con;

                cmd.CommandText = "SELECT * FROM login_tb WHERE UserName='" + textBox1.Text + "' AND Password='" + textBox2.Text + "' ";

                dr = cmd.ExecuteReader();

                if (dr.Read())

                {

                    MessageBox.Show("Success");

                    this.Hide();

                    MainForm mf = new MainForm();

                    mf.ShowDialog();

                }

                else

                {

                    MessageBox.Show("If You are Admin,Please Enter the correct username and password");

                }

                


            }

            finally

            {

                if (con != null)

                {

                    con.Close();

                }

            }




        }


        private void LoginForm_Load(object sender, EventArgs e)

        {

            //con.Open();

            //if (con.State == ConnectionState.Open)

            //{

            //    MessageBox.Show("Sucessfull DB Connection ");

            //    con.Close();

            //}

        }

    }

}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp17
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void label5_Click(object sender, EventArgs e)
        {
            this.Hide();
            LoginForm Lf = new LoginForm();
            Lf.ShowDialog();
        }

        private void panel3_Paint(object sender, PaintEventArgs e)
        {
            
        }

        private void label8_Click(object sender, EventArgs e)
        {
            this.Hide();
            RegistrationForm Rf = new RegistrationForm();
            Rf.ShowDialog();
            Rf = null;
            this.Show();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            label2.Text = DateTime.Now.ToLongDateString();
            label3.Text = DateTime.Now.ToLongTimeString();
        }

        private void pictureBox7_Click(object sender, EventArgs e)
        {
            this.Hide();
            LoginForm Lf = new LoginForm();
            Lf.ShowDialog();
        }

        private void label4_Click(object sender, EventArgs e)
        {
            this.Hide();
            ScanForm Sf = new ScanForm();
            Sf.ShowDialog();
            Sf = null;
            this.Show();
        }

        private void label10_Click(object sender, EventArgs e)
        {
            this.Hide();
            attendanceForm Attf = new attendanceForm();
            Attf.ShowDialog();
            Attf = null;
            this.Show();
        }

        private void label9_Click(object sender, EventArgs e)
        {
            this.Hide();
            StudentInfo Stinfo = new StudentInfo();
            Stinfo.ShowDialog();
            Stinfo = null;
            this.Show();
        }
    }
}


using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp17
{
    public partial class RegistrationForm : Form
    {
        private MySqlConnection con = new MySqlConnection();
        public RegistrationForm()
        {
            InitializeComponent();
            con.ConnectionString = @"server=localhost;database=user_info;userid=root;password=;";
        }
        string Gender;
        private void picturebox_btn_Click(object sender, EventArgs e)
        {
            OpenFileDialog fd = new OpenFileDialog();
            if (fd.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Image = Image.FromFile(fd.FileName);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            QRCoder.QRCodeGenerator QG = new QRCoder.QRCodeGenerator();
            var MyData = QG.CreateQrCode(ID_text.Text, QRCoder.QRCodeGenerator.ECCLevel.H);
            var code = new QRCoder.QRCode(MyData);
            pictureBox2.Image = code.GetGraphic(100);

            try
            {
                MemoryStream ms = new MemoryStream();
                //pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
                //byte[] Photo = ms.ToArray();
                pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] Photo = new byte[ms.Length];
                ms.Position = 0;
                ms.Read(Photo, 0, Photo.Length);
                con.Open();
                MySqlCommand coman = new MySqlCommand();
                coman.Connection = con;
                coman.CommandText = "insert into registration_tb (ID,Name,FatherName,EmailAddress,DateOfBirth,Class,PhoneNumber,Gender,Photo) values('" + ID_text.Text + " ', ' " + Name_text.Text + " ',' " + Fname_text.Text + " ',' " + Email_text.Text + " ','" + dateTime_text.Text + "','" + Class_text.Text + "','" + Phone_text.Text + "','" + Gender + "',@photo)";
                coman.Parameters.AddWithValue("@photo", Photo);
                coman.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("Data Save Successfull !");
                ID_text.Clear();
                Name_text.Clear();
                Fname_text.Clear();
                Email_text.Clear();
                Class_text.Clear();
                Phone_text.Clear();
                pictureBox1.Image = null;
                //loadbtn_Click(null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex);
            }

            string initialDIR = @"C:\Users\acer\Desktop\QRfiles";
            var dialog = new SaveFileDialog();
            dialog.InitialDirectory = initialDIR;
            dialog.Filter = "PNG|*.png|JPEG|*.jpg|BMP|*.bmp|GIF|*.gif";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                pictureBox2.Image.Save(dialog.FileName);
            }
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            Gender = "Male";
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            Gender = "Female";
        }

        

        private void RegistrationForm_Load(object sender, EventArgs e)
        {
            
        }
    }
}




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AForge;
using AForge.Video;
using AForge.Video.DirectShow;
using ZXing;
using ZXing.Aztec;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.IO;

namespace WindowsFormsApp17
{
    public partial class ScanForm : Form
    {
        private MySqlConnection con = new MySqlConnection();
        private FilterInfoCollection CaptureDevice;
        private VideoCaptureDevice FinalFrame;
        public ScanForm()
        {
            InitializeComponent();
            con.ConnectionString = @"server=localhost;database=user_info;userid=root;password=;";
        }
        string Gender;
        private void ScanForm_Load(object sender, EventArgs e)
        {
            CaptureDevice = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            foreach (FilterInfo Device in CaptureDevice)
                comboBox1.Items.Add(Device.Name);

            comboBox1.SelectedIndex = 2;
            FinalFrame = new VideoCaptureDevice();
            //Date and Time
            label2.Text = DateTime.Now.ToLongDateString();
            time_text.Text = DateTime.Now.ToLongTimeString();

        }
        private void button2_Click(object sender, EventArgs e)
        {
            FinalFrame = new VideoCaptureDevice(CaptureDevice[comboBox1.SelectedIndex].MonikerString);
            FinalFrame.NewFrame += new NewFrameEventHandler(FinalFrame_NewFrame);
            FinalFrame.Start();
        }
        private void FinalFrame_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            pictureBox2.Image = (Bitmap)eventArgs.Frame.Clone();
        }

        private void ScanForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (FinalFrame.IsRunning == true)
                FinalFrame.Stop();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            BarcodeReader reader = new BarcodeReader();
            Result result = reader.Decode((Bitmap)pictureBox2.Image);
            try
            {
                string decoded = result.ToString().Trim();
                ID_text.Text = decoded;
                if (decoded != null)
                {
                    con.Open();
                    MySqlCommand coman = new MySqlCommand();
                    coman.Connection = con;
                    coman.CommandText = "select * from  registration_tb  where ID Like'%" + ID_text.Text + "%'";
                    MySqlDataReader dr = coman.ExecuteReader();
                    dr.Read();
                    if (dr.HasRows)
                    {
                        Name_text.Text = dr["Name"].ToString();
                        Fname_text.Text = dr["FatherName"].ToString();
                        Email_text.Text = dr["EmailAddress"].ToString();
                        Dateofbirth_text.Text = dr["DateOfBirth"].ToString();
                        Class_text.Text = dr["Class"].ToString();
                        Phone_text.Text = dr["PhoneNumber"].ToString();
                        gender_text.Text = dr["Gender"].ToString();
                        byte[] img = ((byte[])dr["Photo"]);
                        MemoryStream ms = new MemoryStream(img);
                        pictureBox1.Image = Image.FromStream(ms);


                    }

                    con.Close();
                    timer2.Start();
                    //MessageBox.Show("Data Save Successfull !");
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show("Error " + ex);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }

        

        private void Name_text_TextChanged(object sender, EventArgs e)
        {
            //try


            //{
            //    if (Name_text.Text.Length > 0)

            //    {
            //       // MessageBox.Show("OK");
            //        MemoryStream ms = new MemoryStream();
            //        pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            //        byte[] Photo = new byte[ms.Length];
            //        ms.Position = 0;
            //        ms.Read(Photo, 0, Photo.Length);
                                       
            //        con.Open();
            //        MySqlCommand coman = new MySqlCommand();
            //        coman.Connection = con;
            //        coman.CommandText = "insert into attendance_tbl (ID,Name,FatherName,EmailAddress,DateOfBirth,Class,PhoneNumber,Gender,InTime,Photo) values('" + ID_text.Text + " ', ' " + Name_text.Text + " ',' " + Fname_text.Text + " ',' " + Email_text.Text + " ','" + Dateofbirth_text.Text + "','" + Class_text.Text + "','" + Phone_text.Text + "','" + gender_text + "','"+time_text.Text+"',@photo)";
            //        coman.Parameters.AddWithValue("@photo", Photo);
            //        coman.ExecuteNonQuery();
            //        con.Close();
            //        MessageBox.Show("Data Save Successfull !");
                                   
                    
                    
            //    }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show("Error " + ex);
            //}

        }

        private void gender_text_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            try
            {
                //MessageBox.Show("OK");
                MemoryStream ms = new MemoryStream();
                pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] Photo = new byte[ms.Length];
                ms.Position = 0;
                ms.Read(Photo, 0, Photo.Length);

                con.Open();
                MySqlCommand coman = new MySqlCommand();
                coman.Connection = con;
                coman.CommandText = "insert into attendance_tbl (ID,Name,FatherName,EmailAddress,DateOfBirth,Class,PhoneNumber,Gender,InTime,Photo) values('" + ID_text.Text + " ', ' " + Name_text.Text + " ',' " + Fname_text.Text + " ',' " + Email_text.Text + " ','" + Dateofbirth_text.Text + "','" + Class_text.Text + "','" + Phone_text.Text + "','" + gender_text.Text + "','" + time_text.Text + "',@photo)";
                coman.Parameters.AddWithValue("@photo", Photo);
                coman.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("Data Save Successfull !");
            }
            catch (Exception ex)
            {

            }
        }
    }
}

                      
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp17
{
    public partial class attendanceForm : Form
    {
        private MySqlConnection con = new MySqlConnection();
        
        public attendanceForm()
        {
            InitializeComponent();
            con.ConnectionString = @"server=localhost;database=user_info;userid=root;password=;";
        }

        private void attendanceForm_Load(object sender, EventArgs e)
        {
            try
            {
                con.Open();
                MySqlCommand coman = new MySqlCommand();
                coman.Connection = con;
                string query = "select * from registration_tb ";
                coman.CommandText = query;
                MySqlDataAdapter da = new MySqlDataAdapter(coman);
                DataTable dt = new DataTable();
                da.Fill(dt);
                dataGridView1.DataSource = dt;
                con.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex);
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
                ID_text.Text = row.Cells["ID"].Value.ToString();
                Name_text.Text = row.Cells["Name"].Value.ToString();
                Fname_text.Text = row.Cells["FatherName"].Value.ToString();
                Email_text.Text = row.Cells["EmailAddress"].Value.ToString();
                Dateofbirth_text.Text = row.Cells["DateOfBirth"].Value.ToString();
                Class_text.Text = row.Cells["Class"].Value.ToString();
                Phone_text.Text = row.Cells["PhoneNumber"].Value.ToString();
                gender_text.Text = row.Cells["Gender"].Value.ToString();
                
                //image display
                byte[] bytes = (byte[])dataGridView1.CurrentRow.Cells["Photo"].Value;
                MemoryStream ms = new MemoryStream(bytes);
                pictureBox1.Image = Image.FromStream(ms);
                


            }
        }

        
    }
}



using DGVPrinterHelper;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp17
{
    public partial class StudentInfo : Form
    {
        private MySqlConnection con = new MySqlConnection();
        //private object stringformatflags;

        public StudentInfo()
        {
            InitializeComponent();
            con.ConnectionString = @"server=localhost;database=user_info;userid=root;password=;";
        }

        private void StudentInfo_Load(object sender, EventArgs e)
        {
            //Show Data on datagridview from database 
            try
            {
                con.Open();
                MySqlCommand coman = new MySqlCommand();
                coman.Connection = con;
                string query = "select * from attendance_tbl";
                coman.CommandText = query;
                MySqlDataAdapter da = new MySqlDataAdapter(coman);
                DataTable dt = new DataTable();
                da.Fill(dt);
                dataGridView1.DataSource = dt;
                con.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex);
            }
        }

        

        private void button1_Click(object sender, EventArgs e)
        {
            DGVPrinter printer = new DGVPrinter();
            printer.Title = "STUDENT ATTENDANCE SYSTEM REPROT FORM";
            printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
            printer.PageNumbers = true;
            printer.PageNumberInHeader = false;
            printer.PorportionalColumns = true;
            printer.HeaderCellAlignment = StringAlignment.Near;
            printer.Footer = "Footer";
            printer.FooterSpacing = 15;
            printer.printDocument.DefaultPageSettings.Landscape = true;
            printer.PrintDataGridView(dataGridView1);
            
        }
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {

        }
        
    }
}










Comments

Popular posts from this blog

C# Full Project Tutorial (Coffee Shop Management System) With source code and MySql database