示例#1
0
        public void update(Victim d)
        {
            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("@ID", d.ID);
            cmd.Parameters.AddWithValue("@Name", d.Name);
            cmd.Parameters.AddWithValue("@IDCard", d.IDCard);
            cmd.Parameters.AddWithValue("@VictimAddress", d.VictimAddress);
            cmd.Parameters.AddWithValue("@PhoneNumber", d.PhoneNumber);
            cmd.Parameters.AddWithValue("@CaseNumber", d.CaseNumber);
            using (con)
            {
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    MessageBox.Show("Data updated successfully");
                }
                else
                {
                    MessageBox.Show("something wrong");
                }
            }
        }
示例#2
0
 public void insert(Victim d)
 {
     try
     {
         SqlCommand    cmd = new SqlCommand(INSERT, DBC.getConnection());
         SqlConnection con = cmd.Connection;
         con.Open();
         cmd.Parameters.AddWithValue("@Name", d.Name);
         cmd.Parameters.AddWithValue("@IDCard", d.IDCard);
         cmd.Parameters.AddWithValue("@VictimAddress", d.VictimAddress);
         cmd.Parameters.AddWithValue("@PhoneNumber", d.PhoneNumber);
         cmd.Parameters.AddWithValue("@CaseNumber", d.CaseNumber);
         using (con)
         {
             int rows = cmd.ExecuteNonQuery();
             if (rows > 0)
             {
                 MessageBox.Show("Data Inserted SuccesFully");
             }
             else
             {
                 MessageBox.Show("Something Gone Wrong");
             }
         }
     }
     catch (Exception e1)
     {
     }
 }
示例#3
0
        public List <Victim> fetch(SqlCommand cmd)
        {
            SqlConnection con = cmd.Connection;

            con.Open();
            using (con)
            {
                SqlDataReader dr     = cmd.ExecuteReader();
                List <Victim> victim = null;
                if (dr.HasRows)
                {
                    victim = new List <Victim>();
                    while (dr.Read())
                    {
                        Victim d = new Victim();
                        d.ID            = Convert.ToInt32(dr["ID"]);
                        d.IDCard        = Convert.ToInt64(dr["IDCard"]);
                        d.Name          = Convert.ToString(dr["Name"]);
                        d.VictimAddress = Convert.ToString(dr["VictimAddress"]);
                        d.PhoneNumber   = Convert.ToInt32(dr["PhoneNumber"]);
                        d.CaseNumber    = Convert.ToInt32(dr["CaseNumber"]);
                        victim.Add(d);
                    }
                    victim.TrimExcess();
                }
                return(victim);
            }
        }
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            v    = new Victim();
            v.ID = Convert.ToInt32(VictimGridView.CurrentRow.Cells[0].Value.ToString());
            VictimDataBase victimDataBase = new VictimDataBase();

            victimDataBase.delete(v);
            populate();
        }
        private void SaveButton_Click(object sender, EventArgs e)
        {
            VictimDataBase victimDataBase = new VictimDataBase();

            v               = new Victim();
            v.Name          = NameTextBox.Text;
            v.IDCard        = Convert.ToInt64(IDCardTextBox.Text);
            v.VictimAddress = AddressTextBox.Text;
            v.PhoneNumber   = Convert.ToInt32(PhoneNumberTextBox.Text);
            v.CaseNumber    = Convert.ToInt32(CaseNumberTextBox.Text);
            victimDataBase.insert(v);
            populate();
        }
        private void UpdateButton_Click(object sender, EventArgs e)
        {
            VictimDataBase victimDataBase = new VictimDataBase();

            v               = new Victim();
            v.ID            = Convert.ToInt32(VictimGridView.CurrentRow.Cells[0].Value.ToString());
            v.Name          = NameTextBox.Text;
            v.IDCard        = Convert.ToInt64(IDCardTextBox.Text);
            v.VictimAddress = AddressTextBox.Text;
            v.PhoneNumber   = Convert.ToInt32(PhoneNumberTextBox.Text);
            v.CaseNumber    = Convert.ToInt32(CaseNumberTextBox.Text);
            victimDataBase.update(v);
            populate();
        }
示例#7
0
        public void delete(Victim d)
        {
            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("@ID", d.ID);
            using (con)
            {
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    MessageBox.Show("Data deleted successfully");
                }
                else
                {
                    MessageBox.Show("something wrong");
                }
            }
        }