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);
            }
        }
Exemple #2
0
        private void load_toSettingGrade()
        {
            MysqlClass db = new MysqlClass();
            DataTable  tb = db.GetData("SELECT cou.keterangan FROM(SELECT keterangan FROM tb_grade group by keterangan) as cou");



            //MessageBox.Show(tb.Rows.Count.ToString());
            foreach (DataRow row in tb.Rows)
            {
                TabPage tp = new TabPage(row["keterangan"].ToString());
                Bunifu.Framework.UI.BunifuCustomDataGrid dgv = new Bunifu.Framework.UI.BunifuCustomDataGrid();
                dgv.Dock = DockStyle.Fill;
                dgv.Columns.Add("no", "No");
                dgv.Columns.Add("grade", "Grade");
                dgv.Columns.Add("biaya", "Biaya");
                dgv.RowHeadersVisible = false;
                dgv.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(67, 20, 109);
                dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
                dgv.Dock     = DockStyle.Fill;
                dgv.Location = new Point(20, 10);
                tp.Controls.Add(dgv);
                // settingGrade1.tabControl1.TabPages.Add(tp);
            }
        }
        private string valorCelda(Bunifu.Framework.UI.BunifuCustomDataGrid grid, string column)
        {
            string celda = "";

            try
            {
                celda = grid.CurrentRow.Cells[column].Value.ToString();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return(celda);
        }
        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;
            }
        }
        private void cargarGrid(Bunifu.Framework.UI.BunifuCustomDataGrid grid, string consulta, string[] encabezados, int p1)
        {
            try
            {
                SqlDataAdapter adapter = new SqlDataAdapter(consulta, conex);
                adapter.SelectCommand.Parameters.Add("@p1", SqlDbType.Int).Value = p1;

                DataSet data = new DataSet();
                adapter.Fill(data, "DATA");

                grid.DataSource = data.Tables["DATA"];
                estiloGrid(grid, encabezados);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void estiloGrid(Bunifu.Framework.UI.BunifuCustomDataGrid grid, string[] encabezados)
        {
            // Cargar los encabezados y centrarlos
            for (int i = 0; i < grid.Columns.Count; i++)
            {
                grid.Columns[i].HeaderText = encabezados[i];
                grid.Columns[i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                grid.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            }

            // Color de encabezados y color de letra
            grid.HeaderBgColor   = Color.Black;
            grid.HeaderForeColor = Color.White;

            // Fuente
            grid.ColumnHeadersDefaultCellStyle.Font = new Font("Century Gothic", 8, FontStyle.Regular);

            // Quitar la ultima fila por defecto
            grid.AllowUserToAddRows = false;

            // Quitar el estilo de rejilla de las celdas del gridView
            grid.CellBorderStyle = DataGridViewCellBorderStyle.None;

            // Quitar la columna a la izquierda por defecto
            grid.RowHeadersVisible = false;

            if (grid.Rows.Count > 0)
            {
                // Estilos celdas dentro del gidView
                grid.SelectionMode         = DataGridViewSelectionMode.FullRowSelect;
                grid.MultiSelect           = false;
                grid.ReadOnly              = true;
                grid.AllowUserToResizeRows = false;

                // Seleccionar por defecto la primera fila del gridView
                grid.Rows[0].Selected = true;
            }
        }