コード例 #1
0
 private void PopulateDataGridView()
 {
     dgvCustomer.AutoGenerateColumns = false;
     using (SPM_DatabaseEntities1 db = new SPM_DatabaseEntities1())
     {
         dgvCustomer.DataSource = db.Materials.ToList <Material>();
     }
 }
コード例 #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;
     }
 }
コード例 #3
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);
 }
コード例 #4
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);
         }
     }
 }