public virtual CrystalDecisions.CrystalReports.Engine.ReportDocument CreateReport()
        {
            rptAttendance rpt = new rptAttendance();

            rpt.Site = this.Site;
            return(rpt);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (cmbCourse1.Text == "")
            {
                MessageBox.Show("Please select course", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cmbCourse1.Focus();
                return;
            }
            if (cmbBranch1.Text == "")
            {
                MessageBox.Show("Please select branch", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cmbBranch1.Focus();
                return;
            }
            if (cmbSemester1.Text == "")
            {
                MessageBox.Show("Please select semester", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cmbSemester1.Focus();
                return;
            }
            if (cmbSession1.Text == "")
            {
                MessageBox.Show("Please select session", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cmbSession1.Focus();
                return;
            }
            if (cmbSection1.Text == "")
            {
                MessageBox.Show("Please select section", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cmbSection1.Focus();
                return;
            }
            if (cmbSubjectCode.Text == "")
            {
                MessageBox.Show("Please select subject code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cmbSubjectCode.Focus();
                return;
            }
            try
            {
                Cursor         = Cursors.WaitCursor;
                timer1.Enabled = true;
                rptAttendance rpt = new rptAttendance();
                //The report you created.
                SqlConnection  myConnection = default(SqlConnection);
                SqlCommand     MyCommand    = new SqlCommand();
                SqlDataAdapter myDA         = new SqlDataAdapter();
                CMS_DBDataSet  myDS         = new CMS_DBDataSet();
                //The DataSet you created.


                myConnection          = new SqlConnection("Data Source=GHAFFARI\\ALIGHAFFARI;Initial Catalog=CMS;Integrated Security=True;");
                MyCommand.Connection  = myConnection;
                MyCommand.CommandText = "select * from Attendance where Course= '" + cmbCourse1.Text + "' and branch='" + cmbBranch1.Text + "' and Session='" + cmbSession1.Text + "' and Semester = '" + cmbSemester1.Text + "' and Section = '" + cmbSection1.Text + "' and SubjectCode = '" + cmbSubjectCode.Text + "' and AttendanceDate between @date1 and @date2 order by Student_name ";
                MyCommand.Parameters.Add("@date1", SqlDbType.DateTime, 30, " AttendanceDate").Value = dateTimePicker4.Value.Date;
                MyCommand.Parameters.Add("@date2", SqlDbType.DateTime, 30, " AttendanceDate").Value = dateTimePicker3.Value.Date;

                MyCommand.CommandType = CommandType.Text;
                myDA.SelectCommand    = MyCommand;
                myDA.Fill(myDS, "Attendance");

                con.Open();
                cmd = new SqlCommand("select Count(ScholarNo) from Attendance where Course= '" + cmbCourse1.Text + "' and branch='" + cmbBranch1.Text + "' and Session='" + cmbSession1.Text + "' and Semester = '" + cmbSemester1.Text + "' and Section = '" + cmbSection1.Text + "' and SubjectCode = '" + cmbSubjectCode.Text + "' and AttendanceDate between @date1 and @date2 group by ScholarNo", con);
                cmd.Parameters.Add("@date1", SqlDbType.DateTime, 30, " AttendanceDate").Value = dateTimePicker4.Value.Date;
                cmd.Parameters.Add("@date2", SqlDbType.DateTime, 30, " AttendanceDate").Value = dateTimePicker3.Value.Date;
                rdr = cmd.ExecuteReader();

                if (rdr.Read())
                {
                    label20.Text = rdr.GetInt32(0).ToString();
                }
                if ((rdr != null))
                {
                    rdr.Close();
                }
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
                rpt.SetDataSource(myDS);
                rpt.SetParameterValue("variable", dateTimePicker4.Value);
                rpt.SetParameterValue("variable1", dateTimePicker3.Value);
                rpt.SetParameterValue("variable2", label20.Text);
                crystalReportViewer2.ReportSource = rpt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
0
        private void btnGetData_Click(object sender, EventArgs e)
        {
            crystalReportViewer1.ReportSource = null;
            if (cmbSession.Text == "")
            {
                MessageBox.Show("Please select session", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cmbSession.Focus();
                return;
            }
            if (cmbCourse.Text == "")
            {
                MessageBox.Show("Please select course", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cmbCourse.Focus();
                return;
            }
            if (cmbBranch.Text == "")
            {
                MessageBox.Show("Please select branch", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cmbBranch.Focus();
                return;
            }
            if (cmbSemester.Text == "")
            {
                MessageBox.Show("Please select semester", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cmbSemester.Focus();
                return;
            }

            if (cmbSection.Text == "")
            {
                MessageBox.Show("Please select section", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cmbSection.Focus();
                return;
            }
            try
            {
                Cursor         = Cursors.WaitCursor;
                timer1.Enabled = true;
                rptAttendance rpt = new rptAttendance();
                //The report you created.
                SqlConnection  myConnection = default(SqlConnection);
                SqlCommand     MyCommand    = new SqlCommand();
                SqlDataAdapter myDA         = new SqlDataAdapter();
                CMS_DBDataSet1 myDS         = new CMS_DBDataSet1();
                //The DataSet you created.
                myConnection = new SqlConnection(cs.DBConn);
                myConnection.Open();
                MyCommand.Connection  = myConnection;
                MyCommand.CommandText = "select  * from Attendance,Student where Student.scholarno=Attendance.ScholarNo and Attendance.Course= '" + cmbCourse.Text + "'and Attendance.branch='" + cmbBranch.Text + "'and Attendance.Session='" + cmbSession.Text + "' and Attendance.Semester = '" + cmbSemester.Text + "' and Attendance.Section = '" + cmbSection.Text + "' and Status = 'Yes' and AttendanceDate between @date1 and @date2  order by Student.Student_name,Student.ScholarNo ";
                MyCommand.Parameters.Add("@date1", SqlDbType.DateTime, 30, " AttendanceDate").Value = dateTimePicker1.Value.Date;
                MyCommand.Parameters.Add("@date2", SqlDbType.DateTime, 30, " AttendanceDate").Value = dateTimePicker2.Value.Date;
                MyCommand.CommandType = CommandType.Text;
                myDA.SelectCommand    = MyCommand;
                myDA.Fill(myDS, "Student");
                myDA.Fill(myDS, "Attendance");
                myConnection.Close();
                myDA.Dispose();
                MyCommand.Dispose();
                myConnection.Dispose();
                con = new SqlConnection(cs.DBConn);
                con.Open();
                cmd = new SqlCommand("select Count(ScholarNo) from Attendance where  Course= '" + cmbCourse.Text + "'and branch='" + cmbBranch.Text + "'and Session='" + cmbSession.Text + "' and Semester = '" + cmbSemester.Text + "' and Section = '" + cmbSection.Text + "'  and AttendanceDate between @date1 and @date2 group by ScholarNo ", con);
                cmd.Parameters.Add("@date1", SqlDbType.DateTime, 30, " AttendanceDate").Value = dateTimePicker1.Value.Date;
                cmd.Parameters.Add("@date2", SqlDbType.DateTime, 30, " AttendanceDate").Value = dateTimePicker2.Value.Date;
                rdr = cmd.ExecuteReader();

                if (rdr.Read())
                {
                    label21.Text = rdr.GetInt32(0).ToString();
                }
                else
                {
                    label21.Text = "";
                }
                if ((rdr != null))
                {
                    rdr.Close();
                }
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }

                rpt.SetDataSource(myDS);
                rpt.SetParameterValue("variable", dateTimePicker1.Value);
                rpt.SetParameterValue("variable1", dateTimePicker2.Value);
                rpt.SetParameterValue("variable2", label21.Text);
                crystalReportViewer1.ReportSource = rpt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }