Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
////////////////////////////////dataGridview not generated
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;

namespace ROEAS

{
    public partial class Attendance : Form
    {
        
        SqlDataAdapter dap;
        DataTable dt;
       
        string a;//Here shows a error 
        string b;


        public Attendance()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          //  d1.ConOpen();
          //  dt = d1.DisplayGrid("select emp_code,name,department from employee");
            dataGridView1.DataSource = dt;
          //  d1.ConClose();
            generate();
            //data();
            int t;
            for (t = 0; t <= dataGridView1.Columns.Count - 1; t++)
            {
                dataGridView1.Columns[t].SortMode = DataGridViewColumnSortMode.NotSortable;
                dataGridView1.Columns[t].ReadOnly = true;
                dataGridView1.Columns[t].DefaultCellStyle.BackColor = Color.White;
            }

            data();


        }

        private void Button3_Click(object sender, EventArgs e)
        {
          //  d1.ConOpen();
            int t;
            DateTime d;

            d = DateTime.Parse(a);
            string s = d.Month + "-" + d.Day + "-" + d.Year;

            for (t = 0; t <= dataGridView1.Rows.Count - 1; t++)
            {
                //d1.Delete("delete from attendence where no=" + dataGridView1.Rows[t].Cells["emp_code"].Value.ToString() + " and convert(varchar,d,101)='" + d.ToString() + "'");
            }

            for (t = 0; t <= dataGridView1.Rows.Count - 1; t++)
            {
           //     d1.Insert("Insert into attendance (att_date,emp_code,is_present) values('" + s + "'," + dataGridView1.Rows[t].Cells["emp_code"].Value.ToString() + "," + "1" + ")");
            }


            MessageBox.Show("Complate Fill Attendence");
           // d1.ConClose();


        }

        private void button1_Click(object sender, EventArgs e)
        {

        }


        public void data()
        {
            //d1.ConOpen();
            int t;
            int u;
            //DateTime dt1 ;
            string dt1 = "";
            for (u = 3; u <= dataGridView1.Columns.Count - 5; u++)
            {
                dt1 = DateTime.Parse(dataGridView1.Columns[u].HeaderText).ToShortDateString();

                DataTable dt = new DataTable();
              //  dt = d1.DisplayGrid("select * from attendence where convert(varchar,d,101)='" + dt1.ToString() + "'");



                if (dt.Rows.Count > 0)
                {
                    for (t = 0; t < dt.Columns.Count; t++)
                    {

                        if (dt.Rows[t]["status"].ToString() != "True")
                        {
                            dataGridView1.Rows[t].Cells[u].Value = true;
                        }
                        else
                        {
                            dataGridView1.Rows[t].Cells[u].Value = false;
                        }
                    }
                }

            }

            //d1.ConClose();
            //return 0;
        }


        public void generate()
        {
            DateTime i;
            DateTime j;
     
        
            int[] a = new int[4];

            DataTable dt1=new DataTable();

          //  dt1 = d1.DisplayGrid("select convert(varchar,SDate,101) ,convert(varchar,EDate,101) from semester");
            i = DateTime.Parse(dt1.Rows[0][0].ToString());
            j = DateTime.Parse(dt1.Rows[0][1].ToString());




            while (i.CompareTo(j) != 0)
            {




                DataGridViewCheckBoxColumn dg = new DataGridViewCheckBoxColumn();
                dg.HeaderText = i.Day + "/" + i.Month + "/" + i.Year;
                dg.Width = 30;
                dataGridView1.Columns.Add(dg);
                i = i.Date.AddDays(1);
            }
            dataGridView1.Columns.Add("Total", "Total");
        }





        private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
        {
            int t;
            for (t = 0; t <= 1; t++)
            {
                dataGridView1.Columns[t].Frozen = true;
            }
        }

        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            int i;
            int u;
            int k;

            for (i = 0; i <= dataGridView1.Rows.Count - 1; i++)
            {
                k = 0;
                for (u = 3; u <= dataGridView1.Columns.Count - 5; u++)
                {
                    if (dataGridView1.Rows[i].Cells[u].Value != null)
                    {
                        k = k + 1;
                    }
                }
                if (k == 0)
                {
                    dataGridView1.Rows[i].Cells["Total"].Value = 0;
                }
                else
                {
                    dataGridView1.Rows[i].Cells["Total"].Value = k;
                }

            }
        }

        private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            a = dataGridView1.Columns[e.ColumnIndex].HeaderText;
            b = e.ColumnIndex.ToString();
            int t;

            for (t = 0; t <= dataGridView1.Columns.Count - 2; t++)
            {
                if (dataGridView1.Columns[t].HeaderText == dataGridView1.Columns[e.ColumnIndex].HeaderText)
                {
                    dataGridView1.Columns[t].ReadOnly = false;
                    dataGridView1.Columns[t].DefaultCellStyle.BackColor = Color.DarkTurquoise;
                }
                else
                {
                    dataGridView1.Columns[t].ReadOnly = true;
                    dataGridView1.Columns[t].DefaultCellStyle.BackColor = Color.White;
                }
            }
        }

     private void ChkAll_CheckedChanged(object sender, EventArgs e)
        {
            if ((ChkAll.Checked))
            {
                int t;
                for (t = 3; t <= dataGridView1.Columns.Count - 5; t++)
                {
                    string g = dataGridView1.Columns[t].HeaderText.ToString();

                    DateTime d;
                    d = DateTime.Parse(dataGridView1.Columns[t].HeaderText);
                    if (g.CompareTo(a) == 0)
                    {
                        int i;
                        for (i = 0; i <= dataGridView1.Rows.Count - 1; i++)
                        {
                            dataGridView1.Rows[i].Cells[t].Value = true;
                        }
                    }
                }
            }
            else
            {
                int t;
                for (t = 3; t <= dataGridView1.Columns.Count - 5; t++)
                {
                    DateTime d;
                    d = DateTime.Parse(dataGridView1.Columns[t].HeaderText);
                    string g = dataGridView1.Columns[t].HeaderText.ToString();
                    if (g.CompareTo(a) == 0)
                    {
                        int i;
                        for (i = 0; i <= dataGridView1.Rows.Count - 1; i++)
                        {
                            dataGridView1.Rows[i].Cells[t].Value = false;
                        }
                    }
                }
            }
        }

        private void CheckedListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

 

        private void Attendance_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'logindbDataSet9.Attendance' table. You can move, or remove it, as needed.
            this.attendanceTableAdapter.Fill(this.logindbDataSet9.Attendance);

        }    }
}
Posted
Updated 25-Feb-13 17:59pm
v2
Comments
Tejas Vaishnav 25-Feb-13 23:48pm    
and question is....?
Prakash Thirumoorthy 25-Feb-13 23:50pm    
where is your question?...
Radhakrishnan V 19-Aug-14 1:40am    
Hi... Can u attach source.. pls

1 solution

Firstly you are declaring "a" as string.

Then you are writing below code to Parse it into DateTime.
C#
d = DateTime.Parse(a);


You need to initialize before you parse it.
 
Share this answer
 
Comments
khan siraj 26-Feb-13 5:54am    
Thanks to Reply ....
m new in this......
i tried it....but it also show error on initialization...
Can You tell Me What I need to initialize?
Please HElp ME........
please..............
himanhu989191 29-Aug-13 5:55am    
yes i can help u out..but u hv to post ur designer.cs code
himanhu989191 29-Aug-13 5:55am    
yes i can help u out..but u hv to post ur designer.cs code
himanhu989191 29-Aug-13 6:01am    
i think just replace string a="";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900