Exemplo n.º 1
0
        internal bool insert()
        {
            string        sql = "";
            SqlCommand    command;
            var           CL  = new commonLogic();
            SqlConnection cnn = CL.connect();
            string        id  = HttpContext.Current.Session["id"].ToString();

            try
            {
                string uploadFileName = uploadFile();
                string DrillType      = string.Join(",", TypeOfDrill);
                Durationofdrill = CL.setDurationOfDrill(DurationofdrillMinutes, DurationofdrillSeconds);
                string drillStatus = CL.GetDrillStatus(reportForQuanterEnding, DateTimeofDrill, DrillType, Durationofdrill);
                string drillShift  = CL.GetDrillShift(DateTimeofDrill);
                sql     = "INSERT INTO resdential_drill_log(user_id,program_address,program_location,drill_shift,report_for_quarter_ending,drill_status,type_of_drill,evacuation,name_of_program,date_time_of_drill,staff_ratio,duration_of_drill,drill_scenario,building_exit,egress_was_blocked,secondary_location,staff_signature,staff_signature_date,supervisor_signature,supervisor_signature_date,added_date,drill_was_during,name_of_staff,upload_survey) ";
                sql    += " OUTPUT INSERTED.ID VALUES(@user_id,@ProgramAddress,@ProgramLocation,@drillShift,@reportForQuanterEnding,@DrillStatus,@TypeOfDrill,@Evacuation,@NameofProgram,@DateTimeofDrill, @StaffRatio, @Durationofdrill,@DrillScenario, @BuildingExit,@EgressWasBlocked, @SecondaryLocation,@StaffSignature, @StaffSignatureDate,@SupervisorSignature,@SupervisorSignatureDate,GETDATE(),@DrillWasDuring,@NameofStaff,@upload_survey) ";
                command = new SqlCommand(sql, cnn);
                command.Parameters.AddWithValue("@user_id", id);
                command.Parameters.AddWithValue("@ProgramAddress", ProgramAddress);
                command.Parameters.AddWithValue("@ProgramLocation", Location);
                command.Parameters.AddWithValue("@drillShift", drillShift);
                command.Parameters.AddWithValue("@reportForQuanterEnding", DBNull.Value);
                command.Parameters.AddWithValue("@DrillStatus", drillStatus);
                command.Parameters.AddWithValue("@TypeOfDrill", DrillType);
                command.Parameters.AddWithValue("@Evacuation", Evacuation);
                command.Parameters.AddWithValue("@NameofProgram", NameofProgram);
                command.Parameters.AddWithValue("@DateTimeofDrill", DateTimeofDrill);
                command.Parameters.AddWithValue("@StaffRatio", StaffRatio);
                if (Durationofdrill == null)
                {
                    command.Parameters.AddWithValue("@Durationofdrill", DBNull.Value);
                }
                else
                {
                    command.Parameters.AddWithValue("@Durationofdrill", Durationofdrill);
                }

                command.Parameters.AddWithValue("@DrillScenario", DrillScenario);
                command.Parameters.AddWithValue("@BuildingExit", BuildingExit);
                command.Parameters.AddWithValue("@EgressWasBlocked", EgressWasBlocked);
                command.Parameters.AddWithValue("@SecondaryLocation", SecondaryLocation);
                command.Parameters.AddWithValue("@StaffSignature", StaffSignature);
                command.Parameters.AddWithValue("@StaffSignatureDate", StaffSignatureDate);
                command.Parameters.AddWithValue("@SupervisorSignature", SupervisorSignature);
                command.Parameters.AddWithValue("@SupervisorSignatureDate", SupervisorSignatureDate);
                command.Parameters.AddWithValue("@DrillWasDuring", DrillWasDuring);
                command.Parameters.AddWithValue("@NameofStaff", NameofStaff);
                command.Parameters.AddWithValue("@upload_survey", uploadFileName);
                command.CommandType = CommandType.Text;
                int newId = Convert.ToInt32(command.ExecuteScalar());
                if (newId < 1)
                {
                    CL.getLog("Fail to insert");
                    return(false);
                }
                bool RDclient   = true;//ResidentialDrillClients(newId);
                bool RDUniqueID = updateUniqueId(newId);
                if (RDclient == false || RDUniqueID == false)
                {
                    CL.getLog("Fail to insert and update other tables");
                    return(false);
                }
                cnn.Close();
                return(true);
            }
            catch (Exception e)
            {
                CL.getLog("error while inserting records in resdential_drill_log " + e);
                cnn.Close();
                return(false);
            }
        }