public void BusinessValueSetDescriptionTest() { BusinessValue bv = new BusinessValue("test"); bv.SetDescription("test1"); Assert.IsTrue(bv.GetDescription() == "test1"); bv.SetDescription("test"); }
//Reorder BV to insert a new one in the middle public void ReorderBusinessValue(string currname, string desc, bool isFirst) { BusinessValue current = new BusinessValue(currname, mRoadmapName); current.SetDescription(desc); int index = (int)Char.GetNumericValue(currname[15]) + 1; string nextID = currname.Substring(0,15) + index.ToString(); string nextdesc = null; string selectname = null; if (isFirst) selectname = currname; else selectname = nextID; using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = "SELECT Description FROM [dbo].[BusinessValue] WHERE Name=@sname AND RoadmapName=@Rname"; cmd.Parameters.AddWithValue("@sname", selectname); cmd.Parameters.AddWithValue("@Rname", mRoadmapName); cmd.Connection = conn; conn.Open(); using (SqlDataReader Reader =cmd.ExecuteReader()) { if (Reader.HasRows) { Reader.Read(); nextdesc = Reader.GetString(0); } } conn.Close(); } } BusinessValue next = new BusinessValue(nextID, mRoadmapName); next.SetDescription(nextdesc); BusinessValue nextdummy = new BusinessValue(currname, mRoadmapName); nextdummy.SetDescription(nextdesc); if (nextdesc != null) { nextdummy.SetName(nextID); ReorderBusinessValue(nextID, nextdesc, false); } }
//CONSTRUCTOR public StrategyPoint(string id,string desc, string rname) { mName = id; mDescription = desc; mRoadmapName = rname; //Get the StrategyPoints using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = "SELECT BusinessValueName FROM [dbo].[SP_BV_Crosswalk] WHERE RoadmapName =@Rname AND StrategyPointName =@Sname"; cmd.Parameters.AddWithValue("@Rname", mRoadmapName); cmd.Parameters.AddWithValue("@Sname", mName); cmd.Connection = conn; conn.Open(); using (SqlDataReader Reader = cmd.ExecuteReader()) { while (Reader.Read()) { string temp = Reader.GetString(0); BusinessValue bv = new BusinessValue(Reader.GetString(0), mRoadmapName); mValues.Add(bv); } } } using (SqlCommand cmd3 = new SqlCommand()) { cmd3.CommandText = "SELECT color FROM [dbo].[StrategyPoint] WHERE RoadmapName =@Rname AND Name = @sName"; cmd3.Parameters.AddWithValue("@Rname", mRoadmapName); cmd3.Parameters.AddWithValue("@Sname", mName); cmd3.Connection = conn; try { using (SqlDataReader Reader = cmd3.ExecuteReader()) { Reader.Read(); mColor = Reader.GetString(0); } } catch { mColor = "#000000"; } } foreach (BusinessValue bv in mValues) { using (SqlCommand cmd2 = new SqlCommand()) { cmd2.CommandText = "SELECT Description FROM [dbo].[BusinessValue] WHERE Name=@BVName AND RoadmapName=@Rname"; cmd2.Parameters.AddWithValue("@Rname", mRoadmapName); cmd2.Parameters.AddWithValue("@BVName", bv.GetName()); cmd2.Connection = conn; //conn.Open(); using (SqlDataReader Reader = cmd2.ExecuteReader()) { if (Reader.HasRows) { Reader.Read(); bv.SetDescription(Reader.GetString(0).ToString()); } } } } conn.Close(); } }
//Reload list of BV's public void ReloadBusinessValues() { mValues = new List<BusinessValue>(); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString)) { using (SqlCommand cmd1 = new SqlCommand()) { cmd1.CommandText = "SELECT BusinessValueName FROM [dbo].[SP_BV_Crosswalk] WHERE RoadmapName = @Rname AND StrategyPointName =@Sname"; cmd1.Parameters.AddWithValue("@Rname", mRoadmapName); cmd1.Parameters.AddWithValue("@Sname", mName); cmd1.Connection = conn; conn.Open(); using (SqlDataReader Reader = cmd1.ExecuteReader()) { while (Reader.Read()) { string temp = Reader.GetString(0); BusinessValue bv = new BusinessValue(Reader.GetString(0), mRoadmapName); mValues.Add(bv); } } } foreach (BusinessValue bv in mValues) { using (SqlCommand cmd2 = new SqlCommand()) { cmd2.CommandText = "SELECT Description FROM [dbo].[BusinessValue] WHERE Name=@BVName AND RoadmapName=@Rname"; cmd2.Parameters.AddWithValue("@Rname", mRoadmapName); cmd2.Parameters.AddWithValue("@BVName", bv.GetName()); cmd2.Connection = conn; using (SqlDataReader Reader = cmd2.ExecuteReader()) { if (Reader.HasRows) { Reader.Read(); bv.SetDescription(Reader.GetString(0).ToString()); Reader.Close(); } } } } conn.Close(); } }
public bool CreateBusinessValue(string name, string desc, string rname) { try { bool flag; //Add to both the BV table, and the BV/SP ownership table int i = 8; while (i<100) { if (Char.IsNumber(name[i])) i++; else break; } string orderstring = name.Substring(i + 6, (name.Length) - (i + 6)); int order = Convert.ToInt32(name.Substring(i+6, (name.Length) - (i+6))); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString)) { using (SqlCommand cmd1 = new SqlCommand()) { cmd1.CommandText = "INSERT INTO [dbo].[BusinessValue] (Name, Description, RoadmapName, Sort) VALUES (@BVName, @desc,@Rname, @sort)"; cmd1.Parameters.AddWithValue("@BVName", name); cmd1.Parameters.AddWithValue("@desc", desc); cmd1.Parameters.AddWithValue("@Rname", mRoadmapName); cmd1.Parameters.AddWithValue("@sort", order); cmd1.Connection = conn; conn.Open(); flag = cmd1.ExecuteNonQuery() != 0; conn.Close(); } using (SqlCommand cmd2 = new SqlCommand()) { cmd2.CommandText = "INSERT INTO [dbo].[SP_BV_Crosswalk] (StrategyPointName, BusinessValueName, RoadmapName) VALUES (@Sname,@BVName,@Rname)"; cmd2.Parameters.AddWithValue("@BVName", name); cmd2.Parameters.AddWithValue("@Sname", mName); cmd2.Parameters.AddWithValue("@Rname", mRoadmapName); cmd2.Connection = conn; conn.Open(); flag = cmd2.ExecuteNonQuery() != 0; conn.Close(); } } BusinessValue bis = new BusinessValue(name, rname); bis.SetDescription(desc); mValues.Add(bis); return flag; } catch (Exception ex) { return false; } }