public void ProcessRequest(HttpContext context) { int id = Convert.ToInt32(context.Request["id"]); mydbEntities1 db = new mydbEntities1(); user new1 = db.users.Single(u => u.id == id); db.DeleteObject(new1); db.SaveChanges(); var p1 = new result(); if (new1 != null) { p1.success = true; p1.msg = "aaa"; } else { p1.success = false; p1.msg = "Some errors occured."; } DataContractJsonSerializer json = new DataContractJsonSerializer(p1.GetType()); json.WriteObject(context.Response.OutputStream, p1); }
/// <summary> /// Perform a Matching Test to ensure no Schema elements are missing from the Element Mapping File /// </summary> /// <param name="elementMappingTable">The Element Mapping Table</param> private void PerformMatchingTest(DataTable elementMappingTable) { this.mainWindowObject.StatusLabel.Content = "Performing a Matching Test to ensure no Schema elements are missing from the Element Mapping File..."; DoEvents(); result matchingTest = new result(); List <string> elementsNotInMappingFile = new List <string>(); Type matchingType = matchingTest.GetType(); PropertyInfo[] matchingProps = matchingType.GetProperties(); foreach (PropertyInfo p in matchingProps) { if (this.GetDataColumnName(p.Name, elementMappingTable) == null) { if (!p.Name.Contains("Specified")) { elementsNotInMappingFile.Add(p.Name); } } } if (elementsNotInMappingFile.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (string element in elementsNotInMappingFile) { sb.Append(element + Environment.NewLine); } MessageBox.Show("The following schema elements are not in the Mapping File and will be ignored:" + Environment.NewLine + Environment.NewLine + sb.ToString()); } }
/// <summary> /// Get a list of results to be appended to the dataset object /// </summary> /// <param name="rows">The Data Rows from the supplied Data File </param> /// <param name="elementMappingTable">The Element Mapping Table</param> /// <returns>A list of XML Element result objects</returns> private List <result> GetResults(List <DataRow> rows, DataTable elementMappingTable) { this.mainWindowObject.StatusLabel.Content = "Generating XML ..."; DoEvents(); this.mainWindowObject.pbrDecoding.Value = 0; this.mainWindowObject.pbrDecoding.Minimum = 0; this.mainWindowObject.pbrDecoding.Maximum = rows.Count; try { List <result> results = new List <result>(); foreach (DataRow row in rows) { this.mainWindowObject.pbrDecoding.Value = rows.IndexOf(row) + 1; DoEvents(); result resultObject = new result(); Type t = resultObject.GetType(); PropertyInfo[] props = t.GetProperties(); foreach (PropertyInfo p in props) { this.CreateXMLElement(p.Name, row, resultObject, elementMappingTable); } results.Add(resultObject); } return(results); } catch (Exception ex) { MessageBox.Show("Error getting results: " + ex.Message); return(null); } }
public void ProcessRequest(HttpContext context) { int id =Convert.ToInt32(context.Request["id"]); string firstname = context.Request["firstname"]; string lastname = context.Request["lastname"]; string phone = context.Request["phone"]; string email = context.Request["email"]; mydbEntities1 db = new mydbEntities1(); user new1 = db.users.Single(u => u.id == id); new1.firstname = firstname; new1.lastname = lastname; new1.phone = phone; new1.email = email; db.SaveChanges(); var p1 = new result(); if (new1 != null) { p1.success = true; p1.msg = "aaa"; } else { p1.success = false; p1.msg = "Some errors occured."; } DataContractJsonSerializer json = new DataContractJsonSerializer(p1.GetType()); json.WriteObject(context.Response.OutputStream, p1); }
public void ProcessRequest(HttpContext context) { string firstname = context.Request.Form["firstname"]; string lastname = context.Request.Form["lastname"]; string phone = context.Request.Form["phone"]; string email = context.Request.Form["email"]; mydbEntities1 db = new mydbEntities1(); user p = new user(); p.firstname = firstname; p.lastname = lastname; p.phone = phone; p.email = email; db.AddTousers(p); db.SaveChanges(); var p1 = new result(); if (p != null) { p1.success = true; p1.msg = "aaa"; } else { p1.success = false; p1.msg = "Some errors occured."; } DataContractJsonSerializer json = new DataContractJsonSerializer(p1.GetType()); json.WriteObject(context.Response.OutputStream, p1); }
/// <summary> /// Create the XML Element /// </summary> /// <param name="resultElementName">The Name of the XML Element to be created</param> /// <param name="row">The DataRow from the DBF file</param> /// <param name="resultObject">The result object being added</param> /// <param name="elementMappingTable">The DataTable containing the Element Mapping</param> private void CreateXMLElement(string resultElementName, DataRow row, result resultObject, DataTable elementMappingTable) { // Get the DBF Column name from the codes.xml file string dataColumnName = this.GetDataColumnName(resultElementName, elementMappingTable); // Ensure that such a DBF Column exists if (dataColumnName != null && row.Table.Columns.Contains(dataColumnName)) { // Get the content of the DBF column string givenString = row[dataColumnName].ToString().Trim(); // If there is conent, create the XML element, otherwise skip if (givenString != string.Empty) { PropertyInfo prop = resultObject.GetType().GetProperty(resultElementName, BindingFlags.Public | BindingFlags.Instance); if (prop != null && prop.CanWrite) { if (prop.PropertyType == typeof(string)) { prop.SetValue(resultObject, givenString, null); } if (prop.PropertyType == typeof(decimal)) { decimal decimalValue; decimal.TryParse(givenString, out decimalValue); prop.SetValue(resultObject, decimalValue, null); PropertyInfo propSpecified = resultObject.GetType().GetProperty(resultElementName + "Specified", BindingFlags.Public | BindingFlags.Instance); if (propSpecified != null && propSpecified.CanWrite && decimalValue != 0) { propSpecified.SetValue(resultObject, true, null); } } if (prop.PropertyType == typeof(SSDCompoundType)) { if (givenString.IndexOf("=") > -1) { // If there is a $ separator, there are multiple attributes string[] attributeArray; if (givenString.IndexOf("$") > -1) { attributeArray = givenString.Split("$".ToCharArray()); } else { attributeArray = new string[1]; attributeArray[0] = givenString; } List <SSDCompoundTypeValue> values = new List <SSDCompoundTypeValue>(); for (int i = 0; i < attributeArray.Length; i++) { SSDCompoundTypeValue ctv = new SSDCompoundTypeValue(); ctv.name = attributeArray[i].Split("=".ToCharArray())[0]; ctv.Value = attributeArray[i].Split("=".ToCharArray())[1]; values.Add(ctv); } SSDCompoundType newSSDCompoundType = new SSDCompoundType(); newSSDCompoundType.value = values.ToArray(); prop.SetValue(resultObject, newSSDCompoundType, null); } else { SSDCompoundType newSSDCompoundType = new SSDCompoundType(); newSSDCompoundType.Text = new string[1]; newSSDCompoundType.Text[0] = givenString; prop.SetValue(resultObject, newSSDCompoundType, null); } } if (prop.PropertyType == typeof(SSDRepeatableType)) { SSDRepeatableType newSSDRepeatableType = new SSDRepeatableType(); //// List<String> rvalues = new List<String>(); //// rvalues.Add(givenString); //// newSSDRepeatableType.value = rvalues.ToArray(); newSSDRepeatableType.Text = new string[1]; newSSDRepeatableType.Text[0] = givenString; prop.SetValue(resultObject, newSSDRepeatableType, null); } } } } }