示例#1
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            radnikBindingSource.EndEdit();
            radnik r = radnikBindingSource.Current as radnik;

            if (r != null)
            {
                using (IDbConnection db = new MySqlConnection(Conn.ConnectionString))
                {
                    db.Open();

                    if (state == EntityState.Added)
                    {
                        db.Execute("insert into tbl_radnik (ime, prezime, maticni, sektorid) values (@ime,@prezime,@maticni,@sektorid)",
                                   new { ime = r.ime, prezime = r.prezime, maticni = r.maticni, sektorid = r.sektorid });
                    }
                    else if (state == EntityState.Changed)
                    {
                        db.Execute("update tbl_radnik set ime=@ime, prezime=@prezime, maticni=@maticni, sektorid=@sektorid where id=@id",
                                   new { id = r.id, ime = r.ime, prezime = r.prezime, maticni = r.maticni, sektorid = r.sektorid });
                    }

                    PuniGridRadnik();
                    state = EntityState.Unchanged;
                }
            }
        }
示例#2
0
        private void btn_delete_radnik_Click(object sender, EventArgs e)
        {
            state = EntityState.Deleted;

            using (IDbConnection db = new MySqlConnection(Conn.ConnectionString))
            {
                db.Open();
                radnik r = radnikBindingSource.Current as radnik;
                if (r != null)
                {
                    int result = db.Execute("delete from tbl_radnik where id=@id", new { id = r.id });
                    if (result != 0)
                    {
                        radnikBindingSource.RemoveCurrent();
                        panel1.Enabled = false;
                        state          = EntityState.Unchanged;
                    }
                }
            }
        }