Exemplo n.º 1
0
        private void updateBtn_Click(object sender, EventArgs e)
        {
            using (ProjectDatabaseEntities db = new ProjectDatabaseEntities())
            {
                model = db.Customers.Where(x => x.customerName == newUSerId).FirstOrDefault();

                model.customerName = nameShow.Text;
                model.phoneNumber  = phnShow.Text;
                model.address      = addShow.Text;

                db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                logn = db.Logins.Where(x => x.userId == newUSerId).FirstOrDefault();

                logn.userId = nameShow.Text;

                db.Entry(logn).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                MessageBox.Show("Updated Successfully");

                this.Visible    = false;
                cstHome.Visible = true;
            }
        }
Exemplo n.º 2
0
 private void updateInfo_Click(object sender, EventArgs e)
 {
     model.userId = Convert.ToInt32(empListGrid.CurrentRow.Cells["userId"].Value);
     using (ProjectDatabaseEntities db = new ProjectDatabaseEntities())
     {
         model = db.Employees.Where(x => x.userId == model.userId).FirstOrDefault();
         model.employeeName    = name.Text;
         model.phoneNumber     = phnNumShow.Text;
         model.role            = roleShow.Text;
         model.salary          = Convert.ToInt32(salaryShow.Text);
         db.Entry(model).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         MessageBox.Show("Updated successfully");
     }
 }
Exemplo n.º 3
0
        private void updateBtn_Click(object sender, EventArgs e)
        {
            model.productId = Convert.ToInt32(itemGridView.CurrentRow.Cells["productId"].Value);
            using (ProjectDatabaseEntities db = new ProjectDatabaseEntities())
            {
                model                   = db.Products.Where(x => x.productId == model.productId).FirstOrDefault();
                model.productName       = productNameShow.Text;
                model.price             = Convert.ToInt32(priceShow.Text);
                model.availableQuantity = Convert.ToInt32(quantityShow.Text);

                db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                MessageBox.Show("Updated Successfully");
            }
        }
Exemplo n.º 4
0
 private void delEmpBtn_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure?", "delete data", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (ProjectDatabaseEntities db = new ProjectDatabaseEntities())
         {
             var entry = db.Entry(model);
             if (entry.State == System.Data.Entity.EntityState.Detached)
             {
                 db.Employees.Attach(model);
             }
             db.Employees.Remove(model);
             db.SaveChanges();
             MessageBox.Show("Removed");
         }
     }
 }
        private void buy_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt32(selectQuantityShow.Text) < Convert.ToInt32(quantityShow.Text))
            {
                model.productId = Convert.ToInt32(itemGridView.CurrentRow.Cells["productId"].Value);
                using (ProjectDatabaseEntities db = new ProjectDatabaseEntities())
                {
                    model = db.Products.Where(x => x.productId == model.productId).FirstOrDefault();
                    model.availableQuantity = Convert.ToInt32(Convert.ToInt32(quantityShow.Text) - Convert.ToInt32(selectQuantityShow.Text));
                    model.productName       = nameShow.Text;
                    model.price             = Convert.ToInt32(priceShow.Text);

                    db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    MessageBox.Show("Successfully Bought");

                    ProjectDatabaseEntities cnn = new ProjectDatabaseEntities();
                    List <Product>          pro = cnn.Products.ToList();

                    itemGridView.DataSource    = pro;
                    buy.Enabled                = false;
                    selectQuantityShow.Enabled = false;
                    selectQuantityShow.Text    = "1";
                    nameShow.Text              = string.Empty;
                    priceShow.Text             = string.Empty;
                    quantityShow.Text          = string.Empty;
                }
            }

            else
            {
                MessageBox.Show("Quantity is not available");
                ProjectDatabaseEntities cnn = new ProjectDatabaseEntities();
                List <Product>          pro = cnn.Products.ToList();

                itemGridView.DataSource    = pro;
                buy.Enabled                = false;
                selectQuantityShow.Enabled = false;
                selectQuantityShow.Text    = "1";
                nameShow.Text              = string.Empty;
                priceShow.Text             = string.Empty;
                quantityShow.Text          = string.Empty;
            }
        }