Exemplo n.º 1
0
        public DTO.StockRemains QuickSearchStockRemain(int userID, Hashtable filters, out Library.DTO.Notification notification)
        {
            DTO.StockRemains data = new DTO.StockRemains();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            int totalRows = 0;

            //search info
            string articleCode = string.Empty;
            string description = string.Empty;
            int?   factoryID   = null;

            if (filters.ContainsKey("articleCode"))
            {
                articleCode = filters["articleCode"].ToString();
            }
            if (filters.ContainsKey("description"))
            {
                description = filters["description"].ToString();
            }
            if (filters.ContainsKey("factoryID") && filters["factoryID"] != null)
            {
                factoryID = Convert.ToInt32(filters["factoryID"].ToString());
            }

            //pager info
            int    pageSize        = 20;
            int    pageIndex       = 1;
            string sortedBy        = string.Empty;
            string sortedDirection = string.Empty;

            if (filters.ContainsKey("pageSize"))
            {
                pageSize = Convert.ToInt32(filters["pageSize"].ToString());
            }
            if (filters.ContainsKey("pageIndex"))
            {
                pageIndex = Convert.ToInt32(filters["pageIndex"].ToString());
            }
            if (filters.ContainsKey("sortedBy"))
            {
                sortedBy = filters["sortedBy"].ToString();
            }
            if (filters.ContainsKey("sortedDirection"))
            {
                sortedDirection = filters["sortedDirection"].ToString();
            }

            try
            {
                using (FactoryStockReceiptEntities context = CreateContext())
                {
                    totalRows = context.FactoryStockReceiptMng_function_QuickSearchStockRemain(sortedBy, sortedDirection, articleCode, description, factoryID, userID).Count();
                    var result = context.FactoryStockReceiptMng_function_QuickSearchStockRemain(sortedBy, sortedDirection, articleCode, description, factoryID, userID);
                    data.Data      = converter.DB2DTO_StockRemain(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                    data.TotalRows = totalRows;
                }
                return(data);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(data);
            }
        }