Exemple #1
0
        //public ActionResult Delete(int id)
        //{
        //    rpproduct.Delete(id);
        //    return RedirectToAction("Index");
        //}

        public ActionResult BarCode(int id)
        {
            var    product   = rpproduct.Find(id);
            string trademark = rptrademark.Find(product.TradeMarkID).Name;
            string promodel  = rpproductmodel.Find(product.ProductModelID).Name;

            barcodecs objbar = new barcodecs();

            byte[]       url   = objbar.getBarcodeImage(product.SerialNumber, trademark + " " + promodel);
            BarCodeModel model = new BarCodeModel();

            model.ImageUrl = "data:image/jpg;base64," + Convert.ToBase64String((byte[])url);

            return(View(model));
        }
        public ActionResult Create([Bind(Include = "Cost,NoofSamples,ClientId,CompletionDate,SampleTypeId,RequiredDate,SubmitDate")] Request request) //WorkorderNo,SampleFirstNo,SampleLastNo,
        {
            if (ModelState.IsValid)
            {
                //var manager = new UserManager<ApplicationUser>(new Microsoft.AspNet.Identity.EntityFramework.UserStore<ApplicationUser>(new ApplicationDbContext()));
                //var currentUser = manager.FindById(User.Identity.GetUserId());
                ////barcodecs objbar = new barcodecs();

                //if (currentUser != null)
                //    request.createdBy = currentUser.UserName;
                //else
                //    request.createdBy = User.Identity.Name;

                //request.createdDate = DateTime.Now;



                request.WorkorderNo   = 2017153;
                request.SampleFirstNo = 201706032;
                request.SampleLastNo  = 201706033;

                var worder = db.Request.Select(x => x.WorkorderNo).FirstOrDefault();
                if (worder != 0)
                {
                    var lastWorkOrder = db.Request.Select(x => x.WorkorderNo).Max();
                    request.WorkorderNo = lastWorkOrder + 1;

                    var lstSamplelastNo  = db.Request.Select(x => x.SampleLastNo).Max();
                    var toAdd            = request.NoofSamples;
                    var newSampleFirstNo = lstSamplelastNo + 1;
                    var newSampleLastNo  = lstSamplelastNo + toAdd;

                    request.SampleFirstNo = newSampleFirstNo;
                    request.SampleLastNo  = newSampleLastNo;
                }

                db.Request.Add(request);
                db.SaveChanges();

                //get the total cost



                // filter the test to pick based on type
                var rId   = request.SampleTypeId;
                var ttype = db.SampleType.Where(x => x.Id == rId).Select(x => x.TestType_Id).FirstOrDefault();

                TempData["ttype"] = ttype;


                var varId = db.Request.Where(x => x.SampleLastNo == request.SampleLastNo).Select(x => x.ID).FirstOrDefault();
                TempData["reqId"] = varId;
                barcodecs objbar = new barcodecs();
                Sample    sample = new Sample();


                for (int i = request.SampleFirstNo; i <= request.SampleLastNo; i++)
                {
                    sample.SampleNo        = i;
                    sample.Barcode         = objbar.generateBarcode(request.WorkorderNo.ToString().Substring(4), i.ToString().Substring(4));
                    sample.BarcodeImageUrl = objbar.getBarcodeImage(sample.Barcode, request.WorkorderNo.ToString().Substring(4) + i.ToString().Substring(4));
                    sample.RequestID       = varId;
                    db.Sample.Add(sample);
                    db.SaveChanges();
                }



                return(RedirectToAction("Index", "TestCheck"));
            }

            ViewBag.ClientId     = new SelectList(db.Client, "Id", "Name", request.ClientId);
            ViewBag.SampleTypeId = new SelectList(db.SampleType, "Id", "Id", request.SampleTypeId);
            return(View(request));
        }