Exemplo n.º 1
0
        public void UpdateTable(object objDataviewName)
        {
            string dataviewName = (string)objDataviewName;
            bool updateStatus = false;
            DataTable lookupTableStatus = new DataTable("lookup_table_status");
            DataRow lookupTableStatusRow = null;
            if (_localData.TableExists("lookup_table_status"))
            {
                lookupTableStatus = _localData.GetData("SELECT * FROM lookup_table_status WHERE dataview_name=@dataviewname", new string[1] { "@dataviewname=" + dataviewName });
            }

            if (lookupTableStatus != null &&
                lookupTableStatus.Rows.Count > 0)
            {
                lookupTableStatusRow = lookupTableStatus.Rows[0];
            }

            if (lookupTableStatusRow != null &&
                (lookupTableStatusRow["status"].ToString().Trim().ToUpper() == "COMPLETED" ||
                lookupTableStatusRow["status"].ToString().Trim().ToUpper() == "UPDATED"))
            {
                // Use the last sync date for the remote database query...
                DateTime lastSyncDate = new DateTime();
                lastSyncDate = Convert.ToDateTime(lookupTableStatus.Rows[0]["sync_date"].ToString());

                if (lastSyncDate.AddSeconds(5) < DateTime.UtcNow)
                {
                    int pageSize = 100000;
            //string selectParams = ":createddate=" + lastSyncDate.ToString("u") + "; :modifieddate=" + lastSyncDate.ToString("u") + "; :valuemember=; :startpkey=; :stoppkey=; :displaymember;";
            string selectParams = ":createddate=" + lastSyncDate.ToString("s") + "; :modifieddate=" + lastSyncDate.ToString("s") + "; :valuemember=; :startpkey=; :stoppkey=; :displaymember;";

                    // Go get the records from the remote database that are newer than the lastSyncDate...
                    DataSet tempSync = _webServices.GetData(dataviewName, selectParams, 0, pageSize);
                    if (tempSync.Tables.Contains(dataviewName))
                    {
                        DataTable syncTable = tempSync.Tables[dataviewName].Clone();
                        //// Apply any column constraints (indicated in the column extended properties) to the table...
                        //ApplyColumnConstraints(syncTable);
                        syncTable.Rows.Clear();
                        syncTable.AcceptChanges();
                        syncTable.Load(tempSync.Tables[dataviewName].CreateDataReader(), LoadOption.Upsert);
                        if (syncTable.Rows.Count == 0)
                        {
                            lookupTableStatusRow["current_pk"] = lookupTableStatusRow["max_pk"];
                            lookupTableStatusRow["status"] = "Updated";
                            lookupTableStatusRow["sync_date"] = DateTime.UtcNow;
                            updateStatus = true;
                        }
                        else if (syncTable.Rows.Count > 0 &&
                            syncTable.Rows.Count < pageSize)
                        {
                            // Check to make sure the user wants to update this table...
                            if (lookupTableStatusRow["auto_update"].ToString().Trim().ToUpper() == "Y")
                            {
                                // Save the new lookup table rows to the local database...
                                SaveDataPageToLocalDB(syncTable);
                                // Update the dictionary if one is being used...
                                if (_pkeyLUTCacheCollection.ContainsKey(dataviewName))
                                {
                                    UpdatePKeyLUTDictionary(dataviewName, _pkeyLUTCacheCollection[dataviewName]);
                                }
                                else if (dataviewName.ToLower().Trim() == "code_value_lookup")
                                {
                                    UpdateCodeValueLUTDictionary("code_value_lookup", _codevalueLUTCache);
                                }

                                // Update the stats for this lookup table in the lookup_table_status table on the local database...
                                lookupTableStatusRow["current_pk"] = lookupTableStatusRow["max_pk"];
                                lookupTableStatusRow["status"] = "Updated";
                                lookupTableStatusRow["sync_date"] = DateTime.UtcNow;
                                updateStatus = true;
                            }
                            else
                            {
                                // If the user does not want to update this table but there are less than 1000 new records that need to be downloaded
                                // mark its status as 'PARTIAL' so that the LUT maint. dialog displays warnings properly
                                Int64 max = pageSize + 1;
                                Int64 current = 0;
                                if (Int64.TryParse(lookupTableStatusRow["max_pk"].ToString(), out max) &&
                                    Int64.TryParse(lookupTableStatusRow["current_pk"].ToString(), out current) &&
                                    (max - current) > pageSize)
                                {
                                    lookupTableStatusRow["status"] = "Partial";
                                }
                                updateStatus = false;
                            }
                        }
                        else
                        {
                            lookupTableStatusRow["status"] = "Failed";
                            lookupTableStatusRow["sync_date"] = DateTime.UtcNow;
                            updateStatus = true;
                        }
                        SaveDataPageToLocalDB(lookupTableStatus);
                    }
                    else
                    {
                        // No dataview named 'XXX' exists in the sys_dataview table.
                        // Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
                        if (tempSync.Tables.Contains("ExceptionTable") &&
                            tempSync.Tables["ExceptionTable"].Rows.Count > 0 &&
                            !tempSync.Tables["ExceptionTable"].Rows[0]["Message"].ToString().Contains("Timeout expired"))
                        {
                            // There appears to be a problem getting data for this lookup table (most likely the LU dataview is missing/broken)...
            //lookupTableStatusRow.Delete();
            //SaveDataPageToLocalDB(lookupTableStatus);
            //if (_localData.TableExists(dataviewName)) _localData.Remove(dataviewName);
                            updateStatus = true;
                        }
                    }
                }
                else
                {
                    // This table was successfully updated in the last 10 seconds so
                    // skip the update and return successful status...
                    updateStatus = true;
                }
            }
            else
            {
            //System.Windows.Forms.MessageBox.Show("WARNING!\nThe system can not perform Update for '" + dataviewName + "' until the table has been successfully downloaded", "Partially Loaded Lookup Table", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
            SharedUtils sharedUtils = new SharedUtils(_webServices.Url, _webServices.Username, _webServices.Password_ClearText, true, "");
            GRINGlobal.Client.Common.GGMessageBox ggMessageBox = new GRINGlobal.Client.Common.GGMessageBox("WARNING!\nThe system can not perform Update for '{0}' until the table has been successfully downloaded.\n\nWould you like to do this now?", "Partially Loaded Lookup Table", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxDefaultButton.Button1);
            ggMessageBox.Name = "LookupTables_LoadTableFromDatabaseMessage3";
            if (sharedUtils != null && sharedUtils.IsConnected) sharedUtils.UpdateControls(ggMessageBox.Controls, ggMessageBox.Name);
            //if (ggMessageBox.MessageText.Contains("{0}")) ggMessageBox.MessageText = string.Format(ggMessageBox.MessageText, dataviewName.ToUpper());
            string[] argsArray = new string[100];
            argsArray[0] = dataviewName.ToUpper();
            ggMessageBox.MessageText = string.Format(ggMessageBox.MessageText, argsArray);
            //ggMessageBox.ShowDialog();
            if (System.Windows.Forms.DialogResult.Yes == ggMessageBox.ShowDialog())
            {
            // Start the LUT maintenance dialog...
            //LookupTableLoader ltl = new LookupTableLoader(localDBInstance, _sharedUtils);
            LookupTableLoader ltl = new LookupTableLoader(_localData.ConnectionString, sharedUtils);
            ltl.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            ltl.ShowDialog();
            }
            updateStatus = false;

            }

            // Clear the lookup table status cache (so that it can be refreshed for each lookup table on demand)...
            _lookupTableStatus.Clear();
            //return updateStatus;
        }
Exemplo n.º 2
0
 void tsmiLanguage_Click(object sender, EventArgs e)
 {
     int newLangID = 1;
     ToolStripMenuItem tsmi = (ToolStripMenuItem) sender;
     if (int.TryParse(tsmi.Tag.ToString(), out newLangID))
     {
         _sharedUtils.ChangeLanguage(newLangID);
         languageCode = newLangID.ToString();
         _sharedUtils.UserLanguageCode = newLangID;
         _sharedUtils.UpdateComponents(this.components.Components, this.Name);
         _sharedUtils.UpdateControls(this.Controls, this.Name);
         // Save the statusbar text for the left, center, and right controls...
         ux_statusLeftMessage.Tag = ux_statusLeftMessage.Text;
         ux_statusCenterMessage.Tag = ux_statusCenterMessage.Text;
         ux_statusRightMessage.Tag = ux_statusRightMessage.Text;
         ux_statusRightMessage.Text = "";
         // Refresh the DGV data to get new column headings...
         ux_buttonRefreshData.PerformClick();
     // Warn the user that they should reload their LU tables...
     GRINGlobal.Client.Common.GGMessageBox ggMessageBox = new GRINGlobal.Client.Common.GGMessageBox("You have successfully changed your language to {0}.\n\nWarning: Your lookup tables are language specific so you should reload them very soon.\n\nWould you like to do this now?", "Reload Lookup Tables", MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button1);
     ggMessageBox.Name = "tsmiLanguage1";
     _sharedUtils.UpdateControls(ggMessageBox.Controls, ggMessageBox.Name);
     if (ggMessageBox.MessageText.Contains("{0}")) ggMessageBox.MessageText = string.Format(ggMessageBox.MessageText, tsmi.Text);
     if (DialogResult.Yes == ggMessageBox.ShowDialog())
     {
     // Reload LU tables now...
     LookupTableLoader ltl = new LookupTableLoader(localDBInstance, _sharedUtils);
     ltl.StartPosition = FormStartPosition.CenterParent;
     ltl.Show();
     }
     }
 }
Exemplo n.º 3
0
        private void ux_buttonLookupTableMaintenance_Click(object sender, EventArgs e)
        {
            //LookupTableLoader ltl = new LookupTableLoader(localDBInstance, lookupTables);
            LookupTableLoader ltl = new LookupTableLoader(localDBInstance, _sharedUtils);
            ltl.StartPosition = FormStartPosition.CenterParent;
            ltl.Show();
            //ltl.Focus();

            // Change cursor to the wait cursor...
            //Cursor origCursor = Cursor.Current;
            //Cursor.Current = Cursors.WaitCursor;

            //GrinGlobalClient.ActiveForm.Enabled = false;
            //lookupTables.ResetLookupTables();
            //lookupTables.GetUpdates();
            //GrinGlobalClient.ActiveForm.Enabled = true;

            // Restore cursor to default cursor...
            //Cursor.Current = origCursor;
        }
Exemplo n.º 4
0
        private void LookupTableStatusCheck()
        {
            //// Display the splash page to let the user know that things are happening...
            //Splash splash = new Splash();
            //splash.StartPosition = FormStartPosition.CenterScreen;
            //splash.Show();
            //splash.Update();
            try
            {
                int partiallyLoadedTables = 0;
                DataTable lookupTableStatus = _sharedUtils.LookupTablesGetSynchronizationStats();
                if (lookupTableStatus != null &&
                    lookupTableStatus.Rows.Count > 0)
                {
                    foreach (DataRow dr in lookupTableStatus.Rows)
                    {
                        if (dr["status"].ToString().Trim().ToUpper() != "COMPLETED" &&
                            dr["status"].ToString().Trim().ToUpper() != "UPDATED")
                        {
                            // The program will not auto-update a partially loaded LUT because there could potentially
                            // be 10s of thousands of missing records - so just bail out and warn the user...
                            if (ux_checkboxWarnWhenLUTablesAreOutdated.Checked) partiallyLoadedTables++;
                        }
                        else
                        {
            //// If the attempted update fails for any reason - warn the user...
            //if (!_sharedUtils.LookupTablesUpdateTable(dr["dataview_name"].ToString()))
            //{
            //    if (ux_checkboxWarnWhenLUTablesAreOutdated.Checked) partiallyLoadedTables++;
            //}
                            // Thread the LU table update as a background task...
                            _sharedUtils.LookupTablesUpdateTable(dr["dataview_name"].ToString(), true);
                        }
                    }
                }
                if (partiallyLoadedTables > 0)
                {
            //if (DialogResult.Yes == MessageBox.Show(this, "There are " + partiallyLoadedTables.ToString() + " lookup tables with missing data.\nTo maximize performace of this application it is recommended that all lookup tables be downloaded.\n\nWould you like to do this now?", "Missing Lookup Table Data", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1))
            GRINGlobal.Client.Common.GGMessageBox ggMessageBox = new GRINGlobal.Client.Common.GGMessageBox("There are {0} lookup tables with missing data.\nTo maximize performace of this application it is recommended that all lookup tables be downloaded.\n\nWould you like to do this now?", "Missing Lookup Table Data", MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button1);
            ggMessageBox.Name = "LookupTableStatusCheckMessage1";
            _sharedUtils.UpdateControls(ggMessageBox.Controls, ggMessageBox.Name);
            if (ggMessageBox.MessageText.Contains("{0}")) ggMessageBox.MessageText = string.Format(ggMessageBox.MessageText, partiallyLoadedTables.ToString());
            if (DialogResult.Yes == ggMessageBox.ShowDialog(this))
                    {
                        LookupTableLoader ltl = new LookupTableLoader(localDBInstance, _sharedUtils);
            ltl.StartPosition = FormStartPosition.CenterParent;
                        ltl.Show();
                        ltl.Focus();
                    }
                }
            }
            catch
            {
            //MessageBox.Show("An error was encountered while performing the status check for lookup tables.  Stopping status check.", "Lookup Table Status Check Error");
            GRINGlobal.Client.Common.GGMessageBox ggMessageBox = new GRINGlobal.Client.Common.GGMessageBox("An error was encountered while performing the status check for lookup tables.  Stopping status check.", "Lookup Table Status Check Error", MessageBoxButtons.OK, MessageBoxDefaultButton.Button1);
            ggMessageBox.Name = "LookupTableStatusCheckMessage2";
            _sharedUtils.UpdateControls(ggMessageBox.Controls, ggMessageBox.Name);
            ggMessageBox.ShowDialog(this);
            }

            //// Close the splash page...
            //splash.Close();
        }