コード例 #1
0
ファイル: AddProduct.ascx.cs プロジェクト: puentepr/ptudnhao
        protected void bttDangSanPham_Click(object sender, EventArgs e)
        {
            SAN_PHAM_DTO proDTO = new SAN_PHAM_DTO();

            proDTO.MaSanPham     = txtMaSP.Text;
            proDTO.MaLoaiSanPham = int.Parse(ddlLoaiSP.SelectedValue.ToString());
            proDTO.MoTaSanPham   = txtRreaMoTa.Value;
            proDTO.HinhAnh       = fuLinkHinhAnh.FileName;
            //proDTO.NgayXoa = DateTime.Parse("");
            proDTO.SoLuong          = float.Parse(txtSoLuong.Text);
            proDTO.SoLuongConLai    = float.Parse(txtSoLuong.Text);
            proDTO.TenSanPham       = txtTenSP.Text;
            proDTO.TinhTrangSanPham = "1";
            proDTO.Gia             = float.Parse(txtGiaGoc.Text);
            proDTO.DonViTinh       = txtDVTinh.Text;
            proDTO.ChatLuong       = txtChatLuong.Text;
            proDTO.NgayDangSanPham = DateTime.Today;
            proDTO.NgaySuaDoi      = DateTime.Today;
            try
            {
                ProductBUS.AddProduct(proDTO);
                fuLinkHinhAnh.SaveAs(Server.MapPath("../../Content/images/products/" + proDTO.HinhAnh));
                lbresult.Text = "Đã thêm thành công";
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #2
0
 private void AddProduct()
 {
     if (!GetConfirmation("Do you want to add this Product?", "Confirm add"))
     {
         return;
     }
     ;
     try
     {
         Product product = new Product(txtProductName.Text.Trim(),
                                       (int)numQuantity.Value,
                                       numPrice.Value,
                                       txtUnit.Text.Trim(),
                                       txtDetail.Text.Trim(),
                                       isActiveCheckBox.Checked,
                                       (productBrandBindingSource_All.Current as ProductBrand).Id);
         product.ProductTypes = selectedProductTypes;
         product.Suppliers    = selectedSuppliers;
         CustomResult cr = bus.AddProduct(product);
         if (cr.Result == CustomResultType.Succeed)
         {
             MessageBox.Show("Product added.", "Add Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
             ClearControlValues();
             txtProductName.Focus();
         }
         else if (cr.Result == CustomResultType.InvalidModelState)
         {
             foreach (var error in ModelState.ErrorMessages)
             {
                 MessageBox.Show(error, "Error"
                                 , MessageBoxButtons.OK
                                 , MessageBoxIcon.Error);
             }
             txtProductName.Focus();
         }
         else
         {
             throw new Exception(cr.ErrorMessage);
         }
     }
     catch (Exception ex)
     {
         ShowErrorMessagerBox(ex.Message);
     }
 }
コード例 #3
0
        private void save_Click(object sender, EventArgs e)
        {
            ProductInfo product = new ProductInfo();

            product.ProductName = txtTen.Text;
            product.Price       = int.Parse(txtGia.Text);
            product.Image       = image;
            product.Quantity    = int.Parse(txtSoLuong.Text);
            product.UnitID      = int.Parse(cbxDonvi.SelectedValue.ToString());
            product.Description = txtMota.Text;
            product.ProductName = txtTen.Text;
            product.SupplierID  = int.Parse(cbxNhacungcap.SelectedValue.ToString());
            product.WarehouseID = int.Parse(cbxKho.SelectedValue.ToString());
            product.Code        = txtMa.Text;

            ProductBUS productBUS = new ProductBUS();

            productBUS.AddProduct(product);
        }
コード例 #4
0
        private void BtnProductSave_Click(object sender, EventArgs e)
        {
            // Validate form
            var isValidCode  = ValidateProudctCode();
            var isValidName  = ValidateProudctName();
            var isValidPrice = ValidateProudctPrice();

            if (isValidCode && isValidName && isValidPrice)
            {
                // Parse price string to decimal
                decimal price;
                if (!decimal.TryParse(txtProductUnitPrice.Text, out price))
                {
                    ValidateProudctPrice();
                }

                // Prepare model
                var product = new CreateProduct
                {
                    Code      = txtProductCode.Text,
                    Name      = txtProductName.Text,
                    UnitPrice = price
                };

                if (_productBUS.AddProduct(product))
                {
                    MessageBox.Show("Data saved successfully");
                    LoadProductList();
                }
                else
                {
                    MessageBox.Show("Data not added in database! Please contact administrator.");
                }
            }
            else
            {
                MessageBox.Show("Enter valid data");
            }
        }
コード例 #5
0
ファイル: WareHouseCtr.cs プロジェクト: AGU18PM/Do-An-Nam-3
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (CheckBeforeSave())
            {
                productDTO.Category    = cboCategory.Text;
                productDTO.ProductName = txbName.Text;
                if (cboType.Text == "Smart")
                {
                    productDTO.Type = 1;
                }
                else if (cboType.Text == "Internet")
                {
                    productDTO.Type = 2;
                }
                else if (cboType.Text == "Cong")
                {
                    productDTO.Type = 3;
                }
                else
                {
                    productDTO.Type = 4;
                }

                productDTO.Size     = Convert.ToInt32(txbSize.Text);
                productDTO.PriceIn  = Convert.ToDouble(txbPriceIn.Text);
                productDTO.PriceOut = Convert.ToDouble(txbPriceOut.Text);
                if (productDTO.PriceIn <= 0)
                {
                    MessageBox.Show("Vui lòng nhập giá nhập sản phẩm lớn hơn 0!!!");
                    DataMode(0, false);
                    btnAdd.Enabled    = true;
                    btnUpdate.Enabled = true;
                    nUDCount.Visible  = true;
                    nUDUpdate.Visible = false;
                    btnDelete.Enabled = true;
                    return;
                }
                if (productDTO.PriceIn > productDTO.PriceOut)
                {
                    MessageBox.Show("Vui lòng nhập giá bán lớn hơn giá nhập!!!");
                    DataMode(0, false);
                    btnAdd.Enabled    = true;
                    nUDCount.Visible  = true;
                    nUDUpdate.Visible = false;
                    btnUpdate.Enabled = true;
                    btnDelete.Enabled = true;
                    return;
                }

                productDTO.Count = Convert.ToInt32(nUDCount.Value);

                if (toDo == 1)
                {
                    if (productBUS.AddProduct(productDTO))
                    {
                        MessageBox.Show("Nhập thành công!!!");
                        DataMode(0, false);
                        btnAdd.Enabled    = true;
                        nUDCount.Visible  = true;
                        nUDUpdate.Visible = false;
                        btnUpdate.Enabled = true;
                        btnDelete.Enabled = true;
                    }
                    else
                    {
                        MessageBox.Show("Nhập không thành công vui lòng kiểm tra lại dữ liệu!!!");
                        DataMode(0, false);
                        nUDCount.Visible  = true;
                        nUDUpdate.Visible = false;
                        btnAdd.Enabled    = true;
                        btnUpdate.Enabled = true;
                        btnDelete.Enabled = true;
                    }
                }
                else if (toDo == 2)
                {
                    productDTO.Count     = Convert.ToInt32(nUDUpdate.Value);
                    productDTO.ProductId = Convert.ToInt32(txbID.Text);
                    productBUS.UpdateProduct(productDTO);
                    MessageBox.Show("Cập nhật thành công!!!");
                    DataMode(0, false);
                    btnAdd.Enabled    = true;
                    nUDCount.Visible  = true;
                    nUDUpdate.Visible = false;
                    btnUpdate.Enabled = true;
                    btnDelete.Enabled = true;
                }
                toDo = 0;
            }
            else
            {
                DataMode(0, false);
                btnAdd.Enabled    = true;
                btnUpdate.Enabled = true;
                btnDelete.Enabled = true;
                nUDCount.Visible  = true;
                nUDUpdate.Visible = false;
            }
            productBUS.loadDataToDGV(dGVWareHouse, txbID, cboCategory, txbName, cboType, txbSize, nUDCount, txbPriceOut, txbPriceIn);
            loadNUD();
        }