示例#1
0
        public List <Spare> GetAllSpare(SpareAdvanceSearch spareAdvanceSearch)
        {
            List <Spare> spareList = null;

            try
            {
                using (SqlConnection con = _databaseFactory.GetDBConnection())
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        if (con.State == ConnectionState.Closed)
                        {
                            con.Open();
                        }
                        cmd.Connection  = con;
                        cmd.CommandText = "[PSA].[GetAllSpare]";
                        cmd.Parameters.Add("@SearchValue", SqlDbType.NVarChar, -1).Value = string.IsNullOrEmpty(spareAdvanceSearch.SearchTerm) ? "" : spareAdvanceSearch.SearchTerm;
                        cmd.Parameters.Add("@RowStart", SqlDbType.Int).Value             = spareAdvanceSearch.DataTablePaging.Start;
                        if (spareAdvanceSearch.DataTablePaging.Length == -1)
                        {
                            cmd.Parameters.AddWithValue("@Length", DBNull.Value);
                        }
                        else
                        {
                            cmd.Parameters.Add("@Length", SqlDbType.Int).Value = spareAdvanceSearch.DataTablePaging.Length;
                        }
                        cmd.CommandType = CommandType.StoredProcedure;
                        using (SqlDataReader sdr = cmd.ExecuteReader())
                        {
                            if ((sdr != null) && (sdr.HasRows))
                            {
                                spareList = new List <Spare>();
                                while (sdr.Read())
                                {
                                    Spare spare = new Spare();
                                    {
                                        spare.ID            = (sdr["ID"].ToString() != "" ? Guid.Parse(sdr["ID"].ToString()) : spare.ID);
                                        spare.Code          = (sdr["Code"].ToString() != "" ? sdr["Code"].ToString() : spare.Code);
                                        spare.Name          = (sdr["Name"].ToString() != "" ? sdr["Name"].ToString() : spare.Name);
                                        spare.HSNCode       = (sdr["HSNCode"].ToString() != "" ? sdr["HSNCode"].ToString() : spare.HSNCode);
                                        spare.TotalCount    = (sdr["TotalCount"].ToString() != "" ? int.Parse(sdr["TotalCount"].ToString()) : spare.TotalCount);
                                        spare.FilteredCount = (sdr["FilteredCount"].ToString() != "" ? int.Parse(sdr["FilteredCount"].ToString()) : spare.FilteredCount);
                                    }
                                    spareList.Add(spare);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(spareList);
        }
示例#2
0
 public List <Spare> GetAllSpare(SpareAdvanceSearch spareAdvanceSearch)
 {
     return(_spareRepository.GetAllSpare(spareAdvanceSearch));
 }