コード例 #1
0
 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();
 }
コード例 #2
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");
        }
コード例 #3
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();
 }
コード例 #4
0
 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.");
         }
     }
 }
コード例 #5
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");
 }
コード例 #6
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();
            }
        }