コード例 #1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            Greske = "";
            var properties = myInterface.GetType().GetProperties();

            //String za dodavanje imena polja koja su obavezna a nisu popunjena

            foreach (var item in flowPanel.Controls)
            {
                try
                {
                    string value = "";

                    if (item.GetType() == typeof(InputControl))
                    {
                        InputControl input = item as InputControl;
                        value = input.GetValueFromTextBox();

                        //provjera da li unosimo model vozila koji vec postoji u bazi podataka
                        if (properties[0].Name == "ModelID" && properties[01].Name == "Naziv")
                        {
                            PropertyModelVozila propertyModelVozila = new PropertyModelVozila();
                            SqlDataReader       reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                                                 propertyModelVozila.GetSelectQueryZaModelVozila());
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    if (reader.GetString(0) == value)
                                    {
                                        DialogResult dr = MetroMessageBox.Show(this, $"\n\nError! Model vec postoji u bazi", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                                        return;
                                    }
                                }
                            }
                        }
                        else if (properties[0].Name == "ProizvodjacID" && properties[01].Name == "Naziv")
                        {
                            PropertyProizvodjac propertyModelVozila = new PropertyProizvodjac();
                            SqlDataReader       reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                                                 propertyModelVozila.GetSelectQueryZaModelVozila());
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    if (reader.GetString(0) == value)
                                    {
                                        DialogResult dr = MetroMessageBox.Show(this, $"\n\nError! Model vec postoji u bazi", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                                        return;
                                    }
                                }
                            }
                        }

                        string ImePolja = properties.Where(x => (item as InputControl).Name == x.Name).FirstOrDefault().GetCustomAttribute <DisplayNameAttribute>().DisplayName;
                        if (properties.Where(x => (item as InputControl).Name == x.Name &&
                                             x.GetCustomAttribute <NotRequiredAttribute>() != null).FirstOrDefault() == null && value == "")
                        {
                            Greske += "Polje \"" + ImePolja + "\" ne smije biti prazno!\n";
                            continue;
                        }
                        else
                        {
                            if (Regex.IsMatch(value, @"^[0-9]{3}[//]{1}[0-9]{3}[/-]{1}[0-9]{3}$") == false && (item as InputControl).Name == "BrojTelefon")
                            {
                                Greske += "Polje \"" + ImePolja + "\" ne smije da sadrzi slova i znakove osim '-' i '/'!\n";
                                continue;
                            }
                            else if (Regex.IsMatch(value, @"^[a-zA-Z]+$") == false &&
                                     ((item as InputControl).Name == "Ime" ||
                                      (item as InputControl).Name == "Prezime" ||
                                      (item as InputControl).Name == "Gorivo" ||
                                      (item as InputControl).Name == "Boja"))
                            {
                                Greske += "Polje \"" + ImePolja + "\" ne smije da sadrzi brojeve i znakove!\n";
                                continue;
                            }
                            else if (Regex.IsMatch(value, @"^[0-9]{13}$") == false &&
                                     (item as InputControl).Name == "JMB")
                            {
                                Greske += "Polje \"" + ImePolja + "\" mora da sadrzi samo 13 brojeva!\n";
                                continue;
                            }
                            else if (Regex.IsMatch(value, @"^[2-5]{1}$") == false &&
                                     (item as InputControl).Name == "BrojVrata")
                            {
                                Greske += "Polje \"" + ImePolja + "\" mora da sadrzi jednu cifru od 2 do 5!\n";
                                continue;
                            }
                            else if (Regex.IsMatch(value, @"^[0-9\.]+$") == false &&
                                     (item as InputControl).Name == "Kilometraza")
                            {
                                Greske += "Polje \"" + ImePolja + "\" ne smije da sadrzi slova i znakove!\n";
                                continue;
                            }
                            else if ((item as InputControl).Name == "BrojRegistracije" && Regex.IsMatch(value, @"^[A-Z0-9]{3}[\-]{1}[A-Z]{1}[\-]{1}[0-9]{3}$") == false)
                            {
                                Greske += "Polje \"" + ImePolja + "\" nije u pravilnom formatu!\n";
                                continue;
                            }
                        }

                        PropertyInfo property = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                        property.SetValue(myInterface, Convert.ChangeType(value, property.PropertyType));
                    }
                    else if (item.GetType() == typeof(InputDateControl))
                    {
                        InputDateControl input = item as InputDateControl;
                        value = input.GetValueFromDateBox();

                        PropertyInfo property = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                        property.SetValue(myInterface, Convert.ChangeType(value, property.PropertyType));
                    }
                    else if (item.GetType() == typeof(LookUpControl))
                    {
                        LookUpControl input = item as LookUpControl;
                        value = input.GetKeyValue();

                        if (value == "")
                        {
                            Greske += "Polje \"" + (item as LookUpControl).Name + "\" ne smije biti prazno!\n";
                            continue;
                        }

                        PropertyInfo property = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                        property.SetValue(myInterface, Convert.ChangeType(value, property.PropertyType));
                    }
                    else if (item.GetType() == typeof(TwoRadioButtonsControl))
                    {
                        TwoRadioButtonsControl input = item as TwoRadioButtonsControl;
                        value = input.GetChecked();

                        PropertyInfo property = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                        property.SetValue(myInterface, Convert.ChangeType(value, property.PropertyType));
                    }
                    else if (item.GetType() == typeof(ComboBoxControl))
                    {
                        ComboBoxControl input = item as ComboBoxControl;
                        value = input.GetText();

                        PropertyInfo property = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                        property.SetValue(myInterface, Convert.ChangeType(value, property.PropertyType));
                    }
                }
                catch (Exception)
                {
                    DialogResult dr = MetroMessageBox.Show(this, "Neocekivana greska!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            if (Greske != "")
            {
                DialogResult dr = MetroMessageBox.Show(this, Greske, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Provjera poziva Input forme
            if (state == StateEnum.Create)
            {
                DialogResult myResult = MetroMessageBox.Show(this, "Uspjesno ste dodali novi item", "Uspjesno", MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (myResult == DialogResult.OK)
                {
                    SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text,
                                              myInterface.GetInsertQuery(), myInterface.GetInsertParameters().ToArray());

                    if (myInterface.GetType() == typeof(PropertyVozilo))
                    {
                        PropertyCijena pomCijena = new PropertyCijena();

                        SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text,
                                                  pomCijena.GetInsertQuery());
                    }
                    CRUD.IstorijaCRUD.Istorija(userEmail, StateEnum.Create, myInterface);
                }
            }
            else if (state == StateEnum.Update)
            {
                DialogResult myResult = MetroMessageBox.Show(this, "Da li zelite izvrsiti azuriranje ?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (myResult == DialogResult.Yes)
                {
                    SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text,
                                              myInterface.GetUpdateQuery(), myInterface.GetUpdateParameters().ToArray());


                    CRUD.IstorijaCRUD.Istorija(userEmail, StateEnum.Update, myInterface);
                }
            }

            DialogResult = DialogResult.OK;
        }
コード例 #2
0
ファイル: FormInput.cs プロジェクト: miki010/Biblioteka
        private void tilePotvrdi_Click(object sender, EventArgs e)
        {
            ///
            bool postojiIme = false;

            if (myInterface.GetType() == typeof(PropertyLogin))
            {
                DataTable     dt     = new DataTable();
                SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                               myInterface.GetSelectQuery());
                dt.Load(reader);
                reader.Close();
                bool postoji = false;
                foreach (DataRow row in dt.Rows)
                {
                    string ime = row["KorisnickoIme"].ToString();
                    foreach (var item in flPanelControls.Controls)
                    {
                        if (item.GetType() == typeof(InputControl))
                        {
                            InputControl input = item as InputControl;
                            string       value = input.GetValue();
                            if (input.Name == "KorisnickoIme" && ime == value)
                            {
                                postoji = true;
                                break;
                            }
                        }
                    }
                }

                postojiIme = postoji;

                if (postoji)
                {
                    MessageBox.Show("Korisnicko ime vec postoji u bazi. Molimo Vas da ga promjenite!", "Obajvestenje");
                    return;
                }
                //else if (!postoji)
                //{
                //    return postojiIme;
                //}
            }


            /////


            DateTime[] datumi     = new DateTime[2]; //cuva datum Iznajmljivanja i datum Razduzivanja(u slucaju razduzivanja)
            int        j          = 0;               //brojac datuma^
            var        properties = myInterface.GetType().GetProperties();
            int        idClana    = 0;               //cuva vrijednost iz lookup kontrole pri provjere da li clan postoji u tabeli clanarina
            int        lol        = 0;

            if (state != StateEnum.Search)
            {
                foreach (var item in flPanelControls.Controls)
                {
                    if (item.GetType() == typeof(LookUpControl))
                    {
                        LookUpControl input = item as LookUpControl;
                        string        value = input.Key;

                        if (input.Name == "ClanID")
                        {
                            idClana = Convert.ToInt32(input.Key);
                        }

                        try
                        {
                            PropertyInfo property = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                            //provjera unosa

                            if (property.GetCustomAttribute <RequiredAttribute>() != null && value == null)
                            {
                                input.txtID.Focus();

                                input.SetLabelObavezno(property.GetCustomAttribute <RequiredAttribute>().ErrorMessage);
                                popunjeno = false;
                                return;
                            }
                            else
                            {
                                popunjeno = true;
                                property.SetValue(myInterface, Convert.ChangeType(value, property.PropertyType));
                            }
                            #region Skidanje i Vracanje/Dodavanje na stanje
                            if (myInterface.GetType() == typeof(PropertyIznajmljivanje))
                            {
                                if (state == StateEnum.Create)
                                {
                                    stanje = "zaduzivanje";
                                    PropertyInfo propertyIznajmljivanje = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                                    if (input.Name == "KnjigaID")
                                    {
                                        propertyIznajmljivanje.SetValue(iznajmljivanje, Convert.ChangeType(value, property.PropertyType));
                                    }
                                }
                                else if (state == StateEnum.Update)
                                {
                                    stanje = "vracanje";
                                    PropertyInfo propertyIznajmljivanje = properties.Where(x => input.Name == x.Name).FirstOrDefault();

                                    if (input.Name == "KnjigaID")
                                    {
                                        propertyIznajmljivanje.SetValue(iznajmljivanje, Convert.ChangeType(value, property.PropertyType));
                                    }
                                }
                            }
                            else if (myInterface.GetType() == typeof(PropertyIzdavacKnjiga))
                            {
                                stanje = "kpp";//kolicina++;
                                PropertyInfo propertyIzdavac = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                                propertyIzdavac.SetValue(izdavacKnjiga, Convert.ChangeType(value, propertyIzdavac.PropertyType));
                            }
                            else if (myInterface.GetType() == typeof(PropertyZaposleni))
                            {
                                stanje = "pristupniPodaci";
                                PropertyInfo propertyLoginInfo = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                                propertyLoginInfo.SetValue(propertyLogin, Convert.ChangeType(value, propertyLoginInfo.PropertyType));//XXXXXXXXXXXXXXXXXXXXXXX
                            }

                            #endregion
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Podatak uspješno sačuvan!");///////////////////////////////////////////////
                        }
                    }
                    else if (item.GetType() == typeof(InputControl))
                    {
                        InputControl input = item as InputControl;
                        string       value = input.GetValue();

                        if (input.Name == "Kolicina" && myInterface is PropertyIzdavacKnjiga)
                        {
                            try
                            {
                                lol = Convert.ToInt32(value);
                            }
                            catch (Exception)
                            {
                            }
                        }

                        string pom = value; //cuvam value(morao sam pjeske ovako jer je doslo do hiljadu konflikta)
                        try
                        {
                            PropertyInfo property = properties.Where(x => input.Name == x.Name).FirstOrDefault();

                            if (myInterface is PropertyLogin && state == StateEnum.Create && input.Name == "KorisnickoIme")
                            {
                                string normal            = value.Normalize(NormalizationForm.FormD);
                                var    withoutDiacritics = normal.Where(
                                    c => CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark);
                                string final = new string(withoutDiacritics.ToArray());
                                if (final != value)
                                {
                                    MessageBox.Show("Korisničko ime prihvata samo standardnu kolaciju!", "Greška!");
                                    return;
                                }
                            }
                            if (input.Name.Contains("ID") || input.Name.Contains("Iznos") || input.Name.Contains("Kolicina") && input.Enabled == true)
                            {
                                if (!int.TryParse(input.GetValue(), out int number1))
                                {
                                    MessageBox.Show("Polje " + input.Name + " može biti samo cjelobrojni podatak!", "Greška");
                                    input.SetValue("");
                                    return;
                                }
                                else if (lol < 1 && myInterface is PropertyIzdavacKnjiga) //prilikom dodavanja knjige na stanje
                                {
                                    MessageBox.Show("Potrebno je dodati barem jednu knjigu!", "Greška");
                                    return;
                                }
                            }

                            if (input.Name == "Kolicina" && value == "" && myInterface is PropertyKnjiga)
                            {
                                value = "0";
                            }

                            //zadrzati provjera unosa da li je popunjeno obavezno polje
                            if (property.GetCustomAttribute <RequiredAttribute>() != null && value.Trim().Equals(""))
                            {
                                input.SetLblObavezno(property.GetCustomAttribute <RequiredAttribute>().ErrorMessage);
                                popunjeno = false;
                                return;
                            }
                            else
                            {
                                popunjeno = true;
                                property.SetValue(myInterface, Convert.ChangeType(value, property.PropertyType));
                            }

                            #region Skidanje i Vracanje/Dodavanje na stanje
                            //-**************************

                            if (myInterface.GetType() == typeof(PropertyIznajmljivanje))
                            {
                                if (state == StateEnum.Create)
                                {
                                    stanje = "zaduzivanje";
                                    PropertyInfo propertyIznajmljivanje = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                                    if (input.Name == "KnjigaID")
                                    {
                                        propertyIznajmljivanje.SetValue(iznajmljivanje, Convert.ChangeType(value, property.PropertyType));
                                    }
                                }
                                else if (state == StateEnum.Update)
                                {
                                    stanje = "vracanje";
                                    PropertyInfo propertyIzdavacKnjiga = properties.Where(x => input.Name == x.Name).FirstOrDefault();

                                    if (input.Name == "KnjigaID")
                                    {
                                        propertyIzdavacKnjiga.SetValue(izdavacKnjiga, Convert.ChangeType(value, property.PropertyType));
                                    }
                                }
                            }
                            else if (myInterface.GetType() == typeof(PropertyIzdavacKnjiga))
                            {
                                stanje = "kpp";//kolicina++;
                                PropertyInfo propertyIzdavac = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                                propertyIzdavac.SetValue(izdavacKnjiga, Convert.ChangeType(value, propertyIzdavac.PropertyType));
                            }
                            //************************************
                            #endregion
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                            //input.SetLblObavezno(property.GetCustomAttribute<RequiredAttribute>().ErrorMessage);
                            //return;
                        }
                    }

                    else if (item.GetType() == typeof(DateTimeControl))
                    {
                        DateTimeControl input    = item as DateTimeControl;
                        DateTime        value    = input.GetValue();
                        PropertyInfo    property = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                        property.SetValue(myInterface, Convert.ChangeType(value, property.PropertyType));
                        if (myInterface is PropertyIznajmljivanje && state == StateEnum.Update)
                        {
                            datumi[j++] = input.GetValue(); //cuva datum Iznajmljivanja i Danasnji datum(datum Razduzivanja knjige)
                        }
                    }
                    else if (item.GetType() == typeof(UserControlRadio))
                    {
                        UserControlRadio input    = item as UserControlRadio;
                        string           value    = input.GetValue();
                        PropertyInfo     property = properties.Where(x => input.Name == x.Name).FirstOrDefault();
                        if (property.GetCustomAttribute <RequiredAttribute>() != null && value == "N")
                        {
                            input.SetLblObavezno(property.GetCustomAttribute <RequiredAttribute>().ErrorMessage);
                            popunjeno = false;
                            return;
                        }
                        else
                        {
                            popunjeno = true;
                            property.SetValue(myInterface, Convert.ChangeType(value, property.PropertyType));
                        }
                    }
                }
            }
            #region Pretraga
            else
            {
                for (int i = 0; i < flPanelControls.Controls.Count; i++)
                {
                    var item = flPanelControls.Controls[i];

                    if (item.GetType() == typeof(LookUpControl))
                    {
                        LookUpControl input = item as LookUpControl;
                        if (string.IsNullOrEmpty(input.Key))
                        {
                            continue;
                        }

                        string value = input.Key.Trim();
                        filterString.FStr += input.Name + " = " + value + " and ";
                    }
                    else if (item.GetType() == typeof(InputControl))
                    {
                        InputControl input = item as InputControl;
                        string       value = input.GetValue().Trim();
                        if (input.Name.Contains("ID") || input.Name.Contains("Iznos") || input.Name.Contains("Kolicina"))
                        {
                            if (string.IsNullOrEmpty(input.GetValue()))
                            {
                                continue;
                            }
                            else if (!int.TryParse(input.GetValue(), out int number1) && !double.TryParse(input.GetValue(), out double numer2))
                            {
                                MessageBox.Show("Polje " + input.Name + " može sadržati samo brojevne podatke!", "Greška");
                                input.SetValue("");
                                return;
                            }
                        }

                        if (!string.IsNullOrEmpty(input.GetValue()) && (input.Name.Contains("ID") || input.Name.Contains("Iznos") || input.Name.Contains("Kolicina")))
                        {
                            filterString.FStr += input.Name + " = " + value + " and ";
                        }
                        else if (!string.IsNullOrEmpty(input.GetValue()))
                        {
                            filterString.FStr += input.Name + " LIKE '%" + value + "%' and ";
                        }
                    }
                    else if (item.GetType() == typeof(DateRangeControl))
                    {
                        DateRangeControl input = item as DateRangeControl;
                        DateTime[]       dates = input.GetValue();
                        if (!input.GetChecked())
                        {
                            continue;
                        }
                        else if (dates[0].Date > dates[1].Date)
                        {
                            MessageBox.Show("Izaberite validan raspon datuma!", "Greška");
                            return;
                        }
                        filterString.FStr += input.Name + " >= '" + dates[0].Date.ToString() + "' and " + input.Name + " <= '" + dates[1].Date.ToString() + "' and ";
                    }
                    else if (item.GetType() == typeof(UserControlRadio))
                    {
                        UserControlRadio input = item as UserControlRadio;
                        if (input.GetValue() != "M" && input.GetValue() != "Ž")
                        {
                            continue;
                        }
                        string value = input.GetValue();
                        filterString.FStr += input.Name + " LIKE '" + value + "' and ";
                    }
                    else if (item is CheckBoxControl)
                    {
                        CheckBoxControl input = item as CheckBoxControl;
                        if (!input.cbRazduzeno.Enabled)
                        {
                            continue;
                        }
                        else
                        {
                            if (input.cbRazduzeno.Checked)
                            {
                                filterString.FStr += input.Name + " = 1 and ";
                            }
                            else
                            {
                                filterString.FStr += input.Name + " = 0 and ";
                            }
                        }
                    }
                }
                if (string.IsNullOrEmpty(filterString.FStr) || filterString.FStr.Length == 0)
                {
                    return;
                }
                filterString.FStr = filterString.FStr.Substring(0, filterString.FStr.Length - 5);
                // MessageBox.Show(filterString.FStr);
            }
            #endregion

            #region ProvjeraDaLiJePlacenaClanarina
            if (myInterface is PropertyIznajmljivanje)
            {
                if (state == StateEnum.Create) // provjerava da li je clanu istekla clanarina pri pokusaju iznajmljivanja knjige
                {
                    DataTable     dataTable1  = new DataTable();
                    SqlDataReader dataReader1 = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                                        myInterface.GetProcedureKnjigaNaStanju(), myInterface.GetProcedureParameters().ToArray());
                    dataTable1.Load(dataReader1);
                    dataReader1.Close();

                    if (Convert.ToInt32(dataTable1.Rows[0][0]) < 1)
                    {
                        MessageBox.Show("Knjige trenutno nema na stanju!", "Greška");
                        return;
                    }

                    PropertyClanarina clanarina = new PropertyClanarina();

                    DataTable     tableClanarina      = new DataTable();
                    SqlDataReader readerNemaClanarine = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                                                clanarina.GetSelectQuery());
                    tableClanarina.Load(readerNemaClanarine);
                    readerNemaClanarine.Close();

                    bool ima = false;
                    for (int i = 0; i < tableClanarina.Rows.Count; i++)
                    {
                        if ((int)(tableClanarina.Rows[i][1]) == idClana)
                        {
                            ima = true;
                        }
                    }
                    if (!ima)
                    {
                        MessageBox.Show("Korisnik nije uplatio članarinu, iznajmljivanje nije moguće!", "Greška!");
                        return;
                    }


                    DataTable     dt = new DataTable();
                    SqlDataReader readerIstekClanarine = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                                                 myInterface.GetProcedureStatusClanarineZaClanID(), myInterface.GetProcedureParametersClanID().ToArray());
                    dt.Load(readerIstekClanarine);
                    readerIstekClanarine.Close();

                    DateTime datumIsteka = (DateTime)dt.Rows[0][1];
                    if (datumIsteka < DateTime.Now)
                    {
                        MessageBox.Show("Korisniku je istekla clanarina, iznajmljivanje nije moguce!", "Greška!");
                        return;
                    }
                    dt.Clear();

                    DataTable     dataTable  = new DataTable();
                    SqlDataReader dataReader = SqlHelper.ExecuteReader(SqlHelper.GetConnectionString(), CommandType.Text,
                                                                       myInterface.GetProcedureMozeLiSeDici(), myInterface.GetProcedureParametersClanID().ToArray());
                    dataTable.Load(dataReader);
                    dataReader.Close();

                    if (dataTable.Rows.Count > 1)
                    {
                        MessageBox.Show("Korisnik ima više od jedne nerazdužene knjige! Iznajmljivanje nije moguće.", "Greška!");
                        return;
                    }
                    dataTable.Clear();
                }
                else if (state == StateEnum.Update)
                {
                    if (datumi[1] <= datumi[0].AddDays(15))
                    {
                        MessageBox.Show("Knjiga uredno vracena");
                    }
                    else
                    {
                        MessageBox.Show((datumi[1] - datumi[0].AddDays(15)).Days.ToString());
                        MessageBox.Show(DatePart.TimeSpanToDateParts(datumi[0].AddDays(15), datumi[1]));
                    }
                }
            }
            #endregion

            #region Upis u bazu
            if (popunjeno)
            {
                if (state == StateEnum.Create)
                {
                    try
                    {
                        SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text,
                                                  myInterface.GetInsertQuery(), myInterface.GetInsertParameters().ToArray());
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("U bazi već postoji podatak sa istim identifikatorom!");
                        return;
                    }

                    if (stanje == "zaduzivanje")
                    {
                        try
                        {
                            SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text,
                                                      iznajmljivanje.GetProcedureUpdateKnjiga(), iznajmljivanje.GetProcedureParameters().ToArray());
                        }
                        catch (Exception)
                        {
                            return;
                        }
                        //MessageBox.Show("Knjiga je skinuta sa stanja!", "Poruka", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    if (stanje == "kpp")
                    {
                        try
                        {
                            SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text,
                                                      izdavacKnjiga.GetProcedureUpdateKnjiga(), izdavacKnjiga.GetProcedureParameters().ToArray());
                        }
                        catch (Exception)
                        {
                            //throw;
                            return;
                        }
                        //MessageBox.Show("Uvecano stanje knjiga!", "Poruka", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    //MessageBox.Show("Podatak je sačuvan!", "Poruka", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (stanje == "pristupniPodaci")
                    {
                        //popuniPristupnePodatke();
                        SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text,
                                                  propertyLogin.GetInsertQuery(), propertyLogin.GetLoginParameters().ToArray());
                    }

                    MessageBox.Show("Podatak je sacuvan!", "Poruka", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (state == StateEnum.Update)
                {
                    try
                    {
                        SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text,
                                                  myInterface.GetUpdateQuery(), myInterface.GetUpdateParameters().ToArray());
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("U bazi već postoji podatak sa istim identifikatorom!");
                        return;
                    }

                    if (stanje == "vracanje")
                    {
                        try
                        {
                            SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text,
                                                      iznajmljivanje.GetProcedureSelectAllDetails(), iznajmljivanje.GetProcedureParameters().ToArray());
                        }
                        catch (Exception)
                        {
                            return;
                        }
                        //MessageBox.Show("Knjiga je vracena na stanje!", "Poruka", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    MessageBox.Show("Podatak je izmjenjen!", "Poruka", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                DialogResult = DialogResult.OK;
                if (myInterface is PropertyIznajmljivanje)
                {
                    ((PropertyIznajmljivanje)myInterface).Razduzeno = false;
                }
            }
            else
            {
                return;
            }
        }/// dodane dvije zagrade
コード例 #3
0
        public bool Add(bool poljaIspravnoPopunjena)
        {
            var    properties = myProperty.GetType().GetProperties();
            bool   nepravlinoIspunjenoPolje = false;
            string poruka = "";


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

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

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


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

                poljaIspravnoPopunjena = false;
                return(poljaIspravnoPopunjena);
            }
        }
コード例 #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;
        }