Esempio n. 1
0
        //Pravi i popunjava detaljan prokaz podataka iz selektovanog reda
        private void popuniDetaljno(PropertyInterface property, StateEnum state)
        {
            try
            {
                if (dgvPrikaz.SelectedRows.Count > 0)
                {
                    ocistiKontrole();
                    foreach (PropertyInfo item in property.GetType().GetProperties())
                    {
                        if (item.GetCustomAttribute <ForeignKeyAttribute>() != null)
                        {
                            PropertyInterface foreignKeyInterface = Assembly.GetExecutingAssembly().
                                                                    CreateInstance(item.GetCustomAttribute <ForeignKeyAttribute>().className)
                                                                    as PropertyInterface;
                            UserLookUpControl ul = new UserLookUpControl(foreignKeyInterface);
                            ul.Name = item.Name;
                            ul.Zabrani();
                            ul.SetLabel(item.GetCustomAttribute <DisplayNameAttribute>().DisplayName);
                            ul.SetKey(item.GetValue(property).ToString());

                            DataTable dt    = new DataTable();
                            string    query = @"select * from " + item.GetCustomAttribute <ForeignKeyAttribute>().referencedTable +
                                              " where " + item.GetCustomAttribute <SqlNameAttribute>().Naziv + "=" + ul.getKey();
                            //MessageBox.Show(query);
                            SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text, query);

                            dt.Load(reader);
                            reader.Close();

                            string colName  = dt.Columns[1].ColumnName;
                            string colValue = "";
                            if (colName == "Ime")
                            {
                                colValue = dt.Rows[0][1].ToString() + " " + dt.Rows[0][2].ToString();
                            }
                            else if (colName.Contains("ID"))
                            {
                                PropertyInterface foreignKeyInterface1 = new FilmPropertyClass();
                                DataTable         dt1     = new DataTable();
                                SqlDataReader     reader1 = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                                                    foreignKeyInterface1.GetLookUpQuery(dt.Rows[0][1].ToString()));

                                dt1.Load(reader1);
                                reader1.Close();
                                colValue = dt1.Rows[0][0].ToString();
                            }
                            else
                            {
                                try
                                {
                                    colValue = dt.Rows[0][1].ToString();
                                }
                                catch
                                {
                                }
                            }

                            ul.SetValue(colValue);
                            flpDetaljno.Controls.Add(ul);
                            if (state == StateEnum.Preview)
                            {
                                ul.Zakljucaj();//Zakljucaj nakon sto se spojimo sa markom
                            }
                        }
                        else if (item.GetCustomAttribute <RichTextBoxAttribute>() != null)
                        {
                            RichTextBoxControl rc = new RichTextBoxControl();
                            rc.Name = item.Name;
                            rc.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                            rc.SetVrijednost(item.GetValue(property).ToString());
                            flpDetaljno.Controls.Add(rc);
                            if (state == StateEnum.Preview)
                            {
                                rc.Zabrani();
                            }
                        }
                        else if (item.GetCustomAttribute <DateTimeAttribute>() != null)
                        {
                            DateTimeControl dc = new DateTimeControl();
                            dc.SetVrijednost(item.GetValue(property).ToString());
                            dc.Name = item.Name;
                            dc.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                            flpDetaljno.Controls.Add(dc);
                            if (state == StateEnum.Preview)
                            {
                                dc.Zabrani();
                            }
                        }
                        else if (item.GetCustomAttribute <CheckBoxAttribute>() != null)
                        {
                            CheckBoxControl cb = new CheckBoxControl();
                            cb.SetValue(Convert.ToBoolean(item.GetValue(property)));
                            cb.Name = item.Name;
                            cb.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                            flpDetaljno.Controls.Add(cb);
                            if (state == StateEnum.Preview)
                            {
                                cb.Zabrani();
                            }
                        }
                        else if (item.GetCustomAttribute <NumericAttribute>() != null)
                        {
                            NumericUpDownControl num = new NumericUpDownControl();
                            num.SetValue(Convert.ToDecimal(item.GetValue(property)));
                            num.Name = item.Name;
                            num.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                            flpDetaljno.Controls.Add(num);
                            if (state == StateEnum.Preview)
                            {
                                num.Zabrani();
                            }
                        }
                        else
                        {
                            if (item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName == "Lozinka")
                            {
                                continue;
                            }
                            else if (item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName == "Naziv filma" &&
                                     property.GetType() == typeof(ProjekcijaPropertyClass))
                            {
                                continue;
                            }
                            else
                            {
                                TextBoxControl uc = new TextBoxControl();
                                uc.Name = item.Name;
                                uc.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                                uc.SetTextBox(item.GetValue(property).ToString());

                                if (item.GetCustomAttribute <PrimaryKeyAttribute>() != null)
                                {
                                    uc.Zabrani();
                                }
                                flpDetaljno.Controls.Add(uc);
                                if (state == StateEnum.Preview)
                                {
                                    uc.Zabrani();
                                }
                            }
                        }
                    }
                    if (property.GetType() == typeof(LoginPropertyClass))
                    {
                        dgvPrikaz.Columns["Lozinka"].Visible = false;
                    }

                    if (state == StateEnum.Preview)
                    {
                        panelDugmici.Visible = false;
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
                MessageBox.Show(e.Message);
            }
        }
Esempio n. 2
0
        //Zavisno od tog u kom smo meniju pravi kontrole u panelu (PRAZNE)
        private void postaviControle(PropertyInterface property)
        {
            ocistiKontrole();
            var properties = property.GetType().GetProperties();

            foreach (PropertyInfo item in properties)
            {
                if (item.GetCustomAttribute <ForeignKeyAttribute>() != null)
                {
                    PropertyInterface foreignKeyInterface = Assembly.GetExecutingAssembly().
                                                            CreateInstance(item.GetCustomAttribute <ForeignKeyAttribute>().className)
                                                            as PropertyInterface;
                    UserLookUpControl ul = new UserLookUpControl(foreignKeyInterface);
                    ul.Name = item.Name;
                    ul.SetLabel(item.GetCustomAttribute <DisplayNameAttribute>().DisplayName);
                    ul.Zabrani();
                    flpDetaljno.Controls.Add(ul);
                }
                else if (item.GetCustomAttribute <RichTextBoxAttribute>() != null)
                {
                    RichTextBoxControl rc = new RichTextBoxControl();
                    rc.Name = item.Name;
                    rc.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                    flpDetaljno.Controls.Add(rc);
                }
                else if (item.GetCustomAttribute <DateTimeAttribute>() != null)
                {
                    DateTimeControl dc = new DateTimeControl();
                    dc.Name = item.Name;
                    dc.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                    dc.SetVrijednost(DateTime.Now.ToShortDateString());
                    flpDetaljno.Controls.Add(dc);
                }
                else if (item.GetCustomAttribute <CheckBoxAttribute>() != null)
                {
                    CheckBoxControl cb = new CheckBoxControl();
                    cb.Name = item.Name;
                    cb.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                    flpDetaljno.Controls.Add(cb);
                }
                else if (item.GetCustomAttribute <NumericAttribute>() != null)
                {
                    NumericUpDownControl num = new NumericUpDownControl();
                    num.Name = item.Name;
                    num.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                    flpDetaljno.Controls.Add(num);
                }
                else //if (item.GetCustomAttribute<SqlNameAttribute>() != null)
                {
                    TextBoxControl uc = new TextBoxControl();
                    if (item.GetCustomAttribute <PrimaryKeyAttribute>() != null)
                    {
                        continue;
                    }
                    if (item.GetCustomAttribute <TimeAttribute>() != null)
                    {
                        uc.SetTextBox("00:00:00");
                    }
                    uc.Name = item.Name;
                    uc.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                    flpDetaljno.Controls.Add(uc);
                }
            }
        }