Esempio n. 1
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var dialog1 = new ContentDialog1();
            var result  = await dialog1.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                var text = dialog1.Text;
            }
        }
        private async Task <string> ReqName()
        {
            var dialog1 = new ContentDialog1();
            var result  = await dialog1.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                return(dialog1.Text);
            }
            return(null);
        }
        private async void LoginLoad()
        {
            // Login screen
            ContentDialog1 signInDialog = new ContentDialog1();

            Debug.WriteLine("login");
            await signInDialog.ShowAsync();

            Debug.WriteLine("login shows");
            // Because it is statically allocated all the instances of content dialog share it, thus it only makes sense to access the property from the type itself
            var client = ContentDialog1.client;

            sharedClient = client;
            // Patient list request
            //Debug.WriteLine(signInDialog.username);
            string preQuery = String.Format("MATCH (a:doctor)-[: treat]->(b:patient) WHERE a.username = \"{0}\"  RETURN b", signInDialog.username);
            // Preparing a JSON query
            queryObject query1 = new queryObject(preQuery);
            string      output = await query1.cypherPOST(client);

            // Deserialization of data
            JsonObject value = JsonObject.Parse(output);
            IJsonValue j, k, m;

            value.TryGetValue("data", out j);
            JsonArray value2 = j.GetArray();
            // In case the search does not return any results, this array will be empty
            List <PatientSheet> patientList = new List <PatientSheet> {
            };                     // Meaning it will be empty if zero found

            if (value2.Count != 0) // If there are patients
            {
                for (int i = 0; i < value2.Count; i++)
                {
                    JsonArray  value3  = value2[i].GetArray();
                    JsonObject object2 = value3[0].GetObject();
                    object2.TryGetValue("data", out k);
                    JsonObject object3 = k.GetObject();
                    // Switching it to name
                    object3.TryGetValue("username", out m);
                    string username = m.GetString();
                    string id       = await fetchPatientId(username); // patients user

                    Debug.WriteLine(id);
                    string[] keys = await downloadPrivateKeys(signInDialog.username, id); // doctors user

                    Debug.WriteLine(keys[0]);
                    string decryptedDoctorPrivate = keyGenerator.Decrypt(keys[0], signInDialog.password);
                    Debug.WriteLine(keys[1]);
                    // Patient's private key is decrypted. It can be decrypted by doctor's private key, but only in pieces.
                    // Partition string by _
                    string[] splitKeys   = keys[1].Split('_');
                    string   combinedKey = "";
                    foreach (string splittedKey in splitKeys)
                    {
                        if (splittedKey.Length > 0)
                        {
                            string decryptedKeyPart;
                            Debug.Write("encrypted:");
                            Debug.WriteLine(splittedKey);
                            keyGenerator.AsymmetricDecrypt(decryptedDoctorPrivate, splittedKey, out decryptedKeyPart);
                            Debug.Write("decrypted:");
                            Debug.WriteLine(decryptedKeyPart);
                            combinedKey += decryptedKeyPart;
                        }
                    }
                    Debug.WriteLine(combinedKey);
                    // Combined key is patient's private key, with those we can decrypt the other relevant data
                    string dob;
                    object3.TryGetValue("dob", out m);
                    keyGenerator.AsymmetricDecrypt(combinedKey, m.GetString(), out dob);
                    Debug.WriteLine(dob);
                    string name;
                    object3.TryGetValue("name", out m);
                    keyGenerator.AsymmetricDecrypt(combinedKey, m.GetString(), out name);
                    Debug.WriteLine(name);
                    PatientSheet patientItem = new PatientSheet {
                        patientName = name, patientDOB = dob, patientUser = username
                    };
                    patientList.Add(patientItem);
                }
            }
            ContentDialog2 patientDialog = new ContentDialog2(signInDialog.username);

            patientDialog.patientList = patientList; // You could make patientlist private if you do an initaliser for it
            await patientDialog.ShowAsync();

            commandBar.Text       = String.Format("Currently treating {0}.", patientDialog.patientDisplayName);
            this.userBeingTreated = patientDialog.patientToTreat;
            this.doctor           = signInDialog.username;
            // When everything is done, load the patient measurement data into the plot
            List <MeasurementPoint> mes = await fetchMeasurements();

            Debug.Write("mes:");
            Debug.WriteLine(mes.Count);
            if (mes.Count != 0)
            {
                updatePatientPlot(mes);
            }
        }
Esempio n. 4
0
        private async void btnNew_Click(object sender, RoutedEventArgs e)
        {
            ContentDialog1 dialog = new ContentDialog1();
            var            dlg    = await dialog.ShowAsync();

            if (dlg == ContentDialogResult.Primary)
            {
                int PlayerNumber = dialog.PlayerNumber;

                switch (PlayerNumber)
                {
                case 0:
                {
                    lblName1.Text    = dialog.Player1;
                    lblName2.Text    = dialog.Player2;
                    lblName3.Text    = "none";
                    lblName4.Text    = "none";
                    lblName3.Opacity = 50;
                    lblName4.Opacity = 50;
                    MaxLP            = Int32.Parse(dialog.LifePoints);
                    LP1                 = Int32.Parse(dialog.LifePoints);
                    LP2                 = Int32.Parse(dialog.LifePoints);
                    LP3                 = 0;
                    LP4                 = 0;
                    lblLP1.Text         = dialog.LifePoints;
                    lblLP2.Text         = dialog.LifePoints;
                    lblLP3.Text         = "-";
                    lblLP4.Text         = "-";
                    lblLP3.Opacity      = 50;
                    lblLP4.Opacity      = 50;
                    pbLP1.Maximum       = double.Parse(dialog.LifePoints);
                    pbLP1.Value         = double.Parse(dialog.LifePoints);
                    pbLP2.Maximum       = double.Parse(dialog.LifePoints);
                    pbLP2.Value         = double.Parse(dialog.LifePoints);
                    pbLP3.Maximum       = double.Parse(dialog.LifePoints);
                    pbLP3.Value         = double.Parse(dialog.LifePoints);;
                    pbLP4.Maximum       = double.Parse(dialog.LifePoints);;
                    pbLP4.Value         = double.Parse(dialog.LifePoints);;
                    pbLP3.Opacity       = 50;
                    pbLP4.Opacity       = 50;
                    edtLP3.IsEnabled    = false;
                    edtLP4.IsEnabled    = false;
                    btnLPRem1.IsEnabled = true;
                    btnLPAdd1.IsEnabled = true;
                    btnLPRem2.IsEnabled = true;
                    btnLPAdd2.IsEnabled = true;
                    btnLPRem3.IsEnabled = false;
                    btnLPAdd3.IsEnabled = false;
                    btnLPRem4.IsEnabled = false;
                    btnLPAdd4.IsEnabled = false;
                    lblLP1.Foreground   = new SolidColorBrush(Windows.UI.Colors.Black);
                    lblLP2.Foreground   = new SolidColorBrush(Windows.UI.Colors.Black);
                    lblLP3.Foreground   = new SolidColorBrush(Windows.UI.Colors.Black);
                    lblLP4.Foreground   = new SolidColorBrush(Windows.UI.Colors.Black);
                    break;
                }

                case 1:
                {
                    lblName1.Text    = dialog.Player1;
                    lblName2.Text    = dialog.Player2;
                    lblName3.Text    = dialog.Player3;
                    lblName4.Text    = "none";
                    lblName3.Opacity = 100;
                    lblName4.Opacity = 50;
                    MaxLP            = Int32.Parse(dialog.LifePoints);
                    LP1                 = Int32.Parse(dialog.LifePoints);
                    LP2                 = Int32.Parse(dialog.LifePoints);
                    LP3                 = Int32.Parse(dialog.LifePoints);
                    LP4                 = 0;
                    lblLP1.Text         = dialog.LifePoints;
                    lblLP2.Text         = dialog.LifePoints;
                    lblLP3.Text         = dialog.LifePoints;
                    lblLP4.Text         = "-";
                    lblLP3.Opacity      = 100;
                    lblLP4.Opacity      = 50;
                    pbLP1.Maximum       = double.Parse(dialog.LifePoints);
                    pbLP1.Value         = double.Parse(dialog.LifePoints);
                    pbLP2.Maximum       = double.Parse(dialog.LifePoints);
                    pbLP2.Value         = double.Parse(dialog.LifePoints);
                    pbLP3.Maximum       = double.Parse(dialog.LifePoints);
                    pbLP3.Value         = double.Parse(dialog.LifePoints);
                    pbLP4.Maximum       = double.Parse(dialog.LifePoints);;
                    pbLP4.Value         = double.Parse(dialog.LifePoints);;
                    pbLP3.Opacity       = 100;
                    pbLP4.Opacity       = 50;
                    edtLP3.IsEnabled    = true;
                    edtLP4.IsEnabled    = false;
                    btnLPRem1.IsEnabled = true;
                    btnLPAdd1.IsEnabled = true;
                    btnLPRem2.IsEnabled = true;
                    btnLPAdd2.IsEnabled = true;
                    btnLPRem3.IsEnabled = true;
                    btnLPAdd3.IsEnabled = true;
                    btnLPRem4.IsEnabled = false;
                    btnLPAdd4.IsEnabled = false;
                    lblLP1.Foreground   = new SolidColorBrush(Windows.UI.Colors.Black);
                    lblLP2.Foreground   = new SolidColorBrush(Windows.UI.Colors.Black);
                    lblLP3.Foreground   = new SolidColorBrush(Windows.UI.Colors.Black);
                    lblLP4.Foreground   = new SolidColorBrush(Windows.UI.Colors.Black);
                    break;
                }

                case 2:
                {
                    lblName1.Text    = dialog.Player1;
                    lblName2.Text    = dialog.Player2;
                    lblName3.Text    = dialog.Player3;
                    lblName4.Text    = dialog.Player4;
                    lblName3.Opacity = 100;
                    lblName4.Opacity = 100;
                    MaxLP            = Int32.Parse(dialog.LifePoints);
                    LP1                 = Int32.Parse(dialog.LifePoints);
                    LP2                 = Int32.Parse(dialog.LifePoints);
                    LP3                 = Int32.Parse(dialog.LifePoints);
                    LP4                 = Int32.Parse(dialog.LifePoints);
                    lblLP1.Text         = dialog.LifePoints;
                    lblLP2.Text         = dialog.LifePoints;
                    lblLP3.Text         = dialog.LifePoints;
                    lblLP4.Text         = dialog.LifePoints;
                    lblLP3.Opacity      = 100;
                    lblLP4.Opacity      = 100;
                    pbLP1.Maximum       = double.Parse(dialog.LifePoints);
                    pbLP1.Value         = double.Parse(dialog.LifePoints);
                    pbLP2.Maximum       = double.Parse(dialog.LifePoints);
                    pbLP2.Value         = double.Parse(dialog.LifePoints);
                    pbLP3.Maximum       = double.Parse(dialog.LifePoints);
                    pbLP3.Value         = double.Parse(dialog.LifePoints);
                    pbLP4.Maximum       = double.Parse(dialog.LifePoints);
                    pbLP4.Value         = double.Parse(dialog.LifePoints);
                    pbLP3.Opacity       = 100;
                    pbLP4.Opacity       = 100;
                    edtLP3.IsEnabled    = true;
                    edtLP4.IsEnabled    = true;
                    btnLPRem1.IsEnabled = true;
                    btnLPAdd1.IsEnabled = true;
                    btnLPRem2.IsEnabled = true;
                    btnLPAdd2.IsEnabled = true;
                    btnLPRem3.IsEnabled = true;
                    btnLPAdd3.IsEnabled = true;
                    btnLPRem4.IsEnabled = true;
                    btnLPAdd4.IsEnabled = true;
                    lblLP1.Foreground   = new SolidColorBrush(Windows.UI.Colors.Black);
                    lblLP2.Foreground   = new SolidColorBrush(Windows.UI.Colors.Black);
                    lblLP3.Foreground   = new SolidColorBrush(Windows.UI.Colors.Black);
                    lblLP4.Foreground   = new SolidColorBrush(Windows.UI.Colors.Black);
                    break;
                }
                }
            }
        }