예제 #1
0
        public ActionResult Search(SearchModel model)
        {
            int totalservice = 0;

            using (InhCheckupDataContext cdc = new InhCheckupDataContext())
            {
                totalservice = cdc.vw_patient_corporates
                               .Where(x => (x.companyname == null ? "" : x.companyname) == (model.companyname == null ? "" : model.companyname) &&
                                      x.arrived_date.Value.Date >= model.startdate.Date &&
                                      x.arrived_date.Value.Date <= model.enddate.Date)
                               .Count();
                model.totalservice = totalservice;
            }
            try
            {
                if (model.func == SearchModel.functionCriterias.funcSearch)
                {
                    using (InhCheckupDataContext cdc = new InhCheckupDataContext())
                    {
                        model.dataListCompany = getListCorp();
                        using (DBToDoList.InhToDoListDataContext itc = new DBToDoList.InhToDoListDataContext())
                        {
                            string sub_com = "";
                            if (!string.IsNullOrEmpty(model.companyname))
                            {
                                var doc_no = (from itd in itc.index_trn_company_details
                                              join tcd in itc.trn_company_details
                                              on itd.tcd_id equals tcd.tcd_id
                                              where tcd.tcd_tname == model.companyname
                                              select itd.tcd_document_no).FirstOrDefault();

                                sub_com = (from tcd in itc.trn_company_details
                                           join itd in itc.index_trn_company_details
                                           on tcd.tcd_id equals itd.tcd_id
                                           where tcd.tcd_document_no == doc_no
                                           select tcd.tcd_legal).FirstOrDefault();

                                model.sub_companyname = sub_com;

                                if (!string.IsNullOrEmpty(doc_no))
                                {
                                    List <patient> pt = cdc.trn_patient_book_covers
                                                        .Where(x => x.tcd_document_no == doc_no && x.trn_patient_regi.tpr_arrive_date.Value.Date >= model.startdate.Date &&
                                                               x.trn_patient_regi.tpr_arrive_date.Value.Date <= model.enddate.Date)
                                                        .Select(x => new patient
                                    {
                                        hn   = x.trn_patient_regi.trn_patient.tpt_hn_no,
                                        en   = x.trn_patient_regi.tpr_en_no,
                                        id   = x.trn_patient_regi.trn_patient_book_cover.tpbc_emp_id,
                                        name = x.trn_patient_regi.trn_patient.tpt_othername,
                                        // arrived = x.trn_patient_regi.trn_patient_regis_detail.tpr_real_arrived_date.Value
                                        arrived = cdc.GetArrivedate(x.tpr_id).Value
                                    }).OrderBy(x => x.arrived).ToList();



                                    model.listPatient     = pt;
                                    model.patients        = pt.Count();
                                    model.sub_companyname = sub_com;
                                }
                                else
                                {
                                    model.listPatient     = new List <patient>();
                                    model.patients        = model.listPatient.Count();
                                    model.sub_companyname = sub_com;
                                }
                            }
                            else
                            {
                                model.listPatient     = new List <patient>();
                                model.patients        = model.listPatient.Count();
                                model.sub_companyname = sub_com;
                            }

                            //List<patient> pt = cdc.vw_patient_corporates
                            //                      .Where(x => (x.companyname == null ? "" : x.companyname) == (model.companyname == null ? "" : model.companyname) &&
                            //                                  x.arrived_date.Value.Date >= model.startdate.Date &&
                            //                                  x.arrived_date.Value.Date <= model.enddate.Date)
                            //                      .Select(x => new patient
                            //                      {
                            //                          hn = x.hn,
                            //                          en = x.en,
                            //                          name = x.patient_name,
                            //                          arrived = x.arrived_date.Value
                            //                      }).ToList();
                            //model.listPatient = pt;
                        }
                    }
                }
                else
                {
                    Criterias cModel = new Criterias
                    {
                        companyname     = model.companyname,
                        startdate       = model.startdate,
                        enddate         = model.enddate,
                        patients        = model.patients,
                        totalservice    = model.totalservice,
                        sub_companyname = model.sub_companyname
                    };
                    return(SelectReport(model));
                }
            }
            catch
            {
            }
            return(View("Search", model));
        }