Advertisement
touhid_xml

AttendenceWebService.cs

Apr 2nd, 2017
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 13.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Script.Serialization;
  8. using System.Web.Script.Services;
  9. using System.Web.Services;
  10. using System.Web.Security;
  11.  
  12. /// <summary>
  13. /// Summary description for AttendenceWebService
  14. /// </summary>
  15. [WebService(Namespace = "http://tempuri.org/")]
  16. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  17. // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
  18. // [System.Web.Script.Services.ScriptService]
  19. public class AttendenceWebService : System.Web.Services.WebService
  20. {
  21.     protected string ConString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
  22.     public AttendenceWebService()
  23.     {
  24.  
  25.         //Uncomment the following line if using designed components
  26.         //InitializeComponent();
  27.     }
  28.  
  29.     [WebMethod]
  30.     public string HelloWorld()
  31.     {
  32.         return "Hello World";
  33.     }
  34.  
  35.     [WebMethod]
  36.     [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  37.     public void GetSubjects()
  38.     {
  39.         List<Object> list = new List<Object>();
  40.  
  41.         //Context.Response.Write("Message: 'Hello World'");
  42.         HttpContext.Current.Response.ContentType = "application/json";
  43.         HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
  44.  
  45.  
  46.         SqlConnection con = new SqlConnection(ConString);
  47.         SqlCommand command = con.CreateCommand();
  48.         command.CommandText = "SELECT [SubjectID],[SubjectName] FROM [pmc_mis].[dbo].[Student_Subjects]";
  49.  
  50.  
  51.         con.Open();
  52.         SqlDataReader reader = command.ExecuteReader();
  53.         while (reader.Read())
  54.         {
  55.             Subject Sub = new Subject();
  56.             Sub.ID = Convert.ToInt32(reader["SubjectID"]);
  57.             Sub.Name = reader["SubjectName"].ToString();
  58.             list.Add(Sub);
  59.         }
  60.  
  61.  
  62.         con.Close();
  63.  
  64.         JavaScriptSerializer js = new JavaScriptSerializer();
  65.  
  66.  
  67.         HttpContext.Current.Response.Write(js.Serialize(list));
  68.     }
  69.  
  70.  
  71.     [WebMethod]
  72.     [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  73.     public void getClassType()
  74.     {
  75.         List<Object> list = new List<Object>();
  76.  
  77.         //Context.Response.Write("Message: 'Hello World'");
  78.         HttpContext.Current.Response.ContentType = "application/json";
  79.         HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
  80.  
  81.  
  82.         SqlConnection con = new SqlConnection(ConString);
  83.         SqlCommand command = con.CreateCommand();
  84.         command.CommandText = "SELECT  [ClassTypeID],[ClassTypeName] FROM [pmc_mis].[dbo].[Student_TypeOfClass]";
  85.        
  86.  
  87.         con.Open();
  88.         SqlDataReader reader = command.ExecuteReader();
  89.         while (reader.Read())
  90.         {
  91.             ClassType _ClassType = new ClassType();
  92.             _ClassType.ID = Convert.ToInt32(reader["ClassTypeID"]);
  93.             _ClassType.Name = reader["ClassTypeName"].ToString();
  94.             list.Add(_ClassType);
  95.         }
  96.  
  97.  
  98.         con.Close();
  99.  
  100.         JavaScriptSerializer js = new JavaScriptSerializer();
  101.  
  102.  
  103.         HttpContext.Current.Response.Write(js.Serialize(list));
  104.     }
  105.  
  106.  
  107.  
  108.  
  109.     [WebMethod]
  110.     public void GetStudents()
  111.     {
  112.         List<Object> list = new List<Object>();
  113.         SqlConnection con = new SqlConnection(ConString);
  114.         SqlCommand cmd = con.CreateCommand();
  115.         cmd.CommandText = "SELECT [ProfileID],[Name] FROM[pmc_mis].[dbo].[Student_Profile]";
  116.        
  117.         con.Open();
  118.         SqlDataReader Reader = cmd.ExecuteReader();
  119.         while (Reader.Read())
  120.         {
  121.             StudentInfoAjaxOne _StudentInfo = new StudentInfoAjaxOne();
  122.             _StudentInfo.ID = Convert.ToString(Reader["ProfileID"]);
  123.             _StudentInfo.Name = Convert.ToString(Reader["Name"]);
  124.             list.Add(_StudentInfo);
  125.         }
  126.  
  127.         con.Close();
  128.  
  129.         JavaScriptSerializer js = new JavaScriptSerializer();
  130.         HttpContext.Current.Response.ContentType = "application/json";
  131.         HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
  132.  
  133.         HttpContext.Current.Response.Write(js.Serialize(list));
  134.  
  135.     }
  136.  
  137.  
  138.     [WebMethod]
  139.     public void GetStudentInfoByID(String ID)
  140.     {
  141.         StudentInfoAjaxTwo _StudentInfo = new StudentInfoAjaxTwo();
  142.         SqlConnection con = new SqlConnection(ConString);
  143.         SqlCommand cmd = con.CreateCommand();
  144.         cmd.CommandText = "SELECT [Student ID],[Name],[Session],[Batch],[Phase] FROM[pmc_mis].[dbo].[Student_Profile] WHERE [Student ID] = @studentid ";
  145.         cmd.Parameters.AddWithValue("@studentid",ID);
  146.  
  147.         con.Open();
  148.         SqlDataReader Reader = cmd.ExecuteReader();
  149.         if (Reader.Read())
  150.         {
  151.             _StudentInfo.Status = 1;
  152.             _StudentInfo.Name = Convert.ToString(Reader["Name"]);
  153.             _StudentInfo.Batch = Convert.ToString(Reader["Batch"]);
  154.             _StudentInfo.Phase = Convert.ToString(Reader["Phase"]);
  155.             _StudentInfo.Session= Convert.ToString(Reader["Session"]);
  156.         }else
  157.         {
  158.             _StudentInfo.Status = 0;
  159.         }
  160.        
  161.  
  162.         con.Close();
  163.  
  164.         JavaScriptSerializer js = new JavaScriptSerializer();
  165.  
  166.         HttpContext.Current.Response.ContentType = "application/json";
  167.         HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
  168.         HttpContext.Current.Response.Write(js.Serialize(_StudentInfo));
  169.     }
  170.  
  171.     [WebMethod]
  172.     public void SaveSingleAttendenceData(int Department, int ClassType, String ClassDay, String ClassTeacher, int Batch, int Phase, String Present, String Absent )
  173.     {
  174.  
  175.         try
  176.         {
  177.             string userId = Membership.GetUser().ProviderUserKey.ToString();
  178.             //int percentComplete = (int)Math.Round((double)(100 * DoneClass) / HeldClass);
  179.             //int AbsentClass = HeldClass - DoneClass;
  180.             SqlConnection con = new SqlConnection(ConString);
  181.             SqlCommand cmd = con.CreateCommand();
  182.             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 )";
  183.            
  184.             cmd.Parameters.AddWithValue("@date", Convert.ToDateTime(ClassDay));
  185.             cmd.Parameters.AddWithValue("@phase", Phase);
  186.             cmd.Parameters.AddWithValue("@batch", Batch);
  187.             cmd.Parameters.AddWithValue("@department", Department);
  188.             cmd.Parameters.AddWithValue("@teacher", ClassTeacher);
  189.             cmd.Parameters.AddWithValue("@classtype", ClassType);
  190.             cmd.Parameters.AddWithValue("@present", Present);
  191.             cmd.Parameters.AddWithValue("@absent", Absent);
  192.             cmd.Parameters.AddWithValue("@addedby", userId);
  193.             cmd.Parameters.AddWithValue("@modifiedby", DBNull.Value);
  194.             cmd.Parameters.AddWithValue("@timeadded", DateTime.Now);
  195.             cmd.Parameters.AddWithValue("@timemodified", DBNull.Value);
  196.             cmd.Parameters.AddWithValue("@status", 1);
  197.  
  198.  
  199.             con.Open();
  200.             int a = cmd.ExecuteNonQuery();
  201.             con.Close();
  202.             if (a > 0)
  203.             {
  204.                 JavaScriptSerializer js = new JavaScriptSerializer();
  205.  
  206.                 HttpContext.Current.Response.ContentType = "application/json";
  207.                 HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
  208.                 ResponseInfo _ResponseInfo = new ResponseInfo();
  209.                 _ResponseInfo.Status = 1;
  210.                 _ResponseInfo.Message = "Attendence Information Added Successfull and waiting for Approval";
  211.                 HttpContext.Current.Response.Write(js.Serialize(_ResponseInfo));
  212.             }
  213.             else
  214.             {
  215.                 JavaScriptSerializer js = new JavaScriptSerializer();
  216.                 ResponseInfo _ResponseInfo = new ResponseInfo();
  217.                 _ResponseInfo.Status = 0;
  218.                 _ResponseInfo.Message = "Write to database failed.";
  219.  
  220.                 HttpContext.Current.Response.ContentType = "application/json";
  221.                 HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
  222.                 HttpContext.Current.Response.Write(js.Serialize(_ResponseInfo));
  223.             }
  224.        
  225.         }
  226.         catch (SqlException Exc)
  227.         {
  228.             JavaScriptSerializer js = new JavaScriptSerializer();
  229.             ResponseInfo _ResponseInfo = new ResponseInfo();
  230.             _ResponseInfo.Status = 0;
  231.             _ResponseInfo.Message = "Database Error: " + Exc.Message;
  232.  
  233.             HttpContext.Current.Response.ContentType = "application/json";
  234.             HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
  235.             HttpContext.Current.Response.Write(js.Serialize(_ResponseInfo));
  236.         }
  237.     }
  238.  
  239.     [WebMethod]
  240.     public void GetTeachers()
  241.     {
  242.         List<Object> list = new List<Object>();
  243.         var TeacherList = Roles.GetUsersInRole("Teacher").Select(Membership.GetUser).ToList();
  244.  
  245.         foreach (var Teacher in TeacherList)
  246.         {
  247.             TeacherInfo2 _TeacherInfo = new TeacherInfo2();
  248.             _TeacherInfo.ID = Teacher.ProviderUserKey.ToString();
  249.             _TeacherInfo.Name = Teacher.UserName;
  250.             list.Add(_TeacherInfo);
  251.         }
  252.        
  253.         JavaScriptSerializer js = new JavaScriptSerializer();
  254.         HttpContext.Current.Response.ContentType = "application/json";
  255.         HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
  256.         HttpContext.Current.Response.Write(js.Serialize(list));
  257.        
  258.     }
  259.  
  260.  
  261.  
  262.     [WebMethod]
  263.     public void getPhaseList()
  264.     {
  265.         List<Object> list = new List<Object>();
  266.  
  267.         //Context.Response.Write("{Message: 'Hello World'}");
  268.  
  269.         SqlConnection con = new SqlConnection(ConString);
  270.         SqlCommand command = con.CreateCommand();
  271.         command.CommandText = "SELECT [PhaseID],[PhaseName] FROM [pmc_mis].[dbo].[Student_Phase]";
  272.  
  273.  
  274.         con.Open();
  275.         SqlDataReader reader = command.ExecuteReader();
  276.         while (reader.Read())
  277.         {
  278.             PhaseInfo _PhaseInfo = new PhaseInfo();
  279.             _PhaseInfo.ID = Convert.ToInt32(reader["PhaseID"]);
  280.             _PhaseInfo.Name = reader["PhaseName"].ToString();
  281.             list.Add(_PhaseInfo);
  282.         }
  283.  
  284.  
  285.         con.Close();
  286.  
  287.         JavaScriptSerializer js = new JavaScriptSerializer();
  288.         HttpContext.Current.Response.ContentType = "application/json";
  289.         HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
  290.  
  291.         HttpContext.Current.Response.Write(js.Serialize(list));
  292.  
  293.  
  294.     }
  295.  
  296.  
  297.     [WebMethod]
  298.     public void getBatchList()
  299.     {
  300.         List<Object> list = new List<Object>();
  301.         SqlConnection con = new SqlConnection(ConString);
  302.         SqlCommand command = con.CreateCommand();
  303.         command.CommandText = "SELECT  [BatchID] , [BatchName] FROM [dbo].[Student_Batch] WHERE IsEnabled = 1";
  304.  
  305.         con.Open();
  306.         SqlDataReader reader = command.ExecuteReader();
  307.         while (reader.Read())
  308.         {
  309.             Common _Common = new Common();
  310.             _Common.ID = Convert.ToString(reader["BatchID"]);
  311.             _Common.Name = Convert.ToString(reader["BatchName"]);
  312.  
  313.             list.Add(_Common);
  314.  
  315.  
  316.         }
  317.  
  318.  
  319.         con.Close();
  320.         JavaScriptSerializer js = new JavaScriptSerializer();
  321.         HttpContext.Current.Response.ContentType = "application/json";
  322.         HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
  323.  
  324.         HttpContext.Current.Response.Write(js.Serialize(list));
  325.     }
  326.  
  327.     [WebMethod]
  328.     public void getClassTime()
  329.     {
  330.         List<Object> list = new List<Object>();
  331.  
  332.         //Context.Response.Write("{Message: 'Hello World'}");
  333.  
  334.         SqlConnection con = new SqlConnection(ConString);
  335.         SqlCommand command = con.CreateCommand();
  336.         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]";
  337.  
  338.  
  339.         con.Open();
  340.         SqlDataReader reader = command.ExecuteReader();
  341.         while (reader.Read())
  342.         {
  343.             PhaseInfo _PhaseInfo = new PhaseInfo();
  344.             _PhaseInfo.ID = Convert.ToInt32(reader["ClassTimeID"]);
  345.             _PhaseInfo.Name = reader["FromTime"].ToString() + " - " + reader["ToTime"].ToString();
  346.             list.Add(_PhaseInfo);
  347.         }
  348.  
  349.  
  350.         con.Close();
  351.  
  352.         JavaScriptSerializer js = new JavaScriptSerializer();
  353.         HttpContext.Current.Response.ContentType = "application/json";
  354.         HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
  355.  
  356.         HttpContext.Current.Response.Write(js.Serialize(list));
  357.  
  358.  
  359.     }
  360.  
  361.  
  362.  
  363.  
  364.  
  365. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement