Beispiel #1
0
        private async void buttonLoadRecords_Click(object sender, EventArgs e)
        {
            ResetUi();

            //Sync Approvals from Remote(Site) Server
            toolStripStatusLabel.Text = @"Checking for and synchronising Approvals if any. Please Wait...";
            //DatabaseOpperations.SyncApprovals();

            toolStripStatusLabel.Text = @"Loading data to be synchronised. Please Wait...";
            //var totalRecords = DatabaseOpperations.GetTotalRecordCount();
            var reasons = new List <FingerprintReason>();
            var result  = await Task.Run(() =>
            {
                SyncBacklogInput input = new SyncBacklogInput
                {
                    SyncMode     = GetSyncMode(),
                    FilterStart  = dateTimePickerFrom.Value,
                    FilterEnd    = dateTimePickerTo.Value,
                    EnrollmentId = textBoxRecordID.Text
                };

                //Load data whose ApprovalStatus == pending for synchronisation using the filter option : 'input'
                return(DatabaseOpperations.GetSyncBacklog(new Project(), input, out reasons));
            });

            //Retrieve BaseData Result
            _BaseDatas = result;

            //Display Result Count on the Screen
            //labelTotalRecords.Text = totalRecords.ToString();
            labelRecordInSyncQueue.Text = _BaseDatas.Any() ? _BaseDatas.Count().ToString() : "0";

            toolStripStatusLabel.Text = @"Loading Completed";
            DisableUI(true);
        }
Beispiel #2
0
 private void buttonTest_Click(object sender, EventArgs e)
 {
     try
     {
         bool testResult = new DatabaseOpperations().TestDBConnection(Settings.Default.DBServer, Settings.Default.DBName, Settings.Default.DBPort, Settings.Default.DBUser, Settings.Default.DBPassword);
         MessageBox.Show(this, $"Connection to Server {(testResult ? "Successful" : "Failed")}", @"Test Database Server");
     }
     catch (Exception exp)
     {
         MessageBox.Show(this, exp.Message, "Test Database Server");
     }
 }
Beispiel #3
0
 private void buttonTestSyncServer_Click(object sender, EventArgs e)
 {
     try
     {
         bool testResult = new DatabaseOpperations().TestDBConnection(Settings.Default.syncDBServer, Settings.Default.syncDBName,
                                                                      Settings.Default.syncDBPort, Settings.Default.syncDBUser, Settings.Default.syncDBPassword);
         MessageBox.Show(this, String.Format("Connection to Server {0}", testResult == true ? "Successful" : "Failed"), "Test Sync Database Server");
     }
     catch (Exception exp)
     {
         MessageBox.Show(this, exp.Message, "Test Sync Database Server");
     }
 }
Beispiel #4
0
        /// <summary>
        /// This is a likely CPU Intensive Opperation.
        /// The Method has been marked async and the CPU bound TASK(s) is being Excuted in a Background Thread
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void CrimsSync_Shown(object sender, EventArgs e)
        {
            //Load Sync Job History
            toolStripStatusLabel.Text = @"Loading Sync Job History, Please Wait...";
            DisableUI(false);
            //var totalRecords = DatabaseOpperations.GetTotalRecordCount();

            var result = await Task.Run(() => DatabaseOpperations.GetSyncedJobHistory());

            toolStripStatusLabel.Text = @"Sync Job History Loaded Succesfully";
            _SyncJobHistory           = (IList <SyncJobHistory>)result;
            DisableUI(true);
        }
Beispiel #5
0
        private async Task <List <EnrollmentBackup> > InitImport(List <EnrollmentBackup> imports)
        {
            try
            {
                ResetImportUi();
                toolStripStatusLabel.Text = @"Loading data for Export. Please Wait...";
                var result = await Task.Run(() => DatabaseOpperations.ImportFromBackup(imports));

                return(result);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return(new List <EnrollmentBackup>());
            }
        }
Beispiel #6
0
        private async void buttonResetSyncHistory_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(this, @"Are you sure you want to delete all Sync History on this System?", "DELETE SYNC HISTORY", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                //Load Sync Job History
                toolStripStatusLabel.Text = @"Deleting Sync Job History, Please Wait...";
                DisableUI(false);

                await Task.Run(() =>
                {
                    DatabaseOpperations.ResetSyncHistory();
                });

                toolStripStatusLabel.Text = @"Sync Job History Deleted Succesfully";
                DisableUI(true);
            }
        }
Beispiel #7
0
        private async void button1_Click(object sender, EventArgs e)
        {
            string query            = richTextBox1.Text;
            string connectionString = richTextBox2.Text;
            string saveFileDir      = richTextBox3.Text;
            var    customData       = await Task.Run(() =>
            {
                try
                {
                    return(DatabaseOpperations.QueryAndConvertToWQS(query, connectionString, saveFileDir));
                }
                catch (Exception)
                {
                    throw;
                }
            });

            MessageBox.Show("Completed");
        }
Beispiel #8
0
        private async Task <List <EnrollmentBackup> > InitExport()
        {
            try
            {
                ResetExportUi();
                toolStripStatusLabel.Text = @"Loading data for Export. Please Wait...";
                var result = await Task.Run(() =>
                {
                    var backupMode = GetBackUpMode();
                    if (backupMode == SyncMode.Specific)
                    {
                        if (string.IsNullOrEmpty(txtSingleBackup.Text))
                        {
                            MessageBox.Show(@"Please provide the specific EnrolleeId for Export");
                            return(new List <EnrollmentBackup>());
                        }
                    }

                    var input = new SyncBacklogInput
                    {
                        SyncMode     = GetBackUpMode(),
                        FilterStart  = backupStartDate.Value,
                        FilterEnd    = backupEndDate.Value,
                        EnrollmentId = txtSingleBackup.Text
                    };

                    //Load data for backup using the filter option : 'input'
                    return(DatabaseOpperations.GenerateBackup(new Project(), input));
                });

                //Display Result Count on the Screen
                lblTotalExport.Text       = result.Count.ToString();
                toolStripStatusLabel.Text = @"Data Loading Completed";
                return(result);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return(new List <EnrollmentBackup>());
            }
        }
Beispiel #9
0
        private void btnSyncDataForm_Click(object sender, EventArgs e)
        {
            var destinationUrl = Settings.Default.dataFormsDestination;

            if (string.IsNullOrEmpty(destinationUrl))
            {
                MessageBox.Show(@"Please provide the destination URL for synchronising data forms in the settings menu");
                return;
            }
            var project = DatabaseOpperations.GetProject();

            if (string.IsNullOrEmpty(project?.ProjectCode))
            {
                MessageBox.Show(@"An Internal server error was encountered. The action was terminated. Please contact our support team.");
                return;
            }
            var fileSyncResult = SyncEnrollmentDataForms(destinationUrl, project.ProjectCode).Result;

            if (!string.IsNullOrEmpty(fileSyncResult))
            {
                var result = JsonConvert.DeserializeObject <List <FileDesc> >(fileSyncResult);
                MessageBox.Show(result.Count + @" Data form(s) were successfully synchronised.");
            }
        }
Beispiel #10
0
        private async void buttonLogin_Click(object sender, EventArgs e)
        {
            if (textBoxUserName.Text.Trim() == string.Empty)
            {
                labelMsg.Text = "Please Enter a Username";
                return;
            }
            if (!Settings.Default.AuthoriseOnlyUserName && textBoxPassword.Text.Trim() == String.Empty)
            {
                labelMsg.Text = "Please Enter a Username";
                return;
            }
            string email    = textBoxUserName.Text.Trim();
            string password = textBoxPassword.Text.Trim();

            labelMsg.Text       = "Logging In, Please wait...";
            buttonLogin.Enabled = false;


            if (Settings.Default.AuthoriseOnlyUserName)
            {
                var result = await Task.Run(() =>
                {
                    return(DatabaseOpperations.AuthoriseOnlyUserName(email));
                });

                if (result.Rows.Count > 0)
                {
                    _UserProfile = new UserAccountModel
                    {
                        UserName  = result.Rows[0]["Email"].ToString(),
                        UserId    = result.Rows[0]["Id"].ToString(),
                        ProfileId = result.Rows[0]["UserInfo_Id"].ToString(),
                        Email     = result.Rows[0]["Email"].ToString()
                    };
                    _LoginNotifyer(_UserProfile, true);
                }
                else
                {
                    labelMsg.Text       = "Invalid Username";
                    buttonLogin.Enabled = true;
                    return;
                }
            }
            else
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(_LoginUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
                HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Post, _LoginUrl + "ApiLogin?");
                var keyValues          = new List <KeyValuePair <string, string> >();
                keyValues.Add(new KeyValuePair <string, string>("email", email));
                keyValues.Add(new KeyValuePair <string, string>("password", password));
                msg.Content = new FormUrlEncodedContent(keyValues);
                HttpResponseMessage response = await client.SendAsync(msg);

                if (response.IsSuccessStatusCode)
                {
                    string result = await response.Content.ReadAsStringAsync();

                    _UserProfile = Newtonsoft.Json.JsonConvert.DeserializeObject <UserAccountModel>(result);
                }
                else
                {
                    var errorMessage = response.StatusCode.ToString();
                    labelMsg.Text        = errorMessage + " - Unable to login. Please contact your Admin.";
                    buttonLogin.Enabled  = true;
                    textBoxPassword.Text = string.Empty;
                    return;
                }
                if (_UserProfile.Code == 5)
                {
                    //After Succesfully Loging In...
                    _LoginNotifyer(_UserProfile, true);
                }
                else
                {
                    buttonLogin.Enabled  = true;
                    textBoxPassword.Text = string.Empty;
                    labelMsg.Text        = _UserProfile.Message;
                }
            }
        }
Beispiel #11
0
        private async Task SynEnrollmentData()
        {
            var progressHandler = new Progress <int>(value =>
            {
                labelTotalSuccess.Text = value.ToString();
            });
            var progress = (IProgress <int>)progressHandler;

            //Download User Profiles
            toolStripStatusLabel.Text = @"Searching and Downloading New User Profiles, Please Wait... ";
            await Task.Run(() => DatabaseOpperations.DownloadNewUserProfiles());

            toolStripStatusLabel.Text = @"User Profiles Update Completed ";

            if (_UserProfile == null)
            {
                toolStripStatusLabel.Text = @"Sync Job Terminated, User Must Login";
                return;
            }

            //Scroll through records in result
            if (_BaseDatas.Any())
            {
                toolStripStatusLabel.Text = @"Sync Job Processing, Please Wait...";
                var startDate = DateTime.Now;
                labelSyncStartTime.Text = startDate.ToString("dd/MM/yyyy hh:mm tt");
                DisableUI(false);

                //0. Create Entry into the SyncJobLog
                var syncJobId = DatabaseOpperations.CreateSyncJobSession(_UserProfile, startDate);

                //1. Find User Custom Datas
                var i = 0;//This is the counter to Updating UI on total Completed So For
                _BaseDatas.ForEach(async res =>
                {
                    var enrollmentRecordInfo = await Task.Run(() =>
                    {
                        try
                        {
                            var enrollmentRecordDetails = new EnrollmentRecord
                            {
                                CustomDatas         = DatabaseOpperations.GetEnrolleeCustomData(res.EnrollmentId),
                                Photograph          = DatabaseOpperations.GetEnrolleePhotoGraph(res.EnrollmentId),
                                FingerprintTemplate = DatabaseOpperations.GetEnrolleeFingerprintTemplate(res.EnrollmentId),
                                FingerprintImages   = DatabaseOpperations.GetEnrolleeFingerprintImages(res.EnrollmentId),
                                Signature           = DatabaseOpperations.GetEnrolleeSignature(res.EnrollmentId)
                            };
                            return(enrollmentRecordDetails);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                            return(new EnrollmentRecord());
                        }
                    });

                    if (enrollmentRecordInfo == null || !enrollmentRecordInfo.CustomDatas.Any())
                    {
                        MessageBox.Show(@"An error was encountered. Data to be synchronised could not be retrieved");
                        return;
                    }

                    enrollmentRecordInfo.BaseData = res;

                    if (!enrollmentRecordInfo.CustomDatas.Any())
                    {
                        MessageBox.Show(@"This Enrollment will not be Synchronised with empty Custom data!");
                        return;
                    }

                    if (!enrollmentRecordInfo.FingerprintImages.Any())
                    {
                        MessageBox.Show(@"This Enrollment will not be Synchronised without Fingerprints");
                        return;
                    }

                    if (string.IsNullOrEmpty(enrollmentRecordInfo.Photograph?.EnrollmentId))
                    {
                        MessageBox.Show(@"This Enrollment will not be Synchronised without Fingerprints");
                        return;
                    }

                    await Task.Run(() => DatabaseOpperations.SynchroniseDataToServer(enrollmentRecordInfo));

                    //5. Update Local Database SyncJobHistoy for specific Record
                    DatabaseOpperations.UpdateDbSyncHistory(syncJobId, res.EnrollmentId);

                    i++; // IncreamentItems Completed Counter
                    if (progress != null)
                    {
                        progress.Report(i);
                    }
                });

                //6. Log Sync End Time for Sync Job
                DatabaseOpperations.CloseSyncJobSession(syncJobId);
                toolStripStatusLabel.Text = @"Sync Job Completed Succesfully";
                labelSyncEndTime.Text     = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt");
                DisableUI(true);
            }
            else
            {
                toolStripStatusLabel.Text = @"No Records to Synchronize. Try Applying a Filter.";
            }
        }