예제 #1
0
        public List<TrainingDate> GetDates(PersonAndDbidsOperators operators)
        {
            //PersonAndDbidsOperators operators = new PersonAndDbidsOperators();
            //DeserializeXml dx = new DeserializeXml();
            //operators = dx.DeserializePersons();

            List<TrainingDate> listToReturn = new List<TrainingDate>();
            int countByDate = 0;


            var dates = operators.Persons.Select(p => p.LastTrainedDate).Distinct();
            int totalNumbers = operators.Persons.Count();

            if (dates != null)
            {
                foreach (var date in dates)
                {
                    if (date != null)
                    {
                        countByDate = operators.Persons.Where(p => p.LastTrainedDate.Equals(date)).Count();
                        listToReturn.Add(new TrainingDate(date, string.Format(" ({0})", countByDate.ToString())));
                    }
                }
            }

            return listToReturn;
        }
예제 #2
0
        public void WriteXml(PersonAndDbidsOperators operators)
        {
            string filename = Path.Combine(root, @"Data\PersonAndDbidsOperators.xml");
            serializer = new XmlSerializer(typeof(PersonAndDbidsOperators));

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            fs = new FileStream(filename, FileMode.Create);
            serializer.Serialize(fs, operators);
            fs.Close();
        }
        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();
            }

        }