protected override void Attach()
 {
     _control = (NumericUpDownControl)ControlObject;
     _control.ValueChanged += ValueChanged;
 }
Пример #2
0
 void ToolstripNumericUpDown_Enter(object sender, EventArgs e)
 {
     NumericUpDownControl.Select(0, NumericUpDownControl.Text.Length);
     NumericUpDownControl.Focus();
 }
Пример #3
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);
            }
        }
Пример #4
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;
        }
Пример #5
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);
                }
            }
        }