Esempio n. 1
0
        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;
            }
        }