protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    DTOInstituteDetails toins = new DTOInstituteDetails();
                    toins.InstituteID = int.Parse(hfInstituteID.Value.ToString()); ;

                    if (new BOInstituteDetails().DeleteInstituteDetails(toins))
                    {
                        //string script = @"document.getElementById('" + divStatus.ClientID + "').innerHTML='Record deleted';var elem = document.createElement('img');elem.setAttribute('src', 'tick.jpg');document.getElementById('" + divStatus.ClientID + "').appendChild(elem);document.getElementById('" + divStatus.ClientID + "').style.color = 'Green';document.getElementById('" + divStatus.ClientID + "').style.fontSize = '1em' ;document.getElementById('" + divStatus.ClientID + "').style.fontWeight = 'bold' ;setTimeout(function(){document.getElementById('" + divStatus.ClientID + "').style.display='none';},4500);";
                        //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", script, true);
                        string alertScript = "jAlert('Institute Details Deleted Successfully', 'Campus2Caretaker');";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true);
                        RefreshGridView();
                        clear();
                    }
                    else
                    {
                        //string script = @"document.getElementById('" + divStatus.ClientID + "').innerHTML='Error';var elem = document.createElement('img');elem.setAttribute('src', 'cross.jpg');document.getElementById('" + divStatus.ClientID + "').appendChild(elem);document.getElementById('" + divStatus.ClientID + "').style.color = 'Red';document.getElementById('" + divStatus.ClientID + "').style.fontSize = '1em' ;document.getElementById('" + divStatus.ClientID + "').style.fontWeight = 'bold' ;setTimeout(function(){document.getElementById('" + divStatus.ClientID + "').style.display='none';},4500);";
                        //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", script, true);
                        string alertScript = "jAlert('Error', 'Campus2Caretaker');";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true);
                    }
                }
                catch { }
            }
        }
 public int? GetStudentCountReport(DTOInstituteDetails toinst, string gender)
 {
     using (Campus2CaretakerDataContext dbcontext = new Campus2CaretakerDataContext())
     {
         return (dbcontext.GetStudentCount(toinst.InstituteID)).Where(t => t.Gender == gender).Select(x => x.TotalCount).FirstOrDefault();
     }
 }
        public List<DTOClasswiseCount> GetStudentCountClasswiseReport(DTOInstituteDetails toinst, string gender, int branchid)
        {
            Campus2CaretakerDataContext dbcontext = new Campus2CaretakerDataContext();

            return (from v in dbcontext.GetStudentCountClasswiseGender(toinst.InstituteID)
                    where v.Gender == gender && v.colBranchId == branchid
                    select new DTOClasswiseCount
                    {
                        Count = v.TotalCount,
                        ClassName = v.colBranchName
                    }).ToList();
        }
        public bool DeleteInstituteDetails(DTOInstituteDetails toins)
        {
            try
            {
                Campus2CaretakerDataContext dbContext = new Campus2CaretakerDataContext();

                // Institute Details

                tblInstituteDetail InstDetail = dbContext.tblInstituteDetails.Where(x => x.colInstituteId == toins.InstituteID).FirstOrDefault();
                dbContext.tblInstituteDetails.DeleteOnSubmit(InstDetail);
                dbContext.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        protected void btnGetInstituteInfo_Click(object sender, EventArgs e)
        {
            DTOInstituteDetails toins = new DTOInstituteDetails();
            toins.InstituteID = int.Parse(hfInstituteID.Value);
            txtInstituteEmail.Enabled = false;
            btnSave.Enabled = false;
            btnUpdate.Enabled = true;
            btnDelete.Enabled = true;
            DataTable dt = new DataTable();
            dt = new BOInstituteDetails().GetInstituteDetails(toins);
            try
            {
                txtInstituteName.Text = dt.Rows[0][0].ToString();
                txtInstituteEmail.Text = dt.Rows[0][7].ToString();
                Session["LogoPhoto"] = dt.Rows[0][3].ToString();
                imgInstituteLogo.Src = "~/uploaded/" + Session["LogoPhoto"].ToString();
                txtInstituteAddress.Text = dt.Rows[0][1].ToString();
                txtInstitutePhoneNumber.Text = dt.Rows[0][2].ToString();
                txtState.Text = dt.Rows[0][9].ToString();
                txtDistrict.Text = dt.Rows[0][8].ToString();
                txtMaxStudents.Text = dt.Rows[0][10].ToString();

                if (dt.Rows[0][6].ToString().Equals("S"))
                {
                    ddlInstituteType.SelectedIndex = 1;
                }
                else if (dt.Rows[0][6].ToString().Equals("C"))
                {
                    ddlInstituteType.SelectedIndex = 2;
                }
                else if (dt.Rows[0][6].ToString().Equals("D"))
                {
                    ddlInstituteType.SelectedIndex = 3;
                }
                txtPrincipalContactNumber.Text = dt.Rows[0][5].ToString();
                txtPrincipalName.Text = dt.Rows[0][4].ToString();
            }
            catch
            {

            }
        }
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            try
            {
                DTOLogin tologin = new DTOLogin();
                tologin.UserID = UserName.Text;
                tologin.Password = PasswordEncDec.EncodePasswordToBase64(Password.Text);
                bool authenticated = new BOLogin().CheckInstituteUser(tologin);
                if (authenticated)
                {
                    Session["InstituteID"] = new BOInstituteDetails().GetInstituteId(UserName.Text);
                    Session["UserName"] = UserName.Text;

                    DTOInstituteDetails toins = new DTOInstituteDetails();
                    toins.InstituteEmail = Session["UserName"].ToString();
                    toins.InstituteID = int.Parse(Session["InstituteID"].ToString());

                    DataTable dt = new BOInstituteDetails().GetInstituteDetails(toins);

                    Session["LogoPath"] = dt.Rows[0][3].ToString();
                    Session["InstituteName"] = dt.Rows[0][0].ToString();
                    Session["InstituteType"] = dt.Rows[0][6].ToString();
                    Session["MaxStudentsInstitute"] = dt.Rows[0][10].ToString();

                    Response.Redirect("InstituteDefault.aspx");
                }
                else
                {
                    FailureText.Text = "Username or Password is incorrect.";
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
 public bool UpdateInstituteDetails(DTOInstituteDetails toinst)
 {
     return new DAOInstituteDetails().UpdateInstituteDetails(toinst);
 }
 public bool DeleteInstituteDetails(DTOInstituteDetails toins)
 {
     return new DAOInstituteDetails().DeleteInstituteDetails(toins);
 }
 public bool IsInstituteEmailExists(DTOInstituteDetails toinst)
 {
     return new DAOInstituteDetails().IsInstituteEmailExists(toinst);
 }
 public DataTable GetInstituteDetails(DTOInstituteDetails toins)
 {
     return new DAOInstituteDetails().GetInstituteDetails(toins);
 }
        public bool InsertInstituteDetails(DTOInstituteDetails toins)
        {
            try
            {
                Campus2CaretakerDataContext dbContext = new Campus2CaretakerDataContext();

                // Institute Details

                tblInstituteDetail InstDetail = new tblInstituteDetail();
                InstDetail.colAddress = toins.InstituteAddress;
                InstDetail.colInstituteName = toins.InstituteName;
                InstDetail.colInstituteType = toins.InstituteType;
                InstDetail.colLogoPath = toins.LogoPath;
                InstDetail.colPhone = toins.InstitutePhoneNo;
                InstDetail.colPrincipalContact = toins.PrincipalContact;
                InstDetail.colPrincipalName = toins.PrincipalName;
                InstDetail.colState = toins.State;
                InstDetail.colDistrict = toins.District;
                InstDetail.colMaxStudents = toins.MaxStudents;

                dbContext.tblInstituteDetails.InsertOnSubmit(InstDetail);
                dbContext.SubmitChanges();

                // Institute Login Details

                tblInstituteLogin InstLogin = new tblInstituteLogin();
                InstLogin.colInstituteId = dbContext.tblInstituteDetails.Select(x => x.colInstituteId).Max();
                InstLogin.colPassword = toins.InstituteDefaultPwd;
                InstLogin.colUsername = toins.InstituteEmail;
                InstLogin.colUserType = toins.InstituteUserType;

                dbContext.tblInstituteLogins.InsertOnSubmit(InstLogin);
                dbContext.SubmitChanges();

                return true;
            }
            catch
            {
                return false;
            }
        }
 public bool InsertInstituteDetails(DTOInstituteDetails toinst)
 {
     return new DAOInstituteDetails().InsertInstituteDetails(toinst);
 }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    DTOInstituteDetails toinst = new DTOInstituteDetails();
                    toinst.InstituteID = int.Parse(hfInstituteID.Value.ToString());
                    toinst.InstituteName = txtInstituteName.Text;
                    toinst.InstituteEmail = txtInstituteEmail.Text;

                    if (imgInstituteLogo.Src != null)
                    {
                        toinst.LogoPath = Session["LogoPhoto"].ToString();
                    }

                    toinst.InstituteAddress = txtInstituteAddress.Text;
                    toinst.InstitutePhoneNo = txtInstitutePhoneNumber.Text;
                    toinst.InstituteType = ddlInstituteType.SelectedValue;
                    toinst.PrincipalContact = txtPrincipalContactNumber.Text;
                    toinst.PrincipalName = txtPrincipalName.Text;
                    toinst.State = txtState.Text;
                    toinst.District = txtDistrict.Text;
                    toinst.MaxStudents = int.Parse(txtMaxStudents.Text);

                    if (new BOInstituteDetails().UpdateInstituteDetails(toinst))
                    {
                        //string script = @"document.getElementById('" + divStatus.ClientID + "').innerHTML='Record updated';var elem = document.createElement('img');elem.setAttribute('src', 'tick.jpg');document.getElementById('" + divStatus.ClientID + "').appendChild(elem);document.getElementById('" + divStatus.ClientID + "').style.color = 'Green';document.getElementById('" + divStatus.ClientID + "').style.fontSize = '1em' ;document.getElementById('" + divStatus.ClientID + "').style.fontWeight = 'bold' ;setTimeout(function(){document.getElementById('" + divStatus.ClientID + "').style.display='none';},4500);";
                        //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", script, true);

                        string alertScript = "jAlert('Institute Details Updated Successfully', 'Campus2Caretaker');";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true);

                        RefreshGridView();
                        clear();
                    }
                    else
                    {
                        //string script = @"document.getElementById('" + divStatus.ClientID + "').innerHTML='Error';var elem = document.createElement('img');elem.setAttribute('src', 'cross.jpg');document.getElementById('" + divStatus.ClientID + "').appendChild(elem);document.getElementById('" + divStatus.ClientID + "').style.color = 'Red';document.getElementById('" + divStatus.ClientID + "').style.fontSize = '1em' ;document.getElementById('" + divStatus.ClientID + "').style.fontWeight = 'bold' ;setTimeout(function(){document.getElementById('" + divStatus.ClientID + "').style.display='none';},4500);";
                        //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", script, true);
                        string alertScript = "jAlert('Error', 'Campus2Caretaker');";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true);
                    }
                }
                catch { }
            }
        }
 public bool IsInstituteNameExists(DTOInstituteDetails toins)
 {
     try
     {
         Campus2CaretakerDataContext dbContext = new Campus2CaretakerDataContext();
         int inCount = dbContext.tblInstituteDetails.Where(x => x.colInstituteName == toins.InstituteName).Count();
         if (inCount > 0)
             return true;
         else
             return false;
     }
     catch
     {
         return false;
     }
 }
        public bool UpdateInstituteDetails(DTOInstituteDetails toins)
        {
            try
            {
                Campus2CaretakerDataContext dbContext = new Campus2CaretakerDataContext();

                // Institute Details

                tblInstituteDetail InstDetail = dbContext.tblInstituteDetails.Where(x => x.colInstituteId == toins.InstituteID).FirstOrDefault();
                InstDetail.colAddress = toins.InstituteAddress;
                InstDetail.colInstituteName = toins.InstituteName;
                InstDetail.colInstituteType = toins.InstituteType;
                InstDetail.colLogoPath = toins.LogoPath;
                InstDetail.colPhone = toins.InstitutePhoneNo;
                InstDetail.colPrincipalContact = toins.PrincipalContact;
                InstDetail.colPrincipalName = toins.PrincipalName;
                InstDetail.colState = toins.State;
                InstDetail.colDistrict = toins.District;
                InstDetail.colMaxStudents = toins.MaxStudents;

                dbContext.SubmitChanges();
                return true;
            }
            catch { return false; }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //to Save a new employee to the db and updates it to the below gridview

            if (Page.IsValid)
            {
                DTOInstituteDetails toinst = new DTOInstituteDetails();
                toinst.InstituteName = txtInstituteName.Text;
                toinst.InstituteEmail = txtInstituteEmail.Text;

                if (new BOInstituteDetails().IsInstituteNameExists(toinst) || new BOInstituteDetails().IsInstituteEmailExists(toinst))
                {
                    //string script = @"document.getElementById('" + divStatus.ClientID + "').innerHTML='Institute already exists!!';var elem = document.createElement('img');elem.setAttribute('src', 'cross.jpg');document.getElementById('" + divStatus.ClientID + "').appendChild(elem);document.getElementById('" + divStatus.ClientID + "').style.color = 'Red';document.getElementById('" + divStatus.ClientID + "').style.fontSize = '1em' ;document.getElementById('" + divStatus.ClientID + "').style.fontWeight = 'bold' ;setTimeout(function(){document.getElementById('" + divStatus.ClientID + "').style.display='none';},4500);";
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", script, true);
                    string alertScript = "jAlert('Institute already exists', 'Campus2Caretaker');";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true);
                    return;
                }

                if (imgInstituteLogo.Src != null)
                {
                    toinst.LogoPath = Session["LogoPhoto"].ToString();
                }
                toinst.InstituteAddress = txtInstituteAddress.Text;
                toinst.InstitutePhoneNo = txtInstitutePhoneNumber.Text;
                toinst.InstituteType = ddlInstituteType.SelectedValue;
                toinst.PrincipalContact = txtPrincipalContactNumber.Text;
                toinst.PrincipalName = txtPrincipalName.Text;
                toinst.State = txtState.Text;
                toinst.District = txtDistrict.Text;
                toinst.MaxStudents = int.Parse(txtMaxStudents.Text);

                RandomStringGenerator randstring = new RandomStringGenerator();
                string DefaultPwd = randstring.Generate(8);
                toinst.InstituteDefaultPwd = PasswordEncDec.EncodePasswordToBase64(DefaultPwd);
                toinst.InstituteUserType = "Usr";

                if (new BOInstituteDetails().InsertInstituteDetails(toinst))
                {
                    //string script = @"document.getElementById('" + divStatus.ClientID + "').innerHTML='Record inserted';var elem = document.createElement('img');elem.setAttribute('src', 'tick.jpg');document.getElementById('" + divStatus.ClientID + "').appendChild(elem);document.getElementById('" + divStatus.ClientID + "').style.color = 'Green';document.getElementById('" + divStatus.ClientID + "').style.fontSize = '1em' ;document.getElementById('" + divStatus.ClientID + "').style.fontWeight = 'bold' ;setTimeout(function(){document.getElementById('" + divStatus.ClientID + "').style.display='none';},4500);";
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", script, true);

                    string alertScript = "jAlert('Institute Details Saved Successfully', 'Campus2Caretaker');";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true);

                    #region E-Mail

                    //Send mail

                    string s_subject = "Institute Account Details From Campus2Caretaker";
                    string s_msg = "Please use the below details for managing your institute account in Campus2Caretaker." + Environment.NewLine + Environment.NewLine;

                    string s_link = "http://" + Request.ServerVariables["SERVER_NAME"] + ":" + Request.ServerVariables["SERVER_PORT"] + "/Institute/InstituteLogin.aspx";
                    s_msg += s_link + Environment.NewLine + Environment.NewLine;
                    s_msg += "Username and Password to Login to account is" + Environment.NewLine + Environment.NewLine;
                    s_msg += "Username :"******"Password :"******"document.getElementById('" + divStatus.ClientID + "').innerHTML='Error';var elem = document.createElement('img');elem.setAttribute('src', 'cross.jpg');document.getElementById('" + divStatus.ClientID + "').appendChild(elem);document.getElementById('" + divStatus.ClientID + "').style.color = 'Red';document.getElementById('" + divStatus.ClientID + "').style.fontSize = '1em' ;document.getElementById('" + divStatus.ClientID + "').style.fontWeight = 'bold' ;setTimeout(function(){document.getElementById('" + divStatus.ClientID + "').style.display='none';},4500);";
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", script, true);

                    string alertScript = "jAlert('Error', 'Campus2Caretaker');";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true);
                }
            }
        }
 public DataTable GetInstituteDetails(DTOInstituteDetails toins)
 {
     using (Campus2CaretakerDataContext dbcontext = new Campus2CaretakerDataContext())
     {
         return (dbcontext.GetInstituteDetails(toins.InstituteID)).ToDataTable();
     }
 }
        private void LoadStudentsCountClasswise(string instituteId)
        {
            DTOInstituteDetails toins = new DTOInstituteDetails();
            toins.InstituteID = int.Parse(instituteId);

            DataTable branches = new BOPersonalizeApplication().GetClassesList(instituteId);
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[4] { new DataColumn("colBranchName", typeof(string)),
                            new DataColumn("colTotalCount", typeof(string)),
                            new DataColumn("colMaleCount",typeof(string)) ,
                            new DataColumn("colFemaleCount",typeof(string)) });

            for (int j = 0; j < branches.Rows.Count; j++)
            {
                List<DTOClasswiseCount> allCount = new BOReport().GetStudentCountClasswiseReport(toins, "All", int.Parse(branches.Rows[j][0].ToString()));
                List<DTOClasswiseCount> maleCount = new BOReport().GetStudentCountClasswiseReport(toins, "Male", int.Parse(branches.Rows[j][0].ToString()));
                List<DTOClasswiseCount> femaleCount = new BOReport().GetStudentCountClasswiseReport(toins, "Female", int.Parse(branches.Rows[j][0].ToString()));

                for (int i = 0; i < allCount.Count; i++)
                {
                    string finalMaleCount = "0";
                    if (maleCount.Count > i)
                    {
                        finalMaleCount = maleCount[i].Count.ToString();
                    }

                    string finalFemaleCount = "0";
                    if (femaleCount.Count > i)
                    {
                        finalFemaleCount = femaleCount[i].Count.ToString();
                    }

                    dt.Rows.Add(allCount[i].ClassName, allCount[i].Count.ToString(), finalMaleCount, finalFemaleCount);
                }
            }

            for (int i = 1; i < dt.Columns.Count; i++)
            {
                Series series = new Series();

                foreach (DataRow dr in dt.Rows)
                {
                    int y = Convert.ToInt32(dr[i]);

                    series.Points.AddXY(dr["colBranchName"].ToString(), y);
                }

                chrtStudentsStrengthvsClass.Series.Add(series);
            }
            gvClasswiseStrength.DataSource = dt;
            gvClasswiseStrength.DataBind();
        }
        private void LoadStudentsCount(string instituteId)
        {
            DTOInstituteDetails toins = new DTOInstituteDetails();
            toins.InstituteID = int.Parse(instituteId);

            int? allCount = new BOReport().GetStudentCountReport(toins, "All");
            int? maleCount = new BOReport().GetStudentCountReport(toins, "Male");
            int? femaleCount = new BOReport().GetStudentCountReport(toins, "Female");

            double? allPercent = (double)((double)allCount / double.Parse(Session["MaxStudentsInstitute"].ToString()));
            dvAllCount.InnerText = String.Concat(String.Format("{0:0.00}", (allPercent * 100)).ToString(), "%");
            dvAllCount.Attributes["data-percent"] = (allPercent * 100).ToString();
            lblAllCount.InnerText = allCount.ToString();
            lblAllCountText.InnerText = "Total Students";

            double? malePercent = (double)((double)maleCount / (double)allCount);
            dvMaleCount.InnerText = String.Concat(String.Format("{0:0.00}", (malePercent * 100)).ToString(), "%");
            dvMaleCount.Attributes["data-percent"] = (malePercent * 100).ToString();
            lblMaleCount.InnerText = maleCount.ToString();
            lblMaleCountText.InnerText = "Male";

            double? femalePercent = (double)((double)femaleCount / (double)allCount);
            dvFemaleCount.InnerText = String.Concat(String.Format("{0:0.00}", (femalePercent * 100)).ToString(), "%");
            dvFemaleCount.Attributes["data-percent"] = (femalePercent * 100).ToString();
            lblFemaleCount.InnerText = femaleCount.ToString();
            lblFemaleCountText.InnerText = "Female";
        }
 public int? GetStudentCountReport(DTOInstituteDetails toinst, string gender)
 {
     return new DAOReport().GetStudentCountReport(toinst, gender);
 }
 public List<DTOClasswiseCount> GetStudentCountClasswiseReport(DTOInstituteDetails toinst, string gender, int branchid)
 {
     return new DAOReport().GetStudentCountClasswiseReport(toinst, gender, branchid);
 }