Exemplo n.º 1
0
 private void PopulateDataGridView()
 {
     dgvCustomer.AutoGenerateColumns = false;
     using (SPM_DatabaseEntities1 db = new SPM_DatabaseEntities1())
     {
         dgvCustomer.DataSource = db.Materials.ToList <Material>();
     }
 }
Exemplo n.º 2
0
 private void dgvCustomer_DoubleClick(object sender, EventArgs e)
 {
     if (dgvCustomer.CurrentRow.Index != -1)
     {
         model.id = Convert.ToInt32(dgvCustomer.CurrentRow.Cells["id"].Value);
         using (SPM_DatabaseEntities1 db = new SPM_DatabaseEntities1())
         {
             model         = db.Materials.Where(x => x.id == model.id).FirstOrDefault();
             custname.Text = model.MaterialNames;
         }
         btnSave.Text      = "Update";
         btnDelete.Enabled = true;
     }
 }
Exemplo n.º 3
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are You Sure to Delete this Record ?", "SPM Connect", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         using (SPM_DatabaseEntities1 db = new SPM_DatabaseEntities1())
         {
             var entry = db.Entry(model);
             if (entry.State == EntityState.Detached)
             {
                 db.Materials.Attach(model);
             }
             db.Materials.Remove(model);
             db.SaveChanges();
             PopulateDataGridView();
             Clear();
             MessageBox.Show("Deleted Successfully", "SPM Connect", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
Exemplo n.º 4
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     model.MaterialNames = custname.Text.Trim();
     using (SPM_DatabaseEntities1 db = new SPM_DatabaseEntities1())
     {
         if (model.id == 0)//Insert
         {
             db.Materials.Add(model);
         }
         else //Update
         {
             db.Entry(model).State = EntityState.Modified;
         }
         db.SaveChanges();
     }
     Clear();
     PopulateDataGridView();
     MessageBox.Show("Submitted Successfully", "SPM Connect", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }