Exemplo n.º 1
0
        public JsonResult Delete(int id)
        {
            ResponeModel response = new ResponeModel(true);

            Context.MasterProduct dbItem = RepoProduct.FindByPK(id);

            RepoProduct.delete(dbItem);

            return(Json(response));
        }
Exemplo n.º 2
0
 public void setDb(Context.MasterProduct dbitem)
 {
     dbitem.Id         = Id;
     dbitem.NamaProduk = NamaProduk;
     dbitem.IdKategori = IdKategori.Value;
     dbitem.TargetSuhu = TargetSuhu.Value;
     dbitem.MaxTemps   = MaxTemps.Value;
     dbitem.MinTemps   = MinTemps.Value;
     dbitem.Treshold   = Treshold.Value;
     dbitem.Remarks    = Remarks;
 }
Exemplo n.º 3
0
 public Product(Context.MasterProduct dbitem)
 {
     Id         = dbitem.Id;
     NamaProduk = dbitem.NamaProduk;
     IdKategori = dbitem.IdKategori;
     Kategori   = dbitem.LookupCode.Nama;
     TargetSuhu = dbitem.TargetSuhu;
     MaxTemps   = dbitem.MaxTemps;
     MinTemps   = dbitem.MinTemps;
     Treshold   = dbitem.Treshold;
     Remarks    = dbitem.Remarks;
 }
Exemplo n.º 4
0
        public ActionResult Add(Product model)
        {
            if (ModelState.IsValid)
            {
                bool NamaProdukexist = RepoProduct.IsExist(model.NamaProduk);

                if (NamaProdukexist)
                {
                    ModelState.AddModelError("NamaProduk", "Nama Produk sudah terdaftar !");
                    return(View("Form", model));
                }

                Context.MasterProduct dbitem = new Context.MasterProduct();
                model.setDb(dbitem);
                RepoProduct.save(dbitem);

                return(RedirectToAction("Index"));
            }
            return(View("Form", model));
        }
Exemplo n.º 5
0
        public string UploadProduct(IEnumerable <HttpPostedFileBase> filesProduct)
        {
            ResponeModel response = new ResponeModel();

            //algoritma
            if (filesProduct != null)
            {
                foreach (var file in filesProduct)
                {
                    try
                    {
                        using (var package = new ExcelPackage(file.InputStream))
                        {
                            var currentSheet = package.Workbook.Worksheets;
                            var workSheet    = currentSheet.First();
                            var noOfRow      = workSheet.Dimension.End.Row;

                            for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                            {
                                if (workSheet.Cells[rowIterator, 1].Value != null && workSheet.Cells[rowIterator, 2].Value != null && workSheet.Cells[rowIterator, 3].Value != null &&
                                    workSheet.Cells[rowIterator, 4].Value != null && workSheet.Cells[rowIterator, 5].Value != null && workSheet.Cells[rowIterator, 6].Value != null &&
                                    decimal.Parse(workSheet.Cells[rowIterator, 3].Value.ToString()) >= -30 && decimal.Parse(workSheet.Cells[rowIterator, 3].Value.ToString()) <= 30 &&
                                    decimal.Parse(workSheet.Cells[rowIterator, 4].Value.ToString()) >= -30 && decimal.Parse(workSheet.Cells[rowIterator, 4].Value.ToString()) <= 30 &&
                                    decimal.Parse(workSheet.Cells[rowIterator, 5].Value.ToString()) >= -30 && decimal.Parse(workSheet.Cells[rowIterator, 5].Value.ToString()) <= 30)
                                {
                                    int id = 0;

                                    int resId;
                                    if (workSheet.Cells[rowIterator, 8].Value != null)
                                    {
                                        if (int.TryParse(workSheet.Cells[rowIterator, 8].Value.ToString(), out resId))
                                        {
                                            id = resId;
                                        }
                                    }

                                    //cara gancang ngarah teu kudu aya pengecekan tiap field
                                    Context.MasterProduct dbitem = new Context.MasterProduct();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            dbitem = RepoProduct.FindByPK(id);
                                            if (RepoProduct.IsExist(workSheet.Cells[rowIterator, 1].Value.ToString(), id))
                                            {
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            if (RepoProduct.IsExist(workSheet.Cells[rowIterator, 1].Value.ToString()))
                                            {
                                                continue;
                                            }
                                        }


                                        dbitem.NamaProduk = workSheet.Cells[rowIterator, 1].Value.ToString();
                                        dbitem.IdKategori = RepoLookup.FindByName(workSheet.Cells[rowIterator, 2].Value.ToString()).Id;
                                        dbitem.TargetSuhu = decimal.Parse(workSheet.Cells[rowIterator, 3].Value.ToString());
                                        dbitem.MaxTemps   = decimal.Parse(workSheet.Cells[rowIterator, 4].Value.ToString());
                                        dbitem.MinTemps   = decimal.Parse(workSheet.Cells[rowIterator, 5].Value.ToString());
                                        dbitem.Treshold   = int.Parse(workSheet.Cells[rowIterator, 6].Value.ToString());
                                        dbitem.Remarks    = workSheet.Cells[rowIterator, 7].Value == null ? "" : workSheet.Cells[rowIterator, 7].Value.ToString();

                                        RepoProduct.save(dbitem);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }

            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }