Пример #1
0
        private decimal Get_Assets(string accountNumber, decimal balance)
        {
            HKeInvestCode     myHKeInvestCode     = new HKeInvestCode();
            HKeInvestData     myHKeInvestData     = new HKeInvestData();
            ExternalFunctions myExternalFunctions = new ExternalFunctions();

            DataTable dtCurrency = myExternalFunctions.getCurrencyData();
            DataTable dt         = myHKeInvestData.getData("SELECT type, code, shares, base FROM [SecurityHolding] WHERE accountNumber='" + accountNumber + "'");
            decimal   ret        = balance;

            foreach (DataRow row in dt.Rows)
            {
                string    securityCode = row["code"].ToString();
                string    securityType = row["type"].ToString();
                string    securityBase = row["base"].ToString();
                decimal   shares       = Convert.ToDecimal(row["shares"]);
                decimal   price        = myExternalFunctions.getSecuritiesPrice(securityType, securityCode);
                decimal   value        = Math.Round(shares * price - (decimal).005, 2);
                DataRow[] baseRateRow  = dtCurrency.Select("currency = '" + securityBase + "'");
                DataRow[] toRateRow    = dtCurrency.Select("currency = 'HKD'");
                if (baseRateRow.Length == 1 && toRateRow.Length == 1)
                {
                    value = myHKeInvestCode.convertCurrency(securityBase, baseRateRow[0]["rate"].ToString(), "HKD", toRateRow[0]["rate"].ToString(), value);
                }
                ret += value;
            }
            return(ret);
        }
Пример #2
0
        private void Calculate_totalPrice(DataTable dtTransaction, string type, string code, out decimal totalPrice, out decimal totalShares, out string securityBase)
        {
            ExternalFunctions myExternalFunctions = new ExternalFunctions();

            securityBase = "HKD";
            totalShares  = 0;
            totalPrice   = 0;
            if (type != "stock")
            {
                DataTable dt = myExternalFunctions.getSecuritiesByCode(type, code);
                securityBase = dt.Rows[0].Field <string>("base");
            }
            decimal exchangeRate = myExternalFunctions.getCurrencyRate(securityBase);

            foreach (DataRow row in dtTransaction.Rows)
            {
                decimal price  = row.Field <decimal>("executePrice");
                decimal shares = row.Field <decimal>("executeShares");
                totalShares += shares;
                // need to convert the base for price
                totalPrice = totalPrice + (price * shares);
            }
            totalPrice *= exchangeRate;
            totalPrice  = Math.Round(totalPrice, 2);
            return;
        }
Пример #3
0
        public void retrieveCurrency(System.Web.SessionState.HttpSessionState session)
        {
            ExternalFunctions myExternalFunctions = new ExternalFunctions();
            DataTable         currencies          = myExternalFunctions.getCurrencyData();

            session["currency"] = currencies;
        }
 public void Clear()
 {
     ParseErrors.Clear();
     Functions.Clear();
     ExternalFunctions.Clear();
     MaxFunctionVariables = 0;
 }
Пример #5
0
        public void getcurrency(HttpSessionState Session)
        {
            ExternalFunctions myExternalFunctions = new ExternalFunctions();
            DataTable         dtCurrency          = myExternalFunctions.getCurrencyData();

            Session["currencyRate"] = dtCurrency;
        }
Пример #6
0
        public void RegisterHotKey(ShortcutItemEntity item)
        {
            var helper = new WindowInteropHelper(this);

            if (!ExternalFunctions.RegisterHotKey(helper.Handle, item.Id + 9000, (uint)item.ModifierKeys, (uint)item.Key))
            {
                throw new Exception("Could not register Shortcut");
            }
        }
Пример #7
0
 public void getCurrency(HttpSessionState state)
 {
     if (state == null)
     {
         ExternalFunctions myExternalFunctions = new ExternalFunctions();
         DataTable         currencies          = myExternalFunctions.getCurrencies();
         state.Add("currencies", currencies);
     }
 }
Пример #8
0
 public DataTable getCurrencyData(HttpSessionState session)
 {
     if (session["currencyData"] == null)
     {
         ExternalFunctions myExternalFunctions = new ExternalFunctions();
         session["currencyData"] = myExternalFunctions.getCurrencyData();
     }
     return((DataTable)session["currencyData"]);
 }
Пример #9
0
        /// <summary>
        /// Whether or not the name/member combination supplied is a script level function or an external C# function
        /// </summary>
        /// <param name="ctx">Context of script</param>
        /// <param name="name">Object name "Log"</param>
        /// <param name="member">Member name "Info" as in "Log.Info"</param>
        /// <returns></returns>
        //public static bool IsInternalOrExternalFunction2(Context ctx, string name, string member)
        //{
        //    string fullName = name;
        //    if (!string.IsNullOrEmpty(member))
        //        fullName += "." + member;
        //
        //    // Case 1: getuser() script function
        //    if (ctx.Functions.Contains(fullName) || ctx.ExternalFunctions.Contains(fullName))
        //        return true;
        //
        //    return false;
        //}

        /// <summary>
        /// Whether or not this variable + member name maps to an external function call.
        /// Note: In fluentscript you can setup "Log.*" and allow all method calls to "Log" to map to that external call.
        /// </summary>
        /// <param name="funcs">The collection of external functions.</param>
        /// <param name="varName">The name of the external object e.g. "Log" as in "Log.Error"</param>
        /// <param name="memberName">The name of the method e.g. "Error" as in "Log.Error"</param>
        /// <returns></returns>
        public static bool IsExternalFunction(ExternalFunctions funcs, string varName, string memberName)
        {
            var funcName = varName + "." + memberName;

            if (funcs.Contains(funcName))
            {
                return(true);
            }
            return(false);
        }
Пример #10
0
        /*public void addSessionVariable()
         * {
         *  ExternalFunctions myExternalFunctions = new ExternalFunctions();
         *  DataTable dtCurrency = myExternalFunctions.getCurrencyData();
         * }*/

        public void addSessionVariable(System.Web.SessionState.HttpSessionState Session)
        {
            ExternalFunctions myExternalFunctions = new ExternalFunctions();
            DataTable         dtCurrency          = myExternalFunctions.getCurrencyData();

            Session["CurrencyData"] = myExternalFunctions.getCurrencyData();

            foreach (DataRow row in dtCurrency.Rows)
            {
                string targetCurr = row["currency"].ToString().Trim();
                Session[targetCurr] = row["rate"].ToString().Trim();
            }
        }
        protected void cv3_ServerValidate(object source, ServerValidateEventArgs args)
        {
            ExternalFunctions myExternalFunctions = new ExternalFunctions();
            decimal           curprice            = myExternalFunctions.getSecuritiesPrice(Stype.SelectedValue, Snamecode.SelectedValue);

            if (lowValue.Text != "")
            {
                if (System.Convert.ToDecimal(lowValue.Text) >= curprice)
                {
                    args.IsValid     = false;
                    cv1.ErrorMessage = "The low value must not higher or equal to the current price.";
                }
            }
        }
Пример #12
0
        private void Check_AlertStatus()
        {
            HKeInvestData     myHKeInvestData     = new HKeInvestData();
            ExternalFunctions myExternalFunctions = new ExternalFunctions();
            DataTable         dtAlert             = myHKeInvestData.getData("SELECT * FROM [Alert]");

            foreach (DataRow alert in dtAlert.Rows)
            {
                string  accountNumber = alert.Field <string>("accountNumber");
                string  code          = alert.Field <string>("code");
                string  type          = alert.Field <string>("type");
                string  highOrLow     = alert.Field <string>("highOrLow");
                decimal value         = alert.Field <decimal>("value");
                string  isSameSide    = alert.Field <string>("isSameSide");
                decimal currPrice     = myExternalFunctions.getSecuritiesPrice(type, code);

                if (((highOrLow == "high" && currPrice >= value) || (highOrLow == "low" && currPrice <= value)) && isSameSide == "no")
                {
                    // send notification to the client and cancel the alert.
                    string sql = string.Format("DELETE FROM [Alert] WHERE accountNumber='{0}' AND code='{1}' AND type='{2}' AND highOrLow='{3}'",
                                               accountNumber,
                                               code,
                                               type,
                                               highOrLow);
                    var trans = myHKeInvestData.beginTransaction();
                    myHKeInvestData.setData(sql, trans);
                    myHKeInvestData.commitTransaction(trans);
                    Send_Notification(accountNumber, type, code, highOrLow, currPrice);
                }
                else if (isSameSide == "yes" && ((highOrLow == "high" && currPrice < value) || (highOrLow == "low" && currPrice > value)))
                {
                    string sql = string.Format("UPDATE [Alert] SET isSameSide='no' WHERE  accountNumber='{0}' AND code='{1}' AND type='{2}' AND highOrLow='{3}'",
                                               accountNumber,
                                               code,
                                               type,
                                               highOrLow);
                    var trans = myHKeInvestData.beginTransaction();
                    myHKeInvestData.setData(sql, trans);
                    myHKeInvestData.commitTransaction(trans);
                }
            }
        }
Пример #13
0
        private void PeriodicTask()
        {
            HKeInvestData     myHKeInvestData     = new HKeInvestData();
            ExternalFunctions myExternalFunctions = new ExternalFunctions();

            do
            {
                DataTable dtOrders = myHKeInvestData.getData("SELECT * FROM [Order]");

                foreach (DataRow order in dtOrders.Rows)
                {
                    string code            = order.Field <string>("securityCode");
                    string referenceNumber = order.Field <string>("orderReferenceNumber");
                    string oldStatus       = order.Field <string>("orderStatus").Trim();
                    string status          = myExternalFunctions.getOrderStatus(referenceNumber).Trim();
                    if (status == "partial" || oldStatus != status)
                    {
                        DataTable dtTransaction = myExternalFunctions.getOrderTransaction(referenceNumber);
                        // update the local transaction table, get the new transactions in dtChanges
                        DataTable dtChanges = Sync_TransactionTable(dtTransaction, referenceNumber);
                        if (dtChanges != null || oldStatus != status)
                        {
                            string    type, buyOrSell;
                            DataTable dtOrderDetails = getOrderDetails(referenceNumber, out type, out buyOrSell);
                            if (dtOrderDetails == null)
                            {
                                // cannot find the order details, internal error
                                continue;
                            }

                            string    accountNumber = order.Field <string>("accountNumber");
                            DataTable dtAccount     = myHKeInvestData.getData("SELECT balance FROM [Account] WHERE accountNumber='" + accountNumber + "'");
                            if (dtAccount.Rows.Count != 1)
                            {
                                // cannot find the account balance, internal error
                                continue;
                            }
                            decimal balance = dtAccount.Rows[0].Field <decimal>("balance");

                            // calculate the total executed price for dtChanges not all transactions
                            decimal totalPrice, totalShares;
                            string  securityBase;
                            if (dtChanges != null)
                            {
                                Calculate_totalPrice(dtChanges, type, code, out totalPrice, out totalShares, out securityBase);

                                // update account balance and security holdings
                                balance = Update_AccountBalance(accountNumber, balance, 0, totalPrice, buyOrSell);
                                Update_SecurityHolding(dtOrderDetails, type, accountNumber, totalShares, securityBase, buyOrSell);
                            }


                            if (oldStatus != status)
                            {
                                if (status == "completed" || status == "cancelled")
                                {
                                    // order finished execution
                                    decimal assets = Get_Assets(accountNumber, balance);
                                    // calculate service fee
                                    Calculate_totalPrice(dtTransaction, type, code, out totalPrice, out totalShares, out securityBase);
                                    decimal serviceFee = Calculate_ServiceFee(totalPrice, assets, type, buyOrSell, dtOrderDetails);
                                    // update order status
                                    Update_OrderStatus(referenceNumber, status, serviceFee);
                                    // update account balance and security holdings
                                    Update_AccountBalance(accountNumber, balance, serviceFee, 0, buyOrSell);
                                    // send invoice to client
                                    Send_Invoice(referenceNumber, accountNumber, buyOrSell, code, type, dtOrderDetails, serviceFee, totalPrice, totalShares, dtTransaction);
                                }
                                else
                                {
                                    Update_OrderStatus(referenceNumber, status, 0);
                                }
                            }
                        }
                    }
                }

                // check the status of alerts
                Check_AlertStatus();

                Thread.Sleep(20000);
            } while (true);

            throw new NotImplementedException();
        }
Пример #14
0
 public static void Register <T1, T2, T3, TResult>(string name, Func <T1, T2, T3, TResult> fn)
 => ExternalFunctions.Register(name, fn, 3, typeof(TResult));
Пример #15
0
        public void UnRegisterHotKey(ShortcutItemEntity item)
        {
            var helper = new WindowInteropHelper(this);

            ExternalFunctions.UnregisterHotKey(helper.Handle, item.Id);
        }
Пример #16
0
        protected void doSearch(object sender, EventArgs e)
        {
            string            type = Stype.SelectedValue;
            string            code = Scode.Text.Trim();
            string            name = Sname.Text.Trim();
            DataTable         searchresult;
            ExternalFunctions myExternalFunctions = new ExternalFunctions();

            if (Stype.SelectedValue == "bond")
            {
                stocktable.Visible = false;
                unittable.Visible  = false;

                if (code == "" && name == "")
                {
                    searchresult = myExternalFunctions.getSecuritiesData(type);
                    if (searchresult == null)
                    {
                        lblerror.Text    = "No machted security is found.";
                        lblerror.Visible = true;
                    }
                    else
                    {
                        /*//searchresult.AcceptChanges();
                         * //ViewState["SortExpression"] = "name";
                         * //ViewState["SortDirection"] = "ASC";
                         * gvBond.DataSource = searchresult;
                         * gvBond.DataBind();
                         * //gvActiveBond.Sort("datesubmitted", SortDirection.Descending);
                         * //gvBond.Sort("name", SortDirection.Ascending);
                         * bondtable.Visible = true;*/
                        foreach (DataRow row in searchresult.Rows)
                        {
                            foreach (DataColumn col in searchresult.Columns)
                            {
                                if (row[col] == DBNull.Value)
                                {
                                    row[col] = Convert.ToDecimal("0.00");
                                }
                            }
                        }
                        searchresult.AcceptChanges();
                        ViewState["SortExpression"] = "name";
                        ViewState["SortDirection"]  = "DESC";
                        gvBond.DataSource           = searchresult;
                        gvBond.DataBind();
                        gvBond.Sort("name", SortDirection.Descending);
                        bondtable.Visible = true;
                    }
                }
                else if (name == "")
                {
                    searchresult = myExternalFunctions.getSecuritiesByCode(type, code);
                    if (searchresult == null)
                    {
                        lblerror.Text    = "No machted security is found.";
                        lblerror.Visible = true;
                    }
                    else
                    {
                        foreach (DataRow row in searchresult.Rows)
                        {
                            foreach (DataColumn col in searchresult.Columns)
                            {
                                if (row[col] == DBNull.Value)
                                {
                                    row[col] = Convert.ToDecimal("0.00");
                                }
                            }
                        }
                        searchresult.AcceptChanges();
                        ViewState["SortExpression"] = "name";
                        ViewState["SortDirection"]  = "DESC";
                        gvBond.DataSource           = searchresult;
                        gvBond.DataBind();
                        gvBond.Sort("name", SortDirection.Descending);
                        bondtable.Visible = true;
                    }
                }
                else if (code == "")
                {
                    searchresult = myExternalFunctions.getSecuritiesByName(type, name);
                    if (searchresult == null)
                    {
                        lblerror.Text    = "No machted security is found.";
                        lblerror.Visible = true;
                    }
                    else
                    {
                        foreach (DataRow row in searchresult.Rows)
                        {
                            foreach (DataColumn col in searchresult.Columns)
                            {
                                if (row[col] == DBNull.Value)
                                {
                                    row[col] = Convert.ToDecimal("0.00");
                                }
                            }
                        }
                        searchresult.AcceptChanges();
                        ViewState["SortExpression"] = "name";
                        ViewState["SortDirection"]  = "DESC";
                        gvBond.DataSource           = searchresult;
                        gvBond.DataBind();
                        gvBond.Sort("name", SortDirection.Descending);
                        bondtable.Visible = true;
                    }
                }
                else
                {
                    lblerror.Text    = "Either one of security code or security name is allowed to input.";
                    lblerror.Visible = true;
                }
            }
            else if (Stype.SelectedValue == "stock")
            {
                bondtable.Visible = false;
                unittable.Visible = false;
                if (code == "" && name == "")
                {
                    searchresult = myExternalFunctions.getSecuritiesData(type);
                    if (searchresult == null)
                    {
                        lblerror.Text    = "No machted security is found.";
                        lblerror.Visible = true;
                    }
                    else
                    {
                        foreach (DataRow row in searchresult.Rows)
                        {
                            foreach (DataColumn col in searchresult.Columns)
                            {
                                if (row[col] == DBNull.Value)
                                {
                                    row[col] = Convert.ToDecimal("0.00");
                                }
                            }
                        }
                        searchresult.AcceptChanges();
                        ViewState["SortExpression"] = "name";
                        ViewState["SortDirection"]  = "DESC";
                        gvStock.DataSource          = searchresult;
                        gvStock.DataBind();
                        gvStock.Sort("name", SortDirection.Descending);
                        stocktable.Visible = true;
                    }
                }
                else if (name == "")
                {
                    searchresult = myExternalFunctions.getSecuritiesByCode(type, code);
                    if (searchresult == null)
                    {
                        lblerror.Text    = "No machted security is found.";
                        lblerror.Visible = true;
                    }
                    else
                    {
                        foreach (DataRow row in searchresult.Rows)
                        {
                            foreach (DataColumn col in searchresult.Columns)
                            {
                                if (row[col] == DBNull.Value)
                                {
                                    row[col] = Convert.ToDecimal("0.00");
                                }
                            }
                        }
                        searchresult.AcceptChanges();
                        ViewState["SortExpression"] = "name";
                        ViewState["SortDirection"]  = "DESC";
                        gvStock.DataSource          = searchresult;
                        gvStock.DataBind();
                        gvStock.Sort("name", SortDirection.Descending);
                        stocktable.Visible = true;
                    }
                }
                else if (code == "")
                {
                    searchresult = myExternalFunctions.getSecuritiesByName(type, name);
                    if (searchresult == null)
                    {
                        lblerror.Text    = "No machted security is found.";
                        lblerror.Visible = true;
                    }
                    else
                    {
                        foreach (DataRow row in searchresult.Rows)
                        {
                            foreach (DataColumn col in searchresult.Columns)
                            {
                                if (row[col] == DBNull.Value)
                                {
                                    row[col] = Convert.ToDecimal("0.00");
                                }
                            }
                        }
                        searchresult.AcceptChanges();
                        ViewState["SortExpression"] = "name";
                        ViewState["SortDirection"]  = "DESC";
                        gvStock.DataSource          = searchresult;
                        gvStock.DataBind();
                        gvStock.Sort("name", SortDirection.Descending);
                        stocktable.Visible = true;
                    }
                }
                else
                {
                    lblerror.Text    = "Either one of security code or security name is allowed to input.";
                    lblerror.Visible = true;
                }
                ViewState["SortExpression"] = "name";
                ViewState["SortDirection"]  = "ASC";
            }
            else if (Stype.SelectedValue == "unit trust")
            {
                bondtable.Visible  = false;
                stocktable.Visible = false;
                if (code == "" && name == "")
                {
                    searchresult = myExternalFunctions.getSecuritiesData(type);
                    if (searchresult == null)
                    {
                        lblerror.Text    = "No machted security is found.";
                        lblerror.Visible = true;
                    }
                    else
                    {
                        foreach (DataRow row in searchresult.Rows)
                        {
                            foreach (DataColumn col in searchresult.Columns)
                            {
                                if (row[col] == DBNull.Value)
                                {
                                    row[col] = Convert.ToDecimal("0.00");
                                }
                            }
                        }
                        searchresult.AcceptChanges();
                        gvUnitTrust.DataSource = searchresult;
                        gvUnitTrust.DataBind();
                        unittable.Visible = true;
                    }
                }
                else if (name == "")
                {
                    searchresult = myExternalFunctions.getSecuritiesByCode(type, code);
                    if (searchresult == null)
                    {
                        lblerror.Text    = "No machted security is found.";
                        lblerror.Visible = true;
                    }
                    else
                    {
                        foreach (DataRow row in searchresult.Rows)
                        {
                            foreach (DataColumn col in searchresult.Columns)
                            {
                                if (row[col] == DBNull.Value)
                                {
                                    row[col] = Convert.ToDecimal("0.00");
                                }
                            }
                        }
                        searchresult.AcceptChanges();
                        gvUnitTrust.DataSource = searchresult;
                        gvUnitTrust.DataBind();
                        unittable.Visible = true;
                    }
                }
                else if (code == "")
                {
                    searchresult = myExternalFunctions.getSecuritiesByName(type, name);
                    if (searchresult == null)
                    {
                        lblerror.Text    = "No machted security is found.";
                        lblerror.Visible = true;
                    }
                    else
                    {
                        foreach (DataRow row in searchresult.Rows)
                        {
                            foreach (DataColumn col in searchresult.Columns)
                            {
                                if (row[col] == DBNull.Value)
                                {
                                    row[col] = Convert.ToDecimal("0.00");
                                }
                            }
                        }
                        searchresult.AcceptChanges();
                        gvUnitTrust.DataSource = searchresult;
                        gvUnitTrust.DataBind();
                        unittable.Visible = true;
                    }
                }
                else
                {
                    lblerror.Text    = "Either one of security code or security name is allowed to input.";
                    lblerror.Visible = true;
                }
            }
            ViewState["SortExpression"] = "name";
            ViewState["SortDirection"]  = "ASC";
        }
Пример #17
0
Файл: CPU.cs Проект: vosechu/KOS
 public override bool FindExternalFunction(string name)
 {
     return(ExternalFunctions.Any(function => function.Name == name.ToUpper()));
 }