Esempio n. 1
0
        public void PopulateControls()
        {
            foreach (PropertyInfo item in myProperty.GetType().GetProperties())
            {
                if (item.GetCustomAttribute <ForeignKeyAttribute>() != null)
                {
                    PropertyClassProizvodjac foreignInterface = Assembly.GetExecutingAssembly().
                                                                CreateInstance(item.GetCustomAttribute <ForeignKeyAttribute>().referencedClass) as PropertyClassProizvodjac;

                    LookupControl lookup = new LookupControl(foreignInterface);
                    lookup.Name = item.Name;
                    lookup.setLabel(item.GetCustomAttribute <DisplayNameAttribute>().DisplayName);

                    flpModel.Controls.Add(lookup);
                }
                else if (item.GetCustomAttribute <ForeignField>() != null)
                {
                    continue;
                }

                else if (item.GetCustomAttribute <PrimaryKeyAttribute>() != null)
                {
                    continue;
                }

                else
                {
                    InputControl ic = new InputControl();

                    ic.Naziv = item.GetCustomAttribute <DisplayNameAttribute>().DisplayName;

                    if (item.GetCustomAttribute <PrimaryKeyAttribute>() != null)
                    {
                        ic.Enabled = false;
                    }

                    flpModel.Controls.Add(ic);
                }
            }
        }
Esempio n. 2
0
        public bool Add(bool poljaIspravnoPopunjena)
        {
            var    properties = myProperty.GetType().GetProperties();
            bool   nepravlinoIspunjenoPolje = false;
            string poruka = "";


            foreach (var item in flpModel.Controls)
            {
                if (item.GetType() == typeof(LookupControl))
                {
                    LookupControl input = item as LookupControl;
                    string        value = input.Key;

                    if (value == "" || value == null)
                    {
                        nepravlinoIspunjenoPolje = true;
                        if (poruka == "")
                        {
                            poruka += "Morate popuniti sva polja.\n";
                        }
                    }

                    else
                    {
                        PropertyInfo property = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                        property.SetValue(myProperty, Convert.ChangeType(value, property.PropertyType));
                    }
                }
                else if (item.GetType() == typeof(InputControl))
                {
                    InputControl input = item as InputControl;
                    if (!input.Enabled)
                    {
                        continue;
                    }
                    string value = input.UnosPolje;


                    if (value == "" || value == null)
                    {
                        nepravlinoIspunjenoPolje = true;
                        if (poruka == "")
                        {
                            poruka += "Morate popuniti sva polja.\n";
                        }
                    }
                    else if (input.Naziv == "Naziv" && Regex.IsMatch(value, @"[@#%&',.\+$]"))
                    {
                        nepravlinoIspunjenoPolje = true;
                        poruka += input.Naziv + " ne smije sadržavati specijalne karaktere .\n";
                    }
                    else
                    {
                        PropertyInfo property = properties.Where(x => input.Naziv == x.GetCustomAttribute <DisplayNameAttribute>().DisplayName).FirstOrDefault();
                        property.SetValue(myProperty, Convert.ChangeType(value, property.PropertyType));
                    }
                }
            }
            if (nepravlinoIspunjenoPolje == true)
            {
                CustomMessageBox mb = new CustomMessageBox("Greska", poruka, MessageBoxIcon.Error);
                poljaIspravnoPopunjena = true;
                return(poljaIspravnoPopunjena);
            }
            else
            {
                SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text,
                                          myProperty.GetInsertQuery(), myProperty.GetInsertParameters().ToArray());

                poljaIspravnoPopunjena = false;
                return(poljaIspravnoPopunjena);
            }
        }