Beispiel #1
0
        private void PopulateControls()
        {
            Opacity = 0.95;

            if (myInterface is PropertyIznajmljivanje && state == StateEnum.Update)
            {
                tilePotvrdi.Enabled = false;
            }

            foreach (PropertyInfo item in myInterface.GetType().GetProperties())
            {
                if (item.GetCustomAttribute <ForeignKeyAttribute>() != null)
                {
                    PropertyInterface foreignKeyInterface = Assembly.GetExecutingAssembly().
                                                            CreateInstance(item.GetCustomAttribute <ForeignKeyAttribute>().className) as PropertyInterface;
                    LookUpControl ul = new LookUpControl(foreignKeyInterface);
                    ul.Name = item.Name;
                    if (state == StateEnum.Update)
                    {
                        ul.Enabled = true;
                    }



                    if (item.GetCustomAttribute <RequiredAttribute>() != null)
                    {
                        ul.SetLabelObavezno("*");
                    }

                    //provjerava da li ima, id koji se prosljedjuje kroz konstruktor, kod unosa autora i izdavaca knjige
                    if (id != null && ul.Name == "KnjigaID" && state != StateEnum.Search)
                    {
                        ul.SetKey(id.ToString());
                        ul.Enabled = false;
                    }
                    //za login
                    if (myInterface.GetType() == typeof(PropertyLogin))
                    {
                        ul.SetKey(FormStandard.radnoMjestoId);
                        ul.Enabled = false;
                    }

                    //kao id zaposlenog postavlja se vrijednost staticke varijable koja tu vrijednost dobija prilikom logovanja
                    if (ul.Name == "ZaposleniID" && state != StateEnum.Search)
                    {
                        ul.SetKey(FormLogin.idZaposlenog);
                        ul.Enabled = false;
                    }

                    if (myInterface.GetType() == typeof(PropertyIznajmljivanje) && state == StateEnum.Update)
                    {
                        ul.Enabled = false;
                    }

                    ul.SetLabel(item.GetCustomAttribute <DisplayNameAttribute>().DisplayName);
                    if (state == StateEnum.Update)
                    {
                        ul.SetKey(item.GetValue(myInterface).ToString());
                    }

                    if (myInterface is PropertyClanarina && ul.Name == "TipID" && state == StateEnum.Create)
                    {
                        ul.AddTextChangedEvent();////////////////////////// dodaje jos jedan event za automatsko mijenjanje datuma za tip clanarine
                    }

                    flPanelControls.Controls.Add(ul);
                }

                else if (item.GetCustomAttribute <DateTimeAttribute>() != null)
                {
                    if (state == StateEnum.Create || state == StateEnum.Update)
                    {
                        DateTimeControl dtc = new DateTimeControl();
                        dtc.Name = item.Name;
                        dtc.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);

                        if (dtc.Name == "DatumRazduzivanja" || dtc.Name == "DatumIznajmljivanja")
                        {
                            dtc.Enabled = false;
                        }

                        if (state == StateEnum.Create)
                        {
                            dtc.SetValue(DateTime.Now);
                        }
                        else if (state == StateEnum.Update)
                        {
                            dtc.SetValue((DateTime)item.GetValue(myInterface));
                        }

                        flPanelControls.Controls.Add(dtc);

                        if (state == StateEnum.Create && dtc.Name == "DatumRazduzivanja")
                        {
                            dtc.SetValue(DateTime.Now.AddDays(15));
                        }
                        else if (state == StateEnum.Update && dtc.Name == "DatumRazduzivanja")
                        {
                            dtc.SetValue(DateTime.Now);
                        }

                        if (myInterface is PropertyClanarina)
                        {
                            dtc.Enabled = false;
                            if (state == StateEnum.Update)
                            {
                                tilePotvrdi.Enabled = false;
                            }
                        }
                    }
                    else if (state == StateEnum.Search)
                    {
                        DateRangeControl dateRange = new DateRangeControl();
                        dateRange.Name = item.Name;
                        dateRange.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                        flPanelControls.Controls.Add(dateRange);
                    }
                }
                else if (item.GetCustomAttribute <RadioValue>() != null)
                {
                    UserControlRadio ucr = new UserControlRadio();
                    ucr.Name = item.Name;
                    ucr.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);

                    if (state == StateEnum.Update)
                    {
                        ucr.SetValue(item.GetValue(myInterface).ToString());
                    }

                    if (item.GetCustomAttribute <RequiredAttribute>() != null)
                    {
                        ucr.SetLblObavezno("*");
                    }

                    flPanelControls.Controls.Add(ucr);
                }
                else if (item.GetCustomAttribute <CheckValue>() != null)
                {
                    if (state != StateEnum.Search)
                    {
                        MetroCheckBox cb = new MetroCheckBox();
                        cb.Name = "cbRazduzi";
                        cb.Text = item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName;
                        flPanelControls.Controls.Add(cb);
                        if (!((PropertyIznajmljivanje)myInterface).Razduzeno && state == StateEnum.Update)
                        {
                            cb.Enabled = true;
                        }
                        else
                        {
                            cb.Enabled = false;
                        }
                        cb.Checked = ((PropertyIznajmljivanje)myInterface).Razduzeno;
                        if (((PropertyIznajmljivanje)myInterface).Razduzeno)
                        {
                            tilePotvrdi.Enabled = false;
                        }
                        cb.Margin = new Padding(12, 0, 0, 0);

                        cb.CheckedChanged += Cb_CheckedChanged;
                    }
                    else
                    {
                        CheckBoxControl checkBoxControl = new CheckBoxControl();
                        checkBoxControl.Name = "Razduzeno";
                        flPanelControls.Controls.Add(checkBoxControl);
                    }
                }
                else
                {
                    InputControl ic = new InputControl();
                    ic.Name = item.Name;
                    ic.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);

                    if (item.GetCustomAttribute <RequiredAttribute>() != null)
                    {
                        ic.SetLblObavezno("*");
                    }

                    if (state == StateEnum.Create && item.GetCustomAttribute <PrimaryKeyAttribute>() != null)
                    {
                        ic.SetValue("0");
                        ic.Visible = false;
                    }
                    else if (state == StateEnum.Update && item.GetCustomAttribute <PrimaryKeyAttribute>() != null)
                    {
                        ic.Visible = false;
                        ic.Enabled = false;
                    }
                    if (state == StateEnum.Update)
                    {
                        ic.SetValue(item.GetValue(myInterface).ToString());
                    }
                    if (item.GetCustomAttribute <ForeignKeyAttribute>() != null && state == StateEnum.Update)
                    {
                        ic.Enabled = false;
                    }

                    if (myInterface.GetType() == typeof(PropertyLogin))
                    {
                        if (ic.Name != "KorisnickoIme")
                        {
                            ic.Enabled = false;
                        }

                        switch (ic.Name.ToString())
                        {
                        case "ZaposleniID":
                            ic.SetValue(FormStandard.zaposleniId);
                            break;

                        case "KorisnickoIme":
                            ic.SetValue(FormStandard.korisnickoIme);
                            break;

                        default:
                            break;
                        }
                    }

                    if (myInterface is PropertyKnjiga && ic.Name == "Kolicina" && state != StateEnum.Search)
                    {
                        ic.Enabled = false;
                    }
                    flPanelControls.Controls.Add(ic);
                }
            }
        }