//
        // GET: /BillOfMaterial/

        public ActionResult Add(string ID)
        {
            ViewBag.FinishedProductList    = ProductLogic.GetFinishedProducts();
            ViewBag.RawMaterialProductList = ProductLogic.GetRawMaterialProducts();
            ViewBag.BOMProcessList         = BOMProcessLogic.BOMProcessByID(0);
            ViewBag.UnitList      = ProductUnitLogic.GetProductUnitByID(0);
            ViewBag.LabParameters = LabParameterLogic.GetLabParameterByID(0);
            ViewBag.UserType      = currUser.Type;
            if (Convert.ToInt32(ID) > 0)
            {
                var bom = BillOfMaterialLogic.GetBillOfMaterialByID(Convert.ToInt32(ID)).FirstOrDefault();
                ViewBag.ShadeList = ShadeLogic.GetShadeByProductID(Convert.ToInt32(bom.ProductID)).Select(x => new { x.ShadeID, x.ShadeName }).Distinct();
                //var productShades = ShadeLogic.GetShadeByProductID(bom.ProductID);
                //if (productShades != null && productShades.Count() > 0)
                //{
                //    foreach (var productShade in productShades.Select(x => x.ShadeID).Distinct())
                //    {
                //        ViewBag.ShadeList = ShadeLogic.GetShadeByID(Convert.ToInt32(productShade));
                //    }
                //}
                //else
                //{
                //    ViewBag.ShadeList = null;
                //}
                return(View(bom));
            }
            else
            {
                ViewBag.ShadeList = null;
                return(View(new BillOfMaterial()));
            }
        }
        public ActionResult GetLastRevision(int ProductID, int ShadeID)
        {
            ViewBag.RawMaterialProductList = ProductLogic.GetRawMaterialProducts();
            ViewBag.BOMProcessList         = BOMProcessLogic.BOMProcessByID(0);
            var lastReivision = BillOfMaterialLogic.GetLastRevision(ProductID, ShadeID);

            if (lastReivision != null)
            {
                return(PartialView("_BOMRawMaterials", lastReivision));
            }
            else
            {
                return(null);
            }
        }
        public ActionResult GetRawMaterialDetails(int ProductID, int ShadeID, string RevisionNo)
        {
            ResponseMsg response = new ResponseMsg();

            ViewBag.RawMaterialProductList = ProductLogic.GetRawMaterialProducts();
            ViewBag.BOMProcessList         = BOMProcessLogic.BOMProcessByID(0);
            var lastReivision = BillOfMaterialDetailLogic.GetRawMaterialDetails(ProductID, ShadeID, RevisionNo);

            if (lastReivision != null)
            {
                var rmHtml  = "";
                var labHtml = "";
                using (var sw = new StringWriter())
                {
                    PartialViewResult result = PartialView("_BOMRawMaterials", lastReivision);
                    result.View = ViewEngines.Engines.FindPartialView(ControllerContext, "_BOMRawMaterials").View;
                    ViewContext vc = new ViewContext(ControllerContext, result.View, result.ViewData, result.TempData, sw);
                    result.View.Render(vc, sw);
                    rmHtml = sw.GetStringBuilder().ToString();
                }
                using (var sw = new StringWriter())
                {
                    var bom = BillOfMaterialLogic.GetBillOfMaterialByPSR(ProductID, ShadeID, RevisionNo);
                    ViewBag.LabParameters = LabParameterLogic.GetLabParameterByID(0);
                    PartialViewResult result = PartialView("_BOMLabParameters", bom);
                    result.View = ViewEngines.Engines.FindPartialView(ControllerContext, "_BOMLabParameters").View;
                    ViewContext vc = new ViewContext(ControllerContext, result.View, result.ViewData, result.TempData, sw);
                    result.View.Render(vc, sw);
                    labHtml = sw.GetStringBuilder().ToString();
                }
                response.IsSuccess     = true;
                response.ResponseValue = new { RMData = rmHtml, LABData = labHtml };
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(null);
            }
        }