Exemplo n.º 1
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (clsGlobal.currentReportID == 0)
                {
                    MessageBox.Show("You must select a report to open.", "Weekly Report.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
//*****************************************************************************************************************************************
                    //Get max ReportID from table tblReportHeader

                    SqlCommand cmdReportNo = new SqlCommand("SELECT ProjectNumber FROM Weekly_Report.tblProjectInfo WHERE ReportID = " +
                                                            clsGlobal.currentReportID + ";", conn);
                    conn.Open();
                    SqlDataReader readerReportNo = cmdReportNo.ExecuteReader();
                    readerReportNo.Read();
                    clsGlobal.projectNumber = readerReportNo.GetString(0);
                    conn.Close();

                    var m = refWeeklyReportMDI.mdi;
                    m.mdiToolStripProject.Text   = "    Project: " + clsGlobal.projectNumber;
                    m.mnuProject.Enabled         = true;
                    m.mnuReports.Enabled         = true;
                    m.mnuFileCloseReport.Enabled = true;
                    m.mnuFileOpenReport.Enabled  = false;

                    //Open the form frmFrontPage as a child to the parent
                    frmFrontPage objfrmFrontPage = new frmFrontPage();
                    objfrmFrontPage.MdiParent     = this.MdiParent;
                    objfrmFrontPage.StartPosition = FormStartPosition.CenterScreen;
                    objfrmFrontPage.Show();

                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Weekly Report",
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
Exemplo n.º 2
0
        private void cmdCreateReport_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtProjectNo.Text))
                {
                    MessageBox.Show("A Project Number must be entered.", "Weekly Report.",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    var t = this.txtProjectNo;
                    t.Focus();
                    t.BackColor = Color.Red;
                    t.ForeColor = Color.White;
                    return;
                }

                if (string.IsNullOrEmpty(txtProjectDesc.Text))
                {
                    MessageBox.Show("A Project Description must be entered.", "Weekly Report.",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    var t = this.txtProjectDesc;
                    t.Focus();
                    t.BackColor = Color.Red;
                    t.ForeColor = Color.White;
                    return;
                }

                //Connect to the DB
                SqlConnection conn = new SqlConnection(Properties.Settings.Default.SQLConn);

//*****************************************************************************************************************************************
                //Check if entered report already exists from table tblReportHeader

                SqlCommand cmd = new SqlCommand("SELECT tblProjectInfo.ProjectNumber, tblReportHeader.DisciplineID AS DisciplineID, " +
                                                "tblReportHeader.ShiftID " +
                                                "FROM (Weekly_Report.tblRepDiscipline tblRepDiscipline " +
                                                "INNER JOIN Weekly_Report.tblReportHeader tblReportHeader " +
                                                "ON (tblRepDiscipline.DisciplineID = tblReportHeader.DisciplineID)) " +
                                                "INNER JOIN Weekly_Report.tblProjectInfo tblProjectInfo " +
                                                "ON (tblProjectInfo.ReportID = tblReportHeader.ReportID) " +
                                                "WHERE ([tblProjectInfo].[ProjectNumber] = @ProjectNumber) " +
                                                "AND ([tblReportHeader].[DisciplineID] = @DisciplineID) " +
                                                "AND ([tblReportHeader].[ShiftID] = @ShiftID);", conn);
                conn.Open();
                cmd.Parameters.AddWithValue("@ProjectNumber", txtProjectNo.Text);
                cmd.Parameters.AddWithValue("@DisciplineID", cboDiscipline.SelectedValue);
                cmd.Parameters.AddWithValue("@ShiftID", cboShift.SelectedValue);
                SqlDataReader reader = cmd.ExecuteReader();

                int countReport = reader.Cast <object>().Count();

                conn.Close();

                if (countReport > 0)
                {
                    MessageBox.Show("A report for the project number and discipline entered is already on the system. " +
                                    "Change the information to start a new report", "Weekly Report",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    return;
                }

//*****************************************************************************************************************************************

                //Add information to main report header table tblReportHeader

                cmd = new SqlCommand("INSERT INTO Weekly_Report.tblReportHeader (DisciplineID, DateCreated, ShiftID) " +
                                     "VALUES (@DisciplineID, @DateCreated, @ShiftID);", conn);
                cmd.Parameters.AddWithValue("@DisciplineID", cboDiscipline.SelectedValue);
                cmd.Parameters.AddWithValue("@DateCreated", DateTime.Today);
                cmd.Parameters.AddWithValue("@ShiftID", cboShift.SelectedValue);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();

//*****************************************************************************************************************************************
                //Get max ReportID from table tblReportHeader

                cmd = new SqlCommand("SELECT MAX (tblReportHeader.ReportID) FROM Weekly_Report.tblReportHeader tblReportHeader", conn);
                conn.Open();
                SqlDataReader readerMaxRepID = cmd.ExecuteReader();
                readerMaxRepID.Read();
                clsGlobal.currentReportID = readerMaxRepID.GetInt32(0);
                conn.Close();

//*****************************************************************************************************************************************
                //Add information to project information table tblProjectInfo

                cmd = new SqlCommand("INSERT INTO Weekly_Report.tblProjectInfo(ReportID, ProjectNumber, ProjectDescription) " +
                                     "VALUES (@ReportID, @ProjectNumber, @ProjectDescription);", conn);
                cmd.Parameters.AddWithValue("@ReportID", clsGlobal.currentReportID);
                cmd.Parameters.AddWithValue("@ProjectNumber", txtProjectNo.Text);
                cmd.Parameters.AddWithValue("@ProjectDescription", txtProjectDesc.Text);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();

//*****************************************************************************************************************************************

                //Add information to supervisor table tblReportSupervisor

                cmd = new SqlCommand("INSERT INTO Weekly_Report.tblReportSupervisor(EmpID, ReportID) " +
                                     "VALUES (@EmpID, @ReportID);", conn);
                cmd.Parameters.AddWithValue("@ReportID", clsGlobal.currentReportID);
                cmd.Parameters.AddWithValue("@EmpID", cboSupervisor.SelectedValue);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();

//*****************************************************************************************************************************************

                //Add information to project manager table tblProjectMan

                cmd = new SqlCommand("INSERT INTO Weekly_Report.tblProjManager(EmpID, ReportID) " +
                                     "VALUES (@EmpID, @ReportID);", conn);
                cmd.Parameters.AddWithValue("@ReportID", clsGlobal.currentReportID);
                cmd.Parameters.AddWithValue("@EmpID", cboProjectMan.SelectedValue);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();

//*****************************************************************************************************************************************

                MessageBox.Show("The weekly report has been added to the system", "Weekly Report.",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                clsGlobal.projectNumber = txtProjectNo.Text;

                var m = refWeeklyReportMDI.mdi;
                m.mdiToolStripProject.Text   = "    Project: " + clsGlobal.projectNumber;
                m.mnuProject.Enabled         = true;
                m.mnuReports.Enabled         = true;
                m.mnuFileCloseReport.Enabled = true;

                //Open the form frmFrontPage as a child to the parent
                frmFrontPage objfrmFrontPage = new frmFrontPage();
                objfrmFrontPage.MdiParent     = this.MdiParent;
                objfrmFrontPage.StartPosition = FormStartPosition.CenterScreen;
                objfrmFrontPage.Show();

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Weekly Report",
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }