コード例 #1
0
 public ActionResult Edit([Bind(Include = "Id,Name,Address,WorkingHours")] Shop shop)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shop).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(shop));
 }
コード例 #2
0
        private void btnDel_Click(object sender, EventArgs e)
        {
            if (dgv.SelectedRows.Count == 0)
            {
                MetroMessageBox.Show(this, "Please select category first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string name = dgv.SelectedRows[0].Cells[1].Value.ToString();

            try
            {
                for (int i = 0; i < dgv.SelectedRows.Count; i++)
                {
                    int id = Convert.ToInt32(dgv.SelectedRows[i].Cells[0].Value);
                    //CategoryClass.Delete(id);
                    using (ShopDBEntities db = new ShopDBEntities())
                    {
                        var ent = db.Categories.FirstOrDefault(c => c.CatID == id);
                        db.Categories.Remove(ent);
                        db.Entry(ent).State = EntityState.Deleted;
                        db.SaveChanges();
                    }
                }

                Notifications.Notfication("Categories Removed", "Operation Successful", Color.Green);
            }
            catch (Exception ex)
            {
                MetroMessageBox.Show(this, "Category not deleted from the system.\nDetails: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            InitiateControls();
        }
コード例 #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbName.Text.Trim()))
            {
                MetroMessageBox.Show(this, "Please Enter Category Name to continue..", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                // CategoryClass.Create(tbName.Text.Trim(), tbDesc.Text.Trim(), dtp.Value);
                using (ShopDBEntities db = new ShopDBEntities())
                {
                    db.Configuration.AutoDetectChangesEnabled = false;
                    ElectricStoreMetro.Category cat = new ElectricStoreMetro.Category();
                    cat.Name            = tbName.Text.Trim();
                    cat.Description     = tbDesc.Text.Trim();
                    cat.Date            = dtp.Value;
                    db.Entry(cat).State = EntityState.Added;

                    db.SaveChanges();
                }
                Notifications.Notfication("New Category Created", "Category " + tbName.Text + " created successfully.", Color.Green);
                InitiateControls();
            }
            catch (Exception ex)
            {
                MetroMessageBox.Show(this, "Category not saved. see below details for more information\nDetails: " + ex.Message, "Saving error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
コード例 #4
0
        public ActionResult ChangeData(MemberDataViewModel memberData)
        {
            //取得會員資料
            var memberAccount = db.member.Where(x => x.Account == memberData.Account).FirstOrDefault();

            //判斷密碼是否正確
            if (memberAccount.PassWord != memberData.PassWord)
            {
                ModelState.AddModelError("PassWord", "密碼不正確");
            }
            if (ModelState.IsValid)
            {
                //更改會員資料
                memberAccount.Adress          = memberData.Adress;
                memberAccount.Email           = memberData.Email;
                memberAccount.Name            = memberData.Name;
                memberAccount.Telphone        = memberData.Telphone;
                memberAccount.PassWord        = memberData.PassWord2;
                db.Entry(memberAccount).State = EntityState.Modified;
                db.SaveChanges();
                TempData["Change"]   = "更改成功";
                memberData.PassWord  = "";
                memberData.PassWord2 = "";
                return(View(memberData));
            }
            return(View(memberData));
        }
コード例 #5
0
        public ActionResult Edit(int id, Product productToEdit)
        {
            try
            {
                // TODO: Add update logic here
                var originalProduct = (from p in _db.Products
                                       where p.Id == productToEdit.Id
                                       select p).First();

                string fileName  = Path.GetFileNameWithoutExtension(productToEdit.ImageFile.FileName);
                string extension = Path.GetExtension(productToEdit.ImageFile.FileName);
                fileName = fileName + DateTime.Now.ToString("yymmssff") + extension;
                productToEdit.FileName = "~/Image/" + fileName;
                fileName = Path.Combine(Server.MapPath("~/Image/"), fileName);
                productToEdit.ImageFile.SaveAs(fileName);

                _db.Entry(originalProduct).CurrentValues.SetValues(productToEdit);
                _db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(productToEdit));
            }
        }
コード例 #6
0
ファイル: frUpdateOrder.cs プロジェクト: mohammdwaqas/estore
        private void brnProcess_Click(object sender, EventArgs e)
        {
            try
            {
                int CompleteOStatusID = Convert.ToInt32(Properties.Settings.Default["CompleteOStatusID"]);
                int PendingOStatusID  = Convert.ToInt32(Properties.Settings.Default["PendingOStatusID"]);

                using (ShopDBEntities db = new ShopDBEntities())
                {
                    string prderNo  = txtOrderNo.Text;
                    var    toUpdate = db.Orders.SingleOrDefault(c => c.OrderNo == prderNo);
                    toUpdate.TotalPayment = Convert.ToDecimal(txtTotalPayment.Text);
                    toUpdate.PaymentDue   = Convert.ToDecimal(txtPaymentDue.Text);
                    if (Convert.ToDecimal(txtPaymentDue.Text) == 0)
                    {
                        toUpdate.OrderStatusID = CompleteOStatusID;
                    }
                    else
                    {
                        toUpdate.OrderStatusID = PendingOStatusID;
                    }
                    db.Entry(toUpdate).State = EntityState.Modified;
                    db.SaveChanges();
                    MessageBox.Show("Updated successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error.\nDetails: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;

                txtOrderNo.Focus();
            }
        }
コード例 #7
0
 private void metroButton3_Click(object sender, EventArgs e)
 {
     if (id == 0)
     {
         MetroMessageBox.Show(this, "Validation Error. Please check for emty fields.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     try
     {
         using (ShopDBEntities db = new ShopDBEntities())
         {
             var user = db.Users.SingleOrDefault(c => c.UserID == id);
             db.Users.Remove(user);
             db.Entry(user).State = EntityState.Deleted;
             db.SaveChanges();
         }
         id = 0;
         Notifications.Notfication("Account Deleted", "Account " + tbCreateName.Text + " deleted from the system.", Color.Red);
         initiate();
     }
     catch (System.Data.Entity.Infrastructure.DbUpdateException)
     {
         MetroMessageBox.Show(this, "Please remove data from child tables first. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
 }
コード例 #8
0
 private void btnProcessUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         //UPDADE ORDER TABLE
         using (ShopDBEntities db = new ShopDBEntities())
         {
             string orderNo     = txtUpdateOrderNo.Text;
             var    updateOrder = db.Orders.SingleOrDefault(c => c.OrderNo == orderNo);
             updateOrder.TotalPayment = Convert.ToDecimal(txtTotalPayment.Text);
             if (txtPaymentDue.Text.Trim() == "0.00" || Convert.ToDecimal(txtPaymentDue.Text) == 0)
             {
                 updateOrder.OrderStatusID = 1;
             }
             else
             {
                 updateOrder.OrderStatusID = 2;
             }
             db.Entry(updateOrder).State = EntityState.Modified;
             db.SaveChanges();
             DialogResult result = MessageBox.Show("Print Slip?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (result == DialogResult.Yes)
             {
                 InvoiceType = "Update Order";
                 PrintPreviewDialog.Document = PrintDocument;
                 PrintPreviewDialog.Show();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #9
0
ファイル: frStock.cs プロジェクト: mohammdwaqas/estore
        private void btnSave_Click(object sender, EventArgs e)
        {
            //if (validateInput(numStock.Value, numAddStock.Value))
            //{
            try
            {
                using (ShopDBEntities db = new ShopDBEntities())
                {
                    int id   = Convert.ToInt32(txtID.Text);
                    var item = db.Items.SingleOrDefault(c => c.ItemID == id);
                    item.Qty = item.Qty + Convert.ToInt32(numAddStock.Value);

                    db.Entry(item).State = EntityState.Modified;
                    db.SaveChanges();
                    Notifications.Notfication("Item Updated Successfully!", txtName.Text + " quantity updated successfully", Color.Green);
                    initiate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error\n:" + ex.Message);
            }
            //}
            //else
            //{
            //    MessageBox.Show("Error");
            //}
        }
コード例 #10
0
ファイル: frProduct.cs プロジェクト: mohammdwaqas/estore
        private void metroButton3_Click(object sender, EventArgs e)
        {
            try
            {
                using (ShopDBEntities _context = new ShopDBEntities())
                {
                    var item = _context.Items.SingleOrDefault(c => c.ItemID == updateID);
                    _context.Items.Remove(item);
                    _context.Entry(item).State = EntityState.Deleted;
                    try
                    {
                        _context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }

                    Notifications.Notfication("Deleted successfully!", tbName.Text + " deleted successfully.", Color.Green);
                    initiate();
                }
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Please select Item to update and try again.", "No Selection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
コード例 #11
0
ファイル: frProduct.cs プロジェクト: mohammdwaqas/estore
        private void metroButton2_Click(object sender, EventArgs e)
        {
            try
            {
                using (ShopDBEntities _context = new ShopDBEntities())
                {
                    var item = _context.Items.SingleOrDefault(c => c.ItemID == updateID);
                    item.Name            = tbName.Text;
                    item.Description     = tbDesc.Text;
                    item.CatID           = Convert.ToInt32(cbCat.SelectedValue);
                    item.PurchasePrice   = Convert.ToDecimal(txtPPrice.Text);
                    item.Saleprice       = Convert.ToDecimal(txtSPrice.Text);
                    item.DiscountPercent = Convert.ToInt32(numDPercent.Value);
                    item.Qty             = Convert.ToInt32(numQty.Value);
                    item.UserID          = 5;
                    item.DateUpdated     = DateTime.Now;

                    _context.Entry(item).State = EntityState.Modified;
                    _context.SaveChanges();
                    Notifications.Notfication("Item Updated successfully!", tbName.Text + " updated successfully", Color.Green);
                    initiate();
                    //MessageBox.Show("updated");
                }
            }
            catch (NullReferenceException ex)
            {
                MessageBox.Show("Please select Item to update and try again.", "No Selection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
コード例 #12
0
        private void btnProcessReturn_Click(object sender, EventArgs e)
        {
            /*ACTIONS
             * 1. DELETE RESPECTIVE DATA FROM ORDER ITEMS AND ORDER TABLE
             * 2. INSERT STOCK BACK IN ITEMS TABLE
             * 3. SAVE DATA IN ORDERS TABLE
             * 4. SAVE DATA IN ORDER ITEMS TABLE
             * 5. REMOVE STOCK FROM ITEMS TABLE
             */
            try
            {
                using (TransactionScope trans = new TransactionScope())
                {
                    string orderno = txtUpdateOrderNo.Text;
                    #region DELETE FROM ORDERS
                    using (ShopDBEntities db = new ShopDBEntities())
                    {
                        var orderToRemove = db.Orders.SingleOrDefault(c => c.OrderNo == orderno);
                        db.Orders.Remove(orderToRemove);
                        db.Entry(orderToRemove).State = EntityState.Deleted;
                        db.SaveChanges();
                    }
                    #endregion
                    #region DELETE FROM ORDER ITEMS
                    using (ShopDBEntities db = new ShopDBEntities())
                    {
                        var itemToRemove = db.OrderItems.FirstOrDefault(c => c.OrderNo == orderno);
                        db.OrderItems.Remove(itemToRemove);
                        db.Entry(itemToRemove).State = EntityState.Deleted;
                        db.SaveChanges();
                    }
                    #endregion
                    #region UPDATE QUANTITY
                    foreach (DataGridViewRow row in dgvCart.Rows)
                    {
                        using (var context = new ShopDBEntities())
                        {
                            int itemid = Convert.ToInt32(row.Cells["ProductID"].Value);
                            var item   = context.Items.SingleOrDefault(c => c.ItemID == itemid);
                            item.UsedQty = item.UsedQty - Convert.ToInt32(row.Cells["Quantity"].Value);

                            context.Entry(item).State = EntityState.Modified;
                            context.SaveChanges();
                        }
                    }
                    #endregion


                    trans.Complete();
                }
            }
            catch (Exception ex)
            {
                throw;
                MessageBox.Show(ex.Message);
                return;
            }
        }
コード例 #13
0
        public ActionResult Edit2(string OrderID, string Select)
        {
            var selectOrder = db.Orders.Where(x => x.OrderID == OrderID).FirstOrDefault();

            selectOrder.Orderstat       = Convert.ToInt32(Select);
            db.Entry(selectOrder).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #14
0
 public ActionResult Edit([Bind(Include = "Id,key,Date,LastEdit,State")] Quest quest)
 {
     if (ModelState.IsValid)
     {
         db.Entry(quest).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(quest));
 }
コード例 #15
0
ファイル: ItemsController.cs プロジェクト: LikChaos/foo
 public ActionResult Edit([Bind(Include = "Id,barcode,info,price")] Item item)
 {
     if (ModelState.IsValid)
     {
         db.Entry(item).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(item));
 }
コード例 #16
0
 public ActionResult Edit([Bind(Include = "OrderNumber,ProdectID,ProdectName,ProdectNameAR,Descriotion,DescriotionAR,Price,Rating,ImagePath,CategorieID,UserID,FullName,UserName,Email,Phone,Password,City,State,Country,Address")] oldOrder oldOrder)
 {
     if (ModelState.IsValid)
     {
         db.Entry(oldOrder).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(oldOrder));
 }
コード例 #17
0
 public ActionResult Edit([Bind(Include = "Id,Login,Info,Password")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
コード例 #18
0
 public ActionResult Edit([Bind(Include = "CategorieID,CategorieName,CategorieNameAR,ImagePath")] CategoriesT categoriesT)
 {
     if (ModelState.IsValid)
     {
         db.Entry(categoriesT).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(categoriesT));
 }
コード例 #19
0
 public ActionResult Edit([Bind(Include = "UserID,FullName,UserName,Email,Phone,Password,City,State,Country,Address")] UserT userT)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userT).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userT));
 }
コード例 #20
0
 public ActionResult Edit([Bind(Include = "Id,Role1")] Role role)
 {
     if (ModelState.IsValid)
     {
         db.Entry(role).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(role));
 }
コード例 #21
0
 public ActionResult Edit([Bind(Include = "Id,Name")] Provider provider)
 {
     if (ModelState.IsValid)
     {
         db.Entry(provider).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(provider));
 }
コード例 #22
0
 public ActionResult Edit([Bind(Include = "id,Name")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
コード例 #23
0
 public ActionResult Edit([Bind(Include = "Id,Date,Id_Provider,State")] ShopQuest shopQuest)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shopQuest).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Id_Provider = new SelectList(db.Provider, "Id", "Name", shopQuest.Id_Provider);
     return(View(shopQuest));
 }
コード例 #24
0
 public ActionResult Edit(OrderViewModel order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerId = new SelectList(db.Customer, "Id", "FirstName", order.CustomerId);
     return(View(order));
 }
コード例 #25
0
ファイル: WriteOffsController.cs プロジェクト: LikChaos/foo
 public ActionResult Edit([Bind(Include = "Id,Date,Id_Item,Count")] WriteOff writeOff)
 {
     if (ModelState.IsValid)
     {
         db.Entry(writeOff).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Id_Item = new SelectList(db.Item, "Id", "barcode", writeOff.Id_Item);
     return(View(writeOff));
 }
コード例 #26
0
 public ActionResult Edit([Bind(Include = "ImageID,ImagePath,ImageTitle,ProdectID")] ImageT imageT)
 {
     if (ModelState.IsValid)
     {
         db.Entry(imageT).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProdectID = new SelectList(db.ProdectTs, "ProdectID", "ProdectName", imageT.ProdectID);
     return(View(imageT));
 }
コード例 #27
0
ファイル: ProductsController.cs プロジェクト: Uastreb/Shop
 public ActionResult Edit([Bind(Include = "id,Category_id,Name,Price,Count,Description")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Category_id = new SelectList(db.Category, "id", "Name", product.Category_id);
     return(View(product));
 }
コード例 #28
0
 public ActionResult Edit([Bind(Include = "ProdectID,ProdectName,ProdectNameAR,Descriotion,DescriotionAR,Price,Rating,ImagePath,CategorieID")] ProdectT prodectT)
 {
     if (ModelState.IsValid)
     {
         db.Entry(prodectT).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategorieID = new SelectList(db.CategoriesTs, "CategorieID", "CategorieName", prodectT.CategorieID);
     return(View(prodectT));
 }
コード例 #29
0
 public ActionResult Edit([Bind(Include = "Id,Id_Item,Id_ShopQuest,Count")] ShopQuest_item shopQuest_item)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shopQuest_item).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Id_Item      = new SelectList(db.Item, "Id", "barcode", shopQuest_item.Id_Item);
     ViewBag.Id_ShopQuest = new SelectList(db.ShopQuest, "Id", "Id", shopQuest_item.Id_ShopQuest);
     return(View(shopQuest_item));
 }
コード例 #30
0
ファイル: Item_TypeController.cs プロジェクト: LikChaos/foo
 public ActionResult Edit([Bind(Include = "Id,Id_Item,Id_ItemType")] Item_Type item_Type)
 {
     if (ModelState.IsValid)
     {
         db.Entry(item_Type).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Id_Item     = new SelectList(db.Item, "Id", "barcode", item_Type.Id_Item);
     ViewBag.Id_ItemType = new SelectList(db.ItemType, "Id", "Name", item_Type.Id_ItemType);
     return(View(item_Type));
 }