Exemple #1
0
        public JsonResult CheckPartName(string partName, int side)
        {
            List <Part> parts = new List <Part>();
            // gets the list of parts
            var data = PartProcessor.LoadPart();

            foreach (var row in data)
            {
                parts.Add(new Part
                {
                    partId   = row.partId,
                    partName = row.partName,
                    side     = row.side
                });
            }


            // Checks thru the list of parts to see if parts exist in database
            bool isValid = !parts.ToList().Exists(p => p.partName.Equals(partName, StringComparison.CurrentCultureIgnoreCase));

            if (isValid == true)
            {
                isValid = parts.ToList().Exists(p => p.side.Equals(side));
            }


            return(Json(isValid));
        }
Exemple #2
0
        public List <Part> getParts()
        {
            List <Part> parts    = new List <Part>();
            var         partData = PartProcessor.LoadPart();

            foreach (var row in partData)
            {
                parts.Add(new Part
                {
                    partId   = row.partId,
                    partName = row.partName,
                });
            }

            return(parts);
        }
        public ActionResult editOrderCSV(int id)
        {
            var orderData = OrderProcessor.LoadOrder(id);

            Order order = new Order();

            foreach (var row in orderData)
            {
                order.orderId          = row.orderId;
                order.partId           = row.partId;
                order.projectName      = row.projectName;
                order.lastMaterialDate = row.lastMaterialDate;
                order.shipDate         = row.shipDate;
                order.quantity         = row.quantity;
                order.status           = row.status;
                order.priority         = row.priority;
            }

            List <Part> parts = new List <Part>();
            var         data  = PartProcessor.LoadPart();

            foreach (var row in data)
            {
                parts.Add(new Part
                {
                    partId   = row.partId,
                    partName = row.partName,
                    side     = row.side
                });
            }



            OrderPartViewModel OrderPartViewModel = new OrderPartViewModel();

            OrderPartViewModel.order = order;
            //   OrderPartViewModel.selectedPart = order.partId;
            //   OrderPartViewModel.selectedStatus = order.status;
            //  OrderPartViewModel.selectedPriority = order.priority;

            OrderPartViewModel.parts = parts;



            return(View(OrderPartViewModel));
        }
Exemple #4
0
        public ActionResult ViewParts()
        {
            ViewBag.Message = "Part List";

            var data = PartProcessor.LoadPart();

            List <Part> parts = new List <Part>();

            foreach (var row in data)
            {
                parts.Add(new Part
                {
                    partId   = row.partId,
                    partName = row.partName,
                    side     = row.side
                });
            }

            return(View(parts));
        }
        public ActionResult newOrder()
        {
            List <Part> parts = new List <Part>();
            var         data  = PartProcessor.LoadPart();

            foreach (var row in data)
            {
                parts.Add(new Part
                {
                    partId   = row.partId,
                    partName = row.partName,
                    side     = row.side
                });
            }

            OrderPartViewModel OrderPartViewModel = new OrderPartViewModel();

            OrderPartViewModel.parts = parts;


            return(View(OrderPartViewModel));
        }
Exemple #6
0
        public ActionResult importManufacturingCSV(HttpPostedFileBase excelfile)
        {
            if (excelfile == null || excelfile.ContentLength == 0)
            {
                //ViewBag.Error = "Please select a excel file";
                TempData["ErrorCSV"] = "Please select a excel file";
                return(RedirectToAction("importManufacturingCSV"));
            }
            else
            {
                if (excelfile.FileName.EndsWith("xls") || excelfile.FileName.EndsWith("xlsx"))
                {
                    string path = Server.MapPath("~/Content/" + excelfile.FileName);
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                    excelfile.SaveAs(path);

                    //Read data from excel
                    Excel.Application application = new Excel.Application();
                    Excel.Workbook    workbook    = application.Workbooks.Open(path);
                    Excel.Worksheet   worksheet   = workbook.ActiveSheet;
                    Excel.Range       range       = worksheet.UsedRange;



                    //import current list of ManufacturingTime
                    List <ManufacturingTime> existingMTList = new List <ManufacturingTime>();
                    var data = manufacturingTimeProcessor.LoadManufacturingList();
                    foreach (var row in data)
                    {
                        existingMTList.Add(new ManufacturingTime
                        {
                            lineId            = row.lineId,
                            PartId            = row.partId,
                            manufacturingTIme = row.manufacturingTime
                        });
                    }

                    //import current list of parts
                    List <Part> existingPartList = new List <Part>();
                    var         partData         = PartProcessor.LoadPart();
                    foreach (var row in partData)
                    {
                        existingPartList.Add(new Part
                        {
                            partId   = row.partId,
                            partName = row.partName,
                            side     = row.side
                        });
                    }


                    //import current list of lines
                    List <Line> existingLineList = new List <Line>();
                    var         lineData         = LineProcessor.LoadLine();
                    foreach (var row in lineData)
                    {
                        existingLineList.Add(new Line
                        {
                            lineId   = row.lineId,
                            lineName = row.lineName,
                        });
                    }

                    //create List of of orders that have orderID exist and partId does not exist. Return list of objects to user
                    List <PartLineManufacturingViewModel> ErrorListMT = new List <PartLineManufacturingViewModel>();


                    // check part exist , if exist skip, else add
                    List <ManufacturingTime> listMT = new List <ManufacturingTime>();
                    for (int row = 2; row <= range.Rows.Count; row++)
                    {
                        ManufacturingTime MT = new ManufacturingTime();
                        Part part            = new Part();
                        Line line            = new Line();

                        //check if part exist. if exist skip
                        part.partId   = int.Parse(((Excel.Range)range.Cells[row, 1]).Text);
                        part.partName = ((Excel.Range)range.Cells[row, 2]).Text;
                        string side = ((Excel.Range)range.Cells[row, 3]).Text;
                        side                 = Regex.Replace(side, @"\s", "");
                        line.lineName        = ((Excel.Range)range.Cells[row, 6]).Text;
                        line.lineName        = Regex.Replace(line.lineName, @"\s", "");
                        MT.manufacturingTIme = int.Parse(((Excel.Range)range.Cells[row, 7]).Text);



                        if (String.Equals(side, "Top", StringComparison.OrdinalIgnoreCase))
                        {
                            part.side = 1;
                        }
                        else if (String.Equals(side, "Bottom", StringComparison.OrdinalIgnoreCase))
                        {
                            part.side = 2;
                        }
                        else
                        {
                            part.side = -1;
                            MT.error  = " Error with product Information.Invalid boardside";
                            MT.lineId = 0;
                            ErrorListMT.Add(new PartLineManufacturingViewModel {
                                partName = part.partName, lineName = line.lineName, manufacturingTIme = MT.manufacturingTIme, error = MT.error, selectedLine = MT.lineId
                            });
                            continue;
                        }

                        int addPartResult = 0;

                        /*
                         * // check if part exist
                         * bool partExist = PartController.CheckPartExist(part.partName, part.side);
                         * if (partExist == false)
                         * {
                         *  //add to part DB
                         *  addPartResult = PartController.addNewPart(part);
                         * }
                         */



                        bool continueCond = false;

                        int partId = existingPartList.Where(r => r.partName == part.partName && r.side == part.side).Select(r => r.partId).SingleOrDefault();

                        if (partId != 0)
                        {
                            part.partId = partId;


                            continueCond = true;
                        }
                        else
                        {
                            addPartResult = PartController.addNewPart(part);


                            if (addPartResult == 1)
                            {
                                //set new partId
                                var partIDData = PartProcessor.getPartIdByName(part.partName, part.side);

                                foreach (var row1 in partIDData)
                                {
                                    part.partId = row1.partId;
                                }

                                existingPartList.Add(part);

                                continueCond = true;
                            }
                        }



                        // Error with part information
                        if (continueCond == false)
                        {
                            //order.quantity = 0;
                            MT.error  = " Error with product Information. Check product or add new product";
                            MT.lineId = 0;
                            ErrorListMT.Add(new PartLineManufacturingViewModel {
                                partName = part.partName, lineName = line.lineName, manufacturingTIme = MT.manufacturingTIme, error = MT.error, selectedLine = MT.lineId
                            });
                            continue;
                        }


                        // check SMT line exist

                        //check if part exist, if part does not exist discard list
                        bool continueCond2 = false;


                        int lineId = existingLineList.Where(r => r.lineName == line.lineName).Select(x => x.lineId).SingleOrDefault();
                        if (lineId != 0)
                        {
                            line.lineId   = lineId;
                            continueCond2 = true;
                        }

                        if (continueCond2 == false)
                        {
                            MT.error  = " Error with line information, please check line Information or add new line ";
                            MT.lineId = 0;
                            ErrorListMT.Add(new PartLineManufacturingViewModel {
                                partName = part.partName, lineName = line.lineName, manufacturingTIme = MT.manufacturingTIme, error = MT.error, selectedLine = MT.lineId
                            });
                            continue;
                        }



                        // check line , part, MT data exist
                        bool manufacturingTimeExist = CheckManufacturingTimeExistBool(line.lineId, part.partId);


                        // if exist update
                        if (manufacturingTimeExist == true)
                        {
                            int updateManufacturingTimeResult = updateManufacturingTimeCSV(line.lineId, part.partId, MT.manufacturingTIme);



                            if (updateManufacturingTimeResult == -1)
                            {
                                MT.error = "Cycle time is not valid. please check cycle time";

                                MT.lineId = 0;
                                ErrorListMT.Add(new PartLineManufacturingViewModel {
                                    partName = part.partName, lineName = line.lineName, manufacturingTIme = MT.manufacturingTIme, error = MT.error, selectedLine = MT.lineId
                                });
                            }
                            else if (updateManufacturingTimeResult == 1)
                            {
                                MT.error = "Successfully updated";

                                MT.lineId = 1;
                                ErrorListMT.Add(new PartLineManufacturingViewModel {
                                    partName = part.partName, lineName = line.lineName, manufacturingTIme = MT.manufacturingTIme, error = MT.error, selectedLine = MT.lineId
                                });
                            }
                            else
                            {
                                MT.error = "Error updating manufacturing time information";

                                MT.lineId = 0;
                                ErrorListMT.Add(new PartLineManufacturingViewModel {
                                    partName = part.partName, lineName = line.lineName, manufacturingTIme = MT.manufacturingTIme, error = MT.error, selectedLine = MT.lineId
                                });
                            }
                            continue;
                        }

                        // Does not exist add new manufacturing Time data here

                        int newMTResult = newManufacturingTimeCSV(line.lineId, part.partId, MT.manufacturingTIme);

                        if (newMTResult == -1)
                        {
                            MT.error = "Cycle time is not valid. please check cycle time";

                            MT.lineId = 0;
                            ErrorListMT.Add(new PartLineManufacturingViewModel {
                                partName = part.partName, lineName = line.lineName, manufacturingTIme = MT.manufacturingTIme, error = MT.error, selectedLine = MT.lineId
                            });
                        }
                        else if (newMTResult == 1)
                        {
                            MT.error = "Successfully Added";

                            MT.lineId = 1;
                            ErrorListMT.Add(new PartLineManufacturingViewModel {
                                partName = part.partName, lineName = line.lineName, manufacturingTIme = MT.manufacturingTIme, error = MT.error, selectedLine = MT.lineId
                            });
                        }
                        else
                        {
                            MT.error = "Error in adding manufacturing time information";

                            MT.lineId = 0;
                            ErrorListMT.Add(new PartLineManufacturingViewModel {
                                partName = part.partName, lineName = line.lineName, manufacturingTIme = MT.manufacturingTIme, error = MT.error, selectedLine = MT.lineId
                            });
                        }
                    }



                    workbook.Save();
                    workbook.Close(true);
                    application.Quit();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(application);

                    // application.Workbooks.Close();
                    //  workbook.Close(path);


                    TempData["importManufacturingCSV"] = 1;
                    return(View(ErrorListMT));
                }
                else
                {
                    // ViewBag.Error = "File type is incorrect";
                    TempData["ErrorCSV"] = "File type is incorrect";

                    return(RedirectToAction("importManufacturingCSV"));
                }
            }
        }
        public ActionResult newOrder(Order order, int selectedPart)
        {
            int created = 0;

            order.status   = "unscheduled";
            order.priority = 3;



            order.partId = selectedPart;
            if (ModelState.IsValid)
            {
                try
                {
                    created = OrderProcessor.CreateOrder(
                        order.orderId,
                        order.partId,
                        order.projectName,
                        order.lastMaterialDate,
                        order.shipDate,
                        order.quantity);



                    //TempData["newOrderResult"] = created;


                    if (created == 1)
                    {
                        // Schedule object
                        int result = ScheduleController.scheduleOrder(order);
                        if (result == 1)
                        {
                            TempData["newOrderResult"] = 1;
                        }
                        else if (result == -1)
                        {
                            //rollback and remove order
                            OrderProcessor.DeleteOrder(order.orderId);
                            TempData["newOrderResult"] = -1;
                        }
                        else if (result == 0)
                        {
                            TempData["newOrderResult"] = 0;
                        }
                    }



                    return(RedirectToAction("ViewOrders"));
                }
                catch (Exception ex)
                {
                    //  TempData["newOrderResult"] = created;
                    //return RedirectToAction("ViewOrders");
                    return(View(ex.Message));
                }
            }

            ModelState.AddModelError("", "Error");
            List <Part> parts = new List <Part>();
            var         data  = PartProcessor.LoadPart();

            foreach (var row in data)
            {
                parts.Add(new Part
                {
                    partId   = row.partId,
                    partName = row.partName,
                    side     = row.side
                });
            }



            OrderPartViewModel OrderPartViewModel = new OrderPartViewModel();

            OrderPartViewModel.parts = parts;


            return(View(OrderPartViewModel));
        }
        public ActionResult editOrderCSV(Order order)
        {
            //  order.partId = selectedPart;
            //  order.status = selectedStatus;
            //   order.priority = selectedPriority;

            int updated = 0;



            if (ModelState.IsValid)
            {
                try
                {
                    updated = OrderProcessor.updateOrder(order.orderId, order.partId, order.projectName, order.lastMaterialDate, order.shipDate, order.quantity, order.status, order.priority);



                    //TempData["newOrderResult"] = created;


                    if (updated == 1)
                    {
                        TempData["newOrderResult"] = 3;
                    }
                    else if (updated == 0)
                    {
                        TempData["newOrderResult"] = 0;
                    }



                    return(RedirectToAction("reviewOrderCSVPost"));
                }
                catch (Exception ex)
                {
                    //  TempData["newOrderResult"] = created;
                    //eturn View(ex.Message);
                    TempData["newOrderResult"] = 0;

                    return(RedirectToAction("reviewOrderCSVPost"));
                }
            }



            OrderPartViewModel OPViewModel = new OrderPartViewModel();

            List <Part> parts = new List <Part>();
            var         data  = PartProcessor.LoadPart();

            foreach (var row in data)
            {
                parts.Add(new Part
                {
                    partId   = row.partId,
                    partName = row.partName,
                    side     = row.side
                });
            }

            OPViewModel.order = order;

            OPViewModel.parts = parts;

            //  OPViewModel.selectedPart = selectedPart;
            // OPViewModel.selectedStatus = selectedStatus;
            // OPViewModel.selectedPriority = selectedPriority;

            return(View(OPViewModel));
        }