private void RefreshClasses() { DataTable dt = new BOStudentRegistration().GetClassesList(Session["InstituteID"].ToString()); ddlFromClass.DataSource = dt; ddlToClass.DataSource = dt; ddlFromClass.DataBind(); ddlToClass.DataBind(); System.Web.UI.WebControls.ListItem Item = new System.Web.UI.WebControls.ListItem("Select", "Select"); ddlFromClass.Items.Insert(0, Item); ddlFromClass.SelectedIndex = 0; ddlToClass.Items.Insert(0, Item); ddlToClass.SelectedIndex = 0; }
protected void btnGetStudentInfo_Click(object sender, EventArgs e) { DTOStudentRegistration tostu = new DTOStudentRegistration(); tostu.StudentId = int.Parse(hfStudentID.Value.ToString()); btnSave.Enabled = false; btnUpdate.Enabled = true; btnDelete.Enabled = true; DataTable dt = new DataTable(); dt = new BOStudentRegistration().GetStudentDetails(tostu); try { txtStudentName.Text = dt.Rows[0][0].ToString(); txtFatherName.Text = dt.Rows[0][2].ToString(); txtMotherName.Text = dt.Rows[0][3].ToString(); txtDOB.Text = DateTime.Parse(dt.Rows[0][4].ToString()).ToString("dd MMMM, yyyy"); if (Session["InstituteType"].ToString() != "S") ddlSemester.SelectedValue = dt.Rows[0][5].ToString(); ddlClass.SelectedValue = dt.Rows[0][6].ToString(); txtRollNo.Text = dt.Rows[0][8].ToString(); txtParentsContactNumber.Text = dt.Rows[0][9].ToString(); txtStudentAddress.Text = dt.Rows[0][11].ToString(); txtParentsEmail.Text = dt.Rows[0][12].ToString(); ddlGender.SelectedValue = dt.Rows[0][13].ToString(); } catch { } }
private void RefreshGridView() { DataTable dt = new BOStudentRegistration().GetStudentsList(Session["InstituteID"].ToString()); string strSort = String.Empty; if (ViewState.Keys.Count > 0) { strSort = String.Format("{0} {1}", m_strSortExp, (m_SortDirection == SortDirection.Descending) ? "DESC" : "ASC"); dt.DefaultView.Sort = strSort; } DataView dv = new DataView(dt, String.Empty, strSort, DataViewRowState.CurrentRows); gvStudents.DataSource = dv; gvStudents.DataBind(); }
private bool CheckExcelSheet(string FileName, DataTable dt) { bool isValidExcelSheet = true; try { #region local variables for processing string StudentName = ""; string LastName = ""; string FatherName = ""; string MotherName = ""; DateTime DateOfBirth; int Semester; string Branch = ""; string Section = ""; string RollNo = ""; string ParentsMobileNo = ""; string StudentAddress = ""; string Gender = ""; string ParentsEmail = ""; #endregion string path = string.Concat(Server.MapPath("~/Documents/" + FileName)); FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read); IExcelDataReader excelReader; switch (Path.GetExtension(path).ToLower()) { case ".xls": //1. Reading from a binary Excel file ('97-2003 format; *.xls) excelReader = ExcelReaderFactory.CreateBinaryReader(stream); break; //... case ".xlsx": //2. Reading from a OpenXml Excel file (2007 format; *.xlsx) excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); break; //... default: return false; } //3. DataSet - Create column names from first row excelReader.IsFirstRowAsColumnNames = true; DataSet result = excelReader.AsDataSet(); //5. Data Reader methods for (int i = 0; i < result.Tables[0].Rows.Count; i++) { //excelReader.GetInt32(0); try { StudentName = valid(result.Tables[0].Rows[i], 0); LastName = valid(result.Tables[0].Rows[i], 1); FatherName = valid(result.Tables[0].Rows[i], 2); MotherName = valid(result.Tables[0].Rows[i], 3); DateOfBirth = DateTime.Parse(valid(result.Tables[0].Rows[i], 4)); if (Session["InstituteType"].ToString() == "S") { Semester = 0; } else { Semester = int.Parse(valid(result.Tables[0].Rows[i], 5)); } Branch = valid(result.Tables[0].Rows[i], 6); Section = valid(result.Tables[0].Rows[i], 7); RollNo = valid(result.Tables[0].Rows[i], 8); ParentsMobileNo = valid(result.Tables[0].Rows[i], 9); StudentAddress = valid(result.Tables[0].Rows[i], 10); Gender = valid(result.Tables[0].Rows[i], 11); ParentsEmail = valid(result.Tables[0].Rows[i], 12); if (excelReader[0] == DBNull.Value) break; string BranchId = new BOStudentRegistration().GetBranchId(valid(result.Tables[0].Rows[i], 6)); if (BranchId == string.Empty) { //string script = @"document.getElementById('" + dvUploadStatus.ClientID + "').innerHTML='Invalid Branch Name found in Branch column!!; it should be number!!';var elem = document.createElement('img');elem.setAttribute('src', 'cross.jpg');document.getElementById('" + dvUploadStatus.ClientID + "').appendChild(elem);document.getElementById('" + dvUploadStatus.ClientID + "').style.color = 'Red';document.getElementById('" + dvUploadStatus.ClientID + "').style.fontSize = '1em' ;document.getElementById('" + dvUploadStatus.ClientID + "').style.fontWeight = 'bold' ;setTimeout(function(){document.getElementById('" + dvUploadStatus.ClientID + "').style.display='none';},4500);"; //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", script, true); string alertScript = "jAlert('Invalid Branch Name found in Branch column', 'Campus2Caretaker');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true); return false; } int intvalue; if (!int.TryParse(Semester.ToString(), out intvalue)) { //string script = @"document.getElementById('" + dvUploadStatus.ClientID + "').innerHTML='Invalid Semester Id found in Semester column!!; it should be numeric!!';var elem = document.createElement('img');elem.setAttribute('src', 'cross.jpg');document.getElementById('" + dvUploadStatus.ClientID + "').appendChild(elem);document.getElementById('" + dvUploadStatus.ClientID + "').style.color = 'Red';document.getElementById('" + dvUploadStatus.ClientID + "').style.fontSize = '1em' ;document.getElementById('" + dvUploadStatus.ClientID + "').style.fontWeight = 'bold' ;setTimeout(function(){document.getElementById('" + dvUploadStatus.ClientID + "').style.display='none';},4500);"; //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", script, true); isValidExcelSheet = false; string alertScript = "jAlert('Invalid Semester Id found in Semester column', 'Campus2Caretaker');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true); isValidExcelSheet = false; break; } DateTime dateTimeValue; if (!DateTime.TryParse(DateOfBirth.ToString(), out dateTimeValue)) { //string script = @"document.getElementById('" + dvUploadStatus.ClientID + "').innerHTML='Invalid DOB found in DOB column!!; it should be numeric!!';var elem = document.createElement('img');elem.setAttribute('src', 'cross.jpg');document.getElementById('" + dvUploadStatus.ClientID + "').appendChild(elem);document.getElementById('" + dvUploadStatus.ClientID + "').style.color = 'Red';document.getElementById('" + dvUploadStatus.ClientID + "').style.fontSize = '1em' ;document.getElementById('" + dvUploadStatus.ClientID + "').style.fontWeight = 'bold' ;setTimeout(function(){document.getElementById('" + dvUploadStatus.ClientID + "').style.display='none';},4500);"; //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", script, true); string alertScript = "jAlert('Invalid DOB found in DOB column', 'Campus2Caretaker');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true); isValidExcelSheet = false; break; } string genderValue = valid(result.Tables[0].Rows[i], 11); if (genderValue == string.Empty || (genderValue != "Male" && genderValue != "Female")) { //string script = @"document.getElementById('" + dvUploadStatus.ClientID + "').innerHTML='Invalid Gender found in Gender column!!; it should be Male or Female!!';var elem = document.createElement('img');elem.setAttribute('src', 'cross.jpg');document.getElementById('" + dvUploadStatus.ClientID + "').appendChild(elem);document.getElementById('" + dvUploadStatus.ClientID + "').style.color = 'Red';document.getElementById('" + dvUploadStatus.ClientID + "').style.fontSize = '1em' ;document.getElementById('" + dvUploadStatus.ClientID + "').style.fontWeight = 'bold' ;setTimeout(function(){document.getElementById('" + dvUploadStatus.ClientID + "').style.display='none';},4500);"; //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", script, true); string alertScript = "jAlert('Invalid Gender found in Gender column', 'Campus2Caretaker');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true); return false; } string parentsEmailValue = valid(result.Tables[0].Rows[i], 12); RegexUtilities util = new RegexUtilities(); if (parentsEmailValue != string.Empty) { if (!util.IsValidEmail(parentsEmailValue)) { //string script = @"document.getElementById('" + dvUploadStatus.ClientID + "').innerHTML='Invalid email found in parents email column!!';var elem = document.createElement('img');elem.setAttribute('src', 'cross.jpg');document.getElementById('" + dvUploadStatus.ClientID + "').appendChild(elem);document.getElementById('" + dvUploadStatus.ClientID + "').style.color = 'Red';document.getElementById('" + dvUploadStatus.ClientID + "').style.fontSize = '1em' ;document.getElementById('" + dvUploadStatus.ClientID + "').style.fontWeight = 'bold' ;setTimeout(function(){document.getElementById('" + dvUploadStatus.ClientID + "').style.display='none';},4500);"; //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", script, true); string alertScript = "jAlert('Invalid email found in parents email column', 'Campus2Caretaker');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true); return false; } } //Here using this method we are inserting the data into a temporary DataTable dt.Rows.Add(StudentName, LastName, FatherName, MotherName, DateOfBirth, Semester, BranchId, Section, RollNo, ParentsMobileNo, StudentAddress, Gender, ParentsEmail); } catch (Exception err) { //string script = @"document.getElementById('" + dvUploadStatus.ClientID + "').innerHTML='Invalid data found in uploaded excel!!';var elem = document.createElement('img');elem.setAttribute('src', 'cross.jpg');document.getElementById('" + dvUploadStatus.ClientID + "').appendChild(elem);document.getElementById('" + dvUploadStatus.ClientID + "').style.color = 'Red';document.getElementById('" + dvUploadStatus.ClientID + "').style.fontSize = '1em' ;document.getElementById('" + dvUploadStatus.ClientID + "').style.fontWeight = 'bold' ;setTimeout(function(){document.getElementById('" + dvUploadStatus.ClientID + "').style.display='none';},4500);"; //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", script, true); isValidExcelSheet = false; string alertScript = "jAlert('Invalid data found in uploaded excel', 'Campus2Caretaker');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true); isValidExcelSheet = false; break; } } //6. Free resources (IExcelDataReader is IDisposable) excelReader.Close(); } catch (DataException ee) { //string script = @"document.getElementById('" + dvUploadStatus.ClientID + "').innerHTML='" + ee.Message + "';var elem = document.createElement('img');elem.setAttribute('src', 'cross.jpg');document.getElementById('" + dvUploadStatus.ClientID + "').appendChild(elem);document.getElementById('" + dvUploadStatus.ClientID + "').style.color = 'Red';document.getElementById('" + dvUploadStatus.ClientID + "').style.fontSize = '1em' ;document.getElementById('" + dvUploadStatus.ClientID + "').style.fontWeight = 'bold' ;setTimeout(function(){document.getElementById('" + dvUploadStatus.ClientID + "').style.display='none';},4500);"; //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", script, true); string alertScript = "jAlert('"+ ee.Message +"', 'Campus2Caretaker');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true); isValidExcelSheet = false; } finally { } return isValidExcelSheet; }
protected void btnSaveInternals_Click(object sender, EventArgs e) { for (int index = 0; index < gvInternals.Rows.Count - 1; index++) { if (int.Parse(((TextBox)gvInternals.Rows[index].FindControl("txtMarksScored")).Text) > 0) { DTOInternals toInt = new DTOInternals(); toInt.BranchId = int.Parse(ddlClass.SelectedValue); if (Session["InstituteType"].ToString() == "S") { toInt.SemesterId = 0; } else { toInt.SemesterId = int.Parse(ddlSemester.SelectedValue); } toInt.Month = ddlMonth.SelectedValue; toInt.Year = ddlYear.SelectedValue; toInt.SubjectId = int.Parse(ddlSubjects.SelectedValue); toInt.Description = txtDescription.Text; Label lblStudentID = (Label)gvInternals.Rows[index].FindControl("lblStudentID"); Label lblStudentName = (Label)gvInternals.Rows[index].FindControl("lblStudentName"); TextBox txtMaxMarks = (TextBox)gvInternals.Rows[index].FindControl("txtMaxMarks"); TextBox txtMinMarks = (TextBox)gvInternals.Rows[index].FindControl("txtMinMarks"); TextBox txtMarksScored = (TextBox)gvInternals.Rows[index].FindControl("txtMarksScored"); TextBox txtReMarks = (TextBox)gvInternals.Rows[index].FindControl("txtRemarks"); toInt.InstituteId = int.Parse(Session["InstituteID"].ToString()); toInt.MarksScored = decimal.Parse(txtMarksScored.Text); toInt.MaxMarks = decimal.Parse(txtMaxMarks.Text); toInt.MinMarks = decimal.Parse(txtMinMarks.Text); toInt.StudentId = int.Parse(lblStudentID.Text); toInt.Remarks = txtReMarks.Text; DTOStudentRegistration tostu = new DTOStudentRegistration(); tostu.StudentId = int.Parse(lblStudentID.Text); DataTable dtStudDet = new BOStudentRegistration().GetStudentDetails(tostu); if (new BOInternals().SaveUpdateInternals(toInt)) { #region SMS string _messageTemplate = new BOSms().GetSMSTemplate("INTERNALMARKSINTIMATION"); C2CSMS.SendSMS(_messageTemplate.Replace("##STUDENTNAME##", dtStudDet.Rows[0][0].ToString()).Replace("##INTERNALSMARKS##", String.Concat(toInt.MarksScored, " Out of ", toInt.MaxMarks)).Replace("##SUBJECTNAME##", ddlSubjects.SelectedItem.Text).Replace("##MONTHYEAR##", String.Concat(ddlMonth.SelectedItem.Text, string.Empty, ddlYear.SelectedItem.Text)).Replace("##InstituteName##", Session["InstituteName"].ToString()), dtStudDet.Rows[0][9].ToString()); #endregion #region E-Mail //Send mail if (!string.IsNullOrEmpty(dtStudDet.Rows[0][12].ToString())) { string s_subject = "Information From Campus2Caretaker"; string s_msg = String.Concat("Greetings from Campus2Caretaker.", Environment.NewLine, Environment.NewLine, _messageTemplate.Replace("##STUDENTNAME##", dtStudDet.Rows[0][0].ToString()).Replace("##INTERNALSMARKS##", String.Concat(toInt.MarksScored, " Out of ", toInt.MaxMarks)).Replace("##SUBJECTNAME##", ddlSubjects.SelectedItem.Text).Replace("##MONTHYEAR##", String.Concat(ddlMonth.SelectedItem.Text, string.Empty, ddlYear.SelectedItem.Text)).Replace("##InstituteName##", Session["InstituteName"].ToString())) + Environment.NewLine + Environment.NewLine; C2CEmail.SendC2CMail(s_msg, s_subject, string.Empty, dtStudDet.Rows[0][12].ToString(), null, null); } #endregion //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('Internals Details Saved Successfully', 'Campus2Caretaker');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", alertScript, true); } 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); } } } clear(); }
private void BindClassList() { DataTable dt = new BOStudentRegistration().GetClassesList(Session["InstituteID"].ToString()); ddlClass.DataSource = dt; ddlClass.DataBind(); ListItem Item = new ListItem("Select", "Select"); ddlClass.Items.Insert(0, Item); ddlClass.SelectedIndex = 0; }