Example #1
0
        public void update(Criminals c)
        {
            SqlCommand    cmd = new SqlCommand(UPDATE, DBC.getConnection());
            SqlConnection con = cmd.Connection;

            con.Open();
            //Left side table attributes and right side class variables

            cmd.Parameters.AddWithValue("@criminalID", c.criminalID);
            cmd.Parameters.AddWithValue("@name", c.name);
            cmd.Parameters.AddWithValue("@age", c.Age);
            cmd.Parameters.AddWithValue("@criminalAddress", c.criminalAddress);
            cmd.Parameters.AddWithValue("@dateOfArrest", c.dateOfArrest);
            cmd.Parameters.AddWithValue("@batchID", c.batchID);
            cmd.Parameters.AddWithValue("@crimeID", c.crimeID);
            cmd.Parameters.AddWithValue("@caseNo", c.caseNo);
            using (con)
            {
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    MessageBox.Show("Data updated successfully");
                }
                else
                {
                    MessageBox.Show("something wrong");
                }
            }
        }
Example #2
0
 public void insert(Criminals c)
 {
     try
     {
         SqlCommand    cmd = new SqlCommand(INSERT, DBC.getConnection());
         SqlConnection con = cmd.Connection;
         con.Open();
         cmd.Parameters.AddWithValue("@name", c.name);
         cmd.Parameters.AddWithValue("@age", c.Age);
         cmd.Parameters.AddWithValue("@criminalAddress", c.criminalAddress);
         cmd.Parameters.AddWithValue("@dateOfArrest", c.dateOfArrest);
         cmd.Parameters.AddWithValue("@batchID", c.batchID);
         cmd.Parameters.AddWithValue("@crimeID", c.crimeID);
         cmd.Parameters.AddWithValue("@caseNo", c.caseNo);
         using (con)
         {
             int rows = cmd.ExecuteNonQuery();
             if (rows > 0)
             {
                 MessageBox.Show("Data inserted successfully");
             }
             else
             {
                 MessageBox.Show("something wrong");
             }
         }
     }
     catch (Exception e1)
     {
         //MessageBox.Show(e1 + "");
     }
 }
Example #3
0
        public List <Criminals> fetch(SqlCommand cmd)
        {
            SqlConnection con = cmd.Connection;

            con.Open();
            using (con)
            {
                SqlDataReader    dr       = cmd.ExecuteReader();
                List <Criminals> criminal = null;
                if (dr.HasRows)
                {
                    criminal = new List <Criminals>();
                    while (dr.Read())
                    {
                        Criminals c = new Criminals();
                        c.criminalID      = Convert.ToInt32(dr["CriminalID"]);
                        c.name            = Convert.ToString(dr["name"]);
                        c.Age             = Convert.ToInt32(dr["Age"]);
                        c.criminalAddress = Convert.ToString(dr["criminalAddress"]);
                        c.dateOfArrest    = Convert.ToString(dr["dateOfArrest"]);
                        c.batchID         = Convert.ToInt32(dr["batchID"]);
                        c.crimeID         = Convert.ToInt32(dr["crimeID"]);
                        c.caseNo          = Convert.ToInt32(dr["caseNo"]);
                        criminal.Add(c);
                    }
                    criminal.TrimExcess();
                }
                return(criminal);
            }
        }
        private void deleteBtn_Click(object sender, EventArgs e)
        {
            c            = new Criminals();
            c.criminalID = Convert.ToInt32(criminalsGridView.CurrentRow.Cells[0].Value.ToString());
            CriminalDataBase criminalDB = new CriminalDataBase();

            criminalDB.delete(c);
            populate();
        }
        private void saveBtn_Click(object sender, EventArgs e)
        {
            CriminalDataBase criminalDB = new CriminalDataBase();

            c                 = new Criminals();
            c.name            = nameTxt.Text;
            c.Age             = Convert.ToInt32(ageTxt.Text);
            c.criminalAddress = addressTxt.Text;
            c.dateOfArrest    = arrestTxt.Text;
            c.batchID         = Convert.ToInt32(batchIDTxt.Text);
            c.crimeID         = Convert.ToInt32(crimesTxt.Text);
            c.caseNo          = Convert.ToInt32(caseNoTxt.Text);
            criminalDB.insert(c);
            populate();
        }
        private void updateBtn_Click(object sender, EventArgs e)
        {
            CriminalDataBase criminalDB = new CriminalDataBase();

            c                 = new Criminals();
            c.criminalID      = Convert.ToInt32(criminalsGridView.CurrentRow.Cells[0].Value.ToString());
            c.name            = nameTxt.Text;
            c.Age             = Convert.ToInt32(ageTxt.Text);
            c.criminalAddress = addressTxt.Text;
            c.dateOfArrest    = arrestTxt.Text;
            c.batchID         = Convert.ToInt32(batchIDTxt.Text);
            c.crimeID         = Convert.ToInt32(crimeIDTxt.Text);
            c.caseNo          = Convert.ToInt32(caseNoTxt.Text);
            criminalDB.update(c);
            populate();
        }
Example #7
0
        public void delete(Criminals c)
        {
            SqlCommand    cmd = new SqlCommand(DELETE, DBC.getConnection());
            SqlConnection con = cmd.Connection;

            con.Open();
            //Left side table attribute and right side class variabled
            cmd.Parameters.AddWithValue("@CriminalID", c.criminalID);
            using (con)
            {
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    MessageBox.Show("Data deleted successfully");
                }
                else
                {
                    MessageBox.Show("something wrong");
                }
            }
        }