Ejemplo n.º 1
0
        public bool Insert(PPEBLL ppe)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(UserDAL.myconnstrng);

            try
            {
                string     sql = "INSERT INTO tbl_PPE (ppe_no, Personal_Protective_Gear, Unit) VALUES (@ppe_no, @Personal_Protective_Gear, @Unit)";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@ppe_no", ppe.ID);
                cmd.Parameters.AddWithValue("@Personal_Protective_Gear", ppe.PersonalProtectiveGear);
                cmd.Parameters.AddWithValue("@Unit", ppe.Unit);

                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                // If the query is executed successfully then the value to rows will be greaten than 0 else it will be less than 0
                if (rows > 0)
                {
                    // Query successful
                    isSuccess = true;
                }
                else
                {
                    // Query failed
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                // Throw message if any error occurs
                MessageBox.Show(ex.Message, "Insert data in Database Information!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
Ejemplo n.º 2
0
        public bool Update(PPEBLL ppe)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(UserDAL.myconnstrng);

            try
            {
                string     sql = "UPDATE tbl_PPE SET Personal_Protective_Gear=@Personal_Protective_Gear, Unit=@Unit WHERE ppe_no=@ppe_no";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@Personal_Protective_Gear", ppe.PersonalProtectiveGear);
                cmd.Parameters.AddWithValue("@Unit", ppe.Unit);
                cmd.Parameters.AddWithValue("@ppe_no", ppe.ID);

                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    // Query successful
                    isSuccess = true;
                }
                else
                {
                    // Query failed
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                // Throw message if any error occurs
                MessageBox.Show(ex.Message, "Update data in Database Information!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
Ejemplo n.º 3
0
        public bool Delete(PPEBLL ppe)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(UserDAL.myconnstrng);

            try
            {
                string     sql = "DELETE FROM tbl_PPE WHERE ppe_no=@ppe_no";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@ppe_no", ppe.ID);

                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    // Query successful
                    isSuccess = true;
                }
                else
                {
                    // Query failed
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                // Throw message if any error occurs
                MessageBox.Show(ex.Message, "Delete data from Database Information!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }