public static AssetInventoryModel ToModel(this AssetInventory entity)
        {
            var model = new AssetInventoryModel()
            {
                Id          = entity.Id,
                Title       = entity.Title,
                Description = entity.Description,
                CreatedTime = entity.CreatedTime
            };

            if (entity.Status.HasValue)
            {
                model.Status = (AssetInventoryStatus)entity.Status.Value;
            }
            if (entity.AssetInventoryRecords != null && entity.AssetInventoryRecords.Count > 0)
            {
                model.AssetInventoryRecords = new List <AssetInventoryRecordModel>();
                foreach (var item in entity.AssetInventoryRecords)
                {
                    model.AssetInventoryRecords.Add(new AssetInventoryRecordModel()
                    {
                        Id          = item.Id,
                        AssetId     = item.AssetId,
                        InventoryId = item.InventoryId,
                        ScanCode    = item.ScanCode,
                        UserId      = item.UserId
                    });
                }
            }
            return(model);
        }
Exemple #2
0
        private void NewSelectedGroup(object sender, RoutedEventArgs e)
        {
            var group = (GroupModel)groupsListBox.SelectedValue;

            if (group != null)
            {
                if (Itemlist == null)
                {
                    var a = new AssetInventoryModel(0, 0, 0, 0);
                    foreach (AssetInventoryModel k in Assetlist)
                    {
                        if (group.Id == k.GroupId)
                        {
                            a = k;
                        }
                    }
                    _tempAssetPercent       = a.Share;
                    CTamount.Text           = a.Share.ToString();
                    CTbtnAmuntUp.Visibility = Visibility.Collapsed;

                    if (a.Share <= 5)
                    {
                        CTbtnAmuntDown.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        CTbtnAmuntDown.Visibility = Visibility.Visible;
                    }
                }
                else
                {
                    var i = new ItemInventoryModel(0, 0, 0, 0);
                    foreach (ItemInventoryModel k in Itemlist)
                    {
                        if (group.Id == k.GroupId)
                        {
                            i = k;
                        }
                    }
                    _tempItemAmount         = i.Quantity;
                    CTamount.Text           = i.Quantity.ToString();
                    CTbtnAmuntUp.Visibility = Visibility.Collapsed;

                    if (i.Quantity <= 1)
                    {
                        CTbtnAmuntDown.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        CTbtnAmuntDown.Visibility = Visibility.Visible;
                    }
                }
            }
        }
        public static AssetInventory ToEntity(this AssetInventoryModel model)
        {
            var entity = new AssetInventory()
            {
                Id          = model.Id,
                Title       = model.Title,
                Description = model.Description,
                Status      = (int)model.Status
            };

            return(entity);
        }
        /// <summary>
        ///     Checks if asset inventory exists.
        /// </summary>
        /// <param name="assetInventory"></param>
        /// <returns></returns>
        public Boolean AssetInventoryExists(AssetInventoryModel assetInventory)
        {
            foreach (AssetInventoryModel aim in AssetInventories)
            {
                if (assetInventory.AssetId == aim.AssetId && assetInventory.GroupId == aim.GroupId)
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        ///     Edits asset inventory.
        /// </summary>
        /// <param name="assetInventory"></param>
        public void EditAssetInventoryModel(AssetInventoryModel assetInventory)
        {
            foreach (AssetInventoryModel aim in AssetInventories)
            {
                if (aim.AssetId == assetInventory.AssetId && aim.GroupId == assetInventory.GroupId)
                {
                    aim.Share = assetInventory.Share;
                }
            }

            AddAssets(Assets, AssetInventories);
        }
Exemple #6
0
        /// <summary>
        ///     Gets asset inventory
        /// </summary>
        /// <param name="aId">Asset id</param>
        /// <param name="grp">Group id</param>
        /// <returns>Asset inventory</returns>
        public AssetInventoryModel GetAssetInventory(int aId, int grp)
        {
            AssetInventoryModel aInvM = (from ainv in _db.assetInventories
                                         where ainv.assetId == aId && ainv.teamId == grp
                                         select new AssetInventoryModel
            {
                Id = ainv.Id,
                AssetId = ainv.assetId,
                GroupId = ainv.teamId,
                Share = (int)ainv.share
            }).ToList().Last();

            return(aInvM);
        }
Exemple #7
0
        /// <summary>
        ///     Recieves asset inventory
        /// </summary>
        /// <param name="doc"></param>
        /// <returns>Asset inventory</returns>
        private AssetInventoryModel RecieveAssetInventory(XmlDocument doc)
        {
            var        recieveAssetInventory = new AssetInventoryModel(0, 0, 0, 0);
            XmlElement root    = doc["AssetInventory"];
            string     id      = root["ID"].InnerText;
            string     assetId = root["AssetID"].InnerText;
            string     groupId = root["GroupID"].InnerText;
            string     share   = root["Share"].InnerText;

            recieveAssetInventory.Id      = Int32.Parse(id);
            recieveAssetInventory.AssetId = Int32.Parse(assetId);
            recieveAssetInventory.GroupId = Int32.Parse(groupId);
            recieveAssetInventory.Share   = Int32.Parse(share);
            return(recieveAssetInventory);
        }
 /// <summary>
 /// 添加盘点任务
 /// </summary>
 /// <param name="model">返回保存后的实体Id</param>
 /// <returns></returns>
 public int AddAssetInventory(AssetInventoryModel model)
 {
     using (var dbContext = new MissionskyOAEntities())
     {
         var existOpenTask = dbContext.AssetInventories.Where(it => it.Status.HasValue && it.Status.Value == (int)AssetInventoryStatus.Open).FirstOrDefault();
         if (existOpenTask != null)
         {
             throw new Exception("当前还有未关闭的盘点任务,不能启动新任务");
         }
         var entity = model.ToEntity();
         entity.CreatedTime = DateTime.Now;
         dbContext.AssetInventories.Add(entity);
         dbContext.SaveChanges();
         return(entity.Id);
     }
 }
Exemple #9
0
        /// <summary>
        ///     Adds new asset inventory to DB
        /// </summary>
        /// <param name="a">Asset inventory</param>
        /// <returns>Asset inventory</returns>
        public AssetInventoryModel BuyAsset(AssetInventoryModel a)
        {
            var newAssetInventory = new assetInventory {
                assetId = a.AssetId, teamId = a.GroupId, share = a.Share
            };

            _db.assetInventories.InsertOnSubmit(newAssetInventory);
            try
            {
                _db.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            AssetInventoryModel outgoing = GetAssetInventory(a.AssetId, a.GroupId);

            return(outgoing);
        }
Exemple #10
0
        /// <summary>
        ///     Communcates with server
        /// </summary>
        private void DoChat()
        {
            Thread.Sleep(100);
            while (true)
            {
                Thread.Sleep(10);
                string     incomeData;
                TextReader reader = new StreamReader(_clientSocket.GetStream());

                if (_clientSocket.Available > 0)
                {
                    var doc = new XmlDocument();

                    while ((incomeData = reader.ReadLine()) != null && (incomeData.StartsWith("<") && incomeData.EndsWith(">")))
                    {
                        Console.WriteLine(incomeData);
                        doc.LoadXml(incomeData);
                        XmlElement root = doc.DocumentElement;
                        if (root != null)
                        {
                            string rootText = root.Name;

                            if (rootText == "Timestamp")
                            {
                                DateTime s = RecieveTimeStamp(doc);
                                RecieveObject(s, null);
                            }

                            else if (rootText == "Cashlist")
                            {
                                List <CashPerTeamModel> s = RecieveCurrentCash(doc);
                                RecieveObject(s, null);
                            }

                            else if (rootText == "Message")
                            {
                                MessageModel incoming = RecieveMessage(doc);
                                RecieveObject(incoming, null);
                            }

                            else if (rootText == "Trading")
                            {
                                TradingModel incoming = RecieveTrading(doc);
                                RecieveObject(incoming, null);
                            }

                            else if (rootText == "Notification")
                            {
                                NotificationModel incoming = RecieveNotification(doc);
                                RecieveObject(incoming, null);
                            }
                            else if (rootText == "Asset")
                            {
                                AssetModel incoming = RecieveAsset(doc);
                                RecieveObject(incoming, null);
                            }
                            else if (rootText == "AssetInventory")
                            {
                                AssetInventoryModel incoming = RecieveAssetInventory(doc);
                                RecieveObject(incoming, null);
                            }
                            else if (rootText == "AssetList")
                            {
                                List <AssetModel> incoming = RecieveAssetList(doc);
                                RecieveObject(incoming, null);
                            }

                            else if (rootText == "AssetInventoryList")
                            {
                                List <AssetInventoryModel> incoming = RecieveAssetInventoryList(doc);
                                RecieveObject(incoming, null);
                            }

                            else if (rootText == "Item")
                            {
                                ItemModel incoming = RecieveItem(doc);
                                RecieveObject(incoming, null);
                            }
                            else if (rootText == "ItemInventory")
                            {
                                ItemInventoryModel incoming = RecieveItemInventory(doc);
                                RecieveObject(incoming, null);
                            }

                            else if (rootText == "ItemList")
                            {
                                List <ItemModel> incoming = RecieveItemList(doc);
                                RecieveObject(incoming, null);
                            }

                            else if (rootText == "ItemInventoryList")
                            {
                                List <ItemInventoryModel> incoming = RecieveItemInventoryList(doc);
                                RecieveObject(incoming, null);
                            }

                            else if (rootText == "GroupList")
                            {
                                List <GroupModel> incoming = RecieveGroupList(doc);
                                RecieveObject(incoming, null);
                            }

                            else if (rootText == "MessageList")
                            {
                                List <MessageModel> incoming = RecieveMessageList(doc);
                                RecieveObject(incoming, null);
                            }

                            else if (rootText == "NotificationList")
                            {
                                List <NotificationModel> incoming = RecieveNotificationList(doc);
                                RecieveObject(incoming, null);
                            }

                            else if (rootText == "TradingList")
                            {
                                List <TradingModel> incoming = RecieveTradingList(doc);
                                //Console.WriteLine("test");
                                RecieveObject(incoming, null);
                            }

                            else if (rootText == "Groupnumber")
                            {
                                int groupNumber = RecieveGroupNumber(doc);
                                RecieveObject(groupNumber, null);
                            }

                            else if (rootText == "Pause")
                            {
                                bool paused = RecievePauseState(doc);
                                RecieveObject(paused, null);
                            }
                        }
                    }
                }
            }
        }
 public static AssetInventoryModel BuyAsset(AssetInventoryModel a)
 {
     return(InventoryDal.BuyAsset(a));
 }
        /// <summary>
        ///     Performs asset trade
        /// </summary>
        /// <param name="tm">Trade</param>
        /// <returns>Changed asset inventories</returns>
        public List <AssetInventoryModel> TradeAsset(TradingModel tm)
        {
            var assetInventories = new List <AssetInventoryModel>();
            var assetInventory   = new AssetInventoryModel();

            IQueryable <assetInventory> query =
                (from assetInv in _db.assetInventories
                 where assetInv.assetId == tm.AssetId &&
                 assetInv.teamId == tm.Buyer
                 select assetInv);

            if (query.Count() != 0)
            {
                assetInventory result = query.First();
                result.share += tm.Amount;
                if (result.share != null)
                {
                    assetInventory = new AssetInventoryModel(result.Id, tm.AssetId, tm.Buyer, (int)result.share);
                }
            }

            else
            {
                var newAssetInventory = new AssetInventoryModel(0, tm.AssetId, tm.Buyer, tm.Amount);
                assetInventory = _inventoryDal.BuyAsset(newAssetInventory);
            }

            // Submit the changes to the database.
            try
            {
                _db.SubmitChanges();
                assetInventories.Add(assetInventory);
                ValueDal.IncreaseOrDecreaseCash(tm.Buyer, -tm.Price);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                // Provide for exceptions.
            }

            if (tm.Owner != 0)
            {
                query = (from assetInv in _db.assetInventories
                         where assetInv.assetId == tm.AssetId &&
                         assetInv.teamId == tm.Owner
                         select assetInv);
                if (query.Count() != 0)
                {
                    assetInventory result = query.First();
                    result.share -= tm.Amount;
                    if (result.share != null)
                    {
                        assetInventory = new AssetInventoryModel(result.Id, tm.AssetId, tm.Owner, (int)result.share);
                    }
                }

                // Submit the changes to the database.
                try
                {
                    _db.SubmitChanges();
                    assetInventories.Add(assetInventory);
                    ValueDal.IncreaseOrDecreaseCash(tm.Owner, tm.Price);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    // Provide for exceptions.
                }
            }

            return(assetInventories);
        }
 /// <summary>
 ///     Adds new asset inventory.
 /// </summary>
 /// <param name="assetInventory"></param>
 public void AddAssetInventoryModel(AssetInventoryModel assetInventory)
 {
     AssetInventories.Add(assetInventory);
     AddAssets(Assets, AssetInventories);
 }