private void AddPerson_btn_Click(object sender, EventArgs e)
        {
            string name = NewPersonName_txtbox.Text.Trim();
            string enter = NewPersonEntDate_txtbox.Text.Trim();
            string grad = NewPersonEndDate_txtbox.Text.Trim();
            DateTime enterDateTime = new DateTime();
            DateTime gradDateTime = new DateTime();
            if (name != String.Empty && enter != String.Empty && grad != String.Empty)
            {
                try
                {
                    enterDateTime = Convert.ToDateTime(enter);
                    gradDateTime = Convert.ToDateTime(grad);
                    newPerson = new Person(name, enterDateTime, gradDateTime);
                    DialogResult = DialogResult.OK;
                    return;
                }
                catch
                {
                    MessageBox.Show("Неправильно введені дати, спробуйте ввести у форматі dd.mm.yyyy");
                }

            }
            else
                MessageBox.Show("Не всі поля введені");
        }
        public IEnumerable<Person> GetPeople()
        {
            var people = new List<Person>();

            if (File.Exists(path))
            {
                using (var sr = new StreamReader(path))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        var elems = line.Split(',');
                        var per = new Person()
                        {
                            FirstName = elems[0],
                            LastName = elems[1],
                            StartDate = DateTime.Parse(elems[2]),
                            Rating = Int32.Parse(elems[3])
                        };
                        people.Add(per);
                    }
                }
            }
            return people;
        }
 private static string GetMessage(Random rand)
 {
     Person p = new Person();
     p.Age = rand.Next(100);
     p.Name = string.Format("named from .NET {0}", p.Age);
     return JsonConvert.SerializeObject(p);
 }
 private void DeletePerson_btn_Click(object sender, EventArgs e)
 {
     string name = DeletePersonName_cmbbox.Text.Trim();
     if (name != String.Empty)
     {
         deletedPerson = new Person(getPersonId(), name);
         DialogResult = DialogResult.OK;
         return;
     }
     else
         MessageBox.Show("Спершу введіть ім'я людини, яке бажаєте видалити");
 }
示例#5
0
 public Boolean CheckRegister(string idCardNumber)
 {
     Common.Person p = this.GetPerson(idCardNumber);
     if (p == null)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public void TestChristmasPickDeserialization()
        {
            Person Bob = new Person("Bob", "Gehred", new DateTime(1972, 7, 27), "21111111-2222-3333-4444-555555555555");
            Person Angie = new Person("Angie", "Gehred", new DateTime(1971, 9, 26), "11111111-2222-3333-4444-555555555555");

              XMasPick expectedPick = new XMasPick(Bob, Angie);
              XMasPick actual = null;
              byte[] serializedPickItem = ConvertStringToByteArray("<?xml version=\"1.0\"?>\r\n<XMasPick>\r\n  <Subject firstname=\"Bob\" lastname=\"Gehred\" birthday=\"7/27/1972\" id=\"21111111-2222-3333-4444-555555555555\" />\r\n  <Recipient firstname=\"Angie\" lastname=\"Gehred\" birthday=\"9/26/1971\" id=\"11111111-2222-3333-4444-555555555555\" />\r\n</XMasPick>");
              Stream testData = new MemoryStream(serializedPickItem);
              XmlSerializer xml = new XmlSerializer(typeof(XMasPick));
              actual = (XMasPick)xml.Deserialize(testData);
              Assert.AreEqual(expectedPick, actual);
        }
示例#7
0
 /// <summary>
 /// If there is a chatter name and image provided
 /// the currentPerson property is set to be a new
 /// <see cref="Common.Person">chatter</see> and the
 /// AddButtonClickEvent is raised which is used by the
 /// parent <see cref="Window1">window</see>
 /// </summary>
 /// <param name="sender">AddButton</param>
 /// <param name="e">The event args</param>
 private void AddButton_Click(object sender, RoutedEventArgs e)
 {
     if (!string.IsNullOrEmpty(txtName.Text) &&
        !string.IsNullOrEmpty(photoPath))
     {
         currentPerson = new Person(photoPath, txtName.Text);
         RaiseEvent(new RoutedEventArgs(AddButtonClickEvent));
     }
     else
     {
         MessageBox.Show("You need to pick a screen name and image", "Error",
                         MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
 public List<Common.Person> GetAllPersons()
 {
     if (dataBase.Person == null)
         return null;
     List<Common.Person> Person = new List<Common.Person>();
     foreach (var currPerson in dataBase.Person)
     {
         Common.Person person = new Common.Person();
         person.ID = currPerson.ppers_id;
         person.Name = currPerson.name;
         person.date_begin_ed = (DateTime)currPerson.date_begin_ed;
         person.date_end_ed = (DateTime)currPerson.date_end_ed;
         Person.Add(person);
     }
     return Person;
 }
        public void TestChristmaPickSerialization()
        {
            Person Bob = new Person("Bob", "Gehred", new DateTime(1972, 7, 27), "21111111-2222-3333-4444-555555555555");
            Person Angie = new Person("Angie", "Gehred", new DateTime(1971, 9, 26), "11111111-2222-3333-4444-555555555555");

              XMasPick testPick = new XMasPick(Bob, Angie);

              Stream myStream = new BufferedStream(new MemoryStream(new byte[1024], true), 1024);
              if (myStream != null)
              {
            XmlSerializer xml = new XmlSerializer(typeof(XMasPick));
            xml.Serialize(myStream, testPick);
              }

              long length = myStream.Position;
              myStream.Position = 0;
              StreamReader rawData = new StreamReader(myStream);
              string actual = rawData.ReadToEnd();
              actual = actual.Substring(0, (int)length);
              Assert.AreEqual("<?xml version=\"1.0\"?>\r\n<XMasPick>\r\n  <Subject firstname=\"Bob\" lastname=\"Gehred\" birthday=\"7/27/1972\" id=\"21111111-2222-3333-4444-555555555555\" />\r\n  <Recipient firstname=\"Angie\" lastname=\"Gehred\" birthday=\"9/26/1971\" id=\"11111111-2222-3333-4444-555555555555\" />\r\n</XMasPick>", actual);
        }
        public Person GetPerson(string lastName)
        {
            Person selPerson = new Person();
            if (File.Exists(path))
            {
                var sr = new StreamReader(path);
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    var elems = line.Split(',');
                    if (elems[1].ToLower() == lastName.ToLower())
                    {
                        selPerson.FirstName = elems[0];
                        selPerson.LastName = elems[1];
                        selPerson.StartDate = DateTime.Parse(elems[2]);
                        selPerson.Rating = Int32.Parse(elems[3]);
                    }
                }
            }

            return selPerson;
        }
示例#11
0
 public bool IsAboveFourteen(Person person) => person.Age > 14;
示例#12
0
        private void AddButton_Click_1(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtName.Text) &&
               !string.IsNullOrEmpty(photoPath))
            {
                currentPerson = new Person();
                currentPerson.ImageURL = photoPath;
                currentPerson.Name = txtName.Text;

                //RaiseEvent(new RoutedEventArgs(AddButtonClickEvent));
                OnAddButtonClickEvent(this);
            }
            else
            {
                MessageBox.Show("You need to pick a screen name and image", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#13
0
 public void AllPersons_AreAbove14_WithTheoryData_FromDataGenerator(Person a) => Assert.True(IsAboveFourteen(a));
 public void AddPerson(Person newPerson)
 {
     ServiceProxy.AddPerson(newPerson);
 }
示例#15
0
        /// <summary>
        /// A request has been made by a client to leave the chat room,
        /// so remove the <see cref="Common.Person">Person </see>from
        /// the internal list of chatters, and unwire the chatters
        /// delegate from the multicast delegate, so that it no longer
        /// gets invokes by globally broadcasted methods
        /// </summary>
        public void Leave()
        {
            if (this.person == null)
                return;

            //get the chatters ChatEventHandler delegate
            ChatEventHandler chatterToRemove = getPersonHandler(this.person.Name);

            //carry out a critical section, that removes the chatter from the
            //internal list of chatters
            lock (syncObj)
            {
                chatters.Remove(this.person);
            }
            //unwire the chatters delegate from the multicast delegate, so that 
            //it no longer gets invokes by globally broadcasted methods
            ChatEvent -= chatterToRemove;
            ChatEventArgs e = new ChatEventArgs();
            e.msgType = MessageType.UserLeave;
            e.person = this.person;
            this.person = null;
            //broadcast this leave message to all other remaining connected
            //chatters
            BroadcastMessage(e);
        }
示例#16
0
 /// <summary>
 /// Removes the person input parameter to the internal list of
 /// chatters
 /// </summary>
 /// <param name="sender">The <see cref="Common.Person">chatter leaving</see> 
 /// </param>
 private void UserLeave(Person person)
 {
     lstChatters.Items.Remove(person);
 }
示例#17
0
 /// <summary>
 /// Uses the data entered on the <see cref="SignInControl">SignInControl</see>
 /// to initialise certain UI elements. And also creates a new 
 /// <see cref="Proxy_Singleton">ProxySingleton</see> and subscribes to its
 /// ProxyEvent/ProxyCallBackEvent events
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SignInControl_AddButtonClick(object sender, RoutedEventArgs e)
 {
     lstChatters.Items.Clear();
     currPerson = this.SignInControl.CurrentPerson;
     //connect to proxy, and subscribe to its events
     ProxySingleton.Connect(currPerson);
     ProxySingleton.ProxyEvent += new Proxy_Singleton.ProxyEventHandler(ProxySingleton_ProxyEvent);
     //one event subscription for the embedded ChatControl
     ProxySingleton.ProxyCallBackEvent += new Proxy_Singleton.ProxyCallBackEventHandler(this.ChatControl.ProxySingleton_ProxyCallBackEvent);
     //one event subscription for this window
     ProxySingleton.ProxyCallBackEvent += new Proxy_Singleton.ProxyCallBackEventHandler(this.ProxySingleton_ProxyCallBackEvent);
     //set the UI elements using signin data
     this.photoBig.Source = new BitmapImage(new Uri(currPerson.ImageURL));
     this.SignInControl.Visibility = Visibility.Hidden;
     this.MainBorder.Visibility = Visibility.Visible;
     this.mnuBorder.Visibility = Visibility.Visible;
     this.lblInstructions.Content = "You can click on the gridview below to launch a chat window. When the window is opened you may\r\n" +
                                 "either chat using either the Whisper button which will ONLY chat to the person you selected in\r\n" +
                                 "the gridview, or you can use the Say button, which will allow ALL connected people to see the message.\r\n";
     this.txtPerson.Content = "Hello " + currPerson.Name;
 }
 public void AddPerson(Person newPerson)
 {
     _wrappedRepository.AddPerson(newPerson);
     InvalidateCache();
 }
示例#19
0
 public IAsyncResult BeginUserLeave(Person person, AsyncCallback callback, object asyncState)
 {
     throw new Exception("The method or operation is not implemented.");
 }
 public void AddPerson(Person newPerson)
 {
     throw new NotImplementedException();
 }
示例#21
0
 /// <summary>
 /// An existing chatter left chat room, so call the 
 /// internal UserEnterLeave() method passing it the input parameters
 /// and the <see cref="CallBackType">CallBackType.UserLeave</see>
 /// type
 /// </summary>
 /// <param name="sender">The <see cref="Common.Person">current chatter</see></param>
 /// <param name="message">The message</param>
 public void UserLeave(Person person)
 {
     UserEnterLeave(person, CallBackType.UserLeave);
 }
示例#22
0
 /// <summary>
 /// If the input list is not empty, then call the 
 /// OnProxyEvent() event, to raise the event for subscribers
 /// </summary>
 /// <param name="list">The list of <see cref="Common.Person">Chatters</see> </param>
 private void HandleEndJoin(Person[] list)
 {
     if (list == null)
     {
         MessageBox.Show("Error: List is empty", "Error",
                                            MessageBoxButton.OK, MessageBoxImage.Error);
         ExitChatSession();
     }
     else
     {
         ProxyEventArgs e = new ProxyEventArgs();
         e.list = list;
         OnProxyEvent(e);
     }
 }
示例#23
0
 /// <summary>
 /// Calls by either the Receive() or ReceiveWhisper() <see cref="IChatCallback">IChatCallback</see>
 /// method implementations, and simply raises the OnProxyCallBackEvent() event
 /// to any subscribers
 /// </summary>
 /// <param name="sender">The <see cref="Common.Person">current chatter</see></param>
 /// <param name="message">The message</param>
 /// <param name="callbackType">Could be <see cref="CallBackType">CallBackType.Receive</see> or
 /// <see cref="CallBackType">CallBackType.ReceiveWhisper</see></param>
 private void Receive(Person sender, string message, CallBackType callbackType)
 {
     ProxyCallBackEventArgs e = new ProxyCallBackEventArgs();
     e.message = message;
     e.callbackType = callbackType;
     e.person = sender;
     OnProxyCallBackEvent(e);
 }
示例#24
0
 /// <summary>
 /// Calls by either the UserEnter() or UserLeave() <see cref="IChatCallback">IChatCallback</see>
 /// method implementations, and simply raises the OnProxyCallBackEvent() event
 /// to any subscribers
 /// </summary>
 /// <param name="sender">The <see cref="Common.Person">current chatter</see></param>
 /// <param name="message">The message</param>
 /// <param name="callbackType">Could be <see cref="CallBackType">CallBackType.UserEnter</see> or
 /// <see cref="CallBackType">CallBackType.UserLeave</see></param>
 private void UserEnterLeave(Person person, CallBackType callbackType)
 {
     ProxyCallBackEventArgs e = new ProxyCallBackEventArgs();
     e.person = person;
     e.callbackType = callbackType;
     OnProxyCallBackEvent(e);
 }
示例#25
0
 /// <summary>
 /// Adds a new to the database.
 /// </summary>
 /// <param name="Patient">user instance to be added.</param>
 public void AddPerson(Common.Person Person)
 {
     this.Entities.Persons.Add(Person);
     this.Entities.SaveChanges();
 }
示例#26
0
 /// <summary>
 /// Recieve a message from a fellow chatter, so call the 
 /// internal Receive() method passing it these input parameters
 /// and the <see cref="CallBackType">CallBackType.ReceiveWhisper</see>
 /// type
 /// </summary>
 /// <param name="sender">The <see cref="Common.Person">current chatter</see></param>
 /// <param name="message">The message</param>
 public void ReceiveWhisper(Person sender, string message)
 {
     Receive(sender, message, CallBackType.ReceiveWhisper);
 }
示例#27
0
 /// <summary>
 /// Adds the person input parameter to the internal list of
 /// chatters
 /// </summary>
 /// <param name="sender">The <see cref="Common.Person">new chatter</see> 
 /// </param>
 private void UserEnter(Person person)
 {
     lstChatters.Items.Add(person);
 }
示例#28
0
 /// <summary>
 /// Begins an asynchronous join operation on the underlying <see cref="ChatProxy">ChatProxy</see>
 /// which will call the OnEndJoin() method on completion
 /// </summary>
 /// <param name="p">The <see cref="Common.Person">chatter</see> to try and join with</param>
 public void Connect(Person p)
 {
     InstanceContext site = new InstanceContext(this);
     proxy = new ChatProxy(site);
     IAsyncResult iar = proxy.BeginJoin(p, new AsyncCallback(OnEndJoin), null);
 }
示例#29
0
 /// <summary>
 /// This event occurs when a item is clicked within the 
 /// list of connected <see cref="Common.Person">chatters</see>
 /// The showChatWindow animation is found from the WPF 
 /// resources and is triggered, which shows the 
 /// <see cref="ChatControl">ChatControl</see> 
 /// and the CurrentPerson/OtherPerson properties are
 /// set on the <see cref="ChatControl">
 /// ChatControl</see>
 /// </summary>
 /// <param name="otherPerson">The <see cref="Common.Person">other chatter to talk to</see></param>
 private void showChatWindow(Person otherPerson)
 {
     if (!chatControlShown)
     {
         ChatControl.CurrentPerson = currPerson;
         ChatControl.OtherPerson = otherPerson;
         ChatControl.Visibility = Visibility.Visible;
         //get Storyboard animation from window resources
         ((Storyboard)this.Resources["showChatWindow"]).Begin(this);
         chatControlShown = true;
         mnuDisConnect.IsEnabled = false;
     }
 }
示例#30
0
 /// <summary>
 /// Adds a new to the database.
 /// </summary>
 /// <param name="User">user instance to be added.</param>
 private void AddPersonToDatabase(Common.Person Person)
 {
     new DataLayer.PatientsHandler().AddPerson(Person);
 }
示例#31
0
 /// <summary>
 /// Calls the showChatWindow() method, passing it the sender
 /// parameter
 /// </summary>
 /// <param name="sender">The <see cref="Common.Person">Originator</see> 
 /// chatter</param>
 /// <param name="message">The message</param>
 private void ReceiveWhisper(Person sender, string message)
 {
     showChatWindow(sender);
 }
示例#32
0
        /// <summary>
        /// Registers a new user.
        /// </summary>
        /// <param name="User">User to be added.</param>
        public void RegisterPerson(Common.Person Person, string street, string property, Guid?ddLocality, Guid?ddStreet)
        {
            if (Person.IdCardNumber != null)
            {
                if (CheckRegister(Person.IdCardNumber))
                {
                    if (Person.Gender_fk == "None")
                    {
                        Person.Gender_fk = null;
                    }
                    Person.PersonID = Guid.NewGuid();
                    DataLayer.PatientsHandler dap = new DataLayer.PatientsHandler();
                    if (property == "")
                    {
                        this.AddPersonToDatabase(Person);
                    }
                    else
                    {
                        if (street == "")
                        {
                            Common.Property p = new Common.Property();
                            p.PropertyName = property;
                            p.Street_fk    = ddStreet;
                            p.PropertyId   = Guid.NewGuid();
                            dap.AddProperty(p);
                            Person.Property_fk = p.PropertyId;
                            this.AddPersonToDatabase(Person);
                        }
                        else
                        {
                            Common.Street s = new Common.Street();
                            s.StreetName  = street;
                            s.Locality_fk = ddLocality;
                            s.StreetId    = Guid.NewGuid();
                            dap.AddStreet(s);

                            Common.Property p = new Common.Property();
                            p.PropertyName = property;
                            p.Street_fk    = s.StreetId;
                            p.PropertyId   = Guid.NewGuid();
                            dap.AddProperty(p);
                            Person.Property_fk = p.PropertyId;
                            this.AddPersonToDatabase(Person);
                        }
                    }
                }
            }
            else
            {
                if (Person.Gender_fk == "None")
                {
                    Person.Gender_fk = null;
                }
                Person.PersonID = Guid.NewGuid();
                DataLayer.PatientsHandler dap = new DataLayer.PatientsHandler();
                if (property == "")
                {
                    this.AddPersonToDatabase(Person);
                }
                else
                {
                    if (street == "")
                    {
                        Common.Property p = new Common.Property();
                        p.PropertyName = property;
                        p.Street_fk    = ddStreet;
                        p.PropertyId   = Guid.NewGuid();
                        dap.AddProperty(p);
                        Person.Property_fk = p.PropertyId;
                        this.AddPersonToDatabase(Person);
                    }
                    else
                    {
                        Common.Street s = new Common.Street();
                        s.StreetName  = street;
                        s.Locality_fk = ddLocality;
                        s.StreetId    = Guid.NewGuid();
                        dap.AddStreet(s);

                        Common.Property p = new Common.Property();
                        p.PropertyName = property;
                        p.Street_fk    = s.StreetId;
                        p.PropertyId   = Guid.NewGuid();
                        dap.AddProperty(p);
                        Person.Property_fk = p.PropertyId;
                        this.AddPersonToDatabase(Person);
                    }
                }
            }
        }
 public void UpdatePerson(string lastName, Person updatedPerson)
 {
     ServiceProxy.UpdatePerson(lastName, updatedPerson);
 }
示例#34
0
        /// <summary>
        /// Takes a <see cref="Common.Person">Person</see> and allows them
        /// to join the chat room, if there is not already a chatter with
        /// the same name
        /// </summary>
        /// <param name="person"><see cref="Common.Person">Person</see> joining</param>
        /// <returns>An array of <see cref="Common.Person">Person</see> objects</returns>
        public Person[] Join(Person person)
        {
            bool userAdded = false;
            //create a new ChatEventHandler delegate, pointing to the MyEventHandler() method
            myEventHandler = new ChatEventHandler(MyEventHandler);

            //carry out a critical section that checks to see if the new chatter
            //name is already in use, if its not allow the new chatter to be
            //added to the list of chatters, using the person as the key, and the
            //ChatEventHandler delegate as the value, for later invocation
            lock (syncObj)
            {
                if (!checkIfPersonExists(person.Name) && person != null)
                {
                    this.person = person;
                    chatters.Add(person, MyEventHandler);
                    userAdded = true;
                }
            }

            //if the new chatter could be successfully added, get a callback instance
            //create a new message, and broadcast it to all other chatters, and then 
            //return the list of al chatters such that connected clients may show a
            //list of all the chatters
            if (userAdded)
            {
                callback = OperationContext.Current.GetCallbackChannel<IChatCallback>();
                ChatEventArgs e = new ChatEventArgs();
                e.msgType = MessageType.UserEnter;
                e.person = this.person;
                BroadcastMessage(e);
                //add this newly joined chatters ChatEventHandler delegate, to the global
                //multicast delegate for invocation
                ChatEvent += myEventHandler;
                Person[] list = new Person[chatters.Count];
                //carry out a critical section that copy all chatters to a new list
                lock (syncObj)
                {
                    chatters.Keys.CopyTo(list, 0);
                }
                return list;
            }
            else
            {
                return null;
            }
        }
 public void UpdatePerson(string lastName, Person updatedPerson)
 {
     _wrappedRepository.UpdatePerson(lastName, updatedPerson);
     InvalidateCache();
 }
 public void UpdatePerson(string lastName, Person updatedPerson)
 {
     throw new NotImplementedException();
 }