Beispiel #1
0
        public static ClsDepartments GetEditData(string Val)
        {
            try
            {
                string        con1 = System.Configuration.ConfigurationManager.ConnectionStrings["DBMS"].ConnectionString;
                SqlConnection conn = new SqlConnection(con1);

                SqlCommand cmd = new SqlCommand(@"select dep_name,dep_discription from Department where dep_id=@id", conn);
                cmd.Parameters.AddWithValue("@id", Convert.ToInt32(Val));

                conn.Open();
                SqlDataReader  rea = cmd.ExecuteReader();
                ClsDepartments obj = new ClsDepartments();
                while (rea.Read())
                {
                    obj.dep_name = rea["dep_name"].ToString();
                    obj.desc     = rea["dep_discription"].ToString();
                }
                return(obj);
            }
            catch (Exception ex)
            {
                ClsDepartments dep = new ClsDepartments();
                dep.dep_name = "" + ex.Message;
                return(dep);
            }
        }
Beispiel #2
0
        public void Get_Departments(int iDisplayLength, int iDisplayStart, int iSortCol_0, string sSortDir_0, string sSearch)
        {
            int    displayLength = iDisplayLength;
            int    displayStart  = iDisplayStart;
            int    sortCol       = iSortCol_0;
            string sortDir       = sSortDir_0;
            string search        = sSearch;

            string cs = ConfigurationManager.ConnectionStrings["DBMS"].ConnectionString;

            List <ClsDepartments> listEmployees = new List <ClsDepartments>();
            int filteredCount = 0;

            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("Sp_GetDepartment", con);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter paramDisplayLength = new SqlParameter()
                {
                    ParameterName = "@DisplayLength",
                    Value         = displayLength
                };
                cmd.Parameters.Add(paramDisplayLength);

                SqlParameter paramDisplayStart = new SqlParameter()
                {
                    ParameterName = "@DisplayStart",
                    Value         = displayStart
                };
                cmd.Parameters.Add(paramDisplayStart);

                SqlParameter paramSortCol = new SqlParameter()
                {
                    ParameterName = "@SortCol",
                    Value         = sortCol
                };
                cmd.Parameters.Add(paramSortCol);

                SqlParameter paramSortDir = new SqlParameter()
                {
                    ParameterName = "@SortDir",
                    Value         = sortDir
                };
                cmd.Parameters.Add(paramSortDir);

                SqlParameter paramSearchString = new SqlParameter()
                {
                    ParameterName = "@Search",
                    Value         = string.IsNullOrEmpty(search) ? null : search
                };
                cmd.Parameters.Add(paramSearchString);

                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    ClsDepartments emp = new ClsDepartments();
                    emp.dep_name  = Convert.ToString(rdr["dep_name"]);
                    filteredCount = Convert.ToInt32(rdr["TotalCount"]);
                    emp.dep_id    = Convert.ToInt32(rdr["dep_id"].ToString());
                    emp.desc      = Convert.ToString(rdr["dep_discription"]);

                    listEmployees.Add(emp);
                }
            }

            var result = new
            {
                iTotalRecords        = GetDepTotalCount(),
                iTotalDisplayRecords = filteredCount,
                aaData = listEmployees
            };

            JavaScriptSerializer js = new JavaScriptSerializer();

            Context.Response.Write(js.Serialize(result));
        }