Exemplo n.º 1
0
        private void btnSignin_Click(object sender, EventArgs e)
        {
            OnlineCommerceEntities2 db = new OnlineCommerceEntities2();

            if (rdbAdmin.Checked)
            {
                Accounts ac = db.Accounts.Where(x => x.Username == txtUsername.Text && x.Password == txtPassword.Text && x.AccountTypeID == 3).SingleOrDefault();

                if (ac == null)
                {
                    MessageBox.Show("No admin found", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    AdminForm admin = new AdminForm();
                    admin.ShowDialog();
                }
            }
            else
            {
                Accounts ac = db.Accounts.Where(x => x.Username == txtUsername.Text && x.Password == txtPassword.Text && x.AccountTypeID == 1).SingleOrDefault();

                if (ac == null)
                {
                    MessageBox.Show("No customer found", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    Companies company = db.Companies.Where(x => x.AccountID == ac.ID).SingleOrDefault();

                    proform.company_id = company.ID;
                    proform.ShowDialog();
                }
            }
        }
 private void btnSave_Click(object sender, EventArgs e)
 {
     companies.Name      = txtName.Text.Trim();
     companies.Phone     = txtPhone.Text.Trim();
     companies.Mail      = txtMail.Text.Trim();
     companies.Fax       = txtFax.Text.Trim();
     companies.Address   = txtAdres.Text.Trim();
     companies.AccountID = 18;
     using (OnlineCommerceEntities2 db = new OnlineCommerceEntities2())
     {
         if (companies.ID == 0)
         {
             db.Companies.Add(companies);
         }
         else
         {
             db.Entry(companies).State = System.Data.Entity.EntityState.Modified;
         }
         db.SaveChanges();
     }
     MessageBox.Show("Succesfully");
     Clear();
     companies.ID = 0;
     PopulateDataGridView();
 }
Exemplo n.º 3
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            OnlineCommerceEntities2 db = new OnlineCommerceEntities2();

            Categories category = db.Categories.Where(x => x.Name == cmb_Categories.Text).SingleOrDefault();

            productModel.CategoryID = category.ID;
            productModel.CompanyID  = company_id;
            productModel.Name       = txt_Name.Text.Trim();
            productModel.Cost       = decimal.Parse(txt_Cost.Text.Trim());
            productModel.Price      = decimal.Parse(txt_Price.Text.Trim());
            productModel.Stock      = decimal.Parse(txt_Stock.Text.Trim());
            productModel.Image      = txt_imageLocation.Text;

            if (productModel.ID == 0)
            {
                db.Products.Add(productModel);
            }
            else
            {
                db.Entry(productModel).State = System.Data.Entity.EntityState.Modified;
            }

            db.SaveChanges();
            Clear();

            PopulateDataGridView();
            productModel.ID = 0;
            MessageBox.Show("Succesfully");
        }
 void PopulateDataGridView()
 {
     dgvCompanies.AutoGenerateColumns = false;
     using (OnlineCommerceEntities2 db = new OnlineCommerceEntities2())
     {
         dgvCompanies.DataSource = db.Companies.ToList <Companies>();
     }
 }
Exemplo n.º 5
0
        public void CategoryIdControl()
        {
            OnlineCommerceEntities2 db = new OnlineCommerceEntities2();

            if (categoryId != -1)
            {
                Categories categories = db.Categories.Where(x => x.ID == productModel.CategoryID).SingleOrDefault();
                cmb_Categories.Text = categories.Name;
            }
        }
Exemplo n.º 6
0
 private void dgvCategory_DoubleClick(object sender, EventArgs e)
 {
     if (dgvCategory.CurrentRow.Index != -1)
     {
         categoryModel.ID = Convert.ToInt32(dgvCategory.CurrentRow.Cells["ID"].Value);
         using (OnlineCommerceEntities2 db = new OnlineCommerceEntities2())
         {
             categoryModel = db.Categories.Where(x => x.ID == categoryModel.ID).FirstOrDefault();
             txt_Name.Text = categoryModel.Name;
         }
         btn_Save.Text      = "Update";
         btn_Delete.Enabled = true;
     }
 }
Exemplo n.º 7
0
 void PopulateDataGridView()
 {
     dgvProduct.AutoGenerateColumns = false;
     using (OnlineCommerceEntities2 db = new OnlineCommerceEntities2())
     {
         dgvProduct.DataSource = db.Products.Where(x => x.CompanyID == company_id).ToList <Products>();
         for (int i = 0; i < dgvProduct.RowCount; i++)
         {
             DataGridViewRow a = new DataGridViewRow();
             int             tempCategoryID = Convert.ToInt32(dgvProduct.Rows[i].Cells[5].Value);
             Categories      category       = db.Categories.Where(x => x.ID == tempCategoryID).SingleOrDefault();
             dgvProduct.Rows[i].Cells[6].Value = category.Name;
         }
     }
 }
Exemplo n.º 8
0
 void PopulateComboBox()
 {
     using (OnlineCommerceEntities2 db = new OnlineCommerceEntities2())
     {
         var tempList = (from x in db.Categories
                         select new
         {
             x.ID,
             x.Name
         }).ToList();
         cmb_Categories.DataSource    = tempList;
         cmb_Categories.DisplayMember = "Name";
         cmb_Categories.ValueMember   = "ID";
     }
 }
Exemplo n.º 9
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     comp.Name    = txtName.Text.Trim();
     comp.Mail    = txtMail.Text.Trim();
     comp.Phone   = txtPhone.Text.Trim();
     comp.Fax     = txtFax.Text.Trim();
     comp.Address = txtAdress.Text.Trim();
     using (OnlineCommerceEntities2 db = new OnlineCommerceEntities2())
     {
         db.Companies.Add(comp);
         db.SaveChanges();
     }
     MessageBox.Show("Succsesfully");
     proForm.company_id = comp.ID;
     proForm.Show();
 }
 private void dgvCompanies_DoubleClick(object sender, EventArgs e)
 {
     if (dgvCompanies.CurrentRow.Index != -1)
     {
         companies.ID = Convert.ToInt32(dgvCompanies.CurrentRow.Cells["ID"].Value);
         using (OnlineCommerceEntities2 db = new OnlineCommerceEntities2())
         {
             companies     = db.Companies.Where(x => x.ID == companies.ID).FirstOrDefault();
             txtName.Text  = companies.Name;
             txtPhone.Text = companies.Phone;
             txtMail.Text  = companies.Mail;
             txtAdres.Text = companies.Address;
             txtFax.Text   = companies.Fax;
         }
         btnSave.Text      = "Update";
         btnDelete.Enabled = true;
     }
 }
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure to delete this record ?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (OnlineCommerceEntities2 db = new OnlineCommerceEntities2())
         {
             var entry = db.Entry(companies);
             if (entry.State == System.Data.Entity.EntityState.Detached)
             {
                 db.Companies.Attach(companies);
             }
             db.Companies.Remove(companies);
             db.SaveChanges();
             PopulateDataGridView();
             Clear();
             companies.ID = 0;
             MessageBox.Show("Deleted succesfully.");
         }
     }
 }
Exemplo n.º 12
0
 private void btn_Save_Click(object sender, EventArgs e)
 {
     categoryModel.Name = txt_Name.Text.Trim();
     using (OnlineCommerceEntities2 db = new OnlineCommerceEntities2())
     {
         if (categoryModel.ID == 0)
         {
             db.Categories.Add(categoryModel);
         }
         else
         {
             db.Entry(categoryModel).State = System.Data.Entity.EntityState.Modified;
         }
         db.SaveChanges();
     }
     Clear();
     PopulateDataGridView();
     categoryModel.ID = 0;
     MessageBox.Show("Succesfully");
 }
Exemplo n.º 13
0
 private void dgvProduct_DoubleClick(object sender, EventArgs e)
 {
     if (dgvProduct.CurrentRow.Index != -1)
     {
         productModel.ID = Convert.ToInt32(dgvProduct.CurrentRow.Cells["ID"].Value);
         using (OnlineCommerceEntities2 db = new OnlineCommerceEntities2())
         {
             productModel           = db.Products.Where(x => x.ID == productModel.ID).FirstOrDefault();
             txt_Name.Text          = productModel.Name;
             txt_Cost.Text          = productModel.Cost.ToString();
             txt_Price.Text         = productModel.Price.ToString();
             txt_Stock.Text         = productModel.Stock.ToString();
             categoryId             = Convert.ToInt32(productModel.CategoryID);
             txt_imageLocation.Text = productModel.Image.ToString();
             image.ImageLocation    = productModel.Image;
         }
         CategoryIdControl();
         btn_Save.Text      = "Update";
         btn_Delete.Enabled = true;
     }
 }
Exemplo n.º 14
0
        private void btnSignup_Click(object sender, EventArgs e)
        {
            accounts.Username      = txtUsername.Text.Trim();
            accounts.Password      = txtPassword.Text.Trim();
            accounts.AccountTypeID = 1;

            if (txtUsername.Text == "" || txtPassword.Text == "")
            {
                MessageBox.Show("Please fill in the boxes");
            }
            else
            {
                using (OnlineCommerceEntities2 db = new OnlineCommerceEntities2())
                {
                    db.Accounts.Add(accounts);
                    db.SaveChanges();
                }
                signUpfrm.comp.AccountID = accounts.ID;
                signUpfrm.Show();
            }
        }