コード例 #1
0
        protected void btnFinalize_Click(object sender, EventArgs e)
        {
            //Inspection is technically already created.  The only data that needs to be added
            //iS the finish date and the hazard items

            string           messageBoxText = "Are you sure you want to finalize this inspection?";
            string           caption        = "Finalize Inspection Warning";
            MessageBoxButton button         = MessageBoxButton.YesNoCancel;
            MessageBoxImage  icon           = MessageBoxImage.Warning;
            MessageBoxResult result         = MessageBox.Show(messageBoxText, caption, button, icon);

            if (result == MessageBoxResult.Yes)
            {
                //Get the inspectionID
                int inspectionID = Convert.ToInt32(Request.QueryString["ID"]);

                //Create a new SQL connection
                SqlConnection conn = new SqlConnection(connectionString);

                //Create a new SQL command
                SqlCommand comm = conn.CreateCommand();

                //Assign the query to the command
                comm.CommandText = "UPDATE Inspection SET FinishDate=@finishDate, IsComplete=1 WHERE ID = " + inspectionID;

                //Assign the current date time to the query
                comm.Parameters.AddWithValue("@finishDate", DateTime.Now);

                //Open the connection
                conn.Open();

                //Execute the command
                int rows = comm.ExecuteNonQuery();

                //Close the connection
                conn.Close();

                if (rows > 0)
                {
                    MessageBox.Show("Inspection Finalized");
                    //Reload the page
                    Response.Redirect("Homepage.aspx");
                    //Send out an email to the admin users
                    string mailBody = "Hello Administrator users.  Technician " + lblTechnicianName.Text + " has completed inspection " + inspectionID + " In the lab/room " + lblRoomName.Text + " At the time of " + DateTime.Now + ".";
                    DataLookup.SendMail(999, "An Inspection Has Been Completed", mailBody);
                }
                else
                {
                    MessageBox.Show("Error.  No Action Taken.");
                }
            }
            if (result == MessageBoxResult.No | result == MessageBoxResult.Cancel)
            {
                MessageBox.Show("No Action Taken");
            }
        }
コード例 #2
0
        protected void btnSchedule_Click(object sender, EventArgs e)
        {
            string           messageBoxText = "Are you sure you want to schedule this inspection?";
            string           caption        = "Inspection Schedule Warning";
            MessageBoxButton button         = MessageBoxButton.YesNoCancel;
            MessageBoxImage  icon           = MessageBoxImage.Warning;
            MessageBoxResult result         = MessageBox.Show(messageBoxText, caption, button, icon);

            if (result == MessageBoxResult.Yes)
            {
                //Get the lab ID
                string room          = ddlLab.SelectedItem.Text;
                var    splitValueLab = room.Split(' ');
                int    labID         = Convert.ToInt16(splitValueLab[0]);

                //Get the technician ID
                string technician     = ddlTechnician.SelectedItem.Text;
                var    splitValueTech = technician.Split(' ');
                int    technicianID   = Convert.ToInt16(splitValueTech[3]);

                //Get the due date value
                DateTime dueDate = calDueDate.SelectedDate;

                //Create a new SQL connection
                SqlConnection conn = new SqlConnection(connectionString);

                //Create a new SQL command
                SqlCommand comm = conn.CreateCommand();

                //Assign the query to the command
                comm.CommandText = "INSERT INTO Inspection (TechnicianID, LabID, AssignedDate, DueDate) VALUES (@technicianID, @labID, @assignedDate, @dueDate)";
                comm.Parameters.Add("@technicianID", technicianID);
                comm.Parameters.Add("@labID", labID);
                comm.Parameters.Add("@assignedDate", SqlDbType.DateTime).Value = DateTime.Now;
                comm.Parameters.Add("@dueDate", SqlDbType.DateTime).Value      = dueDate;

                //Open the connection
                conn.Open();

                //Execute the query
                int rows = comm.ExecuteNonQuery();

                //Close the connection
                conn.Close();

                //Shows feedback based on the success of the transaction
                if (rows > 0)
                {
                    MessageBox.Show("Inspection has been scheduled.");
                    //Send a notification Email
                    string mailBody = "Hello " + technician + ", You have a new inspection in room " + room + " that is due on " + dueDate;
                    DataLookup.SendMail(technicianID, "You Have a New Scheduled Inspection", mailBody);
                }
                else
                {
                    MessageBox.Show("Error. Inspection  has not been scheduled.");
                }
            }
            if (result == MessageBoxResult.No | result == MessageBoxResult.Cancel)
            {
                MessageBox.Show("No Action Taken");
            }
        }