public Boolean UploadToDB() { try { CustomCode u = new CustomCode(); Int64 assyID = -1; if (m_lstObsoleteParts.Count > 0 || m_lstUndefinedPNs.Count > 0) { return(false); } m_errMsg.Clear(); //First, we need to make an entry in table asyBOM so we can get the DB ID of the Assy xDB = new clsDB(); cmd = new SqlCommand(); List <SqlParameter> ps = new List <SqlParameter>(); string assyDesc = "ASSY," + m_topLevelName; ps.Add(new SqlParameter("@" + DBK.strNAME, m_topLevelName)); ps.Add(new SqlParameter("@" + DBK.strASSYPARTNUMBER, m_assyPN)); ps.Add(new SqlParameter("@" + DBK.strREVISION, m_assyRev)); ps.Add(new SqlParameter("@" + DBK.intBOMREV, m_bomRev)); ps.Add(new SqlParameter("@" + DBK.strDESCRIPTION, assyDesc)); ps.Add(new SqlParameter("@intMajor", u.getMajorRev(m_assyRev))); ps.Add(new SqlParameter("@intMinor", u.getMinorRev(m_assyRev))); ps.Add(new SqlParameter("@" + DBK.keyUPLOADEDBY, u.getUserDBID())); ps.Add(new SqlParameter("@" + DBK.keyASSYBU, u.getUserdBUID())); ps.Add(new SqlParameter("@" + DBK.keyREASONFORREV, 1)); ps.Add(new SqlParameter("@" + DBK.keyASSYSTATUS, 1)); ps[ps.Count - 1].Direction = System.Data.ParameterDirection.InputOutput; ps.Add(new SqlParameter("@" + DBK.ID, -1)); ps[ps.Count - 1].Direction = System.Data.ParameterDirection.Output; using (xDB.OpenConnection()) { xDB.ExecuteSP(DBK.SP.spUPSERTASSYBOMENTRY, ps, clsDB.SPExMode.NONQUERY, ref cmd); if (int.Parse(cmd.Parameters["@" + DBK.keyASSYSTATUS].Value.ToString()) == 1) { assyID = Int64.Parse(cmd.Parameters["@" + DBK.ID].Value.ToString()); //Delete this ASSY ID From the database List <SqlParameter> tmpLstP = new List <SqlParameter>(); tmpLstP.Add(new SqlParameter("@" + DBK.keyASSY, assyID)); SqlCommand tmpCmd = new SqlCommand(); using (xDB.OpenConnection()) { xDB.ExecuteSP(DBK.SP.spDELETEASSYBOMPARTS, tmpLstP, clsDB.SPExMode.NONQUERY, ref tmpCmd); } StringBuilder sqlStr = new StringBuilder(); sqlStr.Append("INSERT INTO " + DBK.asyBOMPARTS + " (" + DBK.keyASSY + ", " + DBK.keyPN + ", " + DBK.strREFDES + ", " + DBK.strBOMNOTES + ", " + DBK.intQTY + ") VALUES "); //The values we will insert are in m_BOM foreach (string assyPNKy in m_BOM.Keys) { string abk = assyPNKy; foreach (string PNKy in m_BOM[assyPNKy].Keys) { AssyBomLineItem x = m_BOM[assyPNKy][PNKy]; string bomNotes = x.BOMNotes; if (bomNotes == "" || bomNotes == "-") { bomNotes = "''"; } sqlStr.Append("(" + assyID + ", " + x.PNID.ToString() + ", " + "'" + x.RefDes + "', " + bomNotes + ", " + x.Qty.ToString() + "),"); } } //Remove the last comma sqlStr.Remove(sqlStr.Length - 1, 1); cmd.Parameters.Clear(); using (xDB.OpenConnection()) { if (xDB.ExecuteNonQuery(sqlStr.ToString())) { if (xDB.NAffectedRows > 0) { return(true); } else { m_errMsg.Append("Executed following query without errors:" + sqlStr + AAAK.vbCRLF + "...but no rows were affected by the Statement. Please report this bug."); return(false); } } else { m_errMsg.Append("Method UploadToDB: Unable to execute Nonquery: " + sqlStr + AAAK.vbCRLF + xDB.ErrMsg); return(false); } } } else { m_errMsg.Append(m_topLevelName + " Revision " + m_assyRev + " BOM Revision " + m_bomRev + "is RELEASED. You cannot upload a new BOM if it's status is RELEASED." + AAAK.vbCRLF + "If you want to upload a new BOM, you must change the Assembly and/or BOM revision."); return(false); } } } catch (Exception ex) { m_errMsg.Append(ex.Message + AAAK.vbCRLF + ex.StackTrace); return(false); } }