protected void ButtonPreview_Click(object sender, EventArgs e)
 {
     dataRpt = "<p style='color: #1408C5; font-weight: bold;'>THỐNG KÊ KẾT QUẢ</p>";
     //Print
     nUserLogin = (TNLibrary.SYS.SessionUserLogin)Session["UserLogin"];
     if (nUserLogin.GroupKey == 1 || DropDownListMembers.SelectedIndex > 0)
     {//Print a member
         dataRpt += "<div style='margin-left: 20px;'><p>+ Xã viên: " + (DropDownListMembers.SelectedIndex > 0 ? DropDownListMembers.SelectedItem.Text : nUserLogin.Name) + "</p>";
         dataRpt += PrintMember(DropDownListMembers.SelectedIndex > 0 ? DropDownListMembers.SelectedValue : nUserLogin.EmployeeKey.ToString(), int.Parse(DropDownListFromYear.SelectedValue), int.Parse(DropDownListToYear.SelectedValue));
         dataRpt += "</div>";
     }
     else if ((nUserLogin.GroupKey == 2 && DropDownListMembers.SelectedIndex == 0) || DropDownListCooperatives.SelectedIndex > 0)
     {//Print a cooperative
         System.Data.DataTable users = ReportPUL2.ReportPUL.getMember(DropDownListCooperatives.SelectedIndex > 0 ? int.Parse(DropDownListCooperatives.SelectedValue) : nUserLogin.CooperativeKey);
         dataRpt += "<div><p style='font-weight:bold; color: red;'>+ Hợp tác xã: " + ReportPUL2.ReportPUL.getCooperativeInfo(DropDownListCooperatives.SelectedIndex > 0?int.Parse(DropDownListCooperatives.SelectedValue): nUserLogin.CooperativeKey).Rows[0]["Cooperative_Name"].ToString() + "</p>";
         //Print cooperative total
         dataRpt += "<div>";
         dataRpt += PrintMember("SELECT [Key] FROM Pul_Member WHERE Cooperative_Key=" + (DropDownListCooperatives.SelectedIndex > 0 ? int.Parse(DropDownListCooperatives.SelectedValue) : nUserLogin.CooperativeKey), int.Parse(DropDownListFromYear.SelectedValue), int.Parse(DropDownListToYear.SelectedValue));
         dataRpt += "</div>";
         for (int i = 0; i < users.Rows.Count; i++)
         {
             dataRpt += "<div style='margin-left: 20px;'><p style='text-decoration: underline; font-weight: bold;'>" + (i + 1) + ". Xã viên: " + users.Rows[i]["Name"].ToString() + "</p>";
             dataRpt += PrintMember(users.Rows[i]["Key"].ToString(), int.Parse(DropDownListFromYear.SelectedValue), int.Parse(DropDownListToYear.SelectedValue));
             dataRpt += "</div>";
         }
         dataRpt += "</div>";
     }
     else if ((nUserLogin.GroupKey == 3 && DropDownListCooperatives.SelectedIndex == 0) || DropDownListCooperativeVentures.SelectedIndex > 0)
     {//Print cooperativeventure
         System.Data.DataTable coopeartives = ReportPUL2.ReportPUL.getCooperative(DropDownListCooperativeVentures.SelectedIndex > 0 ? int.Parse(DropDownListCooperativeVentures.SelectedValue) : nUserLogin.CooperativeVenturesKey);
         dataRpt += "<div><p style='font-weight: bold;'>+ Liên hợp tác xã: " + ReportPUL2.ReportPUL.getCooperativeVentureInfo(DropDownListCooperativeVentures.SelectedIndex > 0 ? int.Parse(DropDownListCooperativeVentures.SelectedValue) : nUserLogin.CooperativeVenturesKey).Rows[0]["CooperativeVenturesName"].ToString() + "</p>";
         //Print cooperative total
         dataRpt += "<div>";
         dataRpt += PrintMember("SELECT [Key] FROM Pul_Member WHERE Cooperative_Key in (select cooperative_key from pul_listcooperative where CooperativeVenturesKey=" + (DropDownListCooperativeVentures.SelectedIndex > 0 ? int.Parse(DropDownListCooperativeVentures.SelectedValue) : nUserLogin.CooperativeVenturesKey) + ")", int.Parse(DropDownListFromYear.SelectedValue), int.Parse(DropDownListToYear.SelectedValue));
         dataRpt += "</div>";
         for (int h = 0; h < coopeartives.Rows.Count; h++)
         {
             System.Data.DataTable users = ReportPUL2.ReportPUL.getMember(int.Parse(coopeartives.Rows[h]["Cooperative_Key"].ToString()));
             dataRpt += "<div style='margin-left: 10px;'><p style='font-weight:bold; color: red;'>" + (h + 1) + ". Hợp tác xã: " + coopeartives.Rows[h]["Cooperative_Name"].ToString() + "</p>";
             //Print cooperative total
             dataRpt += "<div>";
             dataRpt += PrintMember("SELECT [Key] FROM Pul_Member WHERE Cooperative_Key=" + (int.Parse(coopeartives.Rows[h]["Cooperative_Key"].ToString())), int.Parse(DropDownListFromYear.SelectedValue), int.Parse(DropDownListToYear.SelectedValue));
             dataRpt += "</div>";
             for (int i = 0; i < users.Rows.Count; i++)
             {
                 dataRpt += "<div style='margin-left: 20px;'><p style='text-decoration: underline; font-weight: bold;'>" + (i + 1) + ". Xã viên: " + users.Rows[i]["Name"].ToString() + "</p>";
                 dataRpt += PrintMember(users.Rows[i]["Key"].ToString(), int.Parse(DropDownListFromYear.SelectedValue), int.Parse(DropDownListToYear.SelectedValue));
                 dataRpt += "</div>";
             }
             dataRpt += "</div>";
         }
         dataRpt += "</div>";
     }
     Session["dataRpt"] = dataRpt;
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["dataRpt"] = dataRpt;
            if (!Page.IsPostBack)
            {
                nUserLogin = (TNLibrary.SYS.SessionUserLogin)Session["UserLogin"];
                if (nUserLogin != null)
                {
                    for (int i = 2000; i <= DateTime.Now.Year; i++)
                    {
                        DropDownListFromYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
                        DropDownListToYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
                    }
                    switch (nUserLogin.GroupKey)
                    {
                    case 1:    //Xa vien
                        Permit(false, false, false, false);
                        break;

                    case 2:    //Hop tac xa
                        Permit(false, false, false, true);
                        FillDropDownList(DropDownListMembers, ReportPUL2.ReportPUL.getMember(nUserLogin.CooperativeKey), "", "", "--- Chọn xã viên ---");
                        break;

                    case 3:    //Lien hop tac xa
                        Permit(false, false, true, true);
                        FillDropDownList(DropDownListCooperatives, ReportPUL2.ReportPUL.getCooperativeVenture(nUserLogin.CooperativeKey), "CooperativeVenturesName", "CooperativeVenturesKey", "--- Chọn hợp tác xã ---");
                        break;

                    case 4:    //Admin
                        Permit(true, true, true, true);
                        FillDropDownList(DropDownListProvinces, ReportPUL2.ReportPUL.getProvincesCities(), "ProvincesCities_Name", "ProvincesCities_Key");
                        break;
                    }
                }
            }
        }