public Indicator AnalyzeData(DataState state)
        {
            double[] closePrices = _analyseRepo.LoadClosePriceBySymbol(state.Symbol, true).ToArray();
            double[] RsiValues   = RSICalculator.CalculateRsi(RSICalculator.Period, closePrices);
            if (RsiValues.Length == 0)
            {
                return(null);
            }

            var cont  = new ContinuousCalculator(RsiValues, r => r > 50.0);
            RSI value = new RSI();

            value.Symbol          = state.Symbol;
            value.Date            = state.Last.Value;
            value.Avg             = RsiValues.Average();
            value.LastRSI         = AlgorithmHelper.GetLast(RsiValues);
            value.PercentGT50     = RsiValues.Where(r => r > 50).Count() * 100 / RsiValues.Count();
            value.TotalDays       = RsiValues.Count();
            value.MaxContGT50Days = cont.TrueMax;
            value.MaxContLT50Days = cont.FalseMax;
            value.AvgContGT50Days = cont.TrueAvg;
            value.AvgContLT50Days = cont.FalseAvg;
            value.LastContDays    = cont.LastCont;
            return(value.ToIndicator());
        }
        public Indicator AnalyzeData(DataState state)
        {
            double[] closePrices = _analyseRepo.LoadClosePriceBySymbol(state.Symbol, true).ToArray();
            List <BollingerBandsData> bBDataValues = BollingerBandsCalculator.CalculateBollingerBands(
                BollingerBandsCalculator.Period,
                BollingerBandsCalculator.DeviationUp,
                BollingerBandsCalculator.DeviationDown,
                closePrices);

            if (bBDataValues.Count == 0)
            {
                return(null);
            }
            var lastBB = AlgorithmHelper.TakeLast <BollingerBandsData>(bBDataValues, 1).FirstOrDefault();

            if (lastBB == null)
            {
                return(null);
            }
            BollingerBands value = new BollingerBands();

            value.Symbol         = state.Symbol;
            value.Date           = state.Last.Value;
            value.Upper          = lastBB.Upper;
            value.Middle         = lastBB.Middle;
            value.Lower          = lastBB.Lower;
            value.ChannelHight   = value.Upper - value.Lower;
            value.ChannelPercent = value.ChannelHight * 100 / value.Middle;
            return(value.ToIndicator());
        }
Exemple #3
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="posx"></param>
        /// <param name="loginpk"></param>
        /// <param name="verifyvode"></param>
        /// <returns></returns>
        public JsonResult LoginIn([FromBody] dynamic data)
        {
            //图形验证码
            //if (!LoginUser.VerificationCode.ToString().Equals(vcode))  return Json(GetResult(StateCode.State_104), JsonRequestBehavior.AllowGet);

            //当前私钥
            string private_key = HttpContext.Session.GetString("privateKey").Replace("\r\n", "");

            //解密登录信息
            string posx = AlgorithmHelper.Decrypt(private_key, data.posx.ToString());

            //用户密码
            string username = posx.Split("\\")[0];
            string password = posx.Split("\\")[1];

            //登录
            SysUser user = ServiceIoc.Get <SysUserService>().Login(username, password, HttpContext.GetClientIp());

            if (user.login_code == StateCode.State_200)
            {
                //登录操作
                LoginUser.Instance.LoginIn(user, this.HttpContext);
                return(Json(GetResult(user.login_code)));
            }

            return(Json(GetResult(user.login_code)));
        }
Exemple #4
0
        public void BollingerBandsCalculator_shouldCalculateBollingerBands_with_validData()
        {
            double[] _longPrices =
            {
                24.8,  24.55, 24.45,  24.5, 24.44, 24.11, 24.31, 25.37,    26, 25.61, 25.43, 25.56,
                25.41, 24.91,  25.1, 25.59, 25.85, 25.15, 25.46, 26.05, 25.74, 25.79, 25.67,
                25.8,  25.23, 25.19, 25.28, 24.91, 24.66, 24.99, 24.53, 24.15,  24.1, 24.18,
                23.92, 24.37,  24.2, 24.66,  24.2, 24.09, 23.49, 23.54, 23.55,  23.2, 23.37,
                23.04, 23.44,  23.3,  23.2, 22.91, 22.97, 23.79, 23.21, 23.13, 23.13, 23.36,
                23.13, 22.92, 22.92,  22.5,  22.8, 22.66, 22.88, 23.16, 23.54, 23.91, 23.92,
                23.83, 24.12, 23.78,    24, 23.83, 23.53, 23.05, 22.15,  22.2, 22.26, 22.38, 22.46,22.54, 22.32, 22.48, 22.25, 21.49, 21.48, 21.7, 21.79, 21.8, 22, 21.89, 21.71, 21.27, 22.07, 22.12, 22.2, 22.05, 21.92, 21.98, 21.81, 22.08, 22.26, 22, 22.22, 22.29, 22.89, 22.96, 23.19, 23.08, 23.14, 22.63, 22.79, 22.64, 22.13, 22.21, 22.17, 22.19, 21.99, 21.67, 21.94, 21.95, 22.02, 22.09, 22.02, 21.99, 21.88, 21.81, 21.84, 22.39, 22.31, 22.33, 21.92, 22.12, 21.71, 21.69, 21.89, 21.9, 22.05, 21.95, 22.14, 22.08, 22.15, 22.26, 22.09, 21.84, 22.07, 21.95, 22.03, 22.26, 22.15, 22.08, 22.48, 22.58, 22.39, 22.35, 22.03, 22.04, 21.97, 22.07, 22.01, 22.16, 22.31, 22.47, 22.52, 22.6, 22.74, 22.6, 22.6, 22.34, 22.19, 22.47, 22.73, 22.69, 22.73, 22.42, 22.62, 22.67, 23.12, 23.12, 23.63, 23.87, 24.58, 24.6, 24.38, 24.63, 24.59, 25.08, 24.81, 24.72, 24.41, 24.71, 25.05, 25.04, 25.02, 24.73, 24.96, 25.21, 25.22, 25, 24.8, 24.88, 24.71, 24.58, 24.59, 24.36, 24.63, 25.17, 25.65, 25.72, 26.04, 25.98, 25.85, 25.72, 25.71, 25.74, 25.6, 25.42, 25.28, 25.38, 25.37, 24.82, 25.04, 25.77, 25.47, 25.61, 25.35, 25.77, 25.54, 25.45, 25.69, 25.97, 25.73, 26.25, 25.86, 25.64, 25.63, 25.64, 25.8, 25.6, 25.76, 25.85, 25.79, 25.47, 25.22, 25.24, 24.88, 25.63, 25.85, 26.09, 26.57, 26.54, 26.55, 26.47, 26.44, 26.38, 27.08, 27.23, 27.44, 27.35, 28.25, 27.43, 27.18, 27.33, 27.23, 28.61, 29.2, 29.67, 29.59, 30.3, 29.22, 30.91, 32.21, 34.79, 34.49, 35.15, 32.57, 33.29, 34.06, 33.43, 33.55, 34.79, 35.9, 35.55, 35.68, 35.4, 34.07, 33.86, 36.16, 35.95, 36.23, 37.21, 37.28, 37.46, 37.58, 38.01, 37.02, 36.96, 36.39, 36.33, 36.09, 37.31, 36.27, 34.9, 36.95, 37, 36.88, 37.16, 36.56, 35.43, 35.74, 33.9, 34.57, 35.93, 36.33, 34.91, 33.67, 34.11, 34.91, 34.88, 35.38, 35.67, 36.18, 36.04, 35.9, 36.05, 36, 36.41, 35.51, 36.54, 36.35, 36.73, 35.75, 35.69, 35.45, 35, 35.77, 35.41, 35.83, 36.64, 36.66, 38.1, 38.82, 39.93, 39.7, 40.53, 40.81, 40.77, 40.17, 40.4, 40.98, 42.89, 41.64, 42.7, 42.32, 43.46, 43.91, 44.18, 43.26, 45, 45.02, 45.35, 44.79, 46.8, 44.48, 46.44, 47.45, 49.24, 48.58, 48.63, 49.4, 48.85, 48.95, 48.76, 49.09, 49.62, 47.11, 46.19, 45.92, 47.12, 48.08, 48.54, 47.96, 48.65, 47.72,
            };

            List <BollingerBandsData> value =
                BollingerBandsCalculator.CalculateBollingerBands(
                    BollingerBandsCalculator.Period,
                    BollingerBandsCalculator.DeviationUp,
                    BollingerBandsCalculator.DeviationDown,
                    _longPrices.ToArray());

            Assert.IsTrue(value.Count == 364);
            var last = AlgorithmHelper.TakeLast <BollingerBandsData>(value, 1).FirstOrDefault();

            Assert.IsTrue(last != null);
            Assert.IsTrue(last.Upper.AlmostEqual(50.30));
            Assert.IsTrue(last.Middle.AlmostEqual(48.12));
            Assert.IsTrue(last.Lower.AlmostEqual(45.92));
        }
        public Indicator AnalyzeData(DataState state)
        {
            double[]        closePrices = _analyseRepo.LoadClosePriceBySymbol(state.Symbol, true).ToArray();
            List <MacdData> macdValues  = MACDCalculator.CalculateMACD(
                MACDCalculator.FastPeriod,
                MACDCalculator.SlowPeriod,
                MACDCalculator.SignalPeriod,
                closePrices);

            if (macdValues.Count == 0)
            {
                return(null);
            }
            var lastMacd = AlgorithmHelper.TakeLast <MacdData>(macdValues, 1).FirstOrDefault();

            if (lastMacd == null)
            {
                return(null);
            }
            MACD value = new MACD();

            value.Symbol     = state.Symbol;
            value.Date       = state.Last.Value;
            value.MacdValue  = lastMacd.MacdValue;
            value.MacdSingal = lastMacd.MacdSingal;
            value.MacdHIST   = lastMacd.MacdHIST;
            return(value.ToIndicator());
        }
Exemple #6
0
        private void DrawMarking(Graphics e, Rectangle outBound, Rectangle inBound)
        {
            // e.SmoothingMode = SmoothingMode.HighQuality;
            GraphicsState state = e.Save();

            e.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            e.SmoothingMode     = SmoothingMode.HighQuality;
            Matrix mat = new Matrix();
            Point  sp  = new Point(inBound.Left + inBound.Width / 2, outBound.Top);
            Point  ep  = new Point(inBound.Left + inBound.Width / 2, inBound.Top);

            if (_collection.Count > 0)
            {
                float angle = 0;
                for (int i = 0; i < _collection.Count; i++)
                {
                    mat.RotateAt(_distance, _center);
                    //   Console.WriteLine("rotate " + i + " : " + _distance + " collection value=" + _collection[i].Value);
                    angle      += _distance;
                    e.Transform = mat;
                    if (_markingType == Marking.CONT || _markingType == Marking.BOTH)
                    {
                        GraphicsPath p = new GraphicsPath();
                        p.AddLine(sp, ep);
                        p.AddArc(inBound, 270, _distance);
                        p.Reverse();
                        GraphicsPath p2 = new GraphicsPath();
                        p2.AddArc(outBound, 270, _distance);
                        p2.AddLine(
                            AlgorithmHelper.LocationToCenter(_center, outBound.Width / 2, AlgorithmHelper.NormalizeDegreeFromX(270 + _distance)),
                            AlgorithmHelper.LocationToCenter(_center, inBound.Width / 2, AlgorithmHelper.NormalizeDegreeFromX(270 + _distance)));
                        p2.AddPath(p, true);
                        e.FillPath(new SolidBrush(_collection[i].MainColor), p2);
                    }
                    if (_markingType == Marking.LINE || _markingType == Marking.BOTH)
                    {
                        e.DrawLine(new Pen(_fontColor, 2), sp, ep);
                    }
                    Size z = new Size(0, 0);
                    if (_markingImage == MarkingImage.FONT)
                    {
                        String text = _collection[i].Desc;
                        z = TextRenderer.MeasureText(text, _f);
                        Point fp = new Point(inBound.Left + inBound.Width / 2 - z.Width / 2, outBound.Top - z.Height);
                        e.DrawString(text, _f, new SolidBrush(_fontColor), fp);
                        //TextEffectHelper.HaloEffect(_f, new SolidBrush(_fontColor), e, fp, text);
                    }
                    if (_markingImage == MarkingImage.IMAGE)
                    {
                        if (_collection[i].Image != null)
                        {
                            e.DrawImage(_collection[i].Image, new Rectangle(inBound.Left + inBound.Width / 2 - 6, outBound.Top - z.Height - 14, 12, 12),
                                        new Rectangle(0, 0, _collection[i].Image.Width, _collection[i].Image.Height), GraphicsUnit.Pixel);
                        }
                    }
                }
            }
            e.Restore(state);
        }
        private bool SaveStaff()
        {
            try
            {
                string fStaffId      = GetFormValue("fStaffId");
                string fStaffName    = GetFormValue("fStaffName");
                string fSex          = GetFormValue("fSex");
                string fPositionId   = GetFormValue("fPositionId");
                string fDepartmentId = GetFormValue("fDepartmentId");
                string fStoreId      = GetFormValue("fStoreId");
                string fPhone        = GetFormValue("fPhone");
                string fEmail        = GetFormValue("fEmail");
                string fAddress      = GetFormValue("fAddress");
                string fDescription  = GetFormValue("fDescription");
                string fState        = GetFormValue("fState");

                if (fPhone.Length != 11)
                {
                    throw new Exception("手机号码长度错误!");
                }
                if (!Utility.IsMobilePhone(fPhone))
                {
                    throw new Exception("手机号码格式错误!");
                }

                string password = AlgorithmHelper.MD5(Utility.Right(fPhone, 8)).ToLower();

                var entity = new Ld_Institution_Staff()
                {
                    SystemID     = SystemID,
                    CompanyID    = CompanyID,
                    StaffID      = fStaffId,
                    StaffName    = fStaffName,
                    UserName     = fStaffId,
                    Password     = password,
                    NickName     = fStaffName,
                    Name         = fStaffName,
                    Sex          = fSex.ToByte(),
                    Phone        = fPhone,
                    Email        = fEmail,
                    Address      = fAddress,
                    DepartmentID = fDepartmentId,
                    PositionID   = fPositionId,
                    StoreID      = fStoreId,
                    WarehouseID  = "",
                    Description  = fDescription,
                    IsInit       = false,
                    State        = fState.ToBool(),
                    IsDel        = false,
                    CreateDate   = DateTime.Now
                };
                return(StaffService.SaveStaffPro(entity));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemple #8
0
        private IronEncryptResult Encrypt(string password, SubConfig config, string toEncrypt)
        {
            var key = GenerateKey(password, config);

            using (var encryption = AlgorithmHelper.GetEncryption(config.Algorithm, key.Key, key.Iv))
            {
                return(EncryptWithCorrectEncryption(toEncrypt, key, encryption));
            }
        }
Exemple #9
0
        private IronDecryptResult Decrypt(string password, SubConfig config, byte[] toDecrypt)
        {
            var key = GenerateKey(password, config);

            using (var encryption = AlgorithmHelper.GetDecryption(config.Algorithm, key.Key, key.Iv))
            {
                return(DecryptWithCorrectDecryptionAlgorithm(toDecrypt, key, encryption));
            }
        }
Exemple #10
0
        private Edge SelectEdge()
        {
            Node currentNode = _way.Last();

            // Проверяем ограничения задачи
            List <Edge> avaliableEdges = new List <Edge>();

            foreach (var edge in currentNode.Outputs)
            {
                // Проверяем все резервуары на переливы недоливы и что не превысили максимальное количество нефти по поставщикам и потребителям
                bool badPoints = edge.Transition.PipelineObjectChanges.Any(x =>
                {
                    if (typeof(Reservoir) == x.Key.GetType())
                    {
                        double reservoirLevel = _length[x.Key] + x.Value;

                        if (reservoirLevel < 0 || reservoirLevel > (x.Key as Reservoir).Volume)
                        {
                            return(true);
                        }
                    }

                    if ((typeof(IOObject) == x.Key.GetType()) && (Math.Abs(_length[x.Key] + x.Value) > Math.Abs(_target[x.Key]) + MAX_VOLUME_ERROR))
                    {
                        return(true);
                    }

                    return(false);
                });

                if (!badPoints)
                {
                    avaliableEdges.Add(edge);
                }
            }

            // Из оставшихся переходов выбираем на базе уровня феромона и эвристики
            List <double> probability = new List <double>();
            double        sum         = 0;

            foreach (var edge in avaliableEdges)
            {
                double pheromone_alpha = Math.Pow(edge.Pheromone, ALPHA);

                double heuristic_beta = Math.Pow(GetEdgeHeuristic(edge), BETA);

                double pr = pheromone_alpha * heuristic_beta;
                probability.Add(pr);
                sum += pr;
            }

            // Вероятности выбора
            probability = probability.Select(x => x / sum).ToList();

            return(avaliableEdges[AlgorithmHelper.GetRouletIndex(probability)]);
        }
Exemple #11
0
 public override void Sort()
 {
     for (int i = 0; i < Array.Length; i++)
     {
         for (int j = i; j > 0 && Array[j - 1] > Array[j]; j--)
         {
             AlgorithmHelper.Swap(ref Array[j], ref Array[j - 1]);
         }
     }
 }
Exemple #12
0
        public static bool IsCorrect(this IHashable component, IAlgorithm algorithm = null)
        {
            if (algorithm == null)
            {
                algorithm = AlgorithmHelper.GetDefaultAlgorithm();
            }

            var correct = component.Hash == component.GetHash(algorithm);

            return(correct);
        }
Exemple #13
0
        private static byte[] CreateIvBytes(SubConfig config)
        {
            var iv = config.Iv;

            if (iv == null)
            {
                iv = AlgorithmHelper.CreateIv(config.Algorithm);
            }

            return(iv);
        }
Exemple #14
0
 private static void CheckConfiguration(string password, SubConfig config)
 {
     if (string.IsNullOrEmpty(password))
     {
         throw new IronMissingPasswordException("No password provided");
     }
     if (password.Length < AlgorithmHelper.GetNumberOfBits(config.Algorithm) / 8)
     {
         throw new IronConfigurationErrorException("Password buffer is too small");
     }
 }
Exemple #15
0
        /// <summary>
        /// Получить начальный блок цепочки блоков.
        /// </summary>
        /// <param name="algorithm"> Алгоритм хеширования. </param>
        /// <returns> Стартовый блок. </returns>
        public static Block GetGenesisBlock(IAlgorithm algorithm = null)
        {
            if (algorithm == null)
            {
                algorithm = AlgorithmHelper.GetDefaultAlgorithm();
            }

            var genesisBlock = new Block(algorithm);

            return(genesisBlock);
        }
Exemple #16
0
 public void MouseMove(MouseEventArgs e)
 {
     if (_mouseDown)
     {
         if (_collection.Count > 1)
         {
             _currentAngle = Helper.AlgorithmHelper.PointToCenterAngle(_center, e.Location);
             _currentAngle = AlgorithmHelper.NormalizeDegree(270, _currentAngle);
             // Console.WriteLine("VAL ===== " + PointerToValue(_currentAngle));
             _value = PointerToValue(_currentAngle);
         }
     }
 }
Exemple #17
0
        public void MACDCalculator_shouldCalculateMacd_with_validData()
        {
            List <double> longPrices = new List <double> {
                24.8, 24.55, 24.45, 24.5, 24.44, 24.11, 24.31, 25.37, 26, 25.61, 25.43,
                25.56, 25.41, 24.91, 25.1, 25.59, 25.85, 25.15, 25.46, 26.05, 25.74, 25.79,
                25.67, 25.8, 25.23, 25.19, 25.28, 24.91, 24.66, 24.99, 24.53, 24.15, 24.1,
                24.18, 23.92, 24.37, 24.2, 24.66, 24.2, 24.09, 23.49, 23.54, 23.55, 23.2,
                23.37, 23.04, 23.44, 23.3, 23.2, 22.91, 22.97, 23.79, 23.21, 23.13, 23.13,
                23.36, 23.13, 22.92, 22.92, 22.5, 22.8, 22.66, 22.88, 23.16, 23.54, 23.91,
                23.92, 23.83, 24.12, 23.78, 24, 23.83, 23.53, 23.05, 22.15, 22.2, 22.26,
                22.38, 22.46, 22.54, 22.32, 22.48, 22.25, 21.49, 21.48, 21.7, 21.79, 21.8,
                22, 21.89, 21.71, 21.27, 22.07, 22.12, 22.2, 22.05, 21.92, 21.98, 21.81,
                22.08, 22.26, 22, 22.22, 22.29, 22.89, 22.96, 23.19, 23.08, 23.14, 22.63,
                22.79, 22.64, 22.13, 22.21, 22.17, 22.19, 21.99, 21.67, 21.94, 21.95, 22.02,
                22.09, 22.02, 21.99, 21.88, 21.81, 21.84, 22.39, 22.31, 22.33, 21.92, 22.12,
                21.71, 21.69, 21.89, 21.9, 22.05, 21.95, 22.14, 22.08, 22.15, 22.26, 22.09,
                21.84, 22.07, 21.95, 22.03, 22.26, 22.15, 22.08, 22.48, 22.58, 22.39, 22.35,
                22.03, 22.04, 21.97, 22.07, 22.01, 22.16, 22.31, 22.47, 22.52, 22.6, 22.74,
                22.6, 22.6, 22.34, 22.19, 22.47, 22.73, 22.69, 22.73, 22.42, 22.62, 22.67,
                23.12, 23.12, 23.63, 23.87, 24.58, 24.6, 24.38, 24.63, 24.59, 25.08, 24.81,
                24.72, 24.41, 24.71, 25.05, 25.04, 25.02, 24.73, 24.96, 25.21, 25.22, 25,
                24.8, 24.88, 24.71, 24.58, 24.59, 24.36, 24.63, 25.17, 25.65, 25.72, 26.04,
                25.98, 25.85, 25.72, 25.71, 25.74, 25.6, 25.42, 25.28, 25.38, 25.37, 24.82,
                25.04, 25.77, 25.47, 25.61, 25.35, 25.77, 25.54, 25.45, 25.69, 25.97, 25.73,
                26.25, 25.86, 25.64, 25.63, 25.64, 25.8, 25.6, 25.76, 25.85, 25.79, 25.47,
                25.22, 25.24, 24.88, 25.63, 25.85, 26.09, 26.57, 26.54, 26.55, 26.47, 26.44,
                26.38, 27.08, 27.23, 27.44, 27.35, 28.25, 27.43, 27.18, 27.33, 27.23, 28.61,
                29.2, 29.67, 29.59, 30.3, 29.22, 30.91, 32.21, 34.79, 34.49, 35.15, 32.57,
                33.29, 34.06, 33.43, 33.55, 34.79, 35.9, 35.55, 35.68, 35.4, 34.07, 33.86,
                36.16, 35.95, 36.23, 37.21, 37.28, 37.46, 37.58, 38.01, 37.02, 36.96, 36.39,
                36.33, 36.09, 37.31, 36.27, 34.9, 36.95, 37, 36.88, 37.16, 36.56, 35.43,
                35.74, 33.9, 34.57, 35.93, 36.33, 34.91, 33.67, 34.11, 34.91, 34.88, 35.38,
                35.67, 36.18, 36.04, 35.9, 36.05, 36, 36.41, 35.51, 36.54, 36.35, 36.73,
                35.75, 35.69, 35.45, 35, 35.77, 35.41, 35.83, 36.64, 36.66, 38.1, 38.82,
                39.93, 39.7, 40.53, 40.81, 40.77, 40.17, 40.4, 40.98, 42.89, 41.64, 42.7,
                42.32, 43.46, 43.91, 44.18, 43.26, 45, 45.02, 45.35, 44.79, 46.8, 44.48,
                46.44, 47.45, 49.24, 48.58, 48.63, 49.4, 48.85, 48.95, 48.76, 49.09, 49.62,
                47.11, 46.19, 45.92, 47.12, 48.08, 48.54, 47.96,
            };

            List <MacdData> value = MACDCalculator.CalculateMACD(MACDCalculator.FastPeriod, MACDCalculator.SlowPeriod, MACDCalculator.SignalPeriod, longPrices.ToArray());

            Assert.IsTrue(value.Count == 348);
            var last = AlgorithmHelper.TakeLast <MacdData>(value, 1).FirstOrDefault();

            Assert.IsTrue(last != null);
            Assert.IsTrue(last.MacdHIST.AlmostEqual(-0.3536));
            Assert.IsTrue(last.MacdValue.AlmostEqual(1.15));
            Assert.IsTrue(last.MacdSingal.AlmostEqual(1.50));
        }
        /// <summary>
        /// 申请退款
        /// </summary>
        /// <param name="user_id"></param>
        /// <param name="serial_no"></param>
        /// <returns></returns>
        public StateCode ApplyRefund(long user_id, string serial_no)
        {
            using (ISession s = SessionFactory.Instance.CreateSession())
            {
                try
                {
                    s.StartTransaction();
                    ProductOrder order = s.Get <ProductOrder>("where serial_no = @0", serial_no);
                    if (order == null)
                    {
                        return(StateCode.State_551);
                    }

                    //是否支付
                    if (!order.is_pay)
                    {
                        return(StateCode.State_552);
                    }

                    //退款订单
                    OrderRefund refund = new OrderRefund();

                    //退款单
                    refund.order_id         = order.id;
                    refund.created_user_id  = user_id;
                    refund.status           = OrderRefundStatus.Apply;
                    refund.order_serial_no  = order.serial_no;
                    refund.refund_serial_no = AlgorithmHelper.CreateNo19("T");
                    //原订单金额
                    refund.order_actual_amount = order.actual_amount;
                    //退款总金额
                    refund.refund_total_amount = order.total_amount;
                    refund.created_date        = DateTime.Now;
                    s.Insert(refund);

                    //修改订单状态
                    s.ExcuteUpdate("update tb_odr_order set refund_status = @0 where serial_no = @1 ", OrderRefundStatus.Apply, serial_no);

                    s.Commit();
                    return(StateCode.State_200);
                }
                catch (Exception ex)
                {
                    s.RollBack();
                    return(StateCode.State_500);
                }
            }
        }
        public Indicator AnalyzeData(DataState state)
        {
            double[] highPrices  = _analyseRepo.LoadHighPriceBySymbol(state.Symbol, true).ToArray();
            double[] lowPrices   = _analyseRepo.LoadLowPriceBySymbol(state.Symbol, true).ToArray();
            double[] closePrices = _analyseRepo.LoadClosePriceBySymbol(state.Symbol, true).ToArray();
            double[] adxValues   = ADXCalculator.CalculateADX(ADXCalculator.Period, highPrices, lowPrices, closePrices);
            if (adxValues.Length == 0)
            {
                return(null);
            }

            ADX value = new ADX();

            value.Symbol = state.Symbol;
            value.Date   = state.Last.Value;
            value.ADX14  = AlgorithmHelper.GetLast(adxValues);
            return(value.ToIndicator());
        }
Exemple #20
0
        public IActionResult Login()
        {
            if (LoginUser.Instance.IsLogin(HttpContext))
            {
                return(LocalRedirect("~/Home/Index"));
            }

            //生成公私钥对
            (string, string)p = AlgorithmHelper.CreateKeyPair();

            //公钥
            ViewBag.publicKey = p.Item1;

            //私钥存储在绘话状态中
            HttpContext.Session.SetString("privateKey", p.Item2);

            return(View());
        }
        public JsonResult UpdatePassword()
        {
            try
            {
                string funcId = PermissionEnum.CodeFormat((int)PermissionEnum.公司管理.员工管理.改密);
                if (!IsPermission(funcId))
                {
                    return(Error("您没有操作权限,请联系系统管理员!"));
                }

                string staffId         = GetQueryString("staffId");
                string newPassword     = GetFormValue("fNewPassword");
                string confirmPassword = GetFormValue("fConfirmPassword");
                if (string.IsNullOrEmpty(staffId))
                {
                    return(Error("员工工号不能为空!"));
                }
                if (confirmPassword.Length < 6)
                {
                    return(Error("密码长度不能少于6位字符!"));
                }
                if (newPassword != confirmPassword)
                {
                    return(Error("输入的二次密码不相同!"));
                }
                string password      = AlgorithmHelper.MD5(confirmPassword).ToLower();
                var    entity        = StaffService.GetStaffPro(SystemID, CompanyID, staffId);
                var    result        = StaffService.UpdateStaffPasswordPro(SystemID, CompanyID, staffId, password);
                string newEntityJson = GetNewEntityJson(entity, password);
                TableOperationManager.Update(entity, newEntityJson, result);
                if (result)
                {
                    return(Success("ok"));
                }
                else
                {
                    return(Error("fail"));
                }
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }
        public List <string> Dencrypt(List <string> source, string key)
        {
            if (key == null || !key.Any())
            {
                throw new ArgumentNullException($"Ключ {key} пуст");
            }

            if (!AlgorithmHelper.IsKeyCorrect(key.ToLower()))
            {
                throw new Exception($"Ключ {key} не соответствует алфавиту");
            }

            if (!source.Any())
            {
                throw new ArgumentNullException($"Массив с исходными данными пуст");
            }

            return(AlgorithmHelper.GetEncodeOrDencodeArray(source, key.ToLower(), Model.ActionMode.dencrypt));
        }
        public JsonResult UpdatePassword()
        {
            try
            {
                string funcId = PermissionEnum.CodeFormat((int)PermissionEnum.接口管理.帐号管理.修改密码);
                if (!IsPermission(funcId))
                {
                    return(Error("您没有操作权限,请联系系统管理员!"));
                }

                string account          = GetQueryString("account");
                string fNewPassword     = GetFormValue("fNewPassword");
                string fConfirmPassword = GetFormValue("fConfirmPassword");
                if (string.IsNullOrEmpty(account))
                {
                    return(Error("帐号不能为空!"));
                }
                if (fConfirmPassword.Length < 6)
                {
                    return(Error("密码长度不能少于6位字符!"));
                }
                if (fNewPassword != fConfirmPassword)
                {
                    return(Error("输入的二次密码不相同!"));
                }
                string password = AlgorithmHelper.MD5(fConfirmPassword).ToLower();

                var result = InterfaceAccountService.UpdateInterfaceAccountPasswordPro(SystemID, CompanyID, account, password);
                if (result)
                {
                    return(Success("ok"));
                }
                else
                {
                    return(Error("fail"));
                }
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }
        public JsonResult UpdatePassword()
        {
            try
            {
                string funcId = PermissionEnum.CodeFormat((int)PermissionEnum.会员管理.会员资料.改密);
                if (!IsPermission(funcId))
                {
                    return(Error("您没有操作权限,请联系系统管理员!"));
                }

                string memberId        = GetQueryString("memberId");
                string newPassword     = GetFormValue("fNewPassword");
                string confirmPassword = GetFormValue("fConfirmPassword");
                if (string.IsNullOrEmpty(memberId))
                {
                    return(Error("会员ID不能为空!"));
                }
                if (confirmPassword.Length < 6)
                {
                    return(Error("密码长度不能少于6位字符!"));
                }
                if (newPassword != confirmPassword)
                {
                    return(Error("输入的二次密码不相同!"));
                }
                string password = AlgorithmHelper.MD5(confirmPassword).ToLower();

                var result = AccountService.UpdateAccountPasswordPro(SystemID, CompanyID, memberId, password);
                if (result)
                {
                    return(Success("ok"));
                }
                else
                {
                    return(Error("fail"));
                }
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }
        public JsonResult UpdatePassword()
        {
            try
            {
                string funcId = PermissionEnum.CodeFormat((int)PermissionEnum.管理员管理.操作员管理.改密);
                if (!IsPermission(funcId))
                {
                    return(Error("您没有操作权限,请联系系统管理员!"));
                }
                string staffId          = GetQueryString("staffId");
                string fNewPassword     = GetFormValue("fNewPassword");
                string fConfirmPassword = GetFormValue("fConfirmPassword");
                if (string.IsNullOrEmpty(staffId))
                {
                    return(Error("员工工号不能为空!"));
                }
                if (fConfirmPassword.Length < 6)
                {
                    return(Error("密码长度不能少于6位字符!"));
                }
                if (fNewPassword != fConfirmPassword)
                {
                    return(Error("输入的二次密码不相同!"));
                }
                string password = AlgorithmHelper.MD5(fConfirmPassword).ToLower();

                var result = OperatorService.UpdateOperatorPasswordPro(SystemID, CompanyID, staffId, password);
                if (result)
                {
                    return(Success("ok"));
                }
                else
                {
                    return(Error("fail"));
                }
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }
Exemple #26
0
 public void MouseDown(MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         if (Helper.AlgorithmHelper.IsPointInRect(_clientRect, e.Location))
         {
             _mouseDown = true;
             if (_collection.Count > 1)
             {
                 if (_step)
                 {
                     NearestAngle();
                 }
                 else
                 {
                     _currentAngle = AlgorithmHelper.PointToCenterAngle(_center, e.Location);
                     _currentAngle = AlgorithmHelper.NormalizeDegree(270, _currentAngle);
                 }
             }
         }
     }
 }
Exemple #27
0
        public Indicator AnalyzeData(DataState state)
        {
            double[] closePrices = _analyseRepo.LoadClosePriceBySymbol(state.Symbol, true).ToArray();

            double[] sma5Values   = SMACalculator.CalculateSMA(5, closePrices);
            double[] sma10Values  = SMACalculator.CalculateSMA(10, closePrices);
            double[] sma20Values  = SMACalculator.CalculateSMA(20, closePrices);
            double[] sma50Values  = SMACalculator.CalculateSMA(50, closePrices);
            double[] sma200Values = SMACalculator.CalculateSMA(200, closePrices);

            SMA value = new SMA();

            value.Symbol = state.Symbol;
            value.Date   = state.Last.Value;
            value.SMA5   = AlgorithmHelper.GetLast(sma5Values);
            value.SMA10  = AlgorithmHelper.GetLast(sma10Values);
            value.SMA20  = AlgorithmHelper.GetLast(sma20Values);
            value.SMA50  = AlgorithmHelper.GetLast(sma50Values);
            value.SMA200 = AlgorithmHelper.GetLast(sma200Values);

            return(value.ToIndicator());
        }
Exemple #28
0
        public override void Sort()
        {
            if (Array == null)
            {
                throw new NullReferenceException();
            }

            if (Array.Length.Equals(0))
            {
                throw new ArgumentNullException();
            }

            for (int i = 0; i < Array.Length; i++)
            {
                for (int j = 0; j < Array.Length - 1; j++)
                {
                    if (Array[j] > Array[j + 1])
                    {
                        AlgorithmHelper.Swap(ref Array[j], ref Array[j + 1]);
                    }
                }
            }
        }
 public string GenerateCacheName(string url)
 {
     return(AlgorithmHelper.ComputeHash(url, HashAlgorithmNames.Sha1));
 }
        public JsonResult Login(string companyId)
        {
            try
            {
                string username                = GetFormValue("username");
                string password                = GetFormValue("password");
                string verifyCode              = GetFormValue("verifycode");
                bool   online                  = GetFormValue("online").ToBool();
                string cookieVerifyCode        = WebHelper.GetCookie("VerifyCode");
                string decryptCookieVerifyCode = DESEncryptHelper.DecryptDES(cookieVerifyCode);

                string[] arrUserName = username.Split('@');
                if (arrUserName.Length == 2)
                {
                    companyId = arrUserName[0].ToString();
                    username  = arrUserName[1].ToString();
                }
                else
                {
                    companyId = Utility.IIF(companyId, "sys");
                }

                if (string.IsNullOrEmpty(username))
                {
                    return(Error("用户名不能为空!"));
                }
                if (string.IsNullOrEmpty(password))
                {
                    return(Error("密码不能为空!"));
                }
                if (string.IsNullOrEmpty(verifyCode))
                {
                    return(Error("验证码不能为空!"));
                }
                if (decryptCookieVerifyCode.ToUpper() != verifyCode.ToUpper())
                {
                    return(Error("验证码不正确!"));
                }

                var LoginResult = StaffService.VerifyStaffLoginPro(SystemID, companyId, username, AlgorithmHelper.MD5(password));
                if (LoginResult)
                {
                    var    entityStaff = StaffService.GetVStaffPro(SystemID, companyId, username);
                    string staffId     = entityStaff.StaffID;
                    string staffName   = entityStaff.StaffName;
                    string CompanyId   = entityStaff.CompanyID;
                    SaveLoginRecord(companyId, username, staffName, LoginResult, 1);
                    AccountModel entity = new AccountModel()
                    {
                        SessionID = "", CompanyID = CompanyId, StaffID = username, StaffName = staffName, Online = online, Roles = "Admins"
                    };
                    string userJson = DESEncryptHelper.EncryptDES(entity.ToJson());
                    WebHelper.WriteCookie(SessionName, userJson);
                    return(Success("成功"));
                }
                else
                {
                    SaveLoginRecord(companyId, username, "-", LoginResult, 2);
                    return(Error("login fail"));
                }
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }