示例#1
0
        private static void LoadNcicCodes(string classicRmsConnectionString, Domain.Administration.Aggregates.Agency.Agency agency, string propertyClass, string className,
                                          string codeField, string codeDescriptionField, string mapPropertyClass = null)
        {
            using (var conn = new SqlConnection(classicRmsConnectionString))
            {
                conn.Open();

                // if a mapPropertyClass is passed use it, otherwise use propertyClass
                var codeSet = agency.CreateCodeSet(mapPropertyClass ?? propertyClass, className, "");

                using (var codeData = new DataSet())
                {
                    var codevalueSelect =
                        String.Format(
                            "SELECT [NCIC_Property_Code_Link], [Class], [Category], [Category_desc], [Property_Code], [Property_Code_Desc], [Date_Entered] FROM [VSI_SYSTEM].[dbo].[NCIC_Property_Code]  where Class = '{0}' ",
                            propertyClass);

                    using (var adapter = new SqlDataAdapter(codevalueSelect, conn)) adapter.Fill(codeData, "CodeValues");

                    Log.Info("Importing {0} {1} codes into {2}", codeData.Tables["CodeValues"].Rows.Count, className, agency.Jurisdiction.Ori);

                    foreach (DataRow code in codeData.Tables["CodeValues"].Rows)
                    {
                        var classicId = code["NCIC_Property_Code_Link"].ToString();

                        var codeValue     = codeSet.CreateCode(code[codeField] as string, code[codeDescriptionField] as string, String.Format("{0}N", classicId));
                        var effectiveDate = DateTime.Now;
                        DateTime.TryParse(code["Date_Entered"] as string, out effectiveDate);
                        codeValue.SetLifetime(effectiveDate, DateTime.MaxValue);
                    }
                }
            }
        }
示例#2
0
        private static void LoadSystemCodesFromClassicRms(Domain.Administration.Aggregates.Agency.Agency agency, string classicRmsConnectionString)
        {
            using (var conn = new SqlConnection(classicRmsConnectionString))
            {
                conn.Open();

                using (var systemCodesData = new DataSet())
                {
                    const string categorySelect = "SELECT DISTINCT [Category], [Code_Name] FROM [VSI_SYSTEM].[dbo].[System_Code]";

                    using (var adapter = new SqlDataAdapter(categorySelect, conn))
                        adapter.Fill(systemCodesData, "Categories");

                    Log.Info("Importing {0} System Code Categories into {1}", systemCodesData.Tables["Categories"].Rows.Count, agency.Jurisdiction.Ori);

                    foreach (DataRow categoryRow in systemCodesData.Tables["Categories"].Rows)
                    {
                        var category = categoryRow["Category"] as string;
                        var codeName = categoryRow["Code_Name"] as string;

                        // just in case
                        if (string.IsNullOrEmpty(category))
                        {
                            Log.Info(@"WARNING: Blank Category Detected for Code_Name '{0}'", codeName);
                            continue;
                        }

                        // Find or create codeset using category
                        var codeSet = agency.CodeSets.FirstOrDefault(x => x.Category == category) ?? agency.CreateCodeSet(category, codeName, codeName);

                        using (var codeData = new DataSet())
                        {
                            var codevalueSelect =
                                String.Format(
                                    "SELECT [System_Code_Link], [Category], [Code], [Description], [Date_Entered] FROM [VSI_SYSTEM].[dbo].[System_Code]  where category = '{0}' ",
                                    category);

                            using (var adapter = new SqlDataAdapter(codevalueSelect, conn))
                                adapter.Fill(codeData, "CodeValues");

                            foreach (DataRow codeRow in codeData.Tables["CodeValues"].Rows)
                            {
                                var classicId   = codeRow["System_Code_Link"].ToString();
                                var value       = codeRow["Code"] as string;
                                var description = codeRow["Description"] as string;
                                var dateEntered = codeRow["Date_Entered"].ToString();

                                var      codeValue = codeSet.CreateCode(value, description, String.Format("{0}S", classicId));
                                DateTime effectiveDate;
                                if (DateTime.TryParse(dateEntered, out effectiveDate))
                                {
                                    codeValue.SetLifetime(effectiveDate, DateTime.MaxValue);
                                }
                                else
                                {
                                    codeValue.MakeActive();
                                }
                            }
                        }
                    }
                }
            }
        }