예제 #1
0
        public ActionResult CloseFactory()
        {
            ViewBag.Locations = db.Locations.ToList();
            ReportResultVM factoryvm = new ReportResultVM();

            return(View(factoryvm));
        }
예제 #2
0
        // GET: LabResults/Create
        public ActionResult Create(Guid id) // this is lab report id
        {
            try
            {
                LabReport labReport  = db.LabReports.SingleOrDefault(q => q.Id == id);
                var       categories = db.TestTypes
                                       .Select(q => new TestTypeVM {
                    Id = q.Id, Category = q.Category
                })
                                       .ToList()
                                       .DistinctBy(q => q.Category)
                                       .ToList();
                ReportResultVM reportResultVM = new ReportResultVM
                {
                    LabReport = labReport
                };

                ViewBag.Category        = new SelectList(categories, "Category", "Category");
                ViewBag.TestItem        = new SelectList(db.TestTypes, "Id", "TestItem");
                ViewBag.DefaultCategory = categories.First().Category;

                return(View(reportResultVM));
            }
            catch (Exception e)
            {
                ViewBag.ExceptionMessage = e.Message;
            }
            return(View("~/Views/Errors/Details.cshtml"));
        }
예제 #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        byte[]         bb = new byte[] { 1, 2, 3 };
        ReportResultVM VM = new ReportResultVM();

        VM.ResultState = 1;
        VM.ResultFile  = bb;
        var x = JsonConvert.DeserializeObject <ReportResultVM>(JsonConvert.SerializeObject(VM));

        Response.Write("");
        Response.End();
    }
예제 #4
0
    public string RunTask(string MD5, int ReportCateID, int ReportType, int ApplyType, Dictionary <string, object> dict)
    {
        var data = DoData(ReportType, ApplyType, dict);
        var file = DoExport(ReportType, ApplyType, data);

        //upload data & xls
        var result = new ReportResultVM();

        result.ResultData = data;
        result.ResultFile = file;

        return(JsonConvert.SerializeObject(result));//, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All });
    }
예제 #5
0
        public ActionResult Edit(ReportResultVM reportResultVM, bool add_result)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    TestType testType = db.TestTypes
                                        .Single(q => q.Id == reportResultVM.TestId);

                    string flag = "Normal";
                    if (reportResultVM.Result1 >= testType.MaxReference)
                    {
                        flag = "High";
                    }
                    else if (reportResultVM.Result1 <= testType.MinReference)
                    {
                        flag = "Low";
                    }


                    Result result = new Result
                    {
                        Id        = reportResultVM.Id,
                        TestType  = reportResultVM.TestType,
                        TestId    = reportResultVM.TestId,
                        ReportId  = reportResultVM.ReportId,
                        LabReport = reportResultVM.LabReport,
                        Note      = reportResultVM.Note,
                        Result1   = reportResultVM.Result1,
                        Flag      = flag
                    };

                    db.Entry(result).State = EntityState.Modified;
                    db.SaveChanges();

                    if (add_result)
                    {
                        return(RedirectToAction("Create", new { Id = result.ReportId }));
                    }

                    return(RedirectToAction("Details", "LabReport", new { Id = result.ReportId }));
                }
                return(View(reportResultVM));
            }
            catch (Exception e)
            {
                ViewBag.ExceptionMessage = e.Message;
            }
            return(View("~/Views/Errors/Details.cshtml"));
        }
예제 #6
0
        // GET: LabResults/Edit/5
        public ActionResult Edit(Guid?id)
        {
            try
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                Result result     = db.Results.Find(id);
                var    categories = db.TestTypes
                                    .Select(q => new TestTypeVM {
                    Id = q.Id, Category = q.Category
                })
                                    .ToList()
                                    .DistinctBy(q => q.Category)
                                    .ToList();

                ViewBag.Category = new SelectList(categories, "Category", "Category", result.TestType.Category);
                ViewBag.TestItem = new SelectList(db.TestTypes, "Id", "TestItem", result.TestType.Id);


                ReportResultVM reportResultVM = new ReportResultVM
                {
                    Id        = result.Id,
                    Note      = result.Note,
                    Result1   = result.Result1,
                    TestType  = result.TestType,
                    LabReport = result.LabReport,
                    ReportId  = result.ReportId,
                    TestId    = result.TestId
                };

                if (result == null)
                {
                    return(HttpNotFound());
                }
                return(View(reportResultVM));
            }
            catch (Exception e)
            {
                ViewBag.ExceptionMessage = e.Message;
            }
            return(View("~/Views/Errors/Details.cshtml"));
        }
예제 #7
0
 public ActionResult CloseFactory(ReportResultVM vm)
 {
     try
     {
         var factory = db.Factory11.FirstOrDefault(p => p.Id == vm.FactoryId);
         db.OpenCloseFactories.Add(new OpenCloseFactory()
         {
             Comment = vm.Comment, FactoryId = factory.Id, Opened = false
         });
         factory.Status   = "Closed";
         factory.IsActive = false;
         db.SaveChanges();
         return(RedirectToAction("Home", "Home", new { Id = 1 }));
     }
     catch (Exception ex)
     {
         return(View());
     }
 }
예제 #8
0
        public ActionResult ReportResult(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FactoryEvaluationReport factoryEvaluationReport = db.FactoryEvaluationReports.Find(id);

            if (factoryEvaluationReport == null)
            {
                return(HttpNotFound());
            }
            ReportResultVM vm = new ReportResultVM()
            {
                ReportId = factoryEvaluationReport.ID
            };

            return(View(vm));
        }
예제 #9
0
 public ActionResult ReportResult(ReportResultVM vm)
 {
     try
     {
         if (vm.ReportId == 0)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         FactoryEvaluationReport factoryEvaluationReport = db.FactoryEvaluationReports.Find(vm.ReportId);
         if (factoryEvaluationReport == null)
         {
             return(HttpNotFound());
         }
         db.ReportResults.Add(new ReportResult()
         {
             Comment = vm.Comment, Status = (int)vm.Status == 1, FactoryId = factoryEvaluationReport.FactoryId, FactoryReportId = vm.ReportId
         });
         var factory = db.Factory11.FirstOrDefault(p => p.Id == factoryEvaluationReport.FactoryId);
         if ((int)vm.Status != 1)
         {
             factory.Status   = "Closed";
             factory.IsActive = false;
         }
         else
         {
             factory.Status   = "Opened";
             factory.IsActive = true;
         }
         db.SaveChanges();
         return(RedirectToAction("Home", "Home", new { Id = 1 }));
     }
     catch (Exception ex)
     {
         return(View());
     }
 }
예제 #10
0
    public void Run(ApplyType applyType, string ClassName, string MD5, int ReportCateID, int ReportType, Dictionary <string, object> dict, Action <string> action = null)
    {
        var            request  = HttpContext.Current.Request;
        var            response = HttpContext.Current.Response;
        ReportResultVM result   = new ReportResultVM();

        Task.Factory.StartNew(() =>
        {
            try
            {
                int MyID    = 0;
                bool CanRun = false;
                int Chk     = 0;

                //check seed
                Dictionary <string, object> OutDict = new Dictionary <string, object>()
                {
                    { "@MyID", MyID },
                    { "@CanRun", CanRun },
                    { "@Chk", Chk }
                };

                //var dt = MSDB.GetDataTable("ConnDB", "dbo.usp_ParameterM_xAddOrUpdateDefaultVaccine"
                //                                 , ref OutDict
                //                                 , new Dictionary<string, object>()
                //                                 {
                //                                    { "@MD5", MD5 },
                //                                    { "@OrgID", OrgID },
                //                                    { "@ReportCateID", ReportCateID },
                //                                    //{ "@SeedStorageFileID",0  },
                //                                    //{ "@FruitStorageFileID" ,0 },
                //                                    //{ "@ExcelStorageFileID",0  },
                //                                    { "@ApplyType",applyType },
                //                                    { "@ReportType",1 },
                //                                });

                Chk = (int)OutDict["@Chk"];

                //if(CanRun==true)
                if (true)
                {
                    //upload seed
                    //call WebService
                    //var json = "";
                    //
                    NIIS_Report.WebServiceSoapClient WS = new NIIS_Report.WebServiceSoapClient();
                    var json = WS.SendTask(ClassName, MD5, ReportCateID, ReportType, (int)applyType, JsonConvert.SerializeObject(dict));
                    result   = JsonConvert.DeserializeObject <ReportResultVM>(json, new JsonSerializerSettings {
                        TypeNameHandling = TypeNameHandling.Objects
                    });
                    //result.ResultFile = new byte[] { 1,2,3};
                }
                else
                {
                    //ReportDataVM VM = new ReportDataVM();
                    //EntityS.FillModel(VM,dt);
                    //get ReportResultVM
                }

                switch (applyType)
                {
                case ApplyType.預覽列印:
                    if (action != null)
                    {
                        success = true;
                        //JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All };
                        //string Serialized = JsonConvert.SerializeObject(inheritanceList, settings);
                        action(JsonConvert.SerializeObject(result.ResultData));
                    }
                    break;

                case ApplyType.匯出xls:
                    success = true;
                    //var filePath = Path.Combine(Path.GetDirectoryName(request.PhysicalPath), Path.GetFileNameWithoutExtension(request.PhysicalPath) + ".xlsx");
                    //response.ContentType = "application/download";
                    //response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode("預防接種紀錄表") + Path.GetExtension(filePath));
                    //response.TransmitFile(filePath);
                    //response.End();
                    response.Clear();
                    MemoryStream ms      = new MemoryStream(result.ResultFile);
                    response.ContentType = "application/pdf";
                    response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(result.DisplayFileName));
                    response.Buffer = true;
                    ms.WriteTo(response.OutputStream);
                    response.End();
                    break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
                #if (Debug)
                Console.WriteLine(ex.Message);
                response.Write(ex.Message);
                response.End();
                #endif
            }
        });


        response.BufferOutput = false;
        response.Write("<html><body><div id='fakeLoader'></div>");
        response.Write("<link rel='stylesheet' href='/css/fakeLoader.css'/>");
        response.Write("<script src='/js/jq/jquery-2.1.4.min.js'></script>");
        response.Write("<script src='/js/jq/fakeLoader.min.js'></script>");
        response.Write("<script>$('#fakeLoader').fakeLoader({timeToHide:60000,bgColor:'#f7cecd'});</script>");
        for (int i = 10; i > 0; i--)
        {
            if (success)
            {
                break;
            }
            response.Write("<script>document.getElementById('spnDisp').innerHTML='" + string.Format("倒數 {0} 秒", i) + "';</script>");

            response.Flush();
            Thread.Sleep(1000);
        }
        response.Write("<script>$('#fakeLoader').fadeOut();document.getElementById('spnDisp').innerText='';</script>");
        if (success == false)
        {
            response.Write("<script>alert('運算進行中,請等候通知');</script>");
        }
        //else
        //{
        //    response.Write("<a id='btnGetFile' href='http://www.google.com' target='_blank'></a>");
        //    response.Write("<script>document.getElementById('btnGetFile').click();</script>");
        //}
        response.Write("</body></html>");
    }
예제 #11
0
        public ActionResult Create(ReportResultVM reportResultVM, bool add_result)
        {
            try
            {
                if (ModelState.IsValid && reportResultVM.TestId != Guid.Empty)
                {
                    TestType testType = db.TestTypes
                                        .Single(q => q.Id == reportResultVM.TestId);

                    string flag = "Normal";
                    if (reportResultVM.Result1 >= testType.MaxReference)
                    {
                        flag = "High";
                    }
                    else if (reportResultVM.Result1 <= testType.MinReference)
                    {
                        flag = "Low";
                    }

                    Result result = new Result
                    {
                        Id       = Guid.NewGuid(),
                        Note     = reportResultVM.Note,
                        Result1  = reportResultVM.Result1,
                        ReportId = reportResultVM.Id,
                        TestId   = reportResultVM.TestId,
                        Flag     = flag
                    };

                    db.Results.Add(result);
                    db.SaveChanges();


                    if (add_result)
                    {
                        return(RedirectToAction("Create", new { Id = result.ReportId }));
                    }
                    return(RedirectToAction("Details", "LabReport", new { Id = result.ReportId }));
                }

                ViewBag.ReportId = new SelectList(db.LabReports, "Id", "Status", reportResultVM.ReportId);
                ViewBag.TestId   = new SelectList(db.TestTypes, "Id", "Category", reportResultVM.TestId);

                var categories = db.TestTypes
                                 .Select(q => new TestTypeVM {
                    Id = q.Id, Category = q.Category
                })
                                 .ToList()
                                 .DistinctBy(q => q.Category)
                                 .ToList();
                ViewBag.Category = new SelectList(categories, "Category", "Category");
                ViewBag.TestItem = new SelectList(db.TestTypes, "Id", "TestItem");

                reportResultVM.LabReport = db.LabReports.First(q => q.Id == reportResultVM.Id);
                ViewBag.DropDownError    = "Tested Item is a required field";

                return(View(reportResultVM));
            }
            catch (Exception e)
            {
                ViewBag.ExceptionMessage = e.Message;
            }
            return(View("~/Views/Errors/Details.cshtml"));
        }