private void Init_NewEntryID() { getspecifiedprefix = new GetSpecifiedPrefix(); Prefix_ID = getspecifiedprefix.GetSchoolYearPrefix(); string VerifyQuery = "SELECT COUNT(*) FROM [Tbl.SchoolYear]"; sqldataadapter = new SqlDataAdapter(VerifyQuery, sqlconnection); DataTable datatable = new DataTable(); sqldataadapter.Fill(datatable); //INCREMENT THE LAST SCHOOL YEAR ID if (int.Parse(datatable.Rows[0][0].ToString()) > 0) { sqlquery1 = "SELECT [ENTRY ID] FROM [Tbl.SchoolYear]"; sqlcommand = new SqlCommand(sqlquery1, sqlconnection); SqlDataReader sqldatareader = sqlcommand.ExecuteReader(); while (sqldatareader.Read()) { string str1 = sqldatareader.GetString(0); string str2 = str1.Remove(0, Prefix_ID.Length); NewEntryID = int.Parse(str2) + 1; } sqldatareader.Close(); } //ASSIGN NEW SCHOOL YEAR ID else if (datatable.Rows[0][0].ToString() == "0") { sqlquery2 = "SELECT SUFFIX FROM [Tbl.Defaults] WHERE [ENTRY NAME] = 'SCHOOL YEAR ID'"; sqlcommand = new SqlCommand(sqlquery2, sqlconnection); SqlDataReader sqldatareader2 = sqlcommand.ExecuteReader(); while (sqldatareader2.Read()) { string str2 = sqldatareader2.GetString(0); NewEntryID = int.Parse(str2); } sqldatareader2.Close(); } }
private void Init_NewSectionID() { getspecifiedprefix = new GetSpecifiedPrefix(); Prefix = getspecifiedprefix.GetSectionIDPrefix(); sqlquery1 = "SELECT COUNT(*) FROM [Tbl.Sections]"; sqldataadapter = new SqlDataAdapter(sqlquery1, sqlconnection); DataTable datatable = new DataTable(); sqldataadapter.Fill(datatable); //INCREMENT THE LAST SECTION ID if (int.Parse(datatable.Rows[0][0].ToString()) > 0) { sqlquery2 = "SELECT [SECTION ID] FROM [Tbl.Sections]"; sqlcommand = new SqlCommand(sqlquery2, sqlconnection); SqlDataReader sqldatareader = sqlcommand.ExecuteReader(); while (sqldatareader.Read()) { str1 = sqldatareader.GetString(0); str3 = str1.Remove(0, Prefix.Length); NewSectionID = int.Parse(str3) + 1; } sqldatareader.Close(); } //AUTO ASSIGN NEW SECTION ID else if (datatable.Rows[0][0].ToString() == "0") { sqlquery3 = "SELECT SUFFIX FROM [Tbl.Defaults] WHERE [ENTRY NAME] = '" + "SECTION ID" + "'"; sqlcommand = new SqlCommand(sqlquery3, sqlconnection); SqlDataReader sqldatareader1 = sqlcommand.ExecuteReader(); while (sqldatareader1.Read()) { str2 = sqldatareader1.GetString(0); NewSectionID = int.Parse(str2); } sqldatareader1.Close(); } }