protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            if (CurrentEnvironment.LoggedUser != null)
            {
                int    userId     = CurrentEnvironment.LoggedUser.Id;
                string language   = CurrentEnvironment.Language;
                int    languageId = int.Parse(language);
                Dictionary <string, string> wtList = (Dictionary <string, string>)HttpContext.Current.Cache["CohortCoverageReport-dictionary" + language + language];
                if (wtList == null)
                {
                    List <WordTranslate> wordTranslateList = WordTranslate.GetWordByLanguage(languageId, "CohortCoverageReport");
                    wtList = new Dictionary <string, string>();
                    foreach (WordTranslate vwt in wordTranslateList)
                    {
                        wtList.Add(vwt.Code, vwt.Name);
                    }
                    HttpContext.Current.Cache.Insert("CohortCoverageReport-dictionary" + language + language, wtList);
                }

                //controls
                this.lbFromDate.Text = wtList["CohortCoverageReportFromDate"];
                this.lbToDate.Text   = wtList["CohortCoverageReportToDate"];
                this.lbEndDate.Text  = wtList["CohortCoverageReportEndDate"];
                this.lbVaccine.Text  = wtList["CohortCoverageReportVaccine"];

                this.lblTitle.Text = wtList["PrintCohortCoverageReportPageTitle"];

                int    hfId  = CurrentEnvironment.LoggedUser.HealthFacilityId;
                string _hfId = (string)Request.QueryString["hfId"];
                if (!String.IsNullOrEmpty(_hfId))
                {
                    int.TryParse(_hfId, out hfId);
                }
                string healthFacilityId = HealthFacility.GetAllChildsForOneHealthFacility(hfId);

                lblFromDate.Text = HttpContext.Current.Session["fromdate"].ToString();
                lblToDate.Text   = HttpContext.Current.Session["todate"].ToString();
                lblEndDate.Text  = HttpContext.Current.Session["enddate"].ToString();
                int vaccine   = Helper.ConvertToInt(HttpContext.Current.Session["vaccineId"]);
                int community = int.Parse(HttpContext.Current.Session["community"].ToString());
                int domicile  = int.Parse(HttpContext.Current.Session["domicile"].ToString());
                if (vaccine != -1)
                {
                    Dose o = Dose.GetDoseById(vaccine);
                    lblVaccine.Text = o.Fullname;
                }

                string dateFormat = ConfigurationDate.GetConfigurationDateById(int.Parse(Configuration.GetConfigurationByName("DateFormat").Value)).DateFormat.ToString();

                DateTime datefrom = DateTime.ParseExact(lblFromDate.Text, dateFormat, CultureInfo.CurrentCulture);
                DateTime dateto   = DateTime.ParseExact(lblToDate.Text, dateFormat, CultureInfo.CurrentCulture);
                DateTime dateend  = DateTime.ParseExact(lblEndDate.Text, dateFormat, CultureInfo.CurrentCulture);

                DataTable dt    = CohortCoverage.GetCohortCoverage(languageId, healthFacilityId, datefrom, dateto, dateend, vaccine, community, domicile);
                DataTable table = CreateDataTable(dt);

                if (dt != null)
                {
                    char[]   stringSeparators = new char[] { ',' };
                    string[] result;
                    foreach (DataRow dr in dt.Rows)
                    {
                        result = dr[0].ToString().Replace(" ", "").Replace("(", "").Replace(")", "").Replace("\"", "").Split(stringSeparators);
                        CreateDataRow(result, table);
                    }

                    gvCohortCoverage.DataSource = table;
                    gvCohortCoverage.DataBind();
                }
            }
            else
            {
                Response.Redirect("Default.aspx", false);
            }
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (CurrentEnvironment.LoggedUser != null)
        {
            string dateFormat = ConfigurationDate.GetConfigurationDateById(int.Parse(Configuration.GetConfigurationByName("DateFormat").Value)).DateFormat.ToString();

            DateTime datefrom = DateTime.ParseExact(txtFromDate.Text, dateFormat, CultureInfo.CurrentCulture);
            DateTime dateto   = DateTime.ParseExact(txtToDate.Text, dateFormat, CultureInfo.CurrentCulture);
            DateTime dateend  = DateTime.ParseExact(txtEndDate.Text, dateFormat, CultureInfo.CurrentCulture);

            string language   = CurrentEnvironment.Language;
            int    languageId = int.Parse(language);

            int vaccineId = int.Parse(ddlVaccine.SelectedValue);
            int community = 0;
            int domicile  = 0;
            if (!String.IsNullOrEmpty(communityId))
            {
                community = int.Parse(communityId);
            }
            if (!String.IsNullOrEmpty(domicileId))
            {
                domicile = int.Parse(domicileId);
            }

            int    hfId  = CurrentEnvironment.LoggedUser.HealthFacilityId;
            string _hfId = (string)Request.QueryString["hfId"];
            if (!String.IsNullOrEmpty(_hfId))
            {
                int.TryParse(_hfId, out hfId);
            }

            string healthFacilityId = "1";
            if (hfId != 1)
            {
                healthFacilityId = HealthFacility.GetAllChildsForOneHealthFacility(hfId, true);
            }

            HttpContext.Current.Session["fromdate"]  = txtFromDate.Text;
            HttpContext.Current.Session["todate"]    = txtToDate.Text;
            HttpContext.Current.Session["enddate"]   = txtEndDate.Text;
            HttpContext.Current.Session["vaccineId"] = vaccineId;
            HttpContext.Current.Session["community"] = community;
            HttpContext.Current.Session["domicile"]  = domicile;

            DataTable dt    = CohortCoverage.GetCohortCoverage(languageId, healthFacilityId, datefrom, dateto, dateend, vaccineId, community, domicile);
            DataTable table = CreateDataTable(dt);

            if (dt != null)
            {
                char[]   stringSeparators = new char[] { ',' };
                string[] result;
                foreach (DataRow dr in dt.Rows)
                {
                    result = dr[0].ToString().Replace(" ", "").Replace("(", "").Replace(")", "").Replace("\"", "").Split(stringSeparators);
                    CreateDataRow(result, table);
                }

                gvCohortCoverage.DataSource = table;
                gvCohortCoverage.DataBind();

                string url = VaccineCoverageReportGrahpHelper.GetUrl(table, this.lblTitle.Text);

                iCoverageReport.Text = String.Format("<img src='{0}' alt='' />", url.Replace(" ", ""));
            }
        }
    }