private void ParseWell(XmlReader rdr, WellInfo parentWell = null)
        {
            WellInfo wellInfo = new WellInfo();

            _wellInfo.Add(wellInfo);
            wellInfo.ParentWell = parentWell;
            while (rdr.Read())
            {
                if (rdr.IsStartElement())
                {
                    if (rdr.Name == "WellMisc")
                    {
                        wellInfo.WellName   = rdr.GetAttribute("wellName");
                        wellInfo.FileNumber = rdr.GetAttribute("fileNumber");
                    }
                    if (rdr.Name == "PlanList")
                    {
                        if (!rdr.IsEmptyElement)
                        {
                            ParsePlans(rdr.ReadSubtree(), wellInfo);
                        }
                    }
                    if (rdr.Name == "ChildWells")
                    {
                        if (!rdr.IsEmptyElement)
                        {
                            ParseChildWellList(rdr.ReadSubtree(), wellInfo);
                        }
                    }
                }
            }
        }
 private void ParseChildWellList(XmlReader rdr, WellInfo parentWell)
 {
     while (rdr.ReadToFollowing("Well"))
     {
         ParseWell(rdr.ReadSubtree(), parentWell);
     }
 }
        private void ParsePlanVersion(XmlReader rdr, WellInfo wi, string planName)
        {
            while (rdr.Read())
            {
                if (rdr.IsStartElement())
                {
                    if (rdr.Name == "VersionInfo")
                    {
                        PlanVersionInfo pvi = new PlanVersionInfo
                        {
                            PlanName      = planName,
                            VersionName   = rdr.GetAttribute("versionName"),
                            Comment       = rdr.GetAttribute("comment"),
                            IsCurrentPlan = false
                        };

                        DateTime.TryParse(rdr.GetAttribute("versionDateCreated"), out var creationDate);
                        pvi.CreationDate = creationDate;

                        bool.TryParse(rdr.GetAttribute("isDefinitivePlan"), out bool isDefinitivePlan);
                        pvi.IsDefinitivePlan = isDefinitivePlan;

                        wi.PlanVersionList.Add(pvi);
                    }
                }
            }
        }
 private void ParsePlans(XmlReader rdr, WellInfo wi)
 {
     while (rdr.ReadToFollowing("Plan"))
     {
         ParsePlan(rdr.ReadSubtree(), wi);
     }
     if (wi.PlanVersionList.Count > 0)
     {
         var lastPlanVersion = wi.PlanVersionList[wi.PlanVersionList.Count - 1];
         lastPlanVersion.IsCurrentPlan = true;
     }
 }
        private void ParsePlan(XmlReader rdr, WellInfo wi)
        {
            string planName = string.Empty;

            while (rdr.Read())
            {
                if (rdr.IsStartElement())
                {
                    if (rdr.Name == "PlanInfo")
                    {
                        planName = rdr.GetAttribute("planName");
                    }
                    if (rdr.Name == "Version")
                    {
                        ParsePlanVersion(rdr.ReadSubtree(), wi, planName);
                    }
                }
            }
        }
        private void AddPlanVersionData(SQLiteConnection conn, SQLiteTransaction txn, ModelRecord record, WellInfo wi, int wellID)
        {
            using (var cmd = new SQLiteCommand(conn))
            {
                cmd.Transaction = txn;
                foreach (var pvi in wi.PlanVersionList)
                {
                    cmd.CommandText = "INSERT INTO [PlanVersions] VALUES (NULL, $modelID, $wellID, $planName, $versionName, $comment, $creationDate, $isDefinitive, $isCurrent)";

                    cmd.Parameters.AddWithValue("$modelID", record.ID);
                    cmd.Parameters.AddWithValue("$wellID", wellID);
                    cmd.Parameters.AddWithValue("$planName", pvi.PlanName);
                    cmd.Parameters.AddWithValue("$versionName", pvi.VersionName);
                    cmd.Parameters.AddWithValue("$comment", pvi.Comment);
                    cmd.Parameters.AddWithValue("$creationDate", pvi.CreationDate);
                    cmd.Parameters.AddWithValue("$isDefinitive", pvi.IsDefinitivePlan ? 1 : 0);
                    cmd.Parameters.AddWithValue("$isCurrent", pvi.IsCurrentPlan ? 1 : 0);

                    cmd.ExecuteNonQuery();
                }
            }
        }