Exemple #1
0
        public Person GetPerson(int id)
        {
            DataSet ds = new DataSet();

            ds = ExecuteQuery($"Select top 1 * from Persons where id = '{id}'");
            DataRow r = ds.Tables[0].Rows[0];

            switch ((string)r["role"].ToString().ToUpper())
            {
            case "AGENT":
                Person a = new Agent((int)r["id"], (string)r["name"], (string)r["address"], (string)r["nationality"], (string)r["serializedImage"], (string)r["description"]);
                return(a);

            case "INFORMANT":
                Person i = new Informant((int)r["id"], (string)r["name"], (string)r["address"], (string)r["nationality"], (string)r["serializedImage"], (string)r["description"], (string)r["methodOfPayment"], (string)r["currency"]);
                return(i);

            case "OBSERVANT":
                Person o = new Observant((int)r["id"], (string)r["name"], (string)r["address"], (string)r["nationality"], (string)r["serializedImage"], (string)r["description"]);
                return(o);

            default:
                throw new ArgumentException("Role Not Valid");
            }
        }
Exemple #2
0
 public EditInformant(Informant i)
 {
     InitializeComponent();
     db                     = new DBHandler();
     informant              = i;
     imgString              = informant.SerializedImage;
     lblName.Content        = informant.Name;
     lblAddress.Content     = informant.Address;
     lblNationality.Content = informant.Nationality;
     lblDescription.Content = informant.Description;
     lblMoP.Content         = informant.MethodOfPayment;
     lblCurrency.Content    = informant.Currency;
     tbxName.Text           = informant.Name;
     tbxAddress.Text        = informant.Address;
     tbxNationality.Text    = informant.Nationality;
     tbxDescription.Text    = informant.Description;
     tbxMoP.Text            = informant.MethodOfPayment;
     tbxCurrency.Text       = informant.Currency;
     if (informant.SerializedImage.ToUpper() != "PLACEHOLDER")
     {
         imgPicture.Source = db.StringToImage(informant.SerializedImage);
     }
 }
Exemple #3
0
 public int UpdatePerson(Person p)
 {
     if (p.GetType() == typeof(Agent))
     {
         return(ExecuteNonQuery($"update Persons set role = 'AGENT', name = '{p.Name}', address = '{p.Address}', nationality = '{p.Nationality}', serializedImage = '{p.SerializedImage}', description = '{p.Description}' " +
                                $"Where ID = '{p.Id}'"));
     }
     else if (p.GetType() == typeof(Informant))
     {
         Informant i = p as Informant;
         return(ExecuteNonQuery($"update Persons set role = 'INFORMANT', name = '{p.Name}', address = '{p.Address}', nationality = '{p.Nationality}', serializedImage = '{p.SerializedImage}', description = '{p.Description}', methodOfPayment = '{i.MethodOfPayment}', currency = '{i.Currency}' " +
                                $"Where ID = '{p.Id}'"));
     }
     else if (p.GetType() == typeof(Observant))
     {
         return(ExecuteNonQuery($"update Persons set role = 'OBSERVANT', name = '{p.Name}', address = '{p.Address}', nationality = '{p.Nationality}', serializedImage = '{p.SerializedImage}', description = '{p.Description}' " +
                                $"Where ID = '{p.Id}'"));
     }
     else
     {
         throw new ArgumentException("Role Invalid or Not Implemented");
     }
 }
Exemple #4
0
 public int NewPerson(Person p)
 {
     if (p.GetType() == typeof(Agent))
     {
         return(ExecuteNonQuery("insert into Persons (role, name, address, nationality, serializedImage, description) " +
                                $"values ('AGENT', '{p.Name}', '{p.Address}', '{p.Nationality}', '{p.SerializedImage}', '{p.Description}')"));
     }
     else if (p.GetType() == typeof(Informant))
     {
         Informant i = p as Informant;
         return(ExecuteNonQuery("insert into Persons (role, name, address, nationality, serializedImage, description, methodOfPayment, currency) " +
                                $"values ('INFORMANT', '{p.Name}', '{p.Address}', '{p.Nationality}', '{p.SerializedImage}', '{p.Description}', '{i.MethodOfPayment}', '{i.Currency}')"));
     }
     else if (p.GetType() == typeof(Observant))
     {
         return(ExecuteNonQuery("insert into Persons (role, name, address, nationality, serializedImage, description) " +
                                $"values ('OBSERVANT', '{p.Name}', '{p.Address}', '{p.Nationality}', '{p.SerializedImage}', '{p.Description}')"));
     }
     else
     {
         throw new ArgumentException("Person Type Not Implemented");
     }
 }
Exemple #5
0
 private void BtnCreate_Click(object sender, RoutedEventArgs e)
 {
     if (String.IsNullOrEmpty(tbxName.Text))
     {
         MessageBox.Show("You must enter a name");
     }
     else if (String.IsNullOrEmpty(tbxAddress.Text))
     {
         MessageBox.Show("You must enter an Address");
     }
     else if (String.IsNullOrEmpty(tbxNationality.Text))
     {
         MessageBox.Show("You must enter a Nationality (NAN for unknown)");
     }
     else if (String.IsNullOrEmpty(tbxMoP.Text))
     {
         MessageBox.Show("You must enter a Method of Payment");
     }
     else if (String.IsNullOrEmpty(tbxCurrency.Text))
     {
         MessageBox.Show("You must enter a Currency");
     }
     else
     {
         if (tbxNationality.Text.Count() != 3)
         {
             MessageBox.Show("Nationality must follow the standards of ISO-3166, Alpha-3");
         }
         else
         {
             Informant i = new Informant(tbxName.Text, tbxAddress.Text, tbxNationality.Text, imgstring, tbxDescription.Text, tbxMoP.Text, tbxCurrency.Text);
             db.NewPerson(i);
             this.Close();
         }
     }
 }