protected void Application_Error(object sender, EventArgs e) { try { var currentContext = ((MvcApplication)sender).Context; var currentRoutData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(currentContext)); var currentAction = ""; var currentController = ""; if (currentRoutData != null) { if (currentRoutData.Values["Controller"] != null && !string.IsNullOrEmpty(currentRoutData.Values["Controller"].ToString())) { currentController = currentRoutData.Values["Controller"].ToString(); } if (currentRoutData.Values["Action"] != null && !string.IsNullOrEmpty(currentRoutData.Values["Action"].ToString())) { currentAction = currentRoutData.Values["Action"].ToString(); } } var exception = Server.GetLastError(); var errorController = new ErrorController(); var routeData = new RouteData(); var ActionName = "ErrorInfo"; //Log Error //Get current user id User objUsr = (User)eSchoolSession.GetDirectValue(SessionKeys.CurrentUser); string userId = string.Empty; if (objUsr != null) { if (!string.IsNullOrEmpty(objUsr.UserID)) userId = objUsr.UserID; } eSchoolExceptionManagement logExpection = new eSchoolExceptionManagement(); logExpection.ManageException(Server.GetLastError().GetBaseException(), true, eSchoolExceptionManagement.ErrorLogType.Database, userId); if (exception is HttpException) { var ex = exception as HttpException; switch (ex.ErrorCode) { case 404: ActionName = "NotFound"; break; default: ActionName = "ErrorInfo"; break; } } currentContext.ClearError(); currentContext.Response.Clear(); currentContext.Response.StatusCode = exception is HttpException ? ((HttpException)exception).GetHttpCode() : 500; currentContext.Response.TrySkipIisCustomErrors = true; routeData.Values["Controller"] = "Error"; routeData.Values["Action"] = ActionName; errorController.ViewData.Model = new HandleErrorInfo(exception, currentController, currentAction); ((IController)errorController).Execute(new RequestContext(new HttpContextWrapper(currentContext), routeData)); } catch (Exception ex) { } }
public bool UploadFromExcelFile(Student entity) { OleDbConnection cnn = null; try { if (!string.IsNullOrEmpty(entity.StudentExcelFilePath)) { cnn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + entity.StudentExcelFilePath + "; Extended Properties=Excel 12.0;"); OleDbCommand oconn = new OleDbCommand("select * from [Students$]", cnn); cnn.Open(); OleDbDataAdapter adp = new OleDbDataAdapter(oconn); DataTable dt = new DataTable(); adp.Fill(dt); cnn.Close(); if (dt != null && dt.Rows.Count > 0) { DataColumnCollection columns = dt.Columns; Student objStudent = null; StudentsParent objStudentsParent = null; StudentsMedical objStudentsMedical = null; StudentsTransport objStudentsTransport = null; int i = 0; foreach (DataRow row in dt.Rows) { objStudent = new Student(); objStudentsParent = new StudentsParent(); objStudentsMedical = new StudentsMedical(); objStudentsTransport = new StudentsTransport(); #region Students Information if (columns.Contains("Form No") && !string.IsNullOrEmpty(Convert.ToString(row["Form No"]))) objStudent.FormNo = Convert.ToString(row["Form No"]).Trim(); if (columns.Contains("Temp Student ID") && !string.IsNullOrEmpty(Convert.ToString(row["Temp Student ID"]))) objStudent.TempStudentID = Convert.ToString(row["Temp Student ID"]).Trim(); if (columns.Contains("GR No") && !string.IsNullOrEmpty(Convert.ToString(row["GR No"]))) objStudent.GRNo = Convert.ToString(row["GR No"]).Trim(); if (columns.Contains("Admission Type") && !string.IsNullOrEmpty(Convert.ToString(row["Admission Type"]))) objStudent.AdmissionType = Convert.ToString(row["Admission Type"]).Trim(); if (columns.Contains("Academic Year") && !string.IsNullOrEmpty(Convert.ToString(row["Academic Year"]))) { AcademicYear obj = new AcademicYear(); obj.AcademicName = Convert.ToString(row["Academic Year"]); obj = _AcademicYearService.GetByName(obj); if (obj != null && !string.IsNullOrEmpty(obj.AcademicYearID)) objStudent.CurrentAcademicYearID = obj.AcademicYearID; } if (columns.Contains("Class") && !string.IsNullOrEmpty(Convert.ToString(row["Class"]))) { Class obj = new Class(); obj.ClassName = Convert.ToString(row["Class"]); obj = _ClassService.GetByName(obj); if (obj != null && !string.IsNullOrEmpty(obj.ClassID)) objStudent.CurrentClassID = obj.ClassID; } if (columns.Contains("Section") && !string.IsNullOrEmpty(Convert.ToString(row["Section"]))) { Section obj = new Section(); obj.SectionName = Convert.ToString(row["Section"]); obj = _SectionService.GetByName(obj); if (obj != null && !string.IsNullOrEmpty(obj.SectionID)) objStudent.CurrentSectionID = obj.SectionID; } if (columns.Contains("Admission Date") && !string.IsNullOrEmpty(Convert.ToString(row["Admission Date"]))) objStudent.AdmissionDate = Convert.ToDateTime(row["Admission Date"]); if (columns.Contains("First Name") && !string.IsNullOrEmpty(Convert.ToString(row["First Name"]))) objStudent.FirstName = Convert.ToString(row["First Name"]).Trim(); if (columns.Contains("Middle Name") && !string.IsNullOrEmpty(Convert.ToString(row["Middle Name"]))) objStudent.MiddleName = Convert.ToString(row["Middle Name"]).Trim(); if (columns.Contains("Last Name") && !string.IsNullOrEmpty(Convert.ToString(row["Last Name"]))) objStudent.LastName = Convert.ToString(row["Last Name"]).Trim(); if (columns.Contains("Gender") && !string.IsNullOrEmpty(Convert.ToString(row["Gender"]))) objStudent.Gender = Convert.ToString(row["Gender"]).Trim(); if (columns.Contains("DOB") && !string.IsNullOrEmpty(Convert.ToString(row["DOB"]))) objStudent.DOB = Convert.ToDateTime(row["DOB"]); if (columns.Contains("Age As On") && !string.IsNullOrEmpty(Convert.ToString(row["Age As On"]))) objStudent.AgeAsOn = Convert.ToDateTime(row["Age As On"]); if (columns.Contains("Place Of Birth Taluka") && !string.IsNullOrEmpty(Convert.ToString(row["Place Of Birth Taluka"]))) objStudent.PlaceOfBirthTaluka = Convert.ToString(row["Place Of Birth Taluka"]).Trim(); if (columns.Contains("Place Of Birth District") && !string.IsNullOrEmpty(Convert.ToString(row["Place Of Birth District"]))) objStudent.PlaceOfBirthDistrict = Convert.ToString(row["Place Of Birth District"]).Trim(); if (columns.Contains("Mother Tongue") && !string.IsNullOrEmpty(Convert.ToString(row["Mother Tongue"]))) objStudent.MotherTongue = Convert.ToString(row["Mother Tongue"]).Trim(); if (columns.Contains("Nationality") && !string.IsNullOrEmpty(Convert.ToString(row["Nationality"]))) objStudent.Nationality = Convert.ToString(row["Nationality"]).Trim(); if (columns.Contains("Permanant Address") && !string.IsNullOrEmpty(Convert.ToString(row["Permanant Address"]))) objStudent.PermanantAddress = Convert.ToString(row["Permanant Address"]).Trim(); if (columns.Contains("Local Address") && !string.IsNullOrEmpty(Convert.ToString(row["Local Address"]))) objStudent.LocalAddress = Convert.ToString(row["Local Address"]).Trim(); if (columns.Contains("Native State") && !string.IsNullOrEmpty(Convert.ToString(row["Native State"]))) objStudent.NativeState = Convert.ToString(row["Native State"]).Trim(); if (columns.Contains("Category") && !string.IsNullOrEmpty(Convert.ToString(row["Category"]))) objStudent.Category = Convert.ToString(row["Category"]).Trim(); if (columns.Contains("Religion") && !string.IsNullOrEmpty(Convert.ToString(row["Religion"]))) objStudent.Religion = Convert.ToString(row["Religion"]).Trim(); if (columns.Contains("Caste") && !string.IsNullOrEmpty(Convert.ToString(row["Caste"]))) objStudent.Caste = Convert.ToString(row["Caste"]).Trim(); if (columns.Contains("Sub Caste") && !string.IsNullOrEmpty(Convert.ToString(row["Sub Caste"]))) objStudent.SubCaste = Convert.ToString(row["Sub Caste"]).Trim(); if (columns.Contains("Last School Attended") && !string.IsNullOrEmpty(Convert.ToString(row["Last School Attended"]))) objStudent.LastSchoolAttended = Convert.ToString(row["Last School Attended"]).Trim(); if (columns.Contains("Phone No") && !string.IsNullOrEmpty(Convert.ToString(row["Phone No"]))) objStudent.PhoneNo = Convert.ToInt32(row["Phone No"]); if (columns.Contains("Reason For Transfer") && !string.IsNullOrEmpty(Convert.ToString(row["Reason For Transfer"]))) objStudent.ReasonForTransfer = Convert.ToString(row["Reason For Transfer"]).Trim(); if (columns.Contains("Date Of Leaving School") && !string.IsNullOrEmpty(Convert.ToString(row["Date Of Leaving School"]))) objStudent.DateOfLeavingSchool = Convert.ToDateTime(row["Date Of Leaving School"]); if (columns.Contains("Remark") && !string.IsNullOrEmpty(Convert.ToString(row["Remark"]))) objStudent.Remark = Convert.ToString(row["Remark"]).Trim(); if (columns.Contains("TC Date") && !string.IsNullOrEmpty(Convert.ToString(row["TC Date"]))) objStudent.TCDate = Convert.ToDateTime(row["TC Date"]); if (columns.Contains("TC Number") && !string.IsNullOrEmpty(Convert.ToString(row["TC Number"]))) objStudent.TCNumber = Convert.ToString(row["TC Number"]).Trim(); i = AddEdit(objStudent); #endregion #region Parents Information if (i > 0 && !string.IsNullOrEmpty(objStudent.StudentID)) { objStudentsParent.StudentID = objStudent.StudentID; if (columns.Contains("Fathers Name") && !string.IsNullOrEmpty(Convert.ToString(row["Fathers Name"]))) objStudentsParent.FathersName = Convert.ToString(row["Fathers Name"]).Trim(); if (columns.Contains("Mothers Name") && !string.IsNullOrEmpty(Convert.ToString(row["Mothers Name"]))) objStudentsParent.MothersName = Convert.ToString(row["Mothers Name"]).Trim(); if (columns.Contains("Ph No Resident") && !string.IsNullOrEmpty(Convert.ToString(row["Ph No Resident"]))) objStudentsParent.PhNoResident = Convert.ToInt32(row["Ph No Resident"]); if (columns.Contains("Ph No Office") && !string.IsNullOrEmpty(Convert.ToString(row["Ph No Office"]))) objStudentsParent.PhNoOffice = Convert.ToInt32(row["Ph No Office"]); if (columns.Contains("Mobile No") && !string.IsNullOrEmpty(Convert.ToString(row["Mobile No"]))) objStudentsParent.MobileNo = Convert.ToInt32(row["Mobile No"]); if (columns.Contains("Email Address") && !string.IsNullOrEmpty(Convert.ToString(row["Email Address"]))) objStudentsParent.EmailAddress = Convert.ToString(row["Email Address"]).Trim(); if (columns.Contains("Qualification") && !string.IsNullOrEmpty(Convert.ToString(row["Qualification"]))) objStudentsParent.Qualification = Convert.ToString(row["Qualification"]).Trim(); if (columns.Contains("Fathers Occupation") && !string.IsNullOrEmpty(Convert.ToString(row["Fathers Occupation"]))) objStudentsParent.FathersOccupation = Convert.ToString(row["Fathers Occupation"]).Trim(); if (columns.Contains("Mothers Occupation") && !string.IsNullOrEmpty(Convert.ToString(row["Mothers Occupation"]))) objStudentsParent.MothersOccupation = Convert.ToString(row["Mothers Occupation"]).Trim(); if (columns.Contains("Fathers Annual Income") && !string.IsNullOrEmpty(Convert.ToString(row["Fathers Annual Income"]))) objStudentsParent.FathersAnnualIncome = Convert.ToString(row["Fathers Annual Income"]).Trim(); if (columns.Contains("Mothers Annual Income") && !string.IsNullOrEmpty(Convert.ToString(row["Mothers Annual Income"]))) objStudentsParent.MothersAnnualIncome = Convert.ToString(row["Mothers Annual Income"]).Trim(); if (columns.Contains("Total Annual Income") && !string.IsNullOrEmpty(Convert.ToString(row["Total Annual Income"]))) objStudentsParent.TotalAnnualIncome = Convert.ToString(row["Total Annual Income"]).Trim(); if (columns.Contains("Total Family Members") && !string.IsNullOrEmpty(Convert.ToString(row["Total Family Members"]))) objStudentsParent.TotalFamilyMembers = Convert.ToInt32(row["Total Family Members"]); if (columns.Contains("Guardian") && !string.IsNullOrEmpty(Convert.ToString(row["Guardian"]))) objStudentsParent.Guardian = Convert.ToString(row["Guardian"]).Trim(); if (columns.Contains("Guardian Address") && !string.IsNullOrEmpty(Convert.ToString(row["Guardian Address"]))) objStudentsParent.GuardianAddress = Convert.ToString(row["Guardian Address"]).Trim(); if (columns.Contains("Guardian Mobile") && !string.IsNullOrEmpty(Convert.ToString(row["Guardian Mobile"]))) objStudentsParent.GuardianMobile = Convert.ToInt32(row["Guardian Mobile"]); if (columns.Contains("Guardian Email") && !string.IsNullOrEmpty(Convert.ToString(row["Guardian Email"]))) objStudentsParent.GuardianEmail = Convert.ToString(row["Guardian Email"]).Trim(); if (columns.Contains("Guardian Relationship With Student") && !string.IsNullOrEmpty(Convert.ToString(row["Guardian Relationship With Student"]))) objStudentsParent.GuardianRelationshipWithStudent = Convert.ToString(row["Guardian Relationship With Student"]).Trim(); _IStudentsParentService.AddEdit(objStudentsParent); } #endregion #region Medical Information if (i > 0 && !string.IsNullOrEmpty(objStudent.StudentID)) { objStudentsMedical.StudentID = objStudent.StudentID; if (columns.Contains("Blood Group") && !string.IsNullOrEmpty(Convert.ToString(row["Blood Group"]))) objStudentsMedical.BloodGroup = Convert.ToString(row["Blood Group"]).Trim(); if (columns.Contains("Any Physical Handicap Or Disability") && !string.IsNullOrEmpty(Convert.ToString(row["Any Physical Handicap Or Disability"]))) { if (Convert.ToString(row["Any Physical Handicap Or Disability"]).Trim() == "Yes") objStudentsMedical.AnyPhysicalHandicapOrDisability = true; else if (Convert.ToString(row["Any Physical Handicap Or Disability"]).Trim() == "No") objStudentsMedical.AnyPhysicalHandicapOrDisability = false; } if (columns.Contains("Physical Handicap Or Disability Desc") && !string.IsNullOrEmpty(Convert.ToString(row["Physical Handicap Or Disability Desc"]))) objStudentsMedical.PhysicalHandicapOrDisabilityDesc = Convert.ToString(row["Physical Handicap Or Disability Desc"]).Trim(); if (columns.Contains("Any Other Health Problems") && !string.IsNullOrEmpty(Convert.ToString(row["Any Other Health Problems"]))) { if (Convert.ToString(row["Any Other Health Problems"]).Trim() == "Yes") objStudentsMedical.AnyOtherHealthProblems = true; else if (Convert.ToString(row["Any Other Health Problems"]).Trim() == "No") objStudentsMedical.AnyOtherHealthProblems = false; } if (columns.Contains("Other Health Problems Desc") && !string.IsNullOrEmpty(Convert.ToString(row["Other Health Problems Desc"]))) objStudentsMedical.OtherHealthProblemsDesc = Convert.ToString(row["Other Health Problems Desc"]).Trim(); if (columns.Contains("Allergies Or Chronic Ailments") && !string.IsNullOrEmpty(Convert.ToString(row["Allergies Or Chronic Ailments"]))) objStudentsMedical.AllergiesOrChronicAilments = Convert.ToString(row["Allergies Or Chronic Ailments"]).Trim(); _IStudentsMedicalService.AddEdit(objStudentsMedical); } #endregion #region Transport Information if (i > 0 && !string.IsNullOrEmpty(objStudent.StudentID)) { objStudentsTransport.StudentID = objStudent.StudentID; if (columns.Contains("School Vehicle Opted") && !string.IsNullOrEmpty(Convert.ToString(row["School Vehicle Opted"]))) { if (Convert.ToString(row["School Vehicle Opted"]).Trim() == "Yes") objStudentsTransport.SchoolVehicleOpted = true; else if (Convert.ToString(row["School Vehicle Opted"]).Trim() == "No") objStudentsTransport.SchoolVehicleOpted = false; } if (columns.Contains("Mode Of Transport") && !string.IsNullOrEmpty(Convert.ToString(row["Mode Of Transport"]))) objStudentsTransport.ModeOfTransport = Convert.ToString(row["Mode Of Transport"]).Trim(); if (columns.Contains("Area") && !string.IsNullOrEmpty(Convert.ToString(row["Area"]))) { Area obj = new Area(); obj.AreaName = Convert.ToString(row["Area"]); obj = _AreaService.GetByName(obj); if (obj != null && !string.IsNullOrEmpty(obj.AreaID)) objStudentsTransport.AreaID = obj.AreaID; } if (columns.Contains("Bus No") && !string.IsNullOrEmpty(Convert.ToString(row["Bus No"]))) objStudentsTransport.BusNo = Convert.ToString(row["Bus No"]).Trim(); if (columns.Contains("In Time Hr") && !string.IsNullOrEmpty(Convert.ToString(row["In Time Hr"]))) objStudentsTransport.BusInTimeHr = Convert.ToInt32(row["In Time Hr"]); if (columns.Contains("In Time Min") && !string.IsNullOrEmpty(Convert.ToString(row["In Time Min"]))) objStudentsTransport.BusInTimeMin = Convert.ToInt32(row["In Time Min"]); if (columns.Contains("In Time AM PM") && !string.IsNullOrEmpty(Convert.ToString(row["In Time AM PM"]))) objStudentsTransport.BusInTimeAMPM = Convert.ToString(row["In Time AM PM"]).Trim(); if (columns.Contains("Out Time Hr") && !string.IsNullOrEmpty(Convert.ToString(row["Out Time Hr"]))) objStudentsTransport.BusOutTimeHr = Convert.ToInt32(row["Out Time Hr"]); if (columns.Contains("Out Time Min") && !string.IsNullOrEmpty(Convert.ToString(row["Out Time Min"]))) objStudentsTransport.BusOutTimeMin = Convert.ToInt32(row["Out Time Min"]); if (columns.Contains("Out Time AM PM") && !string.IsNullOrEmpty(Convert.ToString(row["Out Time AM PM"]))) objStudentsTransport.BusOutTimeAMPM = Convert.ToString(row["Out Time AM PM"]).Trim(); _IStudentsTransportService.AddEdit(objStudentsTransport); } #endregion } } if (File.Exists(entity.StudentExcelFilePath)) File.Delete(entity.StudentExcelFilePath); } } catch (Exception ex) { eSchoolExceptionManagement logExpection = new eSchoolExceptionManagement(); logExpection.ManageException(ex, true, eSchoolExceptionManagement.ErrorLogType.Database, "1"); cnn.Close(); } finally { cnn.Close(); } return true; }