Exemplo n.º 1
0
        protected override IQueryable <UserList> MainQuery(InventoryDbEntities context)
        {
            var query = (from row in context.UserLists
                         select row).OrderBy(row => row.UserId);

            return(query);
        }
Exemplo n.º 2
0
 private AccountRole GetLoginLevel(string userName)
 {
     using (var db = new InventoryDbEntities())
     {
         return((AccountRole)(db.GetLoginLevel(userName).First() ?? -1));
     }
 }
Exemplo n.º 3
0
 public DataTable GetItemCabinetHas()
 {
     using (var context = new InventoryDbEntities())
     {
         return(HelperMethods.LINQToDataTable(context.GetCurrentItemsCabinetHas((int)Grid.SelectedRows[0].Cells["CabinetId"].Value)));
     }
 }
Exemplo n.º 4
0
 public virtual DataTable GetFilterdDataTable(string s)
 {
     using (var context = new InventoryDbEntities())
     {
         return(HelperMethods.LINQToDataTable(FilteredQuery(context, s).ToList()));
     }
 }
Exemplo n.º 5
0
        protected override IQueryable <TransPermissionList> MainQuery(InventoryDbEntities context)
        {
            var query = (from row in context.TransPermissionList
                         select row
                         ).OrderBy(row => row.PermissionId);

            return(query);
        }
Exemplo n.º 6
0
        protected override IQueryable <CabinetList> MainQuery(InventoryDbEntities context)
        {
            var query = (from item in context.CabinetLists
                         select item
                         ).OrderBy(row => row.CabinetId);

            return(query);
        }
Exemplo n.º 7
0
        protected override IQueryable <CatList> FilteredQuery(InventoryDbEntities context, string like)
        {
            var query = (from itemCat in context.CatLists
                         where itemCat.Category_Name.ToLower().Contains(like)
                         orderby itemCat.CatId
                         select itemCat);

            return(query);
        }
Exemplo n.º 8
0
        public DataTable GetSalesOfItem()
        {
            int itemId = (int)Grid.SelectedRows[0].Cells["ItemId"].Value;

            using (var context = new InventoryDbEntities())
            {
                return(HelperMethods.LINQToDataTable(context.GetSalesOfItem(itemId)));
            }
        }
Exemplo n.º 9
0
 public virtual DataTable GetMainGridDataTable(int page)
 {
     CurrentPage = page;
     using (var context = new InventoryDbEntities())
     {
         var paged = PagedResult(MainQuery(context), page);
         return(HelperMethods.LINQToDataTable(paged.ToList()));
     }
 }
Exemplo n.º 10
0
        public DataTable GetItemTransactionOfCabinet()
        {
            int cabinetId = (int)Grid.SelectedRows[0].Cells["CabinetId"].Value;
            int itemId    = (int)OnHandReport.Grid.SelectedRows[0].Cells["ItemId"].Value;

            using (var context = new InventoryDbEntities())
            {
                return(HelperMethods.LINQToDataTable(context.GetItemTransactionsOfCabinet(cabinetId, itemId).OrderBy(r => r.ActionDate)));
            }
        }
        protected override IQueryable <CabinetTypeList> FilteredQuery(InventoryDbEntities context, string like)
        {
            var query = (from row in context.CabinetTypeLists
                         where row.Description.ToLower().Contains(like) ||
                         row.Name.ToLower().Contains(like)
                         orderby row.CabinetTypeId
                         select row);

            return(query);
        }
Exemplo n.º 12
0
        protected override IQueryable <ItemList> FilteredQuery(InventoryDbEntities context, string like)
        {
            var query = (from item in context.ItemLists
                         where item.ItemCode.ToLower().Contains(like) ||
                         item.ItemName.ToLower().Contains(like)
                         orderby item.ItemId
                         select item);

            return(query);
        }
Exemplo n.º 13
0
 private int GetUserId(string username)
 {
     using (var context = new InventoryDbEntities())
     {
         if (!IdTranslater.GetUserId(username, out var id, context))
         {
             return(-1);
         }
         return(id ?? -1);
     }
 }
Exemplo n.º 14
0
 public ItemController(IViewer view) : base(view)
 {
     ParseFunc    = new Func <List <string[]>, List <Item> >((c) => (new EntityParser(UserId).ParseToItems(c)));
     InsertAction = new Func <List <Item>, int>((e) =>
     {
         using (var context = new InventoryDbEntities())
         {
             context.Items.AddRange(e);
             return(context.SaveChanges());
         }
     });
 }
Exemplo n.º 15
0
        public static bool GetProviderId(string name, out int?id, InventoryDbEntities context)
        {
            id = null;
            var provider = context.Providers.FirstOrDefault(e => string.Compare(name, e.Name, true) == 0);

            if (provider == null)
            {
                return(false);
            }
            id = provider.ProviderId;
            return(true);
        }
Exemplo n.º 16
0
        public LoginForm()
        {
            InitializeComponent();
            SetVer();
            SetServer();
            var test = new InventoryDbEntities();

#if DEBUG
            textBoxUsername.Text = "luu.nhat-hong";
            textBoxPwd.Text      = "Dant@760119";
#endif
        }
Exemplo n.º 17
0
        public static bool GetCatId(string name, out int?id, InventoryDbEntities context)
        {
            id = null;
            var cat = context.ItemCats.FirstOrDefault(e => string.Compare(name, e.CatName, true) == 0);

            if (cat == null)
            {
                return(false);
            }
            id = cat.CatId;
            return(true);
        }
Exemplo n.º 18
0
 public void RefreshPageNumber()
 {
     using (var context = new InventoryDbEntities())
     {
         TotalRows  = MainQuery(context).Count();
         TotalPages = (TotalRows + ItemPerPage - 1) / ItemPerPage;
         if (TotalPages < 1)
         {
             TotalPages = 1;
         }
     }
 }
Exemplo n.º 19
0
        public static bool GetItemId(string name, out int?id, InventoryDbEntities context)
        {
            id = null;
            var item = context.Items.FirstOrDefault(e => string.Compare(name, e.ItemCode, true) == 0);

            if (item == null)
            {
                return(false);
            }
            id = item.ItemId;
            return(true);
        }
Exemplo n.º 20
0
        public static bool GetCabinetTypeId(string name, out int?id, InventoryDbEntities context)
        {
            id = null;
            var type = context.CabinetTypes.FirstOrDefault(e => string.Compare(name, e.Name, true) == 0);

            if (type == null)
            {
                return(false);
            }
            id = type.CabinetTypeId;
            return(true);
        }
Exemplo n.º 21
0
        protected override IQueryable <UserList> FilteredQuery(InventoryDbEntities context, string like)
        {
            var query = (from row in context.UserLists
                         where
                         row.Username.ToLower().Contains(like) ||
                         row.RoleName.ToLower().Contains(like) ||
                         row.Note.ToString().ToLower().Contains(like)
                         orderby row.UserId
                         select row);

            return(query);
        }
Exemplo n.º 22
0
        protected override IQueryable <ProviderList> FilteredQuery(InventoryDbEntities context, string like)
        {
            var query = (from row in context.ProviderLists
                         where
                         row.Name.ToLower().Contains(like) ||
                         row.Phone.ToLower().Contains(like) ||
                         row.Address.ToLower().Contains(like)
                         orderby row.ProviderId
                         select row);

            return(query);
        }
Exemplo n.º 23
0
        protected override IQueryable <TransPermissionList> FilteredQuery(InventoryDbEntities context, string like)
        {
            var query = (from row in context.TransPermissionList
                         where
                         row.Cabinet_Type.ToLower().Contains(like) ||
                         row.Note.ToLower().Contains(like) ||
                         row.PermissionType.ToLower().Contains(like) ||
                         row.Username.ToLower().Contains(like)
                         orderby row.PermissionId
                         select row);

            return(query);
        }
Exemplo n.º 24
0
 public PermissionController(IViewer view) : base(view)
 {
     ParseFunc = new Func <List <string[]>, List <TransactionPermission> >((c) =>
                                                                           (new EntityParser(UserId).ParseToPermission(c)));
     InsertAction = new Func <List <TransactionPermission>, int>((e) =>
     {
         using (var context = new InventoryDbEntities())
         {
             context.TransactionPermissions.AddRange(e);
             return(context.SaveChanges());
         }
     });
 }
Exemplo n.º 25
0
        public List <Cabinet> ToEntities()
        {
            var cabinets = new List <Cabinet>();

            for (int i = 0; i < CSV.Count; i++)
            {
                if (CSV[i].Count() != ColumnCount)
                {
                    throw new EntityParsingException("Invalid column count", i);
                }
                string name     = CSV[i][0];
                string typeName = CSV[i][1];
                string address  = CSV[i][2];
                string phone    = CSV[i][3];
                //check length
                if (name.Length > NameLength)
                {
                    throw new EntityParsingException("Invalid length", nameof(name), name, i);
                }
                if (typeName.Length > typeNameLength)
                {
                    throw new EntityParsingException("Invalid length", nameof(typeName), typeName, i);
                }
                if (address.Length > AddressLength)
                {
                    throw new EntityParsingException("Invalid length", nameof(address), address, i);
                }
                if (phone.Length > PhoneLength)
                {
                    throw new EntityParsingException("Invalid length", nameof(phone), phone, i);
                }
                //get id
                int?typeId;
                using (var context = new InventoryDbEntities())
                {
                    if (!IdTranslater.GetCabinetTypeId(typeName, out typeId, context))
                    {
                        throw new EntityParsingException("Name doesnt exist", "CabinetType", typeName, i);
                    }
                }
                var cabinet = new Cabinet()
                {
                    CabinetName   = name,
                    CabinetTypeId = typeId ?? -1,
                    Address       = address,
                    Phone         = phone
                };
                cabinets.Add(cabinet);
            }
            return(cabinets);
        }
Exemplo n.º 26
0
        protected override IQueryable <OrderList> FilteredQuery(InventoryDbEntities context, string like)
        {
            var query = (from row in context.OrderLists
                         where row.CabinetName.ToLower().Contains(like) ||
                         row.InputDate.ToString().ToLower().Contains(like) ||
                         row.ItemCode.ToLower().Contains(like) ||
                         row.Note.ToLower().Contains(like) ||
                         row.Provider.ToLower().Contains(like) ||
                         row.Username.ToLower().Contains(like)
                         orderby row.OrderId
                         select row);

            return(query);
        }
        protected override IQueryable <TransactionList> FilteredQuery(InventoryDbEntities context, string like)
        {
            var query = (from row in context.TransactionLists
                         where
                         row.From.ToLower().Contains(like) ||
                         row.To.ToLower().Contains(like) ||
                         row.TransactionDate.ToString().ToLower().Contains(like) ||
                         row.Username.ToLower().Contains(like) ||
                         row.ItemCode.ToLower().Contains(like) ||
                         row.Note.ToLower().Contains(like)
                         orderby row.TransactionsId
                         select row);

            return(query);
        }
Exemplo n.º 28
0
        public List <TransactionPermission> ToEntities()
        {
            var entities = new List <TransactionPermission>();

            for (int i = 0; i < CSV.Count; i++)
            {
                string pType       = CSV[i][0];
                string userName    = CSV[i][1];
                string cabinetType = CSV[i][2];
                string note        = CSV[i][3];
                if (note.Length > NoteLength)
                {
                    throw new EntityParsingException("Invalid length", nameof(note), note, i);
                }

                int cId, userId;

                int?id;
                using (var context = new InventoryDbEntities())
                {
                    //to cabinet id
                    if (!IdTranslater.GetCabinetTypeId(cabinetType, out id, context))
                    {
                        throw new EntityParsingException("Name doesnt exist", "CabinetType", cabinetType, i);
                    }
                    cId = id ?? -1;
                    //username
                    if (!IdTranslater.GetUserId(userName, out id, context))
                    {
                        throw new EntityParsingException("Name doesnt exist", "Username", userName, i);
                    }
                    userId = id ?? -1;
                }

                var per = new TransactionPermission()
                {
                    PermissionTypeName = pType,
                    CabinetTypeId      = cId,
                    UserId             = userId,
                    Note = note
                };
                entities.Add(per);
            }
            return(entities);
        }
Exemplo n.º 29
0
        private void SetServer()
        {
            var server = string.Empty;

            try
            {
                using (var context = new InventoryDbEntities())
                {
                    server = context.Database.Connection.DataSource.Split('\\').First();
                }
            }
            catch (Exception)
            {
                server = "Unknown";
            }

            labelDataSourse.Text = $"Server: {server}";
        }
Exemplo n.º 30
0
        public List <Item> ToEntities()
        {
            var entities = new List <Item>();

            for (int i = 0; i < CSV.Count; i++)
            {
                if (CSV[i].Count() != ColumnCount)
                {
                    throw new EntityParsingException("Invalid column count", i);
                }
                string code = CSV[i][0];
                string name = CSV[i][1];
                string cat  = CSV[i][2];
                if (code.Length > CodeLength)
                {
                    throw new EntityParsingException("Invalid length", "ItemCode", code, i);
                }
                if (name.Length > NameLength)
                {
                    throw new EntityParsingException("Invalid length", "ItemName", name, i);
                }
                int catId;
                int?id;
                using (var context = new InventoryDbEntities())
                {
                    if (!IdTranslater.GetCatId(cat, out id, context))
                    {
                        throw new EntityParsingException("Name doesnt exist", "Item Category", cat, i);
                    }
                }
                catId = id ?? -1;
                var item = new Item()
                {
                    ItemCode = code,
                    ItemName = name,
                    CatId    = catId
                };
                entities.Add(item);
            }
            return(entities);
        }