コード例 #1
0
        public string addProduct(FormProduct form, List <HttpPostedFileBase> files, string des)
        {
            DBModel dBModel = new DBModel();
            product p       = new product();

            try
            {
                p.ID_PRODUCT     = generateIDProduct();
                p.NAME           = generateNameProduct(form.nameproduct, form.brand);
                p.OS             = form.hedieuhanh;
                p.ID_BRAND       = form.brand;
                p.MEMORY         = Convert.ToInt32(form.memory);
                p.RAM            = Convert.ToInt32(form.ram);
                p.PRICE          = Convert.ToInt32(form.price);
                p.AMOUNT         = Convert.ToInt32(form.amount);
                p.SALE_RATE      = Convert.ToInt32(form.salerate);
                p.AMOUNT_SOLD    = 0;
                p.DATE_SUBMITTED = DateTime.Now;
                p.DESCRIPTION    = des;
                HandleFile    upload = new HandleFile();
                List <string> imgs   = upload.uploadImageProduct(files, p.NAME);
                p.IMG  = imgs[0];
                p.IMG2 = imgs[1];
                p.IMG3 = imgs[2];
                dBModel.products.Add(p);
                dBModel.SaveChanges();
            }
            catch (Exception e)
            {
                return("fail");
            }
            return(p.ID_PRODUCT);
        }
コード例 #2
0
        public OrdersOperations(IOrderView view, DataAccessOrder orderData)
        {
            this.view      = view;
            this.orderData = orderData;

            var orders = orderData.RetrieveOrder();

            this.view.LoadOrder(orders);


            view.Add += () =>
            {
                var order = view.AddOrder();
                orderData.AddOrder(order);

                DataAccessActivity activity = new DataAccessActivity();
                var a = view.AddOrderActivity();
                activity.AddActivity(a);

                view.TotalOrder();
            };

            view.Updatee += () =>
            {
                var order = view.UpdateOrder();
                orderData.UpdateOrder(order);
            };



            view.Ret += () =>
            {
                orders = orderData.RetrieveOrder();
                this.view.LoadOrder(orders);
            };

            view.AddProduct += () =>
            {
                AddProdus();
            };

            view.Products += () =>
            {
                var productForm       = new FormProduct();
                var productRepository = new DataAccessProduct();
                var productPresenter  = new ProductOperations(productForm, productRepository);
                productForm.Show();
            };
            view.EmployeeCustomer += () =>
            {
                var customerForm       = new FormCustomerEmployee();
                var customerRepository = new DataAccessCustomer();
                var customerPresenter  = new CustomerOperations(customerForm, customerRepository);
                customerForm.Show();

                var productForm       = new FormProduct();
                var productRepository = new DataAccessProduct();
                var productPresenter  = new ProductOperations(productForm, productRepository);
            };
        }
コード例 #3
0
 private void GoToFormProduct(object o)
 {
     formProduct = new FormProduct(o);
     formProduct.AddProductClicked += formProduct_AddProductClicked;
     Content.Content             = formProduct;
     NotificationsButton.Content = productBusiness.GetList().Count(x => x.Quantity < 10);
 }
コード例 #4
0
ファイル: FormMain.cs プロジェクト: imatary/work
        private void barButtonItemProduct_ItemClick(object sender, ItemClickEventArgs e)
        {
            _waitDialog.CreateWaitDialog();
            _waitDialog.SetWaitDialogCaption("Chương trình đang tải dữ liệu. Vui lòng chờ...");
            var product = new FormProduct();

            OpenForm(product, xtraTabControlMain);
            _waitDialog.CloseWait();
        }
コード例 #5
0
 public bool CanSaveProduct()
 {
     if (FormProduct != null)
     {
         return(FormProduct.IsValid());
     }
     else
     {
         return(false);
     }
 }
コード例 #6
0
ファイル: MDI-MIPP.cs プロジェクト: kyotsuyoi/MIPP-Desktop
 private void ProdutosToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (FP != null)
     {
         FP.Close();
     }
     FP = new FormProduct {
         MdiParent = this
     };
     FP.Activate();
     FP.Show();
 }
コード例 #7
0
        public FormProductForm(FormProduct formProduct, int Id = 0)
        {
            InitializeComponent();

            this.formProduct = formProduct;

            this.tbId.Enabled = false;

            productComponents = null;

            try
            {
                if (Id > 0)
                {
                    DTO.Product product = ProductCtrl.GetById(Id);

                    this.tbId.Text     = Id.ToString();
                    tbName.Text        = product.Name;
                    tbDescription.Text = product.Description;
                    tbAmount.Text      = product.Amount.ToString();
                    tbPrice.Text       = product.Price.ToString("0.00");
                    this.tbId.ReadOnly = true;

                    productComponents = (from component in product.Components select component.Id).ToList();
                }

                componentsList = ComponentCtrl.GetAll();
                foreach (var component in componentsList)
                {
                    clbComponents.Items.Add(component.Name, productComponents != null && productComponents.Contains(component.Id));
                }

                this.tbName.Select();
            }
            catch (AggregateException ex)
            {
                MessageBox.Show("Aplicação servidora não responde: " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Problema na solicitação: " + ex.Message);
            }
        }
コード例 #8
0
        public ActionResult AddProduct(FormProduct form)
        {
            string             rs              = "";
            ProductDAO         dao             = new ProductDAO();
            User               user            = Session["User"] as User;
            string             idproduct       = "";
            string             nameproduct     = form.nameproduct;
            string             hedieuhanh      = form.hedieuhanh;
            string             brand           = form.brand;
            string             memory          = form.memory;
            string             ram             = form.ram;
            string             price           = form.price;
            string             amount          = form.amount;
            string             salerate        = form.salerate;
            string             description     = form.description;
            HttpPostedFileBase image1          = form.image1;
            HttpPostedFileBase image2          = form.image2;
            HttpPostedFileBase image3          = form.image3;
            List <string>      checkNullString = new List <string>();

            checkNullString.Add(nameproduct);
            checkNullString.Add(hedieuhanh);
            checkNullString.Add(brand);
            checkNullString.Add(memory);
            checkNullString.Add(ram);
            checkNullString.Add(price);
            checkNullString.Add(amount);
            checkNullString.Add(salerate);
            checkNullString.Add(description);
            List <string> checkNum = new List <string>();

            checkNum.Add(memory);
            checkNum.Add(ram);
            checkNum.Add(price);
            checkNum.Add(amount);
            checkNum.Add(salerate);
            List <HttpPostedFileBase> listFiles = new List <HttpPostedFileBase>();

            listFiles.Add(image1);
            listFiles.Add(image2);
            listFiles.Add(image3);

            if (user == null || user.LEVEL.Equals("10") == false)
            {
                rs = "user";
            }

            else if (ToolsOfAdmin.checkNullList(checkNullString) == false)
            {
                rs = "null";
            }
            else if (ToolsOfAdmin.checkNumList(checkNum) == false)
            {
                rs = "number";
            }
            else if (image1 == null || image2 == null || image3 == null)
            {
                rs = "filenull";
            }
            else if (ToolsOfAdmin.checkFileNull(listFiles) == false)
            {
                rs = "filenull";
            }
            else if (ToolsOfAdmin.checkFileImage(listFiles) == false)
            {
                rs = "notimage";
            }
            else if (Convert.ToInt32(salerate) > 100 || Convert.ToInt32(salerate) < 0)
            {
                rs = "sale";
            }
            else if (ToolsOfAdmin.checkSaleRate(price, salerate) == false)
            {
                rs = "sale";
            }
            else if (Convert.ToInt32(amount) < 0 || Convert.ToInt32(price) <= 0)
            {
                rs = "amount";
            }

            else if (dao.checkExitNameProductForAdd(dao.generateNameProduct(form.nameproduct, form.brand)) == false)
            {
                rs = "name";
            }
            else
            {
                description = ToolsOfAdmin.DecodeUrlString(form.description);
                description = ToolsOfAdmin.ExtractText(description);

                idproduct = dao.addProduct(form, listFiles, description);
                if (idproduct == "fail")
                {
                    rs = "fail";
                }
                else
                {
                    rs = "success";
                }
            }
            return(Json(new { result = rs, idproduct = idproduct }, JsonRequestBehavior.DenyGet));
        }
コード例 #9
0
        public async Task <ActionResult> UploadAsync([FromForm] FormProduct formData)
        {
            string output = "";

            LoadFirebase();
            try {
                bool checkFile = true;
                if ("Create".Equals(formData.Button))
                {
                    if (formData.File == null)
                    {
                        return(new UnsupportedMediaTypeResult());
                    }
                }
                else if ("Update".Equals(formData.Button))
                {
                    if (formData.File == null)
                    {
                        checkFile = false;
                    }
                }

                PushResponse response = null;
                if (checkFile)
                {
                    string filename = formData.File.FileName;

                    #region algorithm to check file exists. if true, rename file
                    if (System.IO.File.Exists(fileUploadPath + filename))
                    {
                        while (System.IO.File.Exists(fileUploadPath + filename))
                        {
                            int    lastIndex = filename.LastIndexOf(".");
                            string input     = filename.Substring(lastIndex - 3, 3);
                            if (Regex.IsMatch(input, "^\\(\\d+\\)$"))
                            {
                                string number = filename.Substring(lastIndex - 2, 1);
                                int    num    = Int32.Parse(number);
                                num++;
                                filename = filename.Replace("(" + number + ")", "(" + num + ")");
                            }
                            else
                            {
                                filename = filename.Insert(lastIndex, "(1)");
                            }
                        }
                        string oldPath = Path.Combine(fileUploadPath, formData.File.FileName);
                        string newPath = Path.Combine(fileUploadPath, filename);
                        System.IO.File.Move(oldPath, newPath);
                    }
                    #endregion

                    #region save file to path project
                    var fileExtension = MimeTypeMap.GetExtension(formData.File.ContentType);
                    using var stream = System.IO.File.Create(Path.Combine(fileUploadPath, formData.File.FileName));
                    formData.File.CopyToAsync(stream).Wait();
                    stream.Close();
                    #endregion

                    #region upload file on Firebase - Realtime Database
                    string base64 = GetBase64StringForImage(GetFilePath(filename, fileUploadPath));
                    output = base64;
                    var data = new ImageModel {
                        Img = base64
                    };

                    response = await client.PushTaskAsync("Image/", data);

                    ImageModel result = response.ResultAs <ImageModel>();
                    #endregion
                }

                TempForm tempForm = new TempForm();
                if ("Create".Equals(formData.Button))
                {
                    tempForm.ImageLocation = response.Result.Name;
                }
                else if ("Update".Equals(formData.Button))
                {
                    tempForm.ProductId = formData.ProductId;
                    if (formData.File != null)
                    {
                        tempForm.ImageLocation = response.Result.Name;
                    }
                }
                tempForm.ProductName = formData.ProductName;
                tempForm.Quantity    = formData.Quantity;
                tempForm.Price       = formData.Price;
                tempForm.CategoryId  = formData.CategoryId;


                string serialize = System.Text.Json.JsonSerializer.Serialize <TempForm>(tempForm);
                HttpContext.Session.SetString("tempForm", serialize);

                return(Redirect("Product/addProduct"));
            } catch (Exception) {
                throw;
            }
            return(BadRequest());
        }