Example #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;
            }
        }
        private void signUpBtn_Click(object sender, EventArgs e)
        {
            if (signUpPassTextbox.Text == signUpConfPassTextbox.Text)
            {
                ProjectDatabaseEntities addEmp = new ProjectDatabaseEntities();

                int maxId = addEmp.Employees.Select(p => p.userId).DefaultIfEmpty(0).Max();
                maxId++;

                emp.employeeName = signUpUsernameTextbox.Text;
                emp.phoneNumber  = signUpContactTextbox.Text;
                emp.role         = roleShow.Text;
                emp.salary       = Convert.ToInt32(salaryShow.Text);
                emp.userId       = maxId;

                addEmp.Employees.Add(emp);
                addEmp.SaveChanges();

                int maxIdlog = addEmp.Logins.Select(p => p.id).DefaultIfEmpty(0).Max();
                maxIdlog++;

                logn.userId   = signUpUsernameTextbox.Text;
                logn.password = signUpPassTextbox.Text;
                logn.status   = 1;
                logn.id       = maxIdlog;

                addEmp.Logins.Add(logn);
                addEmp.SaveChanges();

                MessageBox.Show("Account Created");
                this.Visible         = false;
                this.empList.Visible = true;
            }

            else
            {
                MessageBox.Show("Passwords do not match");
            }
        }
Example #3
0
        private void signUpBtn_Click(object sender, EventArgs e)
        {
            if (signUpPassTextbox.Text == signUpConfPassTextbox.Text)
            {
                ProjectDatabaseEntities suo = new ProjectDatabaseEntities();

                int maxId = suo.Customers.Select(p => p.userId).DefaultIfEmpty(0).Max();
                maxId++;

                cust.customerName = signUpUsernameTextbox.Text;
                cust.phoneNumber  = signUpContactTextbox.Text;
                cust.address      = signUpAdd1.Text;
                cust.userId       = maxId;

                suo.Customers.Add(cust);
                suo.SaveChanges();

                int maxIdlog = suo.Logins.Select(p => p.id).DefaultIfEmpty(0).Max();
                maxIdlog++;

                logn.userId   = signUpUsernameTextbox.Text;
                logn.password = signUpPassTextbox.Text;
                logn.status   = 0;
                logn.id       = maxIdlog;

                suo.Logins.Add(logn);
                suo.SaveChanges();

                MessageBox.Show("Account Created");
                this.Visible           = false;
                this.LoginPage.Visible = true;
            }

            else
            {
                MessageBox.Show("Password doesn't match");
            }
        }
Example #4
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");
     }
 }
Example #5
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");
            }
        }
Example #6
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;
            }
        }
Example #8
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            ProjectDatabaseEntities adp = new ProjectDatabaseEntities();

            int maxId = adp.Products.Select(p => p.productId).DefaultIfEmpty(0).Max();

            maxId++;

            prod.productName       = nameShow.Text;
            prod.price             = Convert.ToInt32(priceShow.Text);
            prod.availableQuantity = Convert.ToInt32(quantityShow.Text);
            prod.productId         = maxId;

            adp.Products.Add(prod);
            adp.SaveChanges();

            MessageBox.Show("Product Added");
            nameShow.Text     = string.Empty;
            priceShow.Text    = string.Empty;
            quantityShow.Text = string.Empty;
        }