예제 #1
0
 private void PopulateDataGridView()
 {
     dgvCustomer.AutoGenerateColumns = false;
     using (SPM_DatabaseEntities db = new SPM_DatabaseEntities())
     {
         dgvCustomer.DataSource = db.Customers.ToList <Customer>();
     }
 }
예제 #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_DatabaseEntities db = new SPM_DatabaseEntities())
         {
             _model         = db.Customers.Where(x => x.id == _model.id).FirstOrDefault();
             custidtxt.Text = _model.CustomerId.ToString();
             custname.Text  = _model.Name;
             shortname.Text = _model.ShortName;
             alias.Text     = _model.Alias;
         }
         btnSave.Text      = "Update";
         btnDelete.Enabled = true;
     }
 }
예제 #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_DatabaseEntities db = new SPM_DatabaseEntities())
         {
             var entry = db.Entry(_model);
             if (entry.State == EntityState.Detached)
             {
                 db.Customers.Attach(_model);
             }
             db.Customers.Remove(_model);
             db.SaveChanges();
             PopulateDataGridView();
             Clear();
             MessageBox.Show("Deleted Successfully", "SPM Connect", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
예제 #4
0
 private void BtnSave_Click(object sender, EventArgs e)
 {
     _model.CustomerId = Convert.ToInt16(custidtxt.Text);
     _model.Name       = custname.Text.Trim();
     _model.ShortName  = shortname.Text.Trim();
     _model.Alias      = alias.Text.Trim();
     using (SPM_DatabaseEntities db = new SPM_DatabaseEntities())
     {
         if (_model.id == 0)//Insert
         {
             db.Customers.Add(_model);
         }
         else //Update
         {
             db.Entry(_model).State = EntityState.Modified;
         }
         db.SaveChanges();
     }
     Clear();
     PopulateDataGridView();
     MessageBox.Show(text: "Submitted Successfully", caption: "SPM Connect", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Information);
 }