public static int deleteSolutionParts(SolutionParts sp)
 {
     SqlConnection conn = null;
     SqlCommand cmd = null;
     try
     {
         conn = new SqlConnection(conStr);
         conn.Open();
         cmd = conn.CreateCommand();
         cmd.CommandText = "delete from solution_parts where sp_ID=@spID";
         cmd.Parameters.AddWithValue("@spID", sp.spID);
         return cmd.ExecuteNonQuery();
     }
     finally
     {
         conn.Close();
     }
 }
        public static int addSolutionParts(SolutionParts sp)
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;
            try
            {
                conn = new SqlConnection(conStr);
                conn.Open();
                cmd = conn.CreateCommand();

                if (findSolutionPartsBySpID(sp.spID) != null)
                    return -1;
                cmd.CommandText = "insert into solution_parts (solution_ID,Parts_ID) values(@solutionID,@PartsID)";
                cmd.Parameters.AddWithValue("@solutionID", sp.solutionID);
                cmd.Parameters.AddWithValue("@PartsID", sp.partsID);
                return cmd.ExecuteNonQuery();
            }
            finally
            {
                conn.Close();
            }
        }
        public static List<SolutionParts> getAllSolutionParts()
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;
            try
            {
                conn = new SqlConnection(conStr);
                conn.Open();
                cmd = conn.CreateCommand();
                cmd.CommandText = "select * from solution_parts";
                SqlDataReader reader = cmd.ExecuteReader();
                List<SolutionParts> spList = new List<SolutionParts>();
                while (reader.Read())
                {
                    SolutionParts sp = new SolutionParts();
                    sp.spID = reader.GetInt32(reader.GetOrdinal("sp_ID"));
                    sp.solutionID = reader.GetInt32(reader.GetOrdinal("solution_ID"));
                    sp.partsID = reader.GetInt32(reader.GetOrdinal("parts_ID"));

                    spList.Add(sp);
                }
                return spList;
            }
            finally
            {
                conn.Close();
            }
        }
        public static int addAll(Operator op)
        {
            int faultID = 0;
            int solutionID = 0;
            int i = 0;

            addSolution(op.solution);
            solutionID = findSolutionID();
            op.record.solutionID = solutionID;

            foreach (Parts p in op.parts)
            {
                SolutionParts sp = new SolutionParts();
                addParts(p);
                sp.solutionID = solutionID;
                sp.partsID = findPartsByPartsName(p.partsName).partsID;
                op.solutionParts.Add(sp);
            }

            foreach (SolutionParts sp in op.solutionParts)
            {
                addSolutionParts(sp);
            }

            addFault(op.fault);
            faultID = findFaultID();

            op.record.faultID = faultID;

            i = addRecord(op.record);
            return i;
        }
        public static SolutionParts findSolutionPartsBySpID(int spID)
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;
            try
            {
                conn = new SqlConnection(conStr);
                conn.Open();
                cmd = conn.CreateCommand();
                cmd.CommandText = "select * from solution_parts  where sp_ID=@spID";
                cmd.Parameters.AddWithValue("@spID", spID);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    SolutionParts sp = new SolutionParts();
                    sp.spID = reader.GetInt32(reader.GetOrdinal("sp_ID"));
                    sp.solutionID = reader.GetInt32(reader.GetOrdinal("solution_ID"));
                    sp.partsID = reader.GetInt32(reader.GetOrdinal("parts_ID"));

                    return sp;
                }
                return null;
            }
            finally
            {
                conn.Close();
            }
        }