Exemplo n.º 1
0
        public LookupForm(PropertyInterface mp)
        {
            InitializeComponent();
            myProperty = mp;

            if (mp.GetType() == typeof(PropertyClassZaposleni))
            {
                this.Text = "Zaposleni";
            }
            else if (mp.GetType() == typeof(PropertyClassModel))
            {
                this.Text            = "Model";
                btnNoviModel.Visible = true;
            }
            else if (mp.GetType() == typeof(PropertyClassVozila))
            {
                this.Text = "Vozila";
            }
            else if (mp.GetType() == typeof(PropertyClassProizvodjac))
            {
                this.Text = "Proizvodjaci";
            }

            PopulateGrid();

            formatiranejGrida();



            lookupGrid.CellDoubleClick += btnReturn_Click;
        }
Exemplo n.º 2
0
        public void Delete(PropertyInterface myProperty, int SelektovaniRed, Bunifu.Framework.UI.BunifuCustomDataGrid dgv)
        {
            try
            {
                DataGridViewRow row        = dgv.SelectedRows[0];
                var             properties = myProperty.GetType().GetProperties();

                foreach (PropertyInfo item in properties)
                {
                    if (item.GetCustomAttribute <PrimaryKeyAttribute>() != null)
                    {
                        string value = row.Cells[item.GetCustomAttribute <SqlNameAttribute>().Name]
                                       .Value.ToString();

                        item.SetValue(myProperty, Convert.ChangeType(value, item.PropertyType));
                    }
                }

                SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text,
                                          myProperty.GetDeleteQuery(), myProperty.GetDeleteParameters().ToArray());
                CRUD.IstorijaCRUD.Istorija(UserEmail, StateEnum.Delete, myProperty);
                //PopulateGrid(myProperty);
            }
            catch (System.Data.SqlClient.SqlException)
            {
                MessageBox.Show("\n\nNemoguce je obrisati ovaj red zbog povezanosti sa drugim tabelama!!!\n\n", "Greska pri brisanju!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
 public Izvjestaj(PropertyInterface property)
 {
     InitializeComponent();
     if (property.GetType() == typeof(PropertyVozilo))
     {
         rvIzvjestaj.ServerReport.ReportPath = "/Report_RentACarOscar/izvjestajVozila";
     }
     else if (property.GetType() == typeof(PropertyKlijent))
     {
         rvIzvjestaj.ServerReport.ReportPath = "/Report_RentACarOscar/izvjestajKlijenti";
     }
     else if (property.GetType() == typeof(PropertyRadnik))
     {
         rvIzvjestaj.ServerReport.ReportPath = "/Report_RentACarOscar/izvjestajZaposleni";
     }
     else if (property.GetType() == typeof(PropertyFaktura))
     {
         rvIzvjestaj.ServerReport.ReportPath = "/Report_RentACarOscar/izvjestajSvihFaktura";
     }
 }
Exemplo n.º 4
0
        public void GetSelectAll()
        {
            dgvPregledLookUp.DataSource = null;
            DataTable     dt     = new DataTable();
            SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text, myProperty.GetSelectQuery());

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

            dgvPregledLookUp.DataSource = dt;
            //izvuci display name
            var properties = myProperty.GetType().GetProperties();


            //promjeniti nazive kolona
            foreach (DataGridViewColumn item in dgvPregledLookUp.Columns)
            {
                item.HeaderText = properties.Where(x => x.GetCustomAttributes <SqlNameAttribute>().FirstOrDefault().Naziv == item.HeaderText
                                                   ).FirstOrDefault().GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName;
            }
        }
Exemplo n.º 5
0
        private void PopulateGrid()
        {
            DataTable dt = new DataTable();

            SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                           myProperty.GetLookupQuery());

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

            lookupGrid.DataSource = dt;

            var type       = myProperty.GetType();
            var properties = type.GetProperties();

            foreach (DataGridViewColumn item in lookupGrid.Columns)
            {
                item.HeaderText = properties.Where(x => x.GetCustomAttributes <SqlNameAttribute>().FirstOrDefault().Name == item.HeaderText
                                                   ).FirstOrDefault().GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName;
            }
        }
Exemplo n.º 6
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);
                }
            }
        }
Exemplo n.º 7
0
        //Ucitavanje zadate Property klase iz foldera IspisDGV
        private void PopuniDGV(DataTable dt, PropertyInterface property)
        {
            //Ciscenje panela za refresh
            panelPanelZaGV.Controls.Clear();

            //Restart DGV-a
            dgv = new Bunifu.Framework.UI.BunifuCustomDataGrid();

            //pozadina hedera
            panelPanelZaGV.Controls.Add(dgv);

            //Popunjavanje tabele sa vrijednostima
            dgv.DataSource = dt;

            //Poziv metode za dizajniranje DGV-a
            DGVDizajn();

            //izvuci display name
            var type       = property.GetType();
            var properties = type.GetProperties();

            //promijeniti nazive kolona
            if (property.GetType() != typeof(VoziloIspis))
            {
                foreach (DataGridViewColumn item in dgv.Columns)
                {
                    item.HeaderText = properties.Where(x => x.GetCustomAttributes <SqlNameAttribute>().FirstOrDefault().Name == item.HeaderText
                                                       ).FirstOrDefault().GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName;
                }
            }

            //sakrij ID
            if (property.GetType() == typeof(VoziloIspis) ||
                property.GetType() == typeof(PropertyKlijent))
            {
                dgv.Columns[0].Visible = false;
            }
        }
Exemplo n.º 8
0
        public void Update(PropertyInterface myProperty, string ID, Bunifu.Framework.UI.BunifuCustomDataGrid dgv)
        {
            //Pretraga
            SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                           myProperty.GetSelectQueryZaJedanItem(ID));

            DataTable dt = new DataTable();

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

            dgv.DataSource = dt;

            var type              = myProperty.GetType();
            var properties        = type.GetProperties();
            PropertyInterface pom = myProperty;
            int i = 0;

            try
            {
                foreach (DataGridViewCell cell in dgv.Rows[0].Cells)
                {
                    String value = cell.Value.ToString();

                    PropertyInfo property = properties.Where(x => dgv.Columns[i].HeaderText == x.GetCustomAttribute <DisplayNameAttribute>().DisplayName).FirstOrDefault();
                    property.SetValue(myProperty, Convert.ChangeType(value, property.PropertyType));
                    i++;
                }
            }
            catch { }

            InputForma inputForma = null;

            if (DetaljiUpdate != "detalji")
            {
                inputForma = new InputForma(myProperty, StateEnum.Update, UserEmail, UserID);
            }
            else
            {
                inputForma = new InputForma("detalji", myProperty, StateEnum.Update, UserEmail, UserID);
            }


            inputForma.ShowDialog();

            if (inputForma.DialogResult == DialogResult.Cancel)
            {
                return;
            }
        }
Exemplo n.º 9
0
        private void UcitajDGV(PropertyInterface property)
        {
            DataTable     dt     = new DataTable();
            SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text, property.GetSelectQuery());

            dt.Load(reader);
            reader.Close();
            dgvPrikaz.DataSource = null;
            dgvPrikaz.DataSource = dt;
            var prop = property.GetType().GetProperties();

            foreach (DataGridViewColumn item in dgvPrikaz.Columns)
            {
                item.HeaderText = prop.Where(x => x.GetCustomAttributes <SqlNameAttribute>().FirstOrDefault().Naziv ==
                                             item.HeaderText).FirstOrDefault().GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName;
            }
        }
Exemplo n.º 10
0
 public LookUpForma(PropertyInterface property, string mail, string ID)
 {
     InitializeComponent();
     this.StartPosition = FormStartPosition.CenterScreen;
     UserMail           = mail;
     UserID             = ID;
     myProperty         = property;
     PopulateGrid();
     if (property.GetType() != typeof(PropertyTipFakture))
     {
         btnDelete.Visible = true;
         btnInsert.Visible = true;
         btnUpdate.Visible = true;
     }
     else
     {
         btnDelete.Visible = false;
         btnInsert.Visible = false;
         btnUpdate.Visible = false;
     }
 }
Exemplo n.º 11
0
        //Insert operacija
        private void btnInsert_Click(object sender, EventArgs e)
        {
            //Metoda za upisivanje Mail-a i ID korisnika
            crud.UserMail(UserMail, UserID);

            //Pozivanje metode INSERT za zadatu Property klasu
            crud.Insert(myForm);

            //Popunjavanje DGV-a nakon zavrsene metode INSERT
            PopulateGrid(myProperty);

            if (myForm.GetType() == typeof(PropertyVozilo))
            {
                if (brojRedovaDGVAVozila < dgv.Rows.Count)
                {
                    PropertyInterface pom = myProperty;

                    //Kupljenje ID vozila iz DGV selektovanog reda
                    string ID = dgv.Rows[dgv.Rows.Count - 1].Cells[0].Value.ToString();

                    //Kreiranje objekta PropertyCijena i popunjavanje tabele sa cijenama
                    PropertyCijena cijenaTabela = new PropertyCijena();
                    myForm = cijenaTabela;
                    PopulateGrid(myForm);
                    myProperty = pom;
                    //Visible = false;

                    //Metoda za upisivanje Mail-a i ID korisnika
                    crud.UserMail(UserMail, UserID);

                    //Pozivanje metode UPDATE sa PropertyCijena, selektovani ID i dgv sa popunjenim podacima cijena
                    crud.Update(myForm, ID, dgv);
                    // Visible = true;

                    //Popunjavanje DGV-a nakon zavrsene metode UPDATE
                    PopulateGrid(myProperty);
                }
            }
        }
Exemplo n.º 12
0
 private void btnFind_Click(object sender, EventArgs e)
 {
     if (myInterface.GetType() == typeof(SjedistePropertyClass))
     {
         LookUpForm novaForma1 = new LookUpForm(myInterface, terminID);
         novaForma1.ShowDialog();
         Key              = novaForma1.Key;
         Value            = novaForma1.Value;
         txtValue.Text    = Value;
         txtKeyValue.Text = Key;
         return;
     }
     else
     {
         LookUpForm novaForma = new LookUpForm(myInterface);
         novaForma.ShowDialog();
         Key              = novaForma.Key;
         Value            = novaForma.Value;
         txtValue.Text    = Value;
         txtKeyValue.Text = Key;
     }
 }
Exemplo n.º 13
0
 //popunjava property podatcima iz selektovanog reda u  DataGridView
 private void PopulatePropertyInterface(PropertyInterface property)
 {
     try
     {
         DataGridViewRow row        = dgvPrikaz.SelectedRows[0];
         var             properties = property.GetType().GetProperties();
         foreach (PropertyInfo item in properties)
         {
             string value = row.Cells[item.GetCustomAttribute <SqlNameAttribute>().Naziv]
                            .Value.ToString();
             if (item.GetCustomAttribute <TimeAttribute>() != null)
             {
                 TimeSpan time = TimeSpan.Parse(value);
                 item.SetValue(property, Convert.ChangeType(time, item.PropertyType));
             }
             else
             {
                 item.SetValue(property, Convert.ChangeType(value, item.PropertyType));
             }
         }
     }
     catch { }
 }
Exemplo n.º 14
0
        //Funkcija za popunjavanje kontrole u Input formi
        private void PopunjavanjeKontrola(PropertyInfo item)
        {
            if (item.GetCustomAttributes <BrowsableAttribute>().Count() > 0)
            {
                //f-ja koja provjerava da li ima  BrowsableAttribute ako ima da se ne prikazuje na input formi
                return;
            }
            //Dodavanje kontrole za datum
            if (item.PropertyType.Name == "DateTime")
            {
                InputDateControl uc = new InputDateControl();
                uc.Name = item.Name;
                uc.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);

                if (state == StateEnum.Update)
                {
                    try
                    {
                        uc.SetValueInDateBox(item.GetValue(myInterface).ToString());
                    }
                    catch { }
                }
                //provjera da li smo kliknuli na detalje ako jesmo da polje bude samo read only
                if (Detalji == "detalji")
                {
                    uc.ReadOnly();
                }
                flowPanel.Controls.Add(uc);
            }

            //Dodavanje kontrole za Lookup
            else if (item.GetCustomAttributes <Attributes.ForeignKeyAttribute>() != null && item.Name.Contains("ID"))
            {
                PropertyInterface foreignKeyInterface = Assembly.GetExecutingAssembly().
                                                        CreateInstance(item.GetCustomAttribute <ForeignKeyAttribute>().ClassName)
                                                        as PropertyInterface;

                LookUpControl uc = new LookUpControl(foreignKeyInterface, userEmail, Id);
                uc.Name = item.Name;
                uc.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                if (uc.GetLabelValue() == "Radnik ID")
                {
                    uc.SetValueTextBox(Id, userEmail);
                }
                //provjera da li smo kliknuli na detalje ako jesmo da polje bude samo read only
                if (Detalji == "detalji")
                {
                    uc.ReadOnly();
                }
                if (state == StateEnum.Update)
                {
                    try
                    {
                        string        broj   = item.GetValue(myInterface).ToString();
                        string        red    = "";
                        SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                                       foreignKeyInterface.GetSelectQueryZaJedanItem(broj));

                        DataTable dt = new DataTable();

                        dt.Load(reader);
                        if (uc.GetLabelValue() == "Radnik ID")
                        {
                            PropertyOsoba pom = new PropertyOsoba();
                            broj   = dt.Rows[0][1].ToString();
                            reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                             pom.GetSelectQueryZaJedanItem(broj));
                            dt = new DataTable();
                            dt.Load(reader);
                        }
                        //treba dodati i za ostale property-e sta treba da se prikaze u lookup polju
                        if (myInterface.GetType() == typeof(PropertyKlijent))
                        {
                            red = dt.Rows[0].ItemArray[1].ToString() + " " + dt.Rows[0].ItemArray[2].ToString();
                        }
                        else if (myInterface.GetType() == typeof(PropertyFaktura) && item.Name == "KlijentID")
                        {
                            DataTable dtpom = new DataTable();
                            bool      prop  = true;
                            foreach (PropertyInfo itemPom in foreignKeyInterface.GetType().GetProperties())
                            {
                                //Izbacivanje prikaza primarnog kljuca
                                if (prop == false)
                                {
                                    if (itemPom.Name.Contains("ID"))
                                    {
                                        string klasa = itemPom.GetCustomAttributes <ForeignKeyAttribute>().FirstOrDefault().ClassName;

                                        foreignKeyInterface = Assembly.GetExecutingAssembly().
                                                              CreateInstance(klasa) as PropertyInterface;

                                        reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                                         foreignKeyInterface.GetLookupQuery(dt.Rows[0].ItemArray[1].ToString()));

                                        dtpom.Load(reader);
                                    }
                                }
                                prop = false;
                            }
                            red = dtpom.Rows[0].ItemArray[0].ToString();
                        }
                        else if (uc.GetLabelValue() == "Model ID")
                        {
                            PropertyProizvodjac pom = new PropertyProizvodjac();
                            broj   = dt.Rows[0][2].ToString();
                            red    = dt.Rows[0].ItemArray[1].ToString();
                            reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                             pom.GetSelectQueryZaJedanItem(broj));
                            dt = new DataTable();
                            dt.Load(reader);
                            red += " " + dt.Rows[0].ItemArray[1].ToString();
                        }
                        else if (myInterface.GetType() == typeof(PropertyCijena) && item.Name == "VoziloID")
                        {
                            DataTable dtpom = new DataTable();
                            bool      prop  = true;
                            foreach (PropertyInfo itemPom in foreignKeyInterface.GetType().GetProperties())
                            {
                                //Izbacivanje prikaza primarnog kljuca
                                if (prop == false)
                                {
                                    if (itemPom.Name.Contains("ID"))
                                    {
                                        string klasa = itemPom.GetCustomAttributes <ForeignKeyAttribute>().FirstOrDefault().ClassName;

                                        foreignKeyInterface = Assembly.GetExecutingAssembly().
                                                              CreateInstance(klasa) as PropertyInterface;

                                        reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                                         foreignKeyInterface.GetLookupQuery(dt.Rows[0].ItemArray[1].ToString()));

                                        dtpom.Load(reader);
                                        reader.Close();
                                        red = dtpom.Rows[0].ItemArray[0].ToString();
                                        bool prop1 = true;
                                        foreach (PropertyInfo itemPom1 in foreignKeyInterface.GetType().GetProperties())
                                        {
                                            //Izbacivanje prikaza primarnog kljuca
                                            if (prop1 == false)
                                            {
                                                if (itemPom1.Name.Contains("ID"))
                                                {
                                                    string klasa1 = itemPom1.GetCustomAttributes <ForeignKeyAttribute>().FirstOrDefault().ClassName;

                                                    foreignKeyInterface = Assembly.GetExecutingAssembly().
                                                                          CreateInstance(klasa1) as PropertyInterface;

                                                    reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                                                     foreignKeyInterface.GetLookupQuery(dtpom.Rows[0].ItemArray[1].ToString()));
                                                    dtpom = new DataTable();
                                                    dtpom.Load(reader);

                                                    red += " " + dtpom.Rows[0].ItemArray[0].ToString();
                                                    break;
                                                }
                                            }
                                            prop1 = false;
                                        }
                                        break;
                                    }
                                }
                                prop = false;
                            }
                        }
                        else
                        {
                            red = dt.Rows[0].ItemArray[1].ToString();
                            try
                            {
                                red += " " + dt.Rows[0].ItemArray[2].ToString();
                            }
                            catch { }
                        }

                        reader.Close();
                        uc.SetValueTextBox(item.GetValue(myInterface).ToString(), red);
                    }
                    catch { }
                }
                flowPanel.Controls.Add(uc);
            }

            //Dodavanje kontrole za 2 radio dugmica
            else if (item.GetCustomAttribute <TwoRadioButtonsAttribute>() != null)
            {
                TwoRadioButtonsControl uc = new TwoRadioButtonsControl();
                uc.Name = item.Name;
                uc.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                uc.SetRadioButtons(item.GetCustomAttribute <TwoRadioButtonsAttribute>().Value1, item.GetCustomAttribute <TwoRadioButtonsAttribute>().Value2);
                //provjera da li smo kliknuli na detalje ako jesmo da polje bude samo read only
                if (Detalji == "detalji")
                {
                    uc.ReadOnly();
                }
                if (state == StateEnum.Update)
                {
                    try
                    {
                        uc.SetChecked(item.GetValue(myInterface).ToString());
                    }
                    catch { }
                }
                flowPanel.Controls.Add(uc);
            }

            else if (item.GetCustomAttribute <ComboBoxAttribute>() != null)
            {
                ComboBoxControl uc = new ComboBoxControl();
                uc.Name = item.Name;
                uc.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                uc.FillComboBox(item.GetCustomAttribute <ComboBoxAttribute>().vrijednosti);
                if (Detalji == "detalji")
                {
                    uc.ReadOnly();
                }
                if (state == StateEnum.Update)
                {
                    try
                    {
                        uc.SetComboBox(item.GetValue(myInterface).ToString());
                    }
                    catch { }
                }
                flowPanel.Controls.Add(uc);
            }

            //Dodavanje kontrole za TextBox
            else
            {
                InputControl uc = new InputControl();
                uc.Name = item.Name;
                if (uc.Name == "Napomena")
                {
                    uc.SetValueInTextBox(" ");
                }
                uc.SetLabel(item.GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName);
                if (Detalji == "detalji")
                {
                    uc.ReadOnly();
                }
                if (state == StateEnum.Update)
                {
                    try
                    {
                        uc.SetValueInTextBox(item.GetValue(myInterface).ToString());
                    }
                    catch { }
                }
                flowPanel.Controls.Add(uc);
            }
        }
Exemplo n.º 15
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);
                }
            }
        }
Exemplo n.º 16
0
        private void PopuniFilterPanel()
        {
            pnlFilter1.Controls.Clear();
            pnlFilter1.Font = new Font("Century Gothic", 9);

            if (FilterProperty.GetType() == typeof(FakturaIspis))
            {
                Label lblOd = new Label();
                //Label lblOd = new Label();
                lblOd.Text  = "Od:";
                lblOd.Width = 100;
                pnlFilter1.Controls.Add(lblOd);

                DateTimePicker dtpOd = new DateTimePicker();
                dtpOd.Format       = DateTimePickerFormat.Custom;
                dtpOd.Value        = new DateTime(2018, 01, 01);
                dtpOd.CustomFormat = "dd.MM.yyyy";
                dtpOd.Width        = 100;
                pnlFilter1.Controls.Add(dtpOd);
                pnlFilter1.SetFlowBreak(dtpOd, true);

                //filter

                //Label lblDo = new Label();
                Label lblDo = new Label();
                lblDo.Text  = "Do:";
                lblDo.Width = 100;
                pnlFilter1.Controls.Add(lblDo);

                DateTimePicker dtpDo = new DateTimePicker();
                dtpDo.Format       = DateTimePickerFormat.Custom;
                dtpDo.CustomFormat = "dd.MM.yyyy";
                dtpDo.Width        = 100;
                pnlFilter1.Controls.Add(dtpDo);
                pnlFilter1.SetFlowBreak(dtpDo, true);

                Label lblTip = new Label();
                lblTip.Text  = "Tip Fakture:";
                lblTip.Width = 100;
                pnlFilter1.Controls.Add(lblTip);
                ComboBox cbxTip = new ComboBox();
                cbxTip.Width = 100;
                cbxTip.Items.Add("Racun");
                cbxTip.Items.Add("Predracun");
                cbxTip.Items.Add("Sve");
                pnlFilter1.Controls.Add(cbxTip);
                pnlFilter1.SetFlowBreak(cbxTip, true);

                Label lblKlijent = new Label();
                lblKlijent.Text  = "Klijent:";
                lblKlijent.Width = 100;
                pnlFilter1.Controls.Add(lblKlijent);
                TextBox txtKlijent = new TextBox();
                txtKlijent.Width = 100;
                pnlFilter1.Controls.Add(txtKlijent);
                pnlFilter1.SetFlowBreak(txtKlijent, true);


                cbxTip.SelectedIndexChanged += new EventHandler(f_ValueChanged);
                txtKlijent.TextChanged      += new EventHandler(f_ValueChanged);
                dtpOd.ValueChanged          += new EventHandler(f_ValueChanged);
                dtpDo.ValueChanged          += new EventHandler(f_ValueChanged);

                dtpOd.MaxDate = dtpDo.Value;
                dtpDo.MinDate = dtpOd.Value;

                void f_ValueChanged(object sender, EventArgs e)
                {
                    dtpOd.MaxDate = dtpDo.Value;
                    dtpDo.MinDate = dtpOd.Value;

                    string QueryFilter = "exec [dbo].[spFilterFakutra] @PocetniDatum, @KrajniDatum, @Klijent, @TipFakture";

                    SqlConnection con = new SqlConnection(SqlHelper.GetConnectionString());

                    SqlCommand Cmd = new SqlCommand(QueryFilter, con);

                    Cmd.Parameters.Add(new SqlParameter("@PocetniDatum", SqlDbType.DateTime));
                    Cmd.Parameters.Add(new SqlParameter("@KrajniDatum", SqlDbType.DateTime));
                    Cmd.Parameters.Add(new SqlParameter("@Klijent", SqlDbType.NVarChar));
                    Cmd.Parameters.Add(new SqlParameter("@TipFakture", SqlDbType.NVarChar));

                    Cmd.Parameters["@PocetniDatum"].Value      = dtpOd.Value.ToLongDateString();
                    Cmd.Parameters["@PocetniDatum"].IsNullable = true;
                    Cmd.Parameters["@KrajniDatum"].Value       = dtpDo.Value.ToLongDateString();
                    Cmd.Parameters["@KrajniDatum"].IsNullable  = true;
                    Cmd.Parameters["@Klijent"].Value           = txtKlijent.Text;
                    Cmd.Parameters["@Klijent"].IsNullable      = true;
                    if (cbxTip.SelectedIndex >= 0)
                    {
                        Cmd.Parameters["@TipFakture"].Value = cbxTip.Items[cbxTip.SelectedIndex].ToString();
                    }
                    else
                    {
                        Cmd.Parameters["@TipFakture"].Value = "Sve";
                    }
                    Cmd.Parameters["@TipFakture"].IsNullable = true;

                    dt = new DataTable();

                    //logika za popunjavanje tabele
                    SqlDataAdapter adapter = new SqlDataAdapter(Cmd);

                    adapter.Fill(dt);
                    PopuniDGV(dt, FilterProperty);
                }
            }

            else if (FilterProperty.GetType() == typeof(KlijentIspis))
            {
                Label lblIme = new Label();
                lblIme.Text  = "Ime:";
                lblIme.Width = 100;
                lblIme.Font  = new Font("Century Gothic", 9);
                pnlFilter1.Controls.Add(lblIme);
                TextBox txtIme = new TextBox();
                txtIme.Width = 100;
                pnlFilter1.Controls.Add(txtIme);
                pnlFilter1.SetFlowBreak(txtIme, true);

                Label lblPrezime = new Label();
                lblPrezime.Text  = "Prezime:";
                lblPrezime.Width = 100;
                lblPrezime.Font  = new Font("Century Gothic", 9);
                pnlFilter1.Controls.Add(lblPrezime);
                TextBox txtPrezime = new TextBox();
                txtPrezime.Width    = 100;
                txtPrezime.Location = new Point(60, 31);
                pnlFilter1.Controls.Add(txtPrezime);
                pnlFilter1.SetFlowBreak(txtPrezime, true);

                Label lblTip = new Label();
                lblTip.Text  = "Tip:";
                lblTip.Width = 100;
                lblTip.Font  = new Font("Century Gothic", 9);
                pnlFilter1.Controls.Add(lblTip);
                ComboBox cbxTip = new ComboBox();
                cbxTip.Width = 100;
                cbxTip.Items.Add("Vratio");
                cbxTip.Items.Add("Preuzeo");
                cbxTip.Items.Add("Sve");
                cbxTip.Font = new Font("Century Gothic", 9);
                pnlFilter1.Controls.Add(cbxTip);
                pnlFilter1.SetFlowBreak(cbxTip, true);



                txtIme.TextChanged          += new EventHandler(v_ValueChanged);
                txtPrezime.TextChanged      += new EventHandler(v_ValueChanged);
                cbxTip.SelectedIndexChanged += new EventHandler(v_ValueChanged);

                void v_ValueChanged(object sender, EventArgs e)
                {
                    string        QueryFilter = @"exec dbo.spFilterKlijenata
                                          @Ime,
                                          @Prezime,
                                          @TipFaktureID";
                    SqlConnection con         = new SqlConnection(SqlHelper.GetConnectionString());
                    SqlCommand    Cmd         = new SqlCommand(QueryFilter, con);

                    Cmd.Parameters.Add(new SqlParameter("@Ime", SqlDbType.NVarChar));
                    Cmd.Parameters.Add(new SqlParameter("@Prezime", SqlDbType.NVarChar));
                    Cmd.Parameters.Add(new SqlParameter("@TipFaktureID", SqlDbType.Int));

                    Cmd.Parameters["@Ime"].Value          = txtIme.Text;
                    Cmd.Parameters["@Ime"].IsNullable     = true;
                    Cmd.Parameters["@Prezime"].Value      = txtPrezime.Text;
                    Cmd.Parameters["@Prezime"].IsNullable = true;
                    if (cbxTip.SelectedIndex != 0 && cbxTip.SelectedIndex != 1 && cbxTip.SelectedIndex != 2)
                    {
                        Cmd.Parameters["@TipFaktureID"].Value = DBNull.Value;
                    }
                    else
                    {
                        Cmd.Parameters["@TipFaktureID"].Value = cbxTip.SelectedIndex + 1;
                    }
                    Cmd.Parameters["@TipFaktureID"].IsNullable = true;

                    dt = new DataTable();

                    //logika za popunjavanje tabele
                    SqlDataAdapter adapter = new SqlDataAdapter(Cmd);

                    adapter.Fill(dt);
                    PopuniDGV(dt, FilterProperty);
                }
            }
            else if (FilterProperty.GetType() == typeof(VoziloIspis))
            {
                Label lblProizvodjac = new Label();
                lblProizvodjac.Text = "Proizvodjac:";
                lblProizvodjac.Font = new Font("Century Gothic", 9);
                pnlFilter1.Controls.Add(lblProizvodjac);
                TextBox txtProizvodjac = new TextBox();
                txtProizvodjac.Width = 100;
                pnlFilter1.Controls.Add(txtProizvodjac);
                pnlFilter1.SetFlowBreak(txtProizvodjac, true);

                Label lblModel = new Label();
                lblModel.Text = "Model:";
                lblModel.Font = new Font("Century Gothic", 9);
                pnlFilter1.Controls.Add(lblModel);
                TextBox txtModel = new TextBox();
                txtModel.Width = 100;
                pnlFilter1.Controls.Add(txtModel);
                pnlFilter1.SetFlowBreak(txtModel, true);

                Label lblBoja = new Label();
                lblBoja.Text = "Boja:";
                lblBoja.Font = new Font("Century Gothic", 9);
                pnlFilter1.Controls.Add(lblBoja);
                TextBox txtBoja = new TextBox();

                txtBoja.Width = 100;
                pnlFilter1.Controls.Add(txtBoja);
                pnlFilter1.SetFlowBreak(txtBoja, true);

                Label lblDostupnost = new Label();
                lblDostupnost.Text = "Dostupnost:";
                lblDostupnost.Font = new Font("Century Gothic", 9);
                pnlFilter1.Controls.Add(lblDostupnost);
                ComboBox cmbDostupnost = new ComboBox();
                cmbDostupnost.Width = 100;
                cmbDostupnost.Items.Add("Zauzet");
                cmbDostupnost.Items.Add("Slobodan");
                cmbDostupnost.Items.Add("Sve");
                pnlFilter1.Controls.Add(cmbDostupnost);



                txtProizvodjac.TextChanged         += new EventHandler(Filter);
                txtModel.TextChanged               += new EventHandler(Filter);
                txtBoja.TextChanged                += new EventHandler(Filter);
                cmbDostupnost.SelectedIndexChanged += new EventHandler(Filter);

                void Filter(object sender, EventArgs e)
                {
                    string        Query = @"EXEC dbo.spFilterVozila @Proizvodjac, @Model, @Boja, @Dostupnost";
                    SqlConnection conn  = new SqlConnection(SqlHelper.GetConnectionString());
                    SqlCommand    comm  = new SqlCommand(Query, conn);

                    comm.Parameters.Add(new SqlParameter("@Proizvodjac", SqlDbType.NVarChar));
                    comm.Parameters["@Proizvodjac"].Value      = txtProizvodjac.Text.ToString();
                    comm.Parameters["@Proizvodjac"].IsNullable = true;

                    comm.Parameters.Add(new SqlParameter("@Model", SqlDbType.NVarChar));
                    comm.Parameters["@Model"].Value      = txtModel.Text.ToString();
                    comm.Parameters["@Model"].IsNullable = true;

                    comm.Parameters.Add(new SqlParameter("@Boja", SqlDbType.NVarChar));
                    comm.Parameters["@Boja"].Value      = txtBoja.Text.ToString();
                    comm.Parameters["@Boja"].IsNullable = true;

                    comm.Parameters.Add(new SqlParameter("@Dostupnost", SqlDbType.NVarChar));
                    if (cmbDostupnost.SelectedIndex >= 0)
                    {
                        comm.Parameters["@Dostupnost"].Value = cmbDostupnost.Items[cmbDostupnost.SelectedIndex].ToString();
                    }
                    else
                    {
                        comm.Parameters["@Dostupnost"].Value = DBNull.Value;
                    }
                    comm.Parameters["@Dostupnost"].IsNullable = true;


                    dt = new DataTable();
                    SqlDataAdapter adapter = new SqlDataAdapter(comm);

                    adapter.Fill(dt);
                    PopuniDGV(dt, FilterProperty);
                }
            }

            else if (FilterProperty.GetType() == typeof(RadnikIspis))
            {
                Label lblIme = new Label();
                lblIme.Text  = "Ime:";
                lblIme.Width = 100;
                lblIme.Font  = new Font("Century Gothic", 9);
                pnlFilter1.Controls.Add(lblIme);
                TextBox txtIme = new TextBox();
                txtIme.Width = 100;
                pnlFilter1.Controls.Add(txtIme);
                pnlFilter1.SetFlowBreak(txtIme, true);

                Label lblPrezime = new Label();
                lblPrezime.Text  = "Prezime:";
                lblPrezime.Width = 100;
                lblPrezime.Font  = new Font("Century Gothic", 9);
                pnlFilter1.Controls.Add(lblPrezime);
                TextBox txtPrezime = new TextBox();
                txtPrezime.Width = 100;
                pnlFilter1.Controls.Add(txtPrezime);
                pnlFilter1.SetFlowBreak(txtPrezime, true);

                Label lblPozicija = new Label();
                lblPozicija.Text  = "Pozicija:";
                lblPozicija.Width = 100;
                lblPozicija.Font  = new Font("Century Gothic", 9);
                pnlFilter1.Controls.Add(lblPozicija);
                TextBox txtPozicija = new TextBox();
                txtPozicija.Width = 100;
                pnlFilter1.Controls.Add(txtPozicija);
                pnlFilter1.SetFlowBreak(txtPozicija, true);

                txtIme.TextChanged      += new EventHandler(Filter);
                txtPrezime.TextChanged  += new EventHandler(Filter);
                txtPozicija.TextChanged += new EventHandler(Filter);

                void Filter(object sender, EventArgs e)
                {
                    string        Query = @"EXEC dbo.spFilterZaposleni @Ime, @Prezime, @Pozicija";
                    SqlConnection conn  = new SqlConnection(SqlHelper.GetConnectionString());
                    SqlCommand    comm  = new SqlCommand(Query, conn);

                    comm.Parameters.Add(new SqlParameter("@Ime", SqlDbType.NVarChar));
                    comm.Parameters["@Ime"].Value      = txtIme.Text.ToString();
                    comm.Parameters["@Ime"].IsNullable = true;

                    comm.Parameters.Add(new SqlParameter("@Prezime", SqlDbType.NVarChar));
                    comm.Parameters["@Prezime"].Value      = txtPrezime.Text.ToString();
                    comm.Parameters["@Prezime"].IsNullable = true;

                    comm.Parameters.Add(new SqlParameter("@Pozicija", SqlDbType.NVarChar));
                    comm.Parameters["@Pozicija"].Value      = txtPozicija.Text.ToString();
                    comm.Parameters["@Pozicija"].IsNullable = true;



                    dt = new DataTable();
                    SqlDataAdapter adapter = new SqlDataAdapter(comm);

                    adapter.Fill(dt);
                    PopuniDGV(dt, FilterProperty);
                }
            }
        }
Exemplo n.º 17
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);
                }
            }
        }
Exemplo n.º 18
0
        //Popunjavanje Data Table
        #region PopunjavanjeDataTable
        private void PopulateGrid()
        {
            panelPanelZaGV.Controls.Clear();
            DataTable dt = new DataTable();

            //logika za popunjavanje datatable

            SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                           myProperty.GetSelectQuery());


            if (myProperty.GetType() == typeof(PropertyOsoba))
            {
                PropertyOsoba pom = myProperty as PropertyOsoba;
                reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                 pom.GetSelectQueryRadnik());
            }

            if (myProperty.GetType() == typeof(PropertyKlijent))
            {
                PropertyKlijent pom = myProperty as PropertyKlijent;
                reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                 pom.GetSelectQueryZaFakturu());
            }

            if (myProperty.GetType() == typeof(PropertyModelVozila))
            {
                PropertyModelVozila pom = myProperty as PropertyModelVozila;
                reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                 pom.GetSelectLookUp());
            }


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

            dgv.DataSource      = dt;
            dgv.BackgroundColor = Color.White;
            dgv.HeaderBgColor   = Color.CadetBlue;
            panelPanelZaGV.Controls.Add(dgv);
            dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dgv.MultiSelect   = false;
            dgv.Dock          = DockStyle.Fill;
            dgv.Size          = panelPanelZaGV.Size;

            //izvuci display name
            var type       = myProperty.GetType();
            var properties = type.GetProperties();

            try
            {
                //promjeniti nazive kolona
                foreach (DataGridViewColumn item in dgv.Columns)
                {
                    item.HeaderText = properties.Where(x => x.GetCustomAttributes <SqlNameAttribute>()
                                                       .FirstOrDefault().Name == item.HeaderText).FirstOrDefault()
                                      .GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName;
                }
            }
            catch { }

            //design
            //boja teksta i pozadina kada selektujemo item
            dgv.DefaultCellStyle.SelectionBackColor = Color.FromArgb(44, 46, 62);
            dgv.DefaultCellStyle.SelectionForeColor = Color.WhiteSmoke;
            //boja header teksta u tabeli
            dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.WhiteSmoke;
        }
Exemplo n.º 19
0
        // unos promjena u bazu, bilo izmjena na nekom od redu ili dodavanje novog u tabelu
        private void btnPotvrdi_Click(object sender, EventArgs e)
        {
            var properties = property.GetType().GetProperties();

            foreach (var item in flpDetaljno.Controls)
            {
                if (item.GetType() == typeof(TextBoxControl))
                {
                    TextBoxControl input = item as TextBoxControl;

                    if (input.Name == "DuzinaTrajanja" || input.Name == "VrijemePrikazivanja")
                    {
                        TimeSpan pom = new TimeSpan(0, 0, 0);
                        if (TimeSpan.TryParse(input.GetTextBox(), out pom))
                        {
                            TimeSpan     valueT      = TimeSpan.ParseExact(input.GetTextBox(), "c", null);
                            PropertyInfo myPropertyT = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                            myPropertyT.SetValue(property, Convert.ChangeType(valueT, myPropertyT.PropertyType));
                        }
                        else
                        {
                            MessageBox.Show("Vrijeme nije u ispravnom formatu!" + input.GetTextBox());
                            input.BackColor = Color.Red;
                            return;
                        }
                        if (input.Name == "Lozinka" && input.GetTextBox().Length <= 6)
                        {
                            MessageBox.Show("Lozinka mora biti bar 6  karatktera duga!");
                            return;
                        }
                    }


                    else
                    {
                        PropertyInfo myProperty = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                        string       value      = input.GetTextBox();
                        if (value.Trim() == "" && myProperty.GetCustomAttribute <MandatoryDataAttribute>() != null)
                        {
                            MessageBox.Show("Polje " + input.Name + " je obavezno, popunite ga! ");
                            input.BackColor = Color.Red;
                            return;
                        }
                        if (input.Name == "Pol" && (value == "M" || value == "Ž"))
                        {
                            continue;
                        }
                        else if (input.Name == "Pol" && (value != "M" || value != "Ž"))
                        {
                            MessageBox.Show("Polje pol mora biti jedan karakter (M ili Ž)");
                            return;
                        }

                        else
                        {
                            myProperty.SetValue(property, Convert.ChangeType(value, myProperty.PropertyType));
                            input.BackColor = Color.FromArgb(38, 38, 38);
                        }
                    }
                }

                //Marko J. Pokusaji rjesavanja dopune svih polja prilikom unosa i updatea
                else if (item.GetType() == typeof(RichTextBoxControl))
                {
                    RichTextBoxControl input      = item as RichTextBoxControl;
                    string             value      = input.GetVrijednost();
                    PropertyInfo       myProperty = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                    if (myProperty.GetCustomAttribute <MandatoryDataAttribute>() != null && input.GetVrijednost().Trim() == "")
                    {
                        MessageBox.Show("Polje " + input.Name + " je obavezno, popunite ga! ");
                        input.BackColor = Color.Red;
                        return;
                    }
                    else
                    {
                        myProperty.SetValue(property, Convert.ChangeType(value, myProperty.PropertyType));
                    }
                    input.BackColor = Color.FromArgb(38, 38, 38);
                }
                else if (item.GetType() == typeof(DateTimeControl))
                {
                    DateTimeControl input      = item as DateTimeControl;
                    string          value      = input.GetVrijednost();
                    PropertyInfo    myProperty = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                    if (myProperty.GetCustomAttribute <MandatoryDataAttribute>() != null && input.GetVrijednost().Trim() == "")
                    {
                        MessageBox.Show("Polje " + input.Name + " je obavezno, popunite ga! ");
                        input.BackColor = Color.Red;
                        return;
                    }
                    else
                    {
                        myProperty.SetValue(property, Convert.ChangeType(value, myProperty.PropertyType));
                    }
                    input.BackColor = Color.FromArgb(38, 38, 38);
                }
                else if (item.GetType() == typeof(NumericUpDownControl))
                {
                    NumericUpDownControl input = item as NumericUpDownControl;
                    string       value         = input.GetValue().ToString().Trim();
                    PropertyInfo myProperty    = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                    if (myProperty.GetCustomAttribute <MandatoryDataAttribute>() != null && input.GetValue().ToString().Trim() == "")
                    {
                        MessageBox.Show("Polje " + input.Name + " je obavezno, popunite ga! ");
                        input.BackColor = Color.Red;
                        return;
                    }
                    else
                    {
                        myProperty.SetValue(property, Convert.ChangeType(value, myProperty.PropertyType));
                    }
                    input.BackColor = Color.FromArgb(38, 38, 38);
                }
                else if (item.GetType() == typeof(UserLookUpControl))
                {
                    UserLookUpControl input = item as UserLookUpControl;
                    string            value = input.getKey().ToString();
                    int provjera            = 0;
                    if (value.Trim() == "" || int.TryParse(value, out provjera) == false)
                    {
                        MessageBox.Show("Polje " + input.Name + " je obavezno, popunite ga! ");
                        input.BackColor = Color.Red;
                        return;
                    }
                    else
                    {
                        PropertyInfo myProperty = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                        myProperty.SetValue(property, Convert.ChangeType(value, myProperty.PropertyType));
                        input.BackColor = Color.FromArgb(38, 38, 38);
                    }
                }
                else if (item.GetType() == typeof(CheckBoxControl))
                {
                    CheckBoxControl input      = item as CheckBoxControl;
                    bool            value      = input.GetValue();
                    PropertyInfo    myProperty = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                    myProperty.SetValue(property, Convert.ChangeType(value, myProperty.PropertyType));
                }
            }

            if (state == StateEnum.Create)
            {
                if (DialogResult.Yes == (MessageBox.Show("Da li ste sigurni da zelite da dodate novi red?", "Poruka!",
                                                         MessageBoxButtons.YesNo, MessageBoxIcon.Information)))
                {
                    SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text, property.GetInsertQuery(), property.GetInsertParameters().ToArray());
                }
                else
                {
                    state = StateEnum.Preview;
                }
            }
            else if (state == StateEnum.Update)
            {
                if (DialogResult.Yes == (MessageBox.Show("Da li ste sigurni da zelite da izmjenite odabrani red?", "Poruka!",
                                                         MessageBoxButtons.YesNo, MessageBoxIcon.Information)))
                {
                    SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text, property.GetUpdateQuery(), property.GetUpdateParameters().ToArray());
                }
                else
                {
                    state = StateEnum.Preview;
                }
            }

            UcitajDGV(property);
            state = StateEnum.Preview;
            txtPretraga.Enabled = true;

            panelDugmici.Visible = false;
        }
Exemplo n.º 20
0
        private void loadTable()
        {
            DataTable     dt     = new DataTable();
            SqlDataReader reader = null;

            dgvPrikaz.Focus();
            //if (state == StateEnum.View)
            //{

            //}
            //else
            //{
            reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                             myProperty.GetSelectQuery());
            dt.Load(reader);
            reader.Close();
            dgvPrikaz.DataSource = dt;

            var type       = myProperty.GetType();
            var properties = type.GetProperties();

            foreach (DataGridViewColumn item in dgvPrikaz.Columns)
            {
                item.HeaderText = properties.Where(x => x.GetCustomAttributes <SqlNameAttribute>().FirstOrDefault().Name
                                                   == item.HeaderText).FirstOrDefault().GetCustomAttributes <DisplayNameAttribute>().FirstOrDefault().DisplayName;
            }
        }
Exemplo n.º 21
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);
            }
        }