public ActionResult UpdateInputDetail(Guid inputDetailId, decimal quantity, decimal weight, decimal unit)
        {
            try
            {
                decimal weightMain = quantity * unit;
                if (quantity == 0 && weight > 0)
                {
                    weightMain = weight;
                    quantity   = weight / unit;
                }

                InputDetail inputDetail = UnitOfWork.InputDetailsRepository.GetById(inputDetailId);
                Guid        status      = UnitOfWork.InputDetailStatusRepository.Get(c => c.Code == 2).FirstOrDefault().Id;
                if (weightMain < inputDetail.RemainDestinationWeight || quantity < inputDetail.RemainQuantity)
                {
                    status = UnitOfWork.InputDetailStatusRepository.Get(c => c.Code == 4).FirstOrDefault().Id;
                }
                inputDetail.RemainQuantity          = inputDetail.RemainQuantity - quantity;
                inputDetail.RemainDestinationWeight = inputDetail.RemainDestinationWeight - weightMain;
                inputDetail.InputDetailStatusId     = status;
                UnitOfWork.InputDetailsRepository.Update(inputDetail);
                UnitOfWork.Save();
                return(Json("true", JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json("false", JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Details(Guid id)
        {
            CutOrderViewModel CutOrderViewModel = new CutOrderViewModel();
            InputDetail       inputDetail       = UnitOfWork.InputDetailsRepository.GetById(id);

            CutOrderViewModel.InputDetail = inputDetail;
            CutOrderViewModel.Density     = inputDetail.Product.ProductGroup.Density;
            CutOrderViewModel.Weight      = GetOrderRemainWeight(inputDetail.OrderId.Value);
            CutOrder cutOrder = UnitOfWork.CutOrderRepository.Get(current => current.InputDetailId == inputDetail.Id).FirstOrDefault();

            if (cutOrder != null)
            {
                CutOrderViewModel.CutOrderId      = cutOrder.Id;
                CutOrderViewModel.CutOrderDetails = UnitOfWork.CutOrderDetailRepository.Get(current => current.CutOrderId == cutOrder.Id).ToList();
            }
            ViewBag.CustomActionId         = new SelectList(UnitOfWork.ProductGroupCustomActionRepository.Get(x => x.ProductGroupId == inputDetail.Product.ProductGroupId).Select(x => x.CustomAction), "Id", "Title");
            ViewBag.CustomerName           = inputDetail.Order.Customer.FullName;
            CutOrderViewModel.RemainWeight = GetOrderRemainWeight(inputDetail.OrderId.Value);
            CutOrderViewModel.Math         = inputDetail.Product.ProductGroup.Density * inputDetail.Product.Width * inputDetail.Product.Thickness;
            //CutOrder cutOrder = UnitOfWork.CutOrderRepository.GetById(id);
            //CutOrderViewModel CutOrderViewModel = new CutOrderViewModel();
            ////CutOrderViewModel.CutOrder = cutOrder;
            //CutOrderViewModel.Density = cutOrder.InputDetail.Product.ProductGroup.Density;
            //CutOrderViewModel.CutOrderId = cutOrder.Id;
            //CutOrderViewModel.InputDetail = UnitOfWork.InputDetailsRepository.GetById(cutOrder.InputDetailId);
            //CutOrderViewModel.CutOrderDetails = UnitOfWork.CutOrderDetailRepository.Get(current => current.CutOrderId == id).ToList();
            //ViewBag.CustomActionId = new SelectList(UnitOfWork.CutDetailTypeRepository.Get().ToList(), "Id", "Title");

            return(View(CutOrderViewModel));
        }
        public async Task <IActionResult> Create([Bind("Cantidad,PNETO,PVP,ProductID,InputID")] InputDetail inputDetail, int?ID, string tipo, string serie, string num)
        {
            //if (ID != null)
            //{

            //    var inputID = await _context.Inputs
            //                         .Where(i => i.Tipo_Comprobante == tipo && i.serie_comprobante == serie && i.num_comprobante == num)
            //                         .SingleAsync();


            //}


            if (ModelState.IsValid)
            {
                _context.Add(inputDetail);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Inputs"));
                //return RedirectToAction(nameof(Index));
            }
            // ViewData["InputID"] = new SelectList(_context.Inputs, "InputID", "InputID", inputDetail.InputID);
            //  ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "Description", inputDetail.ProductID);
            populateProductDropDownList();
            populateInputsDropDownList();
            return(RedirectToAction("Create", "Inputs"));
            //return View(inputDetail);
        }
        public List <KardexChildOrderViewModel> GetKardexChild(Guid inputDetailId)
        {
            List <KardexChildOrderViewModel> result = new List <KardexChildOrderViewModel>();
            InputDetail parentInputDetail           = UnitOfWork.InputDetailsRepository.GetById(inputDetailId);

            result.Add(new KardexChildOrderViewModel {
                OrderCode         = parentInputDetail.Order.Code,
                OrderCustomer     = parentInputDetail.Order.Customer.FullName,
                OrderId           = parentInputDetail.OrderId.Value,
                InitialQuantity   = parentInputDetail.RemainQuantity.ToString(),
                InitialWeight     = parentInputDetail.RemainDestinationWeight.ToString(),
                InputDetailId     = parentInputDetail.Id,
                InputDetailStatus = parentInputDetail.InputDetailStatus.Title,
                IssuedQuantity    = "0",
                IssuedWeight      = "0",
                CreationDate      = parentInputDetail.CreationDate.ToString("yyyy/MM/dd")
            });

            List <InputDetail> childeren = UnitOfWork.InputDetailsRepository.Get(current => current.ParentId == parentInputDetail.Id).ToList();

            foreach (var item in childeren)
            {
                result.Add(new KardexChildOrderViewModel
                {
                    OrderCode         = item.Order.Code,
                    OrderCustomer     = item.Order.Customer.FullName,
                    OrderId           = item.OrderId.Value,
                    InitialQuantity   = "0",
                    InitialWeight     = "0",
                    InputDetailId     = item.Id,
                    InputDetailStatus = item.InputDetailStatus.Title,
                    IssuedQuantity    = item.RemainQuantity.ToString(),
                    IssuedWeight      = item.RemainDestinationWeight.ToString(),
                    CreationDate      = item.CreationDate.ToString("yyyy/MM/dd")
                });
                List <InputDetail> childList = UnitOfWork.InputDetailsRepository.Get(current => current.ParentId == item.Id).ToList();
                foreach (var child in childList)
                {
                    result.Add(new KardexChildOrderViewModel
                    {
                        OrderCode         = child.Order.Code,
                        OrderCustomer     = child.Order.Customer.FullName,
                        OrderId           = child.OrderId.Value,
                        InitialQuantity   = "0",
                        InitialWeight     = "0",
                        InputDetailId     = child.Id,
                        InputDetailStatus = child.InputDetailStatus.Title,
                        IssuedQuantity    = child.RemainQuantity.ToString(),
                        IssuedWeight      = child.RemainDestinationWeight.ToString(),
                        CreationDate      = child.CreationDate.ToString("yyyy/MM/dd")
                    });
                }
            }
            return(result);
        }
        public ActionResult Edit(string id)
        {
            Guid        detailId    = new Guid(id);
            InputDetail inputDetail = UnitOfWork.InputDetailsRepository.GetById(detailId);

            return(new JsonResult()
            {
                Data = new { id = inputDetail.Id, productId = inputDetail.ProductId, quantity = inputDetail.Quantity, destinationWeight = inputDetail.DestinationWeight.ToString(), sourceWeight = inputDetail.SourceWeight.ToString() },
                JsonRequestBehavior = JsonRequestBehavior.DenyGet
            });
        }
 public ActionResult Edit([Bind(Include = "InputDetailID,InputID,HardwareID,Tedad")] InputDetail inputDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(inputDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.HardwareID = new SelectList(db.Hardware, "ID", "Name", inputDetail.HardwareID);
     ViewBag.InputID    = new SelectList(db.Input, "InputID", "FactorNo", inputDetail.InputID);
     return(View(inputDetail));
 }
Example #7
0
        public ActionResult PostInputDetails(InputDetail detail)
        {
            if (detail.Id == 0)
            {
                //insert into InputDetails
            }
            else
            {
                //update
            }

            return(Content("OK|" + detail.Id));
        }
        // GET: Admin/InputDetails/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            InputDetail inputDetail = db.InputDetail.Find(id);

            if (inputDetail == null)
            {
                return(HttpNotFound());
            }
            return(View(inputDetail));
        }
        // GET: Admin/InputDetails/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            InputDetail inputDetail = db.InputDetail.Find(id);

            if (inputDetail == null)
            {
                return(HttpNotFound());
            }
            ViewBag.HardwareID = new SelectList(db.Hardware, "ID", "Name", inputDetail.HardwareID);
            ViewBag.InputID    = new SelectList(db.Input, "InputID", "FactorNo", inputDetail.InputID);
            return(View(inputDetail));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            InputDetail inputDetail = db.InputDetail.Find(id);

            try
            {
                db.InputDetail.Remove(inputDetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch (Exception)
            {
                ViewBag.Error = true;
                return(View("Delete"));
            }
        }
        public ActionResult DeleteConfirmed(string id)
        {
            Guid        inputDetailId = new Guid(id);
            InputDetail inputDetail   = db.InputDetails.Find(inputDetailId);

            try
            {
                UnitOfWork.InputDetailsRepository.DeleteById(inputDetailId);
                UnitOfWork.Save();
                return(RedirectToAction("Index", new { id = inputDetail.InputId }));
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", new { id = inputDetail.InputId, error = "error" }));
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //tạo mới detail
            if (!String.IsNullOrEmpty(txtProductId.Text))
            {
                InputDetail inputDetail = new InputDetail();
                inputDetail.ProductId = Convert.ToInt32(txtProductId.Text);
                inputDetail.Price     = Convert.ToDouble(txtPrice.Text);
                inputDetail.Quantity  = Convert.ToInt32(txtQuantity.Value);
                inputDetail.InputId   = maxIdInput;

                //thêm vào list detail
                inputDetails.Add(inputDetail);
                //dgvInputDetail.Rows.Add(inputDetail);
                loadTable();
            }
            else
            {
                MessageBox.Show("Vui lòng chọn 1 mã sản phẩm");
            }
        }
        public ActionResult Kardex(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            InputDetail inputDetail = UnitOfWork.InputDetailsRepository.GetById(id.Value);

            if (inputDetail == null)
            {
                return(HttpNotFound());
            }
            KardexViewModel model = new KardexViewModel();

            model.OrderId             = inputDetail.OrderId.Value;
            model.ParentOrderCode     = inputDetail.Order.Code;
            model.ParentOrderCustomer = inputDetail.Order.Customer.FullName;
            model.OrderProductName    = inputDetail.Product.Title;
            model.ChildOrders         = GetKardexChild(id.Value);
            return(View(model));
        }
        public List <ExitDetailReportViewModel> GetExitDetail(Exit exit)
        {
            List <ExitDetail> exitDetails = UnitOfWork.ExitDetailRepository.Get(c => c.ExitId == exit.Id).ToList();


            List <ExitDetailReportViewModel> result = new List <ExitDetailReportViewModel>();


            foreach (ExitDetail exitDetail in exitDetails)
            {
                InputDetail inputDetail = UnitOfWork.InputDetailsRepository.GetById(exitDetail.InputDetailId);

                Order order = UnitOfWork.OrderRepository.GetById(inputDetail.OrderId.Value);

                string parentCustomerName = "";
                if (order.ParentId == null)
                {
                    parentCustomerName = order.Customer.FullName;
                }
                else
                {
                    parentCustomerName = order.Parent.Customer.FullName;
                }

                result.Add(new ExitDetailReportViewModel()
                {
                    OrderCode          = inputDetail.Order.Code,
                    ProductTitle       = inputDetail.Product.Title,
                    Quantity           = exitDetail.InitialQuantity.ToString().Split('/')[0],
                    PureWeight         = exitDetail.PureWeight.ToString().Split('/')[0],
                    FullWeight         = exitDetail.FullWeight.ToString().Split('/')[0],
                    EmptyWeight        = exitDetail.EmptyWeight.ToString().Split('/')[0],
                    ParentCustomerName = parentCustomerName
                });
            }



            return(result);
        }
        public List <ChildOrderViewModel> GetChildOrders(Guid parentOrderId)
        {
            List <ChildOrderViewModel> result = new List <ChildOrderViewModel>();

            List <Order> orders = UnitOfWork.OrderRepository.Get(c => c.ParentId == parentOrderId).ToList();
            Order        parent = UnitOfWork.OrderRepository.GetById(parentOrderId);

            foreach (Order order in orders)
            {
                string customerName = order.Customer.FullName;
                if (order.Code == parent.Code)
                {
                    customerName = parent.Customer.FullName + "-" + order.Customer.FullName;
                }

                InputDetail inputDetail =
                    UnitOfWork.InputDetailsRepository.Get(c => c.OrderId == order.Id).FirstOrDefault();

                if (inputDetail != null)
                {
                    result.Add(new ChildOrderViewModel()
                    {
                        OrderId           = order.Id,
                        OrderCustomer     = customerName,
                        ProductId         = inputDetail.ProductId,
                        ProducTitle       = inputDetail.Product.Title,
                        Quantity          = inputDetail.RemainQuantity.ToString("N0"),
                        OrderCode         = order.Code,
                        Weight            = inputDetail.RemainDestinationWeight.ToString("N0"),
                        InputDetailStatus = inputDetail.InputDetailStatus?.Title,
                        InitialWeight     = inputDetail.DestinationWeight.ToString("N0"),
                        InitialQuantity   = inputDetail.Quantity.ToString("N0"),
                        InputDetailId     = inputDetail.Id
                    });
                }
            }

            return(result);
        }
        public void CreateChildInputDetail(decimal newWeight, decimal qty, InputDetail inputDetail, Guid childOrderId)
        {
            InputDetail oInputDetail = new InputDetail()
            {
                //Code = GenerateCode.GetInputDetailCode(childOrderId),
                OrderId                 = childOrderId,
                Quantity                = qty,
                DestinationWeight       = newWeight,
                RemainQuantity          = qty,
                RemainDestinationWeight = newWeight,
                InputId                 = inputDetail.InputId,
                IsActive                = true,
                IsDeleted               = false,
                ProductId               = inputDetail.ProductId,
                ParentId                = inputDetail.Id,
                SourceWeight            = newWeight,
                InputDetailStatusId     = UnitOfWork.InputDetailStatusRepository.Get(c => c.Code == 1)
                                          .FirstOrDefault()?.Id,
                CreationDate = DateTime.Now
            };

            UnitOfWork.InputDetailsRepository.Insert(oInputDetail);
        }
        public ActionResult ShowLoadingData(string inputDetailId)
        {
            Guid inputDetailIdGuid = new Guid(inputDetailId);

            InputDetail inputDetail = UnitOfWork.InputDetailsRepository.GetById(inputDetailIdGuid);

            Order order = UnitOfWork.OrderRepository.GetById(inputDetail.OrderId.Value);

            Product product = UnitOfWork.ProductRepository.GetById(inputDetail.ProductId);


            TransferDetailViewModel transfer = new TransferDetailViewModel()
            {
                RemainQuantity   = inputDetail.RemainQuantity,
                RemainWight      = inputDetail.RemainDestinationWeight,
                OrderCode        = order.Code,
                ProductTitle     = product.Title,
                CustomerFullName = order.Customer.FullName,
                ParentOrderId    = order.Id.ToString(),
                ProductId        = product.Id.ToString()
            };

            return(Json(transfer, JsonRequestBehavior.AllowGet));
        }
Example #18
0
        public int Update(InputDetail obj)
        {
            /// 1: update thành công
            /// 0: Update ko thành công
            int    res      = 0;
            string queryStr = "UPDATE inputdetail SET ";

            if (!string.IsNullOrEmpty(obj.IngredientExpDate))
            {
                queryStr += string.Format(" IngredientExpDate = '{0}',", obj.IngredientExpDate);
            }
            if (!string.IsNullOrEmpty(obj.IngredientQty))
            {
                queryStr += string.Format(" IngredientQty = '{0}',", obj.IngredientQty);
            }
            if (!string.IsNullOrEmpty(obj.IngredientPrice))
            {
                queryStr += string.Format(" IngredientPrice = '{0}',", obj.IngredientPrice);
            }
            if (!string.IsNullOrEmpty(obj.IngredientVat))
            {
                queryStr += string.Format(" IngredientVat = '{0}',", obj.IngredientVat);
            }
            if (!string.IsNullOrEmpty(obj.IngredientDiscount))
            {
                queryStr += string.Format(" IngredientDiscount = '{0}',", obj.IngredientDiscount);
            }
            queryStr += string.Format(" WHERE InputId = '{0}' AND IngredientId = '{1}'", obj.InputId, obj.IngredientId);

            Program.destopService.DataExecute(Program.Username, Program.Password, queryStr, ref errorString);
            if (string.IsNullOrEmpty(errorString))
            {
                res = 1;
            }
            return(res);
        }
        public ActionResult Create(InputDetailViewModel ViewModel)
        {
            try
            {
                if (!ViewModel.EditMode)
                {
                    decimal            weight       = 0;
                    Input              input        = UnitOfWork.InputRepository.GetById(ViewModel.Input.Id);
                    List <InputDetail> inputDetails = UnitOfWork.InputDetailsRepository.Get(current => current.InputId == input.Id).ToList();
                    foreach (InputDetail inputDetail in inputDetails)
                    {
                        weight += inputDetail.DestinationWeight;
                    }
                    weight += ViewModel.Detail.DestinationWeight;

                    if (input.DestinationWeight < weight)
                    {
                        //TempData["Error"] = "<p class='alert alert-danger'>مجموع وزن وارد شده از وزن مقصد بیشتر است</p>";
                        return(RedirectToAction("Index", new { id = ViewModel.Input.Id, error = "مجموع وزن وارد شده از وزن مقصد بیشتر است" }));
                    }
                    else
                    {
                        ViewModel.Detail.IsDeleted               = false;
                        ViewModel.Detail.CreationDate            = DateTime.Now;
                        ViewModel.Detail.Id                      = Guid.NewGuid();
                        ViewModel.Detail.ProductId               = ViewModel.ProductId;
                        ViewModel.Detail.OrderId                 = SetOrder(ViewModel.OrderId, ViewModel.Input.CustomerId, ViewModel.ProductId);
                        ViewModel.Detail.InputId                 = ViewModel.Input.Id;
                        ViewModel.Detail.RemainDestinationWeight = ViewModel.Detail.DestinationWeight;
                        ViewModel.Detail.RemainQuantity          = ViewModel.Detail.Quantity;
                        ViewModel.Detail.InputDetailStatusId     = UnitOfWork.InputDetailStatusRepository.Get(c => c.Code == 1)
                                                                   .FirstOrDefault()?.Id;

                        UnitOfWork.InputDetailsRepository.Insert(ViewModel.Detail);
                    }
                }
                else
                {
                    InputDetail inputDetail = UnitOfWork.InputDetailsRepository.GetById(ViewModel.Detail.Id);

                    inputDetail.IsDeleted               = false;
                    inputDetail.ProductId               = ViewModel.ProductId;
                    ViewModel.Detail.OrderId            = SetOrder(ViewModel.OrderId, ViewModel.Input.CustomerId, ViewModel.ProductId);
                    inputDetail.Quantity                = ViewModel.Detail.Quantity;
                    inputDetail.SourceWeight            = ViewModel.Detail.SourceWeight;
                    inputDetail.DestinationWeight       = ViewModel.Detail.DestinationWeight;
                    inputDetail.RemainDestinationWeight = ViewModel.Detail.DestinationWeight;
                    inputDetail.RemainQuantity          = ViewModel.Detail.Quantity;


                    UnitOfWork.InputDetailsRepository.Update(inputDetail);
                }
                UnitOfWork.Save();
                ViewBag.OrderId = new SelectList(UnitOfWork.OrderRepository.Get(c => c.CustomerId == ViewModel.Input.CustomerId && c.IsActive), "Id", "Code");

                return(RedirectToAction("Index", new { id = ViewModel.Input.Id }));
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", new { id = ViewModel.Input.Id, error = "error" }));
            }
        }
Example #20
0
        public async Task <IActionResult> Create([Bind("Tipo_Comprobante,serie_comprobante,num_comprobante,Impuesto,ProviderID")] Input input,

                                                 string[] selectedProducts, string[] selectedCants, string[] selectedPNETOs, string[] selectedPVPs)
        {
            if (selectedProducts == null)
            {
                return(NotFound());
            }
            if (selectedCants == null)
            {
                for (int i = 0; i < selectedProducts.Length; i++)
                {
                    selectedCants[i] = "10";
                }
            }
            if (selectedPNETOs == null)
            {
                for (int i = 0; i < selectedProducts.Length; i++)
                {
                    selectedPNETOs[i] = "100";
                }
            }
            if (selectedPVPs == null)
            {
                for (int i = 0; i < selectedProducts.Length; i++)
                {
                    selectedPVPs[i] = "200";
                }
            }


            input.InputDetails = new List <InputDetail>();
            int j = 0;

            CultureInfo provider = new CultureInfo("es-ES");

            //NumberStyles style = NumberStyles.AllowDecimalPoint; //| NumberStyles.AllowCurrencySymbol; //| NumberStyles.AllowThousands;

            foreach (var product in selectedProducts)
            {
                var productToAdd = new InputDetail
                {
                    InputID   = input.InputID,
                    ProductID = int.Parse(product),
                    Cantidad  = int.Parse(selectedCants[j]),//,style, CultureInfo.CurrentCulture),
                    PNETO     = decimal.Parse(selectedPNETOs[j], CultureInfo.InvariantCulture),
                    //PNETO= System.Convert.ToDecimal(selectedPNETOs[j], provider), //Fallo aquí en conversión
                    PVP = decimal.Parse(selectedPVPs[j], CultureInfo.InvariantCulture)//,style, provider),// CultureInfo.CurrentCulture)
                };
                input.InputDetails.Add(productToAdd);
                foreach (var detalle in input.InputDetails)
                {
                    // total += detalle.TotalParcial;
                    input.TotalInput += detalle.Cantidad * (decimal)detalle.PNETO;
                }
                input.Fecha_hora = DateTime.Now;
                //var productToUpdate = _context.Products.Where(p => p.ProductID == int.Parse(product));
                var productToUpdate = _context.Products.Where(p => p.ProductID == int.Parse(product)).Single();
                productToUpdate.Stock += int.Parse(selectedCants[j]);

                j++;

                if (await TryUpdateModelAsync <Product>(productToUpdate, "",
                                                        s => s.Stock))
                {
                    try
                    {
                        if (ModelState.IsValid)
                        {
                            _context.Add(input);
                            await _context.SaveChangesAsync();

                            return(RedirectToAction(nameof(Index)));
                        }
                        //await _context.SaveChangesAsync();
                        //return RedirectToAction(nameof(Index));
                    }
                    catch (DbUpdateException /* ex */)
                    {
                        //Log the error (uncomment ex variable name and write a log.)
                        ModelState.AddModelError("", "Unable to save changes. " +
                                                 "Try again, and if the problem persists, " +
                                                 "see your system administrator.");
                    }
                }
            }

            //input.Impuesto = decimal.Parse( igic);
            //input.TotalInput = SubTotal * decimal.Parse(igic);
            //input.TotalInput =  SubTotal * input.Impuesto;//¿? +subtotal

            //try
            //{
            //    if (ModelState.IsValid)
            //    {
            //
            //        _context.Add(input);
            //        await _context.SaveChangesAsync();
            //        return RedirectToAction(nameof(Index));
            //    }
            //}
            //catch (DbUpdateException /* ex */)
            //{
            //    //Log the error (uncomment ex variable name and write a log.)
            //    ModelState.AddModelError("", "Unable to save changes. " +
            //        "Try again, and if the problem persists, " +
            //        "see your system administrator.");
            //}


            //ViewData["ProviderID"] = new SelectList(_context.Providers, "ProviderID", "FirstMidName", input.ProviderID);
            PopulateProvidersDropDownList(input.ProviderID);
            populateProductDropDownList();
            return(View(input));
        }
        public static void Seed(MvcTpvContext context)
        {
            /* if (context == null)
             * {
             *   throw new ArgumentNullException(nameof(context));
             * }*/

            context.Database.EnsureCreated();

            if (context.Products.Any())
            {
                return;
            }



            var categorias = new Category[]
            {
                new Category
                {
                    CategoryName = "Cars"
                },
                new Category
                {
                    CategoryName = "Planes"
                },
                new Category
                {
                    CategoryName = "Trucks"
                },
                new Category
                {
                    CategoryName = "Boats"
                },
                new Category
                {
                    CategoryName = "Rockets"
                },
            };

            foreach (Category c in categorias)
            {
                context.Categories.Add(c);
            }
            context.SaveChanges();

            var productos = new Product[]
            {
                new Product
                {
                    ProductName = "Convertible Car",
                    Description = "This convertible car is fast! The engine is powered by a neutrino based battery (not included)." +
                                  "Power it up and let it go!",
                    ImagePath = "carconvert.png",
                    //UnitPrice = 22.50,
                    Stock      = 3,
                    CategoryID = 1
                },
                new Product
                {
                    ProductName = "Old-time Car",
                    Description = "There's nothing old about this toy car, except it's looks. Compatible with other old toy cars.",
                    ImagePath   = "carearly.png",
                    Stock       = 15,
                    CategoryID  = 1
                },
                new Product
                {
                    ProductName = "Fast Car",
                    Description = "Yes this car is fast, but it also floats in water.",
                    ImagePath   = "carfast.png",

                    Stock      = 3,
                    CategoryID = 1
                },
                new Product
                {
                    ProductName = "Super Fast Car",
                    Description = "Use this super fast car to entertain guests. Lights and doors work!",
                    ImagePath   = "carfaster.png",
                    Stock       = 3,
                    CategoryID  = 1
                },
                new Product
                {
                    ProductName = "Old Style Racer",
                    Description = "This old style racer can fly (with user assistance). Gravity controls flight duration." +
                                  "No batteries required.",
                    ImagePath = "carracer.png",

                    Stock      = 3,
                    CategoryID = 1
                },
                new Product
                {
                    ProductName = "Ace Plane",
                    Description = "Authentic airplane toy. Features realistic color and details.",
                    ImagePath   = "planeace.png",

                    Stock      = 3,
                    CategoryID = 2
                },
                new Product
                {
                    ProductName = "Glider",
                    Description = "This fun glider is made from real balsa wood. Some assembly required.",
                    ImagePath   = "planeglider.png",
                    //UnitPrice = 4.95,
                    Stock      = 3,
                    CategoryID = 2
                },
                new Product
                {
                    ProductName = "Paper Plane",
                    Description = "This paper plane is like no other paper plane. Some folding required.",
                    ImagePath   = "planepaper.png",
                    //UnitPrice = 2.95,
                    Stock      = 3,
                    CategoryID = 2
                },
                new Product
                {
                    ProductName = "Propeller Plane",
                    Description = "Rubber band powered plane features two wheels.",
                    ImagePath   = "planeprop.png",
                    //UnitPrice = 32.95,
                    Stock      = 3,
                    CategoryID = 2
                },
                new Product
                {
                    ProductName = "Early Truck",
                    Description = "This toy truck has a real gas powered engine. Requires regular tune ups.",
                    ImagePath   = "truckearly.png",
                    //UnitPrice = 15.00,
                    Stock      = 3,
                    CategoryID = 3
                },
                new Product
                {
                    ProductName = "Fire Truck",
                    Description = "You will have endless fun with this one quarter sized fire truck.",
                    ImagePath   = "truckfire.png",
                    //UnitPrice = 26.00,
                    Stock      = 3,
                    CategoryID = 3
                },
                new Product
                {
                    ProductName = "Big Truck",
                    Description = "This fun toy truck can be used to tow other trucks that are not as big.",
                    ImagePath   = "truckbig.png",
                    //UnitPrice = 29.00,
                    Stock      = 3,
                    CategoryID = 3
                },
                new Product
                {
                    ProductName = "Big Ship",
                    Description = "Is it a boat or a ship. Let this floating vehicle decide by using its " +
                                  "artifically intelligent computer brain!",
                    ImagePath = "boatbig.png",
                    //UnitPrice = 95.00,
                    Stock      = 3,
                    CategoryID = 4
                },
                new Product
                {
                    ProductName = "Paper Boat",
                    Description = "Floating fun for all! This toy boat can be assembled in seconds. Floats for minutes!" +
                                  "Some folding required.",
                    ImagePath = "boatpaper.png",
                    //UnitPrice = 4.95,
                    Stock      = 3,
                    CategoryID = 4
                },
                new Product
                {
                    ProductName = "Sail Boat",
                    Description = "Put this fun toy sail boat in the water and let it go!",
                    ImagePath   = "boatsail.png",
                    //UnitPrice = 42.95,
                    Stock      = 3,
                    CategoryID = 4
                },
                new Product
                {
                    ProductName = "Rocket",
                    Description = "This fun rocket will travel up to a height of 200 feet.",
                    ImagePath   = "rocket.png",
                    //UnitPrice = 122.95,
                    Stock      = 3,
                    CategoryID = 5
                }
            };

            foreach (Product p in productos)
            {
                context.Products.Add(p);
            }
            context.SaveChanges();


            var providers = new Provider[]
            {
                new Provider {
                    CategoryID = 1, FirstMidName = "Laura", LastName = "Cars Provider", HighDate = DateTime.Parse("2013-09-01")
                },
                new Provider {
                    CategoryID = 2, FirstMidName = "Nino", LastName = "Plane Provider", HighDate = DateTime.Parse("2005-09-01")
                },
                new Provider {
                    CategoryID = 3, FirstMidName = "Norman", LastName = "Truck Provider", HighDate = DateTime.Parse("2013-09-01")
                },
                new Provider {
                    CategoryID = 4, FirstMidName = "Olivetto", LastName = "Ship Provider", HighDate = DateTime.Parse("2005-09-01")
                },
                new Provider {
                    CategoryID = 5, FirstMidName = "Lolo", LastName = "Rocket Provider", HighDate = DateTime.Parse("2013-09-01")
                },
            };

            foreach (Provider p in providers)
            {
                context.Providers.Add(p);
            }
            context.SaveChanges();



            var customers = new Customer[]
            {
                new Customer {
                    FirstMidName = "Carson", LastName = "Alexander",
                    HighDate     = DateTime.Parse("2010-09-01")
                },
                new Customer {
                    FirstMidName = "Meredith", LastName = "Alonso",
                    HighDate     = DateTime.Parse("2012-09-01")
                },
                new Customer {
                    FirstMidName = "Arturo", LastName = "Anand",
                    HighDate     = DateTime.Parse("2013-09-01")
                },
                new Customer {
                    FirstMidName = "Gytis", LastName = "Barzdukas",
                    HighDate     = DateTime.Parse("2012-09-01")
                },
                new Customer {
                    FirstMidName = "Laura", LastName = "Norman",
                    HighDate     = DateTime.Parse("2013-09-01")
                },
                new Customer {
                    FirstMidName = "Nino", LastName = "Olivetto",
                    HighDate     = DateTime.Parse("2005-09-01")
                }
            };

            foreach (Customer c in customers)
            {
                context.Customers.Add(c);
            }
            context.SaveChanges();

            var salemans = new SaleMan[]
            {
                new SaleMan {
                    FirstMidName = "Yan", LastName = "Li",
                    HighDate     = DateTime.Parse("2012-09-01")
                },
                new SaleMan {
                    FirstMidName = "Peggy", LastName = "Justice",
                    HighDate     = DateTime.Parse("2011-09-01")
                },
            };

            foreach (SaleMan s in salemans)
            {
                context.SaleMans.Add(s);
            }
            context.SaveChanges();



            var sales = new Sale[]
            {
                new Sale {
                    CustomerID = 1, SaleManID = 1, Tipo_Comprobante = Comprobante.Recibo, Serie_comprobante = "01R", Num_comprobante = "0001", Fecha_Hora = DateTime.Parse("2016-09-01"), Impuesto = 0.14m, Estado = Estado.Emitido
                },
                new Sale {
                    CustomerID = 2, SaleManID = 1, Tipo_Comprobante = Comprobante.Recibo, Serie_comprobante = "01R", Num_comprobante = "0002", Fecha_Hora = DateTime.Parse("2012-10-01"), Impuesto = 0.14m, Estado = Estado.Anulada
                },

                new Sale {
                    CustomerID = 3, SaleManID = 2, Tipo_Comprobante = Comprobante.Factura, Serie_comprobante = "01F", Num_comprobante = "0001", Fecha_Hora = DateTime.Parse("2014-03-01"), Impuesto = 0.14m, Estado = Estado.Emitido
                },
                new Sale {
                    CustomerID = 4, SaleManID = 2, Tipo_Comprobante = Comprobante.Factura, Serie_comprobante = "01F", Num_comprobante = "0002", Fecha_Hora = DateTime.Parse("2015-05-01"), Impuesto = 0.14m, Estado = Estado.Facturado
                },
            };

            foreach (Sale s in sales)
            {
                context.Sales.Add(s);
            }
            context.SaveChanges();


            var saledetails = new SaleDetail[]
            {
                new SaleDetail {
                    ProductID = 1, SaleID = 1, Cantidad = 2, PVP = 22.50m, Descuento = 2.5m
                },
                new SaleDetail {
                    ProductID = 2, SaleID = 1, Cantidad = 2, PVP = 15.95m, Descuento = 2.5m
                },
                new SaleDetail {
                    ProductID = 3, SaleID = 1, Cantidad = 2, PVP = 32.99m, Descuento = 2.5m
                },
                new SaleDetail {
                    ProductID = 4, SaleID = 1, Cantidad = 2, PVP = 8.95m, Descuento = 2.5m
                },


                new SaleDetail {
                    ProductID = 5, SaleID = 2, Cantidad = 2, PVP = 32.99m, Descuento = 2.5m
                },
                new SaleDetail {
                    ProductID = 6, SaleID = 2, Cantidad = 2, PVP = 8.95m, Descuento = 2.5m
                },
            };

            foreach (SaleDetail sd in saledetails)
            {
                context.SaleDetails.Add(sd);
            }
            context.SaveChanges();

            var inputs = new Input[]
            {
                new Input {
                    ProviderID = 1, Tipo_Comprobante = "Albaran", serie_comprobante = "P1A", num_comprobante = "0001", Fecha_hora = DateTime.Parse("2017-09-01"), Impuesto = 0.14m
                },
                new Input {
                    ProviderID = 2, Tipo_Comprobante = "Albaran", serie_comprobante = "P1A", num_comprobante = "0002", Fecha_hora = DateTime.Parse("2014-10-01"), Impuesto = 0.14m
                },
                new Input {
                    ProviderID = 3, Tipo_Comprobante = "Factura", serie_comprobante = "P1F", num_comprobante = "0001", Fecha_hora = DateTime.Parse("2015-03-01"), Impuesto = 0.14m
                },

                new Input {
                    ProviderID = 4, Tipo_Comprobante = "Factura", serie_comprobante = "P1F", num_comprobante = "0002", Fecha_hora = DateTime.Parse("2016-05-01"), Impuesto = 0.14m
                },
            };

            foreach (Input i in inputs)
            {
                context.Inputs.Add(i);
            }
            context.SaveChanges();


            var inputdetails = new InputDetail[]
            {
                new InputDetail {
                    InputID = 1, ProductID = 1, Cantidad = 2, PNETO = 11.25m, PVP = 22.50m,
                },
                new InputDetail {
                    InputID = 1, ProductID = 2, Cantidad = 2, PNETO = 7.95m, PVP = 15.95m
                },
                new InputDetail {
                    InputID = 1, ProductID = 3, Cantidad = 2, PNETO = 17.51m, PVP = 32.99m
                },
                new InputDetail {
                    InputID = 1, ProductID = 4, Cantidad = 2, PNETO = 7.99m, PVP = 8.95m
                },

                new InputDetail {
                    InputID = 2, ProductID = 6, Cantidad = 2, PNETO = 49.95m, PVP = 95.00m
                },
                new InputDetail {
                    InputID = 2, ProductID = 7, Cantidad = 4, PNETO = 5.99m, PVP = 4.95m
                },


                new InputDetail {
                    InputID = 3, ProductID = 10, Cantidad = 2, PNETO = 7.50m, PVP = 15.00m
                },
                new InputDetail {
                    InputID = 3, ProductID = 11, Cantidad = 2, PNETO = 13.00m, PVP = 26.00m
                },

                new InputDetail {
                    InputID = 4, ProductID = 13, Cantidad = 2, PNETO = 49.95m, PVP = 4.95m
                },
            };

            foreach (InputDetail id in inputdetails)
            {
                context.InputDetails.Add(id);
            }
            context.SaveChanges();
        }
        public ActionResult PostLoading(string orderId, string productId, string weight, string qty, string inputDetailId, string driverId
                                        , string carNumber, string phone, string desc, string exitId)
        {
            try
            {
                decimal weightDecimal     = 0;
                int     qtyInt            = 0;
                string  message           = "message-";
                Guid    orderIdGuid       = new Guid(orderId);
                Guid    productIdGuid     = new Guid(productId);
                Guid    inputDetailIdGuid = new Guid(inputDetailId);

                if (!string.IsNullOrEmpty(weight))
                {
                    weightDecimal = Convert.ToDecimal(weight);
                }

                if (!string.IsNullOrEmpty(qty))
                {
                    qtyInt = Convert.ToInt32(qty);
                }

                //Guid customerIdGuid = new Guid(customerId);

                Order order = UnitOfWork.OrderRepository.GetById(orderIdGuid);

                //  Product product = UnitOfWork.ProductRepository.GetById(productIdGuid);

                //ProductRemainsViewModel remain = GetRemainProduct(productIdGuid, orderIdGuid, order.CustomerId);
                InputDetail inputDetail = UnitOfWork.InputDetailsRepository.GetById(inputDetailIdGuid);
                decimal     unit        = inputDetail.RemainDestinationWeight / inputDetail.RemainQuantity;

                if (!string.IsNullOrEmpty(qty) && inputDetail.RemainQuantity < qtyInt)
                {
                    return(Json(message + "تعداد وارد شده بیش از تعداد باقی مانده می باشد", JsonRequestBehavior.AllowGet));
                }

                if (!string.IsNullOrEmpty(weight) && inputDetail.RemainDestinationWeight < weightDecimal)
                {
                    return(Json(message + "وزن وارد شده بیش از وزن باقی مانده می باشد", JsonRequestBehavior.AllowGet));
                }


                if (string.IsNullOrEmpty(exitId))
                {
                    Exit exit = CreateExit(order.CustomerId, driverId, carNumber, phone, desc);
                    CreateExitDetail(exit.Id, inputDetailIdGuid, qtyInt, weightDecimal, unit);
                    UpdateInputDetail(inputDetailIdGuid, qtyInt, weightDecimal, unit);
                }
                else
                {
                    Guid id   = new Guid(exitId);
                    Exit exit = UnitOfWork.ExitRepository.Get(current => current.Id == id && current.ExitComplete == false).FirstOrDefault();

                    if (exit == null)
                    {
                        return(Json(message + "ردیف بارگیری اشتباه است", JsonRequestBehavior.AllowGet));
                    }

                    CreateExitDetail(exit.Id, inputDetailIdGuid, qtyInt, weightDecimal, unit);
                    UpdateInputDetail(inputDetailIdGuid, qtyInt, weightDecimal, unit);
                }

                //if (customerIdGuid == order.CustomerId)
                //    return Json(message + "امکان انتقال حواله به مالک قبلی آن وجود ندارد", JsonRequestBehavior.AllowGet);


                //Guid childOrderId = CreateChildOrder(orderIdGuid, customerIdGuid);

                //decimal unit = remain.RemainWeight / remain.RemainQuantity;

                //SeprateInputDetail(productIdGuid, orderIdGuid, order.CustomerId, qtyInt, weightDecimal, childOrderId, unit);

                //UnitOfWork.Save();

                return(Json("true", JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json("false", JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Details(CutOrderViewModel cutOrderViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    cutOrderViewModel.InputDetail = UnitOfWork.InputDetailsRepository.GetById(cutOrderViewModel.InputDetail.Id);

                    Order inputDetailOrder = UnitOfWork.OrderRepository.Get(current => current.Id == cutOrderViewModel.InputDetail.OrderId).FirstOrDefault();
                    cutOrderViewModel.InputDetail.Order = inputDetailOrder;
                    ProductRemainsViewModel remain = GetRemainProduct(cutOrderViewModel.InputDetail.ProductId, cutOrderViewModel.InputDetail.OrderId.Value, cutOrderViewModel.InputDetail.Order.CustomerId);

                    string cutId = string.Empty;
                    if (cutOrderViewModel.CutOrderId != null)
                    {
                        cutId = cutOrderViewModel.CutOrderId.ToString();
                        Guid cutGuid = new Guid(cutId);
                        cutOrderViewModel.CutOrderDetails = UnitOfWork.CutOrderDetailRepository.Include(current => current.CutOrder.InputDetail.Product.ProductGroup).Where(current => current.CutOrderId == cutGuid).ToList();
                    }
                    if (remain.RemainWeight < cutOrderViewModel.Weight)
                    {
                        ModelState.AddModelError("Weight", "وزن وارد شده بیش از وزن باقی مانده می باشد");
                    }
                    else if (remain.RemainQuantity < cutOrderViewModel.Quantity)
                    {
                        ModelState.AddModelError("Weight", "تعداد برگ وارد شده بیش از تعداد باقی مانده می باشد");
                    }
                    else if (remain.RemainWeight == 0)
                    {
                        ModelState.AddModelError("Weight", "کالا موجود نمی باشد");
                    }
                    else if (remain.RemainWeight == cutOrderViewModel.Weight)
                    {
                        if (cutOrderViewModel.CutOrderId == null)
                        {
                            CutOrder cut = new CutOrder()
                            {
                                CreationDate  = DateTime.Now,
                                InputDetailId = cutOrderViewModel.InputDetail.Id,
                                IsActive      = true,
                                IsDeleted     = false
                            };
                            UnitOfWork.CutOrderRepository.Insert(cut);
                            UnitOfWork.Save();
                            cutId = cut.Id.ToString();
                        }
                        Guid cutGuid = new Guid(cutId);
                        cutOrderViewModel.CutOrderId = cutGuid;
                        CutOrderDetail cutOrderDetail = new CutOrderDetail()
                        {
                            Weight         = cutOrderViewModel.Weight,
                            Length         = cutOrderViewModel.Length,
                            Quantity       = Convert.ToInt32(cutOrderViewModel.Quantity),
                            CutOrderId     = cutGuid,
                            CustomActionId = cutOrderViewModel.CustomActionId,
                            CreationDate   = DateTime.Now,
                            IsActive       = true,
                            IsDeleted      = false
                        };
                        UnitOfWork.CutOrderDetailRepository.Insert(cutOrderDetail);
                        UnitOfWork.Save();

                        cutOrderViewModel.CutOrderDetails = UnitOfWork.CutOrderDetailRepository.Include(current => current.CutOrder.InputDetail.Product.ProductGroup).Where(current => current.CutOrderId == cutOrderViewModel.CutOrderId).ToList();

                        InputDetail inputDetailUpdate = UnitOfWork.InputDetailsRepository.GetById(cutOrderViewModel.InputDetail.Id);
                        inputDetailUpdate.RemainDestinationWeight = 0;
                        inputDetailUpdate.RemainQuantity          = 0;
                        UnitOfWork.InputDetailsRepository.Update(inputDetailUpdate);
                        UnitOfWork.Save();
                        cutOrderViewModel.RemainWeight = inputDetailUpdate.RemainDestinationWeight;
                    }
                    else
                    {
                        if (cutOrderViewModel.CutOrderId != null)
                        {
                            Order order = new Order()
                            {
                                Customer  = cutOrderViewModel.InputDetail.Order.Customer,
                                Parent    = cutOrderViewModel.InputDetail.Order,
                                Code      = GenerateCode.GetChildOrderCode(cutOrderViewModel.InputDetail.OrderId.Value),
                                IsActive  = true,
                                IsDeleted = false,
                                IsLatest  = true
                            };
                            UnitOfWork.OrderRepository.Insert(order);
                            UnitOfWork.Save();

                            CutOrderDetail cutOrderDetail = new CutOrderDetail()
                            {
                                Weight         = cutOrderViewModel.Weight,
                                Length         = cutOrderViewModel.Length,
                                Quantity       = Convert.ToInt32(cutOrderViewModel.Quantity),
                                CutOrderId     = cutOrderViewModel.CutOrderId.Value,
                                CustomActionId = cutOrderViewModel.CustomActionId,
                                CreationDate   = DateTime.Now,
                                IsActive       = true,
                                IsDeleted      = false
                            };
                            UnitOfWork.CutOrderDetailRepository.Insert(cutOrderDetail);
                            UnitOfWork.Save();
                        }
                        else
                        {
                            Order order = new Order()
                            {
                                Customer  = cutOrderViewModel.InputDetail.Order.Customer,
                                Parent    = cutOrderViewModel.InputDetail.Order,
                                Code      = GenerateCode.GetChildOrderCode(cutOrderViewModel.InputDetail.OrderId.Value),
                                IsActive  = true,
                                IsDeleted = false,
                                IsLatest  = true
                            };
                            UnitOfWork.OrderRepository.Insert(order);
                            UnitOfWork.Save();

                            CutOrder cut = new CutOrder()
                            {
                                CreationDate  = DateTime.Now,
                                InputDetailId = cutOrderViewModel.InputDetail.Id,
                                IsActive      = true,
                                IsDeleted     = false
                            };
                            UnitOfWork.CutOrderRepository.Insert(cut);
                            UnitOfWork.Save();

                            cutOrderViewModel.CutOrderId = cut.Id;
                            CutOrderDetail cutOrderDetail = new CutOrderDetail()
                            {
                                Weight         = cutOrderViewModel.Weight,
                                Length         = cutOrderViewModel.Length,
                                Quantity       = Convert.ToInt32(cutOrderViewModel.Quantity),
                                CutOrderId     = cut.Id,
                                CustomActionId = cutOrderViewModel.CustomActionId,
                                CreationDate   = DateTime.Now,
                                IsActive       = true,
                                IsDeleted      = false
                            };
                            UnitOfWork.CutOrderDetailRepository.Insert(cutOrderDetail);
                            UnitOfWork.Save();
                        }
                        cutOrderViewModel.CutOrderDetails = UnitOfWork.CutOrderDetailRepository.Include(current => current.CutOrder.InputDetail.Product.ProductGroup).Where(current => current.CutOrderId == cutOrderViewModel.CutOrderId).ToList();


                        decimal     unit = remain.RemainWeight / remain.RemainQuantity;
                        InputDetail inputDetailUpdate = UnitOfWork.InputDetailsRepository.GetById(cutOrderViewModel.InputDetail.Id);
                        inputDetailUpdate.RemainDestinationWeight = remain.RemainWeight - cutOrderViewModel.Weight;
                        inputDetailUpdate.RemainQuantity          = remain.RemainQuantity - (cutOrderViewModel.Weight / unit);
                        UnitOfWork.InputDetailsRepository.Update(inputDetailUpdate);
                        UnitOfWork.Save();
                        cutOrderViewModel.RemainWeight = inputDetailUpdate.RemainDestinationWeight;
                    }
                }

                ViewBag.CustomActionId = new SelectList(UnitOfWork.ProductGroupCustomActionRepository.Get(x => x.ProductGroupId == cutOrderViewModel.InputDetail.Product.ProductGroupId).Select(x => x.CustomAction), "Id", "Title");
                ViewBag.CustomerName   = cutOrderViewModel.InputDetail.Order.Customer.FullName;
                return(View(cutOrderViewModel));
            }
            catch (Exception exp)
            {
                return(Json(exp.Message, JsonRequestBehavior.AllowGet));
            }
        }
Example #24
0
        public int Insert(InputDetail obj)
        {
            /// 1: update thành công
            /// 0: Update ko thành công

            int    res      = 0;
            string queryStr = "INSERT INTO";

            queryStr += " inputdetail (";
            if (!string.IsNullOrEmpty(obj.InputId))
            {
                queryStr += "`InputId`,";
            }
            if (!string.IsNullOrEmpty(obj.IngredientId))
            {
                queryStr += "`IngredientId`,";
            }
            if (!string.IsNullOrEmpty(obj.IngredientExpDate))
            {
                queryStr += "`IngredientExpDate`,";
            }
            if (!string.IsNullOrEmpty(obj.IngredientQty))
            {
                queryStr += "`IngredientQty`,";
            }
            if (!string.IsNullOrEmpty(obj.IngredientPrice))
            {
                queryStr += "`IngredientPrice`,";
            }
            if (!string.IsNullOrEmpty(obj.IngredientVat))
            {
                queryStr += "`IngredientVat`,";
            }
            if (!string.IsNullOrEmpty(obj.IngredientDiscount))
            {
                queryStr += "`IngredientDiscount`";
            }
            queryStr += ") VALUES (";

            if (!string.IsNullOrEmpty(obj.InputId))
            {
                queryStr += string.Format("'{0}',", obj.InputId);
            }
            if (!string.IsNullOrEmpty(obj.IngredientId))
            {
                queryStr += string.Format("'{0}',", obj.IngredientId);
            }
            if (!string.IsNullOrEmpty(obj.IngredientExpDate))
            {
                queryStr += string.Format("'{0}',", obj.IngredientExpDate);
            }
            if (!string.IsNullOrEmpty(obj.IngredientQty))
            {
                queryStr += string.Format("'{0}',", obj.IngredientQty);
            }
            if (!string.IsNullOrEmpty(obj.IngredientPrice))
            {
                queryStr += string.Format("'{0}',", obj.IngredientPrice);
            }
            if (!string.IsNullOrEmpty(obj.IngredientVat))
            {
                queryStr += string.Format("'{0}',", obj.IngredientVat);
            }
            if (!string.IsNullOrEmpty(obj.IngredientDiscount))
            {
                queryStr += string.Format("'{0}'", obj.IngredientDiscount);
            }
            queryStr += ")";
            Program.destopService.DataExecute(Program.Username, Program.Password, queryStr, ref errorString);
            if (string.IsNullOrEmpty(errorString))
            {
                res = 1;
            }
            return(res);
        }
Example #25
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            DataTable   dtCheck = inputDetailBLL.GetInputDetailById(this.inputId, cbbIngredient.SelectedValue.ToString());
            InputDetail obj     = new InputDetail();

            obj.InputId            = this.inputId;
            obj.IngredientId       = cbbIngredient.SelectedValue.ToString();
            obj.IngredientExpDate  = dtbExDate.Text;
            obj.IngredientQty      = txtQty.Text;
            obj.IngredientPrice    = txtPrice.Text;
            obj.IngredientVat      = txtVAT.Text;
            obj.IngredientDiscount = txtDiscount.Text;
            if (dtCheck != null)
            {
                if (dtCheck.Rows.Count != 0)
                {
                    if (CustomMessageBox.MessageBox.ShowCustomMessageBox("Bạn có muốn cập nhật thông tin nhập này không?",
                                                                         Common.clsLanguages.GetResource("Information"),
                                                                         Common.Config.CUSTOM_MESSAGEBOX_ICON.Information,
                                                                         Common.Config.CUSTOM_MESSAGEBOX_BUTTON.YESNO) == DialogResult.Yes)
                    {
                        // Update
                        int i = inputDetailBLL.Update(obj);
                        if (i == 1)
                        {
                            CustomMessageBox.MessageBox.ShowCustomMessageBox("Cập nhật thành công",
                                                                             Common.clsLanguages.GetResource("Information"),
                                                                             Common.Config.CUSTOM_MESSAGEBOX_ICON.Information,
                                                                             Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                        }
                        else
                        {
                            CustomMessageBox.MessageBox.ShowCustomMessageBox("Cập nhật thất bại",
                                                                             Common.clsLanguages.GetResource("Information"),
                                                                             Common.Config.CUSTOM_MESSAGEBOX_ICON.Information,
                                                                             Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                        }
                    }
                }
                else
                {
                    if (CustomMessageBox.MessageBox.ShowCustomMessageBox("Bạn có muốn thêm thông tin nhập này không?",
                                                                         Common.clsLanguages.GetResource("Information"),
                                                                         Common.Config.CUSTOM_MESSAGEBOX_ICON.Information,
                                                                         Common.Config.CUSTOM_MESSAGEBOX_BUTTON.YESNO) == DialogResult.Yes)
                    {
                        // Insert
                        int i = inputDetailBLL.Insert(obj);
                        if (i == 1)
                        {
                            CustomMessageBox.MessageBox.ShowCustomMessageBox("Thêm mới thành công",
                                                                             Common.clsLanguages.GetResource("Information"),
                                                                             Common.Config.CUSTOM_MESSAGEBOX_ICON.Information,
                                                                             Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                        }
                        else
                        {
                            CustomMessageBox.MessageBox.ShowCustomMessageBox("Thêm mới thất bại",
                                                                             Common.clsLanguages.GetResource("Information"),
                                                                             Common.Config.CUSTOM_MESSAGEBOX_ICON.Information,
                                                                             Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK);
                        }
                    }
                }
            }
        }