public bool FillITPInventoryMainTable(string sSessionId, string sUser, ref string sRtnMsg)
        {
            try
            {
                clsTabletDB.ITPStaticTable Static = new clsTabletDB.ITPStaticTable();
                clsTabletDB.ITPInventory ITPInventory = new clsTabletDB.ITPInventory();
                LocalDB DB = new LocalDB();
                double dNewVersionNumber = 0.0;
                DateTime dtLastVersionDate;
                DateTime dtToday = DateTime.Now;
                string sITPInventoryTableName = ITPInventory.sITPInventoryTableName;

                //Only do all of this if the version has changed. So get the local version number and compare to that on the DB. If different do all of this. - WRITE LATER as a general function
                bool bNewVersion = Static.IsNewVersionOfTable(sSessionId, sUser, sITPInventoryTableName, ref dNewVersionNumber, ref dtLastVersionDate);
                TimeSpan ts = dtToday - dtLastVersionDate;
                int iDaysSinceUpdate = ts.Days;

                if (!DB.TableExists(sITPInventoryTableName) || bNewVersion || iDaysSinceUpdate >= 30)
                {
                    clsLocalUtils util = new clsLocalUtils();
                    string sURL = util.GetEnvironment_wbsURL("wbsITP_External");
                    wbsITP_External ws = new wbsITP_External();
                    ws.Url = sURL;
                    object[] objInventory = ws.GetITPInventoryInfo(sSessionId, sUser);
                    if (objInventory[0].ToString() == "Success")
                    {
                        if (ITPInventory.TableITPInventoryDeleteAllRecords(ref sRtnMsg))
                        {
                            string sITPInventoryInfo = objInventory[1].ToString();
                            string[] sHeaderInfo = sITPInventoryInfo.Split('~');
                            if (sHeaderInfo[0] == "ITPInventoryMakeAndModelInfo")
                            {
                                string[] delimiters = new string[] { "||" };
                                string[] sITPInventoryItems = sHeaderInfo[1].Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                                int iInventoryCount = sITPInventoryItems.Length;
                                if (iInventoryCount > 0)
                                {
                                    this.InvokeOnMainThread(() => { progBarInventoryVw.ShowProgressBar(iInventoryCount); });
                                    //First check if the ITPInventory table exists and if not create it
                                    if (ITPInventory.CheckFullITPInventoryTable())
                                    {
                                        for (int i = 0; i < iInventoryCount; i++)
                                        {
                                            string[] delimiters2 = new string[] { "^" };
                                            string[] sInventoryItems = sITPInventoryItems[i].Split(delimiters2, StringSplitOptions.None);
                                            ITPInventory.TableITPInventoryAddRecord(sInventoryItems);
                                            this.InvokeOnMainThread(() => { progBarInventoryVw.UpdateProgressBar(i + 1); });
                                        }
                                    }
                                }
                            }
                        }
                        //Update the version number locally
                        Static.UpdateVersionNumber(sITPInventoryTableName, dNewVersionNumber);
                        this.InvokeOnMainThread(() => { progBarInventoryVw.CloseProgressBar(); });
                        return true;
                    }
                    else
                    {
                        sRtnMsg = objInventory[1].ToString();
                        return false;
                    }
                }
                else
                {
                    //This means you don't have to fill this static table
                    return true;
                }
            }
            catch (Exception ex)
            {
                sRtnMsg = "Failure" + ex.Message.ToString();
                return false;
            }
        }
        public bool FillITPValidHierarchyTable(string sSessionId, string sUser, ref string sRtnMsg)
        {
            try
            {
                clsTabletDB.ITPStaticTable Static = new clsTabletDB.ITPStaticTable();
                clsTabletDB.ITPValidHierarchy ITPValidHierarchy = new clsTabletDB.ITPValidHierarchy();
                LocalDB DB = new LocalDB();
                double dNewVersionNumber = 0.0;
                DateTime dtLastVersionDate;
                string sITPValidHierarchyTableName = ITPValidHierarchy.sITPValidHierarchyTableName;

                //Only do all of this if the version has changed. So get the local version number and compare to that on the DB. If different do all of this. - WRITE LATER as a general function
                bool bNewVersion = Static.IsNewVersionOfTable(sSessionId, sUser, sITPValidHierarchyTableName, ref dNewVersionNumber, ref dtLastVersionDate);

                if (!DB.TableExists(sITPValidHierarchyTableName) || bNewVersion)
                {
                    clsLocalUtils util = new clsLocalUtils();
                    string sURL = util.GetEnvironment_wbsURL("wbsITP_External");
                    wbsITP_External ws = new wbsITP_External();
                    ws.Url = sURL;
                    object[] objValidHierarchy = ws.GetITPValidHierarchyInfo(sSessionId, sUser);
                    if (objValidHierarchy[0].ToString() == "Success")
                    {
                        if (ITPValidHierarchy.TableITPValidHierarchyDeleteAllRecords(ref sRtnMsg))
                        {
                            string sITPValidHierarchyInfo = objValidHierarchy[1].ToString();
                            string[] sHeaderInfo = sITPValidHierarchyInfo.Split('~');
                            if (sHeaderInfo[0] == "ITPValidHierarchyInfo")
                            {
                                string[] delimiters = new string[] { "||" };
                                string[] sITPValidHierarchyItems = sHeaderInfo[1].Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                                int iValidHierarchyCount = sITPValidHierarchyItems.Length;
                                if (iValidHierarchyCount > 0)
                                {
                                    this.InvokeOnMainThread(() => { progBarValidHierarchyVw.ShowProgressBar(iValidHierarchyCount); });
                                    //First check if the ITPValidHierarchy table exists and if not create it
                                    if (ITPValidHierarchy.CheckFullITPValidHierarchyTable())
                                    {
                                        SqliteConnection conn = DB.OpenConnection();
                                        for (int i = 0; i < iValidHierarchyCount; i++)
                                        {
                                            string[] delimiters2 = new string[] { "^" };
                                            string[] sValidHierarchyItems = sITPValidHierarchyItems[i].Split(delimiters2, StringSplitOptions.None);
                                            string sFieldValue = sValidHierarchyItems[0];
                                            string sFieldType = sValidHierarchyItems[1];
                                            Array.Resize<string>(ref sValidHierarchyItems, sValidHierarchyItems.Length + 1);
                                            sValidHierarchyItems[sValidHierarchyItems.Length - 1] = sFieldType;
                                            sValidHierarchyItems[sValidHierarchyItems.Length - 2] = sFieldValue;
                                            sValidHierarchyItems[0] = i.ToString();
                                            ITPValidHierarchy.TableITPValidHierarchyAddRecord(sValidHierarchyItems, conn);
                                            this.InvokeOnMainThread(() => { progBarValidHierarchyVw.UpdateProgressBar(i + 1); });
                                        }
                                        DB.CloseConnection(conn);

                                    }
                                }
                            }
                        }
                        //Update the version number locally
                        Static.UpdateVersionNumber(sITPValidHierarchyTableName, dNewVersionNumber);
                        this.InvokeOnMainThread(() => { progBarValidHierarchyVw.CloseProgressBar(); });
                        return true;
                    }
                    else
                    {
                        sRtnMsg = objValidHierarchy[1].ToString();
                        return false;
                    }
                }
                else
                {
                    //This means you don't have to fill this static table
                    return true;
                }
            }
            catch (Exception ex)
            {
                sRtnMsg = "Failure" + ex.Message.ToString();
                return false;
            }
        }
        public bool DownloadStaticTables(string sUser, string sSessionId)
        {
            string sRtnMsg = "";
            bool bReturn;
            clsTabletDB.ITPStaticTable clsStatic = new clsTabletDB.ITPStaticTable();

            clsStatic.CheckStaticTable();

            bReturn = FillQuestionnaireMainTable(sSessionId, sUser, ref sRtnMsg);

            if (sRtnMsg != "")
            {
                this.InvokeOnMainThread(() => {
                    iUtils.AlertBox alert = new iUtils.AlertBox();
                    alert.CreateErrorAlertDialog(sRtnMsg);
                });
                return false;
            }

            bReturn = FillITPTypeMainTable(sSessionId, sUser, ref sRtnMsg);

            if (sRtnMsg != "")
            {
                this.InvokeOnMainThread(() => {
                    iUtils.AlertBox alert = new iUtils.AlertBox();
                    alert.CreateErrorAlertDialog(sRtnMsg);
                });
                return false;
            }

            bReturn = FillITPDocumentSectionMainTable(sSessionId, sUser, ref sRtnMsg);

            if (sRtnMsg != "")
            {
                this.InvokeOnMainThread(() => {
                    iUtils.AlertBox alert = new iUtils.AlertBox();
                    alert.CreateErrorAlertDialog(sRtnMsg);
                });
                return false;
            }

            bReturn = FillITPInventoryMainTable(sSessionId, sUser, ref sRtnMsg);

            if (sRtnMsg != "")
            {
                this.InvokeOnMainThread(() => {
                    iUtils.AlertBox alert = new iUtils.AlertBox();
                    alert.CreateErrorAlertDialog(sRtnMsg);
                });
                return false;
            }

            //            bReturn = FillITPInventoryMainTable(sSessionId, sUser, ref sRtnMsg);
            //
            //            if (sRtnMsg != "")
            //            {
            //                this.InvokeOnMainThread(() => {
            //                    iUtils.AlertBox alert = new iUtils.AlertBox();
            //                    alert.CreateErrorAlertDialog(sRtnMsg);
            //                });
            //                return false;
            //            }

            bReturn = FillITPBatteryFuseTypesTable(sSessionId, sUser, ref sRtnMsg);

            if (sRtnMsg != "")
            {
                this.InvokeOnMainThread(() => {
                    iUtils.AlertBox alert = new iUtils.AlertBox();
                    alert.CreateErrorAlertDialog(sRtnMsg);
                });
                return false;
            }

            bReturn = FillITPValidHierarchyTable(sSessionId, sUser, ref sRtnMsg);

            if (sRtnMsg != "")
            {
                this.InvokeOnMainThread(() => {
                    iUtils.AlertBox alert = new iUtils.AlertBox();
                    alert.CreateErrorAlertDialog(sRtnMsg);
                });
                return false;
            }

            return bReturn;
        }