Ejemplo n.º 1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MetroFramework.MetroMessageBox.Show(this, "Are you sure want to delete this record?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         objState = EntityState.Deleted;
         try
         {
             Muzicar obj = bendInfoBindingSource.Current as Muzicar;
             if (obj != null)
             {
                 using (var db = Db.FromConfig("cn"))
                 {
                     db.Sql("delete from BendInfo where MuzicarID = @MuzicarID").WithParameters(new { MuzicarID = obj.MuzicarID }).AsNonQuery();
                     bendInfoBindingSource.RemoveCurrent();
                     pContainer.Enabled = false;
                     ClearInput();
                     objState = EntityState.Unchanged;
                 }
             }
         }
         catch (Exception ex)
         {
             MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Ejemplo n.º 2
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         bendInfoBindingSource.EndEdit();
         //Get current object
         Muzicar obj = bendInfoBindingSource.Current as Muzicar;
         if (obj != null)
         {
             using (var db = Db.FromConfig("cn"))
             {
                 if (objState == EntityState.Added)
                 {
                     //Execute sql insert query
                     obj.MuzicarID = db.Sql("insert into BendInfo(Ime, Prezime, Kontakt, Jmbg, SlikaUrl,Adresa, InstrumentID) values(@Ime, @Prezime, @Kontakt,@InstrumentID, @Jmbg, @SlikaUrl, @InstrumentID);select SCOPE_IDENTITY()").WithParameters(new { Ime = obj.Ime, Prezime = obj.Prezime, Jmbg = obj.Jmbg, SlikaUrl = obj.SlikaUrl, Kontakt = obj.Kontakt, InstrumentID = obj.InstrumentID }).AsScalar <int>();
                 }
                 else if (objState == EntityState.Changed)
                 {
                     //Execute stored procedure update
                     db.StoredProcedure("MuzicariUpdate").WithParameters(new { MuzicarID = obj.MuzicarID, Ime = obj.Ime, InstrumentID = obj.InstrumentID, Prezime = obj.Prezime, Jmbg = obj.Jmbg, SlikaUrl = obj.SlikaUrl, Kontakt = obj.Kontakt, Adresa = obj.Adresa }).AsNonQuery();
                 }
                 metroGrid.Refresh();
                 pContainer.Enabled = false;
                 objState           = EntityState.Unchanged;
             }
         }
     }
     catch (Exception ex)
     {
         MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 3
0
        private void metroGrid_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            Muzicar obj = bendInfoBindingSource.Current as Muzicar;//Get current object

            if (obj != null)
            {
                if (!string.IsNullOrEmpty(obj.SlikaUrl))
                {
                    pic.Image = Image.FromFile(obj.SlikaUrl);//Load image to PictureBox
                }
            }
        }
Ejemplo n.º 4
0
 private void btnBrowse_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog ofd = new OpenFileDialog()
     {
         Filter = "JPEG|*.jpg|PNG|*.png", ValidateNames = true
     })
     {
         if (ofd.ShowDialog() == DialogResult.OK)
         {
             pic.Image = Image.FromFile(ofd.FileName);
             //Get current object
             Muzicar obj = bendInfoBindingSource.Current as Muzicar;
             if (obj != null)
             {
                 obj.SlikaUrl = ofd.FileName;
             }
         }
     }
 }
Ejemplo n.º 5
0
        private void MusicTheatre_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'mabDataSet.Instrument' table. You can move, or remove it, as needed.
            this.instrumentTableAdapter.Fill(this.mabDataSet.Instrument);
            // TODO: This line of code loads data into the 'mabDataSet.BendInfo' table. You can move, or remove it, as needed.
            this.bendInfoTableAdapter.Fill(this.mabDataSet.BendInfo);
            //Connect to sql database
            using (var db = Db.FromConfig("cn"))
            {
                bendInfoBindingSource.DataSource = db.Sql("select *from BendInfo").AsEnumerable <Muzicar>();
            }
            pContainer.Enabled = false;
            Muzicar obj = bendInfoBindingSource.Current as Muzicar;

            if (obj != null)
            {
                if (!string.IsNullOrEmpty(obj.SlikaUrl))
                {
                    pic.Image = Image.FromFile(obj.SlikaUrl);//Load image to PictureBox
                }
            }
        }