public void LoadQAndA(string id, string type) { StudioMResource.QandAForSupplier qa; StudioMQandA.Clear(); client = new SQSAdminServiceClient(); client.Endpoint.Address = new System.ServiceModel.EndpointAddress(CommonVariables.WcfEndpoint); DataSet ds = client.SQSAdmin_StudioM_LoadStudioMAttributeForClusterOrGroup(id, type, DefaultStateID.ToString()); client.Close(); foreach (DataRow dr in ds.Tables[0].Rows) { qa = new StudioMResource.QandAForSupplier(); qa.SupplierBrandID = int.Parse(dr["idStudioMSupplier"].ToString()); qa.SupplierBrandName = dr["SupplierName"].ToString(); qa.QuestionID = int.Parse(dr["idTemplateQuestion"].ToString()); qa.QuestionText = dr["Question"].ToString(); if (bool.Parse(dr["mandatory"].ToString())) { qa.Mandatory = true; } else { qa.Mandatory = false; } qa.AnswerType = dr["AnswerType"].ToString(); qa.AnswerID = int.Parse(dr["idTemplateAnswer"].ToString()); qa.AnswerText = dr["Answer"].ToString(); StudioMQandA.Add(qa); } }
public void SaveStudioMAttributesToClusterOrGroup(string id, string type) { int oldsupplierid = 0; int oldquestionid = 0; int oldanswerid = 0; string xml = ""; string mandatory = ""; string supplierstring = ""; string questionstring = ""; string answerstring = ""; string mandatorystring = ""; StudioMResource.QandAForSupplier qa; if (StudioMQandA.Count > 0) { xml = "<Brands>"; var sortedQANDA = from item in StudioMQandA //orderby item.SupplierBrandID, item.QuestionID, item.AnswerID select item; for (int i = 0; i < sortedQANDA.Count <StudioMResource.QandAForSupplier>(); i++) { qa = sortedQANDA.ElementAt <StudioMResource.QandAForSupplier>(i); if (qa.Mandatory) { mandatory = "1"; } else { mandatory = "0"; } if (supplierstring == "") { supplierstring = qa.SupplierBrandID.ToString(); questionstring = qa.QuestionID.ToString(); answerstring = qa.AnswerID.ToString(); mandatorystring = mandatory; } else { supplierstring = supplierstring + "," + qa.SupplierBrandID.ToString(); questionstring = questionstring + "," + qa.QuestionID.ToString(); answerstring = answerstring + "," + qa.AnswerID.ToString(); mandatorystring = mandatorystring + "," + mandatory; } if (qa.SupplierBrandID == oldsupplierid) { if (qa.QuestionID == oldquestionid) { if (qa.AnswerID == oldanswerid) { } else { oldanswerid = qa.AnswerID; xml = xml + @"<Answer id=""" + qa.AnswerID + @""" text=""" + System.Security.SecurityElement.Escape(qa.AnswerText) + @"""/>"; } } else { oldquestionid = qa.QuestionID; oldanswerid = qa.AnswerID; xml = xml + @"</Answers></Question>"; xml = xml + @"<Question id=""" + qa.QuestionID + @""" text=""" + System.Security.SecurityElement.Escape(qa.QuestionText) + @""" type=""" + qa.AnswerType + @""" mandatory=""" + mandatory + @""">"; xml = xml + @"<Answers>"; xml = xml + @"<Answer id=""" + qa.AnswerID + @""" text=""" + System.Security.SecurityElement.Escape(qa.AnswerText) + @"""/>"; } } else { oldsupplierid = qa.SupplierBrandID; oldquestionid = qa.QuestionID; oldanswerid = qa.AnswerID; if (i > 0) { xml = xml + @"</Answers></Question></Questions></Brand>"; } xml = xml + @"<Brand id=""" + qa.SupplierBrandID + @""" name=""" + System.Security.SecurityElement.Escape(qa.SupplierBrandName) + @""">"; xml = xml + @"<Questions>"; xml = xml + @"<Question id=""" + qa.QuestionID + @""" text=""" + System.Security.SecurityElement.Escape(qa.QuestionText) + @""" type=""" + qa.AnswerType + @""" mandatory=""" + mandatory + @""">"; xml = xml + @"<Answers>"; xml = xml + @"<Answer id=""" + qa.AnswerID + @""" text=""" + System.Security.SecurityElement.Escape(qa.AnswerText) + @"""/>"; } } xml = xml + @"</Answers></Question></Questions></Brand>"; xml = xml + "</Brands>"; } else { xml = ""; } xml = xml.Replace("(Single Selection)", ""); xml = xml.Replace("(Multiple Selection)", ""); xml = xml.Replace("(Free Text)", ""); xml = xml.Replace("(Integer)", ""); xml = xml.Replace("(Decimal)", ""); client = new SQSAdminServiceClient(); client.Endpoint.Address = new System.ServiceModel.EndpointAddress(CommonVariables.WcfEndpoint); client.SQSAdmin_StudioM_UpdateStudioMAttributeForClusterOrGroup(id, xml, type, loginuser, supplierstring, questionstring, answerstring, mandatorystring, DefaultStateID.ToString()); client.Close(); }