Example #1
0
        public void Add(Commod commod)
        {
            List<Commod> list = GetAll();
            //如果存在相同名字的就移除,然后添加新的
            if (list!=null&&list.Count>0&&list.Where(i => i.Name.Equals(commod.Name)).FirstOrDefault() != null)
            {
                var removeModel = list.First(i => i.Name.Equals(commod.Name));
                list.Remove(removeModel);
                
            }
            commod.ID = Guid.NewGuid();
            list.Add(commod);

            BaseLibrary.CacheHelper.RemoveCache(CacheKey);

            BaseLibrary.CacheHelper.Add(CacheKey, list,true);
        }
Example #2
0
 /// <summary>
 /// 添加一个最低价格装备
 /// 如果存在同一天的就修改价格
 /// </summary>
 /// <param name="commod">要添加的装备</param>
 public void Add(Commod commod) {
     using (RxjhEntities en = new RxjhEntities()) {
         //先找到当天是否已经存在该装备
         var thisDateCommod = en.Commod.Where(i => i.Name == commod.Name).FirstOrDefault();
         //存在就更新
         if (thisDateCommod != null)
         {
             en.Commod.Remove(thisDateCommod);
             commod.ID = Guid.NewGuid();
             en.Commod.Add(commod);
             en.SaveChanges();
         }
         else {
             commod.ID = Guid.NewGuid();
             en.Commod.Add(commod);
             en.SaveChanges();
         }
     }
 }
Example #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="hexData"></param>
        public void GetData(string hexData)
        {
            //发送给远程主机的请求内容串 
            string sendStr = hexData;
            //创建bytes字节数组以转换发送串 
            byte[] bytesSendStr = new byte[1024];
            //将发送内容字符串转换成字节byte数组 
            var b = StringToBytes(sendStr);
            try
            {
                //向主机发送请求             
                CommodSocket.Send(b, SocketFlags.None);
            }
            catch (Exception ce)
            {
                Console.WriteLine("发送错误:" + ce.Message);
            }

            Encoding encode = Encoding.Default;
            string result = string.Empty;
            List<byte> data = new List<byte>();
            byte[] buffer = new byte[1024];
            int length = 0;
            try
            {
                while ((length = CommodSocket.Receive(buffer)) > 0)
                {
                    //6为前6个字节无用的字节
                    for (int j = 6; j < length; j++)
                    {
                        data.Add(buffer[j]);
                    }
                    if (length < buffer.Length)
                    {
                        break;
                    }
                }
            }
            catch { }
            if (data.Count > 0)
            {
                result = encode.GetString(data.ToArray(), 0, data.Count);
            }

            var commods = result.Split('|');
            List<Commod> listCommod = new List<Commod>();

            foreach (var tempcommod in commods)
            {

                var _tempCommod = new Commod();
                if (tempcommod.IndexOf('?') > 0)
                    continue;
                var arrayAtt = tempcommod.Split('#');
                if (arrayAtt.Length == 1 || arrayAtt.Length <= 6)
                    continue;
                _tempCommod.MerName = arrayAtt[0].ToString();
                _tempCommod.Axes = arrayAtt[1].ToString();
                _tempCommod.Line = arrayAtt[3].ToString();
                _tempCommod.DateTimes = arrayAtt[4].ToString();
                _tempCommod.Name = arrayAtt[5].ToString();
                //价格
                long _price = 0;
                if (arrayAtt.Length >= 7)
                {
                    long.TryParse(arrayAtt[6], out _price);
                    _tempCommod.Price = _price;
                    //属性
                    _tempCommod.ValueAdd = arrayAtt.Length >= 8 ? arrayAtt[7].ToString() : "";
                }

                listCommod.Add(_tempCommod);

            }
            LowPrice(listCommod.ToArray());

            //禁用Socket 
            //socket.Shutdown(SocketShutdown.Both);
            //关闭Socket 
            CommodSocket.Close();
            commodSocket = null;

        }
Example #4
0
 public void Add(Commod commod)
 {
     CommodDao.Add(commod);
 }