Exemplo n.º 1
0
        public AssayBill AddAssayBillWithSave(Assay oldAssay, int user_id, string billIndex, Contract cont,
                                              IList <GrainQualityIndex> GrainQualityIndexList, List <string> resultList)
        {
            //新增一个SampleDetail
            SampleDetail newSampleDetail = new SampleDetail();

            newSampleDetail.sample_number        = oldAssay.sample_number;
            newSampleDetail.sample_detail_number = oldAssay.sample_number + billIndex;
            newSampleDetail.saved = oldAssay.Sample.sample_saved;
            _unitOfWork.AddAction(newSampleDetail, DataActions.Add);

            //AssayBill新增
            AssayBill newAssayBill = new AssayBill();

            newAssayBill.assay_bill_number = oldAssay.assay_number + billIndex;
            newAssayBill.assay_number      = oldAssay.assay_number;
            newAssayBill.assay_time        = oldAssay.create_time.Value;
            newAssayBill.assay_user        = user_id;
            newAssayBill.sample_detail     = newSampleDetail.sample_detail_number;
            _unitOfWork.AddAction(newAssayBill, DataActions.Add);

            AddAssayResultWithUnitOfWork(newAssayBill, cont, GrainQualityIndexList, resultList);

            _unitOfWork.Save();
            return(newAssayBill);
        }
Exemplo n.º 2
0
        public bool Update(Sample items)
        {
            bool result = false;

            try
            {
                context.Entry(items).State = EntityState.Modified;
                context.SaveChanges();

                foreach (var row in items.Details)
                {
                    var details = new SampleDetail();

                    details.SampleId    = row.SampleId;
                    details.ProductCode = row.ProductCode;
                    details.Quantity    = row.Quantity;
                    details.User        = row.User;
                    details.DateCreated = DateTime.Now.ToString("dd/MM/yyyy hh:mm");
                    details.Value1      = row.Value1;
                    details.Value2      = row.Value2;
                    details.Value3      = row.Value3;
                    details.Value4      = row.Value4;
                    details.Value5      = row.Value5;
                    //esta variable determina la accion a ejecutar en el registro
                    //null or empty  = Nothing
                    //            1  = Add
                    //            2  = Update
                    //            3  = Delete

                    int status = (string.IsNullOrEmpty(row.Value1)) ? 0 : int.Parse(row.Value1);

                    switch (status)
                    {
                    case 1:
                        AddDetail(details);
                        break;

                    case 2:
                        details.Id = row.Id;
                        UpdateDetail(details);
                        break;

                    case 3:
                        details.Id = row.Id;
                        DeleteDetail(details);
                        break;
                    }
                }
                result = true;
            }
            catch (Exception ex)
            {
                result = false;
                Debug.Write(@"Error " + ex.Message);
            }
            return(result);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Details(int sampleDetailId)
        {
            SampleDetail foundSampleDetail = await factory.Samples.GetSampleDetailFromSampleDetailID(sampleDetailId);

            if (foundSampleDetail == null)
            {
                return(NotFound());
            }

            return(View(foundSampleDetail));
        }
Exemplo n.º 4
0
 private void UpdateDetail(SampleDetail detail)
 {
     try
     {
         context.Entry(detail).State = EntityState.Modified;
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 5
0
 private void DeleteDetail(SampleDetail detail)
 {
     try
     {
         context.SampleDetails.Remove(detail);
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 6
0
 private void AddDetail(SampleDetail detail)
 {
     try
     {
         context.SampleDetails.Add(detail);
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 7
0
        public async Task <SampleDetail> GetSampleDetailAsync(string sampleId, EntityHeader org, EntityHeader user)
        {
            var sample = await _sampleRepo.GetSampleAsync(sampleId, org.Id);

            var labels = await _labelSampleRepo.GetLabelsForSampleAsync(sampleId);

            var detail = SampleDetail.FromSample(sample);

            detail.Labels = new List <EntityHeader>(labels.Select(lbl => EntityHeader.Create(lbl.LabelId, lbl.Label)));
            await AuthorizeAsync(detail, AuthorizeResult.AuthorizeActions.Read, user, org);

            return(detail);
        }
Exemplo n.º 8
0
        private void addDetail(int detailKey, int sampleKey)
        {
            var detailText = "Detail" + sampleKey + '.' + detailKey;

            expectedData !.Details.Add(detailKey, detailText);
            var sample = DC.Data.SampleX[sampleKey];
            var detail = new SampleDetail(detailText, sample, false);

            detail.Store();
            expectedData !.Samples.Remove(sampleKey);
            expectedData !.Samples.Add(sampleKey, sample.ToString());
            assertData();
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Edit(int sampleDetailId)
        {
            ViewBag.Error        = false;
            ViewBag.ErrorMessage = "";

            SampleDetail editSampleDetail = await factory.Samples.GetSampleDetailFromSampleDetailID(sampleDetailId);

            if (editSampleDetail == null)
            {
                return(NotFound());
            }

            return(View("CreateOrUpdate", editSampleDetail));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Save(SampleDetail sampleDetail)
        {
            ViewBag.Error = true;
            string errorMessage = string.Empty;

            if (!ModelState.IsValid)
            {
                foreach (var key in ModelState.Keys)
                {
                    var modelStateVal = ModelState[key];
                    foreach (var error in modelStateVal.Errors)
                    {
                        errorMessage += error.ErrorMessage + "<br>";
                    }
                }

                ViewBag.ErrorMessage = errorMessage;

                return(View("CreateOrUpdate"));
            }

            if (sampleDetail.SampleDetailID == 0)
            {
                if (!(User.IsInRole("Sample", AuthType.Add)))
                {
                    return(Unauthorized());
                }

                await factory.Samples.AddSampleDetail(sampleDetail, int.Parse(User.Identity.Name));
            }
            else
            {
                if (!(User.IsInRole("Sample", AuthType.Update)))
                {
                    return(Unauthorized());
                }

                var foundSampleDetails = await factory.Samples.GetSampleDetailFromSampleDetailID(sampleDetail.SampleDetailID);

                foundSampleDetails.Meter    = sampleDetail.Meter;
                foundSampleDetails.DateTime = sampleDetail.DateTime;
                foundSampleDetails.Details  = sampleDetail.Details;

                await factory.Samples.UpdateSampleDetail(foundSampleDetails, int.Parse(User.Identity.Name));
            }

            return(RedirectToAction("Index", new { sampleDetail.RuloID, sampleDetail.SampleID }));
        }
Exemplo n.º 11
0
        public int Save(Sample items)
        {
            int id = 0;

            try
            {
                var user = items.User;
                items.DateCreated = DateTime.Now.ToString("dd/MM/yyyy hh:mm");
                context.Samples.Add(items);
                context.SaveChanges();

                id = items.Id;

                if (id > 0)
                {
                    var detail = new SampleDetail();
                    foreach (var row in items.Details)
                    {
                        detail.SampleId    = id;
                        detail.ProductCode = row.ProductCode;
                        detail.Quantity    = row.Quantity;
                        detail.User        = user;
                        detail.DateCreated = row.DateCreated;
                        detail.Value1      = row.Value1;
                        detail.Value2      = row.Value2;
                        detail.Value3      = row.Value3;
                        detail.Value4      = row.Value4;
                        detail.Value5      = row.Value5;

                        context.SampleDetails.Add(detail);
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                id = 0;
                Debug.Write(@"Error " + ex.Message);
            }
            return(id);
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Create(int sampleId)
        {
            ViewBag.Error        = false;
            ViewBag.ErrorMessage = "";

            var sample = await factory.Samples.GetSampleFromSampleID(sampleId);

            if (sample == null)
            {
                NotFound();
            }

            SampleDetail newSampleDetail = new SampleDetail();

            newSampleDetail.SampleID      = sample.SampleID;
            newSampleDetail.RuloID        = sample.RuloID;
            newSampleDetail.RuloProcessID = sample.RuloProcessID;
            newSampleDetail.DateTime      = DateTime.Now;

            return(View("CreateOrUpdate", newSampleDetail));
        }
Exemplo n.º 13
0
        public Assay AddAssayWithUnitOfWork(Sample newSample, SampleDetail newSampleDetail, int user_id, Contract cont,
                                            IList <GrainQualityIndex> GrainQualityIndexList, List <string> resultList,
                                            AssayStatus status, string AssayBillIndex, OrganizationDepartment org, int gradeID)
        {
            Assay newAssay = new Assay();
            int   billID   = _sysBillNoService.GetBillNoID("QUM", "ASN");

            newAssay.assay_number = _sysBillNoService.GetBillNo(billID);
            //newAssay.assay_result = null;
            //newAssay.bill_owner_org = 1;
            //newAssay.confirm_time = null;
            newAssay.confirm_user  = user_id;
            newAssay.create_time   = _sPGetSysDateTimeService.GetSysDateTime();
            newAssay.grain_grade   = gradeID;
            newAssay.remark        = "";
            newAssay.sample_number = newSample.sample_number;
            newAssay.status        = (int)status;
            _unitOfWork.AddAction(newAssay, DataActions.Add);

            AddAssayBillWithUnitOfWork(newAssay, user_id, newSampleDetail, cont, GrainQualityIndexList, resultList, AssayBillIndex);
            //newAssay.grain_grade = JudgeGrainGrade(newAssay.AssayBills.First().AssayResults,
            return(newAssay);
        }
Exemplo n.º 14
0
        public void AddAssayBillWithUnitOfWork(Assay newAssay, int user_id, SampleDetail newSampleDetail, Contract cont,
                                               IList <GrainQualityIndex> GrainQualityIndexList, List <string> resultList, string AssayBillIndex)
        {
            //AssayBill新增
            AssayBill newAssayBill = new AssayBill();

            if (AssayBillIndex == string.Empty)
            {
                int billNumberIndex = 1;
                if (newAssay != null && newAssay.AssayBills != null && newAssay.AssayBills.Count != 0)
                {
                    billNumberIndex = newAssay.AssayBills.Count + 1;
                }
                AssayBillIndex = billNumberIndex.ToString("D2");
            }
            newAssayBill.assay_bill_number = newAssay.assay_number + AssayBillIndex;
            newAssayBill.assay_number      = newAssay.assay_number;
            newAssayBill.assay_time        = newAssay.create_time.Value;
            newAssayBill.assay_user        = user_id;
            newAssayBill.sample_detail     = newSampleDetail.sample_detail_number;
            _unitOfWork.AddAction(newAssayBill, DataActions.Add);

            AddAssayResultWithUnitOfWork(newAssayBill, cont, GrainQualityIndexList, resultList);
        }
Exemplo n.º 15
0
 public abstract Task DeleteSampleDetail(SampleDetail sampleDetail, int deleterRef);
Exemplo n.º 16
0
 public override async Task AddSampleDetail(SampleDetail sampleDetail, int adderRef)
 {
     await repositorySampleDetail.Add(sampleDetail, adderRef);
 }
Exemplo n.º 17
0
 public override async Task DeleteSampleDetail(SampleDetail sampleDetail, int deleterRef)
 {
     await repositorySampleDetail.Remove(sampleDetail.SampleDetailID, deleterRef);
 }
Exemplo n.º 18
0
 public override async Task UpdateSampleDetail(SampleDetail sampleDetail, int updaterRef)
 {
     await repositorySampleDetail.Update(sampleDetail, updaterRef);
 }
Exemplo n.º 19
0
 public abstract Task UpdateSampleDetail(SampleDetail sampleDetail, int updaterRef);
Exemplo n.º 20
0
 public abstract Task AddSampleDetail(SampleDetail sampleDetail, int adderRef);