// Save data to XML file after upload
 private void SaveTraineesToXML()
 {
     try
     {
         SerializeXml sx = new SerializeXml();
         sx.WriteXml(Trainees);
     }
     catch
     {
         MessageBox.Show("Trainees' data couldn't save.", "Save Data to XML File", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
        private void SaveTrainee()
        {
            try
            {
                if (cbxPolicyAgreement.IsChecked == true)
                {
                    bool isExist = false;
                    Person = new PersonAndDbidsOperators.Person();
                    PersonAndDbidsOperators.Person personExist = new PersonAndDbidsOperators.Person();
                    string date = DateTime.Now.ToShortDateString();
                    string birth = dpkDateOfBirth.SelectedDate.ToString();
                    string pid = SetPID();
                    string filename = string.Format(@"Images\{0}{1}{2}.jpg", txtLastName.Text, txtFirstName.Text.Substring(0, 1), pid.Substring(pid.Length - 4, 4));

                    if (Operators != null)
                    {
                        foreach (PersonAndDbidsOperators.Person person in Operators.Persons)
                        {
                            if (pid == person.PID)
                            {
                                isExist = true;
                                personExist = person;
                            }
                        }
                    }
                    else
                    {
                        Operators = new PersonAndDbidsOperators();
                        Operators.Persons = new List<PersonAndDbidsOperators.Person>();
                    }

                    Person.PID = pid;
                    Person.LastName = txtLastName.Text;
                    Person.MobilePhone = string.Format("{0}-{1}-{2}", cbxMobilePhoneArea.SelectedValue, txtMobilePhonePrefix.Text, txtMobilePhoneNumber.Text);
                    Person.FirstName = txtFirstName.Text;
                    Person.MiddleName = txtMiddleName.Text;
                    Person.DateOfBirth = birth;
                    Person.Gender = cbxGender.SelectedValue.ToString();
                    Person.OfficePhone = string.Format("{0}-{1}-{2}", cbxOfficePhoneArea.SelectedValue, txtOfficePhonePrefix.Text, txtOfficePhoneNumber.Text);
                    //Person.Fax = string.Format("{0}-{1}-{2}", cbxFaxArea.SelectedValue, txtFaxPrefix.Text, txtFaxNumber.Text);
                    Person.Photo = filename;
                    if (cbxEmailServer.SelectedValue.ToString() != "** Manual Input **")
                        Person.Email = string.Format("{0}@{1}", txtEmail.Text, cbxEmailServer.SelectedValue);
                    else
                        Person.Email = txtEmail.Text;
                    Person.ServiceType = cbxService.SelectedValue.ToString();
                    Person.RankID = cbxRank.SelectedValue.ToString();
                    Person.OfficeCode = cbxOffice.SelectedValue.ToString();
                    Person.TypeOfPID = cbxTypeOfPID.SelectedValue.ToString();
                    Person.RegDate = date;
                    Person.JobTitle = txtJobTitle.Text;
                    Person.PersonRemarks = txtPRRemarks.Text;
                    Person.OperatorType = cbxOperatorType.SelectedValue.ToString();
                    Person.LastTrainedDate = date;
                    Person.Installation = cbxInstallation.SelectedValue.ToString();
                    Person.Nationality = cbxNationality.SelectedValue.ToString();
                    Person.isPolicyAgree = cbxPolicyAgreement.IsChecked.ToString();
                    //if (cbxPolicyAgreement.IsChecked == true)
                    //    Person.isPolicyAgree = "true";
                    //else
                    //    Person.isPolicyAgree = "false";

                    if (isExist)
                    {
                        Operators.Persons.Remove(personExist);
                    }

                    if (imgDBIDSOperator.Source != null)
                        SaveImage(Person.LastName, Person.FirstName, pid, filename);
                    Operators.Persons.Add(Person);

                    SerializeXml sx = new SerializeXml();
                    sx.WriteXml(Operators);
                    if (string.IsNullOrEmpty(Person.MiddleName))
                        MessageBox.Show(string.Format("{0}, {1}'s information has been saved.", txtLastName.Text, txtFirstName.Text));
                    else
                        MessageBox.Show(string.Format("{0}, {1} {2}'s information has been saved.", txtLastName.Text, txtFirstName.Text, txtMiddleName.Text));
                    GetOperators();
                }
                else
                {
                    MessageBox.Show("You should agree with the privacy information policy");
                    cbxPolicyAgreement.Background = Brushes.Red;
                }
            }
            catch (Exception ex)
            {
                if (string.IsNullOrEmpty(Person.MiddleName))
                    MessageBox.Show(string.Format("{0}, {1}'s information couldn't saved. /n{2}", txtLastName.Text, txtFirstName.Text, ex.ToString()));
                else
                    MessageBox.Show(string.Format("{0}, {1} {2}'s information couldn't saved. /n{3}", txtLastName.Text, txtFirstName.Text, txtMiddleName.Text, ex.ToString()));
            }
            finally
            {
                DeserializeXml dx = new DeserializeXml();
                Operators = dx.DeserializePersons();
            }

        }
 private void InsertOrUpdateData()
 {
     ProgressBarForProcess progressBarforProcess = new ProgressBarForProcess(this, TraineeToUpload);
     progressBarforProcess.ShowDialog();
     SerializeXml sx = new SerializeXml();
     sx.WriteXml(Trainees);
     GetOperators();
     MessageBox.Show("Completed to upload");
     lbxUploading.ItemsSource = null;
     lbxUploading.ItemsSource = TraineeToUpload;
 }
 private void btnDBIDSRemove_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         MessageBoxResult result = MessageBox.Show(string.Format("Do you want to remove {0}, {1}'s record?", txtLastName.Text, txtFirstName.Text),
             "Remove Person", MessageBoxButton.YesNo, MessageBoxImage.Warning);
         if (result.ToString().Equals("Yes"))
         {
             if (Person != null)
             {
                 var trainedPerson = Operators.Persons.Where(p => p.PID.Equals(Person.PID)).Select(p => p).First();
                 Operators.Persons.Remove(trainedPerson);
                 SerializeXml sx = new SerializeXml();
                 sx.WriteXml(Operators);
                 GetOperators();
                 dgdFindPersonList.ItemsSource = null;
                 MessageBox.Show(string.Format("{0}'s record has been removed", txtLastName.Text));
                 ClearAll();
             }
             else
             {
                 MessageBox.Show(string.Format("{0}'s record not found", txtLastName.Text));
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Couldn't remove data /r Error : {0}", ex.ToString());
     }
 }