Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.Script.Serialization;
- using System.Web.Script.Services;
- using System.Web.Services;
- using System.Web.Security;
- /// <summary>
- /// Summary description for AttendenceWebService
- /// </summary>
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
- // [System.Web.Script.Services.ScriptService]
- public class AttendenceWebService : System.Web.Services.WebService
- {
- protected string ConString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
- public AttendenceWebService()
- {
- //Uncomment the following line if using designed components
- //InitializeComponent();
- }
- [WebMethod]
- public string HelloWorld()
- {
- return "Hello World";
- }
- [WebMethod]
- [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
- public void GetSubjects()
- {
- List<Object> list = new List<Object>();
- //Context.Response.Write("Message: 'Hello World'");
- HttpContext.Current.Response.ContentType = "application/json";
- HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
- SqlConnection con = new SqlConnection(ConString);
- SqlCommand command = con.CreateCommand();
- command.CommandText = "SELECT [SubjectID],[SubjectName] FROM [pmc_mis].[dbo].[Student_Subjects]";
- con.Open();
- SqlDataReader reader = command.ExecuteReader();
- while (reader.Read())
- {
- Subject Sub = new Subject();
- Sub.ID = Convert.ToInt32(reader["SubjectID"]);
- Sub.Name = reader["SubjectName"].ToString();
- list.Add(Sub);
- }
- con.Close();
- JavaScriptSerializer js = new JavaScriptSerializer();
- HttpContext.Current.Response.Write(js.Serialize(list));
- }
- [WebMethod]
- [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
- public void getClassType()
- {
- List<Object> list = new List<Object>();
- //Context.Response.Write("Message: 'Hello World'");
- HttpContext.Current.Response.ContentType = "application/json";
- HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
- SqlConnection con = new SqlConnection(ConString);
- SqlCommand command = con.CreateCommand();
- command.CommandText = "SELECT [ClassTypeID],[ClassTypeName] FROM [pmc_mis].[dbo].[Student_TypeOfClass]";
- con.Open();
- SqlDataReader reader = command.ExecuteReader();
- while (reader.Read())
- {
- ClassType _ClassType = new ClassType();
- _ClassType.ID = Convert.ToInt32(reader["ClassTypeID"]);
- _ClassType.Name = reader["ClassTypeName"].ToString();
- list.Add(_ClassType);
- }
- con.Close();
- JavaScriptSerializer js = new JavaScriptSerializer();
- HttpContext.Current.Response.Write(js.Serialize(list));
- }
- [WebMethod]
- public void GetStudents()
- {
- List<Object> list = new List<Object>();
- SqlConnection con = new SqlConnection(ConString);
- SqlCommand cmd = con.CreateCommand();
- cmd.CommandText = "SELECT [ProfileID],[Name] FROM[pmc_mis].[dbo].[Student_Profile]";
- con.Open();
- SqlDataReader Reader = cmd.ExecuteReader();
- while (Reader.Read())
- {
- StudentInfoAjaxOne _StudentInfo = new StudentInfoAjaxOne();
- _StudentInfo.ID = Convert.ToString(Reader["ProfileID"]);
- _StudentInfo.Name = Convert.ToString(Reader["Name"]);
- list.Add(_StudentInfo);
- }
- con.Close();
- JavaScriptSerializer js = new JavaScriptSerializer();
- HttpContext.Current.Response.ContentType = "application/json";
- HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
- HttpContext.Current.Response.Write(js.Serialize(list));
- }
- [WebMethod]
- public void GetStudentInfoByID(String ID)
- {
- StudentInfoAjaxTwo _StudentInfo = new StudentInfoAjaxTwo();
- SqlConnection con = new SqlConnection(ConString);
- SqlCommand cmd = con.CreateCommand();
- cmd.CommandText = "SELECT [Student ID],[Name],[Session],[Batch],[Phase] FROM[pmc_mis].[dbo].[Student_Profile] WHERE [Student ID] = @studentid ";
- cmd.Parameters.AddWithValue("@studentid",ID);
- con.Open();
- SqlDataReader Reader = cmd.ExecuteReader();
- if (Reader.Read())
- {
- _StudentInfo.Status = 1;
- _StudentInfo.Name = Convert.ToString(Reader["Name"]);
- _StudentInfo.Batch = Convert.ToString(Reader["Batch"]);
- _StudentInfo.Phase = Convert.ToString(Reader["Phase"]);
- _StudentInfo.Session= Convert.ToString(Reader["Session"]);
- }else
- {
- _StudentInfo.Status = 0;
- }
- con.Close();
- JavaScriptSerializer js = new JavaScriptSerializer();
- HttpContext.Current.Response.ContentType = "application/json";
- HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
- HttpContext.Current.Response.Write(js.Serialize(_StudentInfo));
- }
- [WebMethod]
- public void SaveSingleAttendenceData(int Department, int ClassType, String ClassDay, String ClassTeacher, int Batch, int Phase, String Present, String Absent )
- {
- try
- {
- string userId = Membership.GetUser().ProviderUserKey.ToString();
- //int percentComplete = (int)Math.Round((double)(100 * DoneClass) / HeldClass);
- //int AbsentClass = HeldClass - DoneClass;
- SqlConnection con = new SqlConnection(ConString);
- SqlCommand cmd = con.CreateCommand();
- cmd.CommandText = "INSERT INTO [dbo].[Tmp_SingleStudentAddendence] ([TsaID] ,[AttendenceDate] ,[Phase] ,[Batch],[Department] ,[Teacher],[TypeOfClass] ,[Present] ,[Absent] ,[AddedBy] ,[ModifiedBy] ,[TimeAdded],[TimeModified],[Status]) VALUES ( NEWID(), @date , @phase , @batch, @department , @teacher , @classtype , @present , @absent , @addedby , @modifiedby , @timeadded , @timemodified , @status )";
- cmd.Parameters.AddWithValue("@date", Convert.ToDateTime(ClassDay));
- cmd.Parameters.AddWithValue("@phase", Phase);
- cmd.Parameters.AddWithValue("@batch", Batch);
- cmd.Parameters.AddWithValue("@department", Department);
- cmd.Parameters.AddWithValue("@teacher", ClassTeacher);
- cmd.Parameters.AddWithValue("@classtype", ClassType);
- cmd.Parameters.AddWithValue("@present", Present);
- cmd.Parameters.AddWithValue("@absent", Absent);
- cmd.Parameters.AddWithValue("@addedby", userId);
- cmd.Parameters.AddWithValue("@modifiedby", DBNull.Value);
- cmd.Parameters.AddWithValue("@timeadded", DateTime.Now);
- cmd.Parameters.AddWithValue("@timemodified", DBNull.Value);
- cmd.Parameters.AddWithValue("@status", 1);
- con.Open();
- int a = cmd.ExecuteNonQuery();
- con.Close();
- if (a > 0)
- {
- JavaScriptSerializer js = new JavaScriptSerializer();
- HttpContext.Current.Response.ContentType = "application/json";
- HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
- ResponseInfo _ResponseInfo = new ResponseInfo();
- _ResponseInfo.Status = 1;
- _ResponseInfo.Message = "Attendence Information Added Successfull and waiting for Approval";
- HttpContext.Current.Response.Write(js.Serialize(_ResponseInfo));
- }
- else
- {
- JavaScriptSerializer js = new JavaScriptSerializer();
- ResponseInfo _ResponseInfo = new ResponseInfo();
- _ResponseInfo.Status = 0;
- _ResponseInfo.Message = "Write to database failed.";
- HttpContext.Current.Response.ContentType = "application/json";
- HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
- HttpContext.Current.Response.Write(js.Serialize(_ResponseInfo));
- }
- }
- catch (SqlException Exc)
- {
- JavaScriptSerializer js = new JavaScriptSerializer();
- ResponseInfo _ResponseInfo = new ResponseInfo();
- _ResponseInfo.Status = 0;
- _ResponseInfo.Message = "Database Error: " + Exc.Message;
- HttpContext.Current.Response.ContentType = "application/json";
- HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
- HttpContext.Current.Response.Write(js.Serialize(_ResponseInfo));
- }
- }
- [WebMethod]
- public void GetTeachers()
- {
- List<Object> list = new List<Object>();
- var TeacherList = Roles.GetUsersInRole("Teacher").Select(Membership.GetUser).ToList();
- foreach (var Teacher in TeacherList)
- {
- TeacherInfo2 _TeacherInfo = new TeacherInfo2();
- _TeacherInfo.ID = Teacher.ProviderUserKey.ToString();
- _TeacherInfo.Name = Teacher.UserName;
- list.Add(_TeacherInfo);
- }
- JavaScriptSerializer js = new JavaScriptSerializer();
- HttpContext.Current.Response.ContentType = "application/json";
- HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
- HttpContext.Current.Response.Write(js.Serialize(list));
- }
- [WebMethod]
- public void getPhaseList()
- {
- List<Object> list = new List<Object>();
- //Context.Response.Write("{Message: 'Hello World'}");
- SqlConnection con = new SqlConnection(ConString);
- SqlCommand command = con.CreateCommand();
- command.CommandText = "SELECT [PhaseID],[PhaseName] FROM [pmc_mis].[dbo].[Student_Phase]";
- con.Open();
- SqlDataReader reader = command.ExecuteReader();
- while (reader.Read())
- {
- PhaseInfo _PhaseInfo = new PhaseInfo();
- _PhaseInfo.ID = Convert.ToInt32(reader["PhaseID"]);
- _PhaseInfo.Name = reader["PhaseName"].ToString();
- list.Add(_PhaseInfo);
- }
- con.Close();
- JavaScriptSerializer js = new JavaScriptSerializer();
- HttpContext.Current.Response.ContentType = "application/json";
- HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
- HttpContext.Current.Response.Write(js.Serialize(list));
- }
- [WebMethod]
- public void getBatchList()
- {
- List<Object> list = new List<Object>();
- SqlConnection con = new SqlConnection(ConString);
- SqlCommand command = con.CreateCommand();
- command.CommandText = "SELECT [BatchID] , [BatchName] FROM [dbo].[Student_Batch] WHERE IsEnabled = 1";
- con.Open();
- SqlDataReader reader = command.ExecuteReader();
- while (reader.Read())
- {
- Common _Common = new Common();
- _Common.ID = Convert.ToString(reader["BatchID"]);
- _Common.Name = Convert.ToString(reader["BatchName"]);
- list.Add(_Common);
- }
- con.Close();
- JavaScriptSerializer js = new JavaScriptSerializer();
- HttpContext.Current.Response.ContentType = "application/json";
- HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
- HttpContext.Current.Response.Write(js.Serialize(list));
- }
- [WebMethod]
- public void getClassTime()
- {
- List<Object> list = new List<Object>();
- //Context.Response.Write("{Message: 'Hello World'}");
- SqlConnection con = new SqlConnection(ConString);
- SqlCommand command = con.CreateCommand();
- command.CommandText = "SELECT [ClassTimeID],CONVERT(varchar(15),CAST([FromTime] AS TIME),100) AS [FromTime],CONVERT(varchar(15),CAST([ToTime] AS TIME),100) AS [ToTime] FROM [pmc_mis].[dbo].[Student_ClassTime]";
- con.Open();
- SqlDataReader reader = command.ExecuteReader();
- while (reader.Read())
- {
- PhaseInfo _PhaseInfo = new PhaseInfo();
- _PhaseInfo.ID = Convert.ToInt32(reader["ClassTimeID"]);
- _PhaseInfo.Name = reader["FromTime"].ToString() + " - " + reader["ToTime"].ToString();
- list.Add(_PhaseInfo);
- }
- con.Close();
- JavaScriptSerializer js = new JavaScriptSerializer();
- HttpContext.Current.Response.ContentType = "application/json";
- HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
- HttpContext.Current.Response.Write(js.Serialize(list));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement