예제 #1
0
        public static void addDP(string id, string name, List <DateTime> chooseableDates)
        {
            DatumPrakker dp = new DatumPrakker(id, name, username, chooseableDates);

            //Test test = new Test(45);
            CSUtil.SendObject(networkStream, dp);
            //DatumPrakker.DPAnswer dpAnswer = new DatumPrakker.DPAnswer(dp.id, username, new List<DateTime>()
            //{
            //    new DateTime(2020, 10, 26)
            //});
            //CSUtil.SendObject(networkStream, dpAnswer);
        }
예제 #2
0
        public void setDatumPrakker(DatumPrakker datumPrakker_)
        {
            datumPrakker = datumPrakker_;

            dpID.Content           = datumPrakker.id;
            nameLabel.Content      = datumPrakker.name;
            createdByLabel.Content = datumPrakker.createdByUsername;

            foreach (DateTime d in datumPrakker.chooseableDates)
            {
                dateComboBox.Items.Add(d.Date.ToShortDateString());
            }
        }
예제 #3
0
        public void setDatumPrakker(DatumPrakker datumPrakker_)
        {
            datumPrakker = datumPrakker_;

            checkedDates = new List <DateTime>();

            dpID.Content           = datumPrakker.id;
            nameLabel.Content      = datumPrakker.name;
            createdByLabel.Content = datumPrakker.createdByUsername;

            foreach (DateTime dt in datumPrakker.chooseableDates)
            {
                addDateToList(dt);
            }
        }
예제 #4
0
        private void InitTcp()
        {
            TcpClient client = new TcpClient("127.0.0.1", 7575);

            networkStream = client.GetStream();

            bool done = false;



            //while (username == null)
            //{
            //    Thread.Sleep(50);
            //}

            //CSUtil.SendMessage(networkStream, ("N^^M" + username));

            //string nameOk = CSUtil.ReadMessage(networkStream);
            //Object s = CSUtil.ReadObject(networkStream);

            //Console.WriteLine("Name status: " + nameOk);
            //Console.WriteLine("Type 'bye' to end connection");

            while (!done)
            {
                if (networkStream.DataAvailable)
                {
                    Console.Out.WriteLine("data available");
                    Byte[] byteA = CSUtil.ReadObject(networkStream);
                    Console.Out.WriteLine($"Object type = '{byteA.GetType()}'");

                    if (byteA.GetType().ToString().Equals("System.Byte[]"))
                    {
                        Object objUnknown = CSUtil.ByteArrayToObject(byteA);
                        Console.Out.WriteLine($"Object3 type = '{objUnknown.GetType()}'");

                        if (objUnknown.GetType().ToString().Equals("DP.DatumPrakker"))
                        {
                            DatumPrakker datumPrakker = (DatumPrakker)CSUtil.ByteArrayToObject(byteA);
                            Console.Out.WriteLine($"DatumPrakker: {datumPrakker}");

                            //homepage.dpOptionsPage.dpChooseDpid.received = true;
                            homepage.dpOptionsPage.dpChooseDpid.receivedObject = datumPrakker;
                        }
                        else if (objUnknown.GetType().ToString().Equals("System.String"))
                        {
                            String s = (String)CSUtil.ByteArrayToObject(byteA);
                            Console.Out.WriteLine($"String: {s}");

                            if (s.Contains("DPGET-NOTFOUND"))
                            {
                                //homepage.dpOptionsPage.dpChooseDpid.received = true;
                                homepage.dpOptionsPage.dpChooseDpid.receivedObject = "NOTFOUND";
                            }
                        }
                        else
                        {
                            Console.Out.WriteLine($"UnknownObject is Unknown: '{objUnknown.GetType()}'");
                        }
                    }

                    //Console.Out.WriteLine($"Test i: {test.i}");
                    ////CSUtil.Message obj = CSUtil.ReadObject(networkStream);
                    //DatumPrakker dp = CSUtil.readDP(client);
                    //Console.Out.WriteLine($"Name: {dp.name}");
                    ////Console.Out.WriteLine(received.GetType().ToString());
                    ////Console.WriteLine($"Received: {received} from {cTcpClient.userName}");
                }

                //if (networkStream.DataAvailable)
                //{


                //    //string messageR = CSUtil.ReadMessage(networkStream);
                //    //Console.WriteLine("message: " + messageR);
                //    //done = messageR.Equals("BYE");
                //}
                //else
                //{
                //    string messageAnswer = Console.ReadLine();
                //    CSUtil.SendMessage(networkStream, (messageAnswer));
                //}
            }
        }
        private void Button_Click_Next(object sender, RoutedEventArgs e)
        {
            Console.WriteLine("[HomePage] Button Next Clicked");

            if (dpIDTXTBox.Text.Equals(null) || dpIDTXTBox.Text.Equals("") || dpIDTXTBox.Text.Contains(" "))
            {
                System.Windows.MessageBox.Show("Please fill in an ID without spaces.");
            }
            else
            {
                string DPID = dpIDTXTBox.Text;

                MainWindow.getDP(DPID);

                new Thread(() =>
                {
                    while (receivedObject == null)
                    {
                        Thread.Sleep(10);
                    }

                    if (receivedObject != null)
                    {
                        Console.Out.WriteLine($"receivedObject.GetType() = {receivedObject.GetType()}");
                        if (receivedObject.GetType().ToString().Equals("DP.DatumPrakker"))
                        {
                            DatumPrakker datumPrakker = (DatumPrakker)receivedObject;
                            Console.Out.WriteLine($"DP received: {datumPrakker}");

                            Console.Out.WriteLine($"got page type = {pageToGoTo.GetType().ToString()}");

                            if (pageToGoTo.GetType().ToString().Equals("WPFClient.Pages.DPViewPage"))
                            {
                                Console.Out.WriteLine("goto view");
                                DPViewPage dpViewPage = (DPViewPage)pageToGoTo;
                                Dispatcher.Invoke(() => { dpViewPage.setDatumPrakker(datumPrakker); });
                                Dispatcher.Invoke(() => { NavigationService.Navigate(dpViewPage); });
                            }
                            else if (pageToGoTo.GetType().ToString().Equals("WPFClient.Pages.DPFillinPage"))
                            {
                                Console.Out.WriteLine("goto fillin");
                                DPFillinPage dpFillinPage = (DPFillinPage)pageToGoTo;
                                Dispatcher.Invoke(() => { dpFillinPage.setDatumPrakker(datumPrakker); });
                                Dispatcher.Invoke(() => { NavigationService.Navigate(dpFillinPage); });
                            }
                        }
                        else if (receivedObject.GetType().ToString().Equals("System.String"))
                        {
                            String s = (String)receivedObject;
                            if (s.Contains("NOTFOUND"))
                            {
                                Console.Out.WriteLine("DP NOTFOUND");
                                System.Windows.MessageBox.Show($"Datumprakker '{DPID}' not found");
                                Dispatcher.Invoke(() => { dpIDTXTBox.Text = ""; });
                            }
                        }
                    }
                    else
                    {
                        Console.Out.WriteLine("receivedObject is null");
                    }

                    //receivedObject = null;
                }).Start();
                //if ()
                //{

                //}
                //NavigationService.Navigate(pageToGoTo);
            }
        }