Example #1
0
    protected void SetAttr(DataTable dt)
    {
        if (dt.Rows.Count > 0)
        {
            int iGender, iONationality, iImmiType
            , iConCounty, iConTown, iConVillage, iConNei
            , iResCounty, iResTown, iResVillage, iResNei
            , iPregWeek, iBirthNum, iBirthSeq, iBirthWeight
            , iBirthPlace, iDeliver, iBirthMulti
            , iRegionID, iMainContactCaseID;



            CaseID     = Convert.ToInt32(dt.Rows[0]["CaseID"]);
            BirthDate  = dt.Rows[0]["BirthDateSimple"].ToString();
            IdNo       = dt.Rows[0]["IdNo"].ToString();
            PassportNo = dt.Rows[0]["PassportNo"].ToString();
            ResNo      = dt.Rows[0]["ResNo"].ToString();
            OtherNo    = dt.Rows[0]["OtherNo"].ToString();
            ChName     = dt.Rows[0]["ChName"].ToString();
            EnName     = dt.Rows[0]["EnName"].ToString();
            HouseNo    = dt.Rows[0]["HouseNo"].ToString();
            Language   = dt.Rows[0]["Language"].ToString().Split(',');
            foreach (string s in Language)
            {
                if (s != "")
                {
                    LanguageName += SystemCode.GetName("CaseUser_Language", Convert.ToInt32(s)) + ",";
                }
            }

            LanguageName = (LanguageName != null ? LanguageName.TrimEnd(',') : "");

            Capacity = dt.Rows[0]["Capacity"].ToString().Split(',');
            foreach (string s in Capacity)
            {
                if (s != "")
                {
                    CapacityName += SystemCode.GetName("CaseUser_Capacity", Convert.ToInt32(s)) + ",";
                }
            }
            CapacityName = (CapacityName != null ? CapacityName.TrimEnd(',') : "");



            TelDayArea   = dt.Rows[0]["TelDayArea"].ToString();
            TelDayNo     = dt.Rows[0]["TelDayNo"].ToString();
            TelDayExt    = dt.Rows[0]["TelDayExt"].ToString();
            TelNightArea = dt.Rows[0]["TelNightArea"].ToString();
            TelNightNo   = dt.Rows[0]["TelNightNo"].ToString();
            TelNightExt  = dt.Rows[0]["TelNightExt"].ToString();
            ConAddr      = dt.Rows[0]["ConAddr"].ToString();
            ResAddr      = dt.Rows[0]["ResAddr"].ToString();

            DeliverOrg  = dt.Rows[0]["DeliverOrg"].ToString();
            MarryStatus = dt.Rows[0]["MarryStatus"].ToString();
            ElemSchool  = dt.Rows[0]["ElemSchool"].ToString();
            Occupation  = dt.Rows[0]["Occupation"].ToString();
            EduLevel    = dt.Rows[0]["EduLevel"].ToString();

            BirthPlaceOther = dt.Rows[0]["BirthPlaceOther"].ToString();

            int.TryParse(dt.Rows[0]["ONationality"].ToString(), out iONationality);
            int.TryParse(dt.Rows[0]["ImmiType"].ToString(), out iImmiType);
            int.TryParse(dt.Rows[0]["Gender"].ToString(), out iGender);

            int.TryParse(dt.Rows[0]["ConCounty"].ToString(), out iConCounty);
            int.TryParse(dt.Rows[0]["ConTown"].ToString(), out iConTown);
            int.TryParse(dt.Rows[0]["ConVillage"].ToString(), out iConVillage);
            int.TryParse(dt.Rows[0]["ConNei"].ToString(), out iConNei);

            int.TryParse(dt.Rows[0]["ResCounty"].ToString(), out iResCounty);
            int.TryParse(dt.Rows[0]["ResTown"].ToString(), out iResTown);
            int.TryParse(dt.Rows[0]["ResVillage"].ToString(), out iResVillage);
            int.TryParse(dt.Rows[0]["ResNei"].ToString(), out iResNei);

            int.TryParse(dt.Rows[0]["PregWeek"].ToString(), out iPregWeek);
            int.TryParse(dt.Rows[0]["BirthNum"].ToString(), out iBirthNum);
            int.TryParse(dt.Rows[0]["BirthSeq"].ToString(), out iBirthSeq);
            int.TryParse(dt.Rows[0]["BirthWeight"].ToString(), out iBirthWeight);
            int.TryParse(dt.Rows[0]["BirthPlace"].ToString(), out iBirthPlace);
            int.TryParse(dt.Rows[0]["Deliver"].ToString(), out iDeliver);
            int.TryParse(dt.Rows[0]["BirthMulti"].ToString(), out iBirthMulti);
            int.TryParse(dt.Rows[0]["RegionID"].ToString(), out iRegionID);
            int.TryParse(dt.Rows[0]["MainContactID"].ToString(), out iMainContactCaseID);


            ONationality = iONationality;
            ImmiType     = iImmiType;
            Gender       = iGender;

            ConCounty  = iConCounty;
            ConTown    = iConTown;
            ConVillage = iConVillage;
            ConNei     = iConNei;

            ResCounty  = iResCounty;
            ResTown    = iResTown;
            ResVillage = iResVillage;
            ResNei     = iResNei;


            PregWeek          = iPregWeek;
            BirthNum          = iBirthNum;
            BirthSeq          = iBirthSeq;
            BirthWeight       = iBirthWeight;
            BirthPlace        = iBirthPlace;
            Deliver           = iDeliver;
            BirthMulti        = iBirthMulti;
            RegionID          = iRegionID;
            MainContactCaseID = iMainContactCaseID;

            //    RegionName = dt.Rows[0]["RegionName"].ToString();
            // SystemRegion.Update();
            RegionName     = SystemRegion.GetName(RegionID);
            ImmiTypeName   = SystemCode.GetName("CaseUser_ImmiType", ImmiType);
            GenderName     = SystemCode.GetName("CaseUser_Gender", Gender);
            ConCountyName  = SystemAreaCode.GetName(ConCounty);
            ConTownName    = SystemAreaCode.GetName(ConTown);
            ConVillageName = SystemAreaCode.GetName(ConVillage);
            ResCountyName  = SystemAreaCode.GetName(ResCounty);
            ResTownName    = SystemAreaCode.GetName(ResTown);
            ResVillageName = SystemAreaCode.GetName(ResVillage);



            if (dt.Columns.Contains("CreateInfo"))
            {
                CreateInfo = dt.Rows[0]["CreateInfo"].ToString();
            }
            if (dt.Columns.Contains("ModifyInfo"))
            {
                ModifyInfo = dt.Rows[0]["ModifyInfo"].ToString();
            }



            if (dt.Columns.Contains("MotherName"))
            {
                MotherName = dt.Rows[0]["MotherName"].ToString();
            }
            if (dt.Columns.Contains("MotherIdNo"))
            {
                MotherIdNo = dt.Rows[0]["MotherIdNo"].ToString();
            }
            if (dt.Columns.Contains("MotherBirthDateSimple"))
            {
                MotherBirthDate = dt.Rows[0]["MotherBirthDateSimple"].ToString();
            }



            GetMobiles();
            GetEmails();



            try
            {
                AgeCalculatorT AgeCal = new AgeCalculatorT();
                DateTime       b      = new DateTime();
                DateTime.TryParse(dt.Rows[0]["BirthDate"].ToString(), out b);
                AgeTip = AgeCal.GetAge(b);
            }
            catch
            {
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        base.AllowHttpMethod("POST");
        base.DisableTop(false);
        base.BodyClass = "class='bodybg'";

        int.TryParse(Request["I"], out CaseUserID);


        if (CaseUserID == 0)
        {
            string script = "<script>alert('資料取得失敗');history.go(-1);</script>";
            Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "alert", script, false);
            return;
        }

        var user = AuthServer.GetLoginUser();

        OrgName = user.OrgName;

        DataTable dt          = new DataTable();
        int       YCardMainID = 0;

        using (SqlConnection sc = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnDB"].ToString()))
        {
            using (SqlCommand cmd = new SqlCommand("dbo.usp_RecordM_xGetCaseUserByIDAndGetOrAddYCardMain", sc))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@CaseUserID", CaseUserID);
                SqlParameter sp = cmd.Parameters.AddWithValue("@YCardMainID", YCardMainID);
                sp.Direction = ParameterDirection.Output;
                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                {
                    sc.Open();
                    da.Fill(dt);
                    YCardMainID = (int)sp.Value;
                }
            }
        }


        CaseUserVM VM = new CaseUserVM();

        EntityS.FillModel(VM, dt);

        //if(ds.Tables[1].Rows.Count>0)
        //    YCardMainID = (int)ds.Tables[1].Rows[0][0];



        uJson = JsonConvert.SerializeObject(VM);

        AgeCalculatorT AT = new AgeCalculatorT();

        AgeString = AT.GetAge(VM.BirthDate);


        DateTime birthDate = VM.BirthDate;

        dt = new DataTable();

        using (SqlConnection sc = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnDB"].ToString()))
        {
            using (SqlCommand cmd = new SqlCommand("dbo.usp_RecordM_xGetRecordDataByCaseUserID", sc))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@CaseUserID", CaseUserID);
                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                {
                    sc.Open();
                    da.Fill(dt);
                }
            }
        }

        List <RecordDataVM> list = new List <RecordDataVM>();

        //List<RecordYellowDataVM> yellowList = new List<RecordYellowDataVM>();
        List <SystemYCardVM> yellowList = SystemYCard.GetDict(YCardMainID);
        var x = SystemYCard.dict;
        List <RecordUserDataVM> userList = new List <RecordUserDataVM>();

        //List<RecordYellowDataVM> yellowRemoveList = new List<RecordYellowDataVM>();
        List <RecordUserDataVM> userRemoveList = new List <RecordUserDataVM>();

        EntityS.FillModel(userList, dt);

        //EntityS.FillModel(yellowList, ds.Tables[0]);
        //EntityS.FillModel(userList, ds.Tables[1]);

        //var userVaccineCodes =userList.Select(item => item.SystemRecordVaccineCode).ToList();
        //var DoseIDs = yellowList.Select(item => item.DoseID).ToList();



        foreach (var yellow in yellowList)
        {
            var queryList = userList.FindAll(item => item.SystemRecordVaccineCode.Equals(yellow.DoseID));

            if (queryList.Count > 0)
            {
                foreach (var q in queryList)
                {
                    //yellowRemoveList.Add(yellow);
                    userRemoveList.Add(q);
                    RecordDataVM rVM = new RecordDataVM(birthDate);
                    rVM.InoculationDate       = q.InoculationDate;
                    rVM.IsRule                = true;
                    rVM.OrgID                 = q.OrgID;
                    rVM.VaccineBatchID        = q.VaccineBatchID;
                    rVM.SystemRecordVaccineID = q.SystemRecordVaccineID;
                    rVM.AgeEngilsh            = yellow.AgeEngilsh;
                    rVM.DoseID                = yellow.DoseID;
                    rVM.Period                = yellow.Period;
                    rVM.CreatedDate           = q.CreatedDate;
                    rVM.CreateType            = q.CreateType;
                    //rVM.ColorType = 1;
                    rVM.RecordDataID = q.RecordDataID;

                    if (rVM.InoculationDate == null || DateTime.Equals(rVM.InoculationDate, new DateTime(2099, 1, 1, 1, 1, 1, 0)))
                    {
                        rVM.OrgID       = 0;
                        rVM.ColorType   = 0;
                        rVM.CreatedDate = null;
                    }
                    else if (rVM.AppointmentDate != null && DateTime.Equals(rVM.InoculationDate, new DateTime(2099, 1, 1, 1, 1, 1, 0)) == false)
                    {
                        if (DateTime.Compare(rVM.InoculationDate.Value, rVM.AppointmentDate.Value.AddDays(90)) > 0)
                        {
                            rVM.ColorType = 1;
                        }
                    }

                    list.Add(rVM);
                }
            }
            else
            {
                RecordDataVM rVM = new RecordDataVM(birthDate);
                rVM.IsRule     = true;
                rVM.AgeEngilsh = yellow.AgeEngilsh;
                rVM.DoseID     = yellow.DoseID;
                //rVM.SystemRecordVaccineID = SystemRecordVaccine.GetID(yellow.DoseID);
                rVM.Period    = yellow.Period;
                rVM.ColorType = 0;
                list.Add(rVM);
            }
        }

        //yellowList.RemoveAll(item => yellowRemoveList.Contains(item));

        userList.RemoveAll(item => userRemoveList.Contains(item));

        list.OrderBy(item => item.AppointmentDate).ThenBy(item => item.Period).ThenBy(item => item.DoseID);

        foreach (var u in userList)
        {
            RecordDataVM rVM = new RecordDataVM(birthDate);
            rVM.InoculationDate       = u.InoculationDate;
            rVM.IsRule                = false;
            rVM.OrgID                 = u.OrgID;
            rVM.VaccineBatchID        = u.VaccineBatchID;
            rVM.SystemRecordVaccineID = u.SystemRecordVaccineID;
            rVM.RecordDataID          = u.RecordDataID;

            if (rVM.InoculationDate == null || DateTime.Equals(rVM.InoculationDate, new DateTime(2099, 1, 1, 1, 1, 1, 0)))
            {
                rVM.OrgID       = 0;
                rVM.CreatedDate = null;
            }

            //list.Add(VM);
            //find last InoculationDate
            var index = list.FindLastIndex(item => item.InoculationDateOut != null);
            if (index >= 0)
            {
                if (index + 1 <= list.Count)
                {
                    list.Insert(index + 1, rVM);
                }
                else
                {
                    list.Add(rVM);
                }
            }
            else
            {
                list.Insert(0, rVM);
            }
        }


        if (list.Count > 0)
        {
            tbAry = JsonConvert.SerializeObject(list);
        }
    }
    protected new void Page_Load(object sender, EventArgs e)
    {
        base.AllowHttpMethod("POST");
        base.DisableTop(false);

        CaseUserID = GetNumber <int>("i");

        if (CaseUserID == 0)
        {
            string script = "<style>body{disply:none;}</style><script>alert('資料取得失敗');history.go(-1);</script>";
            Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "alert", script, false);
            return;
        }

        ucCaseRemark1.CaseID = CaseUserID;
        var user = AuthServer.GetLoginUser();

        OrgName = user.OrgName;

        DataTable dt          = new DataTable();
        int       YCardMainID = 0;
        int       DeltaDays   = 0;
        Dictionary <string, object> OutDict = new Dictionary <string, object>()
        {
            { "@YCardMainID", YCardMainID },
            { "@DeltaDays", DeltaDays }
        };

        DataSet ds = MSDB.GetDataSet("ConnDB", "dbo.usp_RecordM_xGetCaseUserByIDAndGetOrAddYCardMain"
                                     , ref OutDict
                                     , new Dictionary <string, object>()
        {
            { "@CaseUserID", CaseUserID }
        });

        YCardMainID = (int)OutDict["@YCardMainID"];
        DeltaDays   = (int)OutDict["@DeltaDays"];

        List <RegisterStoolCardVM> scList = new List <RegisterStoolCardVM>();
        List <RegisterFluNotesVM>  fnList = new List <RegisterFluNotesVM>();
        string CapacityIDs = "";

        EntityS.FillModel(VM, ds.Tables[0]);
        if (ds.Tables[2].Rows.Count > 0)
        {
            EntityS.FillModel(VM, ds.Tables[2]);
            VM.HasYellowCardMessage = true;
        }
        EntityS.FillModel(scList, ds.Tables[3]);
        EntityS.FillModel(fnList, ds.Tables[4]);

        if (ds.Tables[1].Rows.Count > 0)
        {
            CapacityIDs = ds.Tables[1].Rows[0][0].ToString();
        }

        if (scList.Count > 0)
        {
            scAry = JsonConvert.SerializeObject(scList);
        }

        if (fnList.Count > 0)
        {
            fnAry = JsonConvert.SerializeObject(fnList);
        }

        List <string> CapacityList = new List <string>();

        foreach (var item in CapacityIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
        {
            CapacityList.Add(SystemCode.GetName("CaseUser_Capacity", int.Parse(item)));
        }

        CapacityString = string.Join(",", CapacityList.ToArray());

        //if(ds.Tables[1].Rows.Count>0)
        //    YCardMainID = (int)ds.Tables[1].Rows[0][0];



        uJson = JsonConvert.SerializeObject(VM);

        AgeCalculatorT AT = new AgeCalculatorT();

        AgeString = AT.GetYearMonthAge(VM.BirthDate);


        DateTime birthDate = VM.BirthDate;

        dt = MSDB.GetDataTable("ConnDB", "dbo.usp_RecordM_xGetRecordDataByCaseUserID"
                               , new Dictionary <string, object>()
        {
            { "@CaseUserID", CaseUserID }
        });

        List <RecordDataVM> list = new List <RecordDataVM>();

        //List<RecordYellowDataVM> yellowList = new List<RecordYellowDataVM>();
        var yellowList = SystemYCard.GetDict(YCardMainID).Where(item => item.YCardDataType == 1);
        //var x = SystemYCard.dict;
        List <RecordUserDataVM> userList = new List <RecordUserDataVM>();

        //List<RecordYellowDataVM> yellowRemoveList = new List<RecordYellowDataVM>();
        List <RecordUserDataVM> userRemoveList = new List <RecordUserDataVM>();

        EntityS.FillModel(userList, dt);

        //EntityS.FillModel(yellowList, ds.Tables[0]);
        //EntityS.FillModel(userList, ds.Tables[1]);

        //var userVaccineCodes =userList.Select(item => item.SystemRecordVaccineCode).ToList();
        //var DoseIDs = yellowList.Select(item => item.DoseID).ToList();



        foreach (var yellow in yellowList)
        {
            var queryList = userList.FindAll(item => item.SystemRecordVaccineCode.Equals(yellow.DoseID));

            if (queryList.Count > 0)
            {
                foreach (var q in queryList)
                {
                    //yellowRemoveList.Add(yellow);
                    userRemoveList.Add(q);
                    RecordDataVM rVM = new RecordDataVM(birthDate);
                    rVM.InoculationDate       = q.InoculationDate;
                    rVM.IsRule                = true;
                    rVM.OrgID                 = q.OrgID;
                    rVM.VaccineBatchID        = q.VaccineBatchID;
                    rVM.SystemRecordVaccineID = q.SystemRecordVaccineID;
                    rVM.AgeEngilsh            = yellow.AgeEngilsh;
                    rVM.DoseID                = yellow.DoseID;
                    rVM.Period                = yellow.Period;
                    rVM.CreatedDate           = q.CreatedDate;
                    rVM.CreateType            = q.CreateType;
                    //rVM.ColorType = 1;
                    rVM.RecordDataID = q.RecordDataID;


                    //if (rVM.InoculationDate == null || DateTime.Equals(rVM.InoculationDate, new DateTime(2099, 1, 1, 1, 1, 1, 0)))
                    //{
                    //    rVM.OrgID = 0;
                    //    rVM.ColorType = 0;
                    //    rVM.CreatedDate = null;
                    //}
                    //else if(rVM.AppointmentDate!=null && DateTime.Equals(rVM.InoculationDate, new DateTime(2099, 1, 1, 1, 1, 1, 0))==false)
                    //{
                    //   if(DateTime.Compare(rVM.InoculationDate.Value, rVM.AppointmentDate.Value.AddDays(90))>0)
                    //    {
                    //        rVM.ColorType = 1;
                    //    }
                    //}

                    list.Add(rVM);
                }
            }
            else
            {
                RecordDataVM rVM = new RecordDataVM(birthDate);
                rVM.IsRule     = true;
                rVM.AgeEngilsh = yellow.AgeEngilsh;
                rVM.DoseID     = yellow.DoseID;
                //rVM.SystemRecordVaccineID = SystemRecordVaccine.GetID(yellow.DoseID);
                rVM.Period = yellow.Period;
                //rVM.ColorType = 0;
                list.Add(rVM);
            }
        }

        //yellowList.RemoveAll(item => yellowRemoveList.Contains(item));

        userList.RemoveAll(item => userRemoveList.Contains(item));

        list.OrderBy(item => item.AppointmentDate).ThenBy(item => item.Period).ThenBy(item => item.DoseID);

        foreach (var u in userList)
        {
            RecordDataVM rVM = new RecordDataVM(birthDate);
            rVM.InoculationDate       = u.InoculationDate;
            rVM.IsRule                = false;
            rVM.OrgID                 = u.OrgID;
            rVM.VaccineBatchID        = u.VaccineBatchID;
            rVM.SystemRecordVaccineID = u.SystemRecordVaccineID;
            rVM.RecordDataID          = u.RecordDataID;

            if (rVM.InoculationDate == null || DateTime.Equals(rVM.InoculationDate, new DateTime(2099, 1, 1, 1, 1, 1, 0)))
            {
                rVM.OrgID       = 0;
                rVM.CreatedDate = null;
            }

            //list.Add(VM);
            //find last InoculationDate
            var index = list.FindLastIndex(item => item.InoculationDateOut != null);
            if (index >= 0)
            {
                if (index + 1 <= list.Count)
                {
                    list.Insert(index + 1, rVM);
                }
                else
                {
                    list.Add(rVM);
                }
            }
            else
            {
                list.Insert(0, rVM);
            }
        }

        var LastInoculationDateIndex = list.FindLastIndex(item => item.InoculationDateOut != null);

        for (int i = LastInoculationDateIndex + 1; i <= list.Count - 1; i++)
        {
            list[i].DeltaDays = DeltaDays;
        }


        if (list.Count > 0)
        {
            tbAry = JsonConvert.SerializeObject(list);
        }
    }