Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.67 KB | None | 0 0
  1. public void InsertOffender(Offender offender)
  2. {
  3.  
  4. using (MySqlCommand command = new MySqlCommand())
  5. {
  6. string[] probationTermArray = offender.currentConviction.ParseConvictionProbation(offender);
  7. command.Connection = this.connection;
  8. // ---- inserting alias ------
  9. command.CommandText = String.Format("INSERT INTO alias (offenders_id, first_name, middle_initial, last_name, updated_by) VALUES ("{0}", "{1}", "{2}", "{3}", {4})", "NY" + offender.offenderId, offender.firstName, offender.middleName, offender.lastName, 5);
  10. command.ExecuteNonQuery();
  11.  
  12. // ------ inserting current conviction ------
  13. command.CommandText = String.Format("INSERT INTO sentencing_info (offenders_id, conviction_date, probation, jail, suprv_agency, arresting_agency) VALUES ("{0}", "{1}", "{2}", "{3}", "{4}", "{5}")", "NY" + offender.offenderId, offender.currentConviction.GetParseableConvictionDate() != null ? DateTime.ParseExact(offender.currentConviction.GetParseableConvictionDate(), "MMM-dd-yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd") : "", probationTermArray[1], probationTermArray[0], offender.supervisingInfo, offender.currentConviction.arrestingAgency);
  14. command.ExecuteNonQuery();
  15.  
  16. // ----- inserting pervious convictions -----
  17. if (offender.perviousConvictions != null)
  18. foreach (Conviction conviction in offender.perviousConvictions)
  19. {
  20. string[] preprobationTermArray = conviction.ParseConvictionProbation(offender);
  21. command.CommandText = String.Format("INSERT INTO sentencing_info (offenders_id, conviction_date, probation, jail, suprv_agency, arresting_agency, Conviction_Type) VALUES ("{0}", "{1}", "{2}", "{3}", "{4}", "{5}", "p")", "NY" + offender.offenderId, conviction.GetParseableConvictionDate() != null ? DateTime.ParseExact(conviction.GetParseableConvictionDate(), "MMM-dd-yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd") : "", preprobationTermArray[1], preprobationTermArray[0], offender.supervisingInfo, conviction.arrestingAgency);
  22. command.ExecuteNonQuery();
  23. }
  24.  
  25. // ------ inserting picture link -----
  26. string possiblePhotoDate = offender.GetParseablePhotoDate();
  27. command.CommandText = String.Format("INSERT INTO offender_pictures (offenders_id, image_name, updated_by, PhotoDate) VALUES ("{0}", "{1}", "{2}", "{3}")", "NY" + offender.offenderId, offender.linkToPic, "5", possiblePhotoDate == null ? "Unknown" : DateTime.Parse(possiblePhotoDate).ToString("yyyy-MM-dd"));
  28. command.ExecuteNonQuery();
  29.  
  30. // ---- inserting markings -----
  31. string MarkingsTemp = "";
  32. if (offender.markings.Length >= 1)
  33. {
  34. foreach (string s in offender.markings)
  35. {
  36. MarkingsTemp = MarkingsTemp + s + "/";
  37. }
  38. MarkingsTemp = MarkingsTemp.Substring(0, MarkingsTemp.Length - 1);
  39. }
  40. else
  41. MarkingsTemp = "NONE REPORTED";
  42. command.CommandText = String.Format("INSERT INTO marks (offenders_id, description) VALUES ("{0}", "{1}")", "NY" + offender.offenderId, MarkingsTemp);
  43. command.ExecuteNonQuery();
  44.  
  45. // ----- inserting addresses -----
  46. //----------------------------------------- I wrote this today, code above of this line was yesterday and it stop working--------------------------------------
  47.  
  48. foreach (Address addr in offender.address)
  49. {
  50. string[] splitAddress = addr.GetComparbleAddress();
  51. if (addr.type.Contains("EMP") && splitAddress != null)
  52. {
  53. command.CommandText = String.Format("INSERT INTO employers (offenders_id, street, city, zip, state_id) VALUES ("{0}", "{1}", "{2}", "{3}", {4})", "NY" + offender.offenderId, splitAddress[0], splitAddress[1], splitAddress[2], 36);
  54. command.ExecuteNonQuery();
  55. }
  56. else
  57. {
  58. if (addr.type.Contains("RES") && addr.type.Contains("Primary"))
  59. {
  60. string haircolor;
  61. Constants.HairConstants.TryGetValue(offender.hairColor.ToUpper().Trim(), out haircolor);
  62. int eyecolor;
  63. Constants.EyeColorConstants.TryGetValue(offender.eyeColor.ToUpper().Trim(), out eyecolor);
  64. int glasses;
  65. Constants.GlassesConstants.TryGetValue(offender.CorrectiveLens.ToUpper().Trim(), out glasses);
  66. int ethnicityid;
  67. string ethnicityString = Address.RemoveSpecialCharacters(offender.ethnicity.Trim().ToUpper());
  68. Constants.EthnicityConstants.TryGetValue(ethnicityString, out ethnicityid);
  69. int raceid = 1;
  70. string raceString = Address.RemoveSpecialCharacters(offender.ethnicity.Replace(" ", "").ToUpper());
  71. if (!raceString.Equals(""))
  72. Constants.RaceConstants.TryGetValue(Constants.RaceConstants.Keys.First(x => x[1].Equals(raceString)), out raceid);
  73. if (splitAddress == null)
  74. {
  75. string toSend = (String.Format("INSERT INTO offenders (dob, sex, first_name, date_created, hair, eyes, glasses, middle_name, last_name, address_line1, city, height, weight, OffDetail, risk_level, special_condition, offender_id, date_modified, designation, victim_relationship, weapon_used, force_used, nysid, scrape_state, state, zipcode, ethnicity_id, county_id, race_id, isgeocoded, created_by_user_id, computer_used, porn_involved, approved_for_web) VALUES ("{0}", "{1}", "{2}", "{3}", "{4}","{5}", "{6}","{7}", "{8}","{9}", "{10}","{11}", "{12}","{13}", "{14}","{15}", "{16}","{17}", "{18}","{19}", "{20}","{21}", "{22}","{23}", "{24}","{25}", "{26}","{27}", "{28}","{29}", "{30}","{31}","{32}","{33}")",
  76. offender.GetParseableDoB() != null ? DateTime.ParseExact(offender.GetParseableDoB(), "MMM-dd-yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd") : "", offender.sex.First(), offender.firstName, DateTime.Now.ToString("yyyy-MM-dd"), haircolor, eyecolor, glasses, offender.middleName, offender.lastName, "",
  77. "", offender.height.Replace("'", "ft").Replace(""", "in"), offender.weight, offender.isWanted ? "Warrant" : offender.currentPlacement, offender.riskLevel, offender.conditions, "NY" + offender.offenderId, DateTime.Now.ToString("yyyy-MM-dd"), offender.designation, offender.currentConviction.relationship, offender.currentConviction.weaponsUsed, offender.currentConviction.forceUsed, offender.offenderId, 36, 36, "", ethnicityid, 360000 + offender.countyid, raceid, (offender.address[0].geoX != null && !offender.address[0].geoX.Equals("")) ? 1 : 0, 5, offender.currentConviction.computerUsed.Contains("No") ? 0 : 1, offender.currentConviction.pornInvolved.Contains("No") ? 0 : 1, 1));
  78. command.CommandText = toSend;
  79. command.ExecuteNonQuery();
  80. }
  81. else
  82. {
  83. string toSend = (String.Format("INSERT INTO offenders (dob, sex, first_name, date_created, hair, eyes, glasses, middle_name, last_name, address_line1, city, height, weight, OffDetail, risk_level, special_condition, offender_id, date_modified, designation, victim_relationship, weapon_used, force_used, nysid, scrape_state, state, zipcode, ethnicity_id, county_id, race_id, isgeocoded, created_by_user_id, computer_used, porn_involved, approved_for_web) VALUES ("{0}", "{1}", "{2}", "{3}", "{4}","{5}", "{6}","{7}", "{8}","{9}", "{10}","{11}", "{12}","{13}", "{14}","{15}", "{16}","{17}", "{18}","{19}", "{20}","{21}", "{22}","{23}", "{24}","{25}", "{26}","{27}", "{28}","{29}", "{30}","{31}","{32}","{33}")",
  84. offender.GetParseableDoB() != null ? DateTime.ParseExact(offender.GetParseableDoB(), "MMM-dd-yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd") : "", offender.sex.First(), offender.firstName, DateTime.Now.ToString("yyyy-MM-dd"), haircolor, eyecolor, glasses, offender.middleName, offender.lastName, splitAddress[0],
  85. splitAddress[1], offender.height.Replace("'", "ft").Replace(""", "in"), offender.weight, offender.currentPlacement, offender.riskLevel, offender.conditions, "NY" + offender.offenderId, DateTime.Now.ToString("yyyy-MM-dd"), offender.designation, offender.currentConviction.relationship, offender.currentConviction.weaponsUsed, offender.currentConviction.forceUsed, offender.offenderId, 36, 36, splitAddress[2], ethnicityid, 360000 + offender.countyid, raceid, (offender.address[0].geoX != null && !offender.address[0].geoX.Equals("")) ? 1 : 0, 5, offender.currentConviction.computerUsed.Contains("No") ? 0 : 1, offender.currentConviction.pornInvolved.Contains("No") ? 0 : 1, 1));
  86. command.CommandText = toSend;
  87. command.ExecuteNonQuery();
  88. }
  89.  
  90. }
  91. else
  92. {
  93. if (splitAddress != null)
  94. {
  95. Console.WriteLine(addr.type + " " + offender.offenderId);
  96. command.CommandText = String.Format("INSERT INTO sec_addr (offender_id, nysid, address_line1, city, state, zipcode, risk_level, TypeAddr) VALUES ("{0}", "{1}", "{2}", "{3}", "{4}", "{5}", "{6}", "RES-SECONDARY")", "NY" + offender.offenderId, offender.offenderId, splitAddress[0], splitAddress[1], 36, splitAddress[2], offender.riskLevel);
  97. command.ExecuteNonQuery();
  98. }
  99. }
  100. }
  101. }
  102.  
  103. //------ inserting vehicles ------------
  104. //------------------------ this little bit was also wrote yesterday and worked---------------------------
  105. Vehicle[] vehicles = offender.currentVehicles;
  106. if (vehicles != null)
  107. foreach (Vehicle v in vehicles)
  108. {
  109. string[] makeModelSplit = v.makeModel.Split(' ');
  110. int stateid = 66;
  111. Constants.StateConstants.TryGetValue((v.state.ToUpper().Replace(" ", "")), out stateid);
  112. command.CommandText = String.Format("INSERT INTO vehicles (offenders_id, vehicle_license_plate, vehicle_year, vehicle_make, vehicle_color, vehicle_model, state_id) VALUES ("{0}", "{1}", "{2}", "{3}", "{4}", "{5}", {6})", "NY" + offender.offenderId, v.plate, v.year, makeModelSplit.Length > 1 ? makeModelSplit[0] : v.makeModel, v.color, makeModelSplit.Length > 1 ? makeModelSplit[1] : "", stateid);
  113. command.ExecuteNonQuery();
  114. }
  115. }
  116. }
  117.  
  118. public static readonly string StatesDirectoryLocation = Path.Combine(Environment.CurrentDirectory, "NY_Offender_OUT");
  119. public static Dictionary<String[], int> RaceConstants;
  120. public static Dictionary<int, int[]> EmailIds;
  121. public static Dictionary<String, String> HairConstants;
  122. public static Dictionary<String, int> GlassesConstants;
  123. public static Dictionary<string, int> EyeColorConstants;
  124. public static Dictionary<string, int> EthnicityConstants;
  125. public static Dictionary<String, int> StateConstants;
  126. public static Dictionary<String, int> CountyContants;
  127.  
  128. public static void loadSqlConstants()
  129. {
  130. MySqlUtils utils = new MySqlUtils();
  131. EthnicityConstants = utils.LoadEthnicityInformation();
  132. EyeColorConstants = utils.LoadEyeColorInformation();
  133. RaceConstants = utils.LoadRaceInformation();
  134. EmailIds = utils.LoadEmailAlertZipcodes();
  135. HairConstants = utils.LoadHairInformation();
  136. GlassesConstants = utils.LoadGlassesInformation();
  137. StateConstants = utils.LoadStateInformation();
  138. CountyContants = utils.LoadCountyId();
  139. utils.close();
  140. }
  141.  
  142. }
  143.  
  144. public Dictionary<string, string> LoadHairInformation()
  145. {
  146. Dictionary<string, string> record = new Dictionary<string, string>();
  147. using (MySqlCommand command = new MySqlCommand())
  148. {
  149. MySqlDataReader rdr = null;
  150. command.Connection = this.connection;
  151. string strQ = String.Format("SELECT * FROM haircolor");
  152. command.CommandText = strQ;
  153. command.Prepare();
  154. rdr = command.ExecuteReader();
  155. while (rdr.Read())
  156. {
  157. record.Add(rdr.GetString(2).ToUpper(), rdr.GetString(1));
  158. }
  159. rdr.Close();
  160. }
  161. return record;
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement