示例#1
0
 public CrimeDetailsForm(Crime crime)
 {
     InitializeComponent();
     SetCrimeDetails(crime);
     DisableControls();
     this.crime                               = crime;
 }
示例#2
0
 //private bool another_crime;
 //NEW VICTIM CONSTRUCTOR
 public VictimsDetailsForm(Perpetrator perp,Crime crime)
 {
     //this.another_crime = false;
     this.perpetrator                                  = perp;
     this.crime                                        = crime;
     InitializeComponent();
     ResetTextValues();
 }
示例#3
0
        public static bool Update(Crime crime)
        {
            try
            {
                String update_sql          = "UPDATE " + TABLE_NAME + " SET DATE=@date ,TIME=@time,TYPE=@type,CRIME=@crime,DETAISL=@details,PERPETRATOR_ID=@perp_id WHERE ID=@id";
                //Sql command
                sql_command                = new MySqlCommand();
                sql_command.Connection     = (MySqlConnection)database.OpenConnection();
                sql_command.CommandText    = update_sql;

                sql_command.Parameters.AddWithValue("@date", crime.date_of_crime);
                sql_command.Parameters.AddWithValue("@time", crime.time_of_crime);
                sql_command.Parameters.AddWithValue("@type", crime.type_of_crime);
                sql_command.Parameters.AddWithValue("@crime", crime.crime_committed);
                sql_command.Parameters.AddWithValue("@details", crime.details_of_crime);
                sql_command.Parameters.AddWithValue("@perp_id", crime.perpetrator_id);

                sql_command.Prepare();

                //execute command
                database.Update(sql_command);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                CloseDatabaseConnection();
            }
        }
示例#4
0
        public static bool Save(Crime crime)
        {
            try
            {

                String insert_sql          = "INSERT INTO " + TABLE_NAME +
                                            " (DATE,TIME,TYPE,CRIME,DETAILS,PERPETRATOR_ID,LOCATION) "+
                                            "values(@date,@time,@type,@crime,@details,@perp_id,@location) ";

                //sql command
                sql_command                = new MySqlCommand();
                sql_command.Connection     = (MySqlConnection)database.OpenConnection();
                sql_command.CommandText    = insert_sql;
                sql_command.Parameters.AddWithValue("@date", crime.date_of_crime);
                sql_command.Parameters.AddWithValue("@time", crime.time_of_crime);
                sql_command.Parameters.AddWithValue("@type", crime.type_of_crime);
                sql_command.Parameters.AddWithValue("@crime", crime.crime_committed);
                sql_command.Parameters.AddWithValue("@details", crime.details_of_crime);
                sql_command.Parameters.AddWithValue("@perp_id", crime.perpetrator_id);
                sql_command.Parameters.AddWithValue("@location", crime.location);

                sql_command.Prepare();

                //execute query
                database.Insert(sql_command);

                crime.id                   = Convert.ToInt32(sql_command.LastInsertedId);

                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                CloseDatabaseConnection();
            }
        }
示例#5
0
        public static Crime[] GetCrimesCommitted(int perpetrator_id)
        {
            List<Crime> crimes             = new List<Crime>();
            try
            {
                //select sql
                String select_sql          = "SELECT * FROM " + TABLE_NAME + " WHERE PERPETRATOR_ID=@id";

                //Sql command
                sql_command                = new MySqlCommand();
                sql_command.Connection     = (MySqlConnection)database.OpenConnection();
                sql_command.CommandText    = select_sql;
                sql_command.Parameters.AddWithValue("@id", perpetrator_id);
                sql_command.Prepare();

                //get results in enum object
                data_reader                = database.Select(sql_command);

                //loop thru em
                while (data_reader.Read())
                {
                    //create new student

                    int id                 = data_reader.GetInt32(ID);
                    String date            = data_reader.GetString(DATE);
                    String time            = data_reader.GetString(TIME);
                    String type            = data_reader.GetString(TYPE);
                    String crime_committed = data_reader.GetString(CRIME);
                    String details         = data_reader.GetString(DETAILS);
                    String created_at      = data_reader.GetString(CREATED_AT);
                    String location        = data_reader.GetString(LOCATION);

                    Crime crime            = new Crime(id,date, details, type, crime_committed, time, location,perpetrator_id,created_at);

                    //add student to list
                    crimes.Add(crime);
                }

            }
            finally
            {
                CloseDatabaseConnection();
            }

            //return array of results
            return crimes.ToArray();
        }
示例#6
0
 private void SetCrimeDetails(Crime crime)
 {
     this.dateTimePicker_dateOfCrime.Text     = crime.date_of_crime;
     this.comboBox_type_of_crime.Text         = crime.type_of_crime;
     this.comboBox_crimeCommited.Text         = crime.crime_committed;
     this.textfield_details_of_crime.Text     = crime.details_of_crime;
     this.textfield_crime_location.Text = crime.location;
 }
示例#7
0
        private void save_button_Click(object sender, EventArgs e)
        {
            //DISABLE BUTTON
            button_save.Enabled = false;

            //get crime details
            String date_of_crime                     = dateTimePicker_dateOfCrime.Text;
            String time_of_crime                     = GetTimeOfCrime();
            String type_of_crime                     = comboBox_type_of_crime.Text;
            String crime_commited                    = comboBox_crimeCommited.Text;
            String details_of_crime                  = textfield_details_of_crime.Text;
            String location_of_crime = textfield_crime_location.Text;

            //create crime object
            Crime crime                              = new Crime(date_of_crime, details_of_crime, type_of_crime, crime_commited, time_of_crime,location_of_crime,-1);

            //if the crime selected has victims
            if (comboBox_type_of_crime.Text.Equals(types_of_crimes[0]) || comboBox_type_of_crime.Text.Equals(types_of_crimes[1]))
            {

                //create victims form
                VictimsDetailsForm form              = new VictimsDetailsForm(perpetrator, crime);

                //close this form
                this.Close();

                //show it
                form.ShowDialog();

                //return
                return;
            }

            // we are dealing with a victimless crime
            else
            {
                Debug.WriteLine("Text                =" + comboBox_crimeCommited.Text);
                Debug.WriteLine("This Crime Has No Victims");
                //save perpetrator
                PerpetratorsManager.Save(perpetrator);

                //set the id of the perpetrator
                crime.perpetrator_id                 = perpetrator.id;

                //save crime
                bool sucess                          = CrimesManager.Save(crime);

            }

            //display error message
        }