Exemplo n.º 1
0
        public ActionResult Create(Item model, HttpPostedFileBase img_upload)
        {
            ViewBag.Department_ID = new SelectList(category_Service.GetDepartments(), "Department_ID", "Department_Name");
            if (img_upload != null)
            {
                string ext = Path.GetExtension(img_upload.FileName);
                if (ext != ".png" && ext != ".PNG" && ext != ".jpg" && ext != ".JPG" && ext != ".jpeg" && ext != ".JPEG")
                {
                }
                try
                {
                    string path = Path.Combine(Server.MapPath("~/Content/Images/"), Guid.NewGuid().ToString() + Path.GetExtension(img_upload.FileName));
                    img_upload.SaveAs(path);
                    model.ImgPath = path.Substring(path.LastIndexOf("\\") + 1);
                }
                catch (Exception e)
                {
                    var err = e.Message;
                }
            }

            if (ModelState.IsValid)
            {
                item.AddItem(model);
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Exemplo n.º 2
0
 public static void NewItem(ItemModel model)
 {
     try
     {
         ItemBusiness.AddItem(model);
         MessageBox.Show("Yeni kayıt oluşturuldu.");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 3
0
        public ActionResult AddItem(ItemViewModel model, HttpPostedFileBase upload)
        {
            {
                ViewBag.Category = _category.GetAllCategorys();
                if (model.QuantityInStock <= 0)
                {
                    ViewBag.Q = "Quantity must be greater than 0";
                    return(View());
                }
                if (model.Price <= 0)
                {
                    ViewBag.P = "Item price must be greater than 0";
                    return(View());
                }
                int    filelength = upload.ContentLength;
                byte[] array      = new byte[filelength];
                upload.InputStream.Read(array, 0, filelength);
                model.Picture = array;

                _item.AddItem(model);
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 4
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            var  index   = dgvListItem.CurrentCell.RowIndex;
            bool kiemTra = false;

            if (txtTen.Text == "")
            {
                MessageBox.Show("Tên sản phẩm không được trống!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (txtCamera.Text == "")
            {
                MessageBox.Show("Camera không được trống!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (txtCpu.Text == "")
            {
                MessageBox.Show("Cpu không được trống!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (txtRam.Text == "")
            {
                MessageBox.Show("Ram không được trống!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (txtPin.Text == "")
            {
                MessageBox.Show("Pin không được trống!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (txtDonGia.Text == "")
            {
                MessageBox.Show("Đơn giá không được trống!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (txtSoLuong.Text == "")
            {
                MessageBox.Show("Số lượng không được trống!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            #region Lưu khi thêm
            else if (g == 1)
            {
                kiemTra = _ItemBusiness.ExisItemName(txtTen.Text.ToString(), -1);
                if (kiemTra == false)
                {
                    MessageBox.Show("Trùng Tên Sản Phẩm! Vui Lòng Chọn Tên Khác", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    _itemDTO          = new ItemDTO();
                    _itemDTO.Name     = txtTen.Text.ToString().Trim();
                    _itemDTO.Camera   = txtCamera.Text.ToString().Trim();
                    _itemDTO.Ram      = txtRam.Text.ToString().Trim();
                    _itemDTO.Cpu      = txtCpu.Text.ToString().Trim();
                    _itemDTO.Pin      = txtPin.Text.ToString().Trim();
                    _itemDTO.Price    = double.Parse(txtDonGia.Text.ToString().Trim());
                    _itemDTO.Quantity = int.Parse(txtSoLuong.Text.ToString().Trim());
                    string oldFileName = "", newFileName = "";
                    oldFileName    = _itemDTO.Image;
                    newFileName    = TaoTenFileAnhMoi(_itemDTO.Name, _itemDTO.Image);
                    _itemDTO.Image = newFileName;

                    if (_ItemBusiness.AddItem(_itemDTO))
                    {
                        if (oldFileName != null)
                        {
                            File.Copy(oldFileName, imagesFolder + "" + newFileName);
                        }
                        MessageBox.Show("Thêm sản phẩm mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                        LoadData();
                    }
                    else
                    {
                        MessageBox.Show("Thêm sản phẩm mới không thành công", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    }
                }
            }
            #endregion

            else if (g == 2)
            {
                kiemTra = _ItemBusiness.ExisItemName(txtTen.Text.ToString(), int.Parse(dgvListItem.Rows[index].Cells[0].Value.ToString()));
                if (kiemTra == false)
                {
                    MessageBox.Show("Trùng Tên Sản Phẩm! Vui Lòng Chọn Tên Khác", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    _itemDTO          = _lstItemDTO.ElementAtOrDefault(index);
                    _itemDTO.Name     = txtTen.Text.ToString().Trim();
                    _itemDTO.Camera   = txtCamera.Text.ToString().Trim();
                    _itemDTO.Ram      = txtRam.Text.ToString().Trim();
                    _itemDTO.Cpu      = txtCpu.Text.ToString().Trim();
                    _itemDTO.Pin      = txtPin.Text.ToString().Trim();
                    _itemDTO.Price    = double.Parse(txtDonGia.Text.ToString().Trim());
                    _itemDTO.Quantity = int.Parse(txtSoLuong.Text.ToString().Trim());
                    string oldFileName = "", newFileName = "";
                    if (_itemDTO.Image != null)
                    {
                        oldFileName = _itemDTO.Image.Trim();
                    }
                    if (_NewImage != "")
                    {
                        newFileName    = TaoTenFileAnhMoi(_itemDTO.Name, _NewImage);
                        _itemDTO.Image = newFileName;
                    }
                    if (_ItemBusiness.EditItem(_itemDTO))
                    {
                        if (_NewImage != "")
                        {
                            if (oldFileName != "")
                            {
                                File.Delete(imagesFolder + "" + oldFileName);
                            }
                            File.Copy(_NewImage, imagesFolder + "" + _itemDTO.Image);
                        }
                        if (_NewImage == "")
                        {
                            if (oldFileName != "")
                            {
                                File.Delete(imagesFolder + "" + oldFileName);
                            }
                        }
                        MessageBox.Show("Sửa thông tin nhóm thiết bị thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                        LoadData();
                    }
                }
            }
            DieuKhien((int)DIEUKHIEN.MO);
            g = 0;
        }