Пример #1
0
        public static List <OtData> GetAllOT(string sortColumn)
        {
            List <OtData> lst      = new List <OtData>();
            string        cs       = ConfigurationManager.ConnectionStrings["connexionInfo"].ConnectionString;
            SqlConnection con      = new SqlConnection(cs);
            string        sqlQuery = "select ordre, date_saisie, designation_ot from ot";

            if (!string.IsNullOrEmpty(sortColumn))
            {
                sqlQuery += " order by " + sortColumn;
            }
            SqlCommand cmd = new SqlCommand(sqlQuery, con);

            con.Open();
            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                OtData otdata = new OtData();
                otdata.ordre          = Convert.ToInt32(rdr["ordre"]);
                otdata.date_saisie    = Convert.ToDateTime(rdr["date_saisie"]);
                otdata.designation_ot = rdr["designation_ot"].ToString();
                lst.Add(otdata);
            }

            return(lst);
        }
Пример #2
0
        public static List <OtData> GetAllOT(int pageIndex, int pageSize, string sortExpression, string sortDirection, out int totalRows)
        {
            List <OtData> lst = new List <OtData>();
            string        cs  = ConfigurationManager.ConnectionStrings["connexionInfo"].ConnectionString;
            SqlConnection con = new SqlConnection(cs);

            SqlCommand cmd = new SqlCommand("spGetOt_by_PageIndex_and_PageSize", con);

            cmd.CommandType = CommandType.StoredProcedure;


            SqlParameter paramStartIndex = new SqlParameter();

            paramStartIndex.ParameterName = "@PageIndex";
            paramStartIndex.Value         = pageIndex;
            cmd.Parameters.Add(paramStartIndex);

            SqlParameter paramMaximumRows = new SqlParameter();

            paramMaximumRows.ParameterName = "@PageSize";
            paramMaximumRows.Value         = pageSize;
            cmd.Parameters.Add(paramMaximumRows);

            SqlParameter paramSortExpression = new SqlParameter();

            paramSortExpression.ParameterName = "@SortExpression";
            paramSortExpression.Value         = sortExpression;
            cmd.Parameters.Add(paramSortExpression);

            SqlParameter paramSortDirection = new SqlParameter();

            paramSortDirection.ParameterName = "@SortDirection";
            paramSortDirection.Value         = sortDirection;
            cmd.Parameters.Add(paramSortDirection);


            SqlParameter paramOutputTotalRows = new SqlParameter();

            paramOutputTotalRows.ParameterName = "@TotalRows";
            paramOutputTotalRows.Direction     = ParameterDirection.Output;
            paramOutputTotalRows.SqlDbType     = SqlDbType.Int;
            cmd.Parameters.Add(paramOutputTotalRows);

            con.Open();

            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                OtData otdata = new OtData();
                otdata.ordre          = Convert.ToInt32(rdr["ordre"]);
                otdata.date_saisie    = Convert.ToDateTime(rdr["date_saisie"]);
                otdata.designation_ot = rdr["designation_ot"].ToString();
                lst.Add(otdata);
            }
            rdr.Close();
            totalRows = (int)cmd.Parameters["@TotalRows"].Value;
            return(lst);
        }