Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            model.Name     = txtName1.Text.Trim();
            model.Surname  = txtSurname.Text.Trim();
            model.INN      = txtINN.Text.Trim();
            model.City     = txtCity.Text.Trim();
            model.Street   = txtStreet.Text.Trim();
            model.DomAndKV = txtDKV.Text.Trim();
            model.Status   = txtRemove1.Text.Trim();

            using (ZakupkaSuria1Entities db = new ZakupkaSuria1Entities())
            {
                if (model.IdSupplier == 0)//Insert
                {
                    db.Supplier.Add(model);
                }
                else //Update
                {
                    db.Entry(model).State = EntityState.Modified;
                }
                db.SaveChanges();
            }
            Clear();
            PopulateDataGridView();
            MessageBox.Show("Submitted Successfully");
        }
Example #2
0
 void PopulateDataGridView()
 {
     dgvIdProdukts.AutoGenerateColumns = false;
     using (ZakupkaSuria1Entities db = new ZakupkaSuria1Entities())
     {
         dgvIdProdukts.DataSource = db.IdProdukts.ToList <IdProdukts>();
     }
 }
Example #3
0
 void PopulateDataGridView()
 {
     dgvSupplier.AutoGenerateColumns = false;
     using (ZakupkaSuria1Entities db = new ZakupkaSuria1Entities())
     {
         dgvSupplier.DataSource = db.Supplier.ToList <Supplier>();
     }
 }
Example #4
0
 private void dgvIdProdukts_DoubleClick(object sender, EventArgs e)
 {
     if (dgvIdProdukts.CurrentRow.Index != -1)
     {
         model.IdGoods = Convert.ToInt32(dgvIdProdukts.CurrentRow.Cells["IdGoods"].Value);
         using (ZakupkaSuria1Entities db = new ZakupkaSuria1Entities())
         {
             model          = db.IdProdukts.Where(x => x.IdGoods == model.IdGoods).FirstOrDefault();
             txtArt.Text    = model.Articul;
             txtName.Text   = model.Name;
             txtRemove.Text = model.Remove;
         }
         btnSave.Text      = "Update";
         btnDelete.Enabled = true;
     }
 }
Example #5
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are You Sure to Delete this Record ?", "EF CRUD Operation", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (ZakupkaSuria1Entities db = new ZakupkaSuria1Entities())
         {
             var entry = db.Entry(model);
             if (entry.State == EntityState.Detached)
             {
                 db.IdProdukts.Attach(model);
             }
             db.IdProdukts.Remove(model);
             db.SaveChanges();
             PopulateDataGridView();
             Clear();
             MessageBox.Show("Deleted Successfully");
         }
     }
 }
Example #6
0
 private void dgvSupplier_DoubleClick(object sender, EventArgs e)
 {
     if (dgvSupplier.CurrentRow.Index != -1)
     {
         model.IdSupplier = Convert.ToInt32(dgvSupplier.CurrentRow.Cells["IdSupplier"].Value);
         using (ZakupkaSuria1Entities db = new ZakupkaSuria1Entities())
         {
             model           = db.Supplier.Where(x => x.IdSupplier == model.IdSupplier).FirstOrDefault();
             txtName1.Text   = model.Name;
             txtSurname.Text = model.Surname;
             txtINN.Text     = model.INN;
             txtCity.Text    = model.City;
             txtStreet.Text  = model.Street;
             txtDKV.Text     = model.DomAndKV;
             txtRemove1.Text = model.Status;
         }
         btnSave.Text      = "Update";
         btnDelete.Enabled = true;
     }
 }
Example #7
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     model.Articul = txtArt.Text.Trim();
     model.Name    = txtName.Text.Trim();
     model.Remove  = txtRemove.Text.Trim();
     using (ZakupkaSuria1Entities db = new ZakupkaSuria1Entities())
     {
         if (model.IdGoods == 0)//Insert
         {
             db.IdProdukts.Add(model);
         }
         else //Update
         {
             db.Entry(model).State = EntityState.Modified;
         }
         db.SaveChanges();
     }
     Clear();
     PopulateDataGridView();
     MessageBox.Show("Submitted Successfully");
 }